Skip to content

Commit

Permalink
Re-generate types
Browse files Browse the repository at this point in the history
  • Loading branch information
maierson authored and maierson committed Dec 15, 2016
1 parent 6c47de9 commit d907a8a
Show file tree
Hide file tree
Showing 60 changed files with 1,650 additions and 20 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
/node_modules/
/lib/
/dist/
.vscode
82 changes: 65 additions & 17 deletions dist/one.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/one.min.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions lib/CacheInstance.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ICacheRepo } from './CacheRepo';
import { ICacheThread } from './CacheThread';
import { ICacheNode } from './CacheNode';
export interface ICacheInstance {
name: string;
repo: ICacheRepo;
thread: ICacheThread;
nextNodeKey: number;
reset: () => void;
addNode: (node: ICacheNode) => boolean;
size: () => number;
length: () => number;
}
export default class CacheInstance implements ICacheInstance {
name: string;
repo: ICacheRepo;
thread: ICacheThread;
nextNodeKey: number;
constructor(name: string);
reset: () => void;
addNode: (node: ICacheNode) => boolean;
length: () => number;
size: () => number;
}
34 changes: 34 additions & 0 deletions lib/CacheInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use strict";
var CacheRepo_1 = require("./CacheRepo");
var CacheThread_1 = require("./CacheThread");
var CacheInstance = (function () {
function CacheInstance(name) {
var _this = this;
this.repo = new CacheRepo_1.default();
this.thread = new CacheThread_1.default();
this.nextNodeKey = 0;
this.reset = function () {
_this.repo = new CacheRepo_1.default();
_this.thread = new CacheThread_1.default();
_this.nextNodeKey = 0;
};
this.addNode = function (node) {
if (_this.repo.add(node)) {
_this.thread.addNode(node.id);
_this.nextNodeKey++;
return true;
}
return false;
};
this.length = function () {
return _this.thread.nodes.length;
};
this.size = function () {
return _this.repo.length;
};
this.name = name;
}
return CacheInstance;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = CacheInstance;
8 changes: 8 additions & 0 deletions lib/CacheItem.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import CacheMap from './CacheMap';
export default class CacheItem {
entity: {};
mapTo: CacheMap<Array<string>>;
mapFrom: CacheMap<Array<string>>;
constructor(entity: {}, liveItem?: CacheItem);
clone: () => CacheItem;
}
22 changes: 22 additions & 0 deletions lib/CacheItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";
var CacheMap_1 = require("./CacheMap");
var CacheItem = (function () {
function CacheItem(entity, liveItem) {
var _this = this;
this.clone = function () {
return new CacheItem(_this.entity, _this);
};
this.entity = entity;
if (liveItem) {
this.mapFrom = liveItem.mapFrom.clone();
this.mapTo = liveItem.mapTo.clone();
}
else {
this.mapFrom = new CacheMap_1.default();
this.mapTo = new CacheMap_1.default();
}
}
return CacheItem;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = CacheItem;
12 changes: 12 additions & 0 deletions lib/CacheMap.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default class CacheMap<T> {
paths: {};
length: number;
constructor();
set(key: string | number, value: T): boolean;
get: (key: any) => T;
delete: (key: any) => boolean;
has: (key: any) => boolean;
forEach: (callback: Function) => void;
clone: () => CacheMap<T>;
size(): number;
}
52 changes: 52 additions & 0 deletions lib/CacheMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use strict";
var objectAssign = require('object-assign');
var CacheMap = (function () {
function CacheMap() {
var _this = this;
this.paths = {};
this.length = 0;
this.get = function (key) {
return _this.paths[key];
};
this.delete = function (key) {
if (typeof _this.paths[key] !== "undefined" && _this.length > 0) {
var val = _this.paths[key];
delete _this.paths[key];
_this.length--;
return val;
}
};
this.has = function (key) {
return typeof _this.paths[key] !== 'undefined';
};
this.forEach = function (callback) {
for (var key in _this.paths) {
if (_this.paths.hasOwnProperty(key)) {
callback(key, _this.paths[key]);
}
}
};
this.clone = function () {
var newInstance = objectAssign({}, _this.paths);
var clone = new CacheMap();
clone.paths = newInstance;
clone.length = _this.length;
return clone;
};
}
CacheMap.prototype.set = function (key, value) {
if (typeof this.paths[key] === "undefined") {
this.length++;
this.paths[key] = value;
return true;
}
this.paths[key] = value;
return false;
};
CacheMap.prototype.size = function () {
return this.length;
};
return CacheMap;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = CacheMap;
11 changes: 11 additions & 0 deletions lib/CacheNode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import CacheMap from './CacheMap';
import CacheItem from './CacheItem';
export interface ICacheNode {
id: number;
items: CacheMap<CacheItem>;
}
export declare class CacheNode implements ICacheNode {
id: number;
items: CacheMap<CacheItem>;
constructor(nodeId: number);
}
10 changes: 10 additions & 0 deletions lib/CacheNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";
var CacheMap_1 = require("./CacheMap");
var CacheNode = (function () {
function CacheNode(nodeId) {
this.items = new CacheMap_1.default();
this.id = nodeId;
}
return CacheNode;
}());
exports.CacheNode = CacheNode;
15 changes: 15 additions & 0 deletions lib/CacheRepo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ICacheNode } from './CacheNode';
import CacheMap from './CacheMap';
export interface ICacheRepo {
get: (nodeId: number) => ICacheNode;
length: number;
add: (node: ICacheNode) => boolean;
delete: (nodeId: number) => void;
}
export default class CacheRepo implements ICacheRepo {
items: CacheMap<ICacheNode>;
length: number;
get: (nodeId: any) => ICacheNode;
add: (node: ICacheNode) => boolean;
delete: (nodeId: number) => void;
}
27 changes: 27 additions & 0 deletions lib/CacheRepo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
var CacheMap_1 = require("./CacheMap");
var CacheRepo = (function () {
function CacheRepo() {
var _this = this;
this.items = new CacheMap_1.default();
this.length = 0;
this.get = function (nodeId) { return (_this.items.get(nodeId)); };
this.add = function (node) {
if (!_this.items.has(node.id)) {
_this.items.set(node.id, node);
_this.length++;
return true;
}
return false;
};
this.delete = function (nodeId) {
if (_this.items.has(nodeId)) {
_this.items.delete(nodeId);
_this.length--;
}
};
}
return CacheRepo;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = CacheRepo;
10 changes: 10 additions & 0 deletions lib/CacheThread.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface ICacheThread {
current: number;
nodes: Array<number>;
addNode: (nodeId: number) => void;
}
export default class CacheThread implements ICacheThread {
current: number;
nodes: Array<number>;
addNode: (nodeId: number) => void;
}
15 changes: 15 additions & 0 deletions lib/CacheThread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";
var CacheThread = (function () {
function CacheThread() {
var _this = this;
this.current = -1;
this.nodes = [];
this.addNode = function (nodeId) {
_this.nodes.push(nodeId);
_this.current++;
};
}
return CacheThread;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = CacheThread;
21 changes: 21 additions & 0 deletions lib/cache.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ICacheStats } from './interfaces';
export declare let instances: any;
export declare let config: any;
export declare function setTesting(testing: boolean): void;
export interface ICache {
put: Function;
get: Function;
getEdit: Function;
evict: Function;
reset: Function;
size: Function;
length: Function;
print: Function;
}
export declare function getCache(instanceName?: string, configuration?: {}): ICache;
export declare const put: (item: {} | {}[]) => void;
export declare const get: (entity: string | number | any[] | {}, nodeId?: number) => any;
export declare const getEdit: (uidOrEntityOrArray: string | number | any[] | {}, nodeId?: number) => any;
export declare const evict: (uidOrEntityOrArray: string | number | any[] | {}) => ICacheStats;
export declare const print: () => string;
export declare const reset: () => void;
99 changes: 99 additions & 0 deletions lib/cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"use strict";
var config_1 = require("./config");
var put_1 = require("./put");
var print_1 = require("./print");
var CacheInstance_1 = require("./CacheInstance");
var util_1 = require("./util");
var get_1 = require("./get");
var evict_1 = require("./evict");
var cacheTest = false;
function setTesting(testing) {
cacheTest = testing;
}
exports.setTesting = setTesting;
function getCache(instanceName, configuration) {
if (instanceName === void 0) { instanceName = "one"; }
if (configuration === void 0) { configuration = config_1.defaultConfig; }
if (!exports.config && !exports.instances) {
exports.config = config_1.configure(configuration);
}
if (!exports.instances) {
exports.instances = {};
}
if (!exports.instances[instanceName]) {
exports.instances[instanceName] = createCache(instanceName);
}
if (window) {
if (window[instanceName] === undefined) {
window[instanceName] = exports.instances[instanceName];
}
}
return exports.instances[instanceName];
}
exports.getCache = getCache;
exports.put = function (item) {
getCache().put(item);
};
exports.get = function (entity, nodeId) {
return getCache().get(entity, nodeId);
};
exports.getEdit = function (uidOrEntityOrArray, nodeId) {
return getCache().getEdit(uidOrEntityOrArray, nodeId);
};
exports.evict = function (uidOrEntityOrArray) {
return getCache().evict(uidOrEntityOrArray);
};
exports.print = function () {
return getCache().print();
};
exports.reset = function () {
getCache().reset();
};
function createCache(name) {
var instance = new CacheInstance_1.default(name);
var reset = function () {
instance.reset();
};
var put = function (item) {
return put_1.putItem(item, instance);
};
var get = function (entity, nodeId) {
return get_1.getItem(entity, instance, nodeId);
};
var getEdit = function (uidOrEntityOrArray, nodeId) {
return get_1.getEditItem(uidOrEntityOrArray, instance, nodeId);
};
var evict = function (uidOrEntityOrArray) {
return evict_1.evictItem(uidOrEntityOrArray, instance);
};
var size = function () {
return util_1.cacheSize(instance);
};
var length = function () {
return util_1.cacheLength(instance);
};
var print = function () {
return print_1.printCache(instance);
};
var result = {
put: put,
get: get,
getEdit: getEdit,
evict: evict,
reset: reset,
size: size,
length: length,
print: print,
};
if (cacheTest === true) {
result.refTo = function (uid) {
var item = get_1.getCachedItem(uid, instance);
return item.mapTo;
};
result.refFrom = function (uid) {
var item = get_1.getCachedItem(uid, instance);
return item.mapFrom;
};
}
return result;
}
8 changes: 8 additions & 0 deletions lib/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export declare const defaultConfig: {
uidName: string;
maxHistoryStates: number;
};
export declare function configure(conf: any): {
uidName: string;
maxHistoryStates: number;
};
Loading

0 comments on commit d907a8a

Please sign in to comment.