diff --git a/dsl/src/fluent.ts b/dsl/src/fluent.ts index a95c08606..5ab7d3170 100644 --- a/dsl/src/fluent.ts +++ b/dsl/src/fluent.ts @@ -193,8 +193,8 @@ class FluentQ { return this } - ids (key: string, val: string[] | Symbol, opts: T.IdsQuery): this { - this[kState].push(Q.ids(key, val, opts)) + ids (key: string, val: (string | Symbol)[]): this { + this[kState].push(Q.ids(key, val)) return this } diff --git a/dsl/src/query.ts b/dsl/src/query.ts index 5ead6276e..5e1008a2c 100644 --- a/dsl/src/query.ts +++ b/dsl/src/query.ts @@ -91,7 +91,19 @@ namespace Q { } export function compileUnsafe = Record> (query: Record): t.compiledFunction { - let stringified = JSON.stringify(query, (key, value) => typeof value === 'symbol' ? `###${value.description!}###` : value) + let stringified = JSON.stringify(query, (key, value) => { + if (typeof value === 'symbol') { + return `###${value.description!}###` + } else if (key === '__proto__') { + return undefined + } else if (key === 'constructor' && typeof value === 'object' && + value !== null && value.prototype !== undefined) { + return undefined + } else { + return value + } + }) + const keys: string[] = [] const matches = stringified.match(/"###\w+###"/g) if (matches === null) { @@ -121,6 +133,7 @@ namespace Q { export function compile = Record> (query: Record): t.compiledFunction { const params: Array<{ path: string[], key: string }> = [] traverse(query, []) + if (params.length === 0) { throw new Error('The query does not contain any use of `Q.params`') } @@ -154,11 +167,23 @@ namespace Q { export function compileJson = Record> (query: Record): t.compiledFunction { const params: Array<{ path: string[], key: string }> = [] traverse(query, []) + if (params.length === 0) { throw new Error('The query does not contain any use of `Q.params`') } - const stringified = JSON.stringify(query, (key, value) => typeof value === 'symbol' ? `###${value.description!}###` : value) + const stringified = JSON.stringify(query, (key, value) => { + if (typeof value === 'symbol') { + return `###${value.description!}###` + } else if (key === '__proto__') { + return undefined + } else if (key === 'constructor' && typeof value === 'object' && + value !== null && value.prototype !== undefined) { + return undefined + } else { + return value + } + }) return function (input: TInput): Record { const q = JSON.parse(stringified) @@ -334,13 +359,12 @@ namespace Q { return generateValueObject('fuzzy', key, val, opts) } - export function ids (key: string, val: string[] | Symbol, opts: T.IdsQuery): { ids: Record } { + export function ids (key: string, val: (string | Symbol)[]): { ids: Record } { return { // @ts-expect-error ids: { [key]: { - values: val, - ...opts + values: val } } }