initial commit

This commit is contained in:
2026-04-29 17:46:58 +08:00
commit b428595769
38 changed files with 2229 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { parseIdList, parseMatchMode, sqlForRelationFilter } from '../src/filter.ts';
describe('filter helpers', () => {
it('parses comma separated ids and drops invalid values', () => {
assert.deepEqual(parseIdList('1, 2, x, -1, 3'), [1, 2, 3]);
});
it('defaults match mode to any', () => {
assert.equal(parseMatchMode('all'), 'all');
assert.equal(parseMatchMode('anything'), 'any');
assert.equal(parseMatchMode(undefined), 'any');
});
it('builds relation filters with bound array parameters', () => {
const params: unknown[] = [];
const sql = sqlForRelationFilter(
[1, 2],
'all',
'pokemon_skills',
'pokemon_id',
'skill_id',
'p.id',
params
);
assert.equal(params.length, 1);
assert.deepEqual(params[0], [1, 2]);
assert.match(sql, /count\(DISTINCT skill_id\)/);
assert.match(sql, /= 2/);
});
});