Comparing version 7.1.0 to 8.0.0
@@ -120,11 +120,11 @@ "use strict"; | ||
let actualNews = (yield api.search({ | ||
filter: (0, filters_1.text)(["one"], { onlyBody: true }) | ||
filter: filters_1.Text.any(["one"], { onlyBody: true }) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(1); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.text)(["1"], { onlyBody: true }) | ||
filter: filters_1.Text.any(["1"], { onlyBody: true }) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(0); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.text)(["1 two"], { onlyBody: true }) | ||
filter: filters_1.Text.any(["1 two"], { onlyBody: true }) | ||
})).data; | ||
@@ -136,11 +136,11 @@ (0, chai_1.expect)(actualNews.length).to.eq(0); | ||
let actualNews = (yield api.search({ | ||
filter: (0, filters_1.text)(["one"], { onlyHeadline: true }) | ||
filter: filters_1.Text.any(["one"], { onlyHeadline: true }) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(0); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.text)(["one 2"], { onlyHeadline: true }) | ||
filter: filters_1.Text.any(["one 2"], { onlyHeadline: true }) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(0); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.text)(["1"], { onlyHeadline: true }) | ||
filter: filters_1.Text.any(["1"], { onlyHeadline: true }) | ||
})).data; | ||
@@ -152,15 +152,15 @@ (0, chai_1.expect)(actualNews.length).to.eq(1); | ||
let actualNews = (yield api.search({ | ||
filter: (0, filters_1.categoryCodes)(enums_1.FilterAction.ANY, ["categoryCode1", "categoryCode2"]) | ||
filter: filters_1.CategoryCodes.any(["categoryCode1", "categoryCode2"]) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(2); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.categoryCodes)(enums_1.FilterAction.ALL, ["categoryCode1", "categoryCode2"]) | ||
filter: filters_1.CategoryCodes.all(["categoryCode1", "categoryCode2"]) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(0); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.categoryCodes)(enums_1.FilterAction.ALL, ["categoryCode1", "categoryCode11"]) | ||
filter: filters_1.CategoryCodes.all(["categoryCode1", "categoryCode11"]) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(1); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.categoryCodes)(enums_1.FilterAction.EXCLUDE, ["categoryCode1", "categoryCode2"]) | ||
filter: filters_1.CategoryCodes.exclude(["categoryCode1", "categoryCode2"]) | ||
})).data; | ||
@@ -172,15 +172,15 @@ (0, chai_1.expect)(actualNews.length).to.eq(4); | ||
let actualNews = (yield api.search({ | ||
filter: (0, filters_1.tickers)(enums_1.FilterAction.ANY, ["ticker1", "ticker2"]) | ||
filter: filters_1.Tickers.any(["ticker1", "ticker2"]) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(2); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.tickers)(enums_1.FilterAction.ALL, ["ticker1", "ticker2"]) | ||
filter: filters_1.Tickers.all(["ticker1", "ticker2"]) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(0); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.tickers)(enums_1.FilterAction.ALL, ["ticker1", "ticker11"]) | ||
filter: filters_1.Tickers.all(["ticker1", "ticker11"]) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(1); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.tickers)(enums_1.FilterAction.EXCLUDE, ["ticker1", "ticker2"]) | ||
filter: filters_1.Tickers.exclude(["ticker1", "ticker2"]) | ||
})).data; | ||
@@ -192,15 +192,15 @@ (0, chai_1.expect)(actualNews.length).to.eq(4); | ||
let actualNews = (yield api.search({ | ||
filter: (0, filters_1.ciks)(enums_1.FilterAction.ANY, [1, 2]) | ||
filter: filters_1.Ciks.any([1, 2]) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(2); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.ciks)(enums_1.FilterAction.ALL, [1, 2]) | ||
filter: filters_1.Ciks.all([1, 2]) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(0); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.ciks)(enums_1.FilterAction.ALL, [1, 11]) | ||
filter: filters_1.Ciks.all([1, 11]) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(1); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.ciks)(enums_1.FilterAction.EXCLUDE, [1, 2]) | ||
filter: filters_1.Ciks.exclude([1, 2]) | ||
})).data; | ||
@@ -212,7 +212,7 @@ (0, chai_1.expect)(actualNews.length).to.eq(4); | ||
let actualNews = (yield api.search({ | ||
filter: (0, filters_1.source)(enums_1.FilterAction.ANY, ["source1", "source2"]) | ||
filter: filters_1.Sources.any(["source1", "source2"]) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(2); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.source)(enums_1.FilterAction.EXCLUDE, ["source1", "source2"]) | ||
filter: filters_1.Sources.exclude(["source1", "source2"]) | ||
})).data; | ||
@@ -224,7 +224,7 @@ (0, chai_1.expect)(actualNews.length).to.eq(4); | ||
let actualNews = (yield api.search({ | ||
filter: (0, filters_1.and)((0, filters_1.text)(["1"]), (0, filters_1.ciks)(enums_1.FilterAction.ANY, [1])) | ||
filter: (0, filters_1.And)(filters_1.Text.any(["1"]), filters_1.Ciks.any([1])) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(1); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.and)((0, filters_1.text)(["2"]), (0, filters_1.ciks)(enums_1.FilterAction.ANY, [1])) | ||
filter: (0, filters_1.And)(filters_1.Text.any(["2"]), filters_1.Ciks.any([1])) | ||
})).data; | ||
@@ -236,7 +236,7 @@ (0, chai_1.expect)(actualNews.length).to.eq(0); | ||
let actualNews = (yield api.search({ | ||
filter: (0, filters_1.or)((0, filters_1.text)(["1"]), (0, filters_1.ciks)(enums_1.FilterAction.ANY, [2])) | ||
filter: (0, filters_1.Or)(filters_1.Text.any(["1"]), filters_1.Ciks.any([2])) | ||
})).data; | ||
(0, chai_1.expect)(actualNews.length).to.eq(2); | ||
actualNews = (yield api.search({ | ||
filter: (0, filters_1.or)((0, filters_1.text)(["2"]), (0, filters_1.ciks)(enums_1.FilterAction.ANY, [1]), (0, filters_1.tickers)(enums_1.FilterAction.ANY, ["ticker3"])) | ||
filter: (0, filters_1.Or)(filters_1.Text.any(["2"]), filters_1.Ciks.any([1]), filters_1.Tickers.any(["ticker3"])) | ||
})).data; | ||
@@ -243,0 +243,0 @@ (0, chai_1.expect)(actualNews.length).to.eq(3); |
@@ -1,9 +0,41 @@ | ||
import { Filter, FilterArray, TextOptions } from "./types"; | ||
import { FilterAction } from "./enums"; | ||
export declare const and: (...queries: Filter[]) => Filter; | ||
export declare const or: (...queries: Filter[]) => Filter; | ||
export declare const text: (value: string[], options?: TextOptions) => Filter; | ||
export declare const tickers: (action: FilterAction, value: string[]) => FilterArray; | ||
export declare const ciks: (action: FilterAction, value: number[]) => FilterArray; | ||
export declare const categoryCodes: (action: FilterAction, value: string[]) => FilterArray; | ||
export declare const source: (action: FilterAction.ANY | FilterAction.EXCLUDE, value: string[]) => FilterArray; | ||
import { Filter, FilterArray, FilterText, TextOptions } from "./types"; | ||
import { FilterAction, FilterType } from "./enums"; | ||
export declare class Text { | ||
constructor(); | ||
static any(value: string[] | string, options?: TextOptions): FilterText; | ||
static all(value: string[] | string, options?: TextOptions): { | ||
onlyBody?: boolean | undefined; | ||
onlyHeadline?: boolean | undefined; | ||
type: FilterType; | ||
action: FilterAction; | ||
value: string[]; | ||
}; | ||
static exclude(value: string[] | string, options?: TextOptions): { | ||
onlyBody?: boolean | undefined; | ||
onlyHeadline?: boolean | undefined; | ||
type: FilterType; | ||
action: FilterAction; | ||
value: string[]; | ||
}; | ||
} | ||
export declare class Tickers { | ||
static any(value: string | string[]): FilterArray; | ||
static all(value: string | string[]): FilterArray; | ||
static exclude(value: string | string[]): FilterArray; | ||
} | ||
export declare class Ciks { | ||
static any(value: number | number[]): FilterArray; | ||
static all(value: number | number[]): FilterArray; | ||
static exclude(value: number | number[]): FilterArray; | ||
} | ||
export declare class CategoryCodes { | ||
static any(value: string | string[]): FilterArray; | ||
static all(value: string | string[]): FilterArray; | ||
static exclude(value: string | string[]): FilterArray; | ||
} | ||
export declare class Sources { | ||
static any(value: string | string[]): FilterArray; | ||
static exclude(value: string | string[]): FilterArray; | ||
} | ||
export declare const And: (...queries: Filter[]) => Filter; | ||
export declare const Or: (...queries: Filter[]) => Filter; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.source = exports.categoryCodes = exports.ciks = exports.tickers = exports.text = exports.or = exports.and = void 0; | ||
exports.Or = exports.And = exports.Sources = exports.CategoryCodes = exports.Ciks = exports.Tickers = exports.Text = void 0; | ||
const enums_1 = require("./enums"); | ||
const and = (...queries) => { | ||
class Text { | ||
constructor() { | ||
} | ||
static any(value, options) { | ||
if (typeof value == "string") | ||
value = [value]; | ||
return Object.assign({ type: enums_1.FilterType.TEXT, action: enums_1.FilterAction.ANY, value }, options); | ||
} | ||
static all(value, options) { | ||
if (typeof value == "string") | ||
value = [value]; | ||
return Object.assign({ type: enums_1.FilterType.TEXT, action: enums_1.FilterAction.ALL, value }, options); | ||
} | ||
static exclude(value, options) { | ||
if (typeof value == "string") | ||
value = [value]; | ||
return Object.assign({ type: enums_1.FilterType.TEXT, action: enums_1.FilterAction.EXCLUDE, value }, options); | ||
} | ||
} | ||
exports.Text = Text; | ||
class FilterArrayBuilderBasic { | ||
constructor(type) { | ||
this.type = type; | ||
} | ||
any(value) { | ||
if (!Array.isArray(value)) | ||
value = [value]; | ||
return { | ||
type: this.type, | ||
action: enums_1.FilterAction.ANY, | ||
value: value | ||
}; | ||
} | ||
exclude(value) { | ||
if (!Array.isArray(value)) | ||
value = [value]; | ||
return { | ||
type: this.type, | ||
action: enums_1.FilterAction.EXCLUDE, | ||
value: value | ||
}; | ||
} | ||
} | ||
class FilterArrayBuilder extends FilterArrayBuilderBasic { | ||
constructor(type) { | ||
super(type); | ||
} | ||
all(value) { | ||
if (!Array.isArray(value)) | ||
value = [value]; | ||
return { | ||
type: this.type, | ||
action: enums_1.FilterAction.ALL, | ||
value: value | ||
}; | ||
} | ||
} | ||
class Tickers { | ||
static any(value) { | ||
return tickers().any(value); | ||
} | ||
static all(value) { | ||
return tickers().all(value); | ||
} | ||
static exclude(value) { | ||
return tickers().exclude(value); | ||
} | ||
} | ||
exports.Tickers = Tickers; | ||
class Ciks { | ||
static any(value) { | ||
return ciks().any(value); | ||
} | ||
static all(value) { | ||
return ciks().all(value); | ||
} | ||
static exclude(value) { | ||
return ciks().exclude(value); | ||
} | ||
} | ||
exports.Ciks = Ciks; | ||
class CategoryCodes { | ||
static any(value) { | ||
return categoryCodes().any(value); | ||
} | ||
static all(value) { | ||
return categoryCodes().all(value); | ||
} | ||
static exclude(value) { | ||
return categoryCodes().exclude(value); | ||
} | ||
} | ||
exports.CategoryCodes = CategoryCodes; | ||
class Sources { | ||
static any(value) { | ||
return sources().any(value); | ||
} | ||
static exclude(value) { | ||
return sources().exclude(value); | ||
} | ||
} | ||
exports.Sources = Sources; | ||
const And = (...queries) => { | ||
return { | ||
@@ -11,4 +113,4 @@ type: enums_1.FilterType.AND, | ||
}; | ||
exports.and = and; | ||
const or = (...queries) => { | ||
exports.And = And; | ||
const Or = (...queries) => { | ||
return { | ||
@@ -19,39 +121,15 @@ type: enums_1.FilterType.OR, | ||
}; | ||
exports.or = or; | ||
const text = (value, options) => { | ||
return Object.assign({ type: enums_1.FilterType.TEXT, value }, options); | ||
exports.Or = Or; | ||
const tickers = () => { | ||
return new FilterArrayBuilder(enums_1.FilterType.TICKERS); | ||
}; | ||
exports.text = text; | ||
const tickers = (action, value) => { | ||
return { | ||
type: enums_1.FilterType.TICKERS, | ||
action, | ||
value | ||
}; | ||
const ciks = () => { | ||
return new FilterArrayBuilder(enums_1.FilterType.CIKS); | ||
}; | ||
exports.tickers = tickers; | ||
const ciks = (action, value) => { | ||
return { | ||
type: enums_1.FilterType.CIKS, | ||
action, | ||
value | ||
}; | ||
const categoryCodes = () => { | ||
return new FilterArrayBuilder(enums_1.FilterType.CATEGORY_CODES); | ||
}; | ||
exports.ciks = ciks; | ||
const categoryCodes = (action, value) => { | ||
return { | ||
type: enums_1.FilterType.CATEGORY_CODES, | ||
action, | ||
value | ||
}; | ||
const sources = () => { | ||
return new FilterArrayBuilderBasic(enums_1.FilterType.SOURCE); | ||
}; | ||
exports.categoryCodes = categoryCodes; | ||
const source = (action, value) => { | ||
return { | ||
type: enums_1.FilterType.SOURCE, | ||
action, | ||
value | ||
}; | ||
}; | ||
exports.source = source; | ||
//# sourceMappingURL=filters.js.map |
@@ -1,2 +0,2 @@ | ||
export { or, and, text, ciks, tickers, source, categoryCodes } from "./filters"; | ||
export { Or, And, Text, Ciks, Tickers, Sources, CategoryCodes } from "./filters"; | ||
export { Api } from "./api"; | ||
@@ -3,0 +3,0 @@ export { WsApi } from "./wsApi"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FilterAction = exports.WebsocketResponseType = exports.WebsocketMethod = exports.Source = exports.WsApi = exports.Api = exports.categoryCodes = exports.source = exports.tickers = exports.ciks = exports.text = exports.and = exports.or = void 0; | ||
exports.FilterAction = exports.WebsocketResponseType = exports.WebsocketMethod = exports.Source = exports.WsApi = exports.Api = exports.CategoryCodes = exports.Sources = exports.Tickers = exports.Ciks = exports.Text = exports.And = exports.Or = void 0; | ||
var filters_1 = require("./filters"); | ||
Object.defineProperty(exports, "or", { enumerable: true, get: function () { return filters_1.or; } }); | ||
Object.defineProperty(exports, "and", { enumerable: true, get: function () { return filters_1.and; } }); | ||
Object.defineProperty(exports, "text", { enumerable: true, get: function () { return filters_1.text; } }); | ||
Object.defineProperty(exports, "ciks", { enumerable: true, get: function () { return filters_1.ciks; } }); | ||
Object.defineProperty(exports, "tickers", { enumerable: true, get: function () { return filters_1.tickers; } }); | ||
Object.defineProperty(exports, "source", { enumerable: true, get: function () { return filters_1.source; } }); | ||
Object.defineProperty(exports, "categoryCodes", { enumerable: true, get: function () { return filters_1.categoryCodes; } }); | ||
Object.defineProperty(exports, "Or", { enumerable: true, get: function () { return filters_1.Or; } }); | ||
Object.defineProperty(exports, "And", { enumerable: true, get: function () { return filters_1.And; } }); | ||
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return filters_1.Text; } }); | ||
Object.defineProperty(exports, "Ciks", { enumerable: true, get: function () { return filters_1.Ciks; } }); | ||
Object.defineProperty(exports, "Tickers", { enumerable: true, get: function () { return filters_1.Tickers; } }); | ||
Object.defineProperty(exports, "Sources", { enumerable: true, get: function () { return filters_1.Sources; } }); | ||
Object.defineProperty(exports, "CategoryCodes", { enumerable: true, get: function () { return filters_1.CategoryCodes; } }); | ||
var api_1 = require("./api"); | ||
@@ -13,0 +13,0 @@ Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return api_1.Api; } }); |
@@ -29,2 +29,3 @@ /// <reference types="ws" /> | ||
type: FilterType.TEXT; | ||
action?: FilterAction; | ||
value: string[]; | ||
@@ -37,3 +38,2 @@ } | ||
export interface TextOptions { | ||
action?: FilterAction; | ||
onlyBody?: boolean; | ||
@@ -115,1 +115,2 @@ onlyHeadline?: boolean; | ||
}; | ||
export type FiltersMetadata = FilterType.TICKERS | FilterType.CATEGORY_CODES | FilterType.SOURCE | FilterType.CIKS; |
{ | ||
"name": "newsware", | ||
"version": "7.1.0", | ||
"version": "8.0.0", | ||
"description": "Typescript client for interacting with the Newsware API", | ||
@@ -5,0 +5,0 @@ "main": "lib/src/index.js", |
import {Api} from "./api"; | ||
import {Endpoint, FilterAction} from "./enums"; | ||
import {Endpoint} from "./enums"; | ||
import {expect} from "chai" | ||
import {TestsContext} from "../test/setup"; | ||
import {and, categoryCodes, ciks, or, source, text, tickers} from "./filters"; | ||
import {And, CategoryCodes, Ciks, Or, Sources, Text, Tickers} from "./filters"; | ||
@@ -39,3 +39,3 @@ describe("Api historical search", () => { | ||
expect(actualNews.length).to.eq(3) | ||
res = await api.search({ | ||
@@ -130,3 +130,3 @@ pagination: { | ||
let actualNews = (await api.search({ | ||
filter: text(["one"], {onlyBody: true}) | ||
filter: Text.any(["one"], {onlyBody: true}) | ||
})).data | ||
@@ -136,3 +136,3 @@ expect(actualNews.length).to.eq(1) | ||
actualNews = (await api.search({ | ||
filter: text(["1"], {onlyBody: true}) | ||
filter: Text.any(["1"], {onlyBody: true}) | ||
})).data | ||
@@ -142,3 +142,3 @@ expect(actualNews.length).to.eq(0) | ||
actualNews = (await api.search({ | ||
filter: text(["1 two"], {onlyBody: true}) | ||
filter: Text.any(["1 two"], {onlyBody: true}) | ||
})).data | ||
@@ -152,3 +152,3 @@ expect(actualNews.length).to.eq(0) | ||
let actualNews = (await api.search({ | ||
filter: text(["one"], {onlyHeadline: true}) | ||
filter: Text.any(["one"], {onlyHeadline: true}) | ||
})).data | ||
@@ -158,3 +158,3 @@ expect(actualNews.length).to.eq(0) | ||
actualNews = (await api.search({ | ||
filter: text(["one 2"], {onlyHeadline: true}) | ||
filter: Text.any(["one 2"], {onlyHeadline: true}) | ||
})).data | ||
@@ -164,3 +164,3 @@ expect(actualNews.length).to.eq(0) | ||
actualNews = (await api.search({ | ||
filter: text(["1"], {onlyHeadline: true}) | ||
filter: Text.any(["1"], {onlyHeadline: true}) | ||
})).data | ||
@@ -174,3 +174,3 @@ expect(actualNews.length).to.eq(1) | ||
let actualNews = (await api.search({ | ||
filter: categoryCodes(FilterAction.ANY, ["categoryCode1", "categoryCode2"]) | ||
filter: CategoryCodes.any(["categoryCode1", "categoryCode2"]) | ||
})).data | ||
@@ -180,3 +180,3 @@ expect(actualNews.length).to.eq(2) | ||
actualNews = (await api.search({ | ||
filter: categoryCodes(FilterAction.ALL, ["categoryCode1", "categoryCode2"]) | ||
filter: CategoryCodes.all(["categoryCode1", "categoryCode2"]) | ||
})).data | ||
@@ -186,3 +186,3 @@ expect(actualNews.length).to.eq(0) | ||
actualNews = (await api.search({ | ||
filter: categoryCodes(FilterAction.ALL, ["categoryCode1", "categoryCode11"]) | ||
filter: CategoryCodes.all(["categoryCode1", "categoryCode11"]) | ||
})).data | ||
@@ -192,3 +192,3 @@ expect(actualNews.length).to.eq(1) | ||
actualNews = (await api.search({ | ||
filter: categoryCodes(FilterAction.EXCLUDE, ["categoryCode1", "categoryCode2"]) | ||
filter: CategoryCodes.exclude(["categoryCode1", "categoryCode2"]) | ||
})).data | ||
@@ -202,3 +202,3 @@ expect(actualNews.length).to.eq(4) | ||
let actualNews = (await api.search({ | ||
filter: tickers(FilterAction.ANY, ["ticker1", "ticker2"]) | ||
filter: Tickers.any(["ticker1", "ticker2"]) | ||
})).data | ||
@@ -208,3 +208,3 @@ expect(actualNews.length).to.eq(2) | ||
actualNews = (await api.search({ | ||
filter: tickers(FilterAction.ALL, ["ticker1", "ticker2"]) | ||
filter: Tickers.all(["ticker1", "ticker2"]) | ||
})).data | ||
@@ -214,3 +214,3 @@ expect(actualNews.length).to.eq(0) | ||
actualNews = (await api.search({ | ||
filter: tickers(FilterAction.ALL, ["ticker1", "ticker11"]) | ||
filter: Tickers.all(["ticker1", "ticker11"]) | ||
})).data | ||
@@ -220,3 +220,3 @@ expect(actualNews.length).to.eq(1) | ||
actualNews = (await api.search({ | ||
filter: tickers(FilterAction.EXCLUDE, ["ticker1", "ticker2"]) | ||
filter: Tickers.exclude(["ticker1", "ticker2"]) | ||
})).data | ||
@@ -230,3 +230,3 @@ expect(actualNews.length).to.eq(4) | ||
let actualNews = (await api.search({ | ||
filter: ciks(FilterAction.ANY, [1, 2]) | ||
filter: Ciks.any([1, 2]) | ||
})).data | ||
@@ -236,3 +236,3 @@ expect(actualNews.length).to.eq(2) | ||
actualNews = (await api.search({ | ||
filter: ciks(FilterAction.ALL, [1, 2]) | ||
filter: Ciks.all([1, 2]) | ||
})).data | ||
@@ -242,3 +242,3 @@ expect(actualNews.length).to.eq(0) | ||
actualNews = (await api.search({ | ||
filter: ciks(FilterAction.ALL, [1, 11]) | ||
filter: Ciks.all([1, 11]) | ||
})).data | ||
@@ -248,3 +248,3 @@ expect(actualNews.length).to.eq(1) | ||
actualNews = (await api.search({ | ||
filter: ciks(FilterAction.EXCLUDE, [1, 2]) | ||
filter: Ciks.exclude([1, 2]) | ||
})).data | ||
@@ -258,3 +258,3 @@ expect(actualNews.length).to.eq(4) | ||
let actualNews = (await api.search({ | ||
filter: source(FilterAction.ANY, ["source1", "source2"]) | ||
filter: Sources.any(["source1", "source2"]) | ||
})).data | ||
@@ -264,3 +264,3 @@ expect(actualNews.length).to.eq(2) | ||
actualNews = (await api.search({ | ||
filter: source(FilterAction.EXCLUDE, ["source1", "source2"]) | ||
filter: Sources.exclude(["source1", "source2"]) | ||
})).data | ||
@@ -274,5 +274,5 @@ expect(actualNews.length).to.eq(4) | ||
let actualNews = (await api.search({ | ||
filter: and( | ||
text(["1"]), | ||
ciks(FilterAction.ANY, [1]) | ||
filter: And( | ||
Text.any(["1"]), | ||
Ciks.any([1]) | ||
) | ||
@@ -283,5 +283,5 @@ })).data | ||
actualNews = (await api.search({ | ||
filter: and( | ||
text(["2"]), | ||
ciks(FilterAction.ANY, [1]) | ||
filter: And( | ||
Text.any(["2"]), | ||
Ciks.any([1]) | ||
) | ||
@@ -296,5 +296,5 @@ })).data | ||
let actualNews = (await api.search({ | ||
filter: or( | ||
text(["1"]), | ||
ciks(FilterAction.ANY, [2]) | ||
filter: Or( | ||
Text.any(["1"]), | ||
Ciks.any([2]) | ||
) | ||
@@ -305,6 +305,6 @@ })).data | ||
actualNews = (await api.search({ | ||
filter: or( | ||
text(["2"]), | ||
ciks(FilterAction.ANY, [1]), | ||
tickers(FilterAction.ANY, ["ticker3"]) | ||
filter: Or( | ||
Text.any(["2"]), | ||
Ciks.any([1]), | ||
Tickers.any(["ticker3"]) | ||
) | ||
@@ -311,0 +311,0 @@ })).data |
@@ -1,68 +0,163 @@ | ||
import {Filter, FilterArray, TextOptions} from "./types"; | ||
import {Filter, FilterArray, FiltersMetadata, FilterText, TextOptions} from "./types"; | ||
import {FilterAction, FilterType} from "./enums"; | ||
export const and = (...queries: Filter[]): Filter => { | ||
return { | ||
type: FilterType.AND, | ||
value: queries | ||
export class Text { | ||
constructor() { | ||
} | ||
static any(value: string[] | string, options?: TextOptions): FilterText { | ||
if (typeof value == "string") | ||
value = [value] | ||
return { | ||
type: FilterType.TEXT, | ||
action: FilterAction.ANY, | ||
value, | ||
...options | ||
} | ||
} | ||
static all(value: string[] | string, options?: TextOptions) { | ||
if (typeof value == "string") | ||
value = [value] | ||
return { | ||
type: FilterType.TEXT, | ||
action: FilterAction.ALL, | ||
value, | ||
...options | ||
} | ||
} | ||
static exclude(value: string[] | string, options?: TextOptions) { | ||
if (typeof value == "string") | ||
value = [value] | ||
return { | ||
type: FilterType.TEXT, | ||
action: FilterAction.EXCLUDE, | ||
value, | ||
...options | ||
} | ||
} | ||
} | ||
export const or = (...queries: Filter[]): Filter => { | ||
return { | ||
type: FilterType.OR, | ||
value: queries | ||
class FilterArrayBuilderBasic<T> { | ||
constructor(protected type: FiltersMetadata) { | ||
} | ||
any(value: T[] | T): FilterArray { | ||
if (!Array.isArray(value)) | ||
value = [value] | ||
return { | ||
type: this.type as any, | ||
action: FilterAction.ANY, | ||
value: value as any | ||
} | ||
} | ||
exclude(value: T[] | T): FilterArray { | ||
if (!Array.isArray(value)) | ||
value = [value] | ||
return { | ||
type: this.type as any, | ||
action: FilterAction.EXCLUDE, | ||
value: value as any | ||
} | ||
} | ||
} | ||
export const text = (value: string[], options?: TextOptions): Filter => { | ||
return { | ||
type: FilterType.TEXT, | ||
value, | ||
...options | ||
class FilterArrayBuilder<T> extends FilterArrayBuilderBasic<T> { | ||
constructor(type: FiltersMetadata) { | ||
super(type); | ||
} | ||
all(value: T[] | T): FilterArray { | ||
if (!Array.isArray(value)) | ||
value = [value] | ||
return { | ||
type: this.type as any, | ||
action: FilterAction.ALL, | ||
value: value as any | ||
} | ||
} | ||
} | ||
export const tickers = ( | ||
action: FilterAction, | ||
value: string[] | ||
): FilterArray => { | ||
return { | ||
type: FilterType.TICKERS, | ||
action, | ||
value | ||
export class Tickers { | ||
static any(value: string | string[]) { | ||
return tickers().any(value) | ||
} | ||
static all(value: string | string[]) { | ||
return tickers().all(value) | ||
} | ||
static exclude(value: string | string[]) { | ||
return tickers().exclude(value) | ||
} | ||
} | ||
export const ciks = ( | ||
action: FilterAction, | ||
value: number[] | ||
): FilterArray => { | ||
return { | ||
type: FilterType.CIKS, | ||
action, | ||
value | ||
export class Ciks { | ||
static any(value: number | number[]) { | ||
return ciks().any(value) | ||
} | ||
static all(value: number | number[]) { | ||
return ciks().all(value) | ||
} | ||
static exclude(value: number | number[]) { | ||
return ciks().exclude(value) | ||
} | ||
} | ||
export const categoryCodes = ( | ||
action: FilterAction, | ||
value: string[] | ||
): FilterArray => { | ||
export class CategoryCodes { | ||
static any(value: string | string[]) { | ||
return categoryCodes().any(value) | ||
} | ||
static all(value: string | string[]) { | ||
return categoryCodes().all(value) | ||
} | ||
static exclude(value: string | string[]) { | ||
return categoryCodes().exclude(value) | ||
} | ||
} | ||
export class Sources { | ||
static any(value: string | string[]) { | ||
return sources().any(value) | ||
} | ||
static exclude(value: string | string[]) { | ||
return sources().exclude(value) | ||
} | ||
} | ||
export const And = (...queries: Filter[]): Filter => { | ||
return { | ||
type: FilterType.CATEGORY_CODES, | ||
action, | ||
value | ||
type: FilterType.AND, | ||
value: queries | ||
} | ||
} | ||
export const source = ( | ||
action: FilterAction.ANY | FilterAction.EXCLUDE, | ||
value: string[] | ||
): FilterArray => { | ||
export const Or = (...queries: Filter[]): Filter => { | ||
return { | ||
type: FilterType.SOURCE, | ||
action, | ||
value | ||
type: FilterType.OR, | ||
value: queries | ||
} | ||
} | ||
const tickers = (): FilterArrayBuilder<string> => { | ||
return new FilterArrayBuilder<string>(FilterType.TICKERS) | ||
} | ||
const ciks = (): FilterArrayBuilder<number> => { | ||
return new FilterArrayBuilder<number>(FilterType.CIKS) | ||
} | ||
const categoryCodes = (): FilterArrayBuilder<string> => { | ||
return new FilterArrayBuilder<string>(FilterType.CATEGORY_CODES) | ||
} | ||
const sources = (): FilterArrayBuilderBasic<string> => { | ||
return new FilterArrayBuilderBasic<string>(FilterType.SOURCE) | ||
} |
@@ -1,2 +0,2 @@ | ||
export {or, and, text, ciks, tickers, source, categoryCodes} from "./filters"; | ||
export {Or, And, Text, Ciks, Tickers, Sources, CategoryCodes} from "./filters"; | ||
export {Api} from "./api" | ||
@@ -3,0 +3,0 @@ export {WsApi} from "./wsApi" |
@@ -32,2 +32,3 @@ import {CloseEvent} from "isomorphic-ws" | ||
type: FilterType.TEXT | ||
action?: FilterAction | ||
value: string[] | ||
@@ -42,3 +43,2 @@ } | ||
export interface TextOptions { | ||
action?: FilterAction | ||
onlyBody?: boolean | ||
@@ -130,2 +130,4 @@ onlyHeadline?: boolean | ||
type: WebsocketResponseType.OK | ||
} | ||
} | ||
export type FiltersMetadata = FilterType.TICKERS | FilterType.CATEGORY_CODES | FilterType.SOURCE | FilterType.CIKS |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
89485
1741