-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathappdb.js
746 lines (738 loc) · 336 KB
/
appdb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
var $jscomp={scope:{}},COMPILED=!0,goog=goog||{};goog.global=this;goog.isDef=function(a){return void 0!==a};goog.exportPath_=function(a,b,c){a=a.split(".");c=c||goog.global;a[0]in c||!c.execScript||c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)!a.length&&goog.isDef(b)?c[d]=b:c=c[d]?c[d]:c[d]={}};
goog.define=function(a,b){var c=b;COMPILED||(goog.global.CLOSURE_UNCOMPILED_DEFINES&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_UNCOMPILED_DEFINES,a)?c=goog.global.CLOSURE_UNCOMPILED_DEFINES[a]:goog.global.CLOSURE_DEFINES&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_DEFINES,a)&&(c=goog.global.CLOSURE_DEFINES[a]));goog.exportPath_(a,c)};goog.DEBUG=!0;goog.LOCALE="en";goog.TRUSTED_SITE=!0;goog.STRICT_MODE_COMPATIBLE=!1;goog.DISALLOW_TEST_ONLY_CODE=COMPILED&&!goog.DEBUG;
goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING=!1;goog.provide=function(a){if(!COMPILED&&goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');goog.constructNamespace_(a)};goog.constructNamespace_=function(a,b){if(!COMPILED){delete goog.implicitNamespaces_[a];for(var c=a;(c=c.substring(0,c.lastIndexOf(".")))&&!goog.getObjectByName(c);)goog.implicitNamespaces_[c]=!0}goog.exportPath_(a,b)};goog.VALID_MODULE_RE_=/^[a-zA-Z_$][a-zA-Z0-9._$]*$/;
goog.module=function(a){if(!goog.isString(a)||!a||-1==a.search(goog.VALID_MODULE_RE_))throw Error("Invalid module identifier");if(!goog.isInModuleLoader_())throw Error("Module "+a+" has been loaded incorrectly.");if(goog.moduleLoaderState_.moduleName)throw Error("goog.module may only be called once per module.");goog.moduleLoaderState_.moduleName=a;if(!COMPILED){if(goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');delete goog.implicitNamespaces_[a]}};goog.module.get=function(a){return goog.module.getInternal_(a)};
goog.module.getInternal_=function(a){if(!COMPILED)return goog.isProvided_(a)?a in goog.loadedModules_?goog.loadedModules_[a]:goog.getObjectByName(a):null};goog.moduleLoaderState_=null;goog.isInModuleLoader_=function(){return null!=goog.moduleLoaderState_};
goog.module.declareLegacyNamespace=function(){if(!COMPILED&&!goog.isInModuleLoader_())throw Error("goog.module.declareLegacyNamespace must be called from within a goog.module");if(!COMPILED&&!goog.moduleLoaderState_.moduleName)throw Error("goog.module must be called prior to goog.module.declareLegacyNamespace.");goog.moduleLoaderState_.declareLegacyNamespace=!0};
goog.setTestOnly=function(a){if(goog.DISALLOW_TEST_ONLY_CODE)throw a=a||"",Error("Importing test-only code into non-debug environment"+(a?": "+a:"."));};goog.forwardDeclare=function(a){};COMPILED||(goog.isProvided_=function(a){return a in goog.loadedModules_||!goog.implicitNamespaces_[a]&&goog.isDefAndNotNull(goog.getObjectByName(a))},goog.implicitNamespaces_={"goog.module":!0});
goog.getObjectByName=function(a,b){for(var c=a.split("."),d=b||goog.global,e;e=c.shift();)if(goog.isDefAndNotNull(d[e]))d=d[e];else return null;return d};goog.globalize=function(a,b){var c=b||goog.global,d;for(d in a)c[d]=a[d]};goog.addDependency=function(a,b,c,d){if(goog.DEPENDENCIES_ENABLED){var e;a=a.replace(/\\/g,"/");for(var f=goog.dependencies_,g=0;e=b[g];g++)f.nameToPath[e]=a,f.pathIsModule[a]=!!d;for(d=0;b=c[d];d++)a in f.requires||(f.requires[a]={}),f.requires[a][b]=!0}};
goog.ENABLE_DEBUG_LOADER=!0;goog.logToConsole_=function(a){goog.global.console&&goog.global.console.error(a)};goog.require=function(a){if(!COMPILED){goog.ENABLE_DEBUG_LOADER&&goog.IS_OLD_IE_&&goog.maybeProcessDeferredDep_(a);if(goog.isProvided_(a))return goog.isInModuleLoader_()?goog.module.getInternal_(a):null;if(goog.ENABLE_DEBUG_LOADER){var b=goog.getPathFromDeps_(a);if(b)return goog.writeScripts_(b),null}a="goog.require could not find: "+a;goog.logToConsole_(a);throw Error(a);}};
goog.basePath="";goog.nullFunction=function(){};goog.abstractMethod=function(){throw Error("unimplemented abstract method");};goog.addSingletonGetter=function(a){a.getInstance=function(){if(a.instance_)return a.instance_;goog.DEBUG&&(goog.instantiatedSingletons_[goog.instantiatedSingletons_.length]=a);return a.instance_=new a}};goog.instantiatedSingletons_=[];goog.LOAD_MODULE_USING_EVAL=!0;goog.SEAL_MODULE_EXPORTS=goog.DEBUG;goog.loadedModules_={};goog.DEPENDENCIES_ENABLED=!COMPILED&&goog.ENABLE_DEBUG_LOADER;
goog.DEPENDENCIES_ENABLED&&(goog.dependencies_={pathIsModule:{},nameToPath:{},requires:{},visited:{},written:{},deferred:{}},goog.inHtmlDocument_=function(){var a=goog.global.document;return null!=a&&"write"in a},goog.findBasePath_=function(){if(goog.isDef(goog.global.CLOSURE_BASE_PATH))goog.basePath=goog.global.CLOSURE_BASE_PATH;else if(goog.inHtmlDocument_())for(var a=goog.global.document.getElementsByTagName("SCRIPT"),b=a.length-1;0<=b;--b){var c=a[b].src,d=c.lastIndexOf("?"),d=-1==d?c.length:
d;if("base.js"==c.substr(d-7,7)){goog.basePath=c.substr(0,d-7);break}}},goog.importScript_=function(a,b){(goog.global.CLOSURE_IMPORT_SCRIPT||goog.writeScriptTag_)(a,b)&&(goog.dependencies_.written[a]=!0)},goog.IS_OLD_IE_=!(goog.global.atob||!goog.global.document||!goog.global.document.all),goog.importModule_=function(a){goog.importScript_("",'goog.retrieveAndExecModule_("'+a+'");')&&(goog.dependencies_.written[a]=!0)},goog.queuedModules_=[],goog.wrapModule_=function(a,b){return goog.LOAD_MODULE_USING_EVAL&&
goog.isDef(goog.global.JSON)?"goog.loadModule("+goog.global.JSON.stringify(b+"\n//# sourceURL="+a+"\n")+");":'goog.loadModule(function(exports) {"use strict";'+b+"\n;return exports});\n//# sourceURL="+a+"\n"},goog.loadQueuedModules_=function(){var a=goog.queuedModules_.length;if(0<a){var b=goog.queuedModules_;goog.queuedModules_=[];for(var c=0;c<a;c++)goog.maybeProcessDeferredPath_(b[c])}},goog.maybeProcessDeferredDep_=function(a){goog.isDeferredModule_(a)&&goog.allDepsAreAvailable_(a)&&(a=goog.getPathFromDeps_(a),
goog.maybeProcessDeferredPath_(goog.basePath+a))},goog.isDeferredModule_=function(a){return(a=goog.getPathFromDeps_(a))&&goog.dependencies_.pathIsModule[a]?goog.basePath+a in goog.dependencies_.deferred:!1},goog.allDepsAreAvailable_=function(a){if((a=goog.getPathFromDeps_(a))&&a in goog.dependencies_.requires)for(var b in goog.dependencies_.requires[a])if(!goog.isProvided_(b)&&!goog.isDeferredModule_(b))return!1;return!0},goog.maybeProcessDeferredPath_=function(a){if(a in goog.dependencies_.deferred){var b=
goog.dependencies_.deferred[a];delete goog.dependencies_.deferred[a];goog.globalEval(b)}},goog.loadModuleFromUrl=function(a){goog.retrieveAndExecModule_(a)},goog.loadModule=function(a){var b=goog.moduleLoaderState_;try{goog.moduleLoaderState_={moduleName:void 0,declareLegacyNamespace:!1};var c;if(goog.isFunction(a))c=a.call(goog.global,{});else if(goog.isString(a))c=goog.loadModuleFromSource_.call(goog.global,a);else throw Error("Invalid module definition");var d=goog.moduleLoaderState_.moduleName;
if(!goog.isString(d)||!d)throw Error('Invalid module name "'+d+'"');goog.moduleLoaderState_.declareLegacyNamespace?goog.constructNamespace_(d,c):goog.SEAL_MODULE_EXPORTS&&Object.seal&&Object.seal(c);goog.loadedModules_[d]=c}finally{goog.moduleLoaderState_=b}},goog.loadModuleFromSource_=function(a){eval(a);return{}},goog.writeScriptSrcNode_=function(a){goog.global.document.write('<script type="text/javascript" src="'+a+'">\x3c/script>')},goog.appendScriptSrcNode_=function(a){var b=goog.global.document,
c=b.createElement("script");c.type="text/javascript";c.src=a;c.defer=!1;c.async=!1;b.head.appendChild(c)},goog.writeScriptTag_=function(a,b){if(goog.inHtmlDocument_()){var c=goog.global.document;if(!goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING&&"complete"==c.readyState){if(/\bdeps.js$/.test(a))return!1;throw Error('Cannot write "'+a+'" after document load');}var d=goog.IS_OLD_IE_;void 0===b?d?(d=" onreadystatechange='goog.onScriptLoad_(this, "+ ++goog.lastNonModuleScriptIndex_+")' ",c.write('<script type="text/javascript" src="'+
a+'"'+d+">\x3c/script>")):goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING?goog.appendScriptSrcNode_(a):goog.writeScriptSrcNode_(a):c.write('<script type="text/javascript">'+b+"\x3c/script>");return!0}return!1},goog.lastNonModuleScriptIndex_=0,goog.onScriptLoad_=function(a,b){"complete"==a.readyState&&goog.lastNonModuleScriptIndex_==b&&goog.loadQueuedModules_();return!0},goog.writeScripts_=function(a){function b(a){if(!(a in e.written||a in e.visited)){e.visited[a]=!0;if(a in e.requires)for(var f in e.requires[a])if(!goog.isProvided_(f))if(f in
e.nameToPath)b(e.nameToPath[f]);else throw Error("Undefined nameToPath for "+f);a in d||(d[a]=!0,c.push(a))}}var c=[],d={},e=goog.dependencies_;b(a);for(a=0;a<c.length;a++){var f=c[a];goog.dependencies_.written[f]=!0}var g=goog.moduleLoaderState_;goog.moduleLoaderState_=null;for(a=0;a<c.length;a++)if(f=c[a])e.pathIsModule[f]?goog.importModule_(goog.basePath+f):goog.importScript_(goog.basePath+f);else throw goog.moduleLoaderState_=g,Error("Undefined script input");goog.moduleLoaderState_=g},goog.getPathFromDeps_=
function(a){return a in goog.dependencies_.nameToPath?goog.dependencies_.nameToPath[a]:null},goog.findBasePath_(),goog.global.CLOSURE_NO_DEPS||goog.importScript_(goog.basePath+"deps.js"));goog.normalizePath_=function(a){a=a.split("/");for(var b=0;b<a.length;)"."==a[b]?a.splice(b,1):b&&".."==a[b]&&a[b-1]&&".."!=a[b-1]?a.splice(--b,2):b++;return a.join("/")};
goog.loadFileSync_=function(a){if(goog.global.CLOSURE_LOAD_FILE_SYNC)return goog.global.CLOSURE_LOAD_FILE_SYNC(a);var b=new goog.global.XMLHttpRequest;b.open("get",a,!1);b.send();return b.responseText};
goog.retrieveAndExecModule_=function(a){if(!COMPILED){var b=a;a=goog.normalizePath_(a);var c=goog.global.CLOSURE_IMPORT_SCRIPT||goog.writeScriptTag_,d=goog.loadFileSync_(a);if(null!=d)d=goog.wrapModule_(a,d),goog.IS_OLD_IE_?(goog.dependencies_.deferred[b]=d,goog.queuedModules_.push(b)):c(a,d);else throw Error("load of "+a+"failed");}};
goog.typeOf=function(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null";
else if("function"==b&&"undefined"==typeof a.call)return"object";return b};goog.isNull=function(a){return null===a};goog.isDefAndNotNull=function(a){return null!=a};goog.isArray=function(a){return"array"==goog.typeOf(a)};goog.isArrayLike=function(a){var b=goog.typeOf(a);return"array"==b||"object"==b&&"number"==typeof a.length};goog.isDateLike=function(a){return goog.isObject(a)&&"function"==typeof a.getFullYear};goog.isString=function(a){return"string"==typeof a};
goog.isBoolean=function(a){return"boolean"==typeof a};goog.isNumber=function(a){return"number"==typeof a};goog.isFunction=function(a){return"function"==goog.typeOf(a)};goog.isObject=function(a){var b=typeof a;return"object"==b&&null!=a||"function"==b};goog.getUid=function(a){return a[goog.UID_PROPERTY_]||(a[goog.UID_PROPERTY_]=++goog.uidCounter_)};goog.hasUid=function(a){return!!a[goog.UID_PROPERTY_]};
goog.removeUid=function(a){null!==a&&"removeAttribute"in a&&a.removeAttribute(goog.UID_PROPERTY_);try{delete a[goog.UID_PROPERTY_]}catch(b){}};goog.UID_PROPERTY_="closure_uid_"+(1E9*Math.random()>>>0);goog.uidCounter_=0;goog.getHashCode=goog.getUid;goog.removeHashCode=goog.removeUid;goog.cloneObject=function(a){var b=goog.typeOf(a);if("object"==b||"array"==b){if(a.clone)return a.clone();var b="array"==b?[]:{},c;for(c in a)b[c]=goog.cloneObject(a[c]);return b}return a};
goog.bindNative_=function(a,b,c){return a.call.apply(a.bind,arguments)};goog.bindJs_=function(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}return function(){return a.apply(b,arguments)}};
goog.bind=function(a,b,c){Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?goog.bind=goog.bindNative_:goog.bind=goog.bindJs_;return goog.bind.apply(null,arguments)};goog.partial=function(a,b){var c=Array.prototype.slice.call(arguments,1);return function(){var b=c.slice();b.push.apply(b,arguments);return a.apply(this,b)}};goog.mixin=function(a,b){for(var c in b)a[c]=b[c]};goog.now=goog.TRUSTED_SITE&&Date.now||function(){return+new Date};
goog.globalEval=function(a){if(goog.global.execScript)goog.global.execScript(a,"JavaScript");else if(goog.global.eval){if(null==goog.evalWorksForGlobals_)if(goog.global.eval("var _evalTest_ = 1;"),"undefined"!=typeof goog.global._evalTest_){try{delete goog.global._evalTest_}catch(d){}goog.evalWorksForGlobals_=!0}else goog.evalWorksForGlobals_=!1;if(goog.evalWorksForGlobals_)goog.global.eval(a);else{var b=goog.global.document,c=b.createElement("SCRIPT");c.type="text/javascript";c.defer=!1;c.appendChild(b.createTextNode(a));
b.body.appendChild(c);b.body.removeChild(c)}}else throw Error("goog.globalEval not available");};goog.evalWorksForGlobals_=null;goog.getCssName=function(a,b){var c=function(a){return goog.cssNameMapping_[a]||a},d=function(a){a=a.split("-");for(var b=[],d=0;d<a.length;d++)b.push(c(a[d]));return b.join("-")},d=goog.cssNameMapping_?"BY_WHOLE"==goog.cssNameMappingStyle_?c:d:function(a){return a};return b?a+"-"+d(b):d(a)};
goog.setCssNameMapping=function(a,b){goog.cssNameMapping_=a;goog.cssNameMappingStyle_=b};!COMPILED&&goog.global.CLOSURE_CSS_NAME_MAPPING&&(goog.cssNameMapping_=goog.global.CLOSURE_CSS_NAME_MAPPING);goog.getMsg=function(a,b){b&&(a=a.replace(/\{\$([^}]+)}/g,function(a,d){return null!=b&&d in b?b[d]:a}));return a};goog.getMsgWithFallback=function(a,b){return a};goog.exportSymbol=function(a,b,c){goog.exportPath_(a,b,c)};goog.exportProperty=function(a,b,c){a[b]=c};
goog.inherits=function(a,b){function c(){}c.prototype=b.prototype;a.superClass_=b.prototype;a.prototype=new c;a.prototype.constructor=a;a.base=function(a,c,f){for(var g=Array(arguments.length-2),h=2;h<arguments.length;h++)g[h-2]=arguments[h];return b.prototype[c].apply(a,g)}};
goog.base=function(a,b,c){var d=arguments.callee.caller;if(goog.STRICT_MODE_COMPATIBLE||goog.DEBUG&&!d)throw Error("arguments.caller not defined. goog.base() cannot be used with strict mode code. See http://www.ecma-international.org/ecma-262/5.1/#sec-C");if(d.superClass_){for(var e=Array(arguments.length-1),f=1;f<arguments.length;f++)e[f-1]=arguments[f];return d.superClass_.constructor.apply(a,e)}e=Array(arguments.length-2);for(f=2;f<arguments.length;f++)e[f-2]=arguments[f];for(var f=!1,g=a.constructor;g;g=
g.superClass_&&g.superClass_.constructor)if(g.prototype[b]===d)f=!0;else if(f)return g.prototype[b].apply(a,e);if(a[b]===d)return a.constructor.prototype[b].apply(a,e);throw Error("goog.base called from a method of one name to a method of a different name");};goog.scope=function(a){a.call(goog.global)};COMPILED||(goog.global.COMPILED=COMPILED);
goog.defineClass=function(a,b){var c=b.constructor,d=b.statics;c&&c!=Object.prototype.constructor||(c=function(){throw Error("cannot instantiate an interface (no constructor defined).");});c=goog.defineClass.createSealingConstructor_(c,a);a&&goog.inherits(c,a);delete b.constructor;delete b.statics;goog.defineClass.applyProperties_(c.prototype,b);null!=d&&(d instanceof Function?d(c):goog.defineClass.applyProperties_(c,d));return c};goog.defineClass.SEAL_CLASS_INSTANCES=goog.DEBUG;
goog.defineClass.createSealingConstructor_=function(a,b){if(goog.defineClass.SEAL_CLASS_INSTANCES&&Object.seal instanceof Function){if(b&&b.prototype&&b.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_])return a;var c=function(){var b=a.apply(this,arguments)||this;b[goog.UID_PROPERTY_]=b[goog.UID_PROPERTY_];this.constructor===c&&Object.seal(b);return b};return c}return a};goog.defineClass.OBJECT_PROTOTYPE_FIELDS_="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");
goog.defineClass.applyProperties_=function(a,b){for(var c in b)Object.prototype.hasOwnProperty.call(b,c)&&(a[c]=b[c]);for(var d=0;d<goog.defineClass.OBJECT_PROTOTYPE_FIELDS_.length;d++)c=goog.defineClass.OBJECT_PROTOTYPE_FIELDS_[d],Object.prototype.hasOwnProperty.call(b,c)&&(a[c]=b[c])};goog.tagUnsealableClass=function(a){!COMPILED&&goog.defineClass.SEAL_CLASS_INSTANCES&&(a.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_]=!0)};goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_="goog_defineClass_legacy_unsealable";goog.async={};goog.async.FreeList=function(a,b,c){this.limit_=c;this.create_=a;this.reset_=b;this.occupants_=0;this.head_=null};goog.async.FreeList.prototype.get=function(){var a;0<this.occupants_?(this.occupants_--,a=this.head_,this.head_=a.next,a.next=null):a=this.create_();return a};goog.async.FreeList.prototype.put=function(a){this.reset_(a);this.occupants_<this.limit_&&(this.occupants_++,a.next=this.head_,this.head_=a)};goog.async.FreeList.prototype.occupants=function(){return this.occupants_};goog.debug={};goog.debug.Error=function(a){if(Error.captureStackTrace)Error.captureStackTrace(this,goog.debug.Error);else{var b=Error().stack;b&&(this.stack=b)}a&&(this.message=String(a));this.reportErrorToServer=!0};goog.inherits(goog.debug.Error,Error);goog.debug.Error.prototype.name="CustomError";goog.dom={};goog.dom.NodeType={ELEMENT:1,ATTRIBUTE:2,TEXT:3,CDATA_SECTION:4,ENTITY_REFERENCE:5,ENTITY:6,PROCESSING_INSTRUCTION:7,COMMENT:8,DOCUMENT:9,DOCUMENT_TYPE:10,DOCUMENT_FRAGMENT:11,NOTATION:12};goog.dom.TagName={A:"A",ABBR:"ABBR",ACRONYM:"ACRONYM",ADDRESS:"ADDRESS",APPLET:"APPLET",AREA:"AREA",ARTICLE:"ARTICLE",ASIDE:"ASIDE",AUDIO:"AUDIO",B:"B",BASE:"BASE",BASEFONT:"BASEFONT",BDI:"BDI",BDO:"BDO",BIG:"BIG",BLOCKQUOTE:"BLOCKQUOTE",BODY:"BODY",BR:"BR",BUTTON:"BUTTON",CANVAS:"CANVAS",CAPTION:"CAPTION",CENTER:"CENTER",CITE:"CITE",CODE:"CODE",COL:"COL",COLGROUP:"COLGROUP",COMMAND:"COMMAND",DATA:"DATA",DATALIST:"DATALIST",DD:"DD",DEL:"DEL",DETAILS:"DETAILS",DFN:"DFN",DIALOG:"DIALOG",DIR:"DIR",DIV:"DIV",
DL:"DL",DT:"DT",EM:"EM",EMBED:"EMBED",FIELDSET:"FIELDSET",FIGCAPTION:"FIGCAPTION",FIGURE:"FIGURE",FONT:"FONT",FOOTER:"FOOTER",FORM:"FORM",FRAME:"FRAME",FRAMESET:"FRAMESET",H1:"H1",H2:"H2",H3:"H3",H4:"H4",H5:"H5",H6:"H6",HEAD:"HEAD",HEADER:"HEADER",HGROUP:"HGROUP",HR:"HR",HTML:"HTML",I:"I",IFRAME:"IFRAME",IMG:"IMG",INPUT:"INPUT",INS:"INS",ISINDEX:"ISINDEX",KBD:"KBD",KEYGEN:"KEYGEN",LABEL:"LABEL",LEGEND:"LEGEND",LI:"LI",LINK:"LINK",MAP:"MAP",MARK:"MARK",MATH:"MATH",MENU:"MENU",META:"META",METER:"METER",
NAV:"NAV",NOFRAMES:"NOFRAMES",NOSCRIPT:"NOSCRIPT",OBJECT:"OBJECT",OL:"OL",OPTGROUP:"OPTGROUP",OPTION:"OPTION",OUTPUT:"OUTPUT",P:"P",PARAM:"PARAM",PRE:"PRE",PROGRESS:"PROGRESS",Q:"Q",RP:"RP",RT:"RT",RUBY:"RUBY",S:"S",SAMP:"SAMP",SCRIPT:"SCRIPT",SECTION:"SECTION",SELECT:"SELECT",SMALL:"SMALL",SOURCE:"SOURCE",SPAN:"SPAN",STRIKE:"STRIKE",STRONG:"STRONG",STYLE:"STYLE",SUB:"SUB",SUMMARY:"SUMMARY",SUP:"SUP",SVG:"SVG",TABLE:"TABLE",TBODY:"TBODY",TD:"TD",TEMPLATE:"TEMPLATE",TEXTAREA:"TEXTAREA",TFOOT:"TFOOT",
TH:"TH",THEAD:"THEAD",TIME:"TIME",TITLE:"TITLE",TR:"TR",TRACK:"TRACK",TT:"TT",U:"U",UL:"UL",VAR:"VAR",VIDEO:"VIDEO",WBR:"WBR"};goog.functions={};goog.functions.constant=function(a){return function(){return a}};goog.functions.FALSE=goog.functions.constant(!1);goog.functions.TRUE=goog.functions.constant(!0);goog.functions.NULL=goog.functions.constant(null);goog.functions.identity=function(a,b){return a};goog.functions.error=function(a){return function(){throw Error(a);}};goog.functions.fail=function(a){return function(){throw a;}};
goog.functions.lock=function(a,b){b=b||0;return function(){return a.apply(this,Array.prototype.slice.call(arguments,0,b))}};goog.functions.nth=function(a){return function(){return arguments[a]}};goog.functions.withReturnValue=function(a,b){return goog.functions.sequence(a,goog.functions.constant(b))};goog.functions.equalTo=function(a,b){return function(c){return b?a==c:a===c}};
goog.functions.compose=function(a,b){var c=arguments,d=c.length;return function(){var a;d&&(a=c[d-1].apply(this,arguments));for(var b=d-2;0<=b;b--)a=c[b].call(this,a);return a}};goog.functions.sequence=function(a){var b=arguments,c=b.length;return function(){for(var a,e=0;e<c;e++)a=b[e].apply(this,arguments);return a}};goog.functions.and=function(a){var b=arguments,c=b.length;return function(){for(var a=0;a<c;a++)if(!b[a].apply(this,arguments))return!1;return!0}};
goog.functions.or=function(a){var b=arguments,c=b.length;return function(){for(var a=0;a<c;a++)if(b[a].apply(this,arguments))return!0;return!1}};goog.functions.not=function(a){return function(){return!a.apply(this,arguments)}};goog.functions.create=function(a,b){var c=function(){};c.prototype=a.prototype;c=new c;a.apply(c,Array.prototype.slice.call(arguments,1));return c};goog.functions.CACHE_RETURN_VALUE=!0;
goog.functions.cacheReturnValue=function(a){var b=!1,c;return function(){if(!goog.functions.CACHE_RETURN_VALUE)return a();b||(c=a(),b=!0);return c}};goog.functions.once=function(a){var b=a;return function(){if(b){var a=b;b=null;a()}}};goog.functions.debounce=function(a,b,c){c&&(a=goog.bind(a,c));var d=null;return function(c){goog.global.clearTimeout(d);var f=arguments;d=goog.global.setTimeout(function(){a.apply(null,f)},b)}};
goog.functions.throttle=function(a,b,c){c&&(a=goog.bind(a,c));var d=null,e=!1,f=[],g=function(){d=null;e&&(e=!1,h())},h=function(){d=goog.global.setTimeout(g,b);a.apply(null,f)};return function(a){f=arguments;d?e=!0:h()}};goog.object={};goog.object.forEach=function(a,b,c){for(var d in a)b.call(c,a[d],d,a)};goog.object.filter=function(a,b,c){var d={},e;for(e in a)b.call(c,a[e],e,a)&&(d[e]=a[e]);return d};goog.object.map=function(a,b,c){var d={},e;for(e in a)d[e]=b.call(c,a[e],e,a);return d};goog.object.some=function(a,b,c){for(var d in a)if(b.call(c,a[d],d,a))return!0;return!1};goog.object.every=function(a,b,c){for(var d in a)if(!b.call(c,a[d],d,a))return!1;return!0};
goog.object.getCount=function(a){var b=0,c;for(c in a)b++;return b};goog.object.getAnyKey=function(a){for(var b in a)return b};goog.object.getAnyValue=function(a){for(var b in a)return a[b]};goog.object.contains=function(a,b){return goog.object.containsValue(a,b)};goog.object.getValues=function(a){var b=[],c=0,d;for(d in a)b[c++]=a[d];return b};goog.object.getKeys=function(a){var b=[],c=0,d;for(d in a)b[c++]=d;return b};
goog.object.getValueByKeys=function(a,b){for(var c=goog.isArrayLike(b),d=c?b:arguments,c=c?0:1;c<d.length&&(a=a[d[c]],goog.isDef(a));c++);return a};goog.object.containsKey=function(a,b){return null!==a&&b in a};goog.object.containsValue=function(a,b){for(var c in a)if(a[c]==b)return!0;return!1};goog.object.findKey=function(a,b,c){for(var d in a)if(b.call(c,a[d],d,a))return d};goog.object.findValue=function(a,b,c){return(b=goog.object.findKey(a,b,c))&&a[b]};
goog.object.isEmpty=function(a){for(var b in a)return!1;return!0};goog.object.clear=function(a){for(var b in a)delete a[b]};goog.object.remove=function(a,b){var c;(c=b in a)&&delete a[b];return c};goog.object.add=function(a,b,c){if(null!==a&&b in a)throw Error('The object already contains the key "'+b+'"');goog.object.set(a,b,c)};goog.object.get=function(a,b,c){return null!==a&&b in a?a[b]:c};goog.object.set=function(a,b,c){a[b]=c};
goog.object.setIfUndefined=function(a,b,c){return b in a?a[b]:a[b]=c};goog.object.setWithReturnValueIfNotSet=function(a,b,c){if(b in a)return a[b];c=c();return a[b]=c};goog.object.equals=function(a,b){for(var c in a)if(!(c in b)||a[c]!==b[c])return!1;for(c in b)if(!(c in a))return!1;return!0};goog.object.clone=function(a){var b={},c;for(c in a)b[c]=a[c];return b};
goog.object.unsafeClone=function(a){var b=goog.typeOf(a);if("object"==b||"array"==b){if(goog.isFunction(a.clone))return a.clone();var b="array"==b?[]:{},c;for(c in a)b[c]=goog.object.unsafeClone(a[c]);return b}return a};goog.object.transpose=function(a){var b={},c;for(c in a)b[a[c]]=c;return b};goog.object.PROTOTYPE_FIELDS_="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");
goog.object.extend=function(a,b){for(var c,d,e=1;e<arguments.length;e++){d=arguments[e];for(c in d)a[c]=d[c];for(var f=0;f<goog.object.PROTOTYPE_FIELDS_.length;f++)c=goog.object.PROTOTYPE_FIELDS_[f],Object.prototype.hasOwnProperty.call(d,c)&&(a[c]=d[c])}};
goog.object.create=function(a){var b=arguments.length;if(1==b&&goog.isArray(arguments[0]))return goog.object.create.apply(null,arguments[0]);if(b%2)throw Error("Uneven number of arguments");for(var c={},d=0;d<b;d+=2)c[arguments[d]]=arguments[d+1];return c};goog.object.createSet=function(a){var b=arguments.length;if(1==b&&goog.isArray(arguments[0]))return goog.object.createSet.apply(null,arguments[0]);for(var c={},d=0;d<b;d++)c[arguments[d]]=!0;return c};
goog.object.createImmutableView=function(a){var b=a;Object.isFrozen&&!Object.isFrozen(a)&&(b=Object.create(a),Object.freeze(b));return b};goog.object.isImmutableView=function(a){return!!Object.isFrozen&&Object.isFrozen(a)};goog.promise={};goog.promise.Resolver=function(){};goog.Thenable=function(){};goog.Thenable.prototype.then=function(a,b,c){};goog.Thenable.IMPLEMENTED_BY_PROP="$goog_Thenable";goog.Thenable.addImplementation=function(a){goog.exportProperty(a.prototype,"then",a.prototype.then);COMPILED?a.prototype[goog.Thenable.IMPLEMENTED_BY_PROP]=!0:a.prototype.$goog_Thenable=!0};goog.Thenable.isImplementedBy=function(a){if(!a)return!1;try{return COMPILED?!!a[goog.Thenable.IMPLEMENTED_BY_PROP]:!!a.$goog_Thenable}catch(b){return!1}};goog.string={};goog.string.DETECT_DOUBLE_ESCAPING=!1;goog.string.FORCE_NON_DOM_HTML_UNESCAPING=!1;goog.string.Unicode={NBSP:"\u00a0"};goog.string.startsWith=function(a,b){return 0==a.lastIndexOf(b,0)};goog.string.endsWith=function(a,b){var c=a.length-b.length;return 0<=c&&a.indexOf(b,c)==c};goog.string.caseInsensitiveStartsWith=function(a,b){return 0==goog.string.caseInsensitiveCompare(b,a.substr(0,b.length))};
goog.string.caseInsensitiveEndsWith=function(a,b){return 0==goog.string.caseInsensitiveCompare(b,a.substr(a.length-b.length,b.length))};goog.string.caseInsensitiveEquals=function(a,b){return a.toLowerCase()==b.toLowerCase()};goog.string.subs=function(a,b){for(var c=a.split("%s"),d="",e=Array.prototype.slice.call(arguments,1);e.length&&1<c.length;)d+=c.shift()+e.shift();return d+c.join("%s")};goog.string.collapseWhitespace=function(a){return a.replace(/[\s\xa0]+/g," ").replace(/^\s+|\s+$/g,"")};
goog.string.isEmptyOrWhitespace=function(a){return/^[\s\xa0]*$/.test(a)};goog.string.isEmptyString=function(a){return 0==a.length};goog.string.isEmpty=goog.string.isEmptyOrWhitespace;goog.string.isEmptyOrWhitespaceSafe=function(a){return goog.string.isEmptyOrWhitespace(goog.string.makeSafe(a))};goog.string.isEmptySafe=goog.string.isEmptyOrWhitespaceSafe;goog.string.isBreakingWhitespace=function(a){return!/[^\t\n\r ]/.test(a)};goog.string.isAlpha=function(a){return!/[^a-zA-Z]/.test(a)};
goog.string.isNumeric=function(a){return!/[^0-9]/.test(a)};goog.string.isAlphaNumeric=function(a){return!/[^a-zA-Z0-9]/.test(a)};goog.string.isSpace=function(a){return" "==a};goog.string.isUnicodeChar=function(a){return 1==a.length&&" "<=a&&"~">=a||"\u0080"<=a&&"\ufffd">=a};goog.string.stripNewlines=function(a){return a.replace(/(\r\n|\r|\n)+/g," ")};goog.string.canonicalizeNewlines=function(a){return a.replace(/(\r\n|\r|\n)/g,"\n")};
goog.string.normalizeWhitespace=function(a){return a.replace(/\xa0|\s/g," ")};goog.string.normalizeSpaces=function(a){return a.replace(/\xa0|[ \t]+/g," ")};goog.string.collapseBreakingSpaces=function(a){return a.replace(/[\t\r\n ]+/g," ").replace(/^[\t\r\n ]+|[\t\r\n ]+$/g,"")};goog.string.trim=goog.TRUSTED_SITE&&String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(/^[\s\xa0]+|[\s\xa0]+$/g,"")};goog.string.trimLeft=function(a){return a.replace(/^[\s\xa0]+/,"")};
goog.string.trimRight=function(a){return a.replace(/[\s\xa0]+$/,"")};goog.string.caseInsensitiveCompare=function(a,b){var c=String(a).toLowerCase(),d=String(b).toLowerCase();return c<d?-1:c==d?0:1};
goog.string.numberAwareCompare_=function(a,b,c){if(a==b)return 0;if(!a)return-1;if(!b)return 1;for(var d=a.toLowerCase().match(c),e=b.toLowerCase().match(c),f=Math.min(d.length,e.length),g=0;g<f;g++){c=d[g];var h=e[g];if(c!=h)return a=parseInt(c,10),!isNaN(a)&&(b=parseInt(h,10),!isNaN(b)&&a-b)?a-b:c<h?-1:1}return d.length!=e.length?d.length-e.length:a<b?-1:1};goog.string.intAwareCompare=function(a,b){return goog.string.numberAwareCompare_(a,b,/\d+|\D+/g)};
goog.string.floatAwareCompare=function(a,b){return goog.string.numberAwareCompare_(a,b,/\d+|\.\d+|\D+/g)};goog.string.numerateCompare=goog.string.floatAwareCompare;goog.string.urlEncode=function(a){return encodeURIComponent(String(a))};goog.string.urlDecode=function(a){return decodeURIComponent(a.replace(/\+/g," "))};goog.string.newLineToBr=function(a,b){return a.replace(/(\r\n|\r|\n)/g,b?"<br />":"<br>")};
goog.string.htmlEscape=function(a,b){if(b)a=a.replace(goog.string.AMP_RE_,"&").replace(goog.string.LT_RE_,"<").replace(goog.string.GT_RE_,">").replace(goog.string.QUOT_RE_,""").replace(goog.string.SINGLE_QUOTE_RE_,"'").replace(goog.string.NULL_RE_,"�"),goog.string.DETECT_DOUBLE_ESCAPING&&(a=a.replace(goog.string.E_RE_,"e"));else{if(!goog.string.ALL_RE_.test(a))return a;-1!=a.indexOf("&")&&(a=a.replace(goog.string.AMP_RE_,"&"));-1!=a.indexOf("<")&&(a=a.replace(goog.string.LT_RE_,
"<"));-1!=a.indexOf(">")&&(a=a.replace(goog.string.GT_RE_,">"));-1!=a.indexOf('"')&&(a=a.replace(goog.string.QUOT_RE_,"""));-1!=a.indexOf("'")&&(a=a.replace(goog.string.SINGLE_QUOTE_RE_,"'"));-1!=a.indexOf("\x00")&&(a=a.replace(goog.string.NULL_RE_,"�"));goog.string.DETECT_DOUBLE_ESCAPING&&-1!=a.indexOf("e")&&(a=a.replace(goog.string.E_RE_,"e"))}return a};goog.string.AMP_RE_=/&/g;goog.string.LT_RE_=/</g;goog.string.GT_RE_=/>/g;goog.string.QUOT_RE_=/"/g;
goog.string.SINGLE_QUOTE_RE_=/'/g;goog.string.NULL_RE_=/\x00/g;goog.string.E_RE_=/e/g;goog.string.ALL_RE_=goog.string.DETECT_DOUBLE_ESCAPING?/[\x00&<>"'e]/:/[\x00&<>"']/;goog.string.unescapeEntities=function(a){return goog.string.contains(a,"&")?!goog.string.FORCE_NON_DOM_HTML_UNESCAPING&&"document"in goog.global?goog.string.unescapeEntitiesUsingDom_(a):goog.string.unescapePureXmlEntities_(a):a};
goog.string.unescapeEntitiesWithDocument=function(a,b){return goog.string.contains(a,"&")?goog.string.unescapeEntitiesUsingDom_(a,b):a};
goog.string.unescapeEntitiesUsingDom_=function(a,b){var c={"&":"&","<":"<",">":">",""":'"'},d;d=b?b.createElement("div"):goog.global.document.createElement("div");return a.replace(goog.string.HTML_ENTITY_PATTERN_,function(a,b){var g=c[a];if(g)return g;if("#"==b.charAt(0)){var h=Number("0"+b.substr(1));isNaN(h)||(g=String.fromCharCode(h))}g||(d.innerHTML=a+" ",g=d.firstChild.nodeValue.slice(0,-1));return c[a]=g})};
goog.string.unescapePureXmlEntities_=function(a){return a.replace(/&([^;]+);/g,function(a,c){switch(c){case "amp":return"&";case "lt":return"<";case "gt":return">";case "quot":return'"';default:if("#"==c.charAt(0)){var d=Number("0"+c.substr(1));if(!isNaN(d))return String.fromCharCode(d)}return a}})};goog.string.HTML_ENTITY_PATTERN_=/&([^;\s<&]+);?/g;goog.string.whitespaceEscape=function(a,b){return goog.string.newLineToBr(a.replace(/ /g,"  "),b)};
goog.string.preserveSpaces=function(a){return a.replace(/(^|[\n ]) /g,"$1"+goog.string.Unicode.NBSP)};goog.string.stripQuotes=function(a,b){for(var c=b.length,d=0;d<c;d++){var e=1==c?b:b.charAt(d);if(a.charAt(0)==e&&a.charAt(a.length-1)==e)return a.substring(1,a.length-1)}return a};goog.string.truncate=function(a,b,c){c&&(a=goog.string.unescapeEntities(a));a.length>b&&(a=a.substring(0,b-3)+"...");c&&(a=goog.string.htmlEscape(a));return a};
goog.string.truncateMiddle=function(a,b,c,d){c&&(a=goog.string.unescapeEntities(a));if(d&&a.length>b){d>b&&(d=b);var e=a.length-d;a=a.substring(0,b-d)+"..."+a.substring(e)}else a.length>b&&(d=Math.floor(b/2),e=a.length-d,a=a.substring(0,d+b%2)+"..."+a.substring(e));c&&(a=goog.string.htmlEscape(a));return a};goog.string.specialEscapeChars_={"\x00":"\\0","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\x0B":"\\x0B",'"':'\\"',"\\":"\\\\","<":"<"};goog.string.jsEscapeCache_={"'":"\\'"};
goog.string.quote=function(a){a=String(a);for(var b=['"'],c=0;c<a.length;c++){var d=a.charAt(c),e=d.charCodeAt(0);b[c+1]=goog.string.specialEscapeChars_[d]||(31<e&&127>e?d:goog.string.escapeChar(d))}b.push('"');return b.join("")};goog.string.escapeString=function(a){for(var b=[],c=0;c<a.length;c++)b[c]=goog.string.escapeChar(a.charAt(c));return b.join("")};
goog.string.escapeChar=function(a){if(a in goog.string.jsEscapeCache_)return goog.string.jsEscapeCache_[a];if(a in goog.string.specialEscapeChars_)return goog.string.jsEscapeCache_[a]=goog.string.specialEscapeChars_[a];var b=a,c=a.charCodeAt(0);if(31<c&&127>c)b=a;else{if(256>c){if(b="\\x",16>c||256<c)b+="0"}else b="\\u",4096>c&&(b+="0");b+=c.toString(16).toUpperCase()}return goog.string.jsEscapeCache_[a]=b};goog.string.contains=function(a,b){return-1!=a.indexOf(b)};
goog.string.caseInsensitiveContains=function(a,b){return goog.string.contains(a.toLowerCase(),b.toLowerCase())};goog.string.countOf=function(a,b){return a&&b?a.split(b).length-1:0};goog.string.removeAt=function(a,b,c){var d=a;0<=b&&b<a.length&&0<c&&(d=a.substr(0,b)+a.substr(b+c,a.length-b-c));return d};goog.string.remove=function(a,b){var c=new RegExp(goog.string.regExpEscape(b),"");return a.replace(c,"")};
goog.string.removeAll=function(a,b){var c=new RegExp(goog.string.regExpEscape(b),"g");return a.replace(c,"")};goog.string.regExpEscape=function(a){return String(a).replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1").replace(/\x08/g,"\\x08")};goog.string.repeat=String.prototype.repeat?function(a,b){return a.repeat(b)}:function(a,b){return Array(b+1).join(a)};
goog.string.padNumber=function(a,b,c){a=goog.isDef(c)?a.toFixed(c):String(a);c=a.indexOf(".");-1==c&&(c=a.length);return goog.string.repeat("0",Math.max(0,b-c))+a};goog.string.makeSafe=function(a){return null==a?"":String(a)};goog.string.buildString=function(a){return Array.prototype.join.call(arguments,"")};goog.string.getRandomString=function(){return Math.floor(2147483648*Math.random()).toString(36)+Math.abs(Math.floor(2147483648*Math.random())^goog.now()).toString(36)};
goog.string.compareVersions=function(a,b){for(var c=0,d=goog.string.trim(String(a)).split("."),e=goog.string.trim(String(b)).split("."),f=Math.max(d.length,e.length),g=0;0==c&&g<f;g++){var h=d[g]||"",k=e[g]||"",n=/(\d*)(\D*)/g,l=/(\d*)(\D*)/g;do{var m=n.exec(h)||["","",""],p=l.exec(k)||["","",""];if(0==m[0].length&&0==p[0].length)break;var c=0==m[1].length?0:parseInt(m[1],10),q=0==p[1].length?0:parseInt(p[1],10),c=goog.string.compareElements_(c,q)||goog.string.compareElements_(0==m[2].length,0==p[2].length)||
goog.string.compareElements_(m[2],p[2])}while(0==c)}return c};goog.string.compareElements_=function(a,b){return a<b?-1:a>b?1:0};goog.string.hashCode=function(a){for(var b=0,c=0;c<a.length;++c)b=31*b+a.charCodeAt(c)>>>0;return b};goog.string.uniqueStringCounter_=2147483648*Math.random()|0;goog.string.createUniqueString=function(){return"goog_"+goog.string.uniqueStringCounter_++};goog.string.toNumber=function(a){var b=Number(a);return 0==b&&goog.string.isEmptyOrWhitespace(a)?NaN:b};
goog.string.isLowerCamelCase=function(a){return/^[a-z]+([A-Z][a-z]*)*$/.test(a)};goog.string.isUpperCamelCase=function(a){return/^([A-Z][a-z]*)+$/.test(a)};goog.string.toCamelCase=function(a){return String(a).replace(/\-([a-z])/g,function(a,c){return c.toUpperCase()})};goog.string.toSelectorCase=function(a){return String(a).replace(/([A-Z])/g,"-$1").toLowerCase()};
goog.string.toTitleCase=function(a,b){var c=goog.isString(b)?goog.string.regExpEscape(b):"\\s";return a.replace(new RegExp("(^"+(c?"|["+c+"]+":"")+")([a-z])","g"),function(a,b,c){return b+c.toUpperCase()})};goog.string.capitalize=function(a){return String(a.charAt(0)).toUpperCase()+String(a.substr(1)).toLowerCase()};goog.string.parseInt=function(a){isFinite(a)&&(a=String(a));return goog.isString(a)?/^\s*-?0x/i.test(a)?parseInt(a,16):parseInt(a,10):NaN};
goog.string.splitLimit=function(a,b,c){a=a.split(b);for(var d=[];0<c&&a.length;)d.push(a.shift()),c--;a.length&&d.push(a.join(b));return d};goog.string.editDistance=function(a,b){var c=[],d=[];if(a==b)return 0;if(!a.length||!b.length)return Math.max(a.length,b.length);for(var e=0;e<b.length+1;e++)c[e]=e;for(e=0;e<a.length;e++){d[0]=e+1;for(var f=0;f<b.length;f++)d[f+1]=Math.min(d[f]+1,c[f+1]+1,c[f]+(a[e]!=b[f]));for(f=0;f<c.length;f++)c[f]=d[f]}return d[b.length]};goog.asserts={};goog.asserts.ENABLE_ASSERTS=goog.DEBUG;goog.asserts.AssertionError=function(a,b){b.unshift(a);goog.debug.Error.call(this,goog.string.subs.apply(null,b));b.shift();this.messagePattern=a};goog.inherits(goog.asserts.AssertionError,goog.debug.Error);goog.asserts.AssertionError.prototype.name="AssertionError";goog.asserts.DEFAULT_ERROR_HANDLER=function(a){throw a;};goog.asserts.errorHandler_=goog.asserts.DEFAULT_ERROR_HANDLER;
goog.asserts.doAssertFailure_=function(a,b,c,d){var e="Assertion failed";if(c)var e=e+(": "+c),f=d;else a&&(e+=": "+a,f=b);a=new goog.asserts.AssertionError(""+e,f||[]);goog.asserts.errorHandler_(a)};goog.asserts.setErrorHandler=function(a){goog.asserts.ENABLE_ASSERTS&&(goog.asserts.errorHandler_=a)};goog.asserts.assert=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!a&&goog.asserts.doAssertFailure_("",null,b,Array.prototype.slice.call(arguments,2));return a};
goog.asserts.fail=function(a,b){goog.asserts.ENABLE_ASSERTS&&goog.asserts.errorHandler_(new goog.asserts.AssertionError("Failure"+(a?": "+a:""),Array.prototype.slice.call(arguments,1)))};goog.asserts.assertNumber=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isNumber(a)&&goog.asserts.doAssertFailure_("Expected number but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};
goog.asserts.assertString=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isString(a)&&goog.asserts.doAssertFailure_("Expected string but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};goog.asserts.assertFunction=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isFunction(a)&&goog.asserts.doAssertFailure_("Expected function but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};
goog.asserts.assertObject=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isObject(a)&&goog.asserts.doAssertFailure_("Expected object but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};goog.asserts.assertArray=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isArray(a)&&goog.asserts.doAssertFailure_("Expected array but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};
goog.asserts.assertBoolean=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isBoolean(a)&&goog.asserts.doAssertFailure_("Expected boolean but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};goog.asserts.assertElement=function(a,b,c){!goog.asserts.ENABLE_ASSERTS||goog.isObject(a)&&a.nodeType==goog.dom.NodeType.ELEMENT||goog.asserts.doAssertFailure_("Expected Element but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};
goog.asserts.assertInstanceof=function(a,b,c,d){!goog.asserts.ENABLE_ASSERTS||a instanceof b||goog.asserts.doAssertFailure_("Expected instanceof %s but got %s.",[goog.asserts.getType_(b),goog.asserts.getType_(a)],c,Array.prototype.slice.call(arguments,3));return a};goog.asserts.assertObjectPrototypeIsIntact=function(){for(var a in Object.prototype)goog.asserts.fail(a+" should not be enumerable in Object.prototype.")};
goog.asserts.getType_=function(a){return a instanceof Function?a.displayName||a.name||"unknown type name":a instanceof Object?a.constructor.displayName||a.constructor.name||Object.prototype.toString.call(a):null===a?"null":typeof a};goog.array={};goog.NATIVE_ARRAY_PROTOTYPES=goog.TRUSTED_SITE;goog.array.ASSUME_NATIVE_FUNCTIONS=!1;goog.array.peek=function(a){return a[a.length-1]};goog.array.last=goog.array.peek;
goog.array.indexOf=goog.NATIVE_ARRAY_PROTOTYPES&&(goog.array.ASSUME_NATIVE_FUNCTIONS||Array.prototype.indexOf)?function(a,b,c){goog.asserts.assert(null!=a.length);return Array.prototype.indexOf.call(a,b,c)}:function(a,b,c){c=null==c?0:0>c?Math.max(0,a.length+c):c;if(goog.isString(a))return goog.isString(b)&&1==b.length?a.indexOf(b,c):-1;for(;c<a.length;c++)if(c in a&&a[c]===b)return c;return-1};
goog.array.lastIndexOf=goog.NATIVE_ARRAY_PROTOTYPES&&(goog.array.ASSUME_NATIVE_FUNCTIONS||Array.prototype.lastIndexOf)?function(a,b,c){goog.asserts.assert(null!=a.length);return Array.prototype.lastIndexOf.call(a,b,null==c?a.length-1:c)}:function(a,b,c){c=null==c?a.length-1:c;0>c&&(c=Math.max(0,a.length+c));if(goog.isString(a))return goog.isString(b)&&1==b.length?a.lastIndexOf(b,c):-1;for(;0<=c;c--)if(c in a&&a[c]===b)return c;return-1};
goog.array.forEach=goog.NATIVE_ARRAY_PROTOTYPES&&(goog.array.ASSUME_NATIVE_FUNCTIONS||Array.prototype.forEach)?function(a,b,c){goog.asserts.assert(null!=a.length);Array.prototype.forEach.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=goog.isString(a)?a.split(""):a,f=0;f<d;f++)f in e&&b.call(c,e[f],f,a)};goog.array.forEachRight=function(a,b,c){for(var d=a.length,e=goog.isString(a)?a.split(""):a,d=d-1;0<=d;--d)d in e&&b.call(c,e[d],d,a)};
goog.array.filter=goog.NATIVE_ARRAY_PROTOTYPES&&(goog.array.ASSUME_NATIVE_FUNCTIONS||Array.prototype.filter)?function(a,b,c){goog.asserts.assert(null!=a.length);return Array.prototype.filter.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=[],f=0,g=goog.isString(a)?a.split(""):a,h=0;h<d;h++)if(h in g){var k=g[h];b.call(c,k,h,a)&&(e[f++]=k)}return e};
goog.array.map=goog.NATIVE_ARRAY_PROTOTYPES&&(goog.array.ASSUME_NATIVE_FUNCTIONS||Array.prototype.map)?function(a,b,c){goog.asserts.assert(null!=a.length);return Array.prototype.map.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=Array(d),f=goog.isString(a)?a.split(""):a,g=0;g<d;g++)g in f&&(e[g]=b.call(c,f[g],g,a));return e};
goog.array.reduce=goog.NATIVE_ARRAY_PROTOTYPES&&(goog.array.ASSUME_NATIVE_FUNCTIONS||Array.prototype.reduce)?function(a,b,c,d){goog.asserts.assert(null!=a.length);d&&(b=goog.bind(b,d));return Array.prototype.reduce.call(a,b,c)}:function(a,b,c,d){var e=c;goog.array.forEach(a,function(c,g){e=b.call(d,e,c,g,a)});return e};
goog.array.reduceRight=goog.NATIVE_ARRAY_PROTOTYPES&&(goog.array.ASSUME_NATIVE_FUNCTIONS||Array.prototype.reduceRight)?function(a,b,c,d){goog.asserts.assert(null!=a.length);goog.asserts.assert(null!=b);d&&(b=goog.bind(b,d));return Array.prototype.reduceRight.call(a,b,c)}:function(a,b,c,d){var e=c;goog.array.forEachRight(a,function(c,g){e=b.call(d,e,c,g,a)});return e};
goog.array.some=goog.NATIVE_ARRAY_PROTOTYPES&&(goog.array.ASSUME_NATIVE_FUNCTIONS||Array.prototype.some)?function(a,b,c){goog.asserts.assert(null!=a.length);return Array.prototype.some.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=goog.isString(a)?a.split(""):a,f=0;f<d;f++)if(f in e&&b.call(c,e[f],f,a))return!0;return!1};
goog.array.every=goog.NATIVE_ARRAY_PROTOTYPES&&(goog.array.ASSUME_NATIVE_FUNCTIONS||Array.prototype.every)?function(a,b,c){goog.asserts.assert(null!=a.length);return Array.prototype.every.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=goog.isString(a)?a.split(""):a,f=0;f<d;f++)if(f in e&&!b.call(c,e[f],f,a))return!1;return!0};goog.array.count=function(a,b,c){var d=0;goog.array.forEach(a,function(a,f,g){b.call(c,a,f,g)&&++d},c);return d};
goog.array.find=function(a,b,c){b=goog.array.findIndex(a,b,c);return 0>b?null:goog.isString(a)?a.charAt(b):a[b]};goog.array.findIndex=function(a,b,c){for(var d=a.length,e=goog.isString(a)?a.split(""):a,f=0;f<d;f++)if(f in e&&b.call(c,e[f],f,a))return f;return-1};goog.array.findRight=function(a,b,c){b=goog.array.findIndexRight(a,b,c);return 0>b?null:goog.isString(a)?a.charAt(b):a[b]};
goog.array.findIndexRight=function(a,b,c){for(var d=a.length,e=goog.isString(a)?a.split(""):a,d=d-1;0<=d;d--)if(d in e&&b.call(c,e[d],d,a))return d;return-1};goog.array.contains=function(a,b){return 0<=goog.array.indexOf(a,b)};goog.array.isEmpty=function(a){return 0==a.length};goog.array.clear=function(a){if(!goog.isArray(a))for(var b=a.length-1;0<=b;b--)delete a[b];a.length=0};goog.array.insert=function(a,b){goog.array.contains(a,b)||a.push(b)};
goog.array.insertAt=function(a,b,c){goog.array.splice(a,c,0,b)};goog.array.insertArrayAt=function(a,b,c){goog.partial(goog.array.splice,a,c,0).apply(null,b)};goog.array.insertBefore=function(a,b,c){var d;2==arguments.length||0>(d=goog.array.indexOf(a,c))?a.push(b):goog.array.insertAt(a,b,d)};goog.array.remove=function(a,b){var c=goog.array.indexOf(a,b),d;(d=0<=c)&&goog.array.removeAt(a,c);return d};
goog.array.removeAt=function(a,b){goog.asserts.assert(null!=a.length);return 1==Array.prototype.splice.call(a,b,1).length};goog.array.removeIf=function(a,b,c){b=goog.array.findIndex(a,b,c);return 0<=b?(goog.array.removeAt(a,b),!0):!1};goog.array.removeAllIf=function(a,b,c){var d=0;goog.array.forEachRight(a,function(e,f){b.call(c,e,f,a)&&goog.array.removeAt(a,f)&&d++});return d};goog.array.concat=function(a){return Array.prototype.concat.apply(Array.prototype,arguments)};
goog.array.join=function(a){return Array.prototype.concat.apply(Array.prototype,arguments)};goog.array.toArray=function(a){var b=a.length;if(0<b){for(var c=Array(b),d=0;d<b;d++)c[d]=a[d];return c}return[]};goog.array.clone=goog.array.toArray;goog.array.extend=function(a,b){for(var c=1;c<arguments.length;c++){var d=arguments[c];if(goog.isArrayLike(d)){var e=a.length||0,f=d.length||0;a.length=e+f;for(var g=0;g<f;g++)a[e+g]=d[g]}else a.push(d)}};
goog.array.splice=function(a,b,c,d){goog.asserts.assert(null!=a.length);return Array.prototype.splice.apply(a,goog.array.slice(arguments,1))};goog.array.slice=function(a,b,c){goog.asserts.assert(null!=a.length);return 2>=arguments.length?Array.prototype.slice.call(a,b):Array.prototype.slice.call(a,b,c)};
goog.array.removeDuplicates=function(a,b,c){b=b||a;var d=function(a){return goog.isObject(a)?"o"+goog.getUid(a):(typeof a).charAt(0)+a};c=c||d;for(var d={},e=0,f=0;f<a.length;){var g=a[f++],h=c(g);Object.prototype.hasOwnProperty.call(d,h)||(d[h]=!0,b[e++]=g)}b.length=e};goog.array.binarySearch=function(a,b,c){return goog.array.binarySearch_(a,c||goog.array.defaultCompare,!1,b)};goog.array.binarySelect=function(a,b,c){return goog.array.binarySearch_(a,b,!0,void 0,c)};
goog.array.binarySearch_=function(a,b,c,d,e){for(var f=0,g=a.length,h;f<g;){var k=f+g>>1,n;n=c?b.call(e,a[k],k,a):b(d,a[k]);0<n?f=k+1:(g=k,h=!n)}return h?f:~f};goog.array.sort=function(a,b){a.sort(b||goog.array.defaultCompare)};goog.array.stableSort=function(a,b){for(var c=0;c<a.length;c++)a[c]={index:c,value:a[c]};var d=b||goog.array.defaultCompare;goog.array.sort(a,function(a,b){return d(a.value,b.value)||a.index-b.index});for(c=0;c<a.length;c++)a[c]=a[c].value};
goog.array.sortByKey=function(a,b,c){var d=c||goog.array.defaultCompare;goog.array.sort(a,function(a,c){return d(b(a),b(c))})};goog.array.sortObjectsByKey=function(a,b,c){goog.array.sortByKey(a,function(a){return a[b]},c)};goog.array.isSorted=function(a,b,c){b=b||goog.array.defaultCompare;for(var d=1;d<a.length;d++){var e=b(a[d-1],a[d]);if(0<e||0==e&&c)return!1}return!0};
goog.array.equals=function(a,b,c){if(!goog.isArrayLike(a)||!goog.isArrayLike(b)||a.length!=b.length)return!1;var d=a.length;c=c||goog.array.defaultCompareEquality;for(var e=0;e<d;e++)if(!c(a[e],b[e]))return!1;return!0};goog.array.compare3=function(a,b,c){c=c||goog.array.defaultCompare;for(var d=Math.min(a.length,b.length),e=0;e<d;e++){var f=c(a[e],b[e]);if(0!=f)return f}return goog.array.defaultCompare(a.length,b.length)};goog.array.defaultCompare=function(a,b){return a>b?1:a<b?-1:0};
goog.array.inverseDefaultCompare=function(a,b){return-goog.array.defaultCompare(a,b)};goog.array.defaultCompareEquality=function(a,b){return a===b};goog.array.binaryInsert=function(a,b,c){c=goog.array.binarySearch(a,b,c);return 0>c?(goog.array.insertAt(a,b,-(c+1)),!0):!1};goog.array.binaryRemove=function(a,b,c){b=goog.array.binarySearch(a,b,c);return 0<=b?goog.array.removeAt(a,b):!1};
goog.array.bucket=function(a,b,c){for(var d={},e=0;e<a.length;e++){var f=a[e],g=b.call(c,f,e,a);goog.isDef(g)&&(d[g]||(d[g]=[])).push(f)}return d};goog.array.toObject=function(a,b,c){var d={};goog.array.forEach(a,function(e,f){d[b.call(c,e,f,a)]=e});return d};goog.array.range=function(a,b,c){var d=[],e=0,f=a;c=c||1;void 0!==b&&(e=a,f=b);if(0>c*(f-e))return[];if(0<c)for(a=e;a<f;a+=c)d.push(a);else for(a=e;a>f;a+=c)d.push(a);return d};
goog.array.repeat=function(a,b){for(var c=[],d=0;d<b;d++)c[d]=a;return c};goog.array.flatten=function(a){for(var b=[],c=0;c<arguments.length;c++){var d=arguments[c];if(goog.isArray(d))for(var e=0;e<d.length;e+=8192)for(var f=goog.array.slice(d,e,e+8192),f=goog.array.flatten.apply(null,f),g=0;g<f.length;g++)b.push(f[g]);else b.push(d)}return b};
goog.array.rotate=function(a,b){goog.asserts.assert(null!=a.length);a.length&&(b%=a.length,0<b?Array.prototype.unshift.apply(a,a.splice(-b,b)):0>b&&Array.prototype.push.apply(a,a.splice(0,-b)));return a};goog.array.moveItem=function(a,b,c){goog.asserts.assert(0<=b&&b<a.length);goog.asserts.assert(0<=c&&c<a.length);b=Array.prototype.splice.call(a,b,1);Array.prototype.splice.call(a,c,0,b[0])};
goog.array.zip=function(a){if(!arguments.length)return[];for(var b=[],c=arguments[0].length,d=1;d<arguments.length;d++)arguments[d].length<c&&(c=arguments[d].length);for(d=0;d<c;d++){for(var e=[],f=0;f<arguments.length;f++)e.push(arguments[f][d]);b.push(e)}return b};goog.array.shuffle=function(a,b){for(var c=b||Math.random,d=a.length-1;0<d;d--){var e=Math.floor(c()*(d+1)),f=a[d];a[d]=a[e];a[e]=f}};goog.array.copyByIndex=function(a,b){var c=[];goog.array.forEach(b,function(b){c.push(a[b])});return c};goog.async.WorkQueue=function(){this.workTail_=this.workHead_=null};goog.async.WorkQueue.DEFAULT_MAX_UNUSED=100;goog.async.WorkQueue.freelist_=new goog.async.FreeList(function(){return new goog.async.WorkItem},function(a){a.reset()},goog.async.WorkQueue.DEFAULT_MAX_UNUSED);goog.async.WorkQueue.prototype.add=function(a,b){var c=this.getUnusedItem_();c.set(a,b);this.workTail_?this.workTail_.next=c:(goog.asserts.assert(!this.workHead_),this.workHead_=c);this.workTail_=c};
goog.async.WorkQueue.prototype.remove=function(){var a=null;this.workHead_&&(a=this.workHead_,this.workHead_=this.workHead_.next,this.workHead_||(this.workTail_=null),a.next=null);return a};goog.async.WorkQueue.prototype.returnUnused=function(a){goog.async.WorkQueue.freelist_.put(a)};goog.async.WorkQueue.prototype.getUnusedItem_=function(){return goog.async.WorkQueue.freelist_.get()};goog.async.WorkItem=function(){this.next=this.scope=this.fn=null};
goog.async.WorkItem.prototype.set=function(a,b){this.fn=a;this.scope=b;this.next=null};goog.async.WorkItem.prototype.reset=function(){this.next=this.scope=this.fn=null};goog.debug.entryPointRegistry={};goog.debug.EntryPointMonitor=function(){};goog.debug.entryPointRegistry.refList_=[];goog.debug.entryPointRegistry.monitors_=[];goog.debug.entryPointRegistry.monitorsMayExist_=!1;goog.debug.entryPointRegistry.register=function(a){goog.debug.entryPointRegistry.refList_[goog.debug.entryPointRegistry.refList_.length]=a;if(goog.debug.entryPointRegistry.monitorsMayExist_)for(var b=goog.debug.entryPointRegistry.monitors_,c=0;c<b.length;c++)a(goog.bind(b[c].wrap,b[c]))};
goog.debug.entryPointRegistry.monitorAll=function(a){goog.debug.entryPointRegistry.monitorsMayExist_=!0;for(var b=goog.bind(a.wrap,a),c=0;c<goog.debug.entryPointRegistry.refList_.length;c++)goog.debug.entryPointRegistry.refList_[c](b);goog.debug.entryPointRegistry.monitors_.push(a)};
goog.debug.entryPointRegistry.unmonitorAllIfPossible=function(a){var b=goog.debug.entryPointRegistry.monitors_;goog.asserts.assert(a==b[b.length-1],"Only the most recent monitor can be unwrapped.");a=goog.bind(a.unwrap,a);for(var c=0;c<goog.debug.entryPointRegistry.refList_.length;c++)goog.debug.entryPointRegistry.refList_[c](a);b.length--};goog.labs={};goog.labs.userAgent={};goog.labs.userAgent.util={};goog.labs.userAgent.util.getNativeUserAgentString_=function(){var a=goog.labs.userAgent.util.getNavigator_();return a&&(a=a.userAgent)?a:""};goog.labs.userAgent.util.getNavigator_=function(){return goog.global.navigator};goog.labs.userAgent.util.userAgent_=goog.labs.userAgent.util.getNativeUserAgentString_();goog.labs.userAgent.util.setUserAgent=function(a){goog.labs.userAgent.util.userAgent_=a||goog.labs.userAgent.util.getNativeUserAgentString_()};
goog.labs.userAgent.util.getUserAgent=function(){return goog.labs.userAgent.util.userAgent_};goog.labs.userAgent.util.matchUserAgent=function(a){var b=goog.labs.userAgent.util.getUserAgent();return goog.string.contains(b,a)};goog.labs.userAgent.util.matchUserAgentIgnoreCase=function(a){var b=goog.labs.userAgent.util.getUserAgent();return goog.string.caseInsensitiveContains(b,a)};
goog.labs.userAgent.util.extractVersionTuples=function(a){for(var b=/(\w[\w ]+)\/([^\s]+)\s*(?:\((.*?)\))?/g,c=[],d;d=b.exec(a);)c.push([d[1],d[2],d[3]||void 0]);return c};goog.labs.userAgent.browser={};goog.labs.userAgent.browser.matchOpera_=function(){return goog.labs.userAgent.util.matchUserAgent("Opera")||goog.labs.userAgent.util.matchUserAgent("OPR")};goog.labs.userAgent.browser.matchIE_=function(){return goog.labs.userAgent.util.matchUserAgent("Trident")||goog.labs.userAgent.util.matchUserAgent("MSIE")};goog.labs.userAgent.browser.matchEdge_=function(){return goog.labs.userAgent.util.matchUserAgent("Edge")};goog.labs.userAgent.browser.matchFirefox_=function(){return goog.labs.userAgent.util.matchUserAgent("Firefox")};
goog.labs.userAgent.browser.matchSafari_=function(){return goog.labs.userAgent.util.matchUserAgent("Safari")&&!(goog.labs.userAgent.browser.matchChrome_()||goog.labs.userAgent.browser.matchCoast_()||goog.labs.userAgent.browser.matchOpera_()||goog.labs.userAgent.browser.matchEdge_()||goog.labs.userAgent.browser.isSilk()||goog.labs.userAgent.util.matchUserAgent("Android"))};goog.labs.userAgent.browser.matchCoast_=function(){return goog.labs.userAgent.util.matchUserAgent("Coast")};
goog.labs.userAgent.browser.matchIosWebview_=function(){return(goog.labs.userAgent.util.matchUserAgent("iPad")||goog.labs.userAgent.util.matchUserAgent("iPhone"))&&!goog.labs.userAgent.browser.matchSafari_()&&!goog.labs.userAgent.browser.matchChrome_()&&!goog.labs.userAgent.browser.matchCoast_()&&goog.labs.userAgent.util.matchUserAgent("AppleWebKit")};
goog.labs.userAgent.browser.matchChrome_=function(){return(goog.labs.userAgent.util.matchUserAgent("Chrome")||goog.labs.userAgent.util.matchUserAgent("CriOS"))&&!goog.labs.userAgent.browser.matchOpera_()&&!goog.labs.userAgent.browser.matchEdge_()};goog.labs.userAgent.browser.matchAndroidBrowser_=function(){return goog.labs.userAgent.util.matchUserAgent("Android")&&!(goog.labs.userAgent.browser.isChrome()||goog.labs.userAgent.browser.isFirefox()||goog.labs.userAgent.browser.isOpera()||goog.labs.userAgent.browser.isSilk())};
goog.labs.userAgent.browser.isOpera=goog.labs.userAgent.browser.matchOpera_;goog.labs.userAgent.browser.isIE=goog.labs.userAgent.browser.matchIE_;goog.labs.userAgent.browser.isEdge=goog.labs.userAgent.browser.matchEdge_;goog.labs.userAgent.browser.isFirefox=goog.labs.userAgent.browser.matchFirefox_;goog.labs.userAgent.browser.isSafari=goog.labs.userAgent.browser.matchSafari_;goog.labs.userAgent.browser.isCoast=goog.labs.userAgent.browser.matchCoast_;goog.labs.userAgent.browser.isIosWebview=goog.labs.userAgent.browser.matchIosWebview_;
goog.labs.userAgent.browser.isChrome=goog.labs.userAgent.browser.matchChrome_;goog.labs.userAgent.browser.isAndroidBrowser=goog.labs.userAgent.browser.matchAndroidBrowser_;goog.labs.userAgent.browser.isSilk=function(){return goog.labs.userAgent.util.matchUserAgent("Silk")};
goog.labs.userAgent.browser.getVersion=function(){function a(a){a=goog.array.find(a,d);return c[a]||""}var b=goog.labs.userAgent.util.getUserAgent();if(goog.labs.userAgent.browser.isIE())return goog.labs.userAgent.browser.getIEVersion_(b);var b=goog.labs.userAgent.util.extractVersionTuples(b),c={};goog.array.forEach(b,function(a){c[a[0]]=a[1]});var d=goog.partial(goog.object.containsKey,c);return goog.labs.userAgent.browser.isOpera()?a(["Version","Opera","OPR"]):goog.labs.userAgent.browser.isEdge()?
a(["Edge"]):goog.labs.userAgent.browser.isChrome()?a(["Chrome","CriOS"]):(b=b[2])&&b[1]||""};goog.labs.userAgent.browser.isVersionOrHigher=function(a){return 0<=goog.string.compareVersions(goog.labs.userAgent.browser.getVersion(),a)};
goog.labs.userAgent.browser.getIEVersion_=function(a){var b=/rv: *([\d\.]*)/.exec(a);if(b&&b[1])return b[1];var b="",c=/MSIE +([\d\.]+)/.exec(a);if(c&&c[1])if(a=/Trident\/(\d.\d)/.exec(a),"7.0"==c[1])if(a&&a[1])switch(a[1]){case "4.0":b="8.0";break;case "5.0":b="9.0";break;case "6.0":b="10.0";break;case "7.0":b="11.0"}else b="7.0";else b=c[1];return b};goog.labs.userAgent.engine={};goog.labs.userAgent.engine.isPresto=function(){return goog.labs.userAgent.util.matchUserAgent("Presto")};goog.labs.userAgent.engine.isTrident=function(){return goog.labs.userAgent.util.matchUserAgent("Trident")||goog.labs.userAgent.util.matchUserAgent("MSIE")};goog.labs.userAgent.engine.isEdge=function(){return goog.labs.userAgent.util.matchUserAgent("Edge")};
goog.labs.userAgent.engine.isWebKit=function(){return goog.labs.userAgent.util.matchUserAgentIgnoreCase("WebKit")&&!goog.labs.userAgent.engine.isEdge()};goog.labs.userAgent.engine.isGecko=function(){return goog.labs.userAgent.util.matchUserAgent("Gecko")&&!goog.labs.userAgent.engine.isWebKit()&&!goog.labs.userAgent.engine.isTrident()&&!goog.labs.userAgent.engine.isEdge()};
goog.labs.userAgent.engine.getVersion=function(){var a=goog.labs.userAgent.util.getUserAgent();if(a){var a=goog.labs.userAgent.util.extractVersionTuples(a),b=goog.labs.userAgent.engine.getEngineTuple_(a);if(b)return"Gecko"==b[0]?goog.labs.userAgent.engine.getVersionForKey_(a,"Firefox"):b[1];var a=a[0],c;if(a&&(c=a[2])&&(c=/Trident\/([^\s;]+)/.exec(c)))return c[1]}return""};
goog.labs.userAgent.engine.getEngineTuple_=function(a){if(!goog.labs.userAgent.engine.isEdge())return a[1];for(var b=0;b<a.length;b++){var c=a[b];if("Edge"==c[0])return c}};goog.labs.userAgent.engine.isVersionOrHigher=function(a){return 0<=goog.string.compareVersions(goog.labs.userAgent.engine.getVersion(),a)};goog.labs.userAgent.engine.getVersionForKey_=function(a,b){var c=goog.array.find(a,function(a){return b==a[0]});return c&&c[1]||""};goog.async.throwException=function(a){goog.global.setTimeout(function(){throw a;},0)};goog.async.nextTick=function(a,b,c){var d=a;b&&(d=goog.bind(a,b));d=goog.async.nextTick.wrapCallback_(d);goog.isFunction(goog.global.setImmediate)&&(c||goog.async.nextTick.useSetImmediate_())?goog.global.setImmediate(d):(goog.async.nextTick.setImmediate_||(goog.async.nextTick.setImmediate_=goog.async.nextTick.getSetImmediateEmulator_()),goog.async.nextTick.setImmediate_(d))};
goog.async.nextTick.useSetImmediate_=function(){return goog.global.Window&&goog.global.Window.prototype&&!goog.labs.userAgent.browser.isEdge()&&goog.global.Window.prototype.setImmediate==goog.global.setImmediate?!1:!0};
goog.async.nextTick.getSetImmediateEmulator_=function(){var a=goog.global.MessageChannel;"undefined"===typeof a&&"undefined"!==typeof window&&window.postMessage&&window.addEventListener&&!goog.labs.userAgent.engine.isPresto()&&(a=function(){var a=document.createElement(goog.dom.TagName.IFRAME);a.style.display="none";a.src="";document.documentElement.appendChild(a);var b=a.contentWindow,a=b.document;a.open();a.write("");a.close();var c="callImmediate"+Math.random(),d="file:"==b.location.protocol?"*":
b.location.protocol+"//"+b.location.host,a=goog.bind(function(a){if(("*"==d||a.origin==d)&&a.data==c)this.port1.onmessage()},this);b.addEventListener("message",a,!1);this.port1={};this.port2={postMessage:function(){b.postMessage(c,d)}}});if("undefined"!==typeof a&&!goog.labs.userAgent.browser.isIE()){var b=new a,c={},d=c;b.port1.onmessage=function(){if(goog.isDef(c.next)){c=c.next;var a=c.cb;c.cb=null;a()}};return function(a){d.next={cb:a};d=d.next;b.port2.postMessage(0)}}return"undefined"!==typeof document&&
"onreadystatechange"in document.createElement(goog.dom.TagName.SCRIPT)?function(a){var b=document.createElement(goog.dom.TagName.SCRIPT);b.onreadystatechange=function(){b.onreadystatechange=null;b.parentNode.removeChild(b);b=null;a();a=null};document.documentElement.appendChild(b)}:function(a){goog.global.setTimeout(a,0)}};goog.async.nextTick.wrapCallback_=goog.functions.identity;goog.debug.entryPointRegistry.register(function(a){goog.async.nextTick.wrapCallback_=a});goog.async.run=function(a,b){goog.async.run.schedule_||goog.async.run.initializeRunner_();goog.async.run.workQueueScheduled_||(goog.async.run.schedule_(),goog.async.run.workQueueScheduled_=!0);goog.async.run.workQueue_.add(a,b)};goog.async.run.initializeRunner_=function(){if(goog.global.Promise&&goog.global.Promise.resolve){var a=goog.global.Promise.resolve(void 0);goog.async.run.schedule_=function(){a.then(goog.async.run.processWorkQueue)}}else goog.async.run.schedule_=function(){goog.async.nextTick(goog.async.run.processWorkQueue)}};
goog.async.run.forceNextTick=function(a){goog.async.run.schedule_=function(){goog.async.nextTick(goog.async.run.processWorkQueue);a&&a(goog.async.run.processWorkQueue)}};goog.async.run.workQueueScheduled_=!1;goog.async.run.workQueue_=new goog.async.WorkQueue;goog.DEBUG&&(goog.async.run.resetQueue=function(){goog.async.run.workQueueScheduled_=!1;goog.async.run.workQueue_=new goog.async.WorkQueue});
goog.async.run.processWorkQueue=function(){for(var a=null;a=goog.async.run.workQueue_.remove();){try{a.fn.call(a.scope)}catch(b){goog.async.throwException(b)}goog.async.run.workQueue_.returnUnused(a)}goog.async.run.workQueueScheduled_=!1};goog.labs.userAgent.platform={};goog.labs.userAgent.platform.isAndroid=function(){return goog.labs.userAgent.util.matchUserAgent("Android")};goog.labs.userAgent.platform.isIpod=function(){return goog.labs.userAgent.util.matchUserAgent("iPod")};goog.labs.userAgent.platform.isIphone=function(){return goog.labs.userAgent.util.matchUserAgent("iPhone")&&!goog.labs.userAgent.util.matchUserAgent("iPod")&&!goog.labs.userAgent.util.matchUserAgent("iPad")};goog.labs.userAgent.platform.isIpad=function(){return goog.labs.userAgent.util.matchUserAgent("iPad")};
goog.labs.userAgent.platform.isIos=function(){return goog.labs.userAgent.platform.isIphone()||goog.labs.userAgent.platform.isIpad()||goog.labs.userAgent.platform.isIpod()};goog.labs.userAgent.platform.isMacintosh=function(){return goog.labs.userAgent.util.matchUserAgent("Macintosh")};goog.labs.userAgent.platform.isLinux=function(){return goog.labs.userAgent.util.matchUserAgent("Linux")};goog.labs.userAgent.platform.isWindows=function(){return goog.labs.userAgent.util.matchUserAgent("Windows")};
goog.labs.userAgent.platform.isChromeOS=function(){return goog.labs.userAgent.util.matchUserAgent("CrOS")};
goog.labs.userAgent.platform.getVersion=function(){var a=goog.labs.userAgent.util.getUserAgent(),b="";goog.labs.userAgent.platform.isWindows()?(b=/Windows (?:NT|Phone) ([0-9.]+)/,b=(a=b.exec(a))?a[1]:"0.0"):goog.labs.userAgent.platform.isIos()?(b=/(?:iPhone|iPod|iPad|CPU)\s+OS\s+(\S+)/,b=(a=b.exec(a))&&a[1].replace(/_/g,".")):goog.labs.userAgent.platform.isMacintosh()?(b=/Mac OS X ([0-9_.]+)/,b=(a=b.exec(a))?a[1].replace(/_/g,"."):"10"):goog.labs.userAgent.platform.isAndroid()?(b=/Android\s+([^\);]+)(\)|;)/,
b=(a=b.exec(a))&&a[1]):goog.labs.userAgent.platform.isChromeOS()&&(b=/(?:CrOS\s+(?:i686|x86_64)\s+([0-9.]+))/,b=(a=b.exec(a))&&a[1]);return b||""};goog.labs.userAgent.platform.isVersionOrHigher=function(a){return 0<=goog.string.compareVersions(goog.labs.userAgent.platform.getVersion(),a)};goog.math={};goog.math.randomInt=function(a){return Math.floor(Math.random()*a)};goog.math.uniformRandom=function(a,b){return a+Math.random()*(b-a)};goog.math.clamp=function(a,b,c){return Math.min(Math.max(a,b),c)};goog.math.modulo=function(a,b){var c=a%b;return 0>c*b?c+b:c};goog.math.lerp=function(a,b,c){return a+c*(b-a)};goog.math.nearlyEquals=function(a,b,c){return Math.abs(a-b)<=(c||1E-6)};goog.math.standardAngle=function(a){return goog.math.modulo(a,360)};
goog.math.standardAngleInRadians=function(a){return goog.math.modulo(a,2*Math.PI)};goog.math.toRadians=function(a){return a*Math.PI/180};goog.math.toDegrees=function(a){return 180*a/Math.PI};goog.math.angleDx=function(a,b){return b*Math.cos(goog.math.toRadians(a))};goog.math.angleDy=function(a,b){return b*Math.sin(goog.math.toRadians(a))};goog.math.angle=function(a,b,c,d){return goog.math.standardAngle(goog.math.toDegrees(Math.atan2(d-b,c-a)))};
goog.math.angleDifference=function(a,b){var c=goog.math.standardAngle(b)-goog.math.standardAngle(a);180<c?c-=360:-180>=c&&(c=360+c);return c};goog.math.sign=Math.sign||function(a){return 0<a?1:0>a?-1:a};
goog.math.longestCommonSubsequence=function(a,b,c,d){c=c||function(a,b){return a==b};d=d||function(b,c){return a[b]};for(var e=a.length,f=b.length,g=[],h=0;h<e+1;h++)g[h]=[],g[h][0]=0;for(var k=0;k<f+1;k++)g[0][k]=0;for(h=1;h<=e;h++)for(k=1;k<=f;k++)c(a[h-1],b[k-1])?g[h][k]=g[h-1][k-1]+1:g[h][k]=Math.max(g[h-1][k],g[h][k-1]);for(var n=[],h=e,k=f;0<h&&0<k;)c(a[h-1],b[k-1])?(n.unshift(d(h-1,k-1)),h--,k--):g[h-1][k]>g[h][k-1]?h--:k--;return n};
goog.math.sum=function(a){return goog.array.reduce(arguments,function(a,c){return a+c},0)};goog.math.average=function(a){return goog.math.sum.apply(null,arguments)/arguments.length};goog.math.sampleVariance=function(a){var b=arguments.length;if(2>b)return 0;var c=goog.math.average.apply(null,arguments);return goog.math.sum.apply(null,goog.array.map(arguments,function(a){return Math.pow(a-c,2)}))/(b-1)};goog.math.standardDeviation=function(a){return Math.sqrt(goog.math.sampleVariance.apply(null,arguments))};
goog.math.isInt=function(a){return isFinite(a)&&0==a%1};goog.math.isFiniteNumber=function(a){return isFinite(a)&&!isNaN(a)};goog.math.isNegativeZero=function(a){return 0==a&&0>1/a};goog.math.log10Floor=function(a){if(0<a){var b=Math.round(Math.log(a)*Math.LOG10E);return b-(parseFloat("1e"+b)>a?1:0)}return 0==a?-Infinity:NaN};goog.math.safeFloor=function(a,b){goog.asserts.assert(!goog.isDef(b)||0<b);return Math.floor(a+(b||2E-15))};
goog.math.safeCeil=function(a,b){goog.asserts.assert(!goog.isDef(b)||0<b);return Math.ceil(a-(b||2E-15))};goog.iter={};goog.iter.StopIteration="StopIteration"in goog.global?goog.global.StopIteration:{message:"StopIteration",stack:""};goog.iter.Iterator=function(){};goog.iter.Iterator.prototype.next=function(){throw goog.iter.StopIteration;};goog.iter.Iterator.prototype.__iterator__=function(a){return this};
goog.iter.toIterator=function(a){if(a instanceof goog.iter.Iterator)return a;if("function"==typeof a.__iterator__)return a.__iterator__(!1);if(goog.isArrayLike(a)){var b=0,c=new goog.iter.Iterator;c.next=function(){for(;;){if(b>=a.length)throw goog.iter.StopIteration;if(b in a)return a[b++];b++}};return c}throw Error("Not implemented");};
goog.iter.forEach=function(a,b,c){if(goog.isArrayLike(a))try{goog.array.forEach(a,b,c)}catch(d){if(d!==goog.iter.StopIteration)throw d;}else{a=goog.iter.toIterator(a);try{for(;;)b.call(c,a.next(),void 0,a)}catch(d){if(d!==goog.iter.StopIteration)throw d;}}};goog.iter.filter=function(a,b,c){var d=goog.iter.toIterator(a);a=new goog.iter.Iterator;a.next=function(){for(;;){var a=d.next();if(b.call(c,a,void 0,d))return a}};return a};
goog.iter.filterFalse=function(a,b,c){return goog.iter.filter(a,goog.functions.not(b),c)};goog.iter.range=function(a,b,c){var d=0,e=a,f=c||1;1<arguments.length&&(d=a,e=b);if(0==f)throw Error("Range step argument must not be zero");var g=new goog.iter.Iterator;g.next=function(){if(0<f&&d>=e||0>f&&d<=e)throw goog.iter.StopIteration;var a=d;d+=f;return a};return g};goog.iter.join=function(a,b){return goog.iter.toArray(a).join(b)};
goog.iter.map=function(a,b,c){var d=goog.iter.toIterator(a);a=new goog.iter.Iterator;a.next=function(){var a=d.next();return b.call(c,a,void 0,d)};return a};goog.iter.reduce=function(a,b,c,d){var e=c;goog.iter.forEach(a,function(a){e=b.call(d,e,a)});return e};goog.iter.some=function(a,b,c){a=goog.iter.toIterator(a);try{for(;;)if(b.call(c,a.next(),void 0,a))return!0}catch(d){if(d!==goog.iter.StopIteration)throw d;}return!1};
goog.iter.every=function(a,b,c){a=goog.iter.toIterator(a);try{for(;;)if(!b.call(c,a.next(),void 0,a))return!1}catch(d){if(d!==goog.iter.StopIteration)throw d;}return!0};goog.iter.chain=function(a){return goog.iter.chainFromIterable(arguments)};
goog.iter.chainFromIterable=function(a){var b=goog.iter.toIterator(a);a=new goog.iter.Iterator;var c=null;a.next=function(){for(;;){if(null==c){var a=b.next();c=goog.iter.toIterator(a)}try{return c.next()}catch(e){if(e!==goog.iter.StopIteration)throw e;c=null}}};return a};goog.iter.dropWhile=function(a,b,c){var d=goog.iter.toIterator(a);a=new goog.iter.Iterator;var e=!0;a.next=function(){for(;;){var a=d.next();if(!e||!b.call(c,a,void 0,d))return e=!1,a}};return a};
goog.iter.takeWhile=function(a,b,c){var d=goog.iter.toIterator(a);a=new goog.iter.Iterator;a.next=function(){var a=d.next();if(b.call(c,a,void 0,d))return a;throw goog.iter.StopIteration;};return a};goog.iter.toArray=function(a){if(goog.isArrayLike(a))return goog.array.toArray(a);a=goog.iter.toIterator(a);var b=[];goog.iter.forEach(a,function(a){b.push(a)});return b};
goog.iter.equals=function(a,b,c){a=goog.iter.zipLongest({},a,b);var d=c||goog.array.defaultCompareEquality;return goog.iter.every(a,function(a){return d(a[0],a[1])})};goog.iter.nextOrValue=function(a,b){try{return goog.iter.toIterator(a).next()}catch(c){if(c!=goog.iter.StopIteration)throw c;return b}};
goog.iter.product=function(a){if(goog.array.some(arguments,function(a){return!a.length})||!arguments.length)return new goog.iter.Iterator;var b=new goog.iter.Iterator,c=arguments,d=goog.array.repeat(0,c.length);b.next=function(){if(d){for(var a=goog.array.map(d,function(a,b){return c[b][a]}),b=d.length-1;0<=b;b--){goog.asserts.assert(d);if(d[b]<c[b].length-1){d[b]++;break}if(0==b){d=null;break}d[b]=0}return a}throw goog.iter.StopIteration;};return b};
goog.iter.cycle=function(a){var b=goog.iter.toIterator(a),c=[],d=0;a=new goog.iter.Iterator;var e=!1;a.next=function(){var a=null;if(!e)try{return a=b.next(),c.push(a),a}catch(g){if(g!=goog.iter.StopIteration||goog.array.isEmpty(c))throw g;e=!0}a=c[d];d=(d+1)%c.length;return a};return a};goog.iter.count=function(a,b){var c=a||0,d=goog.isDef(b)?b:1,e=new goog.iter.Iterator;e.next=function(){var a=c;c+=d;return a};return e};
goog.iter.repeat=function(a){var b=new goog.iter.Iterator;b.next=goog.functions.constant(a);return b};goog.iter.accumulate=function(a){var b=goog.iter.toIterator(a),c=0;a=new goog.iter.Iterator;a.next=function(){return c+=b.next()};return a};goog.iter.zip=function(a){var b=arguments,c=new goog.iter.Iterator;if(0<b.length){var d=goog.array.map(b,goog.iter.toIterator);c.next=function(){return goog.array.map(d,function(a){return a.next()})}}return c};
goog.iter.zipLongest=function(a,b){var c=goog.array.slice(arguments,1),d=new goog.iter.Iterator;if(0<c.length){var e=goog.array.map(c,goog.iter.toIterator);d.next=function(){var b=!1,c=goog.array.map(e,function(c){var d;try{d=c.next(),b=!0}catch(e){if(e!==goog.iter.StopIteration)throw e;d=a}return d});if(!b)throw goog.iter.StopIteration;return c}}return d};goog.iter.compress=function(a,b){var c=goog.iter.toIterator(b);return goog.iter.filter(a,function(){return!!c.next()})};
goog.iter.GroupByIterator_=function(a,b){this.iterator=goog.iter.toIterator(a);this.keyFunc=b||goog.functions.identity};goog.inherits(goog.iter.GroupByIterator_,goog.iter.Iterator);goog.iter.GroupByIterator_.prototype.next=function(){for(;this.currentKey==this.targetKey;)this.currentValue=this.iterator.next(),this.currentKey=this.keyFunc(this.currentValue);this.targetKey=this.currentKey;return[this.currentKey,this.groupItems_(this.targetKey)]};
goog.iter.GroupByIterator_.prototype.groupItems_=function(a){for(var b=[];this.currentKey==a;){b.push(this.currentValue);try{this.currentValue=this.iterator.next()}catch(c){if(c!==goog.iter.StopIteration)throw c;break}this.currentKey=this.keyFunc(this.currentValue)}return b};goog.iter.groupBy=function(a,b){return new goog.iter.GroupByIterator_(a,b)};
goog.iter.starMap=function(a,b,c){var d=goog.iter.toIterator(a);a=new goog.iter.Iterator;a.next=function(){var a=goog.iter.toArray(d.next());return b.apply(c,goog.array.concat(a,void 0,d))};return a};
goog.iter.tee=function(a,b){var c=goog.iter.toIterator(a),d=goog.isNumber(b)?b:2,e=goog.array.map(goog.array.range(d),function(){return[]}),f=function(){var a=c.next();goog.array.forEach(e,function(b){b.push(a)})};return goog.array.map(e,function(a){var b=new goog.iter.Iterator;b.next=function(){goog.array.isEmpty(a)&&f();goog.asserts.assert(!goog.array.isEmpty(a));return a.shift()};return b})};goog.iter.enumerate=function(a,b){return goog.iter.zip(goog.iter.count(b),a)};
goog.iter.limit=function(a,b){goog.asserts.assert(goog.math.isInt(b)&&0<=b);var c=goog.iter.toIterator(a),d=new goog.iter.Iterator,e=b;d.next=function(){if(0<e--)return c.next();throw goog.iter.StopIteration;};return d};goog.iter.consume=function(a,b){goog.asserts.assert(goog.math.isInt(b)&&0<=b);for(var c=goog.iter.toIterator(a);0<b--;)goog.iter.nextOrValue(c,null);return c};
goog.iter.slice=function(a,b,c){goog.asserts.assert(goog.math.isInt(b)&&0<=b);a=goog.iter.consume(a,b);goog.isNumber(c)&&(goog.asserts.assert(goog.math.isInt(c)&&c>=b),a=goog.iter.limit(a,c-b));return a};goog.iter.hasDuplicates_=function(a){var b=[];goog.array.removeDuplicates(a,b);return a.length!=b.length};goog.iter.permutations=function(a,b){var c=goog.iter.toArray(a),d=goog.isNumber(b)?b:c.length,c=goog.array.repeat(c,d),c=goog.iter.product.apply(void 0,c);return goog.iter.filter(c,function(a){return!goog.iter.hasDuplicates_(a)})};
goog.iter.combinations=function(a,b){function c(a){return d[a]}var d=goog.iter.toArray(a),e=goog.iter.range(d.length),e=goog.iter.permutations(e,b),f=goog.iter.filter(e,function(a){return goog.array.isSorted(a)}),e=new goog.iter.Iterator;e.next=function(){return goog.array.map(f.next(),c)};return e};
goog.iter.combinationsWithReplacement=function(a,b){function c(a){return d[a]}var d=goog.iter.toArray(a),e=goog.array.range(d.length),e=goog.array.repeat(e,b),e=goog.iter.product.apply(void 0,e),f=goog.iter.filter(e,function(a){return goog.array.isSorted(a)}),e=new goog.iter.Iterator;e.next=function(){return goog.array.map(f.next(),c)};return e};goog.Promise=function(a,b){this.state_=goog.Promise.State_.PENDING;this.result_=void 0;this.callbackEntriesTail_=this.callbackEntries_=this.parent_=null;this.executing_=!1;0<goog.Promise.UNHANDLED_REJECTION_DELAY?this.unhandledRejectionId_=0:0==goog.Promise.UNHANDLED_REJECTION_DELAY&&(this.hadUnhandledRejection_=!1);goog.Promise.LONG_STACK_TRACES&&(this.stack_=[],this.addStackTrace_(Error("created")),this.currentStep_=0);if(a!=goog.nullFunction)try{var c=this;a.call(b,function(a){c.resolve_(goog.Promise.State_.FULFILLED,
a)},function(a){if(goog.DEBUG&&!(a instanceof goog.Promise.CancellationError))try{if(a instanceof Error)throw a;throw Error("Promise rejected.");}catch(b){}c.resolve_(goog.Promise.State_.REJECTED,a)})}catch(d){this.resolve_(goog.Promise.State_.REJECTED,d)}};goog.Promise.LONG_STACK_TRACES=!1;goog.Promise.UNHANDLED_REJECTION_DELAY=0;goog.Promise.State_={PENDING:0,BLOCKED:1,FULFILLED:2,REJECTED:3};
goog.Promise.CallbackEntry_=function(){this.next=this.context=this.onRejected=this.onFulfilled=this.child=null;this.always=!1};goog.Promise.CallbackEntry_.prototype.reset=function(){this.context=this.onRejected=this.onFulfilled=this.child=null;this.always=!1};goog.Promise.DEFAULT_MAX_UNUSED=100;goog.Promise.freelist_=new goog.async.FreeList(function(){return new goog.Promise.CallbackEntry_},function(a){a.reset()},goog.Promise.DEFAULT_MAX_UNUSED);
goog.Promise.getCallbackEntry_=function(a,b,c){var d=goog.Promise.freelist_.get();d.onFulfilled=a;d.onRejected=b;d.context=c;return d};goog.Promise.returnEntry_=function(a){goog.Promise.freelist_.put(a)};goog.Promise.resolve=function(a){if(a instanceof goog.Promise)return a;var b=new goog.Promise(goog.nullFunction);b.resolve_(goog.Promise.State_.FULFILLED,a);return b};goog.Promise.reject=function(a){return new goog.Promise(function(b,c){c(a)})};
goog.Promise.resolveThen_=function(a,b,c){goog.Promise.maybeThen_(a,b,c,null)||goog.async.run(goog.partial(b,a))};goog.Promise.race=function(a){return new goog.Promise(function(b,c){a.length||b(void 0);for(var d=0,e;d<a.length;d++)e=a[d],goog.Promise.resolveThen_(e,b,c)})};
goog.Promise.all=function(a){return new goog.Promise(function(b,c){var d=a.length,e=[];if(d)for(var f=function(a,c){d--;e[a]=c;0==d&&b(e)},g=function(a){c(a)},h=0,k;h<a.length;h++)k=a[h],goog.Promise.resolveThen_(k,goog.partial(f,h),g);else b(e)})};
goog.Promise.allSettled=function(a){return new goog.Promise(function(b,c){var d=a.length,e=[];if(d)for(var f=function(a,c,f){d--;e[a]=c?{fulfilled:!0,value:f}:{fulfilled:!1,reason:f};0==d&&b(e)},g=0,h;g<a.length;g++)h=a[g],goog.Promise.resolveThen_(h,goog.partial(f,g,!0),goog.partial(f,g,!1));else b(e)})};
goog.Promise.firstFulfilled=function(a){return new goog.Promise(function(b,c){var d=a.length,e=[];if(d)for(var f=function(a){b(a)},g=function(a,b){d--;e[a]=b;0==d&&c(e)},h=0,k;h<a.length;h++)k=a[h],goog.Promise.resolveThen_(k,f,goog.partial(g,h));else b(void 0)})};goog.Promise.withResolver=function(){var a,b,c=new goog.Promise(function(c,e){a=c;b=e});return new goog.Promise.Resolver_(c,a,b)};
goog.Promise.prototype.then=function(a,b,c){null!=a&&goog.asserts.assertFunction(a,"opt_onFulfilled should be a function.");null!=b&&goog.asserts.assertFunction(b,"opt_onRejected should be a function. Did you pass opt_context as the second argument instead of the third?");goog.Promise.LONG_STACK_TRACES&&this.addStackTrace_(Error("then"));return this.addChildPromise_(goog.isFunction(a)?a:null,goog.isFunction(b)?b:null,c)};goog.Thenable.addImplementation(goog.Promise);
goog.Promise.prototype.thenVoid=function(a,b,c){null!=a&&goog.asserts.assertFunction(a,"opt_onFulfilled should be a function.");null!=b&&goog.asserts.assertFunction(b,"opt_onRejected should be a function. Did you pass opt_context as the second argument instead of the third?");goog.Promise.LONG_STACK_TRACES&&this.addStackTrace_(Error("then"));this.addCallbackEntry_(goog.Promise.getCallbackEntry_(a||goog.nullFunction,b||null,c))};
goog.Promise.prototype.thenAlways=function(a,b){goog.Promise.LONG_STACK_TRACES&&this.addStackTrace_(Error("thenAlways"));var c=goog.Promise.getCallbackEntry_(a,a,b);c.always=!0;this.addCallbackEntry_(c);return this};goog.Promise.prototype.thenCatch=function(a,b){goog.Promise.LONG_STACK_TRACES&&this.addStackTrace_(Error("thenCatch"));return this.addChildPromise_(null,a,b)};
goog.Promise.prototype.cancel=function(a){this.state_==goog.Promise.State_.PENDING&&goog.async.run(function(){var b=new goog.Promise.CancellationError(a);this.cancelInternal_(b)},this)};goog.Promise.prototype.cancelInternal_=function(a){this.state_==goog.Promise.State_.PENDING&&(this.parent_?(this.parent_.cancelChild_(this,a),this.parent_=null):this.resolve_(goog.Promise.State_.REJECTED,a))};
goog.Promise.prototype.cancelChild_=function(a,b){if(this.callbackEntries_){for(var c=0,d=null,e=null,f=this.callbackEntries_;f&&(f.always||(c++,f.child==a&&(d=f),!(d&&1<c)));f=f.next)d||(e=f);d&&(this.state_==goog.Promise.State_.PENDING&&1==c?this.cancelInternal_(b):(e?this.removeEntryAfter_(e):this.popEntry_(),this.executeCallback_(d,goog.Promise.State_.REJECTED,b)))}};
goog.Promise.prototype.addCallbackEntry_=function(a){this.hasEntry_()||this.state_!=goog.Promise.State_.FULFILLED&&this.state_!=goog.Promise.State_.REJECTED||this.scheduleCallbacks_();this.queueEntry_(a)};
goog.Promise.prototype.addChildPromise_=function(a,b,c){var d=goog.Promise.getCallbackEntry_(null,null,null);d.child=new goog.Promise(function(e,f){d.onFulfilled=a?function(b){try{var d=a.call(c,b);e(d)}catch(k){f(k)}}:e;d.onRejected=b?function(a){try{var d=b.call(c,a);!goog.isDef(d)&&a instanceof goog.Promise.CancellationError?f(a):e(d)}catch(k){f(k)}}:f});d.child.parent_=this;this.addCallbackEntry_(d);return d.child};
goog.Promise.prototype.unblockAndFulfill_=function(a){goog.asserts.assert(this.state_==goog.Promise.State_.BLOCKED);this.state_=goog.Promise.State_.PENDING;this.resolve_(goog.Promise.State_.FULFILLED,a)};goog.Promise.prototype.unblockAndReject_=function(a){goog.asserts.assert(this.state_==goog.Promise.State_.BLOCKED);this.state_=goog.Promise.State_.PENDING;this.resolve_(goog.Promise.State_.REJECTED,a)};
goog.Promise.prototype.resolve_=function(a,b){this.state_==goog.Promise.State_.PENDING&&(this==b&&(a=goog.Promise.State_.REJECTED,b=new TypeError("Promise cannot resolve to itself")),this.state_=goog.Promise.State_.BLOCKED,goog.Promise.maybeThen_(b,this.unblockAndFulfill_,this.unblockAndReject_,this)||(this.result_=b,this.state_=a,this.parent_=null,this.scheduleCallbacks_(),a!=goog.Promise.State_.REJECTED||b instanceof goog.Promise.CancellationError||goog.Promise.addUnhandledRejection_(this,b)))};
goog.Promise.maybeThen_=function(a,b,c,d){if(a instanceof goog.Promise)return a.thenVoid(b,c,d),!0;if(goog.Thenable.isImplementedBy(a))return a.then(b,c,d),!0;if(goog.isObject(a))try{var e=a.then;if(goog.isFunction(e))return goog.Promise.tryThen_(a,e,b,c,d),!0}catch(f){return c.call(d,f),!0}return!1};goog.Promise.tryThen_=function(a,b,c,d,e){var f=!1,g=function(a){f||(f=!0,c.call(e,a))},h=function(a){f||(f=!0,d.call(e,a))};try{b.call(a,g,h)}catch(k){h(k)}};
goog.Promise.prototype.scheduleCallbacks_=function(){this.executing_||(this.executing_=!0,goog.async.run(this.executeCallbacks_,this))};goog.Promise.prototype.hasEntry_=function(){return!!this.callbackEntries_};goog.Promise.prototype.queueEntry_=function(a){goog.asserts.assert(null!=a.onFulfilled);this.callbackEntriesTail_?this.callbackEntriesTail_.next=a:this.callbackEntries_=a;this.callbackEntriesTail_=a};
goog.Promise.prototype.popEntry_=function(){var a=null;this.callbackEntries_&&(a=this.callbackEntries_,this.callbackEntries_=a.next,a.next=null);this.callbackEntries_||(this.callbackEntriesTail_=null);null!=a&&goog.asserts.assert(null!=a.onFulfilled);return a};goog.Promise.prototype.removeEntryAfter_=function(a){goog.asserts.assert(this.callbackEntries_);goog.asserts.assert(null!=a);a.next==this.callbackEntriesTail_&&(this.callbackEntriesTail_=a);a.next=a.next.next};
goog.Promise.prototype.executeCallbacks_=function(){for(var a=null;a=this.popEntry_();)goog.Promise.LONG_STACK_TRACES&&this.currentStep_++,this.executeCallback_(a,this.state_,this.result_);this.executing_=!1};
goog.Promise.prototype.executeCallback_=function(a,b,c){b==goog.Promise.State_.REJECTED&&a.onRejected&&!a.always&&this.removeUnhandledRejection_();if(a.child)a.child.parent_=null,goog.Promise.invokeCallback_(a,b,c);else try{a.always?a.onFulfilled.call(a.context):goog.Promise.invokeCallback_(a,b,c)}catch(d){goog.Promise.handleRejection_.call(null,d)}goog.Promise.returnEntry_(a)};
goog.Promise.invokeCallback_=function(a,b,c){b==goog.Promise.State_.FULFILLED?a.onFulfilled.call(a.context,c):a.onRejected&&a.onRejected.call(a.context,c)};goog.Promise.prototype.addStackTrace_=function(a){if(goog.Promise.LONG_STACK_TRACES&&goog.isString(a.stack)){var b=a.stack.split("\n",4)[3];a=a.message;a+=Array(11-a.length).join(" ");this.stack_.push(a+b)}};
goog.Promise.prototype.appendLongStack_=function(a){if(goog.Promise.LONG_STACK_TRACES&&a&&goog.isString(a.stack)&&this.stack_.length){for(var b=["Promise trace:"],c=this;c;c=c.parent_){for(var d=this.currentStep_;0<=d;d--)b.push(c.stack_[d]);b.push("Value: ["+(c.state_==goog.Promise.State_.REJECTED?"REJECTED":"FULFILLED")+"] <"+String(c.result_)+">")}a.stack+="\n\n"+b.join("\n")}};
goog.Promise.prototype.removeUnhandledRejection_=function(){if(0<goog.Promise.UNHANDLED_REJECTION_DELAY)for(var a=this;a&&a.unhandledRejectionId_;a=a.parent_)goog.global.clearTimeout(a.unhandledRejectionId_),a.unhandledRejectionId_=0;else if(0==goog.Promise.UNHANDLED_REJECTION_DELAY)for(a=this;a&&a.hadUnhandledRejection_;a=a.parent_)a.hadUnhandledRejection_=!1};
goog.Promise.addUnhandledRejection_=function(a,b){0<goog.Promise.UNHANDLED_REJECTION_DELAY?a.unhandledRejectionId_=goog.global.setTimeout(function(){a.appendLongStack_(b);goog.Promise.handleRejection_.call(null,b)},goog.Promise.UNHANDLED_REJECTION_DELAY):0==goog.Promise.UNHANDLED_REJECTION_DELAY&&(a.hadUnhandledRejection_=!0,goog.async.run(function(){a.hadUnhandledRejection_&&(a.appendLongStack_(b),goog.Promise.handleRejection_.call(null,b))}))};goog.Promise.handleRejection_=goog.async.throwException;
goog.Promise.setUnhandledRejectionHandler=function(a){goog.Promise.handleRejection_=a};goog.Promise.CancellationError=function(a){goog.debug.Error.call(this,a)};goog.inherits(goog.Promise.CancellationError,goog.debug.Error);goog.Promise.CancellationError.prototype.name="cancel";goog.Promise.Resolver_=function(a,b,c){this.promise=a;this.resolve=b;this.reject=c};goog.structs={};goog.structs.Collection=function(){};goog.structs.Map=function(a,b){this.map_={};this.keys_=[];this.version_=this.count_=0;var c=arguments.length;if(1<c){if(c%2)throw Error("Uneven number of arguments");for(var d=0;d<c;d+=2)this.set(arguments[d],arguments[d+1])}else a&&this.addAll(a)};goog.structs.Map.prototype.getCount=function(){return this.count_};goog.structs.Map.prototype.getValues=function(){this.cleanupKeysArray_();for(var a=[],b=0;b<this.keys_.length;b++)a.push(this.map_[this.keys_[b]]);return a};
goog.structs.Map.prototype.getKeys=function(){this.cleanupKeysArray_();return this.keys_.concat()};goog.structs.Map.prototype.containsKey=function(a){return goog.structs.Map.hasKey_(this.map_,a)};goog.structs.Map.prototype.containsValue=function(a){for(var b=0;b<this.keys_.length;b++){var c=this.keys_[b];if(goog.structs.Map.hasKey_(this.map_,c)&&this.map_[c]==a)return!0}return!1};
goog.structs.Map.prototype.equals=function(a,b){if(this===a)return!0;if(this.count_!=a.getCount())return!1;var c=b||goog.structs.Map.defaultEquals;this.cleanupKeysArray_();for(var d,e=0;d=this.keys_[e];e++)if(!c(this.get(d),a.get(d)))return!1;return!0};goog.structs.Map.defaultEquals=function(a,b){return a===b};goog.structs.Map.prototype.isEmpty=function(){return 0==this.count_};goog.structs.Map.prototype.clear=function(){this.map_={};this.version_=this.count_=this.keys_.length=0};
goog.structs.Map.prototype.remove=function(a){return goog.structs.Map.hasKey_(this.map_,a)?(delete this.map_[a],this.count_--,this.version_++,this.keys_.length>2*this.count_&&this.cleanupKeysArray_(),!0):!1};
goog.structs.Map.prototype.cleanupKeysArray_=function(){if(this.count_!=this.keys_.length){for(var a=0,b=0;a<this.keys_.length;){var c=this.keys_[a];goog.structs.Map.hasKey_(this.map_,c)&&(this.keys_[b++]=c);a++}this.keys_.length=b}if(this.count_!=this.keys_.length){for(var d={},b=a=0;a<this.keys_.length;)c=this.keys_[a],goog.structs.Map.hasKey_(d,c)||(this.keys_[b++]=c,d[c]=1),a++;this.keys_.length=b}};
goog.structs.Map.prototype.get=function(a,b){return goog.structs.Map.hasKey_(this.map_,a)?this.map_[a]:b};goog.structs.Map.prototype.set=function(a,b){goog.structs.Map.hasKey_(this.map_,a)||(this.count_++,this.keys_.push(a),this.version_++);this.map_[a]=b};goog.structs.Map.prototype.addAll=function(a){var b;a instanceof goog.structs.Map?(b=a.getKeys(),a=a.getValues()):(b=goog.object.getKeys(a),a=goog.object.getValues(a));for(var c=0;c<b.length;c++)this.set(b[c],a[c])};
goog.structs.Map.prototype.forEach=function(a,b){for(var c=this.getKeys(),d=0;d<c.length;d++){var e=c[d],f=this.get(e);a.call(b,f,e,this)}};goog.structs.Map.prototype.clone=function(){return new goog.structs.Map(this)};goog.structs.Map.prototype.transpose=function(){for(var a=new goog.structs.Map,b=0;b<this.keys_.length;b++){var c=this.keys_[b];a.set(this.map_[c],c)}return a};
goog.structs.Map.prototype.toObject=function(){this.cleanupKeysArray_();for(var a={},b=0;b<this.keys_.length;b++){var c=this.keys_[b];a[c]=this.map_[c]}return a};goog.structs.Map.prototype.getKeyIterator=function(){return this.__iterator__(!0)};goog.structs.Map.prototype.getValueIterator=function(){return this.__iterator__(!1)};
goog.structs.Map.prototype.__iterator__=function(a){this.cleanupKeysArray_();var b=0,c=this.version_,d=this,e=new goog.iter.Iterator;e.next=function(){if(c!=d.version_)throw Error("The map has changed since the iterator was created");if(b>=d.keys_.length)throw goog.iter.StopIteration;var e=d.keys_[b++];return a?e:d.map_[e]};return e};goog.structs.Map.hasKey_=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)};goog.structs.getCount=function(a){return a.getCount&&"function"==typeof a.getCount?a.getCount():goog.isArrayLike(a)||goog.isString(a)?a.length:goog.object.getCount(a)};goog.structs.getValues=function(a){if(a.getValues&&"function"==typeof a.getValues)return a.getValues();if(goog.isString(a))return a.split("");if(goog.isArrayLike(a)){for(var b=[],c=a.length,d=0;d<c;d++)b.push(a[d]);return b}return goog.object.getValues(a)};
goog.structs.getKeys=function(a){if(a.getKeys&&"function"==typeof a.getKeys)return a.getKeys();if(!a.getValues||"function"!=typeof a.getValues){if(goog.isArrayLike(a)||goog.isString(a)){var b=[];a=a.length;for(var c=0;c<a;c++)b.push(c);return b}return goog.object.getKeys(a)}};
goog.structs.contains=function(a,b){return a.contains&&"function"==typeof a.contains?a.contains(b):a.containsValue&&"function"==typeof a.containsValue?a.containsValue(b):goog.isArrayLike(a)||goog.isString(a)?goog.array.contains(a,b):goog.object.containsValue(a,b)};goog.structs.isEmpty=function(a){return a.isEmpty&&"function"==typeof a.isEmpty?a.isEmpty():goog.isArrayLike(a)||goog.isString(a)?goog.array.isEmpty(a):goog.object.isEmpty(a)};
goog.structs.clear=function(a){a.clear&&"function"==typeof a.clear?a.clear():goog.isArrayLike(a)?goog.array.clear(a):goog.object.clear(a)};goog.structs.forEach=function(a,b,c){if(a.forEach&&"function"==typeof a.forEach)a.forEach(b,c);else if(goog.isArrayLike(a)||goog.isString(a))goog.array.forEach(a,b,c);else for(var d=goog.structs.getKeys(a),e=goog.structs.getValues(a),f=e.length,g=0;g<f;g++)b.call(c,e[g],d&&d[g],a)};
goog.structs.filter=function(a,b,c){if("function"==typeof a.filter)return a.filter(b,c);if(goog.isArrayLike(a)||goog.isString(a))return goog.array.filter(a,b,c);var d,e=goog.structs.getKeys(a),f=goog.structs.getValues(a),g=f.length;if(e){d={};for(var h=0;h<g;h++)b.call(c,f[h],e[h],a)&&(d[e[h]]=f[h])}else for(d=[],h=0;h<g;h++)b.call(c,f[h],void 0,a)&&d.push(f[h]);return d};
goog.structs.map=function(a,b,c){if("function"==typeof a.map)return a.map(b,c);if(goog.isArrayLike(a)||goog.isString(a))return goog.array.map(a,b,c);var d,e=goog.structs.getKeys(a),f=goog.structs.getValues(a),g=f.length;if(e){d={};for(var h=0;h<g;h++)d[e[h]]=b.call(c,f[h],e[h],a)}else for(d=[],h=0;h<g;h++)d[h]=b.call(c,f[h],void 0,a);return d};
goog.structs.some=function(a,b,c){if("function"==typeof a.some)return a.some(b,c);if(goog.isArrayLike(a)||goog.isString(a))return goog.array.some(a,b,c);for(var d=goog.structs.getKeys(a),e=goog.structs.getValues(a),f=e.length,g=0;g<f;g++)if(b.call(c,e[g],d&&d[g],a))return!0;return!1};
goog.structs.every=function(a,b,c){if("function"==typeof a.every)return a.every(b,c);if(goog.isArrayLike(a)||goog.isString(a))return goog.array.every(a,b,c);for(var d=goog.structs.getKeys(a),e=goog.structs.getValues(a),f=e.length,g=0;g<f;g++)if(!b.call(c,e[g],d&&d[g],a))return!1;return!0};goog.structs.Set=function(a){this.map_=new goog.structs.Map;a&&this.addAll(a)};goog.structs.Set.getKey_=function(a){var b=typeof a;return"object"==b&&a||"function"==b?"o"+goog.getUid(a):b.substr(0,1)+a};goog.structs.Set.prototype.getCount=function(){return this.map_.getCount()};goog.structs.Set.prototype.add=function(a){this.map_.set(goog.structs.Set.getKey_(a),a)};goog.structs.Set.prototype.addAll=function(a){a=goog.structs.getValues(a);for(var b=a.length,c=0;c<b;c++)this.add(a[c])};
goog.structs.Set.prototype.removeAll=function(a){a=goog.structs.getValues(a);for(var b=a.length,c=0;c<b;c++)this.remove(a[c])};goog.structs.Set.prototype.remove=function(a){return this.map_.remove(goog.structs.Set.getKey_(a))};goog.structs.Set.prototype.clear=function(){this.map_.clear()};goog.structs.Set.prototype.isEmpty=function(){return this.map_.isEmpty()};goog.structs.Set.prototype.contains=function(a){return this.map_.containsKey(goog.structs.Set.getKey_(a))};
goog.structs.Set.prototype.containsAll=function(a){return goog.structs.every(a,this.contains,this)};goog.structs.Set.prototype.intersection=function(a){var b=new goog.structs.Set;a=goog.structs.getValues(a);for(var c=0;c<a.length;c++){var d=a[c];this.contains(d)&&b.add(d)}return b};goog.structs.Set.prototype.difference=function(a){var b=this.clone();b.removeAll(a);return b};goog.structs.Set.prototype.getValues=function(){return this.map_.getValues()};goog.structs.Set.prototype.clone=function(){return new goog.structs.Set(this)};
goog.structs.Set.prototype.equals=function(a){return this.getCount()==goog.structs.getCount(a)&&this.isSubsetOf(a)};goog.structs.Set.prototype.isSubsetOf=function(a){var b=goog.structs.getCount(a);if(this.getCount()>b)return!1;!(a instanceof goog.structs.Set)&&5<b&&(a=new goog.structs.Set(a));return goog.structs.every(this,function(b){return goog.structs.contains(a,b)})};goog.structs.Set.prototype.__iterator__=function(a){return this.map_.__iterator__(!1)};goog.userAgent={};goog.userAgent.ASSUME_IE=!1;goog.userAgent.ASSUME_EDGE=!1;goog.userAgent.ASSUME_GECKO=!1;goog.userAgent.ASSUME_WEBKIT=!1;goog.userAgent.ASSUME_MOBILE_WEBKIT=!1;goog.userAgent.ASSUME_OPERA=!1;goog.userAgent.ASSUME_ANY_VERSION=!1;goog.userAgent.BROWSER_KNOWN_=goog.userAgent.ASSUME_IE||goog.userAgent.ASSUME_EDGE||goog.userAgent.ASSUME_GECKO||goog.userAgent.ASSUME_MOBILE_WEBKIT||goog.userAgent.ASSUME_WEBKIT||goog.userAgent.ASSUME_OPERA;goog.userAgent.getUserAgentString=function(){return goog.labs.userAgent.util.getUserAgent()};
goog.userAgent.getNavigator=function(){return goog.global.navigator||null};goog.userAgent.OPERA=goog.userAgent.BROWSER_KNOWN_?goog.userAgent.ASSUME_OPERA:goog.labs.userAgent.browser.isOpera();goog.userAgent.IE=goog.userAgent.BROWSER_KNOWN_?goog.userAgent.ASSUME_IE:goog.labs.userAgent.browser.isIE();goog.userAgent.EDGE=goog.userAgent.BROWSER_KNOWN_?goog.userAgent.ASSUME_EDGE:goog.labs.userAgent.engine.isEdge();goog.userAgent.EDGE_OR_IE=goog.userAgent.EDGE||goog.userAgent.IE;
goog.userAgent.GECKO=goog.userAgent.BROWSER_KNOWN_?goog.userAgent.ASSUME_GECKO:goog.labs.userAgent.engine.isGecko();goog.userAgent.WEBKIT=goog.userAgent.BROWSER_KNOWN_?goog.userAgent.ASSUME_WEBKIT||goog.userAgent.ASSUME_MOBILE_WEBKIT:goog.labs.userAgent.engine.isWebKit();goog.userAgent.isMobile_=function(){return goog.userAgent.WEBKIT&&goog.labs.userAgent.util.matchUserAgent("Mobile")};goog.userAgent.MOBILE=goog.userAgent.ASSUME_MOBILE_WEBKIT||goog.userAgent.isMobile_();goog.userAgent.SAFARI=goog.userAgent.WEBKIT;
goog.userAgent.determinePlatform_=function(){var a=goog.userAgent.getNavigator();return a&&a.platform||""};goog.userAgent.PLATFORM=goog.userAgent.determinePlatform_();goog.userAgent.ASSUME_MAC=!1;goog.userAgent.ASSUME_WINDOWS=!1;goog.userAgent.ASSUME_LINUX=!1;goog.userAgent.ASSUME_X11=!1;goog.userAgent.ASSUME_ANDROID=!1;goog.userAgent.ASSUME_IPHONE=!1;goog.userAgent.ASSUME_IPAD=!1;
goog.userAgent.PLATFORM_KNOWN_=goog.userAgent.ASSUME_MAC||goog.userAgent.ASSUME_WINDOWS||goog.userAgent.ASSUME_LINUX||goog.userAgent.ASSUME_X11||goog.userAgent.ASSUME_ANDROID||goog.userAgent.ASSUME_IPHONE||goog.userAgent.ASSUME_IPAD;goog.userAgent.MAC=goog.userAgent.PLATFORM_KNOWN_?goog.userAgent.ASSUME_MAC:goog.labs.userAgent.platform.isMacintosh();goog.userAgent.WINDOWS=goog.userAgent.PLATFORM_KNOWN_?goog.userAgent.ASSUME_WINDOWS:goog.labs.userAgent.platform.isWindows();
goog.userAgent.isLegacyLinux_=function(){return goog.labs.userAgent.platform.isLinux()||goog.labs.userAgent.platform.isChromeOS()};goog.userAgent.LINUX=goog.userAgent.PLATFORM_KNOWN_?goog.userAgent.ASSUME_LINUX:goog.userAgent.isLegacyLinux_();goog.userAgent.isX11_=function(){var a=goog.userAgent.getNavigator();return!!a&&goog.string.contains(a.appVersion||"","X11")};goog.userAgent.X11=goog.userAgent.PLATFORM_KNOWN_?goog.userAgent.ASSUME_X11:goog.userAgent.isX11_();
goog.userAgent.ANDROID=goog.userAgent.PLATFORM_KNOWN_?goog.userAgent.ASSUME_ANDROID:goog.labs.userAgent.platform.isAndroid();goog.userAgent.IPHONE=goog.userAgent.PLATFORM_KNOWN_?goog.userAgent.ASSUME_IPHONE:goog.labs.userAgent.platform.isIphone();goog.userAgent.IPAD=goog.userAgent.PLATFORM_KNOWN_?goog.userAgent.ASSUME_IPAD:goog.labs.userAgent.platform.isIpad();goog.userAgent.operaVersion_=function(){var a=goog.global.opera.version;try{return a()}catch(b){return a}};
goog.userAgent.determineVersion_=function(){if(goog.userAgent.OPERA&&goog.global.opera)return goog.userAgent.operaVersion_();var a="",b=goog.userAgent.getVersionRegexResult_();b&&(a=b?b[1]:"");return goog.userAgent.IE&&(b=goog.userAgent.getDocumentMode_(),b>parseFloat(a))?String(b):a};
goog.userAgent.getVersionRegexResult_=function(){var a=goog.userAgent.getUserAgentString();if(goog.userAgent.GECKO)return/rv\:([^\);]+)(\)|;)/.exec(a);if(goog.userAgent.EDGE)return/Edge\/([\d\.]+)/.exec(a);if(goog.userAgent.IE)return/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/.exec(a);if(goog.userAgent.WEBKIT)return/WebKit\/(\S+)/.exec(a)};goog.userAgent.getDocumentMode_=function(){var a=goog.global.document;return a?a.documentMode:void 0};goog.userAgent.VERSION=goog.userAgent.determineVersion_();
goog.userAgent.compare=function(a,b){return goog.string.compareVersions(a,b)};goog.userAgent.isVersionOrHigherCache_={};goog.userAgent.isVersionOrHigher=function(a){return goog.userAgent.ASSUME_ANY_VERSION||goog.userAgent.isVersionOrHigherCache_[a]||(goog.userAgent.isVersionOrHigherCache_[a]=0<=goog.string.compareVersions(goog.userAgent.VERSION,a))};goog.userAgent.isVersion=goog.userAgent.isVersionOrHigher;goog.userAgent.isDocumentModeOrHigher=function(a){return goog.userAgent.DOCUMENT_MODE>=a};
goog.userAgent.isDocumentMode=goog.userAgent.isDocumentModeOrHigher;goog.userAgent.DOCUMENT_MODE=function(){var a=goog.global.document,b=goog.userAgent.getDocumentMode_();return a&&goog.userAgent.IE?b||("CSS1Compat"==a.compatMode?parseInt(goog.userAgent.VERSION,10):5):void 0}();goog.userAgent.product={};goog.userAgent.product.ASSUME_FIREFOX=!1;goog.userAgent.product.ASSUME_IPHONE=!1;goog.userAgent.product.ASSUME_IPAD=!1;goog.userAgent.product.ASSUME_ANDROID=!1;goog.userAgent.product.ASSUME_CHROME=!1;goog.userAgent.product.ASSUME_SAFARI=!1;
goog.userAgent.product.PRODUCT_KNOWN_=goog.userAgent.ASSUME_IE||goog.userAgent.ASSUME_EDGE||goog.userAgent.ASSUME_OPERA||goog.userAgent.product.ASSUME_FIREFOX||goog.userAgent.product.ASSUME_IPHONE||goog.userAgent.product.ASSUME_IPAD||goog.userAgent.product.ASSUME_ANDROID||goog.userAgent.product.ASSUME_CHROME||goog.userAgent.product.ASSUME_SAFARI;goog.userAgent.product.OPERA=goog.userAgent.OPERA;goog.userAgent.product.IE=goog.userAgent.IE;goog.userAgent.product.EDGE=goog.userAgent.EDGE;
goog.userAgent.product.FIREFOX=goog.userAgent.product.PRODUCT_KNOWN_?goog.userAgent.product.ASSUME_FIREFOX:goog.labs.userAgent.browser.isFirefox();goog.userAgent.product.isIphoneOrIpod_=function(){return goog.labs.userAgent.platform.isIphone()||goog.labs.userAgent.platform.isIpod()};goog.userAgent.product.IPHONE=goog.userAgent.product.PRODUCT_KNOWN_?goog.userAgent.product.ASSUME_IPHONE:goog.userAgent.product.isIphoneOrIpod_();
goog.userAgent.product.IPAD=goog.userAgent.product.PRODUCT_KNOWN_?goog.userAgent.product.ASSUME_IPAD:goog.labs.userAgent.platform.isIpad();goog.userAgent.product.ANDROID=goog.userAgent.product.PRODUCT_KNOWN_?goog.userAgent.product.ASSUME_ANDROID:goog.labs.userAgent.browser.isAndroidBrowser();goog.userAgent.product.CHROME=goog.userAgent.product.PRODUCT_KNOWN_?goog.userAgent.product.ASSUME_CHROME:goog.labs.userAgent.browser.isChrome();
goog.userAgent.product.isSafariDesktop_=function(){return goog.labs.userAgent.browser.isSafari()&&!goog.labs.userAgent.platform.isIos()};goog.userAgent.product.SAFARI=goog.userAgent.product.PRODUCT_KNOWN_?goog.userAgent.product.ASSUME_SAFARI:goog.userAgent.product.isSafariDesktop_();/*
Copyright 2014 The Lovefield Project Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var lf={BackStore:function(){}};lf.backstore={};lf.backstore.TableType={DATA:0,INDEX:1};lf.backstore.Tx=function(){};lf.bind=function(a){return new lf.Binder(a)};lf.Binder=function(a){this.index_=a};lf.Binder.prototype.getIndex=function(){return this.index_};lf.cache={};lf.cache.Cache=function(){};/*
Copyright 2015 The Lovefield Project Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
lf.Capability=function(){this.safariWebView_=goog.userAgent.product.SAFARI||goog.userAgent.product.IPAD||goog.userAgent.product.IPHONE;this.indexedDb=!(this.safariWebView_||goog.userAgent.product.IE&&!goog.userAgent.isVersionOrHigher(10));this.localStorageEvent=!(goog.userAgent.product.IE&&!goog.userAgent.isVersionOrHigher(11));this.webSql=goog.userAgent.product.CHROME||goog.userAgent.product.SAFARI;this.nativeMap=goog.isDef(window.Map)&&goog.isDef(window.Map.prototype.values)&&goog.isDef(window.Map.prototype.forEach)&&
!this.safariWebView_;this.nativeSet=goog.isDef(window.Set)&&goog.isDef(window.Set.prototype.values)&&goog.isDef(window.Set.prototype.forEach)&&!this.safariWebView_};lf.Capability.get=function(){goog.isDef(lf.Capability.instance_)||(lf.Capability.instance_=new lf.Capability);return lf.Capability.instance_};lf.Database=function(){};lf.type={};lf.ConstraintAction={};lf.ConstraintAction.RESTRICT=0;lf.ConstraintAction.CASCADE=1;lf.ConstraintTiming={};lf.ConstraintTiming.IMMEDIATE=0;lf.ConstraintTiming.DEFERRABLE=1;lf.Order={};lf.Order.DESC=0;lf.Order.ASC=1;lf.Type={};lf.Type.ARRAY_BUFFER=0;lf.Type.BOOLEAN=1;lf.Type.DATE_TIME=2;lf.Type.INTEGER=3;lf.Type.NUMBER=4;lf.Type.STRING=5;lf.Type.OBJECT=6;lf.type.DEFAULT_VALUES={0:null,1:!1,2:Object.freeze(new Date(0)),3:0,4:0,5:"",6:null};lf.Exception=function(a,b){this.code=a;this.message="http://sn.im/2a0j3wn?c="+a;if(1<arguments.length)for(var c=1;c<=Math.min(4,arguments.length-1);++c)this.message+="&p"+(c-1)+"="+encodeURIComponent(arguments[c].toString().slice(0,64))};goog.inherits(lf.Exception,Error);lf.Flags={};lf.Flags.MEMORY_ONLY=!1;lf.Flags.NATIVE_ES6=!1;lf.index={};lf.index.hashCode=function(a){for(var b=0,c=0;c<a.length;++c)b=(b<<5)-b+a.charCodeAt(c),b&=b;return b};lf.index.hashArray=function(a){return a.map(function(a){return goog.isDefAndNotNull(a)?lf.index.hashCode(a.toString()).toString(32):""}).join("_")};lf.index.slice=function(a,b,c,d){a=b?a.reverse():a;if(!goog.isDefAndNotNull(c)&&!goog.isDefAndNotNull(d))return a;c=Math.min(goog.isDef(c)?c:a.length,a.length);if(0==c)return[];d=Math.min(d||0,a.length);return a.slice(d,d+c)};lf.index.Favor={RHS:-1,TIE:0,LHS:1};lf.index.Comparator=function(){};lf.index.Index=function(){};lf.index.IndexStore=function(){};lf.index.SingleKeyRange=function(a,b,c,d){this.from=a;this.to=b;this.excludeLower=lf.index.SingleKeyRange.isUnbound(this.from)?!1:c;this.excludeUpper=lf.index.SingleKeyRange.isUnbound(this.to)?!1:d};lf.index.UnboundKey=function(){};lf.index.SingleKeyRange.UNBOUND_VALUE=new lf.index.UnboundKey;lf.index.SingleKeyRange.isUnbound=function(a){return a==lf.index.SingleKeyRange.UNBOUND_VALUE};
lf.index.SingleKeyRange.prototype.toString=function(){return(this.excludeLower?"(":"[")+(lf.index.SingleKeyRange.isUnbound(this.from)?"unbound":this.from)+", "+(lf.index.SingleKeyRange.isUnbound(this.to)?"unbound":this.to)+(this.excludeUpper?")":"]")};
lf.index.SingleKeyRange.prototype.complement=function(){if(this.isAll())return[];var a=null,b=null;lf.index.SingleKeyRange.isUnbound(this.from)||(a=new lf.index.SingleKeyRange(lf.index.SingleKeyRange.UNBOUND_VALUE,this.from,!1,!this.excludeLower));lf.index.SingleKeyRange.isUnbound(this.to)||(b=new lf.index.SingleKeyRange(this.to,lf.index.SingleKeyRange.UNBOUND_VALUE,!this.excludeUpper,!1));return[a,b].filter(function(a){return!goog.isNull(a)})};
lf.index.SingleKeyRange.prototype.reverse=function(){return new lf.index.SingleKeyRange(this.to,this.from,this.excludeUpper,this.excludeLower)};lf.index.SingleKeyRange.prototype.overlaps=function(a){var b=lf.index.SingleKeyRange.compareKey_(this.from,a.from,!0,this.excludeLower,a.excludeLower);if(b==lf.index.Favor.TIE)return!0;var c=b==lf.index.Favor.RHS?this:a;a=b==lf.index.Favor.LHS?this:a;return lf.index.SingleKeyRange.isUnbound(c.to)||c.to>a.from||c.to==a.from&&!c.excludeUpper&&!a.excludeLower};
lf.index.SingleKeyRange.upperBound=function(a,b){return new lf.index.SingleKeyRange(lf.index.SingleKeyRange.UNBOUND_VALUE,a,!1,b||!1)};lf.index.SingleKeyRange.lowerBound=function(a,b){return new lf.index.SingleKeyRange(a,lf.index.SingleKeyRange.UNBOUND_VALUE,b||!1,!1)};lf.index.SingleKeyRange.only=function(a){return new lf.index.SingleKeyRange(a,a,!1,!1)};
lf.index.SingleKeyRange.all=function(){return new lf.index.SingleKeyRange(lf.index.SingleKeyRange.UNBOUND_VALUE,lf.index.SingleKeyRange.UNBOUND_VALUE,!1,!1)};lf.index.SingleKeyRange.prototype.isAll=function(){return lf.index.SingleKeyRange.isUnbound(this.from)&&lf.index.SingleKeyRange.isUnbound(this.to)};lf.index.SingleKeyRange.prototype.isOnly=function(){return this.from==this.to&&!lf.index.SingleKeyRange.isUnbound(this.from)&&!this.excludeLower&&!this.excludeUpper};
lf.index.SingleKeyRange.prototype.contains=function(a){var b=lf.index.SingleKeyRange.isUnbound(this.from)||a>this.from||a==this.from&&!this.excludeLower;a=lf.index.SingleKeyRange.isUnbound(this.to)||a<this.to||a==this.to&&!this.excludeUpper;return b&&a};
lf.index.SingleKeyRange.prototype.getBounded=function(a,b){if(lf.index.SingleKeyRange.isUnbound(this.from)&&!this.contains(a)||lf.index.SingleKeyRange.isUnbound(this.to)&&!this.contains(b))return null;var c=new lf.index.SingleKeyRange(a,b,!1,!1);!lf.index.SingleKeyRange.isUnbound(this.from)&&this.from>=a&&(c.from=this.from,c.excludeLower=this.excludeLower);!lf.index.SingleKeyRange.isUnbound(this.to)&&this.to<=b&&(c.to=this.to,c.excludeUpper=this.excludeUpper);return c.from>c.to||c.from==c.to&&(c.excludeUpper||
c.excludeLower)?null:c};lf.index.SingleKeyRange.prototype.equals=function(a){return this.from==a.from&&this.excludeLower==a.excludeLower&&this.to==a.to&&this.excludeUpper==a.excludeUpper};lf.index.SingleKeyRange.xor=function(a,b){return a?!b:b};
lf.index.SingleKeyRange.compareKey_=function(a,b,c,d,e){var f=lf.index.Favor,g=d||!1,h=e||!1,k=function(a){return c?a:a==f.LHS?f.RHS:f.LHS};d=function(){return lf.index.SingleKeyRange.xor(g,h)?g?k(f.LHS):k(f.RHS):f.TIE};return lf.index.SingleKeyRange.isUnbound(a)?lf.index.SingleKeyRange.isUnbound(b)?d():k(f.RHS):lf.index.SingleKeyRange.isUnbound(b)?k(f.LHS):a<b?f.RHS:a==b?d():f.LHS};
lf.index.SingleKeyRange.compare=function(a,b){var c=lf.index.SingleKeyRange.compareKey_(a.from,b.from,!0,a.excludeLower,b.excludeLower);c==lf.index.Favor.TIE&&(c=lf.index.SingleKeyRange.compareKey_(a.to,b.to,!1,a.excludeUpper,b.excludeUpper));return c};
lf.index.SingleKeyRange.getBoundingRange=function(a,b){var c=lf.index.SingleKeyRange.all();if(!lf.index.SingleKeyRange.isUnbound(a.from)&&!lf.index.SingleKeyRange.isUnbound(b.from)){var d=lf.index.SingleKeyRange.compareKey_(a.from,b.from,!0);d!=lf.index.Favor.LHS?(c.from=a.from,c.excludeLower=d!=lf.index.Favor.TIE?a.excludeLower:a.excludeLower&&b.excludeLower):(c.from=b.from,c.excludeLower=b.excludeLower)}lf.index.SingleKeyRange.isUnbound(a.to)||lf.index.SingleKeyRange.isUnbound(b.to)||(d=lf.index.SingleKeyRange.compareKey_(a.to,
b.to,!1),d!=lf.index.Favor.RHS?(c.to=a.to,c.excludeUpper=d!=lf.index.Favor.TIE?a.excludeUpper:a.excludeUpper&&b.excludeUpper):(c.to=b.to,c.excludeUpper=b.excludeUpper));return c};
lf.index.SingleKeyRange.and=function(a,b){if(!a.overlaps(b))return null;var c=lf.index.SingleKeyRange.all(),d=lf.index.SingleKeyRange.compareKey_(a.from,b.from,!0),d=d==lf.index.Favor.TIE?a.excludeLower?a:b:d!=lf.index.Favor.RHS?a:b;c.from=d.from;c.excludeLower=d.excludeLower;lf.index.SingleKeyRange.isUnbound(a.to)||lf.index.SingleKeyRange.isUnbound(b.to)?d=lf.index.SingleKeyRange.isUnbound(a.to)?b:a:(d=lf.index.SingleKeyRange.compareKey_(a.to,b.to,!1),d=d==lf.index.Favor.TIE?a.excludeUpper?a:b:d==
lf.index.Favor.RHS?a:b);c.to=d.to;c.excludeUpper=d.excludeUpper;return c};lf.index.SingleKeyRange.complement=function(a){if(0==a.length)return[];a.sort(lf.index.SingleKeyRange.compare);for(var b=Array(a.length+1),c=0;c<b.length;c++)b[c]=0==c?lf.index.SingleKeyRange.upperBound(a[c].from,!0):c==b.length-1?lf.index.SingleKeyRange.lowerBound(a[c-1].to,!0):new lf.index.SingleKeyRange(a[c-1].to,a[c].from,!0,!0);return b};lf.index.SimpleComparator=function(a){this.compareFn=a==lf.Order.DESC?lf.index.SimpleComparator.compareDescending:lf.index.SimpleComparator.compareAscending;this.normalizeKeyRange_=a==lf.Order.DESC?function(a){return goog.isDefAndNotNull(a)?a.reverse():null}:function(a){return a||null};this.orderRange_=a==lf.Order.DESC?lf.index.SimpleComparator.orderRangeDescending:lf.index.SimpleComparator.orderRangeAscending};
lf.index.SimpleComparator.compareAscending=function(a,b){return a>b?lf.index.Favor.LHS:a<b?lf.index.Favor.RHS:lf.index.Favor.TIE};lf.index.SimpleComparator.compareDescending=function(a,b){return lf.index.SimpleComparator.compareAscending(b,a)};lf.index.SimpleComparator.orderRangeAscending=function(a,b){return lf.index.SingleKeyRange.compare(a,b)};lf.index.SimpleComparator.orderRangeDescending=function(a,b){return lf.index.SingleKeyRange.compare(b,a)};
lf.index.SimpleComparator.prototype.compareRange=function(a,b){var c=this.normalizeKeyRange_(b),d=[lf.index.SingleKeyRange.isUnbound(c.from),lf.index.SingleKeyRange.isUnbound(c.to)];if(!d[0]){var e=this.compareFn(a,c.from);d[0]=c.excludeLower?e==lf.index.Favor.LHS:e!=lf.index.Favor.RHS}d[1]||(e=this.compareFn(a,c.to),d[1]=c.excludeUpper?e==lf.index.Favor.RHS:e!=lf.index.Favor.LHS);return d};lf.index.SimpleComparator.prototype.compare=function(a,b){return this.compareFn(a,b)};
lf.index.SimpleComparator.prototype.min=function(a,b){return a<b?lf.index.Favor.LHS:a==b?lf.index.Favor.TIE:lf.index.Favor.RHS};lf.index.SimpleComparator.prototype.max=function(a,b){return a>b?lf.index.Favor.LHS:a==b?lf.index.Favor.TIE:lf.index.Favor.RHS};lf.index.SimpleComparator.prototype.isInRange=function(a,b){var c=this.compareRange(a,b);return c[0]&&c[1]};lf.index.SimpleComparator.prototype.isFirstKeyInRange=function(a,b){return this.isInRange(a,b)};
lf.index.SimpleComparator.prototype.getAllRange=function(){return lf.index.SingleKeyRange.all()};lf.index.SimpleComparator.prototype.orderKeyRange=function(a,b){return this.orderRange_(a,b)};lf.index.SimpleComparator.prototype.sortKeyRanges=function(a){return a.filter(function(a){return!goog.isNull(a)}).sort(function(a,c){return this.orderRange_(a,c)}.bind(this))};lf.index.SimpleComparator.prototype.isLeftOpen=function(a){return lf.index.SingleKeyRange.isUnbound(this.normalizeKeyRange_(a).from)};
lf.index.SimpleComparator.prototype.rangeToKeys=function(a){a=this.normalizeKeyRange_(a);return[a.from,a.to]};lf.index.SimpleComparator.prototype.comparable=function(a){return!goog.isNull(a)};lf.index.SimpleComparator.prototype.keyDimensions=function(){return 1};lf.index.SimpleComparator.prototype.toString=function(){return this.compare==lf.index.SimpleComparator.compareDescending?"SimpleComparator_DESC":"SimpleComparator_ASC"};
lf.index.SimpleComparatorWithNull=function(a){lf.index.SimpleComparator.call(this,a);this.compareFn=a==lf.Order.DESC?lf.index.SimpleComparatorWithNull.compareDescending:lf.index.SimpleComparatorWithNull.compareAscending};goog.inherits(lf.index.SimpleComparatorWithNull,lf.index.SimpleComparator);
lf.index.SimpleComparatorWithNull.compareAscending=function(a,b){return goog.isNull(a)?goog.isNull(b)?lf.index.Favor.TIE:lf.index.Favor.RHS:goog.isNull(b)?lf.index.Favor.LHS:lf.index.SimpleComparator.compareAscending(a,b)};lf.index.SimpleComparatorWithNull.compareDescending=function(a,b){return lf.index.SimpleComparatorWithNull.compareAscending(b,a)};
lf.index.SimpleComparatorWithNull.prototype.isInRange=function(a,b){return goog.isNull(a)?b.isAll():lf.index.SimpleComparatorWithNull.superClass_.isInRange.call(this,a,b)};lf.index.SimpleComparatorWithNull.prototype.minMax_=function(a,b){return goog.isNull(a)?goog.isNull(b)?lf.index.Favor.TIE:lf.index.Favor.RHS:goog.isNull(b)?lf.index.Favor.LHS:null};
lf.index.SimpleComparatorWithNull.prototype.min=function(a,b){var c=this.minMax_(a,b);goog.isNull(c)&&(c=lf.index.SimpleComparatorWithNull.superClass_.min.call(this,a,b));return c};lf.index.SimpleComparatorWithNull.prototype.max=function(a,b){var c=this.minMax_(a,b);goog.isNull(c)&&(c=lf.index.SimpleComparatorWithNull.superClass_.max.call(this,a,b));return c};lf.index.MultiKeyComparator=function(a){this.comparators=a.map(function(a){return new lf.index.SimpleComparator(a)})};lf.index.MultiKeyComparator.createOrders=function(a,b){for(var c=Array(a),d=0;d<a;++d)c[d]=b;return c};lf.index.MultiKeyComparator.prototype.forEach_=function(a,b,c){for(var d=lf.index.Favor.TIE,e=0;e<this.comparators.length&&d==lf.index.Favor.TIE;++e)d=c(this.comparators[e],a[e],b[e]);return d};
lf.index.MultiKeyComparator.prototype.compare=function(a,b){return this.forEach_(a,b,function(a,b,e){return b==lf.index.SingleKeyRange.UNBOUND_VALUE||e==lf.index.SingleKeyRange.UNBOUND_VALUE?lf.index.Favor.TIE:a.compare(b,e)})};lf.index.MultiKeyComparator.prototype.min=function(a,b){return this.forEach_(a,b,function(a,b,e){return a.min(b,e)})};lf.index.MultiKeyComparator.prototype.max=function(a,b){return this.forEach_(a,b,function(a,b,e){return a.max(b,e)})};
lf.index.MultiKeyComparator.prototype.compareRange=function(a,b){for(var c=[!0,!0],d=0;d<this.comparators.length&&(c[0]||c[1]);++d){var e=this.comparators[d].compareRange(a[d],b[d]);c[0]=c[0]&&e[0];c[1]=c[1]&&e[1]}return c};lf.index.MultiKeyComparator.prototype.isInRange=function(a,b){for(var c=!0,d=0;d<this.comparators.length&&c;++d)c=this.comparators[d].isInRange(a[d],b[d]);return c};
lf.index.MultiKeyComparator.prototype.isFirstKeyInRange=function(a,b){return this.comparators[0].isInRange(a[0],b[0])};lf.index.MultiKeyComparator.prototype.getAllRange=function(){return this.comparators.map(function(a){return a.getAllRange()})};
lf.index.MultiKeyComparator.prototype.sortKeyRanges=function(a){var b=a.filter(function(a){return a.every(goog.isDefAndNotNull)});a=Array(this.comparators.length);for(var c=0;c<a.length;c++)a[c]=b.map(function(a){return a[c]});a.forEach(function(a,b){a.sort(function(a,c){return this.comparators[b].orderKeyRange(a,c)}.bind(this))},this);b=Array(b.length);for(c=0;c<b.length;c++)b[c]=a.map(function(a){return a[c]});return b.sort(function(a,b){for(var c=lf.index.Favor.TIE,g=0;g<this.comparators.length&&
c==lf.index.Favor.TIE;++g)c=this.comparators[g].orderKeyRange(a[g],b[g]);return c}.bind(this))};lf.index.MultiKeyComparator.prototype.isLeftOpen=function(a){return this.comparators[0].isLeftOpen(a[0])};lf.index.MultiKeyComparator.prototype.rangeToKeys=function(a){var b=a.map(function(a,b){return this.comparators[b].rangeToKeys(a)[0]},this);a=a.map(function(a,b){return this.comparators[b].rangeToKeys(a)[1]},this);return[b,a]};
lf.index.MultiKeyComparator.prototype.comparable=function(a){return a.every(function(a,c){return this.comparators[c].comparable(a)},this)};lf.index.MultiKeyComparator.prototype.keyDimensions=function(){return this.comparators.length};lf.index.MultiKeyComparatorWithNull=function(a){lf.index.MultiKeyComparator.call(this,a);this.comparators=a.map(function(a){return new lf.index.SimpleComparatorWithNull(a)})};goog.inherits(lf.index.MultiKeyComparatorWithNull,lf.index.MultiKeyComparator);lf.index.ComparatorFactory={};lf.index.ComparatorFactory.create=function(a){if(1==a.columns.length)return new lf.index.SimpleComparator(a.columns[0].order);var b=a.columns.map(function(a){return a.order});return a.columns.some(function(a){return a.schema.isNullable()})?new lf.index.MultiKeyComparatorWithNull(b):new lf.index.MultiKeyComparator(b)};lf.index.SingleKeyRangeSet=function(a){this.ranges_=[];goog.isDef(a)&&this.add(a)};lf.index.SingleKeyRangeSet.prototype.toString=function(){return this.ranges_.map(function(a){return a.toString()}).join(",")};lf.index.SingleKeyRangeSet.prototype.containsKey=function(a){return this.ranges_.some(function(b){return b.contains(a)})};lf.index.SingleKeyRangeSet.prototype.getValues=function(){return this.ranges_};
lf.index.SingleKeyRangeSet.prototype.add=function(a){if(0!=a.length)if(a=this.ranges_.concat(a),1==a.length)this.ranges_=a;else{a.sort(lf.index.SingleKeyRange.compare);for(var b=[],c=a[0],d=1;d<a.length;++d)c.overlaps(a[d])?c=lf.index.SingleKeyRange.getBoundingRange(c,a[d]):(b.push(c),c=a[d]);b.push(c);this.ranges_=b}};
lf.index.SingleKeyRangeSet.prototype.equals=function(a){return this.ranges_.length==a.ranges_.length?0==this.ranges_.length||this.ranges_.every(function(b,c){return b.equals(a.ranges_[c])}):!1};lf.index.SingleKeyRangeSet.prototype.getBoundingRange=function(){return 1>=this.ranges_.length?0==this.ranges_.length?null:this.ranges_[0]:lf.index.SingleKeyRange.getBoundingRange(this.ranges_[0],this.ranges_[this.ranges_.length-1])};
lf.index.SingleKeyRangeSet.intersect=function(a,b){var c=[];a.getValues().map(function(a){return b.getValues().map(function(b){return lf.index.SingleKeyRange.and(a,b)})}).forEach(function(a){c=c.concat(a)});return new lf.index.SingleKeyRangeSet(c.filter(function(a){return!goog.isNull(a)}))};lf.index.Stats=function(){this.totalRows=0};lf.index.Stats.prototype.add=function(a,b){this.totalRows+=b};lf.index.Stats.prototype.remove=function(a,b){this.totalRows-=b};lf.index.Stats.prototype.clear=function(){this.totalRows=0};lf.index.Stats.prototype.updateFromList=function(a){this.clear();a.forEach(function(a){this.totalRows+=a.totalRows},this)};lf.pred={};lf.pred.Operator={AND:"and",OR:"or"};lf.Predicate=function(){};lf.PredicateProvider=function(){};lf.proc={};lf.proc.PhysicalPlanRewriter=function(a,b,c){this.rootNode_=a;this.queryContext_=b;this.rewritePasses_=c};lf.proc.PhysicalPlanRewriter.prototype.generate=function(){this.rewritePasses_.forEach(function(a){this.rootNode_=a.rewrite(this.rootNode_,this.queryContext_)},this);return this.rootNode_};lf.proc.QueryEngine=function(){};lf.proc.RewritePass=function(){};lf.proc.Task=function(){};lf.proc.TaskPriority={EXPORT_TASK:0,IMPORT_TASK:0,OBSERVER_QUERY_TASK:0,EXTERNAL_CHANGE_TASK:1,USER_QUERY_TASK:2,TRANSACTION_TASK:2};lf.query={};lf.query.Builder=function(){};lf.query.Select=function(){};lf.query.Insert=function(){};lf.query.Update=function(){};lf.query.Delete=function(){};lf.raw={};lf.raw.BackStore=function(){};lf.Row=function(a,b){this.id_=a;this.payload_=b||this.defaultPayload()};lf.Row.nextId_=0;lf.Row.DUMMY_ID=-1;lf.Row.getNextId=function(){return lf.Row.nextId_++};lf.Row.setNextId=function(a){lf.Row.nextId_=a};lf.Row.prototype.id=function(){return this.id_};lf.Row.prototype.assignRowId=function(a){this.id_=a};lf.Row.prototype.payload=function(){return this.payload_};lf.Row.prototype.defaultPayload=function(){return{}};lf.Row.prototype.toDbPayload=function(){return this.payload_};
lf.Row.prototype.serialize=function(){return{id:this.id_,value:this.toDbPayload()}};lf.Row.prototype.keyOfIndex=function(a){return"#"==a.substr(-1)?this.id_:null};lf.Row.deserialize=function(a){return new lf.Row(a.id,a.value)};lf.Row.create=function(a){return new lf.Row(lf.Row.getNextId(),a||{})};lf.Row.binToHex=function(a){if(!goog.isDefAndNotNull(a))return null;a=new Uint8Array(a);for(var b="",c=0;c<a.length;++c)var d=a[c].toString(16),b=b+(2>d.length?"0"+d:d);return b};
lf.Row.hexToBin=function(a){if(!goog.isDefAndNotNull(a)||""==a)return null;0!=a.length%2&&(a="0"+a);for(var b=new ArrayBuffer(a.length/2),c=new Uint8Array(b),d=0,e=0;d<a.length;d+=2)c[e++]=parseInt(a.substr(d,2),16);return b};lf.schema={};lf.schema.Constraint=function(a,b,c){this.primaryKey_=a;this.notNullable_=b;this.foreignKeys_=c};lf.schema.Constraint.prototype.getPrimaryKey=function(){return this.primaryKey_};lf.schema.Constraint.prototype.getNotNullable=function(){return this.notNullable_};lf.schema.Constraint.prototype.getForeignKeys=function(){return this.foreignKeys_};lf.schema.ForeignKeySpec=function(a,b,c){var d=a.ref.split(".");if(2!=d.length)throw new lf.Exception(540,c);this.childTable=b;this.childColumn=a.local;this.parentTable=d[0];this.parentColumn=d[1];this.name=b+"."+c;this.action=a.action;this.timing=a.timing};lf.schema.Column=function(){};lf.schema.Database=function(){};lf.schema.DataStoreType={};lf.schema.DataStoreType.INDEXED_DB=0;lf.schema.DataStoreType.MEMORY=1;lf.schema.DataStoreType.LOCAL_STORAGE=2;lf.schema.DataStoreType.FIREBASE=3;lf.schema.DataStoreType.WEB_SQL=4;lf.schema.DataStoreType.OBSERVABLE_STORE=5;lf.schema.Index=function(a,b,c,d){this.tableName=a;this.name=b;this.isUnique=c;this.columns=d};lf.schema.Index.prototype.getNormalizedName=function(){return this.tableName+"."+this.name};
lf.schema.Index.prototype.hasNullableColumn=function(){return this.columns.some(function(a){return a.schema.isNullable()})};lf.schema.Table=function(a,b,c,d){this.name_=a;this.indices_=c;this.columns_=b;this.persistentIndex_=d;this.alias_=null};lf.schema.Table.prototype.getName=function(){return this.name_};lf.schema.Table.prototype.getAlias=function(){return this.alias_};lf.schema.Table.prototype.getEffectiveName=function(){return this.alias_||this.name_};
lf.schema.Table.prototype.as=function(a){var b=new this.constructor(this.name_);b.alias_=a;b.referencingForeignKeys_=this.referencingForeignKeys_;return b};lf.schema.Table.prototype.getIndices=function(){return this.indices_};lf.schema.Table.prototype.getColumns=function(){return this.columns_};lf.schema.Table.prototype.persistentIndex=function(){return this.persistentIndex_};lf.schema.Table.ROW_ID_INDEX_PATTERN="#";lf.schema.Table.prototype.getRowIdIndexName=function(){return this.name_+"."+lf.schema.Table.ROW_ID_INDEX_PATTERN};lf.fn={};lf.fn.AggregatedColumn=function(a,b){this.child=a;this.aggregatorType=b;this.alias_=null};lf.fn.AggregatedColumn.prototype.getName=function(){return this.aggregatorType+"("+this.child.getName()+")"};lf.fn.AggregatedColumn.prototype.getNormalizedName=function(){return this.aggregatorType+"("+this.child.getNormalizedName()+")"};lf.fn.AggregatedColumn.prototype.getTable=function(){return this.child.getTable()};lf.fn.AggregatedColumn.prototype.toString=function(){return this.getNormalizedName()};
lf.fn.AggregatedColumn.prototype.getType=function(){return this.child.getType()};lf.fn.AggregatedColumn.prototype.getAlias=function(){return this.alias_};lf.fn.AggregatedColumn.prototype.getIndices=function(){return[]};lf.fn.AggregatedColumn.prototype.getIndex=function(){return null};lf.fn.AggregatedColumn.prototype.isNullable=function(){return!1};lf.fn.AggregatedColumn.prototype.as=function(a){this.alias_=a;return this};
lf.fn.AggregatedColumn.prototype.getColumnChain=function(){for(var a=[this],b=this;b instanceof lf.fn.AggregatedColumn;)a.push(b.child),b=b.child;return a};lf.fn.StarColumn=function(a){this.alias_=a||null;this.table_=new lf.schema.Table("#UnknownTable",[],[],!1)};lf.fn.StarColumn.prototype.getName=function(){return"*"};lf.fn.StarColumn.prototype.getNormalizedName=function(){return this.getName()};lf.fn.StarColumn.prototype.toString=function(){return this.getNormalizedName()};
lf.fn.StarColumn.prototype.getTable=function(){return this.table_};lf.fn.StarColumn.prototype.getType=function(){return lf.Type.NUMBER};lf.fn.StarColumn.prototype.getAlias=function(){return this.alias_};lf.fn.StarColumn.prototype.getIndices=function(){return[]};lf.fn.StarColumn.prototype.getIndex=function(){return null};lf.fn.StarColumn.prototype.isNullable=function(){return!1};lf.fn.Type={AVG:"AVG",COUNT:"COUNT",DISTINCT:"DISTINCT",GEOMEAN:"GEOMEAN",MAX:"MAX",MIN:"MIN",STDDEV:"STDDEV",SUM:"SUM"};lf.fn.avg=function(a){return new lf.fn.AggregatedColumn(a,lf.fn.Type.AVG)};lf.fn.count=function(a){a=a||new lf.fn.StarColumn;return new lf.fn.AggregatedColumn(a,lf.fn.Type.COUNT)};lf.fn.distinct=function(a){return new lf.fn.AggregatedColumn(a,lf.fn.Type.DISTINCT)};lf.fn.max=function(a){return new lf.fn.AggregatedColumn(a,lf.fn.Type.MAX)};
lf.fn.min=function(a){return new lf.fn.AggregatedColumn(a,lf.fn.Type.MIN)};lf.fn.stddev=function(a){return new lf.fn.AggregatedColumn(a,lf.fn.Type.STDDEV)};lf.fn.sum=function(a){return new lf.fn.AggregatedColumn(a,lf.fn.Type.SUM)};lf.fn.geomean=function(a){return new lf.fn.AggregatedColumn(a,lf.fn.Type.GEOMEAN)};lf.service={};lf.service.ServiceId=function(a){this.serviceId_=a};lf.service.ServiceId.prototype.toString=function(){return this.serviceId_};lf.service.BACK_STORE=new lf.service.ServiceId("backstore");lf.service.CACHE=new lf.service.ServiceId("cache");lf.service.INDEX_STORE=new lf.service.ServiceId("indexstore");lf.service.QUERY_ENGINE=new lf.service.ServiceId("engine");lf.service.RUNNER=new lf.service.ServiceId("runner");lf.service.OBSERVER_REGISTRY=new lf.service.ServiceId("observerregistry");
lf.service.SCHEMA=new lf.service.ServiceId("schema");lf.cache.InMemoryUpdater=function(a){this.cache_=a.getService(lf.service.CACHE);this.indexStore_=a.getService(lf.service.INDEX_STORE);this.schema_=a.getService(lf.service.SCHEMA)};lf.cache.InMemoryUpdater.prototype.update=function(a){a.forEach(function(a){this.updateIndicesForDiff_(a);this.updateCacheForDiff_(a)},this)};
lf.cache.InMemoryUpdater.prototype.updateCacheForDiff_=function(a){var b=a.getName();a.getDeleted().forEach(function(a,d){this.cache_.remove(b,d)},this);a.getAdded().forEach(function(a,d){this.cache_.set(b,a)},this);a.getModified().forEach(function(a,d){this.cache_.set(b,a[1])},this)};lf.cache.InMemoryUpdater.prototype.updateIndicesForDiff_=function(a){var b=this.schema_.table(a.getName());a.getAsModifications().forEach(function(a){this.updateTableIndicesForRow(b,a)},this)};
lf.cache.InMemoryUpdater.prototype.updateTableIndicesForRow=function(a,b){var c=this.indexStore_.getTableIndices(a.getName()),d=0;c.forEach(function(a){try{this.updateTableIndexForRow_(a,b),d++}catch(f){throw c.slice(0,d).forEach(function(a){this.updateTableIndexForRow_(a,[b[1],b[0]])},this),f;}},this)};
lf.cache.InMemoryUpdater.prototype.updateTableIndexForRow_=function(a,b){var c=goog.isNull(b[1])?void 0:b[1].keyOfIndex(a.getName()),d=goog.isNull(b[0])?void 0:b[0].keyOfIndex(a.getName());if(!goog.isDef(d)&&goog.isDef(c))a.add(c,b[1].id());else if(goog.isDef(d)&&goog.isDef(c)){if(goog.isNull(c)||goog.isNull(d)){if(c==d)return}else if(a.comparator().compare(d,c)==lf.index.Favor.TIE)return;a.add(c,b[1].id());a.remove(d,b[0].id())}else goog.isDef(d)&&!goog.isDef(c)&&a.remove(d,b[0].id())};lf.structs={};lf.structs.array={};lf.structs.array.binarySearch_=function(a,b,c){var d=0,e=a.length;for(c=c||lf.structs.array.defaultComparator_;d<e;){var f=d+e>>1;0>c(a[f],b)?d=f+1:e=f}return d==e&&a[d]==b?d:~d};lf.structs.array.defaultComparator_=function(a,b){return a-b};lf.structs.array.binaryInsert=function(a,b,c){c=lf.structs.array.binarySearch_(a,b,c);return 0>c?(a.splice(-(c+1),0,b),!0):!1};
lf.structs.array.binaryRemove=function(a,b,c){b=lf.structs.array.binarySearch_(a,b,c);if(0>b)return!1;a.splice(b,1);return!0};lf.index.BTree=function(a,b,c,d){this.name_=a;this.comparator_=b;this.uniqueKeyOnly_=c;this.stats_=new lf.index.Stats;d?this.root_=lf.index.BTreeNode_.fromData(this,d):this.clear()};lf.index.BTree.EMPTY=[];lf.index.BTree.prototype.getName=function(){return this.name_};lf.index.BTree.prototype.toString=function(){return this.root_.toString()};lf.index.BTree.prototype.add=function(a,b){this.root_=this.root_.insert(a,b)};lf.index.BTree.prototype.set=function(a,b){this.root_=this.root_.insert(a,b,!0)};
lf.index.BTree.prototype.remove=function(a,b){this.root_=this.root_.remove(a,b)};lf.index.BTree.prototype.get=function(a){return this.root_.get(a)};lf.index.BTree.prototype.cost=function(a){if(!goog.isDefAndNotNull(a))return this.stats().totalRows;if(a instanceof lf.index.SingleKeyRange){if(a.isAll())return this.stats().totalRows;if(a.isOnly())return this.get(a.from).length}return this.getRange([a]).length};lf.index.BTree.prototype.stats=function(){return this.stats_};
lf.index.BTree.prototype.getAll_=function(a,b,c,d){c=Array(a);this.root_.fill({offset:b?this.stats_.totalRows-a-d:d,count:a,startIndex:0},c);return b?c.reverse():c};
lf.index.BTree.prototype.getRange=function(a,b,c,d){var e=this.root_.getLeftMostNode().keys_[0];if(!goog.isDef(e)||0==c)return lf.index.BTree.EMPTY;b=b||!1;c=goog.isDefAndNotNull(c)?Math.min(c,this.stats_.totalRows):this.stats_.totalRows;d=d||0;var f=Math.min(Math.max(this.stats_.totalRows-d,0),c);if(0==f)return lf.index.BTree.EMPTY;if(!goog.isDef(a)||1==a.length&&a[0]instanceof lf.index.SingleKeyRange&&a[0].isAll())return this.getAll_(f,b,c,d);a=this.comparator_.sortKeyRanges(a);var g=Array(b?this.stats_.totalRows:
f),h={count:0,limit:g.length,reverse:b,skip:d},k=1<this.comparator().keyDimensions();a.forEach(function(a){for(var b=this.comparator_.rangeToKeys(a),b=this.comparator_.isLeftOpen(a)?e:b[0],b=this.root_.getContainingLeaf(b),c=0;goog.isDefAndNotNull(b)&&h.count<h.limit;)k?b.getRangeWithFilter(a,h,g):b.getRange(a,h,g),0!=h.skip||b.isFirstKeyInRange(a)?c=0:c++,b=2==c?null:b.next()},this);g.length>h.count&&g.splice(h.count,g.length-h.count);return b?lf.index.slice(g,b,c,d):g};
lf.index.BTree.prototype.clear=function(){this.root_=lf.index.BTreeNode_.create(this);this.stats_.clear()};lf.index.BTree.prototype.containsKey=function(a){return this.root_.containsKey(a)};lf.index.BTree.prototype.min=function(){return this.minMax_(this.comparator_.min.bind(this.comparator_))};lf.index.BTree.prototype.max=function(){return this.minMax_(this.comparator_.max.bind(this.comparator_))};
lf.index.BTree.prototype.checkNullKey_=function(a,b){if(!this.comparator_.comparable(a.keys_[b]))if(1<a.keys_[b].length){if(goog.isNull(a.keys_[b][0]))return null}else return null;return[a.keys_[b],this.uniqueKeyOnly_?[a.values_[b]]:a.values_[b]]};lf.index.BTree.prototype.findLeftMost_=function(){var a=this.root_.getLeftMostNode(),b=0;do if(b>=a.keys_.length)a=a.next_,b=0;else{var c=this.checkNullKey_(a,b);if(!goog.isNull(c))return c;b++}while(!goog.isNull(a));return null};
lf.index.BTree.prototype.findRightMost_=function(){var a=this.root_.getRightMostNode(),b=a.keys_.length-1;do if(0>b)a=a.prev_,b=0;else{var c=this.checkNullKey_(a,b);if(!goog.isNull(c))return c;b--}while(!goog.isNull(a));return null};lf.index.BTree.prototype.minMax_=function(a){var b=this.findLeftMost_(),c=this.findRightMost_();return goog.isNull(b)||goog.isNull(c)?null:a(b[0],c[0])==lf.index.Favor.LHS?b:c};lf.index.BTree.prototype.isUniqueKey=function(){return this.uniqueKeyOnly_};
lf.index.BTree.prototype.comparator=function(){return this.comparator_};lf.index.BTree.prototype.eq=function(a,b){return goog.isDefAndNotNull(a)?this.comparator_.compare(a,b)==lf.index.Favor.TIE:!1};lf.index.BTree.prototype.serialize=function(){var a=this.root_.getLeftMostNode();return lf.index.BTreeNode_.serialize(a)};lf.index.BTree.deserialize=function(a,b,c,d){a=new lf.index.BTree(b,a,c);d=lf.index.BTreeNode_.deserialize(d,a);a.root_=d;return a};
lf.index.BTreeNode_=function(a,b){this.id_=a;this.tree_=b;this.height_=0;this.next_=this.prev_=this.parent_=null;this.keys_=[];this.values_=[];this.children_=[];this.getContainingLeaf=1==b.comparator().keyDimensions()?this.getContainingLeaf_:this.getContainingLeafMultiKey_};lf.index.BTreeNode_.MAX_COUNT_=512;lf.index.BTreeNode_.MAX_KEY_LEN_=lf.index.BTreeNode_.MAX_COUNT_-1;lf.index.BTreeNode_.MIN_KEY_LEN_=lf.index.BTreeNode_.MAX_COUNT_>>1;
lf.index.BTreeNode_.create=function(a){return new lf.index.BTreeNode_(lf.Row.getNextId(),a)};lf.index.BTreeNode_.prototype.isLeaf_=function(){return 0==this.height_};lf.index.BTreeNode_.prototype.isRoot_=function(){return goog.isNull(this.parent_)};lf.index.BTreeNode_.prototype.next=function(){return this.next_};
lf.index.BTreeNode_.dumpLevel_=function(a){var b=a.id_+"["+a.keys_.join("|")+"]",c=a.children_.map(function(a){return a.id_}).join("|"),d=a.values_.join("/"),e=function(a){return goog.isDefAndNotNull(a)?a.id_.toString():"_"},f=e(a.prev_)+"{",f=a.isLeaf_()?f+d:f+c,f=f+"}"+e(a.parent_);a.next_&&(a=lf.index.BTreeNode_.dumpLevel_(a.next_),b=b+" "+a[0],f=f+" "+a[1]);return[b,f]};
lf.index.BTreeNode_.prototype.toString=function(){var a="",b=lf.index.BTreeNode_.dumpLevel_(this),a=a+(b[0]+"\n"+b[1]+"\n");this.children_.length&&(a+=this.children_[0].toString());return a};lf.index.BTreeNode_.prototype.getLeftMostNode=function(){return this.isLeaf_()?this:this.children_[0].getLeftMostNode()};lf.index.BTreeNode_.prototype.getRightMostNode=function(){return this.isLeaf_()?this:this.children_[this.children_.length-1].getRightMostNode()};
lf.index.BTreeNode_.associate_=function(a,b){b&&(b.prev_=a);a&&(a.next_=b)};lf.index.BTreeNode_.calcNodeLen_=function(a){var b=lf.index.BTreeNode_.MAX_KEY_LEN_,c=lf.index.BTreeNode_.MIN_KEY_LEN_+1;return a>=b+c?b:a>=c&&a<=b?a:c};
lf.index.BTreeNode_.createLeaves_=function(a,b){for(var c=b.length,d=0,e=lf.index.BTreeNode_.create(a),f=e;0<c;){var g=lf.index.BTreeNode_.calcNodeLen_(c),h=b.slice(d,d+g);e.keys_=h.map(function(a){return a.key});e.values_=h.map(function(a){return a.value});d+=g;c-=g;0<c&&(g=lf.index.BTreeNode_.create(e.tree_),lf.index.BTreeNode_.associate_(e,g),e=g)}return f};
lf.index.BTreeNode_.createParent_=function(a){var b=a[0],c=lf.index.BTreeNode_.create(b.tree_);c.height_=b.height_+1;c.children_=a;for(b=0;b<a.length;++b)a[b].parent_=c,0<b&&c.keys_.push(a[b].keys_[0]);return c};
lf.index.BTreeNode_.createInternals_=function(a){var b=a,c=[];do c.push(b),b=b.next_;while(b);if(c.length<=lf.index.BTreeNode_.MAX_KEY_LEN_+1)b=lf.index.BTreeNode_.createParent_(c);else{var d=c.length,e=0,b=lf.index.BTreeNode_.create(a.tree_);for(b.height_=a.height_+2;0<d;){a=lf.index.BTreeNode_.calcNodeLen_(d);var f=c.slice(e,e+a),g=lf.index.BTreeNode_.createParent_(f);g.parent_=b;b.children_.length&&(b.keys_.push(f[0].keys_[0]),lf.index.BTreeNode_.associate_(b.children_[b.children_.length-1],g));
b.children_.push(g);e+=a;d-=a}}return b};lf.index.BTreeNode_.fromData=function(a,b){var c=lf.index.BTreeNode_.MAX_KEY_LEN_,c=c*c*c;if(b.length>=c)throw new lf.Exception(6,c);c=lf.index.BTreeNode_.createLeaves_(a,b);return c=lf.index.BTreeNode_.createInternals_(c)};lf.index.BTreeNode_.prototype.get=function(a){var b=this.searchKey_(a);if(this.isLeaf_()){var c=lf.index.BTree.EMPTY;this.tree_.eq(this.keys_[b],a)&&(c=c.concat(this.values_[b]));return c}b=this.tree_.eq(this.keys_[b],a)?b+1:b;return this.children_[b].get(a)};
lf.index.BTreeNode_.prototype.containsKey=function(a){var b=this.searchKey_(a);return this.tree_.eq(this.keys_[b],a)?!0:this.isLeaf_()?!1:this.children_[b].containsKey(a)};lf.index.BTreeNode_.prototype.remove=function(a,b){this.delete_(a,-1,b);if(this.isRoot_()){var c=this;1==this.children_.length&&(c=this.children_[0],c.parent_=null);return c}return this};lf.index.BTreeNode_.leftMostKey_=function(a){return a.isLeaf_()?a.keys_[0]:lf.index.BTreeNode_.leftMostKey_(a.children_[0])};
lf.index.BTreeNode_.prototype.fix_=function(){this.keys_=[];for(var a=1;a<this.children_.length;++a)this.keys_.push(lf.index.BTreeNode_.leftMostKey_(this.children_[a]))};
lf.index.BTreeNode_.prototype.delete_=function(a,b,c){var d=this.searchKey_(a),e=this.isLeaf_();if(!e){var f=this.tree_.eq(this.keys_[d],a)?d+1:d;if(this.children_[f].delete_(a,f,c))this.fix_();else return!1}else if(!this.tree_.eq(this.keys_[d],a))return!1;if(this.keys_.length>d&&this.tree_.eq(this.keys_[d],a)){if(goog.isDef(c)&&!this.tree_.isUniqueKey()&&e&&(lf.structs.array.binaryRemove(this.values_[d],c)&&this.tree_.stats().remove(a,1),this.values_[d].length))return!1;this.keys_.splice(d,1);e&&
(c=this.tree_.isUniqueKey()?1:this.values_[d].length,this.values_.splice(d,1),this.tree_.stats().remove(a,c))}this.keys_.length<lf.index.BTreeNode_.MIN_KEY_LEN_&&!this.isRoot_()&&(this.steal_()||this.merge_(b));return!0};
lf.index.BTreeNode_.prototype.steal_=function(){var a=null,b,c,d;if(this.next_&&this.next_.keys_.length>lf.index.BTreeNode_.MIN_KEY_LEN_)a=this.next_,c=b=0,d=this.keys_.length+1;else if(this.prev_&&this.prev_.keys_.length>lf.index.BTreeNode_.MIN_KEY_LEN_)a=this.prev_,b=this.prev_.keys_.length-1,c=this.isLeaf_()?b:b+1,d=0;else return!1;this.keys_.splice(d,0,a.keys_[b]);a.keys_.splice(b,1);b=this.isLeaf_()?this.values_:this.children_;var e=null;this.isLeaf_()?e=a.values_:(e=a.children_,e[c].parent_=
this);b.splice(d,0,e[c]);e.splice(c,1);a.isLeaf_()||(a.fix_(),this.fix_());return!0};
lf.index.BTreeNode_.prototype.merge_=function(a){var b,c,d;this.next_&&this.next_.keys_.length<lf.index.BTreeNode_.MAX_KEY_LEN_?(b=this.next_,d=c=0):this.prev_&&(b=this.prev_,c=b.keys_.length,d=b.isLeaf_()?b.values_.length:b.children_.length);c=[c,0].concat(this.keys_);Array.prototype.splice.apply(b.keys_,c);c=null;this.isLeaf_()?c=this.values_:(c=this.children_,c.forEach(function(a){a.parent_=b}));c=[d,0].concat(c);Array.prototype.splice.apply(b.isLeaf_()?b.values_:b.children_,c);lf.index.BTreeNode_.associate_(this.prev_,
this.next_);b.isLeaf_()||b.fix_();-1!=a&&(this.parent_.keys_.splice(a,1),this.parent_.children_.splice(a,1))};
lf.index.BTreeNode_.prototype.insert=function(a,b,c){var d=this.searchKey_(a);if(this.isLeaf_()){if(this.tree_.eq(this.keys_[d],a)){if(c)this.tree_.stats().remove(a,this.tree_.isUniqueKey()?1:this.values_[d].length),this.values_[d]=this.tree_.isUniqueKey()?b:[b];else{if(this.tree_.isUniqueKey())throw new lf.Exception(201);if(!lf.structs.array.binaryInsert(this.values_[d],b))throw new lf.Exception(109);}this.tree_.stats().add(a,1);return this}this.keys_.splice(d,0,a);this.values_.splice(d,0,this.tree_.isUniqueKey()?
b:[b]);this.tree_.stats().add(a,1);return this.keys_.length==lf.index.BTreeNode_.MAX_COUNT_?this.splitLeaf_():this}d=this.tree_.eq(this.keys_[d],a)?d+1:d;a=this.children_[d].insert(a,b,c);a.isLeaf_()||1!=a.keys_.length||(this.keys_.splice(d,0,a.keys_[0]),a.children_[1].parent_=this,a.children_[0].parent_=this,this.children_.splice(d,1,a.children_[1]),this.children_.splice(d,0,a.children_[0]));return this.keys_.length==lf.index.BTreeNode_.MAX_COUNT_?this.splitInternal_():this};
lf.index.BTreeNode_.prototype.splitLeaf_=function(){var a=lf.index.BTreeNode_.MIN_KEY_LEN_,b=lf.index.BTreeNode_.create(this.tree_),c=lf.index.BTreeNode_.create(this.tree_);c.height_=1;c.keys_=[this.keys_[a]];c.children_=[this,b];c.parent_=this.parent_;this.parent_=c;b.keys_=this.keys_.splice(a);b.values_=this.values_.splice(a);b.parent_=c;lf.index.BTreeNode_.associate_(b,this.next_);lf.index.BTreeNode_.associate_(this,b);return c};
lf.index.BTreeNode_.prototype.splitInternal_=function(){var a=lf.index.BTreeNode_.MIN_KEY_LEN_,b=lf.index.BTreeNode_.create(this.tree_),c=lf.index.BTreeNode_.create(this.tree_);b.parent_=this.parent_;b.height_=this.height_+1;b.keys_=[this.keys_[a]];b.children_=[this,c];this.keys_.splice(a,1);c.parent_=b;c.height_=this.height_;c.keys_=this.keys_.splice(a);c.children_=this.children_.splice(a+1);c.children_.forEach(function(a){a.parent_=c});this.parent_=b;lf.index.BTreeNode_.associate_(c,this.next_);
lf.index.BTreeNode_.associate_(this,c);return b};lf.index.BTreeNode_.prototype.searchKey_=function(a){for(var b=0,c=this.keys_.length,d=this.tree_.comparator();b<c;){var e=b+c>>1;d.compare(this.keys_[e],a)==lf.index.Favor.RHS?b=e+1:c=e}return b};lf.index.BTreeNode_.prototype.getContainingLeaf_=function(a){if(!this.isLeaf_()){var b=this.searchKey_(a);this.tree_.eq(this.keys_[b],a)&&b++;return this.children_[b].getContainingLeaf_(a)}return this};
lf.index.BTreeNode_.prototype.getContainingLeafMultiKey_=function(a){if(!this.isLeaf_()){var b=this.searchKey_(a);this.tree_.eq(this.keys_[b],a)&&(a.some(function(a){return a==lf.index.SingleKeyRange.UNBOUND_VALUE})||b++);return this.children_[b].getContainingLeafMultiKey_(a)}return this};
lf.index.BTreeNode_.prototype.getRange=function(a,b,c){var d=this.tree_.comparator(),e=0,f=this.keys_.length-1,g=function(a){return a[0]?a[1]?lf.index.Favor.TIE:lf.index.Favor.LHS:lf.index.Favor.RHS},h=this.keys_,k=g(d.compareRange(h[e],a)),n=g(d.compareRange(h[f],a));if(k!=lf.index.Favor.LHS&&(k!=lf.index.Favor.RHS||n!=lf.index.Favor.RHS)){var l=function(a,b){var c=a+b>>1;return c==a?c+1:c},m=function(b,c,e){if(b>=c)return e==lf.index.Favor.TIE?c:-1;var f=g(d.compareRange(h[b],a));if(f==lf.index.Favor.TIE)return b;
if(f==lf.index.Favor.LHS)return-1;f=l(b,c);if(f==c)return e==lf.index.Favor.TIE?c:-1;var k=g(d.compareRange(h[f],a));return k==lf.index.Favor.TIE?m(b,f,k):k==lf.index.Favor.RHS?m(f+1,c,e):m(b+1,f,k)},p=function(b,c){if(b>=c)return b;var e=g(d.compareRange(h[c],a));if(e==lf.index.Favor.TIE)return c;if(e==lf.index.Favor.RHS)return b;e=l(b,c);if(e==c)return b;var f=g(d.compareRange(h[e],a));return f==lf.index.Favor.TIE?p(e,c):f==lf.index.Favor.LHS?p(b,e-1):-1};k!=lf.index.Favor.TIE&&(e=m(e+1,f,n));-1!=
e&&(f=p(e,f),-1!=f&&f>=e&&this.appendResults_(b,c,e,f+1))}};lf.index.BTreeNode_.prototype.appendResultsAt_=function(a,b,c){if(this.tree_.isUniqueKey())!a.reverse&&a.skip?a.skip--:b[a.count++]=this.values_[c];else for(var d=0;d<this.values_[c].length&&a.count<b.length;++d)!a.reverse&&a.skip?a.skip--:b[a.count++]=this.values_[c][d]};lf.index.BTreeNode_.prototype.appendResults_=function(a,b,c,d){for(;c<d&&(a.reverse||!(a.count>=a.limit));++c)this.appendResultsAt_(a,b,c)};
lf.index.BTreeNode_.prototype.getRangeWithFilter=function(a,b,c){for(var d=this.tree_.comparator(),e=-1,f=0;f<this.keys_.length;++f)if(d.isInRange(this.keys_[f],a)){e=f;break}if(-1!=e)for(f=e;f<this.keys_.length&&b.count<b.limit;++f)d.isInRange(this.keys_[f],a)&&this.appendResultsAt_(b,c,f)};
lf.index.BTreeNode_.prototype.fill=function(a,b){if(this.isLeaf_())for(var c=0;c<this.values_.length&&0<a.count;++c)if(0<a.offset){if(a.offset-=this.tree_.isUniqueKey()?1:this.values_[c].length,0>a.offset)for(var d=this.values_[c].length+a.offset;d<this.values_[c].length&&0<a.count;++d)b[a.startIndex++]=this.values_[c][d],a.count--}else if(this.tree_.isUniqueKey())b[a.startIndex++]=this.values_[c],a.count--;else for(d=0;d<this.values_[c].length&&0<a.count;++d)b[a.startIndex++]=this.values_[c][d],
a.count--;else for(c=0;c<this.children_.length&&0<a.count;++c)this.children_[c].fill(a,b)};lf.index.BTreeNode_.serialize=function(a){for(var b=[];a;)b.push(new lf.Row(a.id_,[a.keys_,a.values_])),a=a.next_;return b};
lf.index.BTreeNode_.deserialize=function(a,b){for(var c=b.stats(),d=a.map(function(a){var d=new lf.index.BTreeNode_(a.id(),b);d.keys_=a.payload()[0];d.values_=a.payload()[1];d.keys_.forEach(function(a,e){c.add(a,b.isUniqueKey()?1:d.values_[e].length)});return d}),e=0;e<d.length-1;++e)lf.index.BTreeNode_.associate_(d[e],d[e+1]);return 1<d.length?lf.index.BTreeNode_.createInternals_(d[0]):d[0]};
lf.index.BTreeNode_.prototype.isFirstKeyInRange=function(a){return this.tree_.comparator().isFirstKeyInRange(this.keys_[0],a)};lf.structs.map={};$jscomp.scope.detectUseNative=function(){return lf.Flags.NATIVE_ES6||lf.Capability.get().nativeMap};lf.structs.MapPolyFill_=function(){this.map_=new goog.structs.Map;Object.defineProperty(this,"size",{get:function(){return this.map_.getCount()}})};lf.structs.MapPolyFill_.prototype.clear=function(){this.map_.clear()};lf.structs.MapPolyFill_.prototype.delete=function(a){return this.map_.remove(a)};lf.structs.MapPolyFill_.prototype.forEach=function(a,b){return this.map_.forEach(a,b)};
lf.structs.MapPolyFill_.prototype.get=function(a){return this.map_.get(a)};lf.structs.MapPolyFill_.prototype.has=function(a){return this.map_.containsKey(a)};lf.structs.MapPolyFill_.prototype.set=function(a,b){return this.map_.set(a,b)};$jscomp.scope.USE_NATIVE=(0,$jscomp.scope.detectUseNative)();lf.structs.map.create=function(){return $jscomp.scope.USE_NATIVE?new window.Map:new lf.structs.MapPolyFill_};
lf.structs.map.keys=function(a){if(a instanceof lf.structs.MapPolyFill_)return a.map_.getKeys();var b=0,c=Array(a.size);a.forEach(function(a,e){c[b++]=e});return c};lf.structs.map.values=function(a){if(a instanceof lf.structs.MapPolyFill_)return a.map_.getValues();var b=0,c=Array(a.size);a.forEach(function(a,e){c[b++]=a});return c};lf.backstore.FirebaseRawBackStore=function(a,b){this.version_=a;this.db_=b;this.tableIds_=lf.structs.map.create()};lf.backstore.FirebaseRawBackStore.prototype.getRawDBInstance=function(){return this.db_};lf.backstore.FirebaseRawBackStore.prototype.getRawTransaction=function(){throw new lf.Exception(351);};lf.backstore.FirebaseRawBackStore.getValue=function(a,b){var c=goog.Promise.withResolver(),d=a;b.length&&(d=a.child(b));d.once("value",function(a){c.resolve(a.val())},function(a){c.reject(a)});return c.promise};
lf.backstore.FirebaseRawBackStore.setValue=function(a,b,c){c=c||!1;var d=goog.Promise.withResolver(),e=function(a){a?d.reject(a):d.resolve()};c?a.set(b,e):a.update(b,e);return d.promise};
lf.backstore.FirebaseRawBackStore.prototype.init=function(a){return lf.backstore.FirebaseRawBackStore.getValue(this.db_,"@rev/R").then(function(a){this.revision_=a;return lf.backstore.FirebaseRawBackStore.getValue(this.db_,"@table")}.bind(this)).then(function(b){var c=0,d;for(d in b)this.tableIds_.set(d,b[d]),b[d]>c&&(c=b[d]);a.tables().forEach(function(a){this.tableIds_.has(a.getName())||(b[a.getName()]=++c)},this);d=this.db_.child("@table");return lf.backstore.FirebaseRawBackStore.setValue(d,b)}.bind(this))};
lf.backstore.FirebaseRawBackStore.prototype.transform_=function(a,b){var c=this.tableIds_.get(a);return goog.isDefAndNotNull(c)?function(){var a={},e=goog.Promise.withResolver();this.db_.orderByChild("T").equalTo(c).once("value",function(c){c.forEach(function(c){var e=b(c.val());a[parseInt(c.key(),10)]=e});e.resolve(a)});return e.promise}.call(this).then(function(a){a["@rev"]={R:++this.revision_};return lf.backstore.FirebaseRawBackStore.setValue(this.db_,a)}.bind(this)):goog.Promise.resolve()};
lf.backstore.FirebaseRawBackStore.prototype.dropTable=function(a){return this.transform_(a,function(a){return null}).then(function(){this.tableIds_.delete(a);return lf.backstore.FirebaseRawBackStore.setValue(this.db_.child("@table/"+a),null,!0)}.bind(this))};lf.backstore.FirebaseRawBackStore.prototype.addTableColumn=function(a,b,c){return this.transform_(a,function(a){var e=a.P;e[b]=c;return{R:this.revision_+1,T:a.T,P:e}}.bind(this))};
lf.backstore.FirebaseRawBackStore.prototype.dropTableColumn=function(a,b){return this.transform_(a,function(a){var d=a.P;delete d[b];return{R:this.revision_+1,T:a.T,P:d}}.bind(this))};lf.backstore.FirebaseRawBackStore.prototype.renameTableColumn=function(a,b,c){return this.transform_(a,function(a){var e=a.P;e[c]=e[b];delete e[b];return{R:this.revision_+1,T:a.T,P:e}}.bind(this))};lf.backstore.FirebaseRawBackStore.prototype.createRow=function(a){throw new lf.Exception(351);};
lf.backstore.FirebaseRawBackStore.prototype.getVersion=function(){return this.version_};lf.backstore.FirebaseRawBackStore.prototype.dumpTable_=function(a){var b=goog.Promise.withResolver();a=this.tableIds_.get(a);this.db_.orderByChild("T").equalTo(a).once("value",function(a){var d=[];a.forEach(function(a){d.push(a.val().P)});b.resolve(d)});return b.promise};
lf.backstore.FirebaseRawBackStore.prototype.dump=function(){var a={},b=lf.structs.map.keys(this.tableIds_).map(function(b){return this.dumpTable_(b).then(function(d){a[b]=d})}.bind(this));return goog.Promise.all(b).then(function(){return a})};lf.cache.TableDiff=function(a){this.added_=lf.structs.map.create();this.modified_=lf.structs.map.create();this.deleted_=lf.structs.map.create();this.name_=a};lf.cache.TableDiff.prototype.getName=function(){return this.name_};lf.cache.TableDiff.prototype.getAdded=function(){return this.added_};lf.cache.TableDiff.prototype.getModified=function(){return this.modified_};lf.cache.TableDiff.prototype.getDeleted=function(){return this.deleted_};
lf.cache.TableDiff.prototype.add=function(a){if(this.deleted_.has(a.id())){var b=[this.deleted_.get(a.id()),a];this.modified_.set(a.id(),b);this.deleted_.delete(a.id())}else this.added_.set(a.id(),a)};lf.cache.TableDiff.prototype.modify=function(a){var b=a[0],c=a[1];goog.asserts.assert(b.id()==c.id(),"Row ID mismatch between old/new values.");b=b.id();this.added_.has(b)?this.added_.set(b,c):(this.modified_.has(b)&&(a=[this.modified_.get(a[0].id())[0],c]),this.modified_.set(b,a))};
lf.cache.TableDiff.prototype.delete=function(a){if(this.added_.has(a.id()))this.added_.delete(a.id());else if(this.modified_.has(a.id())){var b=this.modified_.get(a.id())[0];this.modified_.delete(a.id());this.deleted_.set(a.id(),b)}else this.deleted_.set(a.id(),a)};lf.cache.TableDiff.prototype.merge=function(a){a.added_.forEach(function(a,c){this.add(a)},this);a.modified_.forEach(function(a,c){this.modify(a)},this);a.deleted_.forEach(function(a,c){this.delete(a)},this)};
lf.cache.TableDiff.prototype.getAsModifications=function(){var a=[];this.added_.forEach(function(b,c){a.push([null,b])});this.modified_.forEach(function(b,c){a.push(b)});this.deleted_.forEach(function(b,c){a.push([b,null])});return a};lf.cache.TableDiff.prototype.toString=function(){return"["+lf.structs.map.keys(this.added_).toString()+"], ["+lf.structs.map.keys(this.modified_).toString()+"], ["+lf.structs.map.keys(this.deleted_).toString()+"]"};
lf.cache.TableDiff.prototype.getReverse=function(){var a=new lf.cache.TableDiff(this.name_);this.added_.forEach(function(b,c){a.delete(b)});this.deleted_.forEach(function(b,c){a.add(b)});this.modified_.forEach(function(b,c){a.modify([b[1],b[0]])});return a};lf.cache.TableDiff.prototype.isEmpty=function(){return 0==this.added_.size&&0==this.deleted_.size&&0==this.modified_.size};lf.eval={};lf.eval.Type={BETWEEN:"between",EQ:"eq",GTE:"gte",GT:"gt",IN:"in",LTE:"lte",LT:"lt",MATCH:"match",NEQ:"neq"};
lf.eval.Registry=function(){this.keyOfIndexConversionMap_=lf.eval.buildKeyOfIndexConversionMap_();var a=lf.eval.buildNumberEvaluatorMap_();this.evalMaps_=lf.structs.map.create();this.evalMaps_.set(lf.Type.BOOLEAN,lf.eval.buildBooleanEvaluatorMap_());this.evalMaps_.set(lf.Type.DATE_TIME,lf.eval.buildDateEvaluatorMap_());this.evalMaps_.set(lf.Type.NUMBER,a);this.evalMaps_.set(lf.Type.INTEGER,a);this.evalMaps_.set(lf.Type.STRING,lf.eval.buildStringEvaluatorMap_())};
lf.eval.Registry.get=function(){goog.isDefAndNotNull(lf.eval.Registry.instance_)||(lf.eval.Registry.instance_=new lf.eval.Registry);return lf.eval.Registry.instance_};lf.eval.Registry.prototype.getEvaluator=function(a,b){var c=this.evalMaps_.get(a)||null;goog.asserts.assert(!goog.isNull(c),"Could not find evaluation map for "+a);c=c.get(b)||null;goog.asserts.assert(!goog.isNull(c),"Could not find evaluator for "+a+", "+b);return c};
lf.eval.Registry.prototype.getKeyOfIndexEvaluator=function(a){var b=this.keyOfIndexConversionMap_.get(a)||null;goog.asserts.assert(!goog.isNull(b),"Could not find keyOfIndex evaluation function for "+a);return b};
lf.eval.buildKeyOfIndexConversionMap_=function(){var a=lf.structs.map.create();a.set(lf.Type.BOOLEAN,function(a){return goog.isNull(a)?null:a?1:0});a.set(lf.Type.DATE_TIME,function(a){return goog.isNull(a)?null:a.getTime()});var b=function(a){return a};a.set(lf.Type.INTEGER,b);a.set(lf.Type.NUMBER,b);a.set(lf.Type.STRING,b);return a};
lf.eval.buildBooleanEvaluatorMap_=function(){var a=lf.structs.map.create();a.set(lf.eval.Type.EQ,function(a,c){return a==c});a.set(lf.eval.Type.NEQ,function(a,c){return a!=c});return a};
lf.eval.buildCommonEvaluatorMap_=function(){var a=lf.eval.buildBooleanEvaluatorMap_();a.set(lf.eval.Type.BETWEEN,function(a,c){return goog.isNull(a)||goog.isNull(c[0])||goog.isNull(c[1])?!1:a>=c[0]&&a<=c[1]});a.set(lf.eval.Type.GTE,function(a,c){return goog.isNull(a)||goog.isNull(c)?!1:a>=c});a.set(lf.eval.Type.GT,function(a,c){return goog.isNull(a)||goog.isNull(c)?!1:a>c});a.set(lf.eval.Type.IN,function(a,c){return-1!=c.indexOf(a)});a.set(lf.eval.Type.LTE,function(a,c){return goog.isNull(a)||goog.isNull(c)?
!1:a<=c});a.set(lf.eval.Type.LT,function(a,c){return goog.isNull(a)||goog.isNull(c)?!1:a<c});return a};lf.eval.buildNumberEvaluatorMap_=function(){return lf.eval.buildCommonEvaluatorMap_()};lf.eval.buildStringEvaluatorMap_=function(){var a=lf.eval.buildCommonEvaluatorMap_();a.set(lf.eval.Type.MATCH,function(a,c){return goog.isNull(a)||goog.isNull(c)?!1:(new RegExp(c)).test(a)});return a};
lf.eval.buildDateEvaluatorMap_=function(){var a=lf.structs.map.create();a.set(lf.eval.Type.BETWEEN,function(a,c){return goog.isNull(a)||goog.isNull(c[0])||goog.isNull(c[1])?!1:a.getTime()>=c[0].getTime()&&a.getTime()<=c[1].getTime()});a.set(lf.eval.Type.EQ,function(a,c){var d=goog.isNull(a)?-1:a.getTime(),e=goog.isNull(c)?-1:c.getTime();return d==e});a.set(lf.eval.Type.GTE,function(a,c){return goog.isNull(a)||goog.isNull(c)?!1:a.getTime()>=c.getTime()});a.set(lf.eval.Type.GT,function(a,c){return goog.isNull(a)||
goog.isNull(c)?!1:a.getTime()>c.getTime()});a.set(lf.eval.Type.IN,function(a,c){return c.some(function(c){return c.getTime()==a.getTime()})});a.set(lf.eval.Type.LTE,function(a,c){return goog.isNull(a)||goog.isNull(c)?!1:a.getTime()<=c.getTime()});a.set(lf.eval.Type.LT,function(a,c){return goog.isNull(a)||goog.isNull(c)?!1:a.getTime()<c.getTime()});a.set(lf.eval.Type.NEQ,function(a,c){var d=goog.isNull(a)?-1:a.getTime(),e=goog.isNull(c)?-1:c.getTime();return d!=e});return a};lf.DiffCalculator=function(a,b){this.evalRegistry_=lf.eval.Registry.get();this.query_=a;this.observableResults_=b;this.columns_=this.detectColumns_()};lf.DiffCalculator.prototype.detectColumns_=function(){if(0<this.query_.columns.length)return this.query_.columns;var a=[];this.query_.from.forEach(function(b){b.getColumns().forEach(function(b){a.push(b)})});return a};
lf.DiffCalculator.prototype.comparator_=function(a,b){return this.columns_.every(function(c){return this.evalRegistry_.getEvaluator(c.getType(),lf.eval.Type.EQ)(a.getField(c),b.getField(c))},this)};
lf.DiffCalculator.prototype.applyDiff=function(a,b){for(var c=goog.isNull(a)?[]:a.entries,d=goog.math.longestCommonSubsequence(c,b.entries,this.comparator_.bind(this),function(a,b){return c[a]}),e=[],f=0,g=0;g<c.length;g++){var h=c[g];d[f]==h?f++:(h=this.observableResults_.splice(f,1),h=lf.DiffCalculator.createChangeRecord_(g,h,0,this.observableResults_),e.push(h))}d=goog.math.longestCommonSubsequence(c,b.entries,this.comparator_.bind(this),function(a,c){return b.entries[c]});for(g=f=0;g<b.entries.length;g++)h=
b.entries[g],d[f]==h?f++:(this.observableResults_.splice(g,0,h.row.payload()),h=lf.DiffCalculator.createChangeRecord_(g,[],1,this.observableResults_),e.push(h));return e};lf.DiffCalculator.createChangeRecord_=function(a,b,c,d){return{addedCount:c,index:a,object:d,removed:b,type:"splice"}};lf.Global=function(){this.services_=lf.structs.map.create()};lf.Global.get=function(){lf.Global.instance_||(lf.Global.instance_=new lf.Global);return lf.Global.instance_};lf.Global.prototype.clear=function(){this.services_.clear()};lf.Global.prototype.registerService=function(a,b){this.services_.set(a.toString(),b);return b};lf.Global.prototype.getService=function(a){var b=this.services_.get(a.toString())||null;if(goog.isNull(b))throw new lf.Exception(7,a.toString());return b};
lf.Global.prototype.isRegistered=function(a){return this.services_.has(a.toString())};lf.Global.prototype.listServices=function(){return lf.structs.map.keys(this.services_)};lf.debug={};lf.debug.inspect=function(a,b,c,d){return goog.isDefAndNotNull(a)?goog.isDefAndNotNull(b)?lf.debug.inspectTable_(a,b,c,d):lf.debug.listTables_(a):lf.debug.listDb_()};lf.debug.toString_=function(a){var b="";try{b=JSON.stringify(a)}catch(c){}return b};lf.debug.getGlobal_=function(a){var b=lf.Global.get();a=new lf.service.ServiceId("ns_"+a);return b.isRegistered(a)?b.getService(a):null};
lf.debug.listDb_=function(){var a={};lf.Global.get().listServices().forEach(function(b){"ns_"==b.substring(0,3)&&(b=b.substring(3),a[b]=lf.debug.getGlobal_(b).getService(lf.service.SCHEMA).version())});return lf.debug.toString_(a)};lf.debug.listTables_=function(a){a=lf.debug.getGlobal_(a);var b={};if(goog.isDefAndNotNull(a)){var c=a.getService(lf.service.INDEX_STORE);a.getService(lf.service.SCHEMA).tables().forEach(function(a){b[a.getName()]=c.get(a.getRowIdIndexName()).stats().totalRows})}return lf.debug.toString_(b)};
lf.debug.inspectTable_=function(a,b,c,d){var e=lf.debug.getGlobal_(a);a=[];if(goog.isDefAndNotNull(e)){var f=null;try{f=e.getService(lf.service.SCHEMA).table(b)}catch(g){}goog.isDefAndNotNull(f)&&(b=e.getService(lf.service.INDEX_STORE),e=e.getService(lf.service.CACHE),c=b.get(f.getRowIdIndexName()).getRange(void 0,!1,c,d),c.length&&(a=e.getMany(c).map(function(a){return a.payload()})))}return lf.debug.toString_(a)};$jscomp.scope.calculateCartesianProduct=function(a){goog.asserts.assert(1<a.length,"Should only be called for cross-column indices.");a=a.map(function(a){return a.getValues()});a=goog.iter.product.apply(null,a);var b=[];goog.iter.forEach(a,function(a){b.push(a)});return b};lf.proc.IndexKeyRangeCalculator=function(){};lf.proc.NotBoundKeyRangeCalculator=function(a){this.indexSchema_=a};
lf.proc.NotBoundKeyRangeCalculator.prototype.getKeyRangeCombinations=function(a){return 1==this.indexSchema_.columns.length?[lf.index.SingleKeyRange.all()]:[this.indexSchema_.columns.map(function(a){return lf.index.SingleKeyRange.all()})]};lf.proc.BoundKeyRangeCalculator=function(a,b){this.indexSchema_=a;this.predicateMap_=b;this.combinations_=this.lastQueryContext_=null};
lf.proc.BoundKeyRangeCalculator.prototype.calculateKeyRangeMap_=function(a){var b=lf.structs.map.create();this.predicateMap_.keys().forEach(function(c){var d=this.predicateMap_.get(c).map(function(b){return a.getPredicate(b)},this),e=new lf.index.SingleKeyRangeSet([lf.index.SingleKeyRange.all()]);d.forEach(function(a){e=lf.index.SingleKeyRangeSet.intersect(e,a.toKeyRange())});b.set(c,e)},this);return b};
lf.proc.BoundKeyRangeCalculator.prototype.fillMissingKeyRanges_=function(a){for(var b=this.indexSchema_.columns.length-1;0<=b;b--){var c=this.indexSchema_.columns[b],d=a.get(c.schema.getName())||null;if(!goog.isNull(d))break;a.set(c.schema.getName(),new lf.index.SingleKeyRangeSet([lf.index.SingleKeyRange.all()]))}};
lf.proc.BoundKeyRangeCalculator.prototype.getKeyRangeCombinations=function(a){if(this.lastQueryContext_==a)return this.combinations_;var b=this.calculateKeyRangeMap_(a);this.fillMissingKeyRanges_(b);this.combinations_=1==this.indexSchema_.columns.length?lf.structs.map.values(b)[0].getValues():(0,$jscomp.scope.calculateCartesianProduct)(this.getSortedKeyRangeSets_(b));this.lastQueryContext_=a;return this.combinations_};
lf.proc.BoundKeyRangeCalculator.prototype.getSortedKeyRangeSets_=function(a){var b=lf.structs.map.create(),c=0;this.indexSchema_.columns.forEach(function(a){b.set(a.schema.getName(),c);c++});return lf.structs.map.keys(a).sort(function(a,c){return b.get(a)-b.get(c)}).map(function(b){return a.get(b)})};lf.structs.set={};$jscomp.scope.detectUseNative$1=function(){return lf.Flags.NATIVE_ES6||lf.Capability.get().nativeSet};lf.structs.SetPolyFill_=function(a){this.set_=new goog.structs.Set(a);Object.defineProperty(this,"size",{get:function(){return this.set_.getCount()}})};lf.structs.SetPolyFill_.prototype.add=function(a){this.set_.add(a)};lf.structs.SetPolyFill_.prototype.clear=function(){this.set_.clear()};lf.structs.SetPolyFill_.prototype.delete=function(a){return this.set_.remove(a)};
lf.structs.SetPolyFill_.prototype.forEach=function(a,b){this.set_.getValues().forEach(a,b)};lf.structs.SetPolyFill_.prototype.has=function(a){return this.set_.contains(a)};$jscomp.scope.USE_NATIVE$1=(0,$jscomp.scope.detectUseNative$1)();lf.structs.set.create=function(a){return $jscomp.scope.USE_NATIVE$1?goog.isDef(a)?new window.Set(a):new window.Set:new lf.structs.SetPolyFill_(a)};
lf.structs.set.values=function(a){if(a instanceof lf.structs.SetPolyFill_)return a.set_.getValues();var b=0,c=Array(a.size);a.forEach(function(a){c[b++]=a});return c};lf.structs.set.diff=function(a,b){if(a instanceof lf.structs.SetPolyFill_){var c=new lf.structs.SetPolyFill_;c.set_=a.set_.difference(b.set_)}else c=lf.structs.set.create(),lf.structs.set.values(a).forEach(function(a){b.has(a)||c.add(a)});return c};
lf.structs.set.isSubset=function(a,b){if(b.size>a.size)return!1;var c=!0;b.forEach(function(b){c=c&&a.has(b)});return c};lf.structs.set.equals=function(a,b){return a.size==b.size&&lf.structs.set.isSubset(a,b)};lf.backstore.Page=function(a,b){this.id_=a;this.payload_=b||{}};lf.backstore.Page.BUNDLE_EXPONENT=9;lf.backstore.Page.toPageIds=function(a){var b=lf.structs.set.create();a.forEach(function(a){b.add(lf.backstore.Page.toPageId(a))});return lf.structs.set.values(b)};lf.backstore.Page.toPageId=function(a){return a>>lf.backstore.Page.BUNDLE_EXPONENT};lf.backstore.Page.getPageRange=function(a){return[a<<lf.backstore.Page.BUNDLE_EXPONENT,(a+1<<lf.backstore.Page.BUNDLE_EXPONENT)-1]};
lf.backstore.Page.prototype.getId=function(){return this.id_};lf.backstore.Page.prototype.getPayload=function(){return this.payload_};lf.backstore.Page.prototype.setRows=function(a){a.forEach(function(a){this.payload_[a.id()]=a.serialize()},this)};lf.backstore.Page.prototype.removeRows=function(a){a.forEach(function(a){delete this.payload_[a]},this)};lf.backstore.Page.prototype.serialize=function(){return{id:this.id_,value:JSON.stringify(this.payload_)}};
lf.backstore.Page.deserialize=function(a){return new lf.backstore.Page(a.id,JSON.parse(a.value))};lf.backstore.IndexedDBRawBackStore=function(a,b,c,d){this.db_=b;this.tx_=c;this.version_=a;this.bundleMode_=d};lf.backstore.IndexedDBRawBackStore.prototype.getRawDBInstance=function(){return this.db_};lf.backstore.IndexedDBRawBackStore.prototype.getRawTransaction=function(){return this.tx_};lf.backstore.IndexedDBRawBackStore.prototype.dropTable=function(a){return new goog.Promise(function(b,c){try{this.db_.deleteObjectStore(a)}catch(d){c(d);return}b()},this)};
lf.backstore.IndexedDBRawBackStore.prototype.openCursorForWrite_=function(a,b,c){return new goog.Promise(function(d,e){var f;try{var g=this.tx_.objectStore(a);f=g.openCursor()}catch(h){e(h);return}f.onsuccess=function(a){(a=f.result)?(b(a),a.continue()):(c(g),d())};f.onerror=e},this)};lf.backstore.IndexedDBRawBackStore.convert=function(a){var b=null;return b=a instanceof ArrayBuffer?lf.Row.binToHex(a):a instanceof Date?a.getTime():a};
lf.backstore.IndexedDBRawBackStore.prototype.transformRows_=function(a,b){var c=function(a){var c=lf.Row.deserialize(a.value);b(c);a.update(c.serialize())},d=function(a){var c=lf.backstore.Page.deserialize(a.value),d=c.getPayload(),h;for(h in d){var k=lf.Row.deserialize(d[h]);b(k);d[h]=k.serialize()}a.update(c.serialize())};return this.openCursorForWrite_(a,this.bundleMode_?d:c,function(){})};
lf.backstore.IndexedDBRawBackStore.prototype.addTableColumn=function(a,b,c){var d=lf.backstore.IndexedDBRawBackStore.convert(c);return this.transformRows_(a,function(a){a.payload()[b]=d})};lf.backstore.IndexedDBRawBackStore.prototype.dropTableColumn=function(a,b){return this.transformRows_(a,function(a){delete a.payload()[b]})};lf.backstore.IndexedDBRawBackStore.prototype.renameTableColumn=function(a,b,c){return this.transformRows_(a,function(a){a.payload()[c]=a.payload()[b];delete a.payload()[b]})};
lf.backstore.IndexedDBRawBackStore.prototype.getTableRows_=function(a){var b=[];return new goog.Promise(function(c,d){var e;try{e=this.tx_.objectStore(a).openCursor()}catch(f){d(f);return}e.onsuccess=function(a){if(a=e.result){if(this.bundleMode_){var d=lf.backstore.Page.deserialize(a.value).getPayload(),h;for(h in d)b.push(d[h])}else b.push(a.value);a.continue()}else c(b)}.bind(this);e.onerror=d},this)};
lf.backstore.IndexedDBRawBackStore.prototype.createRow=function(a){var b={},c;for(c in a)b[c]=lf.backstore.IndexedDBRawBackStore.convert(a[c]);return lf.Row.create(b)};lf.backstore.IndexedDBRawBackStore.prototype.getVersion=function(){return this.version_};
lf.backstore.IndexedDBRawBackStore.prototype.dump=function(){for(var a=this.db_.objectStoreNames,b=[],c=0;c<a.length;++c){var d=a.item(c);b.push(this.dumpTable_(d))}return goog.Promise.all(b).then(function(b){var c={};b.forEach(function(b,d){c[a.item(d)]=b});return c})};lf.backstore.IndexedDBRawBackStore.prototype.dumpTable_=function(a){return this.getTableRows_(a).then(function(a){return a.map(function(a){return a.value})})};lf.cache.DefaultCache=function(a){this.map_=lf.structs.map.create();this.tableRows_=lf.structs.map.create();a.tables().forEach(function(a){this.tableRows_.set(a.getName(),lf.structs.set.create())},this)};lf.cache.DefaultCache.prototype.set=function(a,b){this.map_.set(b.id(),b);this.tableRows_.get(a).add(b.id())};lf.cache.DefaultCache.prototype.setMany=function(a,b){var c=this.tableRows_.get(a);b.forEach(function(a){this.map_.set(a.id(),a);c.add(a.id())},this)};
lf.cache.DefaultCache.prototype.get=function(a){return this.map_.get(a)||null};lf.cache.DefaultCache.prototype.getMany=function(a){return a.map(function(a){return this.get(a)},this)};
lf.cache.DefaultCache.prototype.getRange=function(a,b,c){var d=[],e=Math.min(b,c),f=Math.max(b,c);a=this.tableRows_.get(a);if(a.size<f-e)a.forEach(function(a){a>=e&&a<=f&&(a=this.map_.get(a),goog.asserts.assert(goog.isDefAndNotNull(a),"Inconsistent cache"),d.push(a))},this);else for(b=e;b<=f;++b)a.has(b)&&(c=this.map_.get(b),goog.asserts.assert(goog.isDefAndNotNull(c),"Inconsistent cache"),d.push(c));return d};lf.cache.DefaultCache.prototype.remove=function(a,b){this.map_.delete(b);this.tableRows_.get(a).delete(b)};
lf.cache.DefaultCache.prototype.removeMany=function(a,b){var c=this.tableRows_.get(a);b.forEach(function(a){this.map_.delete(a);c.delete(a)},this)};lf.cache.DefaultCache.prototype.getCount=function(a){return goog.isDefAndNotNull(a)?this.tableRows_.get(a).size:this.map_.size};lf.cache.DefaultCache.prototype.clear=function(){this.map_.clear();this.tableRows_.clear()};lf.index.NullableIndex=function(a){this.index_=a;this.nulls_=lf.structs.set.create();this.statsNull_=new lf.index.Stats;this.stats_=new lf.index.Stats};lf.index.NullableIndex.prototype.getName=function(){return this.index_.getName()};lf.index.NullableIndex.prototype.add=function(a,b){goog.isNull(a)?(this.nulls_.add(b),this.statsNull_.add(a,1)):this.index_.add(a,b)};
lf.index.NullableIndex.prototype.set=function(a,b){goog.isNull(a)?(this.nulls_.clear(),this.statsNull_.clear(),this.add(a,b)):this.index_.set(a,b)};lf.index.NullableIndex.prototype.remove=function(a,b){goog.isNull(a)?b?(this.nulls_.delete(b),this.statsNull_.remove(a,1)):(this.nulls_.clear(),this.statsNull_.clear()):this.index_.remove(a,b)};lf.index.NullableIndex.prototype.get=function(a){return goog.isNull(a)?lf.structs.set.values(this.nulls_):this.index_.get(a)};
lf.index.NullableIndex.prototype.cost=function(a){return this.index_.cost(a)};lf.index.NullableIndex.prototype.stats=function(){this.stats_.updateFromList([this.index_.stats(),this.statsNull_]);return this.stats_};lf.index.NullableIndex.prototype.getRange=function(a,b,c,d){b=this.index_.getRange(a,b,c,d);return goog.isDefAndNotNull(a)?b:b.concat(lf.structs.set.values(this.nulls_))};lf.index.NullableIndex.prototype.clear=function(){this.nulls_.clear();this.index_.clear()};
lf.index.NullableIndex.prototype.containsKey=function(a){return goog.isNull(a)?0!=this.nulls_.size:this.index_.containsKey(a)};lf.index.NullableIndex.prototype.min=function(){return this.index_.min()};lf.index.NullableIndex.prototype.max=function(){return this.index_.max()};lf.index.NullableIndex.NULL_ROW_ID_=-2;lf.index.NullableIndex.prototype.serialize=function(){return[new lf.Row(lf.index.NullableIndex.NULL_ROW_ID_,lf.structs.set.values(this.nulls_))].concat(this.index_.serialize())};
lf.index.NullableIndex.prototype.comparator=function(){return this.index_.comparator()};lf.index.NullableIndex.deserialize=function(a,b){for(var c=-1,d=0;d<b.length;++d)if(b[d].id()==lf.index.NullableIndex.NULL_ROW_ID_){c=d;break}if(-1==c)throw new lf.Exception(102);var d=b[c].payload(),e=b.slice(0);e.splice(c,1);var c=a(e),f=new lf.index.NullableIndex(c);d.forEach(function(a){f.nulls_.add(a)});return f};lf.index.NullableIndex.prototype.isUniqueKey=function(){return this.index_.isUniqueKey()};lf.index.RowId=function(a){this.name_=a;this.rows_=lf.structs.set.create();this.comparator_=new lf.index.SimpleComparator(lf.Order.ASC)};lf.index.RowId.ROW_ID=0;lf.index.RowId.prototype.getName=function(){return this.name_};lf.index.RowId.prototype.add=function(a,b){if("number"!=typeof a)throw new lf.Exception(103);this.rows_.add(a)};lf.index.RowId.prototype.set=function(a,b){this.add(a,b)};lf.index.RowId.prototype.remove=function(a,b){this.rows_.delete(a)};
lf.index.RowId.prototype.get=function(a){return this.containsKey(a)?[a]:[]};lf.index.RowId.prototype.min=function(){return this.minMax_(this.comparator_.min.bind(this.comparator_))};lf.index.RowId.prototype.max=function(){return this.minMax_(this.comparator_.max.bind(this.comparator_))};lf.index.RowId.prototype.minMax_=function(a){if(0==this.rows_.size)return null;var b=lf.structs.set.values(this.rows_).reduce(function(b,d){return goog.isNull(b)||a(d,b)==lf.index.Favor.LHS?d:b},null);return[b,[b]]};
lf.index.RowId.prototype.cost=function(a){return this.rows_.size};lf.index.RowId.prototype.getRange=function(a,b,c,d){var e=a||[lf.index.SingleKeyRange.all()];a=lf.structs.set.values(this.rows_).filter(function(a){return e.some(function(b){return this.comparator_.isInRange(a,b)},this)},this);return lf.index.slice(a,b,c,d)};lf.index.RowId.prototype.clear=function(){this.rows_.clear()};lf.index.RowId.prototype.containsKey=function(a){return this.rows_.has(a)};
lf.index.RowId.prototype.serialize=function(){return[new lf.Row(lf.index.RowId.ROW_ID,lf.structs.set.values(this.rows_))]};lf.index.RowId.prototype.comparator=function(){return this.comparator_};lf.index.RowId.deserialize=function(a,b){var c=new lf.index.RowId(a);b[0].payload().forEach(function(a){c.add(a,a)});return c};lf.index.RowId.prototype.isUniqueKey=function(){return!0};lf.index.RowId.prototype.stats=function(){var a=new lf.index.Stats;a.totalRows=this.rows_.size;return a};lf.index.MemoryIndexStore=function(){this.store_=lf.structs.map.create();this.tableIndices_=lf.structs.map.create()};
lf.index.MemoryIndexStore.prototype.init=function(a){a.tables().forEach(function(a){var c=[];this.tableIndices_.set(a.getName(),c);var d=a.getRowIdIndexName(),e=this.get(d);goog.isNull(e)&&(e=new lf.index.RowId(d),c.push(e),this.store_.set(d,e));a.getIndices().forEach(function(a){var b=lf.index.MemoryIndexStore.createIndex_(a);c.push(b);this.store_.set(a.getNormalizedName(),b)},this)},this);return goog.Promise.resolve()};
lf.index.MemoryIndexStore.createIndex_=function(a){var b=lf.index.ComparatorFactory.create(a),b=new lf.index.BTree(a.getNormalizedName(),b,a.isUnique);return a.hasNullableColumn()&&1==a.columns.length?new lf.index.NullableIndex(b):b};lf.index.MemoryIndexStore.prototype.get=function(a){return this.store_.get(a)||null};
lf.index.MemoryIndexStore.prototype.set=function(a,b){var c=this.tableIndices_.get(a)||null;goog.isNull(c)&&(c=[],this.tableIndices_.set(a,c));for(var d=null,e=0;e<c.length;e++)if(c[e].getName()==b.getName()){d=e;break}!goog.isNull(d)&&0<c.length?c.splice(d,1,b):c.push(b);this.store_.set(b.getName(),b)};lf.index.MemoryIndexStore.prototype.getTableIndices=function(a){return this.tableIndices_.get(a)||[]};lf.ObserverRegistry=function(){this.entries_=lf.structs.map.create()};lf.ObserverRegistry.prototype.getQueryId_=function(a){return goog.getUid(a).toString()};lf.ObserverRegistry.prototype.addObserver=function(a,b){var c=this.getQueryId_(a.getObservableQuery()),d=this.entries_.get(c)||null;goog.isNull(d)&&(d=new lf.ObserverRegistry.Entry_(a),this.entries_.set(c,d));d.addObserver(b)};
lf.ObserverRegistry.prototype.removeObserver=function(a,b){var c=a.getObservableQuery(),c=this.getQueryId_(c),d=this.entries_.get(c)||null;goog.asserts.assert(goog.isDefAndNotNull(d),"Attempted to unobserve a query that was not observed.");var e=d.removeObserver(b);goog.asserts.assert(e,"removeObserver: Inconsistent state detected.");d.hasObservers()||this.entries_.delete(c)};
lf.ObserverRegistry.prototype.getTaskItemsForTables=function(a){var b=lf.structs.set.create();a.forEach(function(a){b.add(a.getName())});var c=[];this.entries_.forEach(function(a,e){var f=a.getTaskItem();f.context.from.some(function(a){return b.has(a.getName())})&&c.push(f)});return c};
lf.ObserverRegistry.prototype.updateResultsForQuery=function(a,b){var c=this.getQueryId_(goog.isDefAndNotNull(a.clonedFrom)?a.clonedFrom:a),c=this.entries_.get(c)||null;return goog.isNull(c)?!1:(c.updateResults(b),!0)};lf.ObserverRegistry.Entry_=function(a){this.builder_=a;this.observers_=lf.structs.set.create();this.observable_=[];this.lastResults_=null;this.diffCalculator_=new lf.DiffCalculator(a.getObservableQuery(),this.observable_)};
lf.ObserverRegistry.Entry_.prototype.addObserver=function(a){this.observers_.has(a)?goog.asserts.fail("Attempted to register observer twice."):this.observers_.add(a)};lf.ObserverRegistry.Entry_.prototype.removeObserver=function(a){return this.observers_.delete(a)};lf.ObserverRegistry.Entry_.prototype.getTaskItem=function(){return this.builder_.getObservableTaskItem()};lf.ObserverRegistry.Entry_.prototype.hasObservers=function(){return 0<this.observers_.size};
lf.ObserverRegistry.Entry_.prototype.updateResults=function(a){var b=this.diffCalculator_.applyDiff(this.lastResults_,a);this.lastResults_=a;0<b.length&&this.observers_.forEach(function(a){a(b)})};lf.proc.LockManager=function(){this.lockTable_=lf.structs.map.create()};lf.proc.LockType={EXCLUSIVE:0,RESERVED_READ_ONLY:1,RESERVED_READ_WRITE:2,SHARED:3};lf.proc.LockManager.prototype.getEntry_=function(a){var b=this.lockTable_.get(a.getName())||null;goog.isNull(b)&&(b=new lf.proc.LockTableEntry_,this.lockTable_.set(a.getName(),b));return b};lf.proc.LockManager.prototype.grantLock_=function(a,b,c){b.forEach(function(b){this.getEntry_(b).grantLock(a,c)},this)};
lf.proc.LockManager.prototype.canAcquireLock_=function(a,b,c){var d=!0;b.forEach(function(b){d&&(d=this.getEntry_(b).canAcquireLock(a,c))},this);return d};lf.proc.LockManager.prototype.requestLock=function(a,b,c){var d=this.canAcquireLock_(a,b,c);d&&this.grantLock_(a,b,c);return d};lf.proc.LockManager.prototype.releaseLock=function(a,b){b.forEach(function(b){this.getEntry_(b).releaseLock(a)},this)};
lf.proc.LockManager.prototype.clearReservedLocks=function(a){a.forEach(function(a){this.getEntry_(a).reservedReadWriteLock=null},this)};lf.proc.LockTableEntry_=function(){this.sharedLocks=this.reservedReadOnlyLocks=this.reservedReadWriteLock=this.exclusiveLock=null};
lf.proc.LockTableEntry_.prototype.releaseLock=function(a){this.exclusiveLock==a&&(this.exclusiveLock=null);this.reservedReadWriteLock==a&&(this.reservedReadWriteLock=null);goog.isNull(this.reservedReadOnlyLocks)||this.reservedReadOnlyLocks.delete(a);goog.isNull(this.sharedLocks)||this.sharedLocks.delete(a)};
lf.proc.LockTableEntry_.prototype.canAcquireLock=function(a,b){var c=goog.isNull(this.reservedReadOnlyLocks)||0==this.reservedReadOnlyLocks.size;return b==lf.proc.LockType.EXCLUSIVE?(goog.isNull(this.sharedLocks)||0==this.sharedLocks.size)&&c&&goog.isNull(this.exclusiveLock)&&!goog.isNull(this.reservedReadWriteLock)&&this.reservedReadWriteLock==a:b==lf.proc.LockType.SHARED?goog.isNull(this.exclusiveLock)&&goog.isNull(this.reservedReadWriteLock)&&!goog.isNull(this.reservedReadOnlyLocks)&&this.reservedReadOnlyLocks.has(a):
b==lf.proc.LockType.RESERVED_READ_ONLY?goog.isNull(this.reservedReadWriteLock):c&&(goog.isNull(this.reservedReadWriteLock)||this.reservedReadWriteLock==a)};
lf.proc.LockTableEntry_.prototype.grantLock=function(a,b){b==lf.proc.LockType.EXCLUSIVE?(this.reservedReadWriteLock=null,this.exclusiveLock=a):b==lf.proc.LockType.SHARED?(goog.isNull(this.sharedLocks)&&(this.sharedLocks=lf.structs.set.create()),this.sharedLocks.add(a),goog.isNull(this.reservedReadOnlyLocks)&&(this.reservedReadOnlyLocks=lf.structs.set.create()),this.reservedReadOnlyLocks.delete(a)):b==lf.proc.LockType.RESERVED_READ_ONLY?(goog.isNull(this.reservedReadOnlyLocks)&&(this.reservedReadOnlyLocks=
lf.structs.set.create()),this.reservedReadOnlyLocks.add(a)):b==lf.proc.LockType.RESERVED_READ_WRITE&&(this.reservedReadWriteLock=a)};lf.proc.PhysicalQueryPlan=function(a,b){this.rootNode_=a;this.scope_=b};lf.proc.PhysicalQueryPlan.prototype.getRoot=function(){return this.rootNode_};lf.proc.PhysicalQueryPlan.prototype.getScope=function(){return this.scope_};lf.proc.PhysicalQueryPlan.getCombinedScope=function(a){var b=lf.structs.set.create();a.forEach(function(a){a.getScope().forEach(b.add.bind(b))});return b};lf.proc.Relation=function(a,b){this.entries=a;this.tables_=lf.structs.set.create(b);this.aggregationResults_=null};lf.proc.Relation.prototype.isCompatible=function(a){return lf.structs.set.equals(this.tables_,a.tables_)};lf.proc.Relation.assertCompatible_=function(a,b){goog.asserts.assert(a.isCompatible(b),"Intersection/union operations only apply to compatible relations.")};lf.proc.Relation.prototype.getTables=function(){return lf.structs.set.values(this.tables_)};
lf.proc.Relation.prototype.isPrefixApplied=function(){return 1<this.tables_.size};lf.proc.Relation.prototype.getPayloads=function(){return this.entries.map(function(a){return a.row.payload()})};lf.proc.Relation.prototype.getRowIds=function(){return this.entries.map(function(a){return a.row.id()})};
lf.proc.Relation.prototype.setAggregationResult=function(a,b){goog.isNull(this.aggregationResults_)&&(this.aggregationResults_=lf.structs.map.create());this.aggregationResults_.set(a.getNormalizedName(),b)};
lf.proc.Relation.prototype.getAggregationResult=function(a){goog.asserts.assert(!goog.isNull(this.aggregationResults_),"getAggregationResult called before any results have been calculated.");var b=this.aggregationResults_.get(a.getNormalizedName());goog.asserts.assert(goog.isDef(b),"Could not find result for "+a.getNormalizedName());return b};lf.proc.Relation.prototype.hasAggregationResult=function(a){return!goog.isNull(this.aggregationResults_)&&this.aggregationResults_.has(a.getNormalizedName())};
lf.proc.Relation.emptyRelation_=null;lf.proc.Relation.createEmpty=function(){goog.isNull(lf.proc.Relation.emptyRelation_)&&(lf.proc.Relation.emptyRelation_=new lf.proc.Relation([],[]));return lf.proc.Relation.emptyRelation_};
lf.proc.Relation.intersect=function(a){if(0==a.length)return lf.proc.Relation.createEmpty();for(var b=a.reduce(function(b,c){lf.proc.Relation.assertCompatible_(a[0],c);return b+c.entries.length},0),c=Array(b),d=0,b=a.map(function(a){var b=lf.structs.map.create();a.entries.forEach(function(a){c[d++]=a;b.set(a.id,a)});return b}),e=lf.structs.map.create(),f=0;f<c.length;f++)b.every(function(a){return a.has(c[f].id)})&&e.set(c[f].id,c[f]);return new lf.proc.Relation(lf.structs.map.values(e),lf.structs.set.values(a[0].tables_))};
lf.proc.Relation.union=function(a){if(0==a.length)return lf.proc.Relation.createEmpty();var b=lf.structs.map.create();a.forEach(function(c){lf.proc.Relation.assertCompatible_(a[0],c);c.entries.forEach(function(a){b.set(a.id,a)})});return new lf.proc.Relation(lf.structs.map.values(b),lf.structs.set.values(a[0].tables_))};lf.proc.Relation.fromRows=function(a,b){var c=1<b.length,d=a.map(function(a){return new lf.proc.RelationEntry(a,c)});return new lf.proc.Relation(d,b)};
lf.proc.RelationEntry=function(a,b){this.row=a;this.id=lf.proc.RelationEntry.getNextId_();this.isPrefixApplied_=b};lf.proc.RelationEntry.id_=0;lf.proc.RelationEntry.getNextId_=function(){return lf.proc.RelationEntry.id_++};lf.proc.RelationEntry.prototype.getField=function(a){var b=a.getAlias();return!goog.isNull(b)&&this.row.payload().hasOwnProperty(b)?this.row.payload()[b]:this.isPrefixApplied_?this.row.payload()[a.getTable().getEffectiveName()][a.getName()]:this.row.payload()[a.getName()]};
lf.proc.RelationEntry.prototype.setField=function(a,b){var c=a.getAlias();if(goog.isDefAndNotNull(c))this.row.payload()[c]=b;else if(this.isPrefixApplied_){var c=a.getTable().getEffectiveName(),d=this.row.payload()[c];goog.isDefAndNotNull(d)||(d={},this.row.payload()[c]=d);d[a.getName()]=b}else this.row.payload()[a.getName()]=b};
lf.proc.RelationEntry.combineEntries=function(a,b,c,d){var e={},f=function(a,b){if(a.isPrefixApplied_){var c=a.row.payload(),d;for(d in c)e[d]=c[d]}else goog.asserts.assert(!e.hasOwnProperty(b[0]),"Attempted to join table with itself, without using table alias, or same alias "+b[0]+"is reused for multiple tables."),e[b[0]]=a.row.payload()};f(a,b);f(c,d);a=new lf.Row(lf.Row.DUMMY_ID,e);return new lf.proc.RelationEntry(a,!0)};lf.proc.RelationTransformer=function(a,b){this.relation_=a;this.columns_=b};lf.proc.RelationTransformer.prototype.getTransformed=function(){return this.columns_.some(function(a){return a instanceof lf.fn.AggregatedColumn},this)?this.handleAggregatedColumns_():this.handleNonAggregatedColumns_()};
lf.proc.RelationTransformer.prototype.handleAggregatedColumns_=function(){if(1==this.columns_.length&&this.columns_[0].aggregatorType==lf.fn.Type.DISTINCT){var a=this.relation_.getAggregationResult(this.columns_[0]).entries.map(function(a){var b=new lf.proc.RelationEntry(new lf.Row(lf.Row.DUMMY_ID,{}),this.relation_.isPrefixApplied());b.setField(this.columns_[0],a.getField(this.columns_[0].child));return b},this);return new lf.proc.Relation(a,[])}var b=new lf.proc.RelationEntry(new lf.Row(lf.Row.DUMMY_ID,
{}),this.relation_.isPrefixApplied());this.columns_.forEach(function(a){var d=a instanceof lf.fn.AggregatedColumn?this.relation_.getAggregationResult(a):this.relation_.entries[0].getField(a);b.setField(a,d)},this);return new lf.proc.Relation([b],this.relation_.getTables())};
lf.proc.RelationTransformer.prototype.handleNonAggregatedColumns_=function(){var a=Array(this.relation_.entries.length),b=this.relation_.isPrefixApplied();this.relation_.entries.forEach(function(c,d){a[d]=new lf.proc.RelationEntry(new lf.Row(c.row.id(),{}),b);this.columns_.forEach(function(b){a[d].setField(b,c.getField(b))},this)},this);return new lf.proc.Relation(a,this.relation_.getTables())};
lf.proc.RelationTransformer.transformMany=function(a,b){var c=a.map(function(a){return(new lf.proc.RelationTransformer(a,b)).getTransformed().entries[0]});return new lf.proc.Relation(c,a[0].getTables())};lf.structs.MapSet=function(){this.map_=lf.structs.map.create();this.size=0};lf.structs.MapSet.prototype.has=function(a){return this.map_.has(a)};lf.structs.MapSet.prototype.set=function(a,b){var c=this.map_.get(a)||null;goog.isNull(c)&&(c=lf.structs.set.create(),this.map_.set(a,c));c.has(b)||(c.add(b),this.size++);return this};
lf.structs.MapSet.prototype.setMany=function(a,b){var c=this.map_.get(a)||null;goog.isNull(c)&&(c=lf.structs.set.create(),this.map_.set(a,c));b.forEach(function(a){c.has(a)||(c.add(a),this.size++)},this);return this};lf.structs.MapSet.prototype.merge=function(a){a.keys().forEach(function(b){var c=a.get(b);this.setMany(b,c)},this);return this};
lf.structs.MapSet.prototype.delete=function(a,b){var c=this.map_.get(a)||null;if(goog.isNull(c))return!1;var d=c.delete(b);d&&(--this.size,0==c.size&&this.map_.delete(a));return d};lf.structs.MapSet.prototype.get=function(a){a=this.map_.get(a)||null;return goog.isNull(a)?null:lf.structs.set.values(a)};lf.structs.MapSet.prototype.clear=function(){this.map_.clear();this.size=0};lf.structs.MapSet.prototype.keys=function(){return lf.structs.map.keys(this.map_)};
lf.structs.MapSet.prototype.values=function(){var a=[];this.map_.forEach(function(b,c){a.push.apply(a,lf.structs.set.values(b))});return a};lf.cache.ConstraintChecker=function(a){this.indexStore_=a.getService(lf.service.INDEX_STORE);this.schema_=a.getService(lf.service.SCHEMA);this.cache_=a.getService(lf.service.CACHE);this.foreignKeysParentIndices_=null};lf.cache.ConstraintChecker.prototype.findExistingRowIdInPkIndex=function(a,b){var c=a.getConstraint().getPrimaryKey();return goog.isNull(c)?null:this.findExistingRowIdInIndex_(c,b)};
lf.cache.ConstraintChecker.prototype.findExistingRowIdInIndex_=function(a,b){var c=a.getNormalizedName(),d=b.keyOfIndex(c),c=this.indexStore_.get(c).get(d);return 0==c.length?null:c[0]};lf.cache.ConstraintChecker.prototype.checkNotNullable=function(a,b){var c=a.getConstraint().getNotNullable();b.forEach(function(a){c.forEach(function(b){if(!goog.isDefAndNotNull(a.payload()[b.getName()]))throw new lf.Exception(202,b.getNormalizedName());},this)},this)};
lf.cache.ConstraintChecker.prototype.checkReferredKeys_=function(a,b,c){a.getConstraint().getForeignKeys().forEach(function(a){a.timing==c&&this.checkReferredKey_(a,b)},this)};lf.cache.ConstraintChecker.prototype.checkReferredKey_=function(a,b){var c=this.getParentIndex_(a);b.forEach(function(b){if(lf.cache.ConstraintChecker.didColumnValueChange_(b[0],b[1],a.name)&&(b=b[1].keyOfIndex(a.name),!goog.isNull(b)&&!c.containsKey(b)))throw new lf.Exception(203,a.name);},this)};
lf.cache.ConstraintChecker.prototype.findParentIndex_=function(a){a=this.schema_.table(a.parentTable)[a.parentColumn].getIndex();return this.indexStore_.get(a.getNormalizedName())};lf.cache.ConstraintChecker.prototype.getParentIndex_=function(a){goog.isNull(this.foreignKeysParentIndices_)&&(this.foreignKeysParentIndices_=lf.structs.map.create());var b=this.foreignKeysParentIndices_.get(a.name)||null;goog.isNull(b)&&(b=this.findParentIndex_(a),this.foreignKeysParentIndices_.set(a.name,b));return b};
lf.cache.ConstraintChecker.didColumnValueChange_=function(a,b,c){return(goog.isNull(a)?!goog.isNull(b):goog.isNull(b))||a.keyOfIndex(c)!=b.keyOfIndex(c)};lf.cache.ConstraintChecker.prototype.checkReferringKeys_=function(a,b,c,d){a=this.schema_.info().getReferencingForeignKeys(a.getName(),d);goog.isNull(a)||(a=a.filter(function(a){return a.timing==c}),0!=a.length&&this.loopThroughReferringRows_(a,b,function(a,b,c){if(b.containsKey(c))throw new lf.Exception(203,a.name);}))};
lf.cache.ConstraintChecker.prototype.findReferringRowIds_=function(a,b){var c=this.schema_.info().getReferencingForeignKeys(a.getName(),lf.ConstraintAction.CASCADE);if(goog.isNull(c))return null;var d=new lf.structs.MapSet;this.loopThroughReferringRows_(c,b,function(a,b,c){b=b.get(c);0<b.length&&d.setMany(a.childTable,b)});return d};
lf.cache.ConstraintChecker.prototype.detectCascadeUpdates=function(a,b,c){var d=new lf.structs.MapSet;this.loopThroughReferringRows_(c,b,function(a,b,c,h){b.get(c).forEach(function(b){d.set(b,{fkSpec:a,originalUpdatedRow:h[1]})})});return d};
lf.cache.ConstraintChecker.prototype.loopThroughReferringRows_=function(a,b,c){a.forEach(function(a){var e=this.indexStore_.get(a.name),f=this.getParentIndex_(a);b.forEach(function(b){if(lf.cache.ConstraintChecker.didColumnValueChange_(b[0],b[1],f.getName())){var h=b[0].keyOfIndex(f.getName());c(a,e,h,b)}},this)},this)};lf.cache.ConstraintChecker.prototype.checkForeignKeysForInsert=function(a,b,c){0!=b.length&&(b=b.map(function(a){return[null,a]}),this.checkReferredKeys_(a,b,c))};
lf.cache.ConstraintChecker.prototype.checkForeignKeysForUpdate=function(a,b,c){0!=b.length&&(this.checkReferredKeys_(a,b,c),this.checkReferringKeys_(a,b,c,lf.ConstraintAction.RESTRICT))};lf.cache.ConstraintChecker.prototype.checkForeignKeysForDelete=function(a,b,c){0!=b.length&&(b=b.map(function(a){return[a,null]}),this.checkReferringKeys_(a,b,c,lf.ConstraintAction.RESTRICT))};
lf.cache.ConstraintChecker.prototype.detectCascadeDeletion=function(a,b){var c={tableOrder:[],rowIdsPerTable:new lf.structs.MapSet},d=new lf.structs.MapSet;d.setMany(a.getName(),b.map(function(a){return a.id()}));do{var e=new lf.structs.MapSet;d.keys().forEach(function(a){var b=this.schema_.table(a);a=d.get(a).map(function(a){return[this.cache_.get(a),null]},this);b=this.findReferringRowIds_(b,a);goog.isNull(b)||(c.tableOrder.unshift.apply(c.tableOrder,b.keys()),e.merge(b))},this);d=e;c.rowIdsPerTable.merge(d)}while(0<
d.size);return c};lf.cache.Journal=function(a,b){this.scope_=lf.structs.map.create();b.forEach(function(a){this.scope_.set(a.getName(),a)},this);this.schema_=a.getService(lf.service.SCHEMA);this.cache_=a.getService(lf.service.CACHE);this.indexStore_=a.getService(lf.service.INDEX_STORE);this.constraintChecker_=new lf.cache.ConstraintChecker(a);this.inMemoryUpdater_=new lf.cache.InMemoryUpdater(a);this.pendingRollback_=this.terminated_=!1;this.tableDiffs_=lf.structs.map.create()};lf.cache.Journal.prototype.getDiff=function(){return this.tableDiffs_};
lf.cache.Journal.prototype.getIndexDiff=function(){var a=[];lf.structs.map.keys(this.tableDiffs_).map(function(a){return this.scope_.get(a)},this).forEach(function(b){b.persistentIndex()&&(b.getIndices().forEach(function(b){a.push(this.indexStore_.get(b.getNormalizedName()))},this),a.push(this.indexStore_.get(b.getName()+".#")))},this);return a};lf.cache.Journal.prototype.getScope=function(){return this.scope_};
lf.cache.Journal.prototype.insert=function(a,b){this.assertJournalWritable_();this.checkScope_(a);this.constraintChecker_.checkNotNullable(a,b);this.constraintChecker_.checkForeignKeysForInsert(a,b,lf.ConstraintTiming.IMMEDIATE);for(var c=0;c<b.length;c++)this.modifyRow_(a,[null,b[c]])};
lf.cache.Journal.prototype.modifyRow_=function(a,b){var c=a.getName(),d=this.tableDiffs_.get(c)||new lf.cache.TableDiff(c);this.tableDiffs_.set(c,d);try{this.inMemoryUpdater_.updateTableIndicesForRow(a,b)}catch(g){throw this.pendingRollback_=!0,g;}var e=b[0],f=b[1];goog.isNull(e)&&!goog.isNull(f)?(this.cache_.set(c,f),d.add(f)):goog.isNull(e)||goog.isNull(f)?!goog.isNull(e)&&goog.isNull(f)&&(this.cache_.remove(c,e.id()),d.delete(e)):(this.cache_.set(c,f),d.modify(b))};
lf.cache.Journal.prototype.update=function(a,b){this.assertJournalWritable_();this.checkScope_(a);this.constraintChecker_.checkNotNullable(a,b);var c=b.map(function(a){return[this.cache_.get(a.id()),a]},this);this.updateByCascade_(a,c);this.constraintChecker_.checkForeignKeysForUpdate(a,c,lf.ConstraintTiming.IMMEDIATE);c.forEach(function(b){this.modifyRow_(a,b)},this)};
lf.cache.Journal.prototype.insertOrReplace=function(a,b){this.assertJournalWritable_();this.checkScope_(a);this.constraintChecker_.checkNotNullable(a,b);for(var c=0;c<b.length;c++){var d=b[c],e=null,f=this.constraintChecker_.findExistingRowIdInPkIndex(a,d);goog.isDefAndNotNull(f)?(e=this.cache_.get(f),d.assignRowId(f),this.constraintChecker_.checkForeignKeysForUpdate(a,[[e,d]],lf.ConstraintTiming.IMMEDIATE)):this.constraintChecker_.checkForeignKeysForInsert(a,[d],lf.ConstraintTiming.IMMEDIATE);this.modifyRow_(a,
[e,d])}};lf.cache.Journal.prototype.remove=function(a,b){this.assertJournalWritable_();this.checkScope_(a);this.removeByCascade_(a,b);this.constraintChecker_.checkForeignKeysForDelete(a,b,lf.ConstraintTiming.IMMEDIATE);for(var c=0;c<b.length;c++)this.modifyRow_(a,[b[c],null])};
lf.cache.Journal.prototype.updateByCascade_=function(a,b){var c=this.schema_.info().getReferencingForeignKeys(a.getName(),lf.ConstraintAction.CASCADE);if(!goog.isNull(c)){var d=this.constraintChecker_.detectCascadeUpdates(a,b,c);d.keys().forEach(function(a){d.get(a).forEach(function(b){var c=this.schema_.table(b.fkSpec.childTable),d=this.cache_.get(a),k=c.deserializeRow(d.serialize());k.payload()[b.fkSpec.childColumn]=b.originalUpdatedRow.payload()[b.fkSpec.parentColumn];this.modifyRow_(c,[d,k])},
this)},this)}};
lf.cache.Journal.prototype.removeByCascade_=function(a,b){var c=this.schema_.info().getReferencingForeignKeys(a.getName(),lf.ConstraintAction.CASCADE);if(!goog.isNull(c)){var c=this.constraintChecker_.detectCascadeDeletion(a,b),d=c.rowIdsPerTable;c.tableOrder.forEach(function(a){var b=this.schema_.table(a);a=d.get(a).map(function(a){return this.cache_.get(a)},this);this.constraintChecker_.checkForeignKeysForDelete(b,a,lf.ConstraintTiming.IMMEDIATE);a.forEach(function(a){this.modifyRow_(b,[a,null])},
this)},this)}};
lf.cache.Journal.prototype.checkDeferredConstraints=function(){this.tableDiffs_.forEach(function(a,b){var c=this.scope_.get(a.getName());this.constraintChecker_.checkForeignKeysForInsert(c,lf.structs.map.values(a.getAdded()),lf.ConstraintTiming.DEFERRABLE);this.constraintChecker_.checkForeignKeysForDelete(c,lf.structs.map.values(a.getDeleted()),lf.ConstraintTiming.DEFERRABLE);this.constraintChecker_.checkForeignKeysForUpdate(c,lf.structs.map.values(a.getModified()),lf.ConstraintTiming.DEFERRABLE)},this)};
lf.cache.Journal.prototype.commit=function(){this.assertJournalWritable_();this.terminated_=!0};lf.cache.Journal.prototype.assertJournalWritable_=function(){goog.asserts.assert(!this.pendingRollback_,"Attemptted to use journal that needs to be rolled back.");goog.asserts.assert(!this.terminated_,"Attemptted to commit a terminated journal.")};
lf.cache.Journal.prototype.rollback=function(){goog.asserts.assert(!this.terminated_,"Attempted to rollback a terminated journal.");var a=lf.structs.map.values(this.tableDiffs_).map(function(a){return a.getReverse()});this.inMemoryUpdater_.update(a);this.terminated_=!0;this.pendingRollback_=!1};lf.cache.Journal.prototype.checkScope_=function(a){if(!this.scope_.has(a.getName()))throw new lf.Exception(106,a.getName());};lf.schema.Info=function(a){this.schema_=a;this.cascadeReferringFk_=new lf.structs.MapSet;this.restrictReferringFk_=new lf.structs.MapSet;this.parents_=new lf.structs.MapSet;this.colParent_=lf.structs.map.create();this.children_=new lf.structs.MapSet;this.cascadeChildren_=new lf.structs.MapSet;this.restrictChildren_=new lf.structs.MapSet;this.colChild_=new lf.structs.MapSet;this.init_()};
lf.schema.Info.prototype.init_=function(){this.schema_.tables().forEach(function(a){var b=a.getName();a.getConstraint().getForeignKeys().forEach(function(c){this.parents_.set(b,this.schema_.table(c.parentTable));this.children_.set(c.parentTable,a);c.action==lf.ConstraintAction.RESTRICT?(this.restrictReferringFk_.set(c.parentTable,c),this.restrictChildren_.set(c.parentTable,a)):(this.cascadeReferringFk_.set(c.parentTable,c),this.cascadeChildren_.set(c.parentTable,a));this.colParent_.set(a.getName()+
"."+c.childColumn,c.parentTable);this.colChild_.set(c.parentTable+"."+c.parentColumn,a.getName())},this)},this)};lf.schema.Info.prototype.getReferencingForeignKeys=function(a,b){if(goog.isDefAndNotNull(b))return b==lf.ConstraintAction.CASCADE?this.cascadeReferringFk_.get(a):this.restrictReferringFk_.get(a);var c=this.cascadeReferringFk_.get(a),d=this.restrictReferringFk_.get(a);return goog.isNull(c)&&goog.isNull(d)?null:(c||[]).concat(d||[])};
lf.schema.Info.prototype.expandScope_=function(a,b){var c=b.get(a);return goog.isNull(c)?[]:c};lf.schema.Info.prototype.getParentTables=function(a){return this.expandScope_(a,this.parents_)};lf.schema.Info.prototype.getParentTablesByColumns=function(a){var b=lf.structs.set.create();a.forEach(function(a){(a=this.colParent_.get(a))&&b.add(a)},this);return lf.structs.set.values(b).map(function(a){return this.schema_.table(a)},this)};
lf.schema.Info.prototype.getChildTables=function(a,b){return goog.isDefAndNotNull(b)?b==lf.ConstraintAction.RESTRICT?this.expandScope_(a,this.restrictChildren_):this.expandScope_(a,this.cascadeChildren_):this.expandScope_(a,this.children_)};lf.schema.Info.prototype.getChildTablesByColumns=function(a){var b=lf.structs.set.create();a.forEach(function(a){(a=this.colChild_.get(a))&&a.forEach(function(a){b.add(a)})},this);return lf.structs.set.values(b).map(function(a){return this.schema_.table(a)},this)};lf.structs.TreeNode=function(){this.children_=this.parent_=null};lf.structs.TreeNode.EMPTY_ARRAY_=[];lf.structs.TreeNode.prototype.getParent=function(){return this.parent_};lf.structs.TreeNode.prototype.setParent=function(a){this.parent_=a};lf.structs.TreeNode.prototype.getRoot=function(){for(var a=this;!goog.isNull(a.getParent());)a=a.getParent();return a};lf.structs.TreeNode.prototype.getDepth=function(){for(var a=0,b=this;!goog.isNull(b.getParent());)a++,b=b.getParent();return a};
lf.structs.TreeNode.prototype.isLeaf=function(){return goog.isNull(this.children_)};lf.structs.TreeNode.prototype.getChildren=function(){return this.children_||lf.structs.TreeNode.EMPTY_ARRAY_};lf.structs.TreeNode.prototype.getChildAt=function(a){return this.getChildren()[a]||null};lf.structs.TreeNode.prototype.getChildCount=function(){return this.getChildren().length};
lf.structs.TreeNode.prototype.addChildAt=function(a,b){goog.asserts.assert(goog.isNull(a.getParent()));a.setParent(this);goog.isNull(this.children_)?(goog.asserts.assert(0==b),this.children_=[a]):(goog.asserts.assert(0<=b&&b<=this.children_.length),this.children_.splice(b,0,a))};lf.structs.TreeNode.prototype.addChild=function(a){goog.asserts.assert(goog.isNull(a.getParent()));a.setParent(this);goog.isNull(this.children_)?this.children_=[a]:this.children_.push(a)};
lf.structs.TreeNode.prototype.removeChildAt=function(a){var b=this.children_&&this.children_[a];return b?(b.setParent(null),this.children_.splice(a,1),0==this.children_.length&&(this.children_=null),b):null};lf.structs.TreeNode.prototype.removeChild=function(a){return this.removeChildAt(this.getChildren().indexOf(a))};
lf.structs.TreeNode.prototype.replaceChildAt=function(a,b){goog.asserts.assert(goog.isNull(a.getParent()),"New child must not have parent node");var c=this.getChildAt(b);goog.asserts.assert(c,"Invalid child index");c.setParent(null);a.setParent(this);this.children_[b]=a;return c};lf.structs.TreeNode.prototype.traverse=function(a,b){!1!==a.call(b,this)&&this.getChildren().forEach(function(c){c.traverse(a,b)})};lf.pred.PredicateNode=function(){lf.structs.TreeNode.call(this);this.id_=lf.pred.PredicateNode.nextId_++};goog.inherits(lf.pred.PredicateNode,lf.structs.TreeNode);lf.pred.PredicateNode.nextId_=0;lf.pred.PredicateNode.prototype.getId=function(){return this.id_};lf.pred.PredicateNode.prototype.setId=function(a){this.id_=a};lf.pred.JoinPredicate=function(a,b,c){lf.pred.PredicateNode.call(this);this.leftColumn=a;this.rightColumn=b;this.evaluatorType=c;this.nullPayload_=null;a=lf.eval.Registry.get();this.evaluatorFn_=a.getEvaluator(this.leftColumn.getType(),this.evaluatorType);this.keyOfIndexFn_=a.getKeyOfIndexEvaluator(this.leftColumn.getType())};goog.inherits(lf.pred.JoinPredicate,lf.pred.PredicateNode);lf.pred.JoinPredicate.BLOCK_SIZE_EXPONENT_=8;
lf.pred.JoinPredicate.prototype.copy=function(){var a=new lf.pred.JoinPredicate(this.leftColumn,this.rightColumn,this.evaluatorType);a.setId(this.getId());return a};lf.pred.JoinPredicate.prototype.getColumns=function(a){return goog.isDefAndNotNull(a)?(a.push(this.leftColumn),a.push(this.rightColumn),a):[this.leftColumn,this.rightColumn]};
lf.pred.JoinPredicate.prototype.getTables=function(a){a=goog.isDefAndNotNull(a)?a:lf.structs.set.create();a.add(this.leftColumn.getTable());a.add(this.rightColumn.getTable());return a};
lf.pred.JoinPredicate.prototype.reverse=function(){var a=this.evaluatorType;switch(this.evaluatorType){case lf.eval.Type.GT:a=lf.eval.Type.LT;break;case lf.eval.Type.LT:a=lf.eval.Type.GT;break;case lf.eval.Type.GTE:a=lf.eval.Type.LTE;break;case lf.eval.Type.LTE:a=lf.eval.Type.GTE}return new lf.pred.JoinPredicate(this.rightColumn,this.leftColumn,a)};
lf.pred.JoinPredicate.prototype.reverseSelf_=function(){var a=this.leftColumn;this.leftColumn=this.rightColumn;this.rightColumn=a;a=this.evaluatorType;switch(this.evaluatorType){case lf.eval.Type.GT:a=lf.eval.Type.LT;break;case lf.eval.Type.LT:a=lf.eval.Type.GT;break;case lf.eval.Type.GTE:a=lf.eval.Type.LTE;break;case lf.eval.Type.LTE:a=lf.eval.Type.GTE;break;default:return}this.evaluatorType=a;this.evaluatorFn_=lf.eval.Registry.get().getEvaluator(this.leftColumn.getType(),this.evaluatorType)};
lf.pred.JoinPredicate.prototype.eval=function(a){var b=a.entries.filter(function(a){var b=a.getField(this.leftColumn);a=a.getField(this.rightColumn);return this.evaluatorFn_(b,a)},this);return new lf.proc.Relation(b,a.getTables())};lf.pred.JoinPredicate.prototype.toString=function(){return"join_pred("+this.leftColumn.getNormalizedName()+" "+this.evaluatorType+" "+this.rightColumn.getNormalizedName()+")"};lf.pred.JoinPredicate.prototype.appliesToLeft_=function(a){return-1!=a.getTables().indexOf(this.leftColumn.getTable().getEffectiveName())};
lf.pred.JoinPredicate.prototype.appliesToRight_=function(a){return-1!=a.getTables().indexOf(this.rightColumn.getTable().getEffectiveName())};lf.pred.JoinPredicate.prototype.detectLeftRight_=function(a,b){var c=null,d=null;this.appliesToLeft_(a)?(this.assertRelationsApply_(a,b),c=a,d=b):(this.assertRelationsApply_(b,a),c=b,d=a);return c.entries.length>d.entries.length?(this.reverseSelf_(),this.assertRelationsApply_(d,c),[d,c]):[c,d]};
lf.pred.JoinPredicate.prototype.assertRelationsApply_=function(a,b){goog.asserts.assert(this.appliesToLeft_(a),"Mismatch between join predicate left operand and right relation.");goog.asserts.assert(this.appliesToRight_(b),"Mismatch between join predicate right operand and right relation.")};lf.pred.JoinPredicate.prototype.createNullPayload_=function(a){var b={};a.getColumns().forEach(function(a){b[a.getName()]=null});return b};
lf.pred.JoinPredicate.prototype.createCombinedEntryForUnmatched_=function(a,b){goog.isNull(this.nullPayload_)&&(this.nullPayload_=this.createNullPayload_(this.rightColumn.getTable()));var c=new lf.proc.RelationEntry(new lf.Row(lf.Row.DUMMY_ID,this.nullPayload_),!1);return lf.proc.RelationEntry.combineEntries(a,b,c,[this.rightColumn.getTable().getEffectiveName()])};
lf.pred.JoinPredicate.prototype.evalRelationsNestedLoopJoin=function(a,b,c){var d=[a,b];c||(d=this.detectLeftRight_(a,b));a=d[0];b=d[1];for(var d=[],e=a.getTables(),f=b.getTables(),g=a.entries.length,h=b.entries.length,k=lf.pred.JoinPredicate.BLOCK_SIZE_EXPONENT_,n=h+(1<<k)-1>>k,l=0;l<n;){for(var m=0;m<g;m++){var p=!1,q=a.entries[m].getField(this.leftColumn);if(!goog.isNull(q))for(var t=Math.min(l+1<<k,h),r=l<<k;r<t;r++)if(this.evaluatorFn_(q,b.entries[r].getField(this.rightColumn))){var p=!0,u=lf.proc.RelationEntry.combineEntries(a.entries[m],
e,b.entries[r],f);d.push(u)}c&&!p&&d.push(this.createCombinedEntryForUnmatched_(a.entries[m],e))}l++}a=a.getTables().concat(b.getTables());return new lf.proc.Relation(d,a)};
lf.pred.JoinPredicate.prototype.evalRelationsHashJoin=function(a,b,c){var d=[a,b];c||(d=this.detectLeftRight_(a,b));a=d[0];b=d[1];var d=a,e=b,f=this.leftColumn,g=this.rightColumn;c&&(d=b,e=a,f=this.rightColumn,g=this.leftColumn);var h=new lf.structs.MapSet,k=[];d.entries.forEach(function(a){var b=String(a.getField(f));h.set(b,a)});var n=d.getTables(),l=e.getTables();e.entries.forEach(function(a){var b=a.getField(g),d=String(b);!goog.isNull(b)&&h.has(d)?h.get(d).forEach(function(b){b=lf.proc.RelationEntry.combineEntries(a,
l,b,n);k.push(b)}):c&&k.push(this.createCombinedEntryForUnmatched_(a,l))}.bind(this));a=a.getTables().concat(b.getTables());return new lf.proc.Relation(k,a)};
lf.pred.JoinPredicate.prototype.evalRelationsIndexNestedLoopJoin=function(a,b,c,d){goog.asserts.assert(this.evaluatorType==lf.eval.Type.EQ,"For now, index nested loop join can only be leveraged for EQ.");var e=c.indexedColumn.getTable(),f=a,g=b;-1!=a.getTables().indexOf(e.getEffectiveName())&&(f=b,g=a);var h=[],k=g.getTables(),n=f.getTables(),l=function(a,b){var c=new lf.proc.RelationEntry(b,1<k.length),c=lf.proc.RelationEntry.combineEntries(a,n,c,k);h.push(c)};f.entries.forEach(function(a){var b=
this.keyOfIndexFn_(a.getField(c.nonIndexedColumn)),b=c.index.get(b);0!=b.length&&(c.index.isUniqueKey()?l(a,d.get(b[0])):d.getMany(b).forEach(l.bind(null,a)))},this);a=f.getTables().concat(g.getTables());return new lf.proc.Relation(h,a)};lf.pred.ValuePredicate=function(a,b,c){lf.pred.PredicateNode.call(this);this.column=a;this.value=b;this.evaluatorType=c;this.evaluatorFn_=lf.eval.Registry.get().getEvaluator(this.column.getType(),this.evaluatorType);this.isComplement_=!1;this.binder_=b};goog.inherits(lf.pred.ValuePredicate,lf.pred.PredicateNode);
lf.pred.ValuePredicate.prototype.copy=function(){var a=new lf.pred.ValuePredicate(this.column,this.value,this.evaluatorType);a.setBinder(this.binder_);a.setComplement(this.isComplement_);a.setId(this.getId());return a};lf.pred.ValuePredicate.prototype.getColumns=function(a){return goog.isDefAndNotNull(a)?(a.push(this.column),a):[this.column]};lf.pred.ValuePredicate.prototype.getTables=function(a){a=goog.isDefAndNotNull(a)?a:lf.structs.set.create();a.add(this.column.getTable());return a};
lf.pred.ValuePredicate.prototype.setComplement=function(a){this.isComplement_=a};lf.pred.ValuePredicate.prototype.setBinder=function(a){this.binder_=a};lf.pred.ValuePredicate.prototype.checkBinding_=function(){var a=!1;this.value instanceof lf.Binder||(a=goog.isArray(this.value)?!this.value.some(function(a){return a instanceof lf.Binder}):!0);if(!a)throw new lf.Exception(501);};
lf.pred.ValuePredicate.prototype.eval=function(a){this.checkBinding_();if(this.evaluatorType==lf.eval.Type.IN)return this.evalAsIn_(a);var b=a.entries.filter(function(a){return this.evaluatorFn_(a.getField(this.column),this.value)!=this.isComplement_},this);return new lf.proc.Relation(b,a.getTables())};
lf.pred.ValuePredicate.prototype.bind=function(a){var b=function(b){if(a.length<=b)throw new lf.Exception(510);};if(this.binder_ instanceof lf.Binder){var c=this.binder_.getIndex();b(c);this.value=a[c]}else goog.isArray(this.binder_)&&(this.value=this.binder_.map(function(c){return c instanceof lf.Binder?(b(c.getIndex()),a[c.getIndex()]):c}))};
lf.pred.ValuePredicate.prototype.evalAsIn_=function(a){goog.asserts.assert(this.evaluatorType==lf.eval.Type.IN,"ValuePredicate#evalAsIn_() called for wrong predicate type.");var b=lf.structs.set.create(this.value),c=function(a){return goog.isNull(a)?!1:b.has(a)!=this.isComplement_}.bind(this),d=a.entries.filter(function(a){return c(a.getField(this.column))},this);return new lf.proc.Relation(d,a.getTables())};
lf.pred.ValuePredicate.prototype.toString=function(){return"value_pred("+this.column.getNormalizedName()+" "+this.evaluatorType+(this.isComplement_?"(complement)":"")+" "+this.value+")"};
lf.pred.ValuePredicate.prototype.isKeyRangeCompatible=function(){this.checkBinding_();return!goog.isNull(this.value)&&(this.evaluatorType==lf.eval.Type.BETWEEN||this.evaluatorType==lf.eval.Type.IN||this.evaluatorType==lf.eval.Type.EQ||this.evaluatorType==lf.eval.Type.GT||this.evaluatorType==lf.eval.Type.GTE||this.evaluatorType==lf.eval.Type.LT||this.evaluatorType==lf.eval.Type.LTE)};
lf.pred.ValuePredicate.prototype.toKeyRange=function(){goog.asserts.assert(this.isKeyRangeCompatible(),"Could not convert predicate to key range.");var a=null;if(this.evaluatorType==lf.eval.Type.BETWEEN)a=new lf.index.SingleKeyRange(this.getValueAsKey_(this.value[0]),this.getValueAsKey_(this.value[1]),!1,!1);else{if(this.evaluatorType==lf.eval.Type.IN)return a=this.value.map(function(a){return lf.index.SingleKeyRange.only(a)}),new lf.index.SingleKeyRangeSet(this.isComplement_?lf.index.SingleKeyRange.complement(a):
a);a=this.getValueAsKey_(this.value);a=this.evaluatorType==lf.eval.Type.EQ?lf.index.SingleKeyRange.only(a):this.evaluatorType==lf.eval.Type.GTE?lf.index.SingleKeyRange.lowerBound(a):this.evaluatorType==lf.eval.Type.GT?lf.index.SingleKeyRange.lowerBound(a,!0):this.evaluatorType==lf.eval.Type.LTE?lf.index.SingleKeyRange.upperBound(a):lf.index.SingleKeyRange.upperBound(a,!0)}return new lf.index.SingleKeyRangeSet(this.isComplement_?a.complement():[a])};
lf.pred.ValuePredicate.prototype.getValueAsKey_=function(a){return this.column.getType()==lf.Type.DATE_TIME?a.getTime():a};lf.pred.createPredicate=function(a,b,c){return goog.isNull(b)?new lf.pred.ValuePredicate(a,b,c):goog.isDef(b.getNormalizedName)?new lf.pred.JoinPredicate(a,b,c):new lf.pred.ValuePredicate(a,b,c)};lf.proc.PhysicalQueryPlanNode=function(a,b){lf.structs.TreeNode.call(this);this.execType_=b;this.numRelations_=a};goog.inherits(lf.proc.PhysicalQueryPlanNode,lf.structs.TreeNode);lf.proc.PhysicalQueryPlanNode.ExecType={NO_CHILD:-1,ALL:0,FIRST_CHILD:1};lf.proc.PhysicalQueryPlanNode.ANY=-1;
lf.proc.PhysicalQueryPlanNode.prototype.exec=function(a,b){switch(this.execType_){case lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD:return this.execFirstChild_(a,b);case lf.proc.PhysicalQueryPlanNode.ExecType.ALL:return this.execAllChildren_(a,b);default:return this.execNoChild_(a,b)}};lf.proc.PhysicalQueryPlanNode.prototype.toString=function(){return"dummy_node"};lf.proc.PhysicalQueryPlanNode.prototype.toContextString=function(a){return this.toString()};
lf.proc.PhysicalQueryPlanNode.prototype.assertInput_=function(a){goog.asserts.assert(this.numRelations_==lf.proc.PhysicalQueryPlanNode.ANY||a.length==this.numRelations_)};lf.proc.PhysicalQueryPlanNode.prototype.execNoChild_=function(a,b){return new goog.Promise(function(c,d){c(this.execInternal([],a,b))}.bind(this))};lf.proc.PhysicalQueryPlanNode.prototype.execFirstChild_=function(a,b){return this.getChildAt(0).exec(a,b).then(function(c){this.assertInput_(c);return this.execInternal(c,a,b)}.bind(this))};
lf.proc.PhysicalQueryPlanNode.prototype.execAllChildren_=function(a,b){var c=this.getChildren().map(function(c){return c.exec(a,b)});return goog.Promise.all(c).then(function(c){var e=[];c.forEach(function(a){for(var b=0;b<a.length;++b)e.push(a[b])});this.assertInput_(e);return this.execInternal(e,a,b)}.bind(this))};lf.proc.AggregationStep=function(a){lf.proc.PhysicalQueryPlanNode.call(this,lf.proc.PhysicalQueryPlanNode.ANY,lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD);this.aggregatedColumns=a};goog.inherits(lf.proc.AggregationStep,lf.proc.PhysicalQueryPlanNode);lf.proc.AggregationStep.prototype.toString=function(){return"aggregation("+this.aggregatedColumns.map(function(a){return a.getNormalizedName()}).toString()+")"};
lf.proc.AggregationStep.prototype.execInternal=function(a){a.forEach(function(a){(new lf.proc.AggregationStep.Calculator_(a,this.aggregatedColumns)).calculate()},this);return a};lf.proc.AggregationStep.Calculator_=function(a,b){this.relation_=a;this.columns_=b};
lf.proc.AggregationStep.Calculator_.prototype.calculate=function(){this.columns_.forEach(function(a){a=a.getColumnChain().reverse();for(var b=1;b<a.length;b++){var c=a[b],d=c.getColumnChain().slice(-1)[0],e=this.getInputRelationFor_(c);if(e.hasAggregationResult(c))break;d=lf.proc.AggregationStep.Calculator_.evalAggregation_(c.aggregatorType,e,d);this.relation_.setAggregationResult(c,d)}},this)};
lf.proc.AggregationStep.Calculator_.prototype.getInputRelationFor_=function(a){return a.child instanceof lf.fn.AggregatedColumn?this.relation_.getAggregationResult(a.child):this.relation_};
lf.proc.AggregationStep.Calculator_.evalAggregation_=function(a,b,c){var d=null,e=lf.proc.AggregationStep.Calculator_;switch(a){case lf.fn.Type.MIN:d=e.reduce_(b,c,function(a,b){return b<a?b:a});break;case lf.fn.Type.MAX:d=e.reduce_(b,c,function(a,b){return b>a?b:a});break;case lf.fn.Type.DISTINCT:d=e.distinct_(b,c);break;case lf.fn.Type.COUNT:d=e.count_(b,c);break;case lf.fn.Type.SUM:d=e.sum_(b,c);break;case lf.fn.Type.AVG:a=e.count_(b,c);0<a&&(d=e.sum_(b,c)/a);break;case lf.fn.Type.GEOMEAN:d=e.geomean_(b,
c);break;default:d=e.stddev_(b,c)}return d};lf.proc.AggregationStep.Calculator_.reduce_=function(a,b,c){return a.entries.reduce(function(a,e){var f=e.getField(b);return goog.isNull(f)?a:goog.isNull(a)?f:c(a,f)},null)};lf.proc.AggregationStep.Calculator_.count_=function(a,b){return b instanceof lf.fn.StarColumn?a.entries.length:a.entries.reduce(function(a,d){return a+(goog.isNull(d.getField(b))?0:1)},0)};
lf.proc.AggregationStep.Calculator_.sum_=function(a,b){return lf.proc.AggregationStep.Calculator_.reduce_(a,b,function(a,b){return b+a})};lf.proc.AggregationStep.Calculator_.stddev_=function(a,b){var c=[];a.entries.forEach(function(a){a=a.getField(b);goog.isNull(a)||c.push(a)});return 0==c.length?null:goog.math.standardDeviation.apply(null,c)};
lf.proc.AggregationStep.Calculator_.geomean_=function(a,b){var c=0,d=a.entries.reduce(function(a,d){var g=d.getField(b);if(0==g||goog.isNull(g))return a;c++;return a+Math.log(g)},0);return 0==c?null:Math.pow(Math.E,d/c)};lf.proc.AggregationStep.Calculator_.distinct_=function(a,b){var c=lf.structs.map.create();a.entries.forEach(function(a){var e=a.getField(b);c.set(e,a)});return new lf.proc.Relation(lf.structs.map.values(c),a.getTables())};lf.proc.CrossProductStep=function(){lf.proc.PhysicalQueryPlanNode.call(this,2,lf.proc.PhysicalQueryPlanNode.ExecType.ALL)};goog.inherits(lf.proc.CrossProductStep,lf.proc.PhysicalQueryPlanNode);lf.proc.CrossProductStep.prototype.toString=function(){return"cross_product"};lf.proc.CrossProductStep.prototype.execInternal=function(a){return lf.proc.CrossProductStep.crossProduct_(a[0],a[1])};
lf.proc.CrossProductStep.crossProduct_=function(a,b){for(var c=[],d=a.getTables(),e=b.getTables(),f=0;f<a.entries.length;f++)for(var g=0;g<b.entries.length;g++){var h=lf.proc.RelationEntry.combineEntries(a.entries[f],d,b.entries[g],e);c.push(h)}d=a.getTables().concat(b.getTables());return[new lf.proc.Relation(c,d)]};lf.proc.DeleteStep=function(a){lf.proc.PhysicalQueryPlanNode.call(this,1,lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD);this.table_=a};goog.inherits(lf.proc.DeleteStep,lf.proc.PhysicalQueryPlanNode);lf.proc.DeleteStep.prototype.toString=function(){return"delete("+this.table_.getName()+")"};lf.proc.DeleteStep.prototype.execInternal=function(a,b){var c=a[0].entries.map(function(a){return a.row});b.remove(this.table_,c);return[lf.proc.Relation.createEmpty()]};lf.proc.GetRowCountStep=function(a,b){lf.proc.PhysicalQueryPlanNode.call(this,0,lf.proc.PhysicalQueryPlanNode.ExecType.NO_CHILD);this.table=b;this.indexStore_=a.getService(lf.service.INDEX_STORE)};goog.inherits(lf.proc.GetRowCountStep,lf.proc.PhysicalQueryPlanNode);lf.proc.GetRowCountStep.prototype.toString=function(){return"get_row_count("+this.table.getName()+")"};
lf.proc.GetRowCountStep.prototype.execInternal=function(a){a=this.indexStore_.get(this.table.getRowIdIndexName());var b=new lf.proc.Relation([],[this.table.getName()]);b.setAggregationResult(lf.fn.count(),a.stats().totalRows);return[b]};lf.proc.GroupByStep=function(a){lf.proc.PhysicalQueryPlanNode.call(this,1,lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD);this.groupByColumns_=a};goog.inherits(lf.proc.GroupByStep,lf.proc.PhysicalQueryPlanNode);lf.proc.GroupByStep.prototype.toString=function(){return"groupBy("+this.groupByColumns_.map(function(a){return a.getNormalizedName()}).toString()+")"};lf.proc.GroupByStep.prototype.execInternal=function(a){return this.calculateGroupedRelations_(a[0])};
lf.proc.GroupByStep.prototype.calculateGroupedRelations_=function(a){var b=new lf.structs.MapSet,c=function(a){return this.groupByColumns_.map(function(b){return a.getField(b)},this).join(",")}.bind(this);a.entries.forEach(function(a){b.set(c(a),a)},this);return b.keys().map(function(c){return new lf.proc.Relation(b.get(c),a.getTables())},this)};lf.proc.IndexRangeScanStep=function(a,b,c,d){lf.proc.PhysicalQueryPlanNode.call(this,0,lf.proc.PhysicalQueryPlanNode.ExecType.NO_CHILD);this.indexStore_=a.getService(lf.service.INDEX_STORE);this.index=b;this.keyRangeCalculator=c;this.reverseOrder=d;this.useSkip=this.useLimit=!1};goog.inherits(lf.proc.IndexRangeScanStep,lf.proc.PhysicalQueryPlanNode);
lf.proc.IndexRangeScanStep.prototype.toString=function(){return"index_range_scan("+this.index.getNormalizedName()+", ?, "+(this.reverseOrder?"reverse":"natural")+(this.useLimit?", limit:?":"")+(this.useSkip?", skip:?":"")+")"};
lf.proc.IndexRangeScanStep.prototype.toContextString=function(a){var b=this.toString(),c=this.keyRangeCalculator.getKeyRangeCombinations(a),b=b.replace("?",c.toString());this.useLimit&&(b=b.replace("?",a.limit.toString()));this.useSkip&&(b=b.replace("?",a.skip.toString()));return b};
lf.proc.IndexRangeScanStep.prototype.execInternal=function(a,b,c){a=this.keyRangeCalculator.getKeyRangeCombinations(c);b=this.indexStore_.get(this.index.getNormalizedName());c=(1==a.length&&a[0]instanceof lf.index.SingleKeyRange&&a[0].isOnly()?lf.index.slice(b.get(a[0].from),!1,this.useLimit?c.limit:void 0,this.useSkip?c.skip:void 0):b.getRange(a,this.reverseOrder,this.useLimit?c.limit:void 0,this.useSkip?c.skip:void 0)).map(function(a){return new lf.Row(a,{})},this);return[lf.proc.Relation.fromRows(c,
[this.index.tableName])]};lf.proc.MultiIndexRangeScanStep=function(){lf.proc.PhysicalQueryPlanNode.call(this,lf.proc.PhysicalQueryPlanNode.ANY,lf.proc.PhysicalQueryPlanNode.ExecType.ALL)};goog.inherits(lf.proc.MultiIndexRangeScanStep,lf.proc.PhysicalQueryPlanNode);lf.proc.MultiIndexRangeScanStep.prototype.toString=function(){return"multi_index_range_scan()"};
lf.proc.MultiIndexRangeScanStep.prototype.execInternal=function(a){var b=lf.structs.map.create();a.forEach(function(a){a.entries.forEach(function(a){b.set(a.row.id(),a)})});var c=lf.structs.map.values(b);return[new lf.proc.Relation(c,a[0].getTables())]};lf.proc.InsertStep=function(a,b){lf.proc.PhysicalQueryPlanNode.call(this,0,lf.proc.PhysicalQueryPlanNode.ExecType.NO_CHILD);this.indexStore_=a.getService(lf.service.INDEX_STORE);this.table_=b};goog.inherits(lf.proc.InsertStep,lf.proc.PhysicalQueryPlanNode);lf.proc.InsertStep.prototype.toString=function(){return"insert("+this.table_.getName()+")"};
lf.proc.InsertStep.prototype.execInternal=function(a,b,c){lf.proc.InsertStep.assignAutoIncrementPks_(this.table_,c.values,this.indexStore_);b.insert(this.table_,c.values);return[lf.proc.Relation.fromRows(c.values,[this.table_.getName()])]};
lf.proc.InsertStep.assignAutoIncrementPks_=function(a,b,c){a=a.getConstraint().getPrimaryKey();if(goog.isNull(a)?0:a.columns[0].autoIncrement){var d=a.columns[0].schema.getName();c=c.get(a.getNormalizedName()).max();var e=goog.isNull(c)?0:c[0];b.forEach(function(a){0!=a.payload()[d]&&goog.isDefAndNotNull(a.payload()[d])||(e++,a.payload()[d]=e)})}};
lf.proc.InsertOrReplaceStep=function(a,b){lf.proc.PhysicalQueryPlanNode.call(this,0,lf.proc.PhysicalQueryPlanNode.ExecType.NO_CHILD);this.indexStore_=a.getService(lf.service.INDEX_STORE);this.table_=b};goog.inherits(lf.proc.InsertOrReplaceStep,lf.proc.PhysicalQueryPlanNode);lf.proc.InsertOrReplaceStep.prototype.toString=function(){return"insert_replace("+this.table_.getName()+")"};
lf.proc.InsertOrReplaceStep.prototype.execInternal=function(a,b,c){lf.proc.InsertStep.assignAutoIncrementPks_(this.table_,c.values,this.indexStore_);b.insertOrReplace(this.table_,c.values);return[lf.proc.Relation.fromRows(c.values,[this.table_.getName()])]};lf.proc.JoinStep=function(a,b,c){lf.proc.PhysicalQueryPlanNode.call(this,2,lf.proc.PhysicalQueryPlanNode.ExecType.ALL);this.indexStore_=a.getService(lf.service.INDEX_STORE);this.cache_=a.getService(lf.service.CACHE);this.predicate=b;this.isOuterJoin=c;this.algorithm_=this.predicate.evaluatorType==lf.eval.Type.EQ?lf.proc.JoinStep.Algorithm_.HASH:lf.proc.JoinStep.Algorithm_.NESTED_LOOP;this.indexJoinInfo_=null};goog.inherits(lf.proc.JoinStep,lf.proc.PhysicalQueryPlanNode);
lf.proc.JoinStep.Algorithm_={HASH:0,INDEX_NESTED_LOOP:1,NESTED_LOOP:2};lf.proc.JoinStep.AlgorithmToString_=["hash","index_nested_loop","nested_loop"];lf.proc.JoinStep.prototype.toString=function(){return"join(type: "+(this.isOuterJoin?"outer":"inner")+", impl: "+lf.proc.JoinStep.AlgorithmToString_[this.algorithm_]+", "+this.predicate.toString()+")"};
lf.proc.JoinStep.prototype.execInternal=function(a){switch(this.algorithm_){case lf.proc.JoinStep.Algorithm_.HASH:return[this.predicate.evalRelationsHashJoin(a[0],a[1],this.isOuterJoin)];case lf.proc.JoinStep.Algorithm_.INDEX_NESTED_LOOP:return[this.predicate.evalRelationsIndexNestedLoopJoin(a[0],a[1],this.indexJoinInfo_,this.cache_)];default:return[this.predicate.evalRelationsNestedLoopJoin(a[0],a[1],this.isOuterJoin)]}};
lf.proc.JoinStep.prototype.markAsIndexJoin=function(a){this.algorithm_=lf.proc.JoinStep.Algorithm_.INDEX_NESTED_LOOP;var b=this.indexStore_.get(a.getIndex().getNormalizedName());this.indexJoinInfo_={indexedColumn:a,nonIndexedColumn:a==this.predicate.leftColumn?this.predicate.rightColumn:this.predicate.leftColumn,index:b}};lf.proc.LimitStep=function(){lf.proc.PhysicalQueryPlanNode.call(this,1,lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD)};goog.inherits(lf.proc.LimitStep,lf.proc.PhysicalQueryPlanNode);lf.proc.LimitStep.prototype.toString=function(){return"limit(?)"};lf.proc.LimitStep.prototype.toContextString=function(a){return this.toString().replace("?",a.limit.toString())};lf.proc.LimitStep.prototype.execInternal=function(a,b,c){a[0].entries.splice(c.limit);return a};lf.proc.NoOpStep=function(a){lf.proc.PhysicalQueryPlanNode.call(this,lf.proc.PhysicalQueryPlanNode.ANY,lf.proc.PhysicalQueryPlanNode.ExecType.NO_CHILD);this.relations_=a};goog.inherits(lf.proc.NoOpStep,lf.proc.PhysicalQueryPlanNode);lf.proc.NoOpStep.prototype.toString=function(){return"no_op_step("+this.relations_[0].getTables().join(",")+")"};lf.proc.NoOpStep.prototype.execInternal=function(a){return this.relations_};lf.proc.ProjectStep=function(a,b){lf.proc.PhysicalQueryPlanNode.call(this,lf.proc.PhysicalQueryPlanNode.ANY,lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD);this.columns=a;this.groupByColumns=b};goog.inherits(lf.proc.ProjectStep,lf.proc.PhysicalQueryPlanNode);
lf.proc.ProjectStep.prototype.toString=function(){var a="project("+this.columns.toString();if(!goog.isNull(this.groupByColumns))var b=this.groupByColumns.map(function(a){return a.getNormalizedName()}).join(", "),a=a+(", groupBy("+b+")");return a+")"};lf.proc.ProjectStep.prototype.execInternal=function(a){return 0==a.length?[lf.proc.Relation.createEmpty()]:1==a.length?[this.execNonGroupByProjection_(a[0])]:[this.execGroupByProjection_(a)]};
lf.proc.ProjectStep.prototype.hasAggregators=function(){return this.columns.some(function(a){return a instanceof lf.fn.AggregatedColumn})||!goog.isNull(this.groupByColumns)};lf.proc.ProjectStep.prototype.execGroupByProjection_=function(a){return lf.proc.RelationTransformer.transformMany(a,this.columns)};lf.proc.ProjectStep.prototype.execNonGroupByProjection_=function(a){return 0==this.columns.length?a:(new lf.proc.RelationTransformer(a,this.columns)).getTransformed()};lf.proc.SelectStep=function(a){lf.proc.PhysicalQueryPlanNode.call(this,1,lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD);this.predicateId=a};goog.inherits(lf.proc.SelectStep,lf.proc.PhysicalQueryPlanNode);lf.proc.SelectStep.prototype.toString=function(){return"select(?)"};lf.proc.SelectStep.prototype.toContextString=function(a){a=a.getPredicate(this.predicateId);return this.toString().replace("?",a.toString())};lf.proc.SelectStep.prototype.execInternal=function(a,b,c){return[c.getPredicate(this.predicateId).eval(a[0])]};lf.proc.SkipStep=function(){lf.proc.PhysicalQueryPlanNode.call(this,1,lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD)};goog.inherits(lf.proc.SkipStep,lf.proc.PhysicalQueryPlanNode);lf.proc.SkipStep.prototype.toString=function(){return"skip(?)"};lf.proc.SkipStep.prototype.toContextString=function(a){return this.toString().replace("?",a.skip.toString())};lf.proc.SkipStep.prototype.execInternal=function(a,b,c){return[new lf.proc.Relation(a[0].entries.slice(c.skip),a[0].getTables())]};lf.proc.TableAccessByRowIdStep=function(a,b){lf.proc.PhysicalQueryPlanNode.call(this,1,lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD);this.cache_=a.getService(lf.service.CACHE);this.table_=b};goog.inherits(lf.proc.TableAccessByRowIdStep,lf.proc.PhysicalQueryPlanNode);lf.proc.TableAccessByRowIdStep.prototype.toString=function(){return"table_access_by_row_id("+this.table_.getName()+")"};
lf.proc.TableAccessByRowIdStep.prototype.execInternal=function(a){return[lf.proc.Relation.fromRows(this.cache_.getMany(a[0].getRowIds()),[this.table_.getEffectiveName()])]};lf.proc.TableAccessFullStep=function(a,b){lf.proc.PhysicalQueryPlanNode.call(this,0,lf.proc.PhysicalQueryPlanNode.ExecType.NO_CHILD);this.cache_=a.getService(lf.service.CACHE);this.indexStore_=a.getService(lf.service.INDEX_STORE);this.table=b};goog.inherits(lf.proc.TableAccessFullStep,lf.proc.PhysicalQueryPlanNode);lf.proc.TableAccessFullStep.prototype.toString=function(){var a="table_access("+this.table.getName();goog.isNull(this.table.getAlias())||(a+=" as "+this.table.getAlias());return a+")"};
lf.proc.TableAccessFullStep.prototype.execInternal=function(a){a=this.indexStore_.get(this.table.getRowIdIndexName()).getRange();return[lf.proc.Relation.fromRows(this.cache_.getMany(a),[this.table.getEffectiveName()])]};lf.proc.UpdateStep=function(a,b){lf.proc.PhysicalQueryPlanNode.call(this,1,lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD);this.table_=a;this.updates_=b};goog.inherits(lf.proc.UpdateStep,lf.proc.PhysicalQueryPlanNode);lf.proc.UpdateStep.prototype.toString=function(){return"update("+this.table_.getName()+")"};
lf.proc.UpdateStep.prototype.execInternal=function(a,b){var c=a[0].entries.map(function(a){var b=this.table_.deserializeRow(a.row.serialize());this.updates_.forEach(function(a){b.payload()[a.column.getName()]=a.value},this);return b},this);b.update(this.table_,c);return[lf.proc.Relation.createEmpty()]};lf.query.Context=function(a){this.schema=a;this.clonedFrom=this.predicateMap_=null};lf.query.Context.prototype.getPredicate=function(a){goog.isNull(this.predicateMap_)&&goog.isDefAndNotNull(this.where)&&(this.predicateMap_=lf.query.Context.buildPredicateMap_(this.where));a=this.predicateMap_.get(a)||null;goog.asserts.assert(!goog.isNull(a));return a};lf.query.Context.buildPredicateMap_=function(a){var b=lf.structs.map.create();a.traverse(function(a){b.set(a.getId(),a)});return b};
lf.query.Context.prototype.cloneBase=function(a){a.where&&(this.where=a.where.copy());this.clonedFrom=a};lf.query.Context.prototype.bind=function(a){goog.asserts.assert(!goog.isDefAndNotNull(this.clonedFrom));return this};lf.query.Context.prototype.bindValuesInSearchCondition=function(a){var b=this.where;goog.isDefAndNotNull(b)&&b.traverse(function(b){b instanceof lf.pred.ValuePredicate&&b.bind(a)})};lf.query.DeleteContext=function(a){lf.query.Context.call(this,a)};goog.inherits(lf.query.DeleteContext,lf.query.Context);lf.query.DeleteContext.prototype.getScope=function(){var a=lf.structs.set.create();a.add(this.from);this.expandTableScope_(this.from.getName(),a);return a};
lf.query.DeleteContext.prototype.expandTableScope_=function(a,b){var c=this.schema.info().getChildTables(a,lf.ConstraintAction.CASCADE);this.schema.info().getChildTables(a).forEach(b.add.bind(b));c.forEach(function(a){this.expandTableScope_(a.getName(),b)},this)};lf.query.DeleteContext.prototype.clone=function(){var a=new lf.query.DeleteContext(this.schema);a.cloneBase(this);a.from=this.from;return a};
lf.query.DeleteContext.prototype.bind=function(a){lf.query.DeleteContext.superClass_.bind.call(this,a);this.bindValuesInSearchCondition(a);return this};lf.query.InsertContext=function(a){lf.query.Context.call(this,a)};goog.inherits(lf.query.InsertContext,lf.query.Context);lf.query.InsertContext.prototype.getScope=function(){var a=lf.structs.set.create();a.add(this.into);var b=this.schema.info();b.getParentTables(this.into.getName()).forEach(a.add.bind(a));this.allowReplace&&b.getChildTables(this.into.getName()).forEach(a.add.bind(a));return a};
lf.query.InsertContext.prototype.clone=function(){var a=new lf.query.InsertContext(this.schema);a.cloneBase(this);a.into=this.into;this.values&&(a.values=this.values instanceof lf.Binder?this.values:this.values.slice());a.allowReplace=this.allowReplace;a.binder=this.binder;return a};
lf.query.InsertContext.prototype.bind=function(a){lf.query.InsertContext.superClass_.bind.call(this,a);this.binder&&(this.values=this.binder instanceof lf.Binder?a[this.binder.getIndex()]:this.binder.map(function(b){return b instanceof lf.Binder?a[b.getIndex()]:b}));return this};lf.query.SelectContext=function(a){lf.query.Context.call(this,a)};goog.inherits(lf.query.SelectContext,lf.query.Context);lf.query.SelectContext.orderByToString=function(a){var b="";a.forEach(function(c,d){b+=c.column.getNormalizedName()+" ";b+=c.order==lf.Order.ASC?"ASC":"DESC";d<a.length-1&&(b+=", ")});return b};lf.query.SelectContext.prototype.getScope=function(){return lf.structs.set.create(this.from)};
lf.query.SelectContext.prototype.clone=function(){var a=new lf.query.SelectContext(this.schema);a.cloneBase(this);this.columns&&(a.columns=this.columns.slice());this.from&&(a.from=this.from.slice());a.limit=this.limit;a.skip=this.skip;this.orderBy&&(a.orderBy=this.orderBy.slice());this.groupBy&&(a.groupBy=this.groupBy.slice());this.limitBinder&&(a.limitBinder=this.limitBinder);this.skipBinder&&(a.skipBinder=this.skipBinder);a.outerJoinPredicates=this.outerJoinPredicates;return a};
lf.query.SelectContext.prototype.bind=function(a){lf.query.SelectContext.superClass_.bind.call(this,a);goog.isDefAndNotNull(this.limitBinder)&&(this.limit=a[this.limitBinder.getIndex()]);goog.isDefAndNotNull(this.skipBinder)&&(this.skip=a[this.skipBinder.getIndex()]);this.bindValuesInSearchCondition(a);return this};lf.proc.LogicalQueryPlan=function(a,b){this.rootNode_=a;this.scope_=b};lf.proc.LogicalQueryPlan.prototype.getRoot=function(){return this.rootNode_};lf.proc.LogicalQueryPlan.prototype.getScope=function(){return this.scope_};lf.proc.LogicalQueryPlanNode=function(){lf.structs.TreeNode.call(this)};goog.inherits(lf.proc.LogicalQueryPlanNode,lf.structs.TreeNode);lf.proc.InsertNode=function(a,b){lf.proc.LogicalQueryPlanNode.call(this);this.table=a;this.values=b};goog.inherits(lf.proc.InsertNode,lf.proc.LogicalQueryPlanNode);
lf.proc.InsertOrReplaceNode=function(a,b){lf.proc.InsertNode.call(this,a,b)};goog.inherits(lf.proc.InsertOrReplaceNode,lf.proc.InsertNode);lf.proc.DeleteNode=function(a){lf.proc.LogicalQueryPlanNode.call(this);this.table=a};goog.inherits(lf.proc.DeleteNode,lf.proc.LogicalQueryPlanNode);lf.proc.DeleteNode.prototype.toString=function(){return"delete("+this.table.getName()+")"};lf.proc.UpdateNode=function(a,b){lf.proc.LogicalQueryPlanNode.call(this);this.table=a;this.updates=b};
goog.inherits(lf.proc.UpdateNode,lf.proc.LogicalQueryPlanNode);lf.proc.UpdateNode.prototype.toString=function(){var a=[];this.updates&&(a=this.updates.map(function(a){return a.column.getName()},this));return"update("+this.table.getName()+", ["+a.join(",")+"])"};lf.proc.SelectNode=function(a){lf.proc.LogicalQueryPlanNode.call(this);this.predicate=a};goog.inherits(lf.proc.SelectNode,lf.proc.LogicalQueryPlanNode);
lf.proc.SelectNode.prototype.toString=function(){return"select("+this.predicate.toString()+")"};lf.proc.TableAccessNode=function(a){lf.proc.LogicalQueryPlanNode.call(this);this.table=a};goog.inherits(lf.proc.TableAccessNode,lf.proc.LogicalQueryPlanNode);lf.proc.TableAccessNode.prototype.toString=function(){var a="table_access("+this.table.getName();goog.isNull(this.table.getAlias())||(a+=" as "+this.table.getAlias());return a+")"};lf.proc.CrossProductNode=function(){lf.proc.LogicalQueryPlanNode.call(this)};
goog.inherits(lf.proc.CrossProductNode,lf.proc.LogicalQueryPlanNode);lf.proc.CrossProductNode.prototype.toString=function(){return"cross_product"};lf.proc.ProjectNode=function(a,b){lf.proc.LogicalQueryPlanNode.call(this);this.columns=a;this.groupByColumns=b};goog.inherits(lf.proc.ProjectNode,lf.proc.LogicalQueryPlanNode);
lf.proc.ProjectNode.prototype.toString=function(){var a="project("+this.columns.toString();if(!goog.isNull(this.groupByColumns))var b=this.groupByColumns.map(function(a){return a.getNormalizedName()}).join(", "),a=a+(", groupBy("+b+")");return a+")"};lf.proc.OrderByNode=function(a){lf.proc.LogicalQueryPlanNode.call(this);this.orderBy=a};goog.inherits(lf.proc.OrderByNode,lf.proc.LogicalQueryPlanNode);
lf.proc.OrderByNode.prototype.toString=function(){return"order_by("+lf.query.SelectContext.orderByToString(this.orderBy)+")"};lf.proc.AggregationNode=function(a){lf.proc.LogicalQueryPlanNode.call(this);this.columns=a};goog.inherits(lf.proc.AggregationNode,lf.proc.LogicalQueryPlanNode);lf.proc.AggregationNode.prototype.toString=function(){return"aggregation("+this.columns.toString()+")"};lf.proc.GroupByNode=function(a){lf.proc.LogicalQueryPlanNode.call(this);this.columns=a};
goog.inherits(lf.proc.GroupByNode,lf.proc.LogicalQueryPlanNode);lf.proc.GroupByNode.prototype.toString=function(){return"group_by("+this.columns.toString()+")"};lf.proc.LimitNode=function(a){lf.proc.LogicalQueryPlanNode.call(this);this.limit=a};goog.inherits(lf.proc.LimitNode,lf.proc.LogicalQueryPlanNode);lf.proc.LimitNode.prototype.toString=function(){return"limit("+this.limit+")"};lf.proc.SkipNode=function(a){lf.proc.LogicalQueryPlanNode.call(this);this.skip=a};goog.inherits(lf.proc.SkipNode,lf.proc.LogicalQueryPlanNode);
lf.proc.SkipNode.prototype.toString=function(){return"skip("+this.skip+")"};lf.proc.JoinNode=function(a,b){lf.proc.LogicalQueryPlanNode.call(this);this.predicate=a;this.isOuterJoin=b};goog.inherits(lf.proc.JoinNode,lf.proc.LogicalQueryPlanNode);lf.proc.JoinNode.prototype.toString=function(){return"join(type: "+(this.isOuterJoin?"outer":"inner")+", "+this.predicate.toString()+")"};lf.proc.CrossProductPass=function(){lf.proc.RewritePass.call(this)};goog.inherits(lf.proc.CrossProductPass,lf.proc.RewritePass);lf.proc.CrossProductPass.prototype.rewrite=function(a,b){if(3>b.from.length)return a;this.rootNode=a;this.traverse_(this.rootNode);return this.rootNode};
lf.proc.CrossProductPass.prototype.traverse_=function(a){if(a instanceof lf.proc.CrossProductNode)for(;2<a.getChildCount();){for(var b=new lf.proc.CrossProductNode,c=0;2>c;c++){var d=a.removeChildAt(0);b.addChild(d)}a.addChildAt(b,0)}a.getChildren().forEach(function(a){this.traverse_(a)},this)};lf.proc.LogicalPlanGenerator=function(){};lf.proc.LogicalPlanGenerator.prototype.generate=function(){};lf.proc.BaseLogicalPlanGenerator=function(a){this.query=a;this.rootNode_=null};lf.proc.BaseLogicalPlanGenerator.prototype.generate=function(){goog.isNull(this.rootNode_)&&(this.rootNode_=this.generateInternal());return this.rootNode_};lf.proc.InsertLogicalPlanGenerator=function(a){lf.proc.BaseLogicalPlanGenerator.call(this,a)};goog.inherits(lf.proc.InsertLogicalPlanGenerator,lf.proc.BaseLogicalPlanGenerator);
lf.proc.InsertLogicalPlanGenerator.prototype.generateInternal=function(){return this.query.allowReplace?new lf.proc.InsertOrReplaceNode(this.query.into,this.query.values):new lf.proc.InsertNode(this.query.into,this.query.values)};lf.proc.UpdateLogicalPlanGenerator=function(a){lf.proc.BaseLogicalPlanGenerator.call(this,a)};goog.inherits(lf.proc.UpdateLogicalPlanGenerator,lf.proc.BaseLogicalPlanGenerator);
lf.proc.UpdateLogicalPlanGenerator.prototype.generateInternal=function(){var a=new lf.proc.UpdateNode(this.query.table,this.query.set),b=goog.isDefAndNotNull(this.query.where)?new lf.proc.SelectNode(this.query.where.copy()):null,c=new lf.proc.TableAccessNode(this.query.table);goog.isNull(b)?a.addChild(c):(b.addChild(c),a.addChild(b));return a};lf.proc.LogicalPlanRewriter=function(a,b,c){this.rootNode_=a;this.queryContext_=b;this.rewritePasses_=c};lf.proc.LogicalPlanRewriter.prototype.generate=function(){this.rewritePasses_.forEach(function(a){this.rootNode_=a.rewrite(this.rootNode_,this.queryContext_)},this);return this.rootNode_};lf.proc.DeleteLogicalPlanGenerator=function(a,b){lf.proc.BaseLogicalPlanGenerator.call(this,a);this.rewritePasses_=b};goog.inherits(lf.proc.DeleteLogicalPlanGenerator,lf.proc.BaseLogicalPlanGenerator);
lf.proc.DeleteLogicalPlanGenerator.prototype.generateInternal=function(){var a=new lf.proc.DeleteNode(this.query.from),b=goog.isDefAndNotNull(this.query.where)?new lf.proc.SelectNode(this.query.where.copy()):null,c=new lf.proc.TableAccessNode(this.query.from);goog.isNull(b)?a.addChild(c):(b.addChild(c),a.addChild(b));return(new lf.proc.LogicalPlanRewriter(a,this.query,this.rewritePasses_)).generate()};lf.proc.OrderByStep=function(a){lf.proc.PhysicalQueryPlanNode.call(this,lf.proc.PhysicalQueryPlanNode.ANY,lf.proc.PhysicalQueryPlanNode.ExecType.FIRST_CHILD);this.orderBy=a};goog.inherits(lf.proc.OrderByStep,lf.proc.PhysicalQueryPlanNode);lf.proc.OrderByStep.prototype.toString=function(){return"order_by("+lf.query.SelectContext.orderByToString(this.orderBy)+")"};
lf.proc.OrderByStep.prototype.execInternal=function(a){if(1==a.length){var b=this.findDistinctColumn_(a[0]);(goog.isNull(b)?a[0]:a[0].getAggregationResult(b)).entries.sort(this.entryComparatorFn_.bind(this))}else a.sort(this.relationComparatorFn_.bind(this));return a};lf.proc.OrderByStep.prototype.findDistinctColumn_=function(a){for(var b=null,c=0;c<this.orderBy.length;c++){var d=lf.fn.distinct(this.orderBy[c].column);if(a.hasAggregationResult(d)){b=d;break}}return b};
lf.proc.OrderByStep.prototype.comparator_=function(a,b){var c=null,d=null,e=null,f=-1;do f++,e=this.orderBy[f].column,c=this.orderBy[f].order,d=a(e),e=b(e);while(d==e&&f+1<this.orderBy.length);d=d<e?-1:d>e?1:0;return d=c==lf.Order.ASC?d:-d};
lf.proc.OrderByStep.prototype.relationComparatorFn_=function(a,b){return this.comparator_(function(b){return b instanceof lf.fn.AggregatedColumn?a.getAggregationResult(b):a.entries[a.entries.length-1].getField(b)},function(a){return a instanceof lf.fn.AggregatedColumn?b.getAggregationResult(a):b.entries[b.entries.length-1].getField(a)})};lf.proc.OrderByStep.prototype.entryComparatorFn_=function(a,b){return this.comparator_(function(b){return a.getField(b)},function(a){return b.getField(a)})};lf.proc.SelectLogicalPlanGenerator=function(a,b){lf.proc.BaseLogicalPlanGenerator.call(this,a);this.rewritePasses_=b;this.projectNode_=this.limitNode_=this.skipNode_=this.orderByNode_=this.aggregationNode_=this.groupByNode_=this.selectNode_=this.crossProductNode_=this.tableAccessNodes_=null};goog.inherits(lf.proc.SelectLogicalPlanGenerator,lf.proc.BaseLogicalPlanGenerator);
lf.proc.SelectLogicalPlanGenerator.prototype.generateInternal=function(){this.generateNodes_();var a=this.connectNodes_();return(new lf.proc.LogicalPlanRewriter(a,this.query,this.rewritePasses_)).generate()};
lf.proc.SelectLogicalPlanGenerator.prototype.generateNodes_=function(){this.generateTableAccessNodes_();this.generateCrossProductNode_();this.generateSelectNode_();this.generateOrderByNode_();this.generateSkipNode_();this.generateLimitNode_();this.generateGroupByNode_();this.generateAggregationNode_();this.generateProjectNode_()};
lf.proc.SelectLogicalPlanGenerator.prototype.connectNodes_=function(){for(var a=[this.limitNode_,this.skipNode_,this.projectNode_,this.orderByNode_,this.aggregationNode_,this.groupByNode_,this.selectNode_,this.crossProductNode_],b=-1,c=null,d=0;d<a.length;d++){var e=a[d];goog.isNull(e)||(goog.isNull(c)?c=e:a[b].addChild(e),b=d)}this.tableAccessNodes_.forEach(function(c){a[b].addChild(c)});return c};
lf.proc.SelectLogicalPlanGenerator.prototype.generateTableAccessNodes_=function(){this.tableAccessNodes_=this.query.from.map(function(a){return new lf.proc.TableAccessNode(a)},this)};lf.proc.SelectLogicalPlanGenerator.prototype.generateCrossProductNode_=function(){2<=this.query.from.length&&(this.crossProductNode_=new lf.proc.CrossProductNode)};
lf.proc.SelectLogicalPlanGenerator.prototype.generateSelectNode_=function(){this.selectNode_=goog.isDefAndNotNull(this.query.where)?new lf.proc.SelectNode(this.query.where.copy()):null};lf.proc.SelectLogicalPlanGenerator.prototype.generateOrderByNode_=function(){this.query.orderBy&&(this.orderByNode_=new lf.proc.OrderByNode(this.query.orderBy))};lf.proc.SelectLogicalPlanGenerator.prototype.generateLimitNode_=function(){goog.isDefAndNotNull(this.query.limit)&&(this.limitNode_=new lf.proc.LimitNode(this.query.limit))};
lf.proc.SelectLogicalPlanGenerator.prototype.generateSkipNode_=function(){goog.isDefAndNotNull(this.query.skip)&&0<this.query.skip&&(this.skipNode_=new lf.proc.SkipNode(this.query.skip))};lf.proc.SelectLogicalPlanGenerator.prototype.generateGroupByNode_=function(){goog.isDefAndNotNull(this.query.groupBy)&&(this.groupByNode_=new lf.proc.GroupByNode(this.query.groupBy))};
lf.proc.SelectLogicalPlanGenerator.prototype.generateAggregationNode_=function(){var a=this.query.columns.filter(function(a){return a instanceof lf.fn.AggregatedColumn});goog.isDefAndNotNull(this.query.orderBy)&&this.query.orderBy.forEach(function(b){b.column instanceof lf.fn.AggregatedColumn&&a.push(b.column)});0<a.length&&(this.aggregationNode_=new lf.proc.AggregationNode(a))};
lf.proc.SelectLogicalPlanGenerator.prototype.generateProjectNode_=function(){this.projectNode_=new lf.proc.ProjectNode(this.query.columns||[],this.query.groupBy||null)};lf.query.UpdateContext=function(a){lf.query.Context.call(this,a)};goog.inherits(lf.query.UpdateContext,lf.query.Context);lf.query.UpdateContext.prototype.getScope=function(){var a=lf.structs.set.create();a.add(this.table);var b=this.set.map(function(a){return a.column.getNormalizedName()}),c=this.schema.info();c.getParentTablesByColumns(b).forEach(a.add.bind(a));c.getChildTablesByColumns(b).forEach(a.add.bind(a));return a};
lf.query.UpdateContext.prototype.clone=function(){var a=new lf.query.UpdateContext(this.schema);a.cloneBase(this);a.table=this.table;a.set=this.set?this.set.slice():this.set;return a};lf.query.UpdateContext.prototype.bind=function(a){lf.query.UpdateContext.superClass_.bind.call(this,a);this.set.forEach(function(b){-1!=b.binding&&(b.value=a[b.binding])});this.bindValuesInSearchCondition(a);return this};lf.schema.BaseColumn=function(a,b,c,d,e,f){this.table_=a;this.name_=b;this.isUnique_=c;this.isNullable_=d;this.type_=e;this.alias_=f||null};lf.schema.BaseColumn.prototype.getName=function(){return this.name_};lf.schema.BaseColumn.prototype.getNormalizedName=function(){return this.table_.getEffectiveName()+"."+this.name_};lf.schema.BaseColumn.prototype.toString=function(){return this.getNormalizedName()};lf.schema.BaseColumn.prototype.getTable=function(){return this.table_};
lf.schema.BaseColumn.prototype.getType=function(){return this.type_};lf.schema.BaseColumn.prototype.getAlias=function(){return this.alias_};lf.schema.BaseColumn.prototype.getIndices=function(){goog.isDefAndNotNull(this.indices_)||(this.indices_=[],this.getTable().getIndices().forEach(function(a){-1!=a.columns.map(function(a){return a.schema.getName()}).indexOf(this.name_)&&this.indices_.push(a)},this));return this.indices_};
lf.schema.BaseColumn.prototype.getIndex=function(){if(!goog.isDef(this.index_)){var a=this.getIndices().filter(function(a){return 1!=a.columns.length?!1:a.columns[0].schema.getName()==this.getName()},this);this.index_=0<a.length?a[0]:null}return this.index_};lf.schema.BaseColumn.prototype.isNullable=function(){return this.isNullable_};lf.schema.BaseColumn.prototype.isUnique=function(){return this.isUnique_};lf.schema.BaseColumn.prototype.eq=function(a){return lf.pred.createPredicate(this,a,lf.eval.Type.EQ)};
lf.schema.BaseColumn.prototype.neq=function(a){return lf.pred.createPredicate(this,a,lf.eval.Type.NEQ)};lf.schema.BaseColumn.prototype.lt=function(a){return lf.pred.createPredicate(this,a,lf.eval.Type.LT)};lf.schema.BaseColumn.prototype.lte=function(a){return lf.pred.createPredicate(this,a,lf.eval.Type.LTE)};lf.schema.BaseColumn.prototype.gt=function(a){return lf.pred.createPredicate(this,a,lf.eval.Type.GT)};lf.schema.BaseColumn.prototype.gte=function(a){return lf.pred.createPredicate(this,a,lf.eval.Type.GTE)};
lf.schema.BaseColumn.prototype.match=function(a){return lf.pred.createPredicate(this,a,lf.eval.Type.MATCH)};lf.schema.BaseColumn.prototype.between=function(a,b){return lf.pred.createPredicate(this,[a,b],lf.eval.Type.BETWEEN)};lf.schema.BaseColumn.prototype.in=function(a){return lf.pred.createPredicate(this,a,lf.eval.Type.IN)};lf.schema.BaseColumn.prototype.isNull=function(){return this.eq(null)};lf.schema.BaseColumn.prototype.isNotNull=function(){return this.neq(null)};
lf.schema.BaseColumn.prototype.as=function(a){return new lf.schema.BaseColumn(this.table_,this.name_,this.isUnique_,this.isNullable_,this.type_,a)};lf.Table=function(){};lf.backstore.BundledObjectStore=function(a,b,c){this.store_=a;this.deserializeFn_=b;this.retrievePageFn_=c};lf.backstore.BundledObjectStore.prototype.get=function(a){if(0==a.length)return this.getAll_();var b=this.deserializeFn_;return this.getPagesByRowIds_(a).then(function(c){return a.map(function(a){var e=c.get(lf.backstore.Page.toPageId(a));goog.asserts.assert(e,"Containing page is empty");return b(e.getPayload()[a])})})};
lf.backstore.BundledObjectStore.prototype.getPagesByRowIds_=function(a){var b=lf.structs.map.create(),c=goog.Promise.withResolver();a=lf.backstore.Page.toPageIds(a).map(function(a,c){return new goog.Promise(function(c,e){var h;try{h=this.store_.get(a)}catch(k){e(k);return}h.onerror=e;h.onsuccess=function(a){a=lf.backstore.Page.deserialize(a.target.result);b.set(a.getId(),a);c()}},this)},this);goog.Promise.all(a).then(function(){c.resolve(b)});return c.promise};
lf.backstore.BundledObjectStore.prototype.getAll_=function(){return new goog.Promise(function(a,b){var c=[],d;try{d=this.store_.openCursor()}catch(e){b(e);return}d.onerror=b;d.onsuccess=function(){var b=d.result;if(b){var f=lf.backstore.Page.deserialize(b.value).getPayload(),g;for(g in f)c.push(this.deserializeFn_(f[g]));b.continue()}else a(c)}.bind(this)},this)};
lf.backstore.BundledObjectStore.prototype.performWriteOp_=function(a){return new goog.Promise(function(b,c){var d;try{d=a()}catch(e){c(e);return}d.onsuccess=b;d.onerror=c},this)};
lf.backstore.BundledObjectStore.prototype.put=function(a){if(0==a.length)return goog.Promise.resolve();var b=lf.structs.map.create();a.forEach(function(a){var d=lf.backstore.Page.toPageId(a.id()),e=b.get(d)||null;goog.isNull(e)&&(e=this.retrievePageFn_(this.store_.name,d));e.setRows([a]);b.set(d,e)},this);a=lf.structs.map.values(b).map(function(a){return this.performWriteOp_(function(){return this.store_.put(a.serialize())}.bind(this))},this);return goog.Promise.all(a)};
lf.backstore.BundledObjectStore.prototype.remove=function(a){if(0==a.length)return this.performWriteOp_(function(){return this.store_.clear()}.bind(this));var b=lf.structs.map.create();a.forEach(function(a){var d=lf.backstore.Page.toPageId(a),e=b.get(d)||null;goog.isNull(e)&&(e=this.retrievePageFn_(this.store_.name,d));e.removeRows([a]);b.set(d,e)},this);a=lf.structs.map.values(b).map(function(a){return this.performWriteOp_(function(){return 0==Object.keys(a.getPayload()).length?this.store_.delete(a.getId()):
this.store_.put(a.serialize())}.bind(this))},this);return goog.Promise.all(a)};lf.backstore.BundledObjectStore.getDataTablePage_=function(a,b,c){a=a.getService(lf.service.CACHE);var d=lf.backstore.Page.getPageRange(c);b=a.getRange(b,d[0],d[1]);c=new lf.backstore.Page(c);c.setRows(b);return c};lf.backstore.BundledObjectStore.getIndexTablePage_=function(a,b){return new lf.backstore.Page(b)};
lf.backstore.BundledObjectStore.forTableType=function(a,b,c,d){a=d==lf.backstore.TableType.DATA?goog.partial(lf.backstore.BundledObjectStore.getDataTablePage_,a):lf.backstore.BundledObjectStore.getIndexTablePage_;return new lf.backstore.BundledObjectStore(b,c,a)};lf.backstore.MemoryTable=function(){this.data_=lf.structs.map.create()};lf.backstore.MemoryTable.prototype.getSync=function(a){if(0==a.length)return lf.structs.map.values(this.data_);var b=[];a.forEach(function(a){a=this.data_.get(a)||null;goog.isNull(a)||b.push(a)},this);return b};lf.backstore.MemoryTable.prototype.getData=function(){return this.data_};lf.backstore.MemoryTable.prototype.get=function(a){return goog.Promise.resolve(this.getSync(a))};
lf.backstore.MemoryTable.prototype.putSync=function(a){a.forEach(function(a){this.data_.set(a.id(),a)},this)};lf.backstore.MemoryTable.prototype.put=function(a){this.putSync(a);return goog.Promise.resolve()};lf.backstore.MemoryTable.prototype.removeSync=function(a){0==a.length||a.length==this.data_.size?this.data_.clear():a.forEach(function(a){this.data_.delete(a)},this)};lf.backstore.MemoryTable.prototype.remove=function(a){this.removeSync(a);return goog.Promise.resolve()};
lf.backstore.MemoryTable.prototype.getMaxRowId=function(){return 0==this.data_.size?0:lf.structs.map.keys(this.data_).reduce(function(a,b){return a>b?a:b},0)};lf.backstore.ObjectStore=function(a,b){this.store_=a;this.deserializeFn_=b};lf.backstore.ObjectStore.prototype.get=function(a){if(0==a.length)return goog.isDefAndNotNull(this.store_.getAll)?this.getAllBulk_():this.getAllWithCursor_();a=a.map(function(a,c){return new goog.Promise(function(c,e){var f;try{f=this.store_.get(a)}catch(g){e(g);return}f.onerror=e;f.onsuccess=function(a){c(this.deserializeFn_(a.target.result))}.bind(this)},this)},this);return goog.Promise.all(a)};
lf.backstore.ObjectStore.prototype.getAllWithCursor_=function(){return new goog.Promise(function(a,b){var c=[],d;try{d=this.store_.openCursor()}catch(e){b(e);return}d.onerror=b;d.onsuccess=function(){var b=d.result;b?(c.push(this.deserializeFn_(b.value)),b.continue()):a(c)}.bind(this)},this)};
lf.backstore.ObjectStore.prototype.getAllBulk_=function(){return new goog.Promise(function(a,b){var c;try{c=this.store_.getAll()}catch(d){b(d);return}c.onerror=b;c.onsuccess=function(){var b=c.result.map(function(a){return this.deserializeFn_(a)},this);a(b)}.bind(this)},this)};lf.backstore.ObjectStore.prototype.performWriteOp_=function(a){return new goog.Promise(function(b,c){var d;try{d=a()}catch(e){c(e);return}d.onsuccess=b;d.onerror=c},this)};
lf.backstore.ObjectStore.prototype.put=function(a){if(0==a.length)return goog.Promise.resolve();a=a.map(function(a){return this.performWriteOp_(function(){return this.store_.put(a.serialize())}.bind(this))},this);return goog.Promise.all(a)};
lf.backstore.ObjectStore.prototype.remove=function(a){return new goog.Promise(function(b,c){var d=this.store_.count();d.onsuccess=function(d){if(0==a.length||d.target.result==a.length)return this.performWriteOp_(function(){return this.store_.clear()}.bind(this)).then(b,c);d=a.map(function(a){return this.performWriteOp_(function(){return this.store_.delete(a)}.bind(this))},this);goog.Promise.all(d).then(b,c)}.bind(this);d.onerror=c},this)};lf.backstore.WebSqlTable=function(a,b,c){this.tx_=a;this.name_='"'+b+'"';this.deserializeFn_=c};lf.backstore.WebSqlTable.prototype.get=function(a){a=0==a.length?"":"WHERE id IN ("+a.join(",")+")";var b=this.deserializeFn_;return this.tx_.queue("SELECT id, value FROM "+this.name_+" "+a,[],function(a){for(var d=a.rows.length,e=Array(d),f=0;f<d;++f)e[f]=b({id:a.rows.item(f).id,value:JSON.parse(a.rows.item(f).value)});return e})};
lf.backstore.WebSqlTable.prototype.put=function(a){if(0==a.length)return goog.Promise.resolve();var b="INSERT OR REPLACE INTO "+this.name_+"(id, value) VALUES (?, ?)";a.forEach(function(a){this.tx_.queue(b,[a.id(),JSON.stringify(a.payload())])},this);return goog.Promise.resolve()};lf.backstore.WebSqlTable.prototype.remove=function(a){a=0==a.length?"":"WHERE id IN ("+a.join(",")+")";this.tx_.queue("DELETE FROM "+this.name_+" "+a,[]);return goog.Promise.resolve()};lf.TransactionType={};lf.TransactionType.READ_ONLY=0;lf.TransactionType.READ_WRITE=1;lf.Transaction=function(){};lf.cache.Prefetcher=function(a){this.backStore_=a.getService(lf.service.BACK_STORE);this.indexStore_=a.getService(lf.service.INDEX_STORE);this.cache_=a.getService(lf.service.CACHE)};lf.cache.Prefetcher.prototype.init=function(a){var b=a.tables(),c=function(){if(0==b.length)return goog.Promise.resolve();var a=b.shift();return(a.persistentIndex()?this.fetchTableWithPersistentIndices_(a):this.fetchTable_(a)).then(c)}.bind(this);return c()};
lf.cache.Prefetcher.prototype.fetchTable_=function(a){var b=this.backStore_.createTx(lf.TransactionType.READ_ONLY,[a]),c=b.getTable(a.getName(),a.deserializeRow.bind(a),lf.backstore.TableType.DATA).get([]).then(function(b){this.cache_.setMany(a.getName(),b);this.reconstructNonPersistentIndices_(a,b)}.bind(this));b.commit();return c};
lf.cache.Prefetcher.prototype.reconstructNonPersistentIndices_=function(a,b){var c=this.indexStore_.getTableIndices(a.getName());b.forEach(function(a){c.forEach(function(b){var c=a.keyOfIndex(b.getName());b.add(c,a.id())})})};
lf.cache.Prefetcher.prototype.fetchTableWithPersistentIndices_=function(a){var b=this.backStore_.createTx(lf.TransactionType.READ_ONLY,[a]),c=b.getTable(a.getName(),a.deserializeRow,lf.backstore.TableType.DATA).get([]).then(function(b){this.cache_.setMany(a.getName(),b)}.bind(this)),d=a.getIndices().map(function(a){return this.reconstructPersistentIndex_(a,b)},this).concat(this.reconstructPersistentRowIdIndex_(a,b));b.commit();return goog.Promise.all(d.concat(c))};
lf.cache.Prefetcher.prototype.reconstructPersistentIndex_=function(a,b){var c=b.getTable(a.getNormalizedName(),lf.Row.deserialize,lf.backstore.TableType.INDEX),d=lf.index.ComparatorFactory.create(a);return c.get([]).then(function(b){if(0<b.length){if(a.hasNullableColumn()){var c=lf.index.BTree.deserialize.bind(void 0,d,a.getNormalizedName(),a.isUnique);b=lf.index.NullableIndex.deserialize(c,b)}else b=lf.index.BTree.deserialize(d,a.getNormalizedName(),a.isUnique,b);this.indexStore_.set(a.tableName,
b)}}.bind(this))};lf.cache.Prefetcher.prototype.reconstructPersistentRowIdIndex_=function(a,b){return b.getTable(a.getRowIdIndexName(),lf.Row.deserialize,lf.backstore.TableType.INDEX).get([]).then(function(b){0<b.length&&(b=lf.index.RowId.deserialize(a.getRowIdIndexName(),b),this.indexStore_.set(a.getName(),b))}.bind(this))};lf.proc.ExportTask=function(a){this.global_=a;this.schema_=a.getService(lf.service.SCHEMA);this.scope_=lf.structs.set.create(this.schema_.tables());this.resolver_=goog.Promise.withResolver()};
lf.proc.ExportTask.prototype.execSync=function(){var a=this.global_.getService(lf.service.INDEX_STORE),b=this.global_.getService(lf.service.CACHE),c={};this.schema_.tables().forEach(function(d){var e=a.get(d.getRowIdIndexName()).getRange(),e=b.getMany(e).map(function(a){return a.payload()});c[d.getName()]=e});return{name:this.schema_.name(),version:this.schema_.version(),tables:c}};
lf.proc.ExportTask.prototype.exec=function(){var a=this.execSync(),a=new lf.proc.RelationEntry(new lf.Row(lf.Row.DUMMY_ID,a),!0);return goog.Promise.resolve([new lf.proc.Relation([a],[])])};lf.proc.ExportTask.prototype.getType=function(){return lf.TransactionType.READ_ONLY};lf.proc.ExportTask.prototype.getScope=function(){return this.scope_};lf.proc.ExportTask.prototype.getResolver=function(){return this.resolver_};lf.proc.ExportTask.prototype.getId=function(){return goog.getUid(this)};
lf.proc.ExportTask.prototype.getPriority=function(){return lf.proc.TaskPriority.EXPORT_TASK};lf.proc.Runner=function(){this.queue_=new lf.proc.Runner.TaskQueue_;this.lockManager_=new lf.proc.LockManager};lf.proc.Runner.prototype.scheduleTask=function(a){(a.getPriority()<lf.proc.TaskPriority.USER_QUERY_TASK||a.getPriority()<lf.proc.TaskPriority.TRANSACTION_TASK)&&this.lockManager_.clearReservedLocks(a.getScope());this.queue_.insert(a);this.consumePending_();return a.getResolver().promise};
lf.proc.Runner.prototype.consumePending_=function(){for(var a=this.queue_.getValues(),b=0;b<a.length;b++){var c=a[b],d=!1;if(d=c.getType()==lf.TransactionType.READ_ONLY?this.requestTwoPhaseLock_(c,lf.proc.LockType.RESERVED_READ_ONLY,lf.proc.LockType.SHARED):this.requestTwoPhaseLock_(c,lf.proc.LockType.RESERVED_READ_WRITE,lf.proc.LockType.EXCLUSIVE))this.queue_.remove(c),this.execTask_(c)}};
lf.proc.Runner.prototype.requestTwoPhaseLock_=function(a,b,c){var d=!1;this.lockManager_.requestLock(a.getId(),a.getScope(),b)&&(d=this.lockManager_.requestLock(a.getId(),a.getScope(),c));return d};lf.proc.Runner.prototype.execTask_=function(a){a.exec().then(this.onTaskSuccess_.bind(this,a),this.onTaskError_.bind(this,a))};lf.proc.Runner.prototype.onTaskSuccess_=function(a,b){this.lockManager_.releaseLock(a.getId(),a.getScope());a.getResolver().resolve(b);this.consumePending_()};
lf.proc.Runner.prototype.onTaskError_=function(a,b){this.lockManager_.releaseLock(a.getId(),a.getScope());a.getResolver().reject(b);this.consumePending_()};lf.proc.Runner.TaskQueue_=function(){this.queue_=[]};lf.proc.Runner.TaskQueue_.prototype.insert=function(a){lf.structs.array.binaryInsert(this.queue_,a,function(a,c){var d=a.getPriority()-c.getPriority();return 0==d?a.getId()-c.getId():d})};lf.proc.Runner.TaskQueue_.prototype.getValues=function(){return this.queue_.slice()};
lf.proc.Runner.TaskQueue_.prototype.remove=function(a){return goog.array.remove(this.queue_,a)};lf.TransactionStats=function(a,b,c,d,e){this.success_=a;this.insertedRowCount_=b;this.updatedRowCount_=c;this.deletedRowCount_=d;this.changedTableCount_=e};lf.TransactionStats.prototype.success=function(){return this.success_};lf.TransactionStats.prototype.insertedRowCount=function(){return this.insertedRowCount_};lf.TransactionStats.prototype.updatedRowCount=function(){return this.updatedRowCount_};lf.TransactionStats.prototype.deletedRowCount=function(){return this.deletedRowCount_};
lf.TransactionStats.prototype.changedTableCount=function(){return this.changedTableCount_};lf.TransactionStats.getDefault=function(){return new lf.TransactionStats(!1,0,0,0,0)};lf.backstore.BaseTx=function(a,b){this.txType=a;this.journal_=b||null;this.resolver=goog.Promise.withResolver();this.success_=!1;this.stats_=null};lf.backstore.BaseTx.prototype.getJournal=function(){return this.journal_};lf.backstore.BaseTx.prototype.commit=function(){return(this.txType==lf.TransactionType.READ_ONLY?this.commitInternal():this.commitReadWrite_()).then(function(a){this.success_=!0;return a}.bind(this))};
lf.backstore.BaseTx.prototype.commitReadWrite_=function(){try{this.journal_.checkDeferredConstraints()}catch(a){return goog.Promise.reject(a)}return this.mergeIntoBackstore_().then(function(a){this.journal_.commit();return a}.bind(this))};lf.backstore.BaseTx.prototype.mergeIntoBackstore_=function(){this.mergeTableChanges_();this.mergeIndexChanges_();return this.commitInternal()};
lf.backstore.BaseTx.prototype.mergeTableChanges_=function(){this.journal_.getDiff().forEach(function(a,b){var c=this.journal_.getScope().get(b),c=this.getTable(c.getName(),c.deserializeRow.bind(c),lf.backstore.TableType.DATA),d=lf.structs.map.values(a.getDeleted()).map(function(a){return a.id()});0<d.length&&c.remove(d).thenCatch(this.handleError_,this);d=lf.structs.map.values(a.getModified()).map(function(a){return a[1]}).concat(lf.structs.map.values(a.getAdded()));c.put(d).thenCatch(this.handleError_,
this)},this)};lf.backstore.BaseTx.prototype.mergeIndexChanges_=function(){this.journal_.getIndexDiff().forEach(function(a){var b=this.getTable(a.getName(),lf.Row.deserialize,lf.backstore.TableType.INDEX);b.remove([]);b.put(a.serialize())},this)};lf.backstore.BaseTx.prototype.handleError_=function(a){this.resolver.reject(a)};
lf.backstore.BaseTx.prototype.stats=function(){if(goog.isNull(this.stats_))if(this.success_)if(this.txType==lf.TransactionType.READ_ONLY)this.stats_=new lf.TransactionStats(!0,0,0,0,0);else{var a=0,b=0,c=0,d=0;this.journal_.getDiff().forEach(function(e,f){d++;a+=e.getAdded().size;c+=e.getModified().size;b+=e.getDeleted().size});this.stats_=new lf.TransactionStats(!0,a,c,b,d)}else this.stats_=lf.TransactionStats.getDefault();return this.stats_};lf.backstore.FirebaseTx=function(a,b,c){lf.backstore.BaseTx.call(this,b,c);this.db_=a};goog.inherits(lf.backstore.FirebaseTx,lf.backstore.BaseTx);lf.backstore.FirebaseTx.prototype.getTable=function(a,b){return this.db_.getTableInternal(a)};
lf.backstore.FirebaseTx.prototype.commitInternal=function(){if(this.txType==lf.TransactionType.READ_ONLY)return this.resolver.resolve(),this.resolver.promise;var a=this.getJournal().getDiff();if(0==a.size)this.resolver.resolve();else{var b=this.db_.getRevision()+1;this.db_.setRevision(b);var c={"@rev":{R:b}};a.forEach(function(a,e){var f=this.db_.getTableId(e);a.getAdded().forEach(function(a,d){c[d]={R:b,T:f,P:a.payload()}});a.getModified().forEach(function(a,d){c[d]={R:b,T:f,P:a[1].payload()}});
a.getDeleted().forEach(function(a,b){c[b]=null})},this);this.db_.getRef().update(c,function(c){goog.isNull(c)?this.resolver.resolve():(this.db_.setRevision(b-1),c=lf.structs.map.values(a).map(function(a){return this.db_.reloadTable(a.getName())},this),goog.Promise.all(c).then(this.resolver.reject.bind(this.resolver),this.resolver.reject.bind(this.resolver)))}.bind(this))}return this.resolver.promise};lf.backstore.Firebase=function(a,b){this.schema_=a;this.app_=b;this.removedRows_=lf.structs.map.create();this.revision_=-1;this.tables_=lf.structs.map.create();this.tableIds_=lf.structs.map.create();this.changeHandler_=null};lf.backstore.Firebase.prototype.getRevision=function(){return this.revision_};lf.backstore.Firebase.prototype.setRevision=function(a){this.revision_=a};
lf.backstore.Firebase.prototype.init=function(a){this.db_=this.app_.child(this.schema_.name());var b=lf.backstore.FirebaseRawBackStore.getValue,c=a||function(){return goog.Promise.resolve()};return b(this.db_,"@db/version").then(function(a){return goog.isNull(a)?lf.backstore.FirebaseRawBackStore.setValue(this.db_,this.createNewDb_(),!0).then(function(){var a=new lf.backstore.FirebaseRawBackStore(0,this.db_);return c(a)}.bind(this)).then(function(){return this.init()}.bind(this)):a==this.schema_.version()?
b(this.db_,"@rev/R").then(function(a){this.revision_=a;return b(this.db_,"@table")}.bind(this)).then(function(a){for(var b in a)this.tableIds_.set(b,a[b]);a=this.schema_.tables().map(function(a){return this.reloadTable(a.getName())},this);return goog.Promise.all(a)}.bind(this)).then(function(){this.initRowId_();this.listen_();return goog.Promise.resolve()}.bind(this)):this.onUpgrade_(a,c).then(function(){return this.init()}.bind(this))}.bind(this))};
lf.backstore.Firebase.prototype.onUpgrade_=function(a,b){var c=new lf.backstore.FirebaseRawBackStore(a,this.db_);return c.init(this.schema_).then(function(){return this.updateIndexTables_()}.bind(this)).then(function(){return b(c)}).then(function(){var a=this.db_.child("@db");return lf.backstore.FirebaseRawBackStore.setValue(a,{version:this.schema_.version()},!0)}.bind(this))};lf.backstore.Firebase.prototype.updateIndexTables_=function(){return goog.Promise.resolve()};
lf.backstore.Firebase.prototype.listen_=function(){this.db_.off();this.db_.on("child_removed",this.onRemoved_.bind(this));this.change_&&(this.change_.off(),this.removedRows_.clear());this.change_=this.db_.orderByChild("R").startAt(this.revision_+1);this.change_.on("value",this.onChange_.bind(this))};lf.backstore.Firebase.prototype.initRowId_=function(){var a=lf.structs.map.values(this.tables_).map(function(a){return a.getMaxRowId()}).reduce(function(a,c){return a>c?a:c},0);lf.Row.setNextId(a+1)};
lf.backstore.Firebase.prototype.onRemoved_=function(a){var b=a.val(),c=this.removedRows_.get(b.T)||null;goog.isNull(c)&&(c=lf.structs.set.create(),this.removedRows_.set(b.T,c));c.add(parseInt(a.key(),10))};
lf.backstore.Firebase.prototype.onChange_=function(a){var b=a.child("@rev/R").val();goog.isDefAndNotNull(b)&&b!=this.revision_&&(this.revision_=b,a=this.generateDiff_(a),a.forEach(function(a){var b=this.tables_.get(a.getName()),e=lf.structs.map.keys(a.getDeleted());0<e.length&&b.removeSync(e);var f=lf.structs.map.values(a.getAdded());a.getModified().forEach(function(a){f.push(a[1])});b.putSync(f)},this),0<a.length&&this.notify(a),this.listen_())};
lf.backstore.Firebase.prototype.generateDiff_=function(a){var b=lf.structs.set.create(),c=lf.structs.map.create();this.tableIds_.forEach(function(a,e){var f=this.tables_.get(e),g=new lf.cache.TableDiff(e);if(this.removedRows_.has(a)){var h=lf.structs.set.values(this.removedRows_.get(a));h.forEach(function(a){b.add(a)});f.getSync(h).forEach(function(a){g.delete(a)})}c.set(a,g)}.bind(this));a.forEach(function(a){if("@rev"!=a.key()){var e=parseInt(a.key(),10);if(!b.has(e)){var f=a.val();a=c.get(f.T);
var g=this.tables_.get(a.getName()),f=this.schema_.table(a.getName()).deserializeRow({id:e,value:f.P});g.getData().has(e)?a.modify([g.getSync([e])[0],f]):a.add(f)}}}.bind(this));return lf.structs.map.values(c).filter(function(a){return!a.isEmpty()})};
lf.backstore.Firebase.prototype.reloadTable=function(a){var b=goog.Promise.withResolver(),c=this.getTableId(a),d=this.schema_.table(a);this.db_.orderByChild("T").equalTo(c).once("value",function(c){var f=new lf.backstore.MemoryTable,g=[];c.forEach(function(a){g.push(d.deserializeRow({id:parseInt(a.key(),10),value:a.val().P}))});f.putSync(g);this.tables_.set(a,f);b.resolve()}.bind(this));return b.promise};lf.backstore.Firebase.prototype.getTableId=function(a){return this.tableIds_.get(a)};
lf.backstore.Firebase.prototype.createNewDb_=function(){var a={};a["@db"]={version:this.schema_.version()};a["@rev"]={R:1};this.revision_=1;a["@table"]={};this.schema_.tables().forEach(function(b,c){var d=b.getName();a["@table"][d]=c;this.tables_.set(d,new lf.backstore.MemoryTable);this.tableIds_.set(d,c)},this);return a};lf.backstore.Firebase.prototype.createTx=function(a,b,c){return new lf.backstore.FirebaseTx(this,a,c)};
lf.backstore.Firebase.prototype.getTableInternal=function(a){var b=this.tables_.get(a)||null;if(!goog.isNull(b))return b;throw new lf.Exception(101,a);};lf.backstore.Firebase.prototype.getRef=function(){return this.db_};lf.backstore.Firebase.prototype.close=function(){};lf.backstore.Firebase.prototype.subscribe=function(a){this.changeHandler_=a};lf.backstore.Firebase.prototype.unsubscribe=function(){this.changeHandler_=null};
lf.backstore.Firebase.prototype.notify=function(a){goog.isDefAndNotNull(this.changeHandler_)&&this.changeHandler_(a)};lf.backstore.IndexedDBTx=function(a,b,c,d,e){lf.backstore.BaseTx.call(this,c,e);this.global_=a;this.tx_=b;this.bundleMode_=d;this.tx_.oncomplete=this.resolver.resolve.bind(this.resolver);this.tx_.onabort=this.resolver.reject.bind(this.resolver)};goog.inherits(lf.backstore.IndexedDBTx,lf.backstore.BaseTx);
lf.backstore.IndexedDBTx.prototype.getTable=function(a,b,c){return this.bundleMode_?(c=goog.isDefAndNotNull(c)?c:lf.backstore.TableType.DATA,lf.backstore.BundledObjectStore.forTableType(this.global_,this.tx_.objectStore(a),b,c)):new lf.backstore.ObjectStore(this.tx_.objectStore(a),b)};lf.backstore.IndexedDBTx.prototype.abort=function(){this.tx_.abort()};lf.backstore.IndexedDBTx.prototype.commitInternal=function(){return this.resolver.promise};lf.backstore.IndexedDB=function(a,b){this.global_=a;this.schema_=b;this.bundledMode_=b.pragma().enableBundledMode||!1};
lf.backstore.IndexedDB.prototype.init=function(a){var b=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB;if(!goog.isDefAndNotNull(b))throw new lf.Exception(352);var c=a||function(a){return goog.Promise.resolve()};return new goog.Promise(function(a,e){var f;try{f=b.open(this.schema_.name(),this.schema_.version())}catch(g){e(g);return}f.onerror=function(a){a=a.target.error;e(new lf.Exception(361,a.name,a.message))};f.onupgradeneeded=function(a){this.onUpgradeNeeded_(c,
a).then(function(){},e)}.bind(this);f.onsuccess=function(b){this.db_=b.target.result;this.scanRowId_().then(function(b){lf.Row.setNextId(b+1);a(this.db_)}.bind(this))}.bind(this)},this)};lf.backstore.IndexedDB.prototype.onUpgradeNeeded_=function(a,b){var c=b.target.result,d=b.target.transaction,e=new lf.backstore.IndexedDBRawBackStore(b.oldVersion,c,d,this.bundledMode_);this.removeIndexTables_(c,d);this.createTables_(c);return a(e)};
lf.backstore.IndexedDB.prototype.removeIndexTables_=function(a,b){for(var c=[],d=0;d<a.objectStoreNames.length;++d){var e=a.objectStoreNames.item(d);-1!=e.indexOf(".")&&c.push(e)}c.forEach(function(b){try{a.deleteObjectStore(b)}catch(c){}})};lf.backstore.IndexedDB.prototype.createTables_=function(a){this.schema_.tables().forEach(goog.partial(this.createObjectStoresForTable_,a),this)};
lf.backstore.IndexedDB.prototype.createObjectStoresForTable_=function(a,b){a.objectStoreNames.contains(b.getName())||a.createObjectStore(b.getName(),{keyPath:"id"});b.persistentIndex()&&(b.getIndices().forEach(function(b){this.createIndexTable_(a,b.getNormalizedName())},this),this.createIndexTable_(a,b.getRowIdIndexName()))};lf.backstore.IndexedDB.prototype.createIndexTable_=function(a,b){a.objectStoreNames.contains(b)||a.createObjectStore(b,{keyPath:"id"})};
lf.backstore.IndexedDB.prototype.createTx=function(a,b,c){b=this.db_.transaction(lf.backstore.IndexedDB.getIndexedDBScope_(b),a==lf.TransactionType.READ_ONLY?"readonly":"readwrite");return new lf.backstore.IndexedDBTx(this.global_,b,a,this.bundledMode_,c)};
lf.backstore.IndexedDB.getIndexedDBScope_=function(a){var b=lf.structs.set.create();a.forEach(function(a){b.add(a.getName());a.persistentIndex()&&(a.getIndices().forEach(function(a){b.add(a.getNormalizedName())}),b.add(a.getRowIdIndexName()))});return lf.structs.set.values(b)};
lf.backstore.IndexedDB.prototype.scanRowId_=function(a){var b=this.schema_.tables().map(function(a){return a.getName()}),c=this.db_,d=0,e=function(a){return this.bundledMode_?(a=lf.backstore.Page.deserialize(a.value),Object.keys(a.getPayload()).reduce(function(a,b){return Math.max(a,b)},0)):a.key}.bind(this),f=function(b){return new goog.Promise(function(f,g){var l;try{l=(a||c.transaction([b])).objectStore(b).openCursor(null,"prev")}catch(m){g(m);return}l.onsuccess=function(a){(a=a.target.result)&&
(d=Math.max(d,e(a)));f(d)};l.onerror=function(){f(d)}})},g=function(){if(0==b.length)return goog.Promise.resolve();var a=b.shift();return f(a).then(g)};return new goog.Promise(function(a,b){g().then(function(){a(d)})})};lf.backstore.IndexedDB.prototype.close=function(){this.db_.close()};lf.backstore.IndexedDB.prototype.getTableInternal=function(a){throw new lf.Exception(511);};lf.backstore.IndexedDB.prototype.subscribe=function(a){};lf.backstore.IndexedDB.prototype.unsubscribe=function(){};
lf.backstore.IndexedDB.prototype.notify=function(a){};lf.backstore.MemoryTx=function(a,b,c){lf.backstore.BaseTx.call(this,b,c);this.store_=a;b==lf.TransactionType.READ_ONLY&&this.resolver.resolve()};goog.inherits(lf.backstore.MemoryTx,lf.backstore.BaseTx);lf.backstore.MemoryTx.prototype.getTable=function(a,b,c){return this.store_.getTableInternal(a)};lf.backstore.MemoryTx.prototype.abort=function(){this.resolver.reject(void 0)};lf.backstore.MemoryTx.prototype.commitInternal=function(){this.resolver.resolve();return this.resolver.promise};lf.backstore.Memory=function(a){this.schema_=a;this.tables_=lf.structs.map.create()};lf.backstore.Memory.prototype.init=function(a){this.schema_.tables().forEach(this.initTable_,this);return goog.Promise.resolve()};lf.backstore.Memory.prototype.getTableInternal=function(a){var b=this.tables_.get(a)||null;if(goog.isNull(b))throw new lf.Exception(101,a);return b};lf.backstore.Memory.prototype.createTx=function(a,b,c){return new lf.backstore.MemoryTx(this,a,c)};
lf.backstore.Memory.prototype.createTable_=function(a){if(!this.tables_.has(a)){var b=new lf.backstore.MemoryTable;this.tables_.set(a,b);return b}return null};lf.backstore.Memory.prototype.initTable_=function(a){this.createTable_(a.getName());a.persistentIndex()&&(a.getIndices().forEach(function(a){this.createTable_(a.getNormalizedName())},this),this.createTable_(a.getRowIdIndexName()))};lf.backstore.Memory.prototype.close=function(){};lf.backstore.Memory.prototype.subscribe=function(a){};
lf.backstore.Memory.prototype.unsubscribe=function(){};lf.backstore.Memory.prototype.notify=function(a){};lf.backstore.ObservableStore=function(a){lf.backstore.Memory.call(this,a);this.observer_=null};goog.inherits(lf.backstore.ObservableStore,lf.backstore.Memory);lf.backstore.ObservableStore.prototype.subscribe=function(a){goog.isNull(this.observer_)&&(this.observer_=a)};lf.backstore.ObservableStore.prototype.unsubscribe=function(){this.observer_=null};lf.backstore.ObservableStore.prototype.notify=function(a){goog.isNull(this.observer_)||this.observer_(a)};lf.backstore.WebSqlTx=function(a,b,c){lf.backstore.BaseTx.call(this,b,c);this.db_=a;this.tables_=lf.structs.map.create();this.commands_=[]};goog.inherits(lf.backstore.WebSqlTx,lf.backstore.BaseTx);lf.backstore.WebSqlTx.INDEX_MARK="__d__";lf.backstore.WebSqlTx.escapeTableName=function(a){return a.replace(".",lf.backstore.WebSqlTx.INDEX_MARK).replace("#","__s__")};
lf.backstore.WebSqlTx.prototype.getTable=function(a,b){var c=this.tables_.get(a)||null;goog.isNull(c)&&(c=new lf.backstore.WebSqlTable(this,lf.backstore.WebSqlTx.escapeTableName(a),b),this.tables_.set(a,c));return c};lf.backstore.WebSqlTx.prototype.queue=function(a,b,c){var d=goog.Promise.withResolver();this.commands_.push({statement:a,params:b,transform:c,resolver:d});return d.promise};
lf.backstore.WebSqlTx.prototype.commitInternal=function(){var a=null,b=this.resolver.reject.bind(this.resolver),c=function(a,b){this.resolver.reject(b)}.bind(this),d=[],e=function(b,g){if(!goog.isNull(a)){var h=g;goog.isDefAndNotNull(a.transform)&&goog.isDefAndNotNull(g)&&(h=a.transform(g));d.push(h);a.resolver.resolve(h)}0<this.commands_.length?(a=h=this.commands_.shift(),b.executeSql(h.statement,h.params,e,c)):this.resolver.resolve(d)}.bind(this);this.txType==lf.TransactionType.READ_ONLY?this.db_.readTransaction(e,
b):this.db_.transaction(e,b);return this.resolver.promise};lf.backstore.WebSqlTx.prototype.abort=function(){this.commands_=[]};lf.backstore.WebSqlRawBackStore=function(a,b,c){this.db_=c;this.global_=a;this.version_=b};lf.backstore.WebSqlRawBackStore.prototype.getRawDBInstance=function(){return this.db_};lf.backstore.WebSqlRawBackStore.prototype.getRawTransaction=function(){throw new lf.Exception(356);};lf.backstore.WebSqlRawBackStore.prototype.createTx_=function(){return new lf.backstore.WebSqlTx(this.db_,lf.TransactionType.READ_WRITE,new lf.cache.Journal(this.global_,lf.structs.set.create()))};
lf.backstore.WebSqlRawBackStore.prototype.dropTable=function(a){var b=this.createTx_();b.queue("DROP TABLE "+a,[]);return b.commit()};lf.backstore.WebSqlRawBackStore.prototype.dumpTable_=function(a){var b=this.createTx_();b.queue("SELECT id, value FROM "+a,[]);return b.commit().then(function(a){for(var b=a[0].rows.length,e=Array(b),f=0;f<b;++f)e[f]={id:a[0].rows.item(f).id,value:JSON.parse(a[0].rows.item(f).value)};return goog.Promise.resolve(e)})};
lf.backstore.WebSqlRawBackStore.prototype.transformColumn_=function(a,b){var c=this.createTx_(),d="UPDATE "+a+" SET value=? WHERE id=?";return this.dumpTable_(a).then(function(a){a.forEach(function(a){a=b(a);c.queue(d,[JSON.stringify(a.value),a.id])});return c.commit()})};lf.backstore.WebSqlRawBackStore.prototype.addTableColumn=function(a,b,c){var d=lf.backstore.IndexedDBRawBackStore.convert(c);return this.transformColumn_(a,function(a){a.value[b]=d;return a})};
lf.backstore.WebSqlRawBackStore.prototype.dropTableColumn=function(a,b){return this.transformColumn_(a,function(a){delete a.value[b];return a})};lf.backstore.WebSqlRawBackStore.prototype.renameTableColumn=function(a,b,c){return this.transformColumn_(a,function(a){a.value[c]=a.value[b];delete a.value[b];return a})};lf.backstore.WebSqlRawBackStore.prototype.createRow=function(a){var b={},c;for(c in a)b[c]=lf.backstore.IndexedDBRawBackStore.convert(a[c]);return lf.Row.create(b)};
lf.backstore.WebSqlRawBackStore.prototype.getVersion=function(){return this.version_};lf.backstore.WebSqlRawBackStore.queueListTables=function(a){a.queue('SELECT tbl_name FROM sqlite_master WHERE type="table"',[],function(a){for(var c=Array(a.rows.length),d=0;d<c.length;++d)c[d]=a.rows.item(d).tbl_name;return c})};
lf.backstore.WebSqlRawBackStore.prototype.dump=function(){var a=goog.Promise.withResolver(),b=this.createTx_();lf.backstore.WebSqlRawBackStore.queueListTables(b);var c={};b.commit().then(function(b){b=b[0].filter(function(a){return"__lf_ver"!=a&&"__WebKitDatabaseInfoTable__"!=a}).map(function(a){return this.dumpTable_(a).then(function(b){c[a]=b})},this);goog.Promise.all(b).then(function(){a.resolve(c)})}.bind(this));return a.promise};lf.backstore.WebSql=function(a,b,c){this.global_=a;this.schema_=b;this.size_=c||1};lf.backstore.WebSql.prototype.getEmptyJournal_=function(){return new lf.cache.Journal(this.global_,lf.structs.set.create())};
lf.backstore.WebSql.prototype.init=function(a){if(!goog.isDefAndNotNull(window.openDatabase))throw new lf.Exception(353);var b=a||function(a){return goog.Promise.resolve()};return new goog.Promise(function(a,d){var e=window.openDatabase(this.schema_.name(),"",this.schema_.name(),this.size_);if(goog.isDefAndNotNull(e))this.db_=e,this.checkVersion_(b).then(function(){this.scanRowId_().then(a,d)}.bind(this),function(a){if(a instanceof lf.Exception)throw a;throw new lf.Exception(354,a.message);});else throw new lf.Exception(354);
},this)};
lf.backstore.WebSql.prototype.checkVersion_=function(a){var b=goog.Promise.withResolver(),c=new lf.backstore.WebSqlTx(this.db_,lf.TransactionType.READ_WRITE,this.getEmptyJournal_());c.queue("CREATE TABLE IF NOT EXISTS __lf_ver(id INTEGER PRIMARY KEY, v INTEGER)",[]);c.queue("SELECT v FROM __lf_ver WHERE id = 0",[]);c.commit().then(function(c){var e=0;c[1].rows.length&&(e=c[1].rows.item(0).v);e<this.schema_.version()?this.onUpgrade_(a,e).then(b.resolve.bind(b)):e>this.schema_.version()?b.reject(new lf.Exception(108)):b.resolve()}.bind(this),
b.reject.bind(b));return b.promise};lf.backstore.WebSql.prototype.initialized=function(){return goog.isDefAndNotNull(this.db_)};lf.backstore.WebSql.prototype.createTx=function(a,b,c){if(goog.isDefAndNotNull(this.db_))return new lf.backstore.WebSqlTx(this.db_,a,c);throw new lf.Exception(2);};lf.backstore.WebSql.prototype.close=function(){};lf.backstore.WebSql.prototype.getTableInternal=function(a){throw new lf.Exception(512);};
lf.backstore.WebSql.prototype.notSupported_=function(){throw new lf.Exception(355);};lf.backstore.WebSql.prototype.subscribe=function(a){this.notSupported_()};lf.backstore.WebSql.prototype.unsubscribe=function(){this.notSupported_()};lf.backstore.WebSql.prototype.notify=function(a){this.notSupported_()};lf.backstore.WebSql.prototype.onUpgrade_=function(a,b){return this.preUpgrade_().then(function(){var c=new lf.backstore.WebSqlRawBackStore(this.global_,b,this.db_);return a(c)}.bind(this))};
lf.backstore.WebSql.escape_=function(a){return'"'+a+'"'};
lf.backstore.WebSql.prototype.preUpgrade_=function(){var a=this.schema_.tables(),b=new lf.backstore.WebSqlTx(this.db_,lf.TransactionType.READ_WRITE,this.getEmptyJournal_()),c=new lf.backstore.WebSqlTx(this.db_,lf.TransactionType.READ_WRITE,this.getEmptyJournal_());b.queue("INSERT OR REPLACE INTO __lf_ver VALUES (0, ?)",[this.schema_.version()]);lf.backstore.WebSqlRawBackStore.queueListTables(b);return b.commit().then(function(b){var e=b[1];e.filter(function(a){return-1!=a.indexOf(lf.backstore.WebSqlTx.INDEX_MARK)}).forEach(function(a){c.queue("DROP TABLE "+
lf.backstore.WebSql.escape_(a),[])});var f=[],g=[],h=[];a.map(function(a){-1==e.indexOf(a.getName())&&f.push(a.getName());a.persistentIndex&&(a.getIndices().forEach(function(a){a=lf.backstore.WebSqlTx.escapeTableName(a.getNormalizedName());f.push(a);g.push(a)}),a=lf.backstore.WebSqlTx.escapeTableName(a.getRowIdIndexName()),f.push(a),h.push(a))});f.forEach(function(a){c.queue("CREATE TABLE "+lf.backstore.WebSql.escape_(a)+"(id INTEGER PRIMARY KEY, value TEXT)",[])});return c.commit()})};
lf.backstore.WebSql.prototype.scanRowId_=function(){var a=0,b=goog.Promise.withResolver(),c=function(b){var c=new lf.backstore.WebSqlTx(this.db_,lf.TransactionType.READ_ONLY);c.queue("SELECT MAX(id) FROM "+lf.backstore.WebSql.escape_(b),[]);return c.commit().then(function(b){b=b[0].rows.item(0)["MAX(id)"];a=Math.max(b,a)})}.bind(this),d=this.schema_.tables().map(function(a){return c(a.getName())});goog.Promise.all(d).then(function(){lf.Row.setNextId(a+1);b.resolve()},function(a){b.reject(a)});return b.promise};lf.proc.ImportTask=function(a,b){this.global_=a;this.schema_=a.getService(lf.service.SCHEMA);this.scope_=lf.structs.set.create(this.schema_.tables());this.resolver_=goog.Promise.withResolver();this.data_=b;this.backStore_=a.getService(lf.service.BACK_STORE);this.cache_=a.getService(lf.service.CACHE);this.indexStore_=a.getService(lf.service.INDEX_STORE)};
lf.proc.ImportTask.prototype.exec=function(){if(!(this.backStore_ instanceof lf.backstore.IndexedDB||this.backStore_ instanceof lf.backstore.Memory||this.backStore_ instanceof lf.backstore.WebSql))throw new lf.Exception(300);if(!this.isEmptyDB_())throw new lf.Exception(110);if(this.schema_.name()!=this.data_.name||this.schema_.version()!=this.data_.version)throw new lf.Exception(111);if(!goog.isDefAndNotNull(this.data_.tables))throw new lf.Exception(112);return this.import_()};
lf.proc.ImportTask.prototype.getType=function(){return lf.TransactionType.READ_WRITE};lf.proc.ImportTask.prototype.getScope=function(){return this.scope_};lf.proc.ImportTask.prototype.getResolver=function(){return this.resolver_};lf.proc.ImportTask.prototype.getId=function(){return goog.getUid(this)};lf.proc.ImportTask.prototype.getPriority=function(){return lf.proc.TaskPriority.IMPORT_TASK};
lf.proc.ImportTask.prototype.isEmptyDB_=function(){for(var a=this.schema_.tables(),b=0;b<a.length;++b)if(0<this.indexStore_.get(a[b].getRowIdIndexName()).stats().totalRows)return!1;return!0};
lf.proc.ImportTask.prototype.import_=function(){var a=new lf.cache.Journal(this.global_,this.scope_),a=this.backStore_.createTx(this.getType(),lf.structs.set.values(this.scope_),a),b;for(b in this.data_.tables){var c=this.schema_.table(b),d=this.data_.tables[b].map(function(a){return c.createRow(a)}),e=a.getTable(b,c.deserializeRow,lf.backstore.TableType.DATA);this.cache_.setMany(b,d);var f=this.indexStore_.getTableIndices(b);d.forEach(function(a){f.forEach(function(b){var c=a.keyOfIndex(b.getName());
b.add(c,a.id())})});e.put(d)}return a.commit()};lf.proc.QueryTask=function(a,b){this.global=a;this.backStore_=a.getService(lf.service.BACK_STORE);this.queries=b.map(function(a){return a.context});this.plans_=b.map(function(a){return a.plan});this.combinedScope_=lf.proc.PhysicalQueryPlan.getCombinedScope(this.plans_);this.txType_=this.detectType_();this.resolver_=goog.Promise.withResolver()};
lf.proc.QueryTask.prototype.detectType_=function(){return this.queries.some(function(a){return!(a instanceof lf.query.SelectContext)})?lf.TransactionType.READ_WRITE:lf.TransactionType.READ_ONLY};
lf.proc.QueryTask.prototype.exec=function(){var a=this.txType_==lf.TransactionType.READ_ONLY?void 0:new lf.cache.Journal(this.global,this.combinedScope_),b=[],c=this.plans_.slice(),d=this.queries,e=function(){var f=c.shift();if(f){var g=d[b.length];return f.getRoot().exec(a,g).then(function(a){b.push(a[0]);return e()})}return goog.Promise.resolve()};return e().then(function(){this.tx_=this.backStore_.createTx(this.txType_,lf.structs.set.values(this.combinedScope_),a);return this.tx_.commit()}.bind(this)).then(function(){this.onSuccess(b);
return b}.bind(this),function(b){goog.isDefAndNotNull(a)&&a.rollback();throw b;})};lf.proc.QueryTask.prototype.getType=function(){return this.txType_};lf.proc.QueryTask.prototype.getScope=function(){return this.combinedScope_};lf.proc.QueryTask.prototype.getResolver=function(){return this.resolver_};lf.proc.QueryTask.prototype.getId=function(){return goog.getUid(this)};lf.proc.QueryTask.prototype.onSuccess=function(a){};
lf.proc.QueryTask.prototype.stats=function(){var a=null;goog.isDefAndNotNull(this.tx_)&&(a=this.tx_.stats());return goog.isNull(a)?lf.TransactionStats.getDefault():a};lf.proc.ObserverQueryTask=function(a,b){lf.proc.QueryTask.call(this,a,b);this.observerRegistry_=a.getService(lf.service.OBSERVER_REGISTRY)};goog.inherits(lf.proc.ObserverQueryTask,lf.proc.QueryTask);lf.proc.ObserverQueryTask.prototype.getPriority=function(){return lf.proc.TaskPriority.OBSERVER_QUERY_TASK};lf.proc.ObserverQueryTask.prototype.onSuccess=function(a){this.queries.forEach(function(b,c){this.observerRegistry_.updateResultsForQuery(b,a[c])},this)};lf.proc.ExternalChangeTask=function(a,b){this.global_=a;this.observerRegistry_=a.getService(lf.service.OBSERVER_REGISTRY);this.runner_=a.getService(lf.service.RUNNER);this.inMemoryUpdater_=new lf.cache.InMemoryUpdater(a);this.tableDiffs_=b;var c=a.getService(lf.service.SCHEMA),d=this.tableDiffs_.map(function(a){return c.table(a.getName())});this.scope_=lf.structs.set.create(d);this.resolver_=goog.Promise.withResolver()};
lf.proc.ExternalChangeTask.prototype.exec=function(){this.inMemoryUpdater_.update(this.tableDiffs_);this.scheduleObserverTask_();return goog.Promise.resolve()};lf.proc.ExternalChangeTask.prototype.getType=function(){return lf.TransactionType.READ_WRITE};lf.proc.ExternalChangeTask.prototype.getScope=function(){return this.scope_};lf.proc.ExternalChangeTask.prototype.getResolver=function(){return this.resolver_};lf.proc.ExternalChangeTask.prototype.getId=function(){return goog.getUid(this)};
lf.proc.ExternalChangeTask.prototype.getPriority=function(){return lf.proc.TaskPriority.EXTERNAL_CHANGE_TASK};lf.proc.ExternalChangeTask.prototype.scheduleObserverTask_=function(){var a=this.observerRegistry_.getTaskItemsForTables(this.scope_);0!=a.length&&(a=new lf.proc.ObserverQueryTask(this.global_,a),this.runner_.scheduleTask(a))};lf.backstore.ExternalChangeObserver=function(a){this.global_=a;this.backStore_=a.getService(lf.service.BACK_STORE);this.runner_=a.getService(lf.service.RUNNER)};lf.backstore.ExternalChangeObserver.prototype.startObserving=function(){this.backStore_.subscribe(this.onChange_.bind(this))};lf.backstore.ExternalChangeObserver.prototype.stopObserving=function(){this.backStore_.unsubscribe()};
lf.backstore.ExternalChangeObserver.prototype.onChange_=function(a){a=new lf.proc.ExternalChangeTask(this.global_,a);this.runner_.scheduleTask(a)};lf.proc.TransactionTask=function(a,b){this.global_=a;this.backStore_=a.getService(lf.service.BACK_STORE);this.runner_=a.getService(lf.service.RUNNER);this.observerRegistry_=a.getService(lf.service.OBSERVER_REGISTRY);this.scope_=lf.structs.set.create(b);this.journal_=new lf.cache.Journal(this.global_,this.scope_);this.resolver_=goog.Promise.withResolver();this.execResolver_=goog.Promise.withResolver();this.acquireScopeResolver_=goog.Promise.withResolver()};
lf.proc.TransactionTask.prototype.exec=function(){this.acquireScopeResolver_.resolve();return this.execResolver_.promise};lf.proc.TransactionTask.prototype.getType=function(){return lf.TransactionType.READ_WRITE};lf.proc.TransactionTask.prototype.getScope=function(){return this.scope_};lf.proc.TransactionTask.prototype.getResolver=function(){return this.resolver_};lf.proc.TransactionTask.prototype.getId=function(){return goog.getUid(this)};lf.proc.TransactionTask.prototype.getPriority=function(){return lf.proc.TaskPriority.TRANSACTION_TASK};
lf.proc.TransactionTask.prototype.acquireScope=function(){this.runner_.scheduleTask(this);return this.acquireScopeResolver_.promise};lf.proc.TransactionTask.prototype.attachQuery=function(a){a=a.getTaskItem();return a.plan.getRoot().exec(this.journal_,a.context).then(function(a){return a[0].getPayloads()},function(a){this.journal_.rollback();var c=new goog.Promise.CancellationError(a.name);this.execResolver_.reject(c);throw a;}.bind(this))};
lf.proc.TransactionTask.prototype.commit=function(){this.tx_=this.backStore_.createTx(this.getType(),lf.structs.set.values(this.scope_),this.journal_);this.tx_.commit().then(function(){this.scheduleObserverTask_();this.execResolver_.resolve()}.bind(this),function(a){this.journal_.rollback();this.execResolver_.reject(a)}.bind(this));return this.resolver_.promise};lf.proc.TransactionTask.prototype.rollback=function(){this.journal_.rollback();this.execResolver_.resolve();return this.resolver_.promise};
lf.proc.TransactionTask.prototype.scheduleObserverTask_=function(){var a=this.observerRegistry_.getTaskItemsForTables(this.scope_);0!=a.length&&(a=new lf.proc.ObserverQueryTask(this.global_,a),this.runner_.scheduleTask(a))};lf.proc.TransactionTask.prototype.stats=function(){var a=null;goog.isDefAndNotNull(this.tx_)&&(a=this.tx_.stats());return goog.isNull(a)?lf.TransactionStats.getDefault():a};lf.proc.UserQueryTask=function(a,b){lf.proc.QueryTask.call(this,a,b);this.runner_=a.getService(lf.service.RUNNER);this.observerRegistry_=a.getService(lf.service.OBSERVER_REGISTRY)};goog.inherits(lf.proc.UserQueryTask,lf.proc.QueryTask);lf.proc.UserQueryTask.prototype.getPriority=function(){return lf.proc.TaskPriority.USER_QUERY_TASK};lf.proc.UserQueryTask.prototype.onSuccess=function(a){this.getType()==lf.TransactionType.READ_ONLY?this.notifyObserversDirectly_(a):this.scheduleObserverTask_()};
lf.proc.UserQueryTask.prototype.notifyObserversDirectly_=function(a){this.queries.forEach(function(b,c){b instanceof lf.query.SelectContext&&this.observerRegistry_.updateResultsForQuery(b,a[c])},this)};lf.proc.UserQueryTask.prototype.scheduleObserverTask_=function(){var a=this.observerRegistry_.getTaskItemsForTables(this.getScope());0!=a.length&&(a=new lf.proc.ObserverQueryTask(this.global,a),this.runner_.scheduleTask(a))};lf.proc.Transaction=function(a){this.global_=a;this.runner_=a.getService(lf.service.RUNNER);this.task_=null;this.state_=lf.proc.TransactionState_.CREATED;0==lf.proc.StateTransitions_.size&&this.initStateTransitions_()};lf.proc.TransactionState_={CREATED:0,ACQUIRING_SCOPE:1,ACQUIRED_SCOPE:2,EXECUTING_QUERY:3,EXECUTING_AND_COMMITTING:4,COMMITTING:5,ROLLING_BACK:6,FINALIZED:7};lf.proc.StateTransitions_=lf.structs.map.create();
lf.proc.Transaction.prototype.initStateTransitions_=function(){lf.proc.StateTransitions_.set(lf.proc.TransactionState_.CREATED,lf.structs.set.create([lf.proc.TransactionState_.ACQUIRING_SCOPE,lf.proc.TransactionState_.EXECUTING_AND_COMMITTING]));lf.proc.StateTransitions_.set(lf.proc.TransactionState_.ACQUIRING_SCOPE,lf.structs.set.create([lf.proc.TransactionState_.ACQUIRED_SCOPE]));lf.proc.StateTransitions_.set(lf.proc.TransactionState_.ACQUIRED_SCOPE,lf.structs.set.create([lf.proc.TransactionState_.EXECUTING_QUERY,
lf.proc.TransactionState_.COMMITTING,lf.proc.TransactionState_.ROLLING_BACK]));lf.proc.StateTransitions_.set(lf.proc.TransactionState_.EXECUTING_QUERY,lf.structs.set.create([lf.proc.TransactionState_.ACQUIRED_SCOPE,lf.proc.TransactionState_.FINALIZED]));lf.proc.StateTransitions_.set(lf.proc.TransactionState_.EXECUTING_AND_COMMITTING,lf.structs.set.create([lf.proc.TransactionState_.FINALIZED]));lf.proc.StateTransitions_.set(lf.proc.TransactionState_.COMMITTING,lf.structs.set.create([lf.proc.TransactionState_.FINALIZED]));
lf.proc.StateTransitions_.set(lf.proc.TransactionState_.ROLLING_BACK,lf.structs.set.create([lf.proc.TransactionState_.FINALIZED]))};lf.proc.Transaction.prototype.stateTransition_=function(a){var b=lf.proc.StateTransitions_.get(this.state_)||null;if(goog.isNull(b)||!b.has(a))throw new lf.Exception(107,this.state_,a);this.state_=a};
lf.proc.Transaction.prototype.exec=function(a){this.stateTransition_(lf.proc.TransactionState_.EXECUTING_AND_COMMITTING);var b=[];try{a.forEach(function(a){a.assertExecPreconditions();b.push(a.getTaskItem())},this)}catch(c){return this.stateTransition_(lf.proc.TransactionState_.FINALIZED),goog.Promise.reject(c)}this.task_=new lf.proc.UserQueryTask(this.global_,b);return this.runner_.scheduleTask(this.task_).then(function(a){this.stateTransition_(lf.proc.TransactionState_.FINALIZED);return a.map(function(a){return a.getPayloads()})}.bind(this),
function(a){this.stateTransition_(lf.proc.TransactionState_.FINALIZED);throw a;}.bind(this))};lf.proc.Transaction.prototype.begin=function(a){this.stateTransition_(lf.proc.TransactionState_.ACQUIRING_SCOPE);this.task_=new lf.proc.TransactionTask(this.global_,a);return this.task_.acquireScope().then(function(){this.stateTransition_(lf.proc.TransactionState_.ACQUIRED_SCOPE)}.bind(this))};
lf.proc.Transaction.prototype.attach=function(a){this.stateTransition_(lf.proc.TransactionState_.EXECUTING_QUERY);return this.task_.attachQuery(a).then(function(a){this.stateTransition_(lf.proc.TransactionState_.ACQUIRED_SCOPE);return a}.bind(this),function(a){this.stateTransition_(lf.proc.TransactionState_.FINALIZED);throw a;}.bind(this))};lf.proc.Transaction.prototype.commit=function(){this.stateTransition_(lf.proc.TransactionState_.COMMITTING);return this.task_.commit().then(function(){this.stateTransition_(lf.proc.TransactionState_.FINALIZED)}.bind(this))};
lf.proc.Transaction.prototype.rollback=function(){this.stateTransition_(lf.proc.TransactionState_.ROLLING_BACK);return this.task_.rollback().then(function(){this.stateTransition_(lf.proc.TransactionState_.FINALIZED)}.bind(this))};lf.proc.Transaction.prototype.stats=function(){if(this.state_!=lf.proc.TransactionState_.FINALIZED)throw new lf.Exception(105);return this.task_.stats()};lf.tree={};lf.tree.map=function(a,b){var c=[],d=null,e=null;a.traverse(function(a){var g=b(a);null==a.getParent()?e=g:d.addChild(g);var h=a.getParent(),k=d;goog.isNull(h)||h.getChildCount()!=k.getChildCount()||(h=c.indexOf(k),-1!=h&&c.splice(h,1));1<a.getChildCount()&&c.push(g);d=a.isLeaf()?c[c.length-1]:g});return e};lf.tree.getLeafNodes=function(a){return lf.tree.find(a,function(a){return a.isLeaf()})};
lf.tree.removeNode=function(a){var b=a.getParent(),c=0;goog.isNull(b)||(c=b.getChildren().indexOf(a),b.removeChild(a));var d=a.getChildren().slice();d.forEach(function(d,f){a.removeChild(d);goog.isNull(b)||b.addChildAt(d,c+f)});return{parent:b,children:d}};lf.tree.insertNodeAt=function(a,b){a.getChildren().slice().forEach(function(c){a.removeChild(c);b.addChild(c)});a.addChild(b)};
lf.tree.swapNodeWithChild=function(a){goog.asserts.assert(1==a.getChildCount());var b=a.getChildAt(0);goog.asserts.assert(1==b.getChildCount());lf.tree.removeNode(a);lf.tree.insertNodeAt(b,a);return b};
lf.tree.pushNodeBelowChild=function(a,b,c){goog.asserts.assert(1==a.getChildCount());var d=a.getChildAt(0);goog.asserts.assert(1<d.getChildCount());var e=d.getChildren().slice();if(!e.some(function(a){return b(a)}))return a;lf.tree.removeNode(a);e.forEach(function(e,g){if(b(e)){var h=c(a);d.removeChildAt(g);h.addChild(e);d.addChildAt(h,g)}});return d};
lf.tree.replaceChainWithChain=function(a,b,c,d){var e=a.getParent();goog.isNull(e)||(a=e.getChildren().indexOf(a),e.removeChildAt(a),e.addChildAt(c,a));b.getChildren().slice().forEach(function(a){b.removeChild(a);d.addChild(a)});return c};lf.tree.replaceNodeWithChain=function(a,b,c){return lf.tree.replaceChainWithChain(a,a,b,c)};lf.tree.replaceChainWithNode=function(a,b,c){return lf.tree.replaceChainWithChain(a,b,c,c)};
lf.tree.find=function(a,b,c){var d=[],e=function(a){b(a)&&d.push(a);goog.isDefAndNotNull(c)&&c(a)||a.getChildren().forEach(e)};e(a);return d};lf.tree.toString=function(a,b){var c=b||function(a){return a.toString()+"\n"},d="";a.traverse(function(a){for(var b=0;b<a.getDepth();b++)d+="-";d+=c(a)});return d};lf.pred.CombinedPredicate=function(a){lf.pred.PredicateNode.call(this);this.operator=a;this.isComplement_=!1};goog.inherits(lf.pred.CombinedPredicate,lf.pred.PredicateNode);lf.pred.CombinedPredicate.prototype.copy=function(){return lf.tree.map(this,function(a){if(a instanceof lf.pred.CombinedPredicate){var b=new lf.pred.CombinedPredicate(a.operator);b.isComplement_=a.isComplement_;b.setId(a.getId());return b}return a.copy()})};
lf.pred.CombinedPredicate.prototype.getColumns=function(a){var b=a||[];this.traverse(function(a){a!=this&&a.getColumns(b)}.bind(this));a=lf.structs.set.create(b);return lf.structs.set.values(a)};lf.pred.CombinedPredicate.prototype.getTables=function(a){var b=goog.isDefAndNotNull(a)?a:lf.structs.set.create();this.traverse(function(a){a!=this&&a.getTables(b)}.bind(this));return b};
lf.pred.CombinedPredicate.prototype.setComplement=function(a){this.isComplement_!=a&&(this.isComplement_=a,this.operator=this.operator==lf.pred.Operator.AND?lf.pred.Operator.OR:lf.pred.Operator.AND,this.getChildren().forEach(function(b){return b.setComplement(a)}))};lf.pred.CombinedPredicate.prototype.eval=function(a){var b=this.getChildren().map(function(b){return b.eval(a)});return this.combineResults_(b)};
lf.pred.CombinedPredicate.prototype.combineResults_=function(a){return this.operator==lf.pred.Operator.AND?lf.proc.Relation.intersect(a):lf.proc.Relation.union(a)};lf.pred.CombinedPredicate.prototype.toString=function(){return"combined_pred_"+this.operator.toString()};
lf.pred.CombinedPredicate.prototype.toKeyRange=function(){goog.asserts.assert(this.isKeyRangeCompatible(),"Could not convert combined predicate to key range.");if(this.operator==lf.pred.Operator.OR){var a=new lf.index.SingleKeyRangeSet;this.getChildren().forEach(function(b){b=b.toKeyRange().getValues();a.add(b)});return a}goog.asserts.fail("toKeyRange() called for an AND predicate.");return new lf.index.SingleKeyRangeSet};
lf.pred.CombinedPredicate.prototype.isKeyRangeCompatible=function(){return this.operator==lf.pred.Operator.OR?this.isKeyRangeCompatibleOr_():!1};lf.pred.CombinedPredicate.prototype.isKeyRangeCompatibleOr_=function(){var a=null;return this.getChildren().every(function(b){if(!(b instanceof lf.pred.ValuePredicate&&b.isKeyRangeCompatible()))return!1;goog.isNull(a)&&(a=b.column);return a.getNormalizedName()==b.column.getNormalizedName()})};lf.op={};lf.op.and=function(a){var b=Array.prototype.slice.call(arguments);return lf.op.createPredicate_(lf.pred.Operator.AND,b)};lf.op.or=function(a){var b=Array.prototype.slice.call(arguments);return lf.op.createPredicate_(lf.pred.Operator.OR,b)};lf.op.createPredicate_=function(a,b){var c=new lf.pred.CombinedPredicate(a);b.forEach(function(a){c.addChild(a)});return c};lf.op.not=function(a){a.setComplement(!0);return a};lf.proc.AndPredicatePass=function(){lf.proc.RewritePass.call(this)};goog.inherits(lf.proc.AndPredicatePass,lf.proc.RewritePass);lf.proc.AndPredicatePass.prototype.rewrite=function(a){this.rootNode=a;this.traverse_(this.rootNode);return this.rootNode};
lf.proc.AndPredicatePass.prototype.traverse_=function(a){if(a instanceof lf.proc.SelectNode){goog.asserts.assert(1==a.getChildCount(),"SelectNode must have exactly one child.");var b=this.breakAndPredicate_(a.predicate),b=this.createSelectNodeChain_(b);lf.tree.replaceNodeWithChain(a,b[0],b[1]);a==this.rootNode&&(this.rootNode=b[0]);a=b[0]}a.getChildren().forEach(function(a){this.traverse_(a)},this)};
lf.proc.AndPredicatePass.prototype.breakAndPredicate_=function(a){if(0==a.getChildCount()||a.operator!=lf.pred.Operator.AND)return[a];var b=a.getChildren().slice().map(function(b){a.removeChild(b);return this.breakAndPredicate_(b)},this);return goog.array.flatten(b)};lf.proc.AndPredicatePass.prototype.createSelectNodeChain_=function(a){var b=null,c=null;a.map(function(a,e){var f=new lf.proc.SelectNode(a);0==e?b=f:c.addChild(f);c=f},this);return[b,c]};lf.proc.GetRowCountPass=function(a){lf.proc.RewritePass.call(this);this.global_=a};goog.inherits(lf.proc.GetRowCountPass,lf.proc.RewritePass);lf.proc.GetRowCountPass.prototype.rewrite=function(a,b){this.rootNode=a;if(!this.canOptimize_(b))return a;var c=lf.tree.find(a,function(a){return a instanceof lf.proc.TableAccessFullStep})[0],d=new lf.proc.GetRowCountStep(this.global_,c.table);lf.tree.replaceNodeWithChain(c,d,d);return this.rootNode};
lf.proc.GetRowCountPass.prototype.canOptimize_=function(a){return 1!=a.columns.length||1!=a.from.length||goog.isDefAndNotNull(a.where)||goog.isDefAndNotNull(a.limit)||goog.isDefAndNotNull(a.skip)||goog.isDefAndNotNull(a.groupBy)?!1:(a=a.columns[0],a instanceof lf.fn.AggregatedColumn&&a.aggregatorType==lf.fn.Type.COUNT&&a.child instanceof lf.fn.StarColumn)};lf.proc.ImplicitJoinsPass=function(){lf.proc.RewritePass.call(this)};goog.inherits(lf.proc.ImplicitJoinsPass,lf.proc.RewritePass);lf.proc.ImplicitJoinsPass.prototype.rewrite=function(a,b){if(2>b.from.length)return a;this.rootNode=a;this.traverse_(this.rootNode,b);return this.rootNode};
lf.proc.ImplicitJoinsPass.prototype.traverse_=function(a,b){if(a instanceof lf.proc.SelectNode&&a.predicate instanceof lf.pred.JoinPredicate){goog.asserts.assert(1==a.getChildCount(),"SelectNode must have exactly one child.");var c=a.predicate.getId(),d=a.getChildAt(0);d instanceof lf.proc.CrossProductNode&&(c=goog.isDefAndNotNull(b.outerJoinPredicates)&&b.outerJoinPredicates.has(c),c=new lf.proc.JoinNode(a.predicate,c),lf.tree.replaceChainWithNode(a,d,c),a==this.rootNode&&(this.rootNode=c),a=c)}a.getChildren().forEach(function(a){this.traverse_(a,
b)},this)};lf.proc.IndexCostEstimator=function(a,b){this.tableSchema_=b;this.indexStore_=a.getService(lf.service.INDEX_STORE)};$jscomp.scope.INDEX_QUERY_THRESHOLD_PERCENT=.02;lf.proc.IndexCostEstimator.prototype.getIndexQueryThreshold_=function(){var a=this.indexStore_.get(this.tableSchema_.getRowIdIndexName());return Math.floor(a.stats().totalRows*$jscomp.scope.INDEX_QUERY_THRESHOLD_PERCENT)};
lf.proc.IndexCostEstimator.prototype.chooseIndexFor=function(a,b){var c=b.filter(this.isCandidate_,this);if(0==c.length)return null;c=this.generateIndexRangeCandidates_(c);if(0==c.length)return null;if(1==c.length)return c[0];var d=Number.MAX_VALUE;return c.reduce(function(b,c){var g=c.calculateCost(a);return g<d?(d=g,c):b},null)};
lf.proc.IndexCostEstimator.prototype.generateIndexRangeCandidates_=function(a){return this.tableSchema_.getIndices().map(function(b){b=new lf.proc.IndexRangeCandidate(this.indexStore_,b);b.consumePredicates_(a);return b},this).filter(function(a){return a.isUsable()})};lf.proc.IndexCostEstimator.prototype.isCandidate_=function(a){return a instanceof lf.pred.ValuePredicate?this.isCandidateValuePredicate_(a):a instanceof lf.pred.CombinedPredicate?this.isCandidateCombinedPredicate_(a):!1};
lf.proc.IndexCostEstimator.prototype.isCandidateCombinedPredicate_=function(a){return a.isKeyRangeCompatible()&&a.getChildAt(0).column.getTable()==this.tableSchema_?a.getChildCount()<=this.getIndexQueryThreshold_():!1};lf.proc.IndexCostEstimator.prototype.isCandidateValuePredicate_=function(a){return!a.isKeyRangeCompatible()||a.column.getTable()!=this.tableSchema_||a.evaluatorType==lf.eval.Type.IN&&a.value.length>this.getIndexQueryThreshold_()?!1:!0};
lf.proc.IndexRangeCandidate=function(a,b){this.indexStore_=a;this.indexSchema=b;this.indexedColumnNames_=lf.structs.set.create(this.indexSchema.columns.map(function(a){return a.schema.getName()}));this.keyRangeCalculator_=this.predicateMap_=null};lf.proc.IndexRangeCandidate.prototype.getPredicateIds=function(){return goog.isNull(this.predicateMap_)?[]:this.predicateMap_.values()};
lf.proc.IndexRangeCandidate.prototype.getKeyRangeCalculator=function(){goog.asserts.assert(this.predicateMap_);goog.isNull(this.keyRangeCalculator_)&&(this.keyRangeCalculator_=new lf.proc.BoundKeyRangeCalculator(this.indexSchema,this.predicateMap_));return this.keyRangeCalculator_};
lf.proc.IndexRangeCandidate.prototype.consumePredicates_=function(a){a.forEach(function(a){var c=a.getColumns()[0].getName();this.indexedColumnNames_.has(c)&&(goog.isNull(this.predicateMap_)&&(this.predicateMap_=new lf.structs.MapSet),this.predicateMap_.set(c,a.getId()))},this)};
lf.proc.IndexRangeCandidate.prototype.isUsable=function(){if(goog.isNull(this.predicateMap_))return!1;for(var a=!1,b=!0,c=0;c<this.indexSchema.columns.length;c++){var d=this.predicateMap_.has(this.indexSchema.columns[c].schema.getName());if(a&&d){b=!1;break}d||(a=!0)}return b};
lf.proc.IndexRangeCandidate.prototype.calculateCost=function(a){a=this.getKeyRangeCalculator().getKeyRangeCombinations(a);var b=this.indexStore_.get(this.indexSchema.getNormalizedName());return a.reduce(function(a,d){return a+b.cost(d)},0)};lf.proc.IndexJoinPass=function(){lf.proc.RewritePass.call(this)};goog.inherits(lf.proc.IndexJoinPass,lf.proc.RewritePass);lf.proc.IndexJoinPass.prototype.rewrite=function(a,b){this.rootNode=a;if(!this.canOptimize_(b))return a;lf.tree.find(a,function(a){return a instanceof lf.proc.JoinStep}).forEach(this.processJoinStep_,this);return this.rootNode};lf.proc.IndexJoinPass.prototype.canOptimize_=function(a){return 1<a.from.length};
lf.proc.IndexJoinPass.prototype.processJoinStep_=function(a){if(a.predicate.evaluatorType==lf.eval.Type.EQ&&!a.isOuterJoin){var b=function(b){if(!(b instanceof lf.proc.TableAccessFullStep))return null;b=b.table.getEffectiveName()==a.predicate.rightColumn.getTable().getEffectiveName()?a.predicate.rightColumn:a.predicate.leftColumn;return goog.isNull(b.getIndex())?null:b},c=b(a.getChildAt(0)),b=b(a.getChildAt(1));if(!goog.isNull(c)||!goog.isNull(b)){b=goog.isNull(b)?c:b;a.markAsIndexJoin(b);var d=new lf.proc.Relation([],
[b.getTable().getEffectiveName()]);a.replaceChildAt(new lf.proc.NoOpStep([d]),b==c?0:1)}}};lf.proc.IndexRangeScanPass=function(a){lf.proc.RewritePass.call(this);this.global_=a};goog.inherits(lf.proc.IndexRangeScanPass,lf.proc.RewritePass);
lf.proc.IndexRangeScanPass.prototype.rewrite=function(a,b){this.rootNode=a;lf.tree.find(a,function(a){return a instanceof lf.proc.TableAccessFullStep}).forEach(function(a){var d=this.findSelectSteps_(a);if(0!=d.length){var e=(new lf.proc.IndexCostEstimator(this.global_,a.table)).chooseIndexFor(b,d.map(function(a){return b.getPredicate(a.predicateId)}));if(!goog.isNull(e)){var f=lf.structs.map.create();d.forEach(function(a){f.set(a.predicateId,a)},this);this.rootNode=this.replaceWithIndexRangeScanStep_(e,
f,a,b)}}},this);return this.rootNode};lf.proc.IndexRangeScanPass.prototype.findSelectSteps_=function(a){var b=[];for(a=a.getParent();a;){if(a instanceof lf.proc.SelectStep)b.push(a);else if(a instanceof lf.proc.JoinStep)break;a=a.getParent()}return b};
lf.proc.IndexRangeScanPass.prototype.replaceWithIndexRangeScanStep_=function(a,b,c,d){a.getPredicateIds().map(function(a){return b.get(a)}).forEach(lf.tree.removeNode);a=new lf.proc.IndexRangeScanStep(this.global_,a.indexSchema,a.getKeyRangeCalculator(),!1);d=new lf.proc.TableAccessByRowIdStep(this.global_,c.table);d.addChild(a);lf.tree.replaceNodeWithChain(c,d,a);return a.getRoot()};lf.proc.LimitSkipByIndexPass=function(){lf.proc.RewritePass.call(this)};goog.inherits(lf.proc.LimitSkipByIndexPass,lf.proc.RewritePass);lf.proc.LimitSkipByIndexPass.prototype.rewrite=function(a,b){if(!goog.isDef(b.limit)&&!goog.isDef(b.skip))return a;var c=this.findIndexRangeScanStep_(a);if(goog.isNull(c))return a;lf.tree.find(a,function(a){return a instanceof lf.proc.LimitStep||a instanceof lf.proc.SkipStep}).forEach(function(a){this.mergeToIndexRangeScanStep_(a,c)},this);return c.getRoot()};
lf.proc.LimitSkipByIndexPass.prototype.mergeToIndexRangeScanStep_=function(a,b){a instanceof lf.proc.LimitStep?b.useLimit=!0:b.useSkip=!0;return lf.tree.removeNode(a).parent};
lf.proc.LimitSkipByIndexPass.prototype.findIndexRangeScanStep_=function(a){a=lf.tree.find(a,function(a){return a instanceof lf.proc.IndexRangeScanStep},function(a){return a instanceof lf.proc.ProjectStep&&a.hasAggregators()||a instanceof lf.proc.OrderByStep||1!=a.getChildCount()||a instanceof lf.proc.SelectStep});return 0<a.length?a[0]:null};lf.proc.MultiColumnOrPass=function(a){lf.proc.RewritePass.call(this);this.global_=a};goog.inherits(lf.proc.MultiColumnOrPass,lf.proc.RewritePass);
lf.proc.MultiColumnOrPass.prototype.rewrite=function(a,b){this.rootNode=a;var c=this.findOrPredicates_(b);if(0==c.length)return this.rootNode;var d=null,e=null,f=0;do e=c[f++],d=this.findIndexRangeCandidates_(e,b);while(goog.isNull(d)&&f<c.length);if(goog.isNull(d))return this.rootNode;c=this.findTableAccessFullStep_(d[0].indexSchema.tableName);return goog.isNull(c)?this.rootNode:this.rootNode=this.replaceWithIndexRangeScan_(e,c,d)};
lf.proc.MultiColumnOrPass.prototype.findOrPredicates_=function(a){return lf.tree.find(this.rootNode,function(b){if(!(b instanceof lf.proc.SelectStep))return!1;b=a.getPredicate(b.predicateId);return b instanceof lf.pred.CombinedPredicate&&b.operator==lf.pred.Operator.OR})};lf.proc.MultiColumnOrPass.prototype.findTableAccessFullStep_=function(a){return lf.tree.find(this.rootNode,function(b){return b instanceof lf.proc.TableAccessFullStep&&b.table.getName()==a})[0]||null};
lf.proc.MultiColumnOrPass.prototype.findIndexRangeCandidates_=function(a,b){var c=b.getPredicate(a.predicateId),d=c.getTables();if(1!=d.size)return null;var d=lf.structs.set.values(d)[0],e=new lf.proc.IndexCostEstimator(this.global_,d),f=null;return c.getChildren().every(function(a){a=e.chooseIndexFor(b,[a]);goog.isNull(a)||(goog.isNull(f)?f=[a]:f.push(a));return!goog.isNull(a)})?f:null};
lf.proc.MultiColumnOrPass.prototype.replaceWithIndexRangeScan_=function(a,b,c){var d=new lf.proc.TableAccessByRowIdStep(this.global_,b.table),e=new lf.proc.MultiIndexRangeScanStep;d.addChild(e);c.forEach(function(a){a=new lf.proc.IndexRangeScanStep(this.global_,a.indexSchema,a.getKeyRangeCalculator(),!1);e.addChild(a)},this);lf.tree.removeNode(a);lf.tree.replaceNodeWithChain(b,d,e);return e.getRoot()};lf.proc.OrderByIndexPass=function(a){lf.proc.RewritePass.call(this);this.global_=a};goog.inherits(lf.proc.OrderByIndexPass,lf.proc.RewritePass);lf.proc.OrderByIndexPass.prototype.rewrite=function(a,b){var c=lf.proc.OrderByIndexPass.findOrderByStep_(a,b);if(goog.isNull(c))return a;var d=this.applyTableAccessFullOptimization_(c);d==c&&(d=this.applyIndexRangeScanStepOptimization_(c));return d.getRoot()};
lf.proc.OrderByIndexPass.prototype.applyTableAccessFullOptimization_=function(a){var b=a,c=lf.proc.OrderByIndexPass.findTableAccessFullStep_(a.getChildAt(0));if(!goog.isNull(c)){var d=lf.proc.OrderByIndexPass.findIndexCandidateForOrderBy_(c.table,a.orderBy);if(goog.isNull(d))return b;b=new lf.proc.IndexRangeScanStep(this.global_,d.indexSchema,new lf.proc.NotBoundKeyRangeCalculator(d.indexSchema),d.isReverse);d=new lf.proc.TableAccessByRowIdStep(this.global_,c.table);d.addChild(b);lf.tree.removeNode(a);
b=lf.tree.replaceNodeWithChain(c,d,b)}return b};lf.proc.OrderByIndexPass.prototype.applyIndexRangeScanStepOptimization_=function(a){var b=a,c=lf.proc.OrderByIndexPass.findIndexRangeScanStep_(a.getChildAt(0));if(!goog.isNull(c)){var d=lf.proc.OrderByIndexPass.getIndexCandidateForIndexSchema_(c.index,a.orderBy);if(goog.isNull(d))return b;c.reverseOrder=d.isReverse;b=lf.tree.removeNode(a).parent}return b};
lf.proc.OrderByIndexPass.findIndexRangeScanStep_=function(a){a=lf.tree.find(a,function(a){return a instanceof lf.proc.IndexRangeScanStep},function(a){return 1!=a.getChildCount()});return 0<a.length?a[0]:null};lf.proc.OrderByIndexPass.findTableAccessFullStep_=function(a){a=lf.tree.find(a,function(a){return a instanceof lf.proc.TableAccessFullStep},function(a){return 1!=a.getChildCount()});return 0<a.length?a[0]:null};
lf.proc.OrderByIndexPass.findOrderByStep_=function(a,b){return goog.isDef(b.orderBy)?lf.tree.find(a,function(a){return a instanceof lf.proc.OrderByStep})[0]:null};lf.proc.OrderByIndexPass.findIndexCandidateForOrderBy_=function(a,b){for(var c=null,d=a.getIndices(),e=0;e<d.length&&goog.isNull(c);e++)c=lf.proc.OrderByIndexPass.getIndexCandidateForIndexSchema_(d[e],b);return c};
lf.proc.OrderByIndexPass.getIndexCandidateForIndexSchema_=function(a,b){if(a.columns.length!=b.length||!b.every(function(b,c){var f=a.columns[c];return b.column.getName()==f.schema.getName()}))return null;var c=lf.proc.OrderByIndexPass.checkOrder_(b,a);return c[0]||c[1]?{indexSchema:a,isReverse:c[1]}:null};
lf.proc.OrderByIndexPass.checkOrder_=function(a,b){var c=a.reduce(function(a,b){return a<<1|(b.order==lf.Order.DESC?0:1)},0),d=b.columns.reduce(function(a,b){return a<<1|(b.order==lf.Order.DESC?0:1)},0),c=c^d;return[0==c,c==Math.pow(2,Math.max(a.length,b.columns.length))-1]};lf.proc.PhysicalPlanFactory=function(a){this.global_=a;this.selectOptimizationPasses_=[new lf.proc.IndexJoinPass,new lf.proc.IndexRangeScanPass(this.global_),new lf.proc.MultiColumnOrPass(this.global_),new lf.proc.OrderByIndexPass(this.global_),new lf.proc.LimitSkipByIndexPass,new lf.proc.GetRowCountPass(this.global_)];this.deleteOptimizationPasses_=[new lf.proc.IndexRangeScanPass(this.global_)]};
lf.proc.PhysicalPlanFactory.prototype.create=function(a,b){var c=a.getRoot();if(c instanceof lf.proc.InsertOrReplaceNode||c instanceof lf.proc.InsertNode)return this.createPlan_(a,b);if(c instanceof lf.proc.ProjectNode||c instanceof lf.proc.LimitNode||c instanceof lf.proc.SkipNode)return this.createPlan_(a,b,this.selectOptimizationPasses_);if(c instanceof lf.proc.DeleteNode||c instanceof lf.proc.UpdateNode)return this.createPlan_(a,b,this.deleteOptimizationPasses_);throw new lf.Exception(8);};
lf.proc.PhysicalPlanFactory.prototype.createPlan_=function(a,b,c){var d=lf.tree.map(a.getRoot(),this.mapFn_.bind(this));goog.isDefAndNotNull(c)&&(d=(new lf.proc.PhysicalPlanRewriter(d,b,c)).generate());return new lf.proc.PhysicalQueryPlan(d,a.getScope())};
lf.proc.PhysicalPlanFactory.prototype.mapFn_=function(a){if(a instanceof lf.proc.ProjectNode)return new lf.proc.ProjectStep(a.columns,a.groupByColumns);if(a instanceof lf.proc.GroupByNode)return new lf.proc.GroupByStep(a.columns);if(a instanceof lf.proc.AggregationNode)return new lf.proc.AggregationStep(a.columns);if(a instanceof lf.proc.OrderByNode)return new lf.proc.OrderByStep(a.orderBy);if(a instanceof lf.proc.SkipNode)return new lf.proc.SkipStep;if(a instanceof lf.proc.LimitNode)return new lf.proc.LimitStep;
if(a instanceof lf.proc.SelectNode)return new lf.proc.SelectStep(a.predicate.getId());if(a instanceof lf.proc.CrossProductNode)return new lf.proc.CrossProductStep;if(a instanceof lf.proc.JoinNode)return new lf.proc.JoinStep(this.global_,a.predicate,a.isOuterJoin);if(a instanceof lf.proc.TableAccessNode)return new lf.proc.TableAccessFullStep(this.global_,a.table);if(a instanceof lf.proc.DeleteNode)return new lf.proc.DeleteStep(a.table);if(a instanceof lf.proc.UpdateNode)return new lf.proc.UpdateStep(a.table,
a.updates);if(a instanceof lf.proc.InsertOrReplaceNode)return new lf.proc.InsertOrReplaceStep(this.global_,a.table);if(a instanceof lf.proc.InsertNode)return new lf.proc.InsertStep(this.global_,a.table);throw new lf.Exception(514);};lf.proc.PushDownSelectionsPass=function(){lf.proc.RewritePass.call(this);this.alreadyPushedDown_=lf.structs.set.create()};goog.inherits(lf.proc.PushDownSelectionsPass,lf.proc.RewritePass);lf.proc.PushDownSelectionsPass.prototype.clear_=function(){this.alreadyPushedDown_.clear()};lf.proc.PushDownSelectionsPass.prototype.rewrite=function(a,b){if(!goog.isDef(b.where))return a;this.clear_();this.rootNode=a;this.traverse_(this.rootNode,b);this.clear_();return this.rootNode};
lf.proc.PushDownSelectionsPass.prototype.traverse_=function(a,b){var c=function(a){a.getChildren().forEach(d)}.bind(this),d=function(a){if(!this.alreadyPushedDown_.has(a)){if(this.isCandidateNode_(a)){var f=a.predicate.getTables(),g=function(a){return this.doesReferToTables_(a,f)}.bind(this),g=this.pushDownNodeRec_(b,a,g);this.alreadyPushedDown_.add(a);g!=a&&(goog.isNull(g.getParent())&&(this.rootNode=g),d(g))}c(a)}}.bind(this);d(a)};
lf.proc.PushDownSelectionsPass.prototype.pushDownNodeRec_=function(a,b,c){var d=b;if(this.shouldSwapWithChild_(a,b))d=lf.tree.swapNodeWithChild(b),this.pushDownNodeRec_(a,b,c);else if(this.shouldPushBelowChild_(b)){var e=[],d=lf.tree.pushNodeBelowChild(b,c,function(a){a=new lf.proc.SelectNode(a.predicate);e.push(a);return a});e.forEach(function(b){this.pushDownNodeRec_(a,b,c)},this)}return d};
lf.proc.PushDownSelectionsPass.prototype.doesReferToTables_=function(a,b){var c=lf.structs.set.create();lf.tree.getLeafNodes(a).forEach(function(a){c.add(a.table)},this);a instanceof lf.proc.TableAccessNode&&c.add(a.table);return lf.structs.set.isSubset(c,b)};lf.proc.PushDownSelectionsPass.prototype.isCandidateNode_=function(a){return a instanceof lf.proc.SelectNode};
lf.proc.PushDownSelectionsPass.prototype.shouldPushBelowChild_=function(a){a=a.getChildAt(0);return a instanceof lf.proc.CrossProductNode||a instanceof lf.proc.JoinNode};lf.proc.PushDownSelectionsPass.prototype.shouldSwapWithChild_=function(a,b){var c=b.getChildAt(0);if(!(c instanceof lf.proc.SelectNode))return!1;if(!goog.isDefAndNotNull(a.outerJoinPredicates))return!0;var d=b.predicate instanceof lf.pred.JoinPredicate,c=a.outerJoinPredicates.has(c.predicate.getId());return d||!c};lf.proc.LogicalPlanFactory=function(){this.selectOptimizationPasses_=[new lf.proc.AndPredicatePass,new lf.proc.CrossProductPass,new lf.proc.PushDownSelectionsPass,new lf.proc.ImplicitJoinsPass];this.deleteOptimizationPasses_=[new lf.proc.AndPredicatePass]};
lf.proc.LogicalPlanFactory.prototype.create=function(a){var b=null;if(a instanceof lf.query.InsertContext)b=new lf.proc.InsertLogicalPlanGenerator(a);else if(a instanceof lf.query.DeleteContext)b=new lf.proc.DeleteLogicalPlanGenerator(a,this.deleteOptimizationPasses_);else if(a instanceof lf.query.SelectContext)b=new lf.proc.SelectLogicalPlanGenerator(a,this.selectOptimizationPasses_);else if(a instanceof lf.query.UpdateContext)b=new lf.proc.UpdateLogicalPlanGenerator(a);else throw new lf.Exception(513);
b=b.generate();return new lf.proc.LogicalQueryPlan(b,a.getScope())};lf.proc.DefaultQueryEngine=function(a){this.logicalPlanFactory_=new lf.proc.LogicalPlanFactory;this.physicalPlanFactory_=new lf.proc.PhysicalPlanFactory(a)};lf.proc.DefaultQueryEngine.prototype.getPlan=function(a){var b=this.logicalPlanFactory_.create(a);return this.physicalPlanFactory_.create(b,a)};lf.base={};
lf.base.init=function(a,b){var c=a.getService(lf.service.SCHEMA),d=b||{},e=new lf.cache.DefaultCache(c);a.registerService(lf.service.CACHE,e);var e=null,f=!1;if(lf.Flags.MEMORY_ONLY)e=new lf.backstore.Memory(c);else switch(goog.isDefAndNotNull(d.storeType)?e=d.storeType:(e=lf.Capability.get(),e=e.indexedDb?lf.schema.DataStoreType.INDEXED_DB:e.webSql?lf.schema.DataStoreType.WEB_SQL:lf.schema.DataStoreType.MEMORY),e){case lf.schema.DataStoreType.INDEXED_DB:e=new lf.backstore.IndexedDB(a,c);break;case lf.schema.DataStoreType.MEMORY:e=
new lf.backstore.Memory(c);break;case lf.schema.DataStoreType.OBSERVABLE_STORE:e=new lf.backstore.ObservableStore(c);break;case lf.schema.DataStoreType.WEB_SQL:e=new lf.backstore.WebSql(a,c,d.webSqlDbSize);break;case lf.schema.DataStoreType.FIREBASE:e=new lf.backstore.Firebase(c,d.firebase);f=!0;break;default:throw new lf.Exception(300);}a.registerService(lf.service.BACK_STORE,e);var g=new lf.index.MemoryIndexStore;a.registerService(lf.service.INDEX_STORE,g);return e.init(d.onUpgrade).then(function(){var b=
new lf.proc.DefaultQueryEngine(a);a.registerService(lf.service.QUERY_ENGINE,b);b=new lf.proc.Runner;a.registerService(lf.service.RUNNER,b);b=new lf.ObserverRegistry;a.registerService(lf.service.OBSERVER_REGISTRY,b);return g.init(c)}).then(function(){f&&(new lf.backstore.ExternalChangeObserver(a)).startObserving();d.enableInspector&&lf.base.enableInspector_(a);return(new lf.cache.Prefetcher(a)).init(c)})};lf.base.enableInspector_=function(a){window.top["#lfInspect"]=lf.debug.inspect};
lf.base.closeDatabase=function(a){try{a.getService(lf.service.BACK_STORE).close()}catch(b){}};lf.query.escapeSqlValue_=function(a,b){if(!goog.isDefAndNotNull(b))return"NULL";switch(a){case lf.Type.BOOLEAN:return b?1:0;case lf.Type.INTEGER:case lf.Type.NUMBER:return b;case lf.Type.ARRAY_BUFFER:return"'"+lf.Row.binToHex(b)+"'";default:return"'"+b.toString()+"'"}};
lf.query.insertToSql_=function(a,b){var c=a.allowReplace?"INSERT OR REPLACE":"INSERT",d=a.into.getColumns(),c=c+(" INTO "+a.into.getName()+"("),c=c+d.map(function(a){return a.getName()}).join(", "),c=c+") VALUES (";return a.values.map(function(a){var f=d.map(function(c){var d=a.payload()[c.getName()];return b?goog.isDefAndNotNull(d)?"#":"NULL":lf.query.escapeSqlValue_(c.getType(),d)});return c+f.join(", ")+");"}).join("\n")};
lf.query.evaluatorToSql_=function(a){switch(a){case lf.eval.Type.BETWEEN:return"BETWEEN";case lf.eval.Type.EQ:return"=";case lf.eval.Type.GTE:return">=";case lf.eval.Type.GT:return">";case lf.eval.Type.IN:return"IN";case lf.eval.Type.LTE:return"<=";case lf.eval.Type.LT:return"<";case lf.eval.Type.MATCH:return"LIKE";case lf.eval.Type.NEQ:return"<>";default:return"UNKNOWN"}};
lf.query.valueToSql_=function(a,b,c,d){return a instanceof lf.Binder?"?"+a.getIndex().toString():d?goog.isDefAndNotNull(a)?"#":"NULL":b==lf.eval.Type.MATCH?"'"+a.toString()+"'":b==lf.eval.Type.IN?"("+a.map(function(a){return lf.query.escapeSqlValue_(c,a)}).join(", ")+")":b==lf.eval.Type.BETWEEN?lf.query.escapeSqlValue_(c,a[0])+" AND "+lf.query.escapeSqlValue_(c,a[1]):lf.query.escapeSqlValue_(c,a).toString()};
lf.query.valuePredicateToSql_=function(a,b){var c=a.column.getNormalizedName(),d=lf.query.evaluatorToSql_(a.evaluatorType),e=lf.query.valueToSql_(a.value,a.evaluatorType,a.column.getType(),b);return"="==d&&"NULL"==e?[c,"IS NULL"].join(" "):"<>"==d&&"NULL"==e?[c,"IS NOT NULL"].join(" "):[c,d,e].join(" ")};lf.query.combinedPredicateToSql_=function(a,b){return a.getChildren().map(function(a){return"("+lf.query.parseSearchCondition_(a,b)+")"}).join(a.operator==lf.pred.Operator.AND?" AND ":" OR ")};
lf.query.joinPredicateToSql_=function(a){return[a.leftColumn.getNormalizedName(),lf.query.evaluatorToSql_(a.evaluatorType),a.rightColumn.getNormalizedName()].join(" ")};lf.query.parseSearchCondition_=function(a,b){if(a instanceof lf.pred.ValuePredicate)return lf.query.valuePredicateToSql_(a,b);if(a instanceof lf.pred.CombinedPredicate)return lf.query.combinedPredicateToSql_(a,b);if(a instanceof lf.pred.JoinPredicate)return lf.query.joinPredicateToSql_(a);throw new lf.Exception(357,typeof a);};
lf.query.predicateToSql_=function(a,b){var c=lf.query.parseSearchCondition_(a,b);return c?" WHERE "+c:""};lf.query.deleteToSql_=function(a,b){var c="DELETE FROM "+a.from.getName();a.where&&(c+=lf.query.predicateToSql_(a.where,b));return c+";"};
lf.query.updateToSql_=function(a,b){var c="UPDATE "+a.table.getName()+" SET ",c=c+a.set.map(function(a){var b=a.column.getNormalizedName()+" = ";return-1!=a.binding?b+"?"+a.binding.toString():b+lf.query.escapeSqlValue_(a.column.getType(),a.value).toString()}).join(", ");a.where&&(c+=lf.query.predicateToSql_(a.where,b));return c+";"};
lf.query.selectToSql_=function(a,b){var c="*";a.columns.length&&(c=a.columns.map(function(a){return a.getAlias()?a.getNormalizedName()+" AS "+a.getAlias():a.getNormalizedName()}).join(", "));c="SELECT "+c+" FROM ";goog.isDefAndNotNull(a.outerJoinPredicates)&&0!=a.outerJoinPredicates.size?c+=lf.query.getFromListForOuterJoin_(a,b):(c+=lf.query.getFromListForInnerJoin_(a,b),a.where&&(c+=lf.query.predicateToSql_(a.where,b)));if(a.orderBy)var d=a.orderBy.map(function(a){return a.column.getNormalizedName()+
(a.order==lf.Order.DESC?" DESC":" ASC")}).join(", "),c=c+(" ORDER BY "+d);a.groupBy&&(d=a.groupBy.map(function(a){return a.getNormalizedName()}).join(", "),c+=" GROUP BY "+d);a.limit&&(c+=" LIMIT "+a.limit.toString());a.skip&&(c+=" SKIP "+a.skip.toString());return c+";"};lf.query.getTableNameToSql_=function(a){return a.getEffectiveName()!=a.getName()?a.getName()+" AS "+a.getEffectiveName():a.getName()};
lf.query.getFromListForOuterJoin_=function(a,b){for(var c=lf.tree.find(a.where,function(a){return a instanceof lf.pred.JoinPredicate}),d=c.map(lf.query.joinPredicateToSql_),e=lf.query.getTableNameToSql_(a.from[0]),f=1;f<a.from.length;f++)var g=lf.query.getTableNameToSql_(a.from[f]),e=a.outerJoinPredicates.has(c[d.length-f].getId())?e+(" LEFT OUTER JOIN "+g):e+(" INNER JOIN "+g),e=e+(" ON ("+d[d.length-f]+")");c=a.where.getChildAt(0);c instanceof lf.pred.JoinPredicate||(e+=" WHERE "+lf.query.parseSearchCondition_(c,
b));return e};lf.query.getFromListForInnerJoin_=function(a,b){return a.from.map(lf.query.getTableNameToSql_).join(", ")};
lf.query.toSql=function(a,b){var c=b||!1,d=a.getQuery();if(d instanceof lf.query.InsertContext)return lf.query.insertToSql_(d,c);if(d instanceof lf.query.DeleteContext)return lf.query.deleteToSql_(d,c);if(d instanceof lf.query.UpdateContext)return lf.query.updateToSql_(d,c);if(d instanceof lf.query.SelectContext)return lf.query.selectToSql_(d,c);throw new lf.Exception(358,typeof d);};lf.query.BaseBuilder=function(a,b){this.global=a;this.queryEngine_=a.getService(lf.service.QUERY_ENGINE);this.runner_=a.getService(lf.service.RUNNER);this.query=b};lf.query.BaseBuilder.prototype.exec=function(){try{this.assertExecPreconditions()}catch(a){return goog.Promise.reject(a)}return new goog.Promise(function(a,b){var c=new lf.proc.UserQueryTask(this.global,[this.getTaskItem()]);this.runner_.scheduleTask(c).then(function(b){a(b[0].getPayloads())},b)},this)};
lf.query.BaseBuilder.prototype.explain=function(){var a=function(a){return a.toContextString(this.query)+"\n"}.bind(this);return lf.tree.toString(this.getPlan_().getRoot(),a)};lf.query.BaseBuilder.prototype.bind=function(a){this.query.bind(a);return this};lf.query.BaseBuilder.prototype.toSql=function(a){return lf.query.toSql(this,a)};lf.query.BaseBuilder.prototype.assertExecPreconditions=function(){};lf.query.BaseBuilder.prototype.getQuery=function(){return this.query.clone()};
lf.query.BaseBuilder.prototype.getObservableQuery=function(){return this.query};lf.query.BaseBuilder.prototype.getPlan_=function(){goog.isDefAndNotNull(this.plan_)||(this.plan_=this.queryEngine_.getPlan(this.query));return this.plan_};lf.query.BaseBuilder.prototype.getTaskItem=function(){return{context:this.getQuery(),plan:this.getPlan_()}};lf.query.BaseBuilder.prototype.getObservableTaskItem=function(){return{context:this.getObservableQuery(),plan:this.getPlan_()}};lf.query.DeleteBuilder=function(a){lf.query.BaseBuilder.call(this,a,new lf.query.DeleteContext(a.getService(lf.service.SCHEMA)))};goog.inherits(lf.query.DeleteBuilder,lf.query.BaseBuilder);lf.query.DeleteBuilder.prototype.from=function(a){this.assertFromPreconditions_();this.query.from=a;return this};lf.query.DeleteBuilder.prototype.where=function(a){this.assertWherePreconditions_();this.query.where=a;return this};
lf.query.DeleteBuilder.prototype.assertFromPreconditions_=function(){if(goog.isDefAndNotNull(this.query.from))throw new lf.Exception(515);};lf.query.DeleteBuilder.prototype.assertWherePreconditions_=function(){if(!goog.isDefAndNotNull(this.query.from))throw new lf.Exception(548);if(goog.isDefAndNotNull(this.query.where))throw new lf.Exception(516);};
lf.query.DeleteBuilder.prototype.assertExecPreconditions=function(){lf.query.DeleteBuilder.superClass_.assertExecPreconditions.call(this);if(!goog.isDefAndNotNull(this.query.from))throw new lf.Exception(517);};lf.query.InsertBuilder=function(a,b){lf.query.BaseBuilder.call(this,a,new lf.query.InsertContext(a.getService(lf.service.SCHEMA)));this.query.allowReplace=b||!1};goog.inherits(lf.query.InsertBuilder,lf.query.BaseBuilder);
lf.query.InsertBuilder.prototype.assertExecPreconditions=function(){lf.query.InsertBuilder.superClass_.assertExecPreconditions.call(this);var a=this.query;if(!goog.isDefAndNotNull(a.into)||!goog.isDefAndNotNull(a.values))throw new lf.Exception(518);if(a.allowReplace&&goog.isNull(a.into.getConstraint().getPrimaryKey()))throw new lf.Exception(519);};lf.query.InsertBuilder.prototype.into=function(a){this.assertIntoPreconditions_();this.query.into=a;return this};
lf.query.InsertBuilder.prototype.values=function(a){this.assertValuesPreconditions_();a instanceof lf.Binder||a.some(function(a){return a instanceof lf.Binder})?this.query.binder=a:this.query.values=a;return this};lf.query.InsertBuilder.prototype.assertIntoPreconditions_=function(){if(goog.isDefAndNotNull(this.query.into))throw new lf.Exception(520);};lf.query.InsertBuilder.prototype.assertValuesPreconditions_=function(){if(goog.isDefAndNotNull(this.query.values))throw new lf.Exception(521);};lf.query.SelectBuilder=function(a,b){lf.query.BaseBuilder.call(this,a,new lf.query.SelectContext(a.getService(lf.service.SCHEMA)));this.fromAlreadyCalled_=this.whereAlreadyCalled_=!1;this.query.columns=b;this.checkDistinctColumn_();this.checkAggregations_()};goog.inherits(lf.query.SelectBuilder,lf.query.BaseBuilder);
lf.query.SelectBuilder.prototype.assertExecPreconditions=function(){lf.query.SelectBuilder.superClass_.assertExecPreconditions.call(this);var a=this.query;if(!goog.isDefAndNotNull(a.from))throw new lf.Exception(522);if(goog.isDef(a.limitBinder)&&!goog.isDef(a.limit)||goog.isDef(a.skipBinder)&&!goog.isDef(a.skip))throw new lf.Exception(523);this.checkProjectionList_()};
lf.query.SelectBuilder.prototype.checkDistinctColumn_=function(){var a=this.query.columns.filter(function(a){return a instanceof lf.fn.AggregatedColumn&&a.aggregatorType==lf.fn.Type.DISTINCT},this);if(0!=a.length&&(1!=a.length||1!=this.query.columns.length))throw new lf.Exception(524);};lf.query.SelectBuilder.prototype.checkProjectionList_=function(){goog.isDefAndNotNull(this.query.groupBy)?this.checkGroupByColumns_():this.checkProjectionListNotMixed_()};
lf.query.SelectBuilder.prototype.checkGroupByColumns_=function(){var a=this.query.columns.filter(function(a){return!(a instanceof lf.fn.AggregatedColumn)}).map(function(a){return a.getNormalizedName()}),b=!1;if(0==this.query.groupBy.length||0==this.query.columns.length)b=!0;else{var c=this.query.groupBy.map(function(a){return a.getNormalizedName()});(b=a.some(function(a){return-1==c.indexOf(a)}))||(b=this.query.groupBy.some(function(a){a=a.getType();return a==lf.Type.OBJECT||a==lf.Type.ARRAY_BUFFER}))}if(b)throw new lf.Exception(525);
};lf.query.SelectBuilder.prototype.checkProjectionListNotMixed_=function(){var a=this.query.columns.some(function(a){return a instanceof lf.fn.AggregatedColumn},this),b=this.query.columns.some(function(a){return!(a instanceof lf.fn.AggregatedColumn)},this)||0==this.query.columns.length;if(a&&b)throw new lf.Exception(526);};
lf.query.SelectBuilder.prototype.checkAggregations_=function(){this.query.columns.forEach(function(a){if(a instanceof lf.fn.AggregatedColumn&&!lf.query.SelectBuilder.isAggregationValid_(a.aggregatorType,a.getType()))throw new lf.Exception(527,a.getNormalizedName());},this)};lf.query.SelectBuilder.prototype.checkFrom_=function(a){if(!goog.isDefAndNotNull(this.query.from))throw new lf.Exception(a);};
lf.query.SelectBuilder.prototype.from=function(a){if(this.fromAlreadyCalled_)throw new lf.Exception(515);this.fromAlreadyCalled_=!0;goog.isDefAndNotNull(this.query.from)||(this.query.from=[]);this.query.from.push.apply(this.query.from,Array.prototype.slice.call(arguments));return this};lf.query.SelectBuilder.prototype.where=function(a){this.checkFrom_(548);if(this.whereAlreadyCalled_)throw new lf.Exception(516);this.whereAlreadyCalled_=!0;this.augmentWhereClause_(a);return this};
lf.query.SelectBuilder.prototype.augmentWhereClause_=function(a){goog.isDefAndNotNull(this.query.where)&&(a=lf.op.and(a,this.query.where));this.query.where=a};lf.query.SelectBuilder.prototype.innerJoin=function(a,b){this.checkFrom_(542);if(this.whereAlreadyCalled_)throw new lf.Exception(547);this.query.from.push(a);this.augmentWhereClause_(b);return this};
lf.query.SelectBuilder.prototype.leftOuterJoin=function(a,b){this.checkFrom_(542);if(!(b instanceof lf.pred.JoinPredicate))throw new lf.Exception(541);if(this.whereAlreadyCalled_)throw new lf.Exception(547);this.query.from.push(a);goog.isDefAndNotNull(this.query.outerJoinPredicates)||(this.query.outerJoinPredicates=lf.structs.set.create());var c=b;a.getEffectiveName()!=b.rightColumn.getTable().getEffectiveName()&&(c=b.reverse());this.query.outerJoinPredicates.add(c.getId());this.augmentWhereClause_(c);
return this};lf.query.SelectBuilder.prototype.limit=function(a){if(goog.isDefAndNotNull(this.query.limit||this.query.limitBinder))throw new lf.Exception(528);if(a instanceof lf.Binder)this.query.limitBinder=a;else{if(0>a)throw new lf.Exception(531);this.query.limit=a}return this};
lf.query.SelectBuilder.prototype.skip=function(a){if(goog.isDefAndNotNull(this.query.skip||this.query.skipBinder))throw new lf.Exception(529);if(a instanceof lf.Binder)this.query.skipBinder=a;else{if(0>a)throw new lf.Exception(531);this.query.skip=a}return this};lf.query.SelectBuilder.prototype.orderBy=function(a,b){this.checkFrom_(549);goog.isDefAndNotNull(this.query.orderBy)||(this.query.orderBy=[]);this.query.orderBy.push({column:a,order:goog.isDefAndNotNull(b)?b:lf.Order.ASC});return this};
lf.query.SelectBuilder.prototype.groupBy=function(a){this.checkFrom_(549);if(goog.isDefAndNotNull(this.query.groupBy))throw new lf.Exception(530);goog.isDefAndNotNull(this.query.groupBy)||(this.query.groupBy=[]);this.query.groupBy.push.apply(this.query.groupBy,Array.prototype.slice.call(arguments));return this};
lf.query.SelectBuilder.isAggregationValid_=function(a,b){switch(a){case lf.fn.Type.COUNT:case lf.fn.Type.DISTINCT:return!0;case lf.fn.Type.AVG:case lf.fn.Type.GEOMEAN:case lf.fn.Type.STDDEV:case lf.fn.Type.SUM:return b==lf.Type.NUMBER||b==lf.Type.INTEGER;case lf.fn.Type.MAX:case lf.fn.Type.MIN:return b==lf.Type.NUMBER||b==lf.Type.INTEGER||b==lf.Type.STRING||b==lf.Type.DATE_TIME}return!1};
lf.query.SelectBuilder.prototype.clone=function(){var a=new lf.query.SelectBuilder(this.global,this.query.columns);a.query=this.query.clone();a.query.clonedFrom=null;return a};lf.query.UpdateBuilder=function(a,b){lf.query.BaseBuilder.call(this,a,new lf.query.UpdateContext(a.getService(lf.service.SCHEMA)));this.query.table=b};goog.inherits(lf.query.UpdateBuilder,lf.query.BaseBuilder);lf.query.UpdateBuilder.prototype.set=function(a,b){var c={binding:b instanceof lf.Binder?b.getIndex():-1,column:a,value:b};goog.isDefAndNotNull(this.query.set)?this.query.set.push(c):this.query.set=[c];return this};
lf.query.UpdateBuilder.prototype.where=function(a){this.assertWherePreconditions_();this.query.where=a;return this};lf.query.UpdateBuilder.prototype.assertWherePreconditions_=function(){if(goog.isDefAndNotNull(this.query.where))throw new lf.Exception(516);};
lf.query.UpdateBuilder.prototype.assertExecPreconditions=function(){lf.query.UpdateBuilder.superClass_.assertExecPreconditions.call(this);if(!goog.isDefAndNotNull(this.query.set))throw new lf.Exception(532);if(this.query.set.some(function(a){return a.value instanceof lf.Binder}))throw new lf.Exception(501);};lf.proc.Database=function(a){this.global_=a;this.schema_=a.getService(lf.service.SCHEMA);this.isActive_=!1};lf.proc.Database.prototype.init=function(a){this.global_.registerService(lf.service.SCHEMA,this.schema_);return lf.base.init(this.global_,a).then(function(){this.isActive_=!0;this.runner_=this.global_.getService(lf.service.RUNNER);return this}.bind(this))};lf.proc.Database.prototype.getSchema=function(){return this.schema_};
lf.proc.Database.prototype.checkActive_=function(){if(!this.isActive_)throw new lf.Exception(2);};lf.proc.Database.prototype.select=function(a){this.checkActive_();var b=1!=arguments.length||goog.isDefAndNotNull(arguments[0])?Array.prototype.slice.call(arguments):[];return new lf.query.SelectBuilder(this.global_,b)};lf.proc.Database.prototype.insert=function(){this.checkActive_();return new lf.query.InsertBuilder(this.global_)};
lf.proc.Database.prototype.insertOrReplace=function(){this.checkActive_();return new lf.query.InsertBuilder(this.global_,!0)};lf.proc.Database.prototype.update=function(a){this.checkActive_();return new lf.query.UpdateBuilder(this.global_,a)};lf.proc.Database.prototype.delete=function(){this.checkActive_();return new lf.query.DeleteBuilder(this.global_)};lf.proc.Database.prototype.observe=function(a,b){this.checkActive_();this.global_.getService(lf.service.OBSERVER_REGISTRY).addObserver(a,b)};
lf.proc.Database.prototype.unobserve=function(a,b){this.checkActive_();this.global_.getService(lf.service.OBSERVER_REGISTRY).removeObserver(a,b)};lf.proc.Database.prototype.createTransaction=function(a){this.checkActive_();return new lf.proc.Transaction(this.global_)};lf.proc.Database.prototype.close=function(){lf.base.closeDatabase(this.global_);this.global_.clear();this.isActive_=!1};lf.proc.Database.prototype.export=function(){this.checkActive_();var a=new lf.proc.ExportTask(this.global_);return this.runner_.scheduleTask(a).then(function(a){return a[0].getPayloads()[0]})};
lf.proc.Database.prototype.import=function(a){this.checkActive_();a=new lf.proc.ImportTask(this.global_,a);return this.runner_.scheduleTask(a).then(function(){return null})};lf.proc.Database.prototype.isOpen=function(){return this.isActive_};var appdb={row:{},schema:{}};appdb.schema.Database=function(){this.tableMap_={};this.pragma_={enableBundledMode:!1};this.item_=new appdb.schema.Item;this.tableMap_.Item=this.item_;this.comment_=new appdb.schema.Comment;this.tableMap_.Comment=this.comment_};appdb.schema.Database.prototype.name=function(){return"app"};appdb.schema.Database.prototype.version=function(){return 1};appdb.schema.Database.prototype.tables=function(){return[this.item_,this.comment_]};
appdb.schema.Database.prototype.info=function(){this.metaInfo_||(this.metaInfo_=new lf.schema.Info(this));return this.metaInfo_};appdb.schema.Database.prototype.table=function(a){return this.tableMap_[a]||null};appdb.schema.Database.prototype.pragma=function(){return this.pragma_};appdb.schema.Database.prototype.getItem=function(){return this.item_};appdb.schema.Database.prototype.getComment=function(){return this.comment_};
appdb.schema.Item=function(){var a=[];this.id=new lf.schema.BaseColumn(this,"id",!0,!1,lf.Type.INTEGER);a.push(this.id);this.description=new lf.schema.BaseColumn(this,"description",!1,!1,lf.Type.STRING);a.push(this.description);this.deadline=new lf.schema.BaseColumn(this,"deadline",!1,!1,lf.Type.DATE_TIME);a.push(this.deadline);this.done=new lf.schema.BaseColumn(this,"done",!1,!1,lf.Type.BOOLEAN);a.push(this.done);var b=[new lf.schema.Index("Item","pkItem",!0,[{schema:this.id,order:lf.Order.ASC,autoIncrement:!1}]),
new lf.schema.Index("Item","idxDeadline",!1,[{schema:this.deadline,order:lf.Order.DESC}])];lf.schema.Table.call(this,"Item",a,b,!1)};goog.inherits(appdb.schema.Item,lf.schema.Table);appdb.schema.Item.prototype.createRow=function(a){return new appdb.row.Item(lf.Row.getNextId(),a)};appdb.schema.Item.prototype.deserializeRow=function(a){var b=a.value;b.deadline=new Date(b.deadline);return new appdb.row.Item(a.id,b)};
appdb.schema.Item.prototype.getConstraint=function(){if(goog.isDefAndNotNull(this.constraint_))return this.constraint_;var a=this.getIndices()[0];return this.constraint_=new lf.schema.Constraint(a,[this.id,this.description,this.deadline,this.done],[])};appdb.row.ItemType=function(){};appdb.row.ItemDbType=function(){};appdb.row.Item=function(a,b){lf.Row.call(this,a,b)};goog.inherits(appdb.row.Item,lf.Row);
appdb.row.Item.prototype.defaultPayload=function(){var a=new appdb.row.ItemType;a.id=0;a.description="";a.deadline=new Date(0);a.done=!1;return a};appdb.row.Item.prototype.toDbPayload=function(){var a=new appdb.row.ItemDbType;a.id=this.payload().id;a.description=this.payload().description;a.deadline=this.payload().deadline.getTime();a.done=this.payload().done;return a};
appdb.row.Item.prototype.keyOfIndex=function(a){switch(a){case "Item.pkItem":return this.payload().id;case "Item.idxDeadline":return this.payload().deadline.getTime();case "Item.#":return this.id()}return null};appdb.row.Item.prototype.getId=function(){return this.payload().id};appdb.row.Item.prototype.setId=function(a){this.payload().id=a;return this};appdb.row.Item.prototype.getDescription=function(){return this.payload().description};
appdb.row.Item.prototype.setDescription=function(a){this.payload().description=a;return this};appdb.row.Item.prototype.getDeadline=function(){return this.payload().deadline};appdb.row.Item.prototype.setDeadline=function(a){this.payload().deadline=a;return this};appdb.row.Item.prototype.getDone=function(){return this.payload().done};appdb.row.Item.prototype.setDone=function(a){this.payload().done=a;return this};
appdb.schema.Comment=function(){var a=[];this.id=new lf.schema.BaseColumn(this,"id",!0,!1,lf.Type.INTEGER);a.push(this.id);this.itemId=new lf.schema.BaseColumn(this,"itemId",!1,!1,lf.Type.INTEGER);a.push(this.itemId);this.text=new lf.schema.BaseColumn(this,"text",!1,!1,lf.Type.STRING);a.push(this.text);var b=[new lf.schema.Index("Comment","pkComment",!0,[{schema:this.id,order:lf.Order.ASC,autoIncrement:!1}])];lf.schema.Table.call(this,"Comment",a,b,!1)};goog.inherits(appdb.schema.Comment,lf.schema.Table);
appdb.schema.Comment.prototype.createRow=function(a){return new appdb.row.Comment(lf.Row.getNextId(),a)};appdb.schema.Comment.prototype.deserializeRow=function(a){return new appdb.row.Comment(a.id,a.value)};appdb.schema.Comment.prototype.getConstraint=function(){if(goog.isDefAndNotNull(this.constraint_))return this.constraint_;var a=this.getIndices()[0];return this.constraint_=new lf.schema.Constraint(a,[this.id,this.itemId,this.text],[])};appdb.row.CommentType=function(){};
appdb.row.CommentDbType=function(){};appdb.row.Comment=function(a,b){lf.Row.call(this,a,b)};goog.inherits(appdb.row.Comment,lf.Row);appdb.row.Comment.prototype.defaultPayload=function(){var a=new appdb.row.CommentType;a.id=0;a.itemId=0;a.text="";return a};appdb.row.Comment.prototype.toDbPayload=function(){var a=new appdb.row.CommentDbType;a.id=this.payload().id;a.itemId=this.payload().itemId;a.text=this.payload().text;return a};
appdb.row.Comment.prototype.keyOfIndex=function(a){switch(a){case "Comment.pkComment":return this.payload().id;case "Comment.#":return this.id()}return null};appdb.row.Comment.prototype.getId=function(){return this.payload().id};appdb.row.Comment.prototype.setId=function(a){this.payload().id=a;return this};appdb.row.Comment.prototype.getItemId=function(){return this.payload().itemId};appdb.row.Comment.prototype.setItemId=function(a){this.payload().itemId=a;return this};
appdb.row.Comment.prototype.getText=function(){return this.payload().text};appdb.row.Comment.prototype.setText=function(a){this.payload().text=a;return this};appdb.getGlobal=function(){var a=new lf.service.ServiceId("ns_app"),b=lf.Global.get(),c=null;b.isRegistered(a)?c=b.getService(a):(c=new lf.Global,b.registerService(a,c));return c};appdb.getSchema=function(){var a=appdb.getGlobal();if(!a.isRegistered(lf.service.SCHEMA)){var b=new appdb.schema.Database;a.registerService(lf.service.SCHEMA,b)}return a.getService(lf.service.SCHEMA)};
appdb.connect=function(a){if(!goog.isNull(appdb.db_)&&appdb.db_.isOpen())throw new lf.Exception(113);goog.isNull(appdb.db_)&&(appdb.getSchema(),appdb.db_=new lf.proc.Database(appdb.getGlobal()));return appdb.db_.init(a)};appdb.db_=null;