Comparing version 0.0.6 to 0.0.7
@@ -24,2 +24,6 @@ export function internal(_: string): any { | ||
export function variant(_: any, __: string=""): any { | ||
// | ||
} | ||
export const singleton: string = ""; | ||
@@ -26,0 +30,0 @@ export const notify: string = ""; |
@@ -5,5 +5,9 @@ import { IDXDB, SecondaryValue, SecondaryIterator } from "./idxdb"; | ||
import { check } from "./system"; | ||
import { print } from "./debug"; | ||
export const SAME_PAYER = new Name(); | ||
const noAvailablePrimaryKey = <u64>(-2) // Must be the smallest uint64_t value compared to all other tags | ||
const unsetNextPrimaryKey = <u64>(-1) // No table | ||
export class PrimaryIterator { | ||
@@ -17,3 +21,3 @@ constructor(public i: i32) {} | ||
isEnd(): bool { | ||
return this.i == -2; | ||
return this.i == noAvailablePrimaryKey; | ||
} | ||
@@ -30,2 +34,4 @@ } | ||
idxdbs: Array<IDXDB>; | ||
nextPrimaryKey: u64 = unsetNextPrimaryKey; | ||
constructor(code: Name, scope: Name, table: Name, indexes: Array<IDXDB> = []) { | ||
@@ -37,6 +43,12 @@ this.db = new DBI64(code.N, scope.N, table.N); | ||
store(value: T, payer: Name): PrimaryIterator { | ||
let it = this.db.store(value.getPrimaryValue(), value.pack(), payer.N); | ||
const it = this.db.store(value.getPrimaryValue(), value.pack(), payer.N); | ||
for (let i=0; i<this.idxdbs.length; i++) { | ||
this.idxdbs[i].storeEx(value.getPrimaryValue(), value.getSecondaryValue(i), payer.N); | ||
} | ||
const pk = value.getPrimaryValue() | ||
if (pk >= this.nextPrimaryKey) { | ||
this.nextPrimaryKey = (pk >= noAvailablePrimaryKey) ? noAvailablePrimaryKey : (pk + 1); | ||
} | ||
return new PrimaryIterator(it); | ||
@@ -56,2 +68,6 @@ } | ||
} | ||
if (primary >= this.nextPrimaryKey) { | ||
this.nextPrimaryKey = (primary >= noAvailablePrimaryKey) ? noAvailablePrimaryKey : (primary + 1); | ||
} | ||
} | ||
@@ -132,2 +148,6 @@ | ||
begin(): PrimaryIterator { | ||
return this.lowerBound(u64.MIN_VALUE) | ||
} | ||
end(): PrimaryIterator { | ||
@@ -152,2 +172,22 @@ let i = this.db.end(); | ||
} | ||
availablePrimaryKey(): u64 { | ||
if (this.nextPrimaryKey == unsetNextPrimaryKey) { | ||
if (this.begin().i == this.end().i) { | ||
this.nextPrimaryKey = 0; | ||
} else { | ||
const end = this.end(); | ||
const itr = this.previous(end) | ||
const pk = this.get(itr).getPrimaryValue() | ||
if (pk >= noAvailablePrimaryKey) { | ||
this.nextPrimaryKey = noAvailablePrimaryKey | ||
} else { | ||
this.nextPrimaryKey = pk + 1 | ||
} | ||
} | ||
} | ||
check(this.nextPrimaryKey < noAvailablePrimaryKey, "next primary key in table is at autoincrement limit") | ||
return this.nextPrimaryKey | ||
} | ||
} |
{ | ||
"name": "as-chain", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "chain module for assemblyscript", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122220
3231