This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathtable_builder.js
742 lines (638 loc) · 20.7 KB
/
table_builder.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
/**
* @license
* 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.
*/
goog.provide('lf.schema.TableBuilder');
goog.require('lf.ConstraintAction');
goog.require('lf.ConstraintTiming');
goog.require('lf.Exception');
goog.require('lf.Order');
goog.require('lf.Row');
goog.require('lf.Type');
goog.require('lf.eval.Registry');
goog.require('lf.schema.BaseColumn');
goog.require('lf.schema.Constraint');
goog.require('lf.schema.ForeignKeySpec');
goog.require('lf.schema.Index');
goog.require('lf.schema.Table');
goog.require('lf.structs.map');
goog.require('lf.structs.set');
goog.require('lf.type');
/**
* Dynamic Table schema builder.
* @constructor
*
* @param {string} tableName
* @export
*/
lf.schema.TableBuilder = function(tableName) {
this.checkNamingRules_(tableName);
/** @private {!lf.eval.Registry} */
this.evalRegistry_ = lf.eval.Registry.get();
/** @private {string} */
this.name_ = tableName;
/** @private {!lf.structs.Map<string, !lf.Type>} */
this.columns_ = lf.structs.map.create();
/** @private {!lf.structs.Set<string>} */
this.uniqueColumns_ = lf.structs.set.create();
/** @private {!lf.structs.Set<string>} */
this.uniqueIndices_ = lf.structs.set.create();
/** @private {!lf.structs.Set<string>} */
this.nullable_ = lf.structs.set.create();
/** @private {?string} */
this.pkName_ = null;
/**
* @private {!lf.structs.Map<string,
* !Array<!lf.schema.TableBuilder.IndexedColumn_>>}
*/
this.indices_ = lf.structs.map.create();
/** @private {boolean} */
this.persistentIndex_ = false;
/** @private {!Array<!lf.schema.ForeignKeySpec>} */
this.fkSpecs_ = [];
};
/**
* A intermediate representation of an IndexedColumn used while this table's
* declaration is still in progress. Once this table's schema is finalized it is
* convered to a proper lf.schema.IndexedColumn object.
* @typedef {{
* name: string,
* order: !lf.Order,
* autoIncrement: boolean
* }}
* @private
*/
lf.schema.TableBuilder.IndexedColumnRaw_;
/**
* @constructor @struct
* @private
*
* @param {!lf.schema.TableBuilder.IndexedColumnRaw_} raw The plain JS object as
* passed from clients. It is wrapped within a proper JS class, such that
* the rest of the code in this file does not give up compiler coverage.
*/
lf.schema.TableBuilder.IndexedColumn_ = function(raw) {
/** @type {string} */
this.name = raw['name'];
/** @type {!lf.Order} */
this.order = raw['order'];
/** @type {boolean} */
this.autoIncrement = raw['autoIncrement'];
};
/**
* A set of types that are nullable by default. Columns of this type default to
* a null value even if addNullable() is not explicitly called.
* @type {!lf.structs.Set<!lf.Type>}
*/
lf.schema.TableBuilder.NULLABLE_TYPES_BY_DEFAULT = lf.structs.set.create([
lf.Type.ARRAY_BUFFER,
lf.Type.OBJECT
]);
/**
* @param {string} name
* @return {string}
* @private
* @see http://en.wikipedia.org/wiki/CamelCase
*/
lf.schema.TableBuilder.toPascal_ = function(name) {
return name[0].toUpperCase() + name.substring(1);
};
/**
* @param {string} name
* @private
* @throws {!lf.Exception}
*/
lf.schema.TableBuilder.prototype.checkNamingRules_ = function(name) {
if (!(/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))) {
// 502: Naming rule violation: {0}.
throw new lf.Exception(502, name);
}
};
/**
* @param {string} name
* @private
* @throws {!lf.Exception}
*/
lf.schema.TableBuilder.prototype.checkNameConflicts_ = function(name) {
if (name == this.name_) {
// 546: Indices/constraints/columns can't re-use the table name {0},
throw new lf.Exception(546, name);
}
if (this.columns_.has(name) ||
this.indices_.has(name) ||
this.uniqueIndices_.has(name)) {
// 503: Name {0} is already defined.
throw new lf.Exception(503, this.name_ + '.' + name);
}
};
/**
* @param {!Array<!lf.schema.TableBuilder.IndexedColumn_>} columns
* @private
*/
lf.schema.TableBuilder.prototype.checkPrimaryKey_ = function(columns) {
var hasAutoIncrement = false;
columns.forEach(function(column) {
var columnType = this.columns_.get(column.name);
hasAutoIncrement = hasAutoIncrement || column.autoIncrement;
if (column.autoIncrement && columnType != lf.Type.INTEGER) {
// 504: Can not use autoIncrement with a non-integer primary key.
throw new lf.Exception(504);
}
}, this);
if (hasAutoIncrement && columns.length > 1) {
// 505: Can not use autoIncrement with a cross-column primary key.
throw new lf.Exception(505);
}
};
/**
* Checks whether any primary key column is also used as a foreign key child
* column, and throws an exception if such a column is found.
* @private
* @throws {!lf.Exception}
*/
lf.schema.TableBuilder.prototype.checkPrimaryKeyNotForeignKey_ = function() {
if (goog.isNull(this.pkName_)) {
return;
}
var pkColumns = this.indices_.get(this.pkName_).map(
function(indexedColumn) {
return indexedColumn.name;
});
var fkSpecIndex = 0;
var conflict = this.fkSpecs_.some(function(fkSpec, i) {
fkSpecIndex = i;
return pkColumns.indexOf(fkSpec.childColumn) != -1;
}, this);
if (conflict) {
// 543: Foreign key {0}. A primary key column can't also be a foreign key
// child column.
throw new lf.Exception(543, this.fkSpecs_[fkSpecIndex].name);
}
};
/**
* Checks whether the primary key index is identical (in terms of indexed
* columns) with another explicitly added index.
* @private
* @throws {!lf.Exception}
*/
lf.schema.TableBuilder.prototype.checkPrimaryKeyDuplicateIndex_ = function() {
if (goog.isNull(this.pkName_)) {
return;
}
var extractName = function(indexedColumn) {
return indexedColumn.name;
};
var pkColumnsJson = JSON.stringify(
this.indices_.get(this.pkName_).map(extractName));
this.indices_.forEach(function(indexedColumns, indexName) {
if (indexName == this.pkName_) {
return;
}
var indexedColumnNames = indexedColumns.map(extractName);
if (JSON.stringify(indexedColumnNames) == pkColumnsJson) {
// 544: Duplicate primary key index found at {0},
throw new lf.Exception(544, this.name_ + '.' + indexName);
}
}, this);
};
/**
* Checks whether any primary key column has also been marked as nullable.
* @private
* @throws {!lf.Exception}
*/
lf.schema.TableBuilder.prototype.checkPrimaryKeyNotNullable_ = function() {
if (goog.isNull(this.pkName_)) {
return;
}
this.indices_.get(this.pkName_).forEach(
function(indexedColumn) {
if (this.nullable_.has(indexedColumn.name)) {
// 545: Primary key column {0} can't be marked as nullable,
throw new lf.Exception(545, this.name_ + '.' + indexedColumn.name);
}
}, this);
};
/**
* @param {string} name
* @param {!lf.Type} type
* @return {!lf.schema.TableBuilder}
* @export
*/
lf.schema.TableBuilder.prototype.addColumn = function(name, type) {
this.checkNamingRules_(name);
this.checkNameConflicts_(name);
this.columns_.set(name, type);
if (lf.schema.TableBuilder.NULLABLE_TYPES_BY_DEFAULT.has(type)) {
this.addNullable([name]);
}
return this;
};
/**
* Adds a primary key to table.
* There are two overloads of this function:
*
* case 1: (columns: !Array<string>, opt_autoInc)
* specifies primary key by given only column names with default ascending
* orders (lf.Order.ASC). When opt_autoInc is true, there can be only one
* column in the columns, its type must be lf.Type.INTEGER, and its order
* must be the default lf.Order.ASC.
*
* case 2: (columns: !Array<!lf.schema.TableBuilder.IndexedColumnRaw_>)
* allows different ordering per-column, but more verbose.
*
* @param {(!Array<string>|!Array<!lf.schema.TableBuilder.IndexedColumnRaw_>)}
* columns
* @param {boolean=} opt_autoInc
* @return {!lf.schema.TableBuilder}
* @export
*/
lf.schema.TableBuilder.prototype.addPrimaryKey = function(
columns, opt_autoInc) {
this.pkName_ = 'pk' + lf.schema.TableBuilder.toPascal_(this.name_);
this.checkNamingRules_(this.pkName_);
this.checkNameConflicts_(this.pkName_);
var cols = this.normalizeColumns_(columns, true, undefined, opt_autoInc);
this.checkPrimaryKey_(cols);
if (cols.length == 1) {
this.uniqueColumns_.add(cols[0].name);
}
this.uniqueIndices_.add(this.pkName_);
this.indices_.set(this.pkName_, cols);
return this;
};
/**
* Creates a foreign key on a given table column.
* @param {string} name
* @param {!lf.schema.RawForeignKeySpec} rawSpec
* @return {!lf.schema.TableBuilder}
* @export
*/
lf.schema.TableBuilder.prototype.addForeignKey = function(name, rawSpec) {
this.checkNamingRules_(name);
this.checkNameConflicts_(name);
var spec = new lf.schema.ForeignKeySpec(rawSpec, this.name_, name);
if (!goog.isDef(spec.action)) {
spec.action = lf.ConstraintAction.RESTRICT;
}
if (!goog.isDef(spec.timing)) {
spec.timing = lf.ConstraintTiming.IMMEDIATE;
}
if (spec.action == lf.ConstraintAction.CASCADE &&
spec.timing == lf.ConstraintTiming.DEFERRABLE) {
// 506: Lovefield allows only immediate evaluation of cascading constraints.
throw new lf.Exception(506);
}
if (!this.columns_.has(spec.childColumn)) {
// 540: Foreign key {0} has invalid reference syntax.
throw new lf.Exception(540, name);
}
this.fkSpecs_.push(spec);
this.addIndex(
name, [spec.childColumn],
this.uniqueColumns_.has(spec.childColumn));
return this;
};
/**
* @param {string} name
* @param {!Array<string>} columns
* @return {!lf.schema.TableBuilder}
* @export
*/
lf.schema.TableBuilder.prototype.addUnique = function(name, columns) {
this.checkNamingRules_(name);
this.checkNameConflicts_(name);
var cols = this.normalizeColumns_(columns, true);
if (cols.length == 1) {
this.uniqueColumns_.add(cols[0].name);
this.markFkIndexForColumnUnique_(cols[0].name);
}
this.indices_.set(name, cols);
this.uniqueIndices_.add(name);
return this;
};
/**
* Marks the index corresponding to the child column of a foreign key constraint
* as unique, if such an index exists.
* @param {string} column The unique column.
* @private
*/
lf.schema.TableBuilder.prototype.markFkIndexForColumnUnique_ =
function(column) {
this.fkSpecs_.forEach(function(fkSpec) {
if (fkSpec.childColumn == column) {
var indexName = fkSpec.name.split('.')[1];
this.uniqueIndices_.add(indexName);
}
}, this);
};
/**
* @param {!Array<string>} columns Names of the columns that can be nullable.
* @return {!lf.schema.TableBuilder}
* @export
*/
lf.schema.TableBuilder.prototype.addNullable = function(columns) {
var cols = this.normalizeColumns_(columns, false);
cols.forEach(function(col) {
this.nullable_.add(col.name);
}, this);
return this;
};
/**
* Mimics SQL CREATE INDEX.
* There are two overloads of this function:
*
* case 1: (name, columns: !Array<string>, opt_unique, opt_order)
* adds an index by column names only. All columns have same ordering.
*
* case 2: (name, columns: !Array<!lf.schema.TableBuilder.IndexedColumnRaw_>,
* opt_unique)
* adds an index, allowing customization of ordering, but more verbose.
*
* @param {string} name
* @param {!Array<string>|!Array<!lf.schema.TableBuilder.IndexedColumnRaw_>}
* columns
* @param {boolean=} opt_unique Whether the index is unique, default is false.
* @param {!lf.Order=} opt_order Order of columns, only effective when columns
* are array of strings, default to lf.Order.ASC.
* @return {!lf.schema.TableBuilder}
* @export
*/
lf.schema.TableBuilder.prototype.addIndex = function(
name, columns, opt_unique, opt_order) {
this.checkNamingRules_(name);
this.checkNameConflicts_(name);
var cols = this.normalizeColumns_(columns, true, opt_order);
if (opt_unique) {
this.uniqueIndices_.add(name);
}
this.indices_.set(name, cols);
return this;
};
/** @export @param {boolean} value */
lf.schema.TableBuilder.prototype.persistentIndex = function(value) {
this.persistentIndex_ = value;
};
/** @export @return {!lf.schema.Table} */
lf.schema.TableBuilder.prototype.getSchema = function() {
this.checkPrimaryKeyNotForeignKey_();
this.checkPrimaryKeyDuplicateIndex_();
this.checkPrimaryKeyNotNullable_();
var tableClass = this.generateTableClass_();
return new tableClass();
};
/** @return {!Array<!lf.schema.ForeignKeySpec>} */
lf.schema.TableBuilder.prototype.getFkSpecs = function() {
return this.fkSpecs_;
};
/**
* Convert different column representations (column name only or column objects)
* into column object array. Also performs consistency check to make sure
* referred columns are actually defined.
* @param {(!Array<string>|!Array<!lf.schema.TableBuilder.IndexedColumnRaw_>)}
* columns
* @param {boolean} checkIndexable
* @param {!lf.Order=} opt_order
* @param {boolean=} opt_autoInc
* @return {!Array<!lf.schema.TableBuilder.IndexedColumn_>} Normalized columns
* @private
*/
lf.schema.TableBuilder.prototype.normalizeColumns_ = function(
columns, checkIndexable, opt_order, opt_autoInc) {
var normalized = columns;
if (typeof(columns[0]) == 'string') {
normalized = columns.map(function(col) {
return new lf.schema.TableBuilder.IndexedColumn_({
'name': col,
'order': goog.isDefAndNotNull(opt_order) ? opt_order : lf.Order.ASC,
'autoIncrement': opt_autoInc || false
});
});
} else { // case of IndexedColumnRaw_
normalized = columns.map(function(col) {
return new lf.schema.TableBuilder.IndexedColumn_(col);
});
}
normalized.forEach(function(col) {
if (!this.columns_.has(col.name)) {
// 508: Table {0} does not have column: {1}.
throw new lf.Exception(508, this.name_, col.name);
}
if (checkIndexable) {
var type = this.columns_.get(col.name);
if (type == lf.Type.ARRAY_BUFFER || type == lf.Type.OBJECT) {
// 509: Attempt to index table {0} on non-indexable column {1}.
throw new lf.Exception(509, this.name_, col.name);
}
}
}, this);
return normalized;
};
/**
* @return {!Function}
* @private
*/
lf.schema.TableBuilder.prototype.generateTableClass_ = function() {
var that = this;
/**
* @constructor
* @extends {lf.schema.Table}
*/
var tableClass = function() {
var columns = lf.structs.map.keys(that.columns_).map(function(colName) {
this[colName] = new lf.schema.BaseColumn(
this,
colName,
that.uniqueColumns_.has(colName),
that.nullable_.has(colName),
that.columns_.get(colName));
return this[colName];
}, this);
var generateIndexedColumns = function(indexName) {
return that.indices_.get(indexName).map(
function(indexedColumn) {
return {
schema: this[indexedColumn.name],
order: indexedColumn.order,
autoIncrement: indexedColumn.autoIncrement
};
}, this);
};
var indices = lf.structs.map.keys(that.indices_).map(function(indexName) {
return new lf.schema.Index(
that.name_,
indexName,
that.uniqueIndices_.has(indexName),
generateIndexedColumns.call(this, indexName));
}, this);
tableClass.base(
this, 'constructor',
that.name_, columns, indices, that.persistentIndex_);
var pk = !goog.isNull(that.pkName_) ?
new lf.schema.Index(
that.name_, that.pkName_, true,
generateIndexedColumns.call(this, that.pkName_)) :
null;
var notNullable = columns.filter(function(col) {
return !that.nullable_.has(col.getName());
});
/** @private {!lf.schema.Constraint} */
this.constraint_ =
new lf.schema.Constraint(pk, notNullable, that.getFkSpecs());
/** @private {!Function} */
this.rowClass_ = that.generateRowClass_(columns, indices);
};
goog.inherits(tableClass, lf.schema.Table);
/** @override */
tableClass.prototype.createRow = function(opt_value) {
return new this.rowClass_(lf.Row.getNextId(), opt_value);
};
// NOTE: Can't use @export with generated classes, so using
// goog.exportProperty instead.
goog.exportProperty(
tableClass.prototype, 'createRow', tableClass.prototype.createRow);
/** @override */
tableClass.prototype.deserializeRow = function(dbRecord) {
var obj = {};
this.getColumns().forEach(function(col) {
var key = col.getName();
var type = col.getType();
var value = dbRecord['value'][key];
if (type == lf.Type.ARRAY_BUFFER) {
obj[key] = lf.Row.hexToBin(value);
} else if (type == lf.Type.DATE_TIME) {
obj[key] = goog.isDefAndNotNull(value) ? new Date(value) : null;
} else {
obj[key] = value;
}
}, this);
return new this.rowClass_(dbRecord['id'], obj);
};
goog.exportProperty(
tableClass.prototype, 'deserializeRow',
tableClass.prototype.deserializeRow);
/** @override */
tableClass.prototype.getConstraint = function() {
return this.constraint_;
};
goog.exportProperty(
tableClass.prototype, 'getConstraint',
tableClass.prototype.getConstraint);
return tableClass;
};
/**
* @param {!Array<!lf.schema.Column>} columns
* @param {!Array<!lf.schema.Index>} indices
* @return {!Function}
* @private
*/
lf.schema.TableBuilder.prototype.generateRowClass_ = function(
columns, indices) {
/**
* @param {number} rowId
* @param {!Object=} opt_payload
* @extends {lf.Row}
* @constructor
*/
var rowClass = function(rowId, opt_payload) {
/** @private {!Array<!lf.schema.Column>} */
this.columns_ = columns;
/** @private {!Array<!lf.schema.Index>} */
this.indices_ = indices;
// Placed here so that defaultPayload() can run correctly.
rowClass.base(this, 'constructor', rowId, opt_payload);
};
goog.inherits(rowClass, lf.Row);
/** @override */
rowClass.prototype.defaultPayload = function() {
var obj = {};
this.columns_.forEach(function(col) {
obj[col.getName()] = col.isNullable() ?
null : lf.type.DEFAULT_VALUES[col.getType()];
});
return obj;
};
/** @override */
rowClass.prototype.toDbPayload = function() {
var obj = {};
this.columns_.forEach(function(col) {
var key = col.getName();
var type = col.getType();
var value = this.payload()[key];
if (type == lf.Type.ARRAY_BUFFER) {
obj[key] = goog.isDefAndNotNull(value) ? lf.Row.binToHex(value) : null;
} else if (type == lf.Type.DATE_TIME) {
obj[key] = goog.isDefAndNotNull(value) ? value.getTime() : null;
} else if (type == lf.Type.OBJECT) {
obj[key] = goog.isDefAndNotNull(value) ? value : null;
} else {
obj[key] = value;
}
}, this);
return obj;
};
/**
* @param {!lf.schema.Column} column
* @return {function(!Object): !lf.index.Index.Key}
* @this {lf.schema.TableBuilder}
*/
var getSingleKeyFn = function(column) {
var colType = this.columns_.get(column.getName());
var keyOfIndexFn = this.evalRegistry_.getKeyOfIndexEvaluator(colType);
return function(payload) {
return keyOfIndexFn(payload[column.getName()]);
};
}.bind(this);
/**
* @param {!Array<!lf.schema.IndexedColumn>} columns
* @return {function(!Object): !lf.index.Index.Key}
* @this {lf.schema.TableBuilder}
*/
var getMultiKeyFn = function(columns) {
var getSingleKeyFunctions = columns.map(
function(indexedColumn) {
return getSingleKeyFn(indexedColumn.schema);
});
return function(payload) {
return getSingleKeyFunctions.map(function(fn) {
return fn(payload);
});
};
}.bind(this);
/**
* @param {!lf.schema.Index} index
* @return {function(!Object): !lf.index.Index.Key}
*/
var getKeyOfIndexFn = function(index) {
return index.columns.length == 1 ?
getSingleKeyFn(index.columns[0].schema) :
getMultiKeyFn(index.columns);
};
var functionMap = {};
indices.forEach(function(index) {
var key = index.getNormalizedName();
functionMap[key] = getKeyOfIndexFn(index);
});
/** @override */
rowClass.prototype.keyOfIndex = function(indexName) {
if (indexName.indexOf('#') != -1) {
return /** @type {!lf.index.Index.Key} */ (this.id());
}
if (functionMap.hasOwnProperty(indexName)) {
return functionMap[indexName](this.payload());
}
return null;
};
return rowClass;
};