@@ -2,8 +2,6 @@ import { Pool } from 'mariadb';
22import { query } from '../../util/db' ;
33import { Sql } from './sql' ;
44
5- import { logger } from '../../loggers/logger' ;
6-
75export const Helpers = ( sqlClientPool : Pool ) => {
86 const removeAllRoutesFromEnvironment = async ( environmentId : number ) => {
97 await query (
@@ -46,6 +44,12 @@ export const Helpers = (sqlClientPool: Pool) => {
4644 if ( exists ) {
4745 throw new Error ( `Annotation already exists on route` ) ;
4846 } else {
47+ const combinedAnnotationCount = exists . length + 1
48+ // arbitrary limit of 10 annotations, maybe this should be less?
49+ // would prefer that annotations done this way weren't a thing, but here we are
50+ if ( combinedAnnotationCount >= 10 ) {
51+ throw Error ( `Limit of 10 annotations per route` )
52+ }
4953 await query (
5054 sqlClientPool ,
5155 Sql . insertRouteAnnotation ( { routeId, key, value} )
@@ -61,6 +65,12 @@ export const Helpers = (sqlClientPool: Pool) => {
6165 if ( exists ) {
6266 throw new Error ( `Annotation already exists on route` ) ;
6367 }
68+ const combinedAnnotationCount = exists . length + annotations . length
69+ // arbitrary limit of 10 annotations, maybe this should be less?
70+ // would prefer that annotations done this way weren't a thing, but here we are
71+ if ( combinedAnnotationCount >= 10 ) {
72+ throw Error ( `Limit of 10 annotations per route` )
73+ }
6474 }
6575 for ( const annotation of annotations ) {
6676 await query (
@@ -102,7 +112,10 @@ export function addServicePathRoute(
102112 const exists = pathRoutes . some (
103113 ( a ) => a . toService === newToService && a . path === newPath
104114 ) ;
105-
115+ const combinedPathRoutesCount = pathRoutes . length + 1
116+ if ( combinedPathRoutesCount >= 10 ) {
117+ throw Error ( `Limit of 10 path rotues, consider removing some from this route` )
118+ }
106119 if ( ! exists ) {
107120 return [ ...pathRoutes , { toService : newToService , path : newPath } ] ;
108121 }
0 commit comments