Lint format files. Updated rng function.
This commit is contained in:
1 parent
5bf1792b38
commit
306ca4a435
144 files changed
+962
-626
No files matched your search
@@ -30,8 +30,6 @@ describe('getApiUrl', () => {
|
||||
});
|
||||
|
||||
test('returns absolute input urls unchanged', () => {
|
||||
expect(getApiUrl('https://example.com/api/websites')).toBe(
|
||||
'https://example.com/api/websites',
|
||||
);
|
||||
expect(getApiUrl('https://example.com/api/websites')).toBe('https://example.com/api/websites');
|
||||
});
|
||||
});
|
||||
+1
-4
@@ -3,10 +3,7 @@ type ApiUrlOptions = {
|
||||
basePath?: string;
|
||||
};
|
||||
|
||||
const APP_ROUTE_PATTERNS: RegExp[] = [
|
||||
/^\/auth(\/|$)/,
|
||||
/^\/config(\/|$)/,
|
||||
];
|
||||
const APP_ROUTE_PATTERNS: RegExp[] = [/^\/auth(\/|$)/, /^\/config(\/|$)/];
|
||||
|
||||
function trimTrailingSlash(value: string) {
|
||||
return value.replace(/\/+$/, '');
|
||||
|
||||
+3
-8
@@ -1,5 +1,5 @@
|
||||
import type { Board, BoardComponentConfig, BoardParameters } from './types';
|
||||
import { isBoardComponentSupportedByEntityType } from './boardComponentCompatibility';
|
||||
import type { Board, BoardComponentConfig, BoardParameters } from './types';
|
||||
|
||||
export const BOARD_TYPES = {
|
||||
dashboard: 'dashboard',
|
||||
@@ -72,9 +72,7 @@ export function isOpenBoardType(type?: string) {
|
||||
}
|
||||
|
||||
export function requiresBoardEntity(type?: string) {
|
||||
return (
|
||||
type === BOARD_TYPES.website || type === BOARD_TYPES.pixel || type === BOARD_TYPES.link
|
||||
);
|
||||
return type === BOARD_TYPES.website || type === BOARD_TYPES.pixel || type === BOARD_TYPES.link;
|
||||
}
|
||||
|
||||
export function getBoardEntity(board?: Pick<Board, 'type' | 'parameters'> | Partial<Board>): {
|
||||
@@ -141,10 +139,7 @@ export function getResolvedComponentEntity(
|
||||
return getComponentEntity(config);
|
||||
}
|
||||
|
||||
export function isBoardComponentSupported(
|
||||
componentType: string,
|
||||
entityType?: BoardEntityType,
|
||||
) {
|
||||
export function isBoardComponentSupported(componentType: string, entityType?: BoardEntityType) {
|
||||
return isBoardComponentSupportedByEntityType(componentType, entityType);
|
||||
}
|
||||
|
||||
|
||||
+4
-7
@@ -1,11 +1,8 @@
|
||||
import { uniformInt } from 'pure-rand/distribution/uniformInt';
|
||||
import { xoroshiro128plus } from 'pure-rand/generator/xoroshiro128plus';
|
||||
|
||||
const seed = Date.now() ^ (Math.random() * 0x100000000);
|
||||
const rng = xoroshiro128plus(seed);
|
||||
|
||||
export function random(min: number, max: number) {
|
||||
return uniformInt(rng, min, max);
|
||||
const range = max - min + 1;
|
||||
const buf = new Uint32Array(1);
|
||||
globalThis.crypto.getRandomValues(buf);
|
||||
return min + (buf[0] % range);
|
||||
}
|
||||
|
||||
export function getRandomChars(
|
||||
|
||||
@@ -52,11 +52,7 @@ function getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
export async function putHeatmapSnapshot(
|
||||
objectKey: string,
|
||||
imageData: Buffer,
|
||||
mimeType: string,
|
||||
) {
|
||||
export async function putHeatmapSnapshot(objectKey: string, imageData: Buffer, mimeType: string) {
|
||||
await getClient().send(
|
||||
new PutObjectCommand({
|
||||
Bucket: getBucket(),
|
||||
|
||||
+36
-31
@@ -108,42 +108,44 @@ export function parsePropertyFilters(
|
||||
query: Record<string, any>,
|
||||
prefixes: string[] = ['pf'],
|
||||
): PropertyFilter[] {
|
||||
return Object.entries(query)
|
||||
.flatMap(([key, val]) => {
|
||||
const prefix = getPropertyFilterPrefix(key, prefixes);
|
||||
return Object.entries(query).flatMap(([key, val]) => {
|
||||
const prefix = getPropertyFilterPrefix(key, prefixes);
|
||||
|
||||
if (!prefix) {
|
||||
return [];
|
||||
}
|
||||
if (!prefix) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const stringValue = String(val);
|
||||
const withoutPrefix = key.slice(prefix.length + 1);
|
||||
const propertyName = withoutPrefix.replace(/\d+$/, ''); // strip trailing index digits
|
||||
const prefixedDotMatch = stringValue.match(/^(\d+)\.([^.]+)\.(.*)$/);
|
||||
const untypedDotMatch = stringValue.match(/^([^.]+)\.(.*)$/);
|
||||
const explicitDataType = prefixedDotMatch ? Number(prefixedDotMatch[1]) : undefined;
|
||||
const rawOperator = prefixedDotMatch ? prefixedDotMatch[2] : untypedDotMatch?.[1];
|
||||
const operator = resolveOperator(rawOperator);
|
||||
const stringValue = String(val);
|
||||
const withoutPrefix = key.slice(prefix.length + 1);
|
||||
const propertyName = withoutPrefix.replace(/\d+$/, ''); // strip trailing index digits
|
||||
const prefixedDotMatch = stringValue.match(/^(\d+)\.([^.]+)\.(.*)$/);
|
||||
const untypedDotMatch = stringValue.match(/^([^.]+)\.(.*)$/);
|
||||
const explicitDataType = prefixedDotMatch ? Number(prefixedDotMatch[1]) : undefined;
|
||||
const rawOperator = prefixedDotMatch ? prefixedDotMatch[2] : untypedDotMatch?.[1];
|
||||
const operator = resolveOperator(rawOperator);
|
||||
|
||||
if (!operator || (explicitDataType !== undefined && !VALID_EVENT_DATA_TYPES.includes(explicitDataType))) {
|
||||
return [];
|
||||
}
|
||||
if (
|
||||
!operator ||
|
||||
(explicitDataType !== undefined && !VALID_EVENT_DATA_TYPES.includes(explicitDataType))
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const value = prefixedDotMatch ? prefixedDotMatch[3] : untypedDotMatch?.[2];
|
||||
const value = prefixedDotMatch ? prefixedDotMatch[3] : untypedDotMatch?.[2];
|
||||
|
||||
if (value === undefined) {
|
||||
return [];
|
||||
}
|
||||
if (value === undefined) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
propertyName,
|
||||
dataType: explicitDataType ?? DATA_TYPE.string,
|
||||
operator,
|
||||
value,
|
||||
},
|
||||
];
|
||||
});
|
||||
return [
|
||||
{
|
||||
propertyName,
|
||||
dataType: explicitDataType ?? DATA_TYPE.string,
|
||||
operator,
|
||||
value,
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
export function parseEventPropertyFilters(query: Record<string, any>) {
|
||||
@@ -159,7 +161,10 @@ export function serializePropertyFilters(
|
||||
filters.map(f => {
|
||||
const n = counts[f.propertyName] ?? 0;
|
||||
counts[f.propertyName] = n + 1;
|
||||
return [`${prefix}_${f.propertyName}${n > 0 ? n : ''}`, `${f.dataType}.${f.operator}.${f.value}`];
|
||||
return [
|
||||
`${prefix}_${f.propertyName}${n > 0 ? n : ''}`,
|
||||
`${f.dataType}.${f.operator}.${f.value}`,
|
||||
];
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,3 +1,5 @@
|
||||
import { startOfMonth, subMonths } from 'date-fns';
|
||||
import { z } from 'zod';
|
||||
import { checkAuth } from '@/lib/auth';
|
||||
import { DEFAULT_PAGE_SIZE, FILTER_COLUMNS, OPERATORS } from '@/lib/constants';
|
||||
import { getAllowedUnits, getMinimumUnit, maxDate, parseDateRange } from '@/lib/date';
|
||||
@@ -6,8 +8,6 @@ import { filtersArrayToObject } from '@/lib/params';
|
||||
import { badRequest, unauthorized } from '@/lib/response';
|
||||
import type { QueryFilters } from '@/lib/types';
|
||||
import { getWebsiteSegment } from '@/queries/prisma';
|
||||
import { startOfMonth, subMonths } from 'date-fns';
|
||||
import { z } from 'zod';
|
||||
|
||||
export async function parseRequest(
|
||||
request: Request,
|
||||
|
||||
Reference in new issue
Block a user