Reorganized repo using yarn and workspaces

This commit is contained in:
maciejhirsz
2018-06-27 14:04:34 +02:00
parent 8c3b1ee749
commit 0580e25380
84 changed files with 8434 additions and 701 deletions
+26
View File
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Higher order function producing new auto-incremented `Id`s.
*/
function idGenerator() {
let current = 0;
return () => current++;
}
exports.idGenerator = idGenerator;
class IdSet {
constructor() {
this.map = new Map();
}
add(item) {
this.map.set(item.id, item);
}
remove(item) {
this.map.delete(item.id);
}
get entries() {
return this.map.values();
}
}
exports.IdSet = IdSet;
//# sourceMappingURL=id.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"id.js","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":";;AAOA;;GAEG;AACH;IACI,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,OAAO,GAAG,EAAE,CAAC,OAAO,EAAW,CAAC;AACpC,CAAC;AAJD,kCAIC;AAMD;IAAA;QACY,QAAG,GAAkB,IAAI,GAAG,EAAE,CAAC;IAa3C,CAAC;IAXU,GAAG,CAAC,IAAkB;QACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAEM,MAAM,CAAC,IAAkB;QAC5B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;CACJ;AAdD,sBAcC"}
+9
View File
@@ -0,0 +1,9 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./id"));
__export(require("./iterators"));
__export(require("./types"));
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,0BAAqB;AACrB,iCAA4B;AAC5B,6BAAwB"}
+57
View File
@@ -0,0 +1,57 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function* map(iter, fn) {
for (const item of iter) {
yield fn(item);
}
}
exports.map = map;
function* chain(a, b) {
yield* a;
yield* b;
}
exports.chain = chain;
function* zip(a, b) {
let itemA = a.next();
let itemB = b.next();
while (!itemA.done && !itemB.done) {
yield [itemA.value, itemB.value];
itemA = a.next();
itemB = b.next();
}
}
exports.zip = zip;
function* take(iter, n) {
for (const item of iter) {
if (n-- === 0) {
return;
}
yield item;
}
}
exports.take = take;
function skip(iter, n) {
while (n-- !== 0 && !iter.next().done) { }
return iter;
}
exports.skip = skip;
function reduce(iter, fn, accumulator) {
for (const item of iter) {
accumulator = fn(accumulator, item);
}
return accumulator;
}
exports.reduce = reduce;
function join(iter, glue) {
const first = iter.next();
if (first.done) {
return '';
}
let result = first.value.toString();
for (const item of iter) {
result += glue + item;
}
return result;
}
exports.join = join;
//# sourceMappingURL=iterators.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"iterators.js","sourceRoot":"","sources":["../src/iterators.ts"],"names":[],"mappings":";;AAAA,QAAe,CAAC,KAAW,IAAyB,EAAE,EAAkB;IACpE,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;QACrB,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;KAClB;AACL,CAAC;AAJD,kBAIC;AAED,QAAe,CAAC,OAAU,CAAsB,EAAE,CAAsB;IACpE,KAAK,CAAC,CAAC,CAAC,CAAC;IACT,KAAK,CAAC,CAAC,CAAC,CAAC;AACb,CAAC;AAHD,sBAGC;AAED,QAAe,CAAC,KAAW,CAAsB,EAAE,CAAsB;IACrE,IAAI,KAAK,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACrB,IAAI,KAAK,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAErB,OAAO,C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Property(exports, "__esModule", { value: true });
/**
* PhantomData akin to Rust, because sometimes you need to be smarter than
* the compiler.
*/
class PhantomData {
}
exports.PhantomData = PhantomData;
//# sourceMappingURL=types.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AAAA;;;GAGG;AACH;CAAsD;AAAtD,kCAAsD"}
+15
View File
@@ -0,0 +1,15 @@
{
"name": "@dotstats/common",
"version": "0.1.0",
"author": "Parity Technologies Ltd. <admin@parity.io>",
"license": "GPL-3.0",
"description": "Shared utils and types for backend and frontend",
"main": "build/index.js",
"types": "src/index.ts",
"engines": {
"node": ">=9.5"
},
"scripts": {
"test": "echo \"Tests only available from root wrapper\""
}
}
+35
View File
@@ -0,0 +1,35 @@
import { Opaque } from './types';
/**
* Unique type-constrained Id number.
*/
export type Id<T> = Opaque<number, T>;
/**
* Higher order function producing new auto-incremented `Id`s.
*/
export function idGenerator<T>(): () => Id<T> {
let current = 0;
return () => current++ as Id<T>;
}
interface HasId<T> {
id: Id<T>;
}
export class IdSet<T> {
private map: Map<Id<T>, T> = new Map();
public add(item: T & HasId<T>) {
this.map.set(item.id, item);
}
public remove(item: T & HasId<T>) {
this.map.delete(item.id);
}
public get entries(): IterableIterator<T> {
return this.map.values();
}
}
+3
View File
@@ -0,0 +1,3 @@
export * from './id';
export * from './iterators';
export * from './types';
+62
View File
@@ -0,0 +1,62 @@
export function* map<T, U>(iter: IterableIterator<T>, fn: (item: T) => U): IterableIterator<U> {
for (const item of iter) {
yield fn(item);
}
}
export function* chain<T>(a: IterableIterator<T>, b: IterableIterator<T>): IterableIterator<T> {
yield* a;
yield* b;
}
export function* zip<T, U>(a: IterableIterator<T>, b: IterableIterator<U>): IterableIterator<[T, U]> {
let itemA = a.next();
let itemB = b.next();
while (!itemA.done && !itemB.done) {
yield [itemA.value, itemB.value];
itemA = a.next();
itemB = b.next();
}
}
export function* take<T>(iter: IterableIterator<T>, n: number): IterableIterator<T> {
for (const item of iter) {
if (n-- === 0) {
return;
}
yield item;
}
}
export function skip<T>(iter: IterableIterator<T>, n: number): IterableIterator<T> {
while (n-- !== 0 && !iter.next().done) {}
return iter;
}
export function reduce<T, R>(iter: IterableIterator<T>, fn: (accu: R, item: T) => R, accumulator: R): R {
for (const item of iter) {
accumulator = fn(accumulator, item);
}
return accumulator;
}
export function join(iter: IterableIterator<{ toString: () => string }>, glue: string): string {
const first = iter.next();
if (first.done) {
return '';
}
let result = first.value.toString();
for (const item of iter) {
result += glue + item;
}
return result;
}
+22
View File
@@ -0,0 +1,22 @@
/**
* PhantomData akin to Rust, because sometimes you need to be smarter than
* the compiler.
*/
export class PhantomData<P> { private __PHANTOM__: P }
/**
* Opaque type, similar to `opaque type` in Flow, or new types in Rust/C.
* These should be produced only by manually casting `t as Opaque<T, P>`.
*
* `P` can be anything as it's never actually used. Using strings is okay:
*
* ```
* type MyType = Opaque<number, 'MyType'>;
* ```
*/
export type Opaque<T, P> = T & PhantomData<P>;
/**
* Just a readable shorthand for null-ish-able types, akin to `T?` in Flow.
*/
export type Maybe<T> = T | null | undefined;
+9
View File
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "build",
},
"include": [
"src/**/*.ts"
],
}