Commit c564c77f authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate StreamFilter to TS

parent 67ccfb08
/** /**
* Filter clause against which annotation updates are tested before being * Filter clause against which annotation updates are tested before being
* sent to the client. * sent to the client.
*
* @typedef FilterClause
* @prop {'/group'|'/id'|'/references'|'/uri'} field
* @prop {'equals'|'one_of'} operator
* @prop {string|string[]} value
* @prop {boolean} case_sensitive - TODO: Backend doesn't use this at present,
* but it seems important for certain fields (eg. ID).
*/ */
type FilterClause = {
field: '/group' | '/id' | '/references' | '/uri';
operator: 'equals' | 'one_of';
value: string | string[];
/** /**
* @typedef Filter * @todo Backend doesn't use this at present, but it seems important for
* @prop {string} match_policy - TODO: Remove this, the backend doesn't use it any more. * certain fields (eg. ID).
* @prop {FilterClause[]} clauses */
* @prop {object} actions - TODO: Remove this, the backend doesn't use it any more. case_sensitive: boolean;
* @prop {boolean} [actions.create] };
* @prop {boolean} [actions.update]
* @prop {boolean} [actions.delete] type Filter = {
*/ clauses: FilterClause[];
/**
* @deprecated
* @todo Remove this, the backend doesn't use it any more.
*/
match_policy: string;
/**
* @deprecated
* @todo Remove this, the backend doesn't use it any more.
*/
actions: {
create: boolean;
update: boolean;
delete: boolean;
};
};
/** /**
* Return a filter which matches every update that is visible to the current user. * Return a filter which matches every update that is visible to the current user.
*
* @return {Filter}
*/ */
function defaultFilter() { function defaultFilter(): Filter {
return { return {
match_policy: 'include_any', match_policy: 'include_any',
clauses: [], clauses: [],
...@@ -45,6 +57,8 @@ function defaultFilter() { ...@@ -45,6 +57,8 @@ function defaultFilter() {
* for the schema. * for the schema.
*/ */
export class StreamFilter { export class StreamFilter {
private _filter: Filter;
constructor() { constructor() {
this._filter = defaultFilter(); this._filter = defaultFilter();
} }
...@@ -52,12 +66,17 @@ export class StreamFilter { ...@@ -52,12 +66,17 @@ export class StreamFilter {
/** /**
* Add a matching clause to the configuration. * Add a matching clause to the configuration.
* *
* @param {FilterClause['field']} field - Field to filter by * @param field - Field to filter by
* @param {FilterClause['operator']} operator - How to filter * @param operator - How to filter
* @param {FilterClause['value']} value - Value to match * @param value - Value to match
* @param {FilterClause['case_sensitive']} caseSensitive - Whether matching should be case sensitive * @param caseSensitive - Whether matching should be case-sensitive
*/ */
addClause(field, operator, value, caseSensitive = false) { addClause(
field: FilterClause['field'],
operator: FilterClause['operator'],
value: FilterClause['value'],
caseSensitive: FilterClause['case_sensitive'] = false
) {
this._filter.clauses.push({ this._filter.clauses.push({
field, field,
operator, operator,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment