diff --git a/package-lock.json b/package-lock.json index 9fb3fd3..33c016a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2404,6 +2404,12 @@ "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", "dev": true }, + "compare-versions": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-2.0.1.tgz", + "integrity": "sha1-Htwfk2h/2XoyXFn1XkWgfbEGrKY=", + "dev": true + }, "component-emitter": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz", @@ -3312,6 +3318,12 @@ "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", "dev": true }, + "estree-walker": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.2.1.tgz", + "integrity": "sha1-va/oCVOD2EFNXcLs9MkXO225QS4=", + "dev": true + }, "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", @@ -10148,6 +10160,70 @@ "inherits": "2.0.3" } }, + "rollup-plugin-typescript": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-typescript/-/rollup-plugin-typescript-0.8.1.tgz", + "integrity": "sha1-L/fuzCHPa7K0P8J+W2iJUs5xkko=", + "dev": true, + "requires": { + "compare-versions": "2.0.1", + "object-assign": "4.1.1", + "rollup-pluginutils": "1.5.2", + "tippex": "2.3.1", + "typescript": "1.8.10" + }, + "dependencies": { + "typescript": { + "version": "1.8.10", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-1.8.10.tgz", + "integrity": "sha1-tHXW4N/wv1DyluXKbvn7tccyDx4=", + "dev": true + } + } + }, + "rollup-plugin-uglify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-uglify/-/rollup-plugin-uglify-3.0.0.tgz", + "integrity": "sha512-dehLu9eRRoV4l09aC+ySntRw1OAfoyKdbk8Nelblj03tHoynkSybqyEpgavemi1LBOH6S1vzI58/mpxkZIe1iQ==", + "dev": true, + "requires": { + "uglify-es": "3.3.9" + }, + "dependencies": { + "commander": { + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz", + "integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==", + "dev": true + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "uglify-es": { + "version": "3.3.9", + "resolved": "https://registry.npmjs.org/uglify-es/-/uglify-es-3.3.9.tgz", + "integrity": "sha512-r+MU0rfv4L/0eeW3xZrd16t4NZfK8Ld4SWVglYBb7ez5uXFWHuVRs6xCTrf1yirs9a4j4Y27nn7SRfO6v67XsQ==", + "dev": true, + "requires": { + "commander": "2.13.0", + "source-map": "0.6.1" + } + } + } + }, + "rollup-pluginutils": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz", + "integrity": "sha1-HhVud4+UtyVb+hs9AXi+j1xVJAg=", + "dev": true, + "requires": { + "estree-walker": "0.2.1", + "minimatch": "3.0.4" + } + }, "run-async": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", @@ -11073,6 +11149,12 @@ "setimmediate": "1.0.5" } }, + "tippex": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tippex/-/tippex-2.3.1.tgz", + "integrity": "sha1-ov1bcIfXy/sgyYBqbBYQjCwPr9o=", + "dev": true + }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", diff --git a/package.json b/package.json index 26e026f..80596d9 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,8 @@ "gulp": "^3.9.1", "html-webpack-plugin": "^3.2.0", "mocha": "^5.1.1", + "rollup-plugin-typescript": "^0.8.1", + "rollup-plugin-uglify": "^3.0.0", "ts-node": "^6.0.0", "typedoc": "^0.11.1", "typescript": "^2.8.1", diff --git a/release/linq-fns.ru.js b/release/linq-fns.ru.js new file mode 100644 index 0000000..8c1d334 --- /dev/null +++ b/release/linq-fns.ru.js @@ -0,0 +1 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require(".")):"function"==typeof define&&define.amd?define(["."],e):e(t._)}(this,function(t){"use strict";class e{replaceBySyncSource(t){this.nextSource=t}hasSource(){return null!==this.nextSource&&void 0!==this.nextSource}execute(t){throw new Error("Method not implemented.")}}class r{static isPromise(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}static distinct(t){return t.filter((t,e,r)=>r.indexOf(t)===e).filter(t=>void 0!=t)}static getSingle(t){if(t.length>1)throw new Error("The collection does not contain exactly one element");if(1===t.length)return t[0]}static compare(t,e){if(t===e)return!0;const r=Array.isArray(t),s=Array.isArray(e);if(r&&s){if(t.length!==e.length)return!1;for(let r=0,s=t.length;rthis._iterator(t))}}class i extends e{constructor(t){super(),this._iterator=t}execute(t){return t?t.map(t=>this._iterator(t)):t}}class n extends e{constructor(t){super(),this._iterator=t}execute(t){if(!t)return 0;let e=this._iterator?new i(this._iterator).execute(t):t;if(!e)return 0;if(Number.isNaN(e[0]))throw new Error("Avarage operator need type of number");return e.reduce((t,e)=>t+e,0)/e.length}}class o extends e{constructor(t){super(),this._entity=t}execute(t){if(!t)return!1;let e=!1;for(let s=0,i=t.length;sthis._iterator(t)).length||0:t.length:0}}class c extends e{constructor(t){super(),this._iterator=t}execute(t){return this._iterator?t.filter(t=>this._iterator(t))[0]:t[0]}}class l extends e{constructor(t){super(),this._iterator=t}execute(t){if(!t)return null;let e={},s=[],n={},o=r.distinct(new i(this._iterator).execute(t));return t.forEach((t,r)=>{e[r]=t}),s=t.map((t,e)=>({value:this._iterator(t),index:e})).filter(t=>void 0!=t.value),o.forEach(t=>{n[t]=[]}),n?(s.forEach(t=>{n[t.value].push(e[t.index])}),Object.keys(n).map(t=>({key:t,items:n[t]}))):null}}class h extends e{constructor(t,e){super(),this._iterator=e,this.nextSource=t}execute(t){if(t){let e=[];for(let r=0,s=t.length;rthis._iterator(t))[t.length-1]:t[t.length-1]:null}}class f extends e{constructor(t,e){super(),this._iterator=e,this.nextSource=t}execute(t){if(t){let e=[];for(let r=0,s=t.length;r{e[r]=t});let r=t.map((t,e)=>({value:this._iterator(t),index:e}));return r?(r.sort((t,e)=>t.valuee.value?1:0),r.map(t=>e[t.index])):null}}class d extends e{constructor(t){super(),this._iterator=t}execute(t){if(!t)return null;return new w(this._iterator).execute(t).reverse()}}class g extends e{constructor(t){super(),this._iterator=t}execute(t){if(!t)return null;let e=new i(this._iterator).execute(t);if(!e)return null;let r=[];for(let t=0,s=e.length;tthis._iterator(t)):t}}class S extends e{constructor(t){super(),this._iterator=t}execute(t){let e=t;return this._iterator&&(e=new m(this._iterator).execute(e)),r.getSingle(e)}}class y extends e{constructor(t){super(),this._iterator=t}execute(t){return t?t.slice(this._iterator):t}}class C extends e{constructor(t){super(),this._iterator=t}execute(t){if(t){let e=0;for(let r=0;rt+e,0)}}class v extends e{constructor(t){super(),this._iterator=t}execute(t){return t?t.slice(0,this._iterator):t}}class L extends e{constructor(t){super(),this._iterator=t}execute(t){if(t){let e=0;for(let r=0;rthis._iterator(t))}}class E extends e{constructor(t){super(),this.nextSource=t}execute(t){return t.concat(this.nextSource)}}class j extends e{constructor(t){super(),this._comparer=t}execute(t){if(!this._comparer)return r.distinct(t)}}class k extends e{constructor(t){super(),this.nextSource=t}execute(e){let r=e.concat(this.nextSource);return(new t.DistinctClause).execute(r)}}class N extends e{constructor(t){super(),this.nextSource=t}execute(e){let s=[];for(let t=0,i=e.length;tr?r:e;return t.map((t,e)=>{if(!(e>s-1))return this._iterator?this._iterator(t,this.nextSource[e]):[t,this.nextSource[e]]}).filter(t=>void 0!==t)}}class I extends e{constructor(t){super(),this._iterator=t}execute(t){return t.reduce((t,e,r)=>this._iterator(t,e,r))}}class q{constructor(t,e){this._iteratorCollection=[],this._iteratorCollection=t,this._source=e}clone(){const t=Object.assign([],this._iteratorCollection);return new q(t,this._source)}where(t){return this._iteratorCollection.push(new m(t)),this}select(t){return this._iteratorCollection.push(new i(t)),this}selectMany(t){return this._iteratorCollection.push(new g(t)),this}join(t,e){return this._iteratorCollection.push(new h(t,e)),this}leftJoin(t,e){return this._iteratorCollection.push(new f(t,e)),this}orderBy(t){return this._iteratorCollection.push(new w(t)),this}orderByDescending(t){return this._iteratorCollection.push(new d(t)),this}groupBy(t){return this._iteratorCollection.push(new l(t)),this}groupJoin(t,e,r){return this._iteratorCollection.push(new a(t,e,r)),this}distinct(t){return this._iteratorCollection.push(new j(t)),this}concat(t){return this._iteratorCollection.push(new E(t)),this}union(t){return this._iteratorCollection.push(new k(t)),this}zip(t,e){return this._iteratorCollection.push(new A(t,e)),this}except(t){return this._iteratorCollection.push(new P(t)),this}intersect(t){return this._iteratorCollection.push(new N(t)),this}toList(){return this.runIterators()}first(t){return this.filterReturn(this.toList(),e=>new c(t).execute(e))}firstOrDefault(t){return this.filterReturn(this.toList(),e=>new c(t).execute(e)||null)}last(t){return this.filterReturn(this.toList(),e=>new x(t).execute(e))}lastOrDefault(t){return this.filterReturn(this.toList(),e=>new x(t).execute(e)||null)}count(t){return this.filterReturn(this.toList(),e=>new u(t).execute(e)||null)}sum(t){return this.filterReturn(this.toList(),e=>new b(t).execute(e)||null)}avarage(t){return this.filterReturn(this.toList(),e=>new n(t).execute(e)||0)}min(t){return this.filterReturn(this.toList(),e=>new _(t).execute(e)||null)}max(t){return this.filterReturn(this.toList(),e=>new p(t).execute(e)||null)}single(t){return this.filterReturn(this.toList(),e=>{if(!e)throw new Error("Single require source is not null");return new S(t).execute(e)})}singleOrDefault(t){return this.filterReturn(this.toList(),e=>new S(t).execute(e)||null)}take(t){return this._iteratorCollection.push(new v(t)),this}skip(t){return this._iteratorCollection.push(new y(t)),this}skipWhile(t){return this._iteratorCollection.push(new C(t)),this}takeWhile(t){return this._iteratorCollection.push(new L(t)),this}any(t){return this.filterReturn(this.toList(),e=>new s(t).execute(e))}all(t){return this.filterReturn(this.toList(),e=>new R(t).execute(e))}contains(t){return this.filterReturn(this.toList(),e=>new o(t).execute(e))}sequencyEqual(t){return this.filterReturn(this.toList(),e=>r.isPromise(t)?t.then(t=>new O(t).execute(e)):new O(t).execute(e))}aggregate(t){return this.filterReturn(this.toList(),e=>new I(t).execute(e))}filterReturn(t,e){return r.isPromise(t)?t.then(t=>e(t)):e(t)}runIterators(){let t=[],e=[];for(let t=0,s=this._iteratorCollection.length;t{let r=0;t=e[0];for(let t=0,s=this._iteratorCollection.length;t{t=e.execute(t)}),t})}}class D extends q{runIterators(){let t=Object.assign([],this._source);return this._iteratorCollection.forEach(e=>{t=e.execute(t)}),t}}window.Queryable=class{static from(t){return new q([],t)}static fromSync(t){return new D([],t)}}}); diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..d782f73 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,14 @@ +import uglify from 'rollup-plugin-uglify'; +import typescript from 'rollup-plugin-typescript'; + +export default { + input: 'dist/index.browser.js', + output: { + file: 'release/linq-fns.ru.js', + format: 'umd' + }, + plugins: [ + // typescript(), + uglify() + ] +}; \ No newline at end of file diff --git a/src/browser/linq-fns.ts b/src/browser/linq-fns.ts index 845a817..3f74a42 100644 --- a/src/browser/linq-fns.ts +++ b/src/browser/linq-fns.ts @@ -1,3 +1,3 @@ -import { Queryable } from "../implements"; +import { Queryable } from '../implements/index'; window['Queryable'] = Queryable \ No newline at end of file diff --git a/src/demo/index.ts b/src/demo/index.ts index b2ca8b2..1aeab99 100644 --- a/src/demo/index.ts +++ b/src/demo/index.ts @@ -1,4 +1,4 @@ -import { Queryable } from '../implements'; +import { Queryable } from '../implements/index'; import { precompile } from 'handlebars'; const cTable = require('console.table'); diff --git a/src/implements/baseIterator.ts b/src/implements/baseIterator.ts index 6d1cc38..73a8de5 100644 --- a/src/implements/baseIterator.ts +++ b/src/implements/baseIterator.ts @@ -3,7 +3,7 @@ import { IIterator } from "../intefaces/iterator.interface"; export class BaseIterator implements IIterator { nextSource: any[] | Promise; - replaceBySyncSource?(syncSource: T[]) { + replaceBySyncSource(syncSource: T[]) { this.nextSource = syncSource; } diff --git a/src/implements/methods.ts b/src/implements/methods.ts index e5685c8..7e87d61 100644 --- a/src/implements/methods.ts +++ b/src/implements/methods.ts @@ -1,12 +1,12 @@ -import { IMethods, IIterator } from "../intefaces"; -import { Utils } from '../utils'; +import { IMethods, IIterator } from "../intefaces/index"; +import { Utils } from '../utils/index'; import { WhereClause, SelectClause, SelectManyClause, JoinClause, LeftJoinClause, OrderByClause, OrderByDescendingClause, GroupByClause, GroupJoinClause, FirstClause, LastClause, CountClause, SumClause, AvarageClause, MinClause, MaxClause, SingleClause, TakeClause, SkipWhileClause, SkipClause, TakeWhileClause, AnyClause, ContainsClause, AllClause, DistinctClause, ConcatClause, UnionClause, ZipClause, ExceptClause, IntersectClasue, SequenceEqualClause, AggregateClause, -} from "../methods"; +} from "../methods/index"; import { Queryable } from './queryable'; export class IteratorMethods implements IMethods { diff --git a/src/index.browser.ts b/src/index.browser.ts new file mode 100644 index 0000000..a098ada --- /dev/null +++ b/src/index.browser.ts @@ -0,0 +1,3 @@ +import { Queryable } from "./implements/queryable"; + +window['Queryable'] = Queryable; \ No newline at end of file diff --git a/src/methods/aggregate.ts b/src/methods/aggregate.ts index ea4c9ed..bb37754 100644 --- a/src/methods/aggregate.ts +++ b/src/methods/aggregate.ts @@ -1,4 +1,4 @@ -import { BaseIterator } from '../implements'; +import { BaseIterator } from '../implements/index'; import { IIterator } from '../intefaces'; export class AggregateClause extends BaseIterator implements IIterator{ diff --git a/src/methods/concat.ts b/src/methods/concat.ts index 25bd111..fb1eab0 100644 --- a/src/methods/concat.ts +++ b/src/methods/concat.ts @@ -1,4 +1,4 @@ -import { BaseIterator } from '../implements'; +import { BaseIterator } from '../implements/index'; import { IIterator } from '../intefaces'; export class ConcatClause extends BaseIterator implements IIterator{ diff --git a/src/methods/contains.ts b/src/methods/contains.ts index 59ff691..f51251b 100644 --- a/src/methods/contains.ts +++ b/src/methods/contains.ts @@ -1,6 +1,6 @@ import { IIterator } from "../intefaces/iterator.interface"; import { BaseIterator } from "../implements/baseIterator"; -import { Utils } from '../utils'; +import { Utils } from '../utils/index'; export class ContainsClause extends BaseIterator implements IIterator { diff --git a/src/methods/distinct.ts b/src/methods/distinct.ts index 27f66c6..30cc225 100644 --- a/src/methods/distinct.ts +++ b/src/methods/distinct.ts @@ -1,6 +1,6 @@ import { IIterator } from '../intefaces'; -import { BaseIterator } from '../implements'; -import { Utils } from '../utils'; +import { BaseIterator } from '../implements/index'; +import { Utils } from '../utils/index'; export class DistinctClause extends BaseIterator implements IIterator { _comparer: (aEntity: T, bEntity: T) => boolean; diff --git a/src/methods/except.ts b/src/methods/except.ts index 19e02bb..73c2ae7 100644 --- a/src/methods/except.ts +++ b/src/methods/except.ts @@ -1,6 +1,6 @@ -import { BaseIterator } from '../implements'; +import { BaseIterator } from '../implements/index'; import { IIterator } from '../intefaces'; -import { Utils } from '../utils'; +import { Utils } from '../utils/index'; import { SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION } from 'constants'; export class ExceptClause extends BaseIterator implements IIterator{ diff --git a/src/methods/groupBy.ts b/src/methods/groupBy.ts index e3c9d71..dd40b28 100644 --- a/src/methods/groupBy.ts +++ b/src/methods/groupBy.ts @@ -1,7 +1,7 @@ import { IIterator } from "../intefaces/iterator.interface"; import { SelectClause } from "./select"; import { BaseIterator } from "../implements/baseIterator"; -import { Utils } from '../utils'; +import { Utils } from '../utils/index'; export class GroupByClause extends BaseIterator implements IIterator { diff --git a/src/methods/intersect.ts b/src/methods/intersect.ts index fffbd2c..0bc0f92 100644 --- a/src/methods/intersect.ts +++ b/src/methods/intersect.ts @@ -1,6 +1,6 @@ -import { BaseIterator } from '../implements'; +import { BaseIterator } from '../implements/index'; import { IIterator } from '../intefaces'; -import { Utils } from '../utils'; +import { Utils } from '../utils/index'; import { DistinctClause } from '.'; export class IntersectClasue extends BaseIterator implements IIterator{ diff --git a/src/methods/orderBy.ts b/src/methods/orderBy.ts index 32ce19e..0a74d62 100644 --- a/src/methods/orderBy.ts +++ b/src/methods/orderBy.ts @@ -44,4 +44,4 @@ export class OrderByClause extends BaseIterator implements IIterator { super(); this._iterator = func; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/methods/sequenceEqual.ts b/src/methods/sequenceEqual.ts index 565782d..1b4377a 100644 --- a/src/methods/sequenceEqual.ts +++ b/src/methods/sequenceEqual.ts @@ -1,6 +1,6 @@ -import { BaseIterator } from '../implements'; +import { BaseIterator } from '../implements/index'; import { IIterator } from '../intefaces'; -import { Utils } from '../utils'; +import { Utils } from '../utils/index'; export class SequenceEqualClause extends BaseIterator implements IIterator{ nextSource; diff --git a/src/methods/single.ts b/src/methods/single.ts index 6041446..f31f62c 100644 --- a/src/methods/single.ts +++ b/src/methods/single.ts @@ -1,7 +1,7 @@ import { IIterator } from "../intefaces/iterator.interface"; import { WhereClause } from "./where"; import { BaseIterator } from "../implements/baseIterator"; -import { Utils } from '../utils'; +import { Utils } from '../utils/index'; export class SingleClause extends BaseIterator implements IIterator { diff --git a/src/methods/union.ts b/src/methods/union.ts index 84735a8..2fdf2f1 100644 --- a/src/methods/union.ts +++ b/src/methods/union.ts @@ -1,4 +1,4 @@ -import { BaseIterator } from '../implements'; +import { BaseIterator } from '../implements/index'; import { IIterator } from '../intefaces'; import { DistinctClause } from '.'; diff --git a/src/methods/zip.ts b/src/methods/zip.ts index 9743144..2b986d4 100644 --- a/src/methods/zip.ts +++ b/src/methods/zip.ts @@ -1,4 +1,4 @@ -import { BaseIterator } from '../implements'; +import { BaseIterator } from '../implements/index'; import { IIterator } from '../intefaces'; export class ZipClause extends BaseIterator implements IIterator{ diff --git a/tsconfig.json b/tsconfig.json index 93ca402..de53944 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "es6", "importHelpers": true, "sourceMap": true, "outDir": "./dist", @@ -23,7 +23,7 @@ ] }, "baseUrl": "./", - "declaration": true, + // "declaration": true, }, "exclude": [ "demo",