joist-core 2.5.0-next.21 → 2.5.0-next.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/BaseEntity.cjs +5 -2
- package/build/BaseEntity.cjs.map +1 -1
- package/build/BaseEntity.d.cts +2 -0
- package/build/BaseEntity.d.cts.map +1 -1
- package/build/BaseEntity.d.mts +2 -0
- package/build/BaseEntity.d.mts.map +1 -1
- package/build/BaseEntity.js +5 -2
- package/build/BaseEntity.js.map +1 -1
- package/build/Entity.cjs.map +1 -1
- package/build/Entity.d.cts +6 -0
- package/build/Entity.d.cts.map +1 -1
- package/build/Entity.d.mts +6 -0
- package/build/Entity.d.mts.map +1 -1
- package/build/Entity.js.map +1 -1
- package/build/EntityManager.cjs +83 -22
- package/build/EntityManager.cjs.map +1 -1
- package/build/EntityManager.d.cts +7 -4
- package/build/EntityManager.d.cts.map +1 -1
- package/build/EntityManager.d.mts +7 -4
- package/build/EntityManager.d.mts.map +1 -1
- package/build/EntityManager.js +83 -22
- package/build/EntityManager.js.map +1 -1
- package/build/InstanceData.cjs +2 -2
- package/build/InstanceData.cjs.map +1 -1
- package/build/InstanceData.d.cts +2 -2
- package/build/InstanceData.d.mts +2 -2
- package/build/InstanceData.js +2 -2
- package/build/InstanceData.js.map +1 -1
- package/build/PluginManager.cjs +6 -0
- package/build/PluginManager.cjs.map +1 -1
- package/build/PluginManager.d.cts +10 -0
- package/build/PluginManager.d.cts.map +1 -1
- package/build/PluginManager.d.mts +10 -0
- package/build/PluginManager.d.mts.map +1 -1
- package/build/PluginManager.js +6 -0
- package/build/PluginManager.js.map +1 -1
- package/build/clientIds.cjs +47 -0
- package/build/clientIds.cjs.map +1 -0
- package/build/clientIds.d.cts +26 -0
- package/build/clientIds.d.cts.map +1 -0
- package/build/clientIds.d.mts +26 -0
- package/build/clientIds.d.mts.map +1 -0
- package/build/clientIds.js +42 -0
- package/build/clientIds.js.map +1 -0
- package/build/configure.cjs +3 -0
- package/build/configure.cjs.map +1 -1
- package/build/configure.d.cts.map +1 -1
- package/build/configure.d.mts.map +1 -1
- package/build/configure.js +3 -0
- package/build/configure.js.map +1 -1
- package/build/getProperties.cjs +4 -1
- package/build/getProperties.cjs.map +1 -1
- package/build/getProperties.js +4 -1
- package/build/getProperties.js.map +1 -1
- package/build/index.cjs +15 -4
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts +9 -7
- package/build/index.d.cts.map +1 -1
- package/build/index.d.mts +9 -7
- package/build/index.d.mts.map +1 -1
- package/build/index.js +11 -5
- package/build/index.js.map +1 -1
- package/build/keys.cjs +4 -0
- package/build/keys.cjs.map +1 -1
- package/build/keys.d.cts.map +1 -1
- package/build/keys.d.mts.map +1 -1
- package/build/keys.js +4 -0
- package/build/keys.js.map +1 -1
- package/build/newTestInstance.cjs +8 -8
- package/build/newTestInstance.cjs.map +1 -1
- package/build/newTestInstance.d.cts.map +1 -1
- package/build/newTestInstance.d.mts.map +1 -1
- package/build/newTestInstance.js +8 -8
- package/build/newTestInstance.js.map +1 -1
- package/build/queries/ConditionBuilder.cjs +2 -1
- package/build/queries/ConditionBuilder.cjs.map +1 -1
- package/build/queries/ConditionBuilder.d.cts +9 -1
- package/build/queries/ConditionBuilder.d.cts.map +1 -1
- package/build/queries/ConditionBuilder.d.mts +9 -1
- package/build/queries/ConditionBuilder.d.mts.map +1 -1
- package/build/queries/ConditionBuilder.js +2 -2
- package/build/queries/ConditionBuilder.js.map +1 -1
- package/build/queries/conditions.cjs.map +1 -1
- package/build/queries/conditions.d.cts +4 -1
- package/build/queries/conditions.d.cts.map +1 -1
- package/build/queries/conditions.d.mts +4 -1
- package/build/queries/conditions.d.mts.map +1 -1
- package/build/queries/conditions.js.map +1 -1
- package/build/queries/sql/Expr.cjs +79 -134
- package/build/queries/sql/Expr.cjs.map +1 -1
- package/build/queries/sql/Expr.d.cts +26 -34
- package/build/queries/sql/Expr.d.cts.map +1 -1
- package/build/queries/sql/Expr.d.mts +26 -34
- package/build/queries/sql/Expr.d.mts.map +1 -1
- package/build/queries/sql/Expr.js +80 -133
- package/build/queries/sql/Expr.js.map +1 -1
- package/build/queries/sql/ParsedQuery.cjs +119 -0
- package/build/queries/sql/ParsedQuery.cjs.map +1 -0
- package/build/queries/sql/ParsedQuery.d.cts +105 -0
- package/build/queries/sql/ParsedQuery.d.cts.map +1 -0
- package/build/queries/sql/ParsedQuery.d.mts +105 -0
- package/build/queries/sql/ParsedQuery.d.mts.map +1 -0
- package/build/queries/sql/ParsedQuery.js +116 -0
- package/build/queries/sql/ParsedQuery.js.map +1 -0
- package/build/queries/sql/ParsedSqlExpression.cjs +74 -0
- package/build/queries/sql/ParsedSqlExpression.cjs.map +1 -0
- package/build/queries/sql/ParsedSqlExpression.d.cts +65 -0
- package/build/queries/sql/ParsedSqlExpression.d.cts.map +1 -0
- package/build/queries/sql/ParsedSqlExpression.d.mts +65 -0
- package/build/queries/sql/ParsedSqlExpression.d.mts.map +1 -0
- package/build/queries/sql/ParsedSqlExpression.js +69 -0
- package/build/queries/sql/ParsedSqlExpression.js.map +1 -0
- package/build/queries/sql/Tables.cjs +61 -46
- package/build/queries/sql/Tables.cjs.map +1 -1
- package/build/queries/sql/Tables.d.cts.map +1 -1
- package/build/queries/sql/Tables.d.mts.map +1 -1
- package/build/queries/sql/Tables.js +61 -46
- package/build/queries/sql/Tables.js.map +1 -1
- package/build/queries/sql/execute.cjs +45 -62
- package/build/queries/sql/execute.cjs.map +1 -1
- package/build/queries/sql/execute.d.cts +4 -3
- package/build/queries/sql/execute.d.cts.map +1 -1
- package/build/queries/sql/execute.d.mts +4 -3
- package/build/queries/sql/execute.d.mts.map +1 -1
- package/build/queries/sql/execute.js +47 -64
- package/build/queries/sql/execute.js.map +1 -1
- package/build/queries/sql/expressions/arrayAgg.cjs +14 -15
- package/build/queries/sql/expressions/arrayAgg.cjs.map +1 -1
- package/build/queries/sql/expressions/arrayAgg.d.cts +3 -2
- package/build/queries/sql/expressions/arrayAgg.d.cts.map +1 -1
- package/build/queries/sql/expressions/arrayAgg.d.mts +3 -2
- package/build/queries/sql/expressions/arrayAgg.d.mts.map +1 -1
- package/build/queries/sql/expressions/arrayAgg.js +15 -16
- package/build/queries/sql/expressions/arrayAgg.js.map +1 -1
- package/build/queries/sql/expressions/case.cjs +11 -16
- package/build/queries/sql/expressions/case.cjs.map +1 -1
- package/build/queries/sql/expressions/case.d.cts +3 -2
- package/build/queries/sql/expressions/case.d.cts.map +1 -1
- package/build/queries/sql/expressions/case.d.mts +3 -2
- package/build/queries/sql/expressions/case.d.mts.map +1 -1
- package/build/queries/sql/expressions/case.js +11 -16
- package/build/queries/sql/expressions/case.js.map +1 -1
- package/build/queries/sql/expressions/coalesce.cjs.map +1 -1
- package/build/queries/sql/expressions/coalesce.d.cts +3 -2
- package/build/queries/sql/expressions/coalesce.d.cts.map +1 -1
- package/build/queries/sql/expressions/coalesce.d.mts +3 -2
- package/build/queries/sql/expressions/coalesce.d.mts.map +1 -1
- package/build/queries/sql/expressions/coalesce.js.map +1 -1
- package/build/queries/sql/expressions/expression.cjs +10 -12
- package/build/queries/sql/expressions/expression.cjs.map +1 -1
- package/build/queries/sql/expressions/expression.d.cts +4 -3
- package/build/queries/sql/expressions/expression.d.cts.map +1 -1
- package/build/queries/sql/expressions/expression.d.mts +4 -3
- package/build/queries/sql/expressions/expression.d.mts.map +1 -1
- package/build/queries/sql/expressions/expression.js +11 -13
- package/build/queries/sql/expressions/expression.js.map +1 -1
- package/build/queries/sql/expressions/greatest.cjs.map +1 -1
- package/build/queries/sql/expressions/greatest.d.cts +3 -2
- package/build/queries/sql/expressions/greatest.d.cts.map +1 -1
- package/build/queries/sql/expressions/greatest.d.mts +3 -2
- package/build/queries/sql/expressions/greatest.d.mts.map +1 -1
- package/build/queries/sql/expressions/greatest.js.map +1 -1
- package/build/queries/sql/expressions/least.cjs.map +1 -1
- package/build/queries/sql/expressions/least.d.cts +3 -2
- package/build/queries/sql/expressions/least.d.cts.map +1 -1
- package/build/queries/sql/expressions/least.d.mts +3 -2
- package/build/queries/sql/expressions/least.d.mts.map +1 -1
- package/build/queries/sql/expressions/least.js.map +1 -1
- package/build/queries/sql/expressions/nullIf.cjs.map +1 -1
- package/build/queries/sql/expressions/nullIf.d.cts +3 -2
- package/build/queries/sql/expressions/nullIf.d.cts.map +1 -1
- package/build/queries/sql/expressions/nullIf.d.mts +3 -2
- package/build/queries/sql/expressions/nullIf.d.mts.map +1 -1
- package/build/queries/sql/expressions/nullIf.js.map +1 -1
- package/build/queries/sql/query.cjs +168 -381
- package/build/queries/sql/query.cjs.map +1 -1
- package/build/queries/sql/query.d.cts +44 -45
- package/build/queries/sql/query.d.cts.map +1 -1
- package/build/queries/sql/query.d.mts +44 -45
- package/build/queries/sql/query.d.mts.map +1 -1
- package/build/queries/sql/query.js +172 -383
- package/build/queries/sql/query.js.map +1 -1
- package/build/queries/sql/renderSql.cjs +321 -0
- package/build/queries/sql/renderSql.cjs.map +1 -0
- package/build/queries/sql/renderSql.d.cts +14 -0
- package/build/queries/sql/renderSql.d.cts.map +1 -0
- package/build/queries/sql/renderSql.d.mts +14 -0
- package/build/queries/sql/renderSql.d.mts.map +1 -0
- package/build/queries/sql/renderSql.js +318 -0
- package/build/queries/sql/renderSql.js.map +1 -0
- package/build/resurrection.cjs +5 -3
- package/build/resurrection.cjs.map +1 -1
- package/build/resurrection.d.cts.map +1 -1
- package/build/resurrection.d.mts.map +1 -1
- package/build/resurrection.js +5 -3
- package/build/resurrection.js.map +1 -1
- package/build/upsert.cjs +6 -3
- package/build/upsert.cjs.map +1 -1
- package/build/upsert.d.cts +6 -3
- package/build/upsert.d.cts.map +1 -1
- package/build/upsert.d.mts +6 -3
- package/build/upsert.d.mts.map +1 -1
- package/build/upsert.js +6 -3
- package/build/upsert.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.cjs","names":["mapToDb","fail","partition","skipCondition","isDefined"],"sources":["../../src/queries/ConditionBuilder.ts"],"sourcesContent":["import { isDefined } from \"src/EntityManager.ts\";\nimport type { ConditionGroup, ConditionInput } from \"src/queries/conditions.ts\";\nimport type {\n ColumnCondition,\n ParsedExpressionCondition,\n ParsedExpressionFilter,\n ParsedValueFilter,\n RawCondition,\n} from \"src/queries/parsedConditions.ts\";\nimport { skipCondition } from \"src/queries/skipCondition.ts\";\nimport { mapToDb } from \"src/queries/valueFilters.ts\";\nimport type { Column } from \"src/serde/columns.ts\";\nimport { fail, partition } from \"src/utils.ts\";\n\ntype PartialSome<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n/** Converts domain-level values like string ids/enums into their db equivalent. */\nexport class ConditionBuilder {\n /** Simple, single-column conditions, which will be AND-d together. */\n private conditions: (ColumnCondition | RawCondition)[] = [];\n /** Complex expressions, which will also be AND-d together with `conditions`. */\n private expressions: ParsedExpressionFilter[] = [];\n\n /** Accepts a raw user-facing DSL filter, and parses it into a `ParsedExpressionFilter`. */\n maybeAddExpression(expression: ConditionGroup<ConditionInput>): void {\n const parsed = parseExpression(expression);\n if (parsed) this.expressions.push(parsed);\n }\n\n /** Adds an already-db-level condition to the simple conditions list. */\n addSimpleCondition(condition: ColumnCondition): void {\n this.conditions.push(condition);\n }\n\n /** Adds an already-db-level condition to the simple conditions list. */\n addRawCondition(condition: PartialSome<RawCondition, \"kind\" | \"bindings\">): void {\n this.conditions.push({\n kind: \"raw\",\n bindings: [],\n ...condition,\n });\n }\n\n /** Adds an already-db-level expression to the expressions list. */\n addParsedExpression(parsed: ParsedExpressionFilter): void {\n this.expressions.push(parsed);\n }\n\n /**\n * Adds a user-facing `ParsedValueFilter` to the inline conditions.\n *\n * Unless it's something like `in: [a1, null]`, in which case we split it into two `is-null` and `in` conditions.\n */\n addValueFilter(alias: string, column: Column, filter: ParsedValueFilter<any>): void {\n if (filter.kind === \"in\" && filter.value.includes(null)) {\n // If the filter contains a null, we need to split it into an `is-null` and `in` condition\n const isNull = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n cond: { kind: \"is-null\" },\n } satisfies ColumnCondition;\n const inValues = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n cond: {\n kind: \"in\",\n // Filter out the nulls from the in condition\n value: filter.value.filter((v) => v !== null).map((v) => column.mapToDb(v)),\n },\n } satisfies ColumnCondition;\n // Now OR them back together\n this.expressions.push({ kind: \"exp\", op: \"or\", conditions: [isNull, inValues] });\n } else {\n const cond = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n // Rewrite the user-facing domain values to db values\n cond: mapToDb(column, filter),\n } satisfies ColumnCondition;\n this.conditions.push(cond);\n }\n }\n\n /** Combines our collected `conditions` and `expressions` into a single `ParsedExpressionFilter`. */\n toExpressionFilter(): ParsedExpressionFilter | undefined {\n const { expressions, conditions } = this;\n const allSimple: ParsedExpressionCondition[] = [...conditions];\n if (allSimple.length === 0 && expressions.length === 1) {\n // If no inline conditions, and just 1 opt expression, just use that\n return expressions[0];\n } else if (expressions.length === 1 && expressions[0].op === \"and\") {\n // Merge the 1 `AND` expression with the other simple conditions\n return { kind: \"exp\", op: \"and\", conditions: [...allSimple, ...expressions[0].conditions] };\n } else if (allSimple.length > 0 || expressions.length > 0) {\n // Combine the conditions within the `em.find` join literal & the `conditions` as ANDs\n return { kind: \"exp\", op: \"and\", conditions: [...allSimple, ...expressions] };\n }\n return undefined;\n }\n}\n\n/** Parses user-facing `{ and: ... }` or `{ or: ... }` into a `
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.cjs","names":["mapToDb","fail","partition","skipCondition","isDefined"],"sources":["../../src/queries/ConditionBuilder.ts"],"sourcesContent":["import { isDefined } from \"src/EntityManager.ts\";\nimport type { ConditionGroup, ConditionInput, ConditionTree } from \"src/queries/conditions.ts\";\nimport type {\n ColumnCondition,\n ParsedExpressionCondition,\n ParsedExpressionFilter,\n ParsedValueFilter,\n RawCondition,\n} from \"src/queries/parsedConditions.ts\";\nimport { skipCondition } from \"src/queries/skipCondition.ts\";\nimport { mapToDb } from \"src/queries/valueFilters.ts\";\nimport type { Column } from \"src/serde/columns.ts\";\nimport { fail, partition } from \"src/utils.ts\";\n\ntype PartialSome<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n/** Converts domain-level values like string ids/enums into their db equivalent. */\nexport class ConditionBuilder {\n /** Simple, single-column conditions, which will be AND-d together. */\n private conditions: (ColumnCondition | RawCondition)[] = [];\n /** Complex expressions, which will also be AND-d together with `conditions`. */\n private expressions: ParsedExpressionFilter[] = [];\n\n /** Accepts a raw user-facing DSL filter, and parses it into a `ParsedExpressionFilter`. */\n maybeAddExpression(expression: ConditionGroup<ConditionInput>): void {\n const parsed = parseExpression<ColumnCondition | RawCondition>(expression);\n if (parsed) this.expressions.push(parsed);\n }\n\n /** Adds an already-db-level condition to the simple conditions list. */\n addSimpleCondition(condition: ColumnCondition): void {\n this.conditions.push(condition);\n }\n\n /** Adds an already-db-level condition to the simple conditions list. */\n addRawCondition(condition: PartialSome<RawCondition, \"kind\" | \"bindings\">): void {\n this.conditions.push({\n kind: \"raw\",\n bindings: [],\n ...condition,\n });\n }\n\n /** Adds an already-db-level expression to the expressions list. */\n addParsedExpression(parsed: ParsedExpressionFilter): void {\n this.expressions.push(parsed);\n }\n\n /**\n * Adds a user-facing `ParsedValueFilter` to the inline conditions.\n *\n * Unless it's something like `in: [a1, null]`, in which case we split it into two `is-null` and `in` conditions.\n */\n addValueFilter(alias: string, column: Column, filter: ParsedValueFilter<any>): void {\n if (filter.kind === \"in\" && filter.value.includes(null)) {\n // If the filter contains a null, we need to split it into an `is-null` and `in` condition\n const isNull = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n cond: { kind: \"is-null\" },\n } satisfies ColumnCondition;\n const inValues = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n cond: {\n kind: \"in\",\n // Filter out the nulls from the in condition\n value: filter.value.filter((v) => v !== null).map((v) => column.mapToDb(v)),\n },\n } satisfies ColumnCondition;\n // Now OR them back together\n this.expressions.push({ kind: \"exp\", op: \"or\", conditions: [isNull, inValues] });\n } else {\n const cond = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n // Rewrite the user-facing domain values to db values\n cond: mapToDb(column, filter),\n } satisfies ColumnCondition;\n this.conditions.push(cond);\n }\n }\n\n /** Combines our collected `conditions` and `expressions` into a single `ParsedExpressionFilter`. */\n toExpressionFilter(): ParsedExpressionFilter | undefined {\n const { expressions, conditions } = this;\n const allSimple: ParsedExpressionCondition[] = [...conditions];\n if (allSimple.length === 0 && expressions.length === 1) {\n // If no inline conditions, and just 1 opt expression, just use that\n return expressions[0];\n } else if (expressions.length === 1 && expressions[0].op === \"and\") {\n // Merge the 1 `AND` expression with the other simple conditions\n return { kind: \"exp\", op: \"and\", conditions: [...allSimple, ...expressions[0].conditions] };\n } else if (allSimple.length > 0 || expressions.length > 0) {\n // Combine the conditions within the `em.find` join literal & the `conditions` as ANDs\n return { kind: \"exp\", op: \"and\", conditions: [...allSimple, ...expressions] };\n }\n return undefined;\n }\n}\n\n/** A normalized boolean group. */\nexport interface ParsedConditionGroup<C> {\n kind: \"exp\";\n op: \"and\" | \"or\";\n conditions: (C | ParsedConditionGroup<C>)[];\n}\n\n/** Parses user-facing `{ and: ... }` or `{ or: ... }` into a `ParsedConditionGroup`. */\nexport function parseExpression<C extends object>(\n expression: ConditionGroup<ConditionTree<C>>,\n): ParsedConditionGroup<C> | undefined {\n // Look for `{ and: [...] }` or `{ or: [...] }`\n const [op, expressions] =\n \"and\" in expression && expression.and\n ? [\"and\" as const, expression.and]\n : \"or\" in expression && expression.or\n ? [\"or\" as const, expression.or]\n : fail(`Invalid expression ${expression}`);\n // Potentially recurse into nested expressions\n const conditions = expressions.map((exp) =>\n exp && (\"and\" in exp || \"or\" in exp)\n ? parseExpression<C>(exp as ConditionGroup<ConditionTree<C>>)\n : (exp as C | undefined),\n );\n const [skip, valid] = partition(conditions, (cond) => cond === undefined || cond === skipCondition);\n if ((skip.length > 0 && expression.pruneIfUndefined === \"any\") || valid.length === 0) {\n return undefined;\n }\n return { kind: \"exp\", op, conditions: valid.filter(isDefined) };\n}\n"],"mappings":";;;;;;;AAiBA,IAAa,mBAAb,MAA8B;;CAE5B,aAAyD,CAAC;;CAE1D,cAAgD,CAAC;;CAGjD,mBAAmB,YAAkD;EACnE,MAAM,SAAS,gBAAgD,UAAU;EACzE,IAAI,QAAQ,KAAK,YAAY,KAAK,MAAM;CAC1C;;CAGA,mBAAmB,WAAkC;EACnD,KAAK,WAAW,KAAK,SAAS;CAChC;;CAGA,gBAAgB,WAAiE;EAC/E,KAAK,WAAW,KAAK;GACnB,MAAM;GACN,UAAU,CAAC;GACX,GAAG;EACL,CAAC;CACH;;CAGA,oBAAoB,QAAsC;EACxD,KAAK,YAAY,KAAK,MAAM;CAC9B;;;;;;CAOA,eAAe,OAAe,QAAgB,QAAsC;EAClF,IAAI,OAAO,SAAS,QAAQ,OAAO,MAAM,SAAS,IAAI,GAAG;GAEvD,MAAM,SAAS;IACb,MAAM;IACN;IACA,QAAQ,OAAO;IACf,QAAQ,OAAO;IACf,MAAM,EAAE,MAAM,UAAU;GAC1B;GACA,MAAM,WAAW;IACf,MAAM;IACN;IACA,QAAQ,OAAO;IACf,QAAQ,OAAO;IACf,MAAM;KACJ,MAAM;KAEN,OAAO,OAAO,MAAM,QAAQ,MAAM,MAAM,IAAI,CAAC,CAAC,KAAK,MAAM,OAAO,QAAQ,CAAC,CAAC;IAC5E;GACF;GAEA,KAAK,YAAY,KAAK;IAAE,MAAM;IAAO,IAAI;IAAM,YAAY,CAAC,QAAQ,QAAQ;GAAE,CAAC;EACjF,OAAO;GACL,MAAM,OAAO;IACX,MAAM;IACN;IACA,QAAQ,OAAO;IACf,QAAQ,OAAO;IAEf,MAAMA,6BAAAA,QAAQ,QAAQ,MAAM;GAC9B;GACA,KAAK,WAAW,KAAK,IAAI;EAC3B;CACF;;CAGA,qBAAyD;EACvD,MAAM,EAAE,aAAa,eAAe;EACpC,MAAM,YAAyC,CAAC,GAAG,UAAU;EAC7D,IAAI,UAAU,WAAW,KAAK,YAAY,WAAW,GAEnD,OAAO,YAAY;OACd,IAAI,YAAY,WAAW,KAAK,YAAY,EAAE,CAAC,OAAO,OAE3D,OAAO;GAAE,MAAM;GAAO,IAAI;GAAO,YAAY,CAAC,GAAG,WAAW,GAAG,YAAY,EAAE,CAAC,UAAU;EAAE;OACrF,IAAI,UAAU,SAAS,KAAK,YAAY,SAAS,GAEtD,OAAO;GAAE,MAAM;GAAO,IAAI;GAAO,YAAY,CAAC,GAAG,WAAW,GAAG,WAAW;EAAE;CAGhF;AACF;;AAUA,SAAgB,gBACd,YACqC;CAErC,MAAM,CAAC,IAAI,eACT,SAAS,cAAc,WAAW,MAC9B,CAAC,OAAgB,WAAW,GAAG,IAC/B,QAAQ,cAAc,WAAW,KAC/B,CAAC,MAAe,WAAW,EAAE,IAC7BC,cAAAA,KAAK,sBAAsB,YAAY;CAE/C,MAAM,aAAa,YAAY,KAAK,QAClC,QAAQ,SAAS,OAAO,QAAQ,OAC5B,gBAAmB,GAAuC,IACzD,GACP;CACA,MAAM,CAAC,MAAM,SAASC,cAAAA,UAAU,aAAa,SAAS,SAAS,KAAA,KAAa,SAASC,8BAAAA,aAAa;CAClG,IAAK,KAAK,SAAS,KAAK,WAAW,qBAAqB,SAAU,MAAM,WAAW,GACjF;CAEF,OAAO;EAAE,MAAM;EAAO;EAAI,YAAY,MAAM,OAAOC,sBAAAA,SAAS;CAAE;AAChE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConditionGroup, ConditionInput } from "./conditions.cjs";
|
|
1
|
+
import { ConditionGroup, ConditionInput, ConditionTree } from "./conditions.cjs";
|
|
2
2
|
import { ColumnCondition, ParsedExpressionFilter, ParsedValueFilter, RawCondition } from "./parsedConditions.cjs";
|
|
3
3
|
import { Column } from "../serde/columns.cjs";
|
|
4
4
|
type PartialSome<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -25,5 +25,13 @@ export declare class ConditionBuilder {
|
|
|
25
25
|
/** Combines our collected `conditions` and `expressions` into a single `ParsedExpressionFilter`. */
|
|
26
26
|
toExpressionFilter(): ParsedExpressionFilter | undefined;
|
|
27
27
|
}
|
|
28
|
+
/** A normalized boolean group. */
|
|
29
|
+
export interface ParsedConditionGroup<C> {
|
|
30
|
+
kind: "exp";
|
|
31
|
+
op: "and" | "or";
|
|
32
|
+
conditions: (C | ParsedConditionGroup<C>)[];
|
|
33
|
+
}
|
|
34
|
+
/** Parses user-facing `{ and: ... }` or `{ or: ... }` into a `ParsedConditionGroup`. */
|
|
35
|
+
export declare function parseExpression<C extends object>(expression: ConditionGroup<ConditionTree<C>>): ParsedConditionGroup<C> | undefined;
|
|
28
36
|
export {};
|
|
29
37
|
//# sourceMappingURL=ConditionBuilder.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.d.cts","names":[],"sources":["../../src/queries/ConditionBuilder.ts"],"mappings":";;;KAcK,YAAY,GAAG,gBAAgB,KAAK,KAAK,GAAG,KAAK,QAAQ,KAAK,GAAG;;qBAGzD;;UAEH;;UAEA;;EAGR,mBAAmB,YAAY,eAAe;;EAM9C,mBAAmB,WAAW;;EAK9B,gBAAgB,WAAW,YAAY;;EASvC,oBAAoB,QAAQ;;;;;;EAS5B,eAAe,eAAe,QAAQ,QAAQ,QAAQ;;EAqCtD,sBAAsB"}
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.d.cts","names":[],"sources":["../../src/queries/ConditionBuilder.ts"],"mappings":";;;KAcK,YAAY,GAAG,gBAAgB,KAAK,KAAK,GAAG,KAAK,QAAQ,KAAK,GAAG;;qBAGzD;;UAEH;;UAEA;;EAGR,mBAAmB,YAAY,eAAe;;EAM9C,mBAAmB,WAAW;;EAK9B,gBAAgB,WAAW,YAAY;;EASvC,oBAAoB,QAAQ;;;;;;EAS5B,eAAe,eAAe,QAAQ,QAAQ,QAAQ;;EAqCtD,sBAAsB;;;iBAkBP,qBAAqB;EACpC;EACA;EACA,aAAa,IAAI,qBAAqB;;;wBAIxB,gBAAgB,kBAC9B,YAAY,eAAe,cAAc,MACxC,qBAAqB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConditionGroup, ConditionInput } from "./conditions.mjs";
|
|
1
|
+
import { ConditionGroup, ConditionInput, ConditionTree } from "./conditions.mjs";
|
|
2
2
|
import { ColumnCondition, ParsedExpressionFilter, ParsedValueFilter, RawCondition } from "./parsedConditions.mjs";
|
|
3
3
|
import { Column } from "../serde/columns.mjs";
|
|
4
4
|
type PartialSome<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -25,5 +25,13 @@ export declare class ConditionBuilder {
|
|
|
25
25
|
/** Combines our collected `conditions` and `expressions` into a single `ParsedExpressionFilter`. */
|
|
26
26
|
toExpressionFilter(): ParsedExpressionFilter | undefined;
|
|
27
27
|
}
|
|
28
|
+
/** A normalized boolean group. */
|
|
29
|
+
export interface ParsedConditionGroup<C> {
|
|
30
|
+
kind: "exp";
|
|
31
|
+
op: "and" | "or";
|
|
32
|
+
conditions: (C | ParsedConditionGroup<C>)[];
|
|
33
|
+
}
|
|
34
|
+
/** Parses user-facing `{ and: ... }` or `{ or: ... }` into a `ParsedConditionGroup`. */
|
|
35
|
+
export declare function parseExpression<C extends object>(expression: ConditionGroup<ConditionTree<C>>): ParsedConditionGroup<C> | undefined;
|
|
28
36
|
export {};
|
|
29
37
|
//# sourceMappingURL=ConditionBuilder.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.d.mts","names":[],"sources":["../../src/queries/ConditionBuilder.ts"],"mappings":";;;KAcK,YAAY,GAAG,gBAAgB,KAAK,KAAK,GAAG,KAAK,QAAQ,KAAK,GAAG;;qBAGzD;;UAEH;;UAEA;;EAGR,mBAAmB,YAAY,eAAe;;EAM9C,mBAAmB,WAAW;;EAK9B,gBAAgB,WAAW,YAAY;;EASvC,oBAAoB,QAAQ;;;;;;EAS5B,eAAe,eAAe,QAAQ,QAAQ,QAAQ;;EAqCtD,sBAAsB"}
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.d.mts","names":[],"sources":["../../src/queries/ConditionBuilder.ts"],"mappings":";;;KAcK,YAAY,GAAG,gBAAgB,KAAK,KAAK,GAAG,KAAK,QAAQ,KAAK,GAAG;;qBAGzD;;UAEH;;UAEA;;EAGR,mBAAmB,YAAY,eAAe;;EAM9C,mBAAmB,WAAW;;EAK9B,gBAAgB,WAAW,YAAY;;EASvC,oBAAoB,QAAQ;;;;;;EAS5B,eAAe,eAAe,QAAQ,QAAQ,QAAQ;;EAqCtD,sBAAsB;;;iBAkBP,qBAAqB;EACpC;EACA;EACA,aAAa,IAAI,qBAAqB;;;wBAIxB,gBAAgB,kBAC9B,YAAY,eAAe,cAAc,MACxC,qBAAqB"}
|
|
@@ -87,7 +87,7 @@ var ConditionBuilder = class {
|
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
-
/** Parses user-facing `{ and: ... }` or `{ or: ... }` into a `
|
|
90
|
+
/** Parses user-facing `{ and: ... }` or `{ or: ... }` into a `ParsedConditionGroup`. */
|
|
91
91
|
function parseExpression(expression) {
|
|
92
92
|
const [op, expressions] = "and" in expression && expression.and ? ["and", expression.and] : "or" in expression && expression.or ? ["or", expression.or] : fail(`Invalid expression ${expression}`);
|
|
93
93
|
const conditions = expressions.map((exp) => exp && ("and" in exp || "or" in exp) ? parseExpression(exp) : exp);
|
|
@@ -99,6 +99,6 @@ function parseExpression(expression) {
|
|
|
99
99
|
conditions: valid.filter(isDefined)
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
export { ConditionBuilder };
|
|
102
|
+
export { ConditionBuilder, parseExpression };
|
|
103
103
|
|
|
104
104
|
//# sourceMappingURL=ConditionBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.js","names":[],"sources":["../../src/queries/ConditionBuilder.ts"],"sourcesContent":["import { isDefined } from \"src/EntityManager.ts\";\nimport type { ConditionGroup, ConditionInput } from \"src/queries/conditions.ts\";\nimport type {\n ColumnCondition,\n ParsedExpressionCondition,\n ParsedExpressionFilter,\n ParsedValueFilter,\n RawCondition,\n} from \"src/queries/parsedConditions.ts\";\nimport { skipCondition } from \"src/queries/skipCondition.ts\";\nimport { mapToDb } from \"src/queries/valueFilters.ts\";\nimport type { Column } from \"src/serde/columns.ts\";\nimport { fail, partition } from \"src/utils.ts\";\n\ntype PartialSome<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n/** Converts domain-level values like string ids/enums into their db equivalent. */\nexport class ConditionBuilder {\n /** Simple, single-column conditions, which will be AND-d together. */\n private conditions: (ColumnCondition | RawCondition)[] = [];\n /** Complex expressions, which will also be AND-d together with `conditions`. */\n private expressions: ParsedExpressionFilter[] = [];\n\n /** Accepts a raw user-facing DSL filter, and parses it into a `ParsedExpressionFilter`. */\n maybeAddExpression(expression: ConditionGroup<ConditionInput>): void {\n const parsed = parseExpression(expression);\n if (parsed) this.expressions.push(parsed);\n }\n\n /** Adds an already-db-level condition to the simple conditions list. */\n addSimpleCondition(condition: ColumnCondition): void {\n this.conditions.push(condition);\n }\n\n /** Adds an already-db-level condition to the simple conditions list. */\n addRawCondition(condition: PartialSome<RawCondition, \"kind\" | \"bindings\">): void {\n this.conditions.push({\n kind: \"raw\",\n bindings: [],\n ...condition,\n });\n }\n\n /** Adds an already-db-level expression to the expressions list. */\n addParsedExpression(parsed: ParsedExpressionFilter): void {\n this.expressions.push(parsed);\n }\n\n /**\n * Adds a user-facing `ParsedValueFilter` to the inline conditions.\n *\n * Unless it's something like `in: [a1, null]`, in which case we split it into two `is-null` and `in` conditions.\n */\n addValueFilter(alias: string, column: Column, filter: ParsedValueFilter<any>): void {\n if (filter.kind === \"in\" && filter.value.includes(null)) {\n // If the filter contains a null, we need to split it into an `is-null` and `in` condition\n const isNull = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n cond: { kind: \"is-null\" },\n } satisfies ColumnCondition;\n const inValues = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n cond: {\n kind: \"in\",\n // Filter out the nulls from the in condition\n value: filter.value.filter((v) => v !== null).map((v) => column.mapToDb(v)),\n },\n } satisfies ColumnCondition;\n // Now OR them back together\n this.expressions.push({ kind: \"exp\", op: \"or\", conditions: [isNull, inValues] });\n } else {\n const cond = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n // Rewrite the user-facing domain values to db values\n cond: mapToDb(column, filter),\n } satisfies ColumnCondition;\n this.conditions.push(cond);\n }\n }\n\n /** Combines our collected `conditions` and `expressions` into a single `ParsedExpressionFilter`. */\n toExpressionFilter(): ParsedExpressionFilter | undefined {\n const { expressions, conditions } = this;\n const allSimple: ParsedExpressionCondition[] = [...conditions];\n if (allSimple.length === 0 && expressions.length === 1) {\n // If no inline conditions, and just 1 opt expression, just use that\n return expressions[0];\n } else if (expressions.length === 1 && expressions[0].op === \"and\") {\n // Merge the 1 `AND` expression with the other simple conditions\n return { kind: \"exp\", op: \"and\", conditions: [...allSimple, ...expressions[0].conditions] };\n } else if (allSimple.length > 0 || expressions.length > 0) {\n // Combine the conditions within the `em.find` join literal & the `conditions` as ANDs\n return { kind: \"exp\", op: \"and\", conditions: [...allSimple, ...expressions] };\n }\n return undefined;\n }\n}\n\n/** Parses user-facing `{ and: ... }` or `{ or: ... }` into a `
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.js","names":[],"sources":["../../src/queries/ConditionBuilder.ts"],"sourcesContent":["import { isDefined } from \"src/EntityManager.ts\";\nimport type { ConditionGroup, ConditionInput, ConditionTree } from \"src/queries/conditions.ts\";\nimport type {\n ColumnCondition,\n ParsedExpressionCondition,\n ParsedExpressionFilter,\n ParsedValueFilter,\n RawCondition,\n} from \"src/queries/parsedConditions.ts\";\nimport { skipCondition } from \"src/queries/skipCondition.ts\";\nimport { mapToDb } from \"src/queries/valueFilters.ts\";\nimport type { Column } from \"src/serde/columns.ts\";\nimport { fail, partition } from \"src/utils.ts\";\n\ntype PartialSome<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n/** Converts domain-level values like string ids/enums into their db equivalent. */\nexport class ConditionBuilder {\n /** Simple, single-column conditions, which will be AND-d together. */\n private conditions: (ColumnCondition | RawCondition)[] = [];\n /** Complex expressions, which will also be AND-d together with `conditions`. */\n private expressions: ParsedExpressionFilter[] = [];\n\n /** Accepts a raw user-facing DSL filter, and parses it into a `ParsedExpressionFilter`. */\n maybeAddExpression(expression: ConditionGroup<ConditionInput>): void {\n const parsed = parseExpression<ColumnCondition | RawCondition>(expression);\n if (parsed) this.expressions.push(parsed);\n }\n\n /** Adds an already-db-level condition to the simple conditions list. */\n addSimpleCondition(condition: ColumnCondition): void {\n this.conditions.push(condition);\n }\n\n /** Adds an already-db-level condition to the simple conditions list. */\n addRawCondition(condition: PartialSome<RawCondition, \"kind\" | \"bindings\">): void {\n this.conditions.push({\n kind: \"raw\",\n bindings: [],\n ...condition,\n });\n }\n\n /** Adds an already-db-level expression to the expressions list. */\n addParsedExpression(parsed: ParsedExpressionFilter): void {\n this.expressions.push(parsed);\n }\n\n /**\n * Adds a user-facing `ParsedValueFilter` to the inline conditions.\n *\n * Unless it's something like `in: [a1, null]`, in which case we split it into two `is-null` and `in` conditions.\n */\n addValueFilter(alias: string, column: Column, filter: ParsedValueFilter<any>): void {\n if (filter.kind === \"in\" && filter.value.includes(null)) {\n // If the filter contains a null, we need to split it into an `is-null` and `in` condition\n const isNull = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n cond: { kind: \"is-null\" },\n } satisfies ColumnCondition;\n const inValues = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n cond: {\n kind: \"in\",\n // Filter out the nulls from the in condition\n value: filter.value.filter((v) => v !== null).map((v) => column.mapToDb(v)),\n },\n } satisfies ColumnCondition;\n // Now OR them back together\n this.expressions.push({ kind: \"exp\", op: \"or\", conditions: [isNull, inValues] });\n } else {\n const cond = {\n kind: \"column\",\n alias,\n column: column.columnName,\n dbType: column.dbType,\n // Rewrite the user-facing domain values to db values\n cond: mapToDb(column, filter),\n } satisfies ColumnCondition;\n this.conditions.push(cond);\n }\n }\n\n /** Combines our collected `conditions` and `expressions` into a single `ParsedExpressionFilter`. */\n toExpressionFilter(): ParsedExpressionFilter | undefined {\n const { expressions, conditions } = this;\n const allSimple: ParsedExpressionCondition[] = [...conditions];\n if (allSimple.length === 0 && expressions.length === 1) {\n // If no inline conditions, and just 1 opt expression, just use that\n return expressions[0];\n } else if (expressions.length === 1 && expressions[0].op === \"and\") {\n // Merge the 1 `AND` expression with the other simple conditions\n return { kind: \"exp\", op: \"and\", conditions: [...allSimple, ...expressions[0].conditions] };\n } else if (allSimple.length > 0 || expressions.length > 0) {\n // Combine the conditions within the `em.find` join literal & the `conditions` as ANDs\n return { kind: \"exp\", op: \"and\", conditions: [...allSimple, ...expressions] };\n }\n return undefined;\n }\n}\n\n/** A normalized boolean group. */\nexport interface ParsedConditionGroup<C> {\n kind: \"exp\";\n op: \"and\" | \"or\";\n conditions: (C | ParsedConditionGroup<C>)[];\n}\n\n/** Parses user-facing `{ and: ... }` or `{ or: ... }` into a `ParsedConditionGroup`. */\nexport function parseExpression<C extends object>(\n expression: ConditionGroup<ConditionTree<C>>,\n): ParsedConditionGroup<C> | undefined {\n // Look for `{ and: [...] }` or `{ or: [...] }`\n const [op, expressions] =\n \"and\" in expression && expression.and\n ? [\"and\" as const, expression.and]\n : \"or\" in expression && expression.or\n ? [\"or\" as const, expression.or]\n : fail(`Invalid expression ${expression}`);\n // Potentially recurse into nested expressions\n const conditions = expressions.map((exp) =>\n exp && (\"and\" in exp || \"or\" in exp)\n ? parseExpression<C>(exp as ConditionGroup<ConditionTree<C>>)\n : (exp as C | undefined),\n );\n const [skip, valid] = partition(conditions, (cond) => cond === undefined || cond === skipCondition);\n if ((skip.length > 0 && expression.pruneIfUndefined === \"any\") || valid.length === 0) {\n return undefined;\n }\n return { kind: \"exp\", op, conditions: valid.filter(isDefined) };\n}\n"],"mappings":";;;;;;AAiBA,IAAa,mBAAb,MAA8B;;CAE5B,aAAyD,CAAC;;CAE1D,cAAgD,CAAC;;CAGjD,mBAAmB,YAAkD;EACnE,MAAM,SAAS,gBAAgD,UAAU;EACzE,IAAI,QAAQ,KAAK,YAAY,KAAK,MAAM;CAC1C;;CAGA,mBAAmB,WAAkC;EACnD,KAAK,WAAW,KAAK,SAAS;CAChC;;CAGA,gBAAgB,WAAiE;EAC/E,KAAK,WAAW,KAAK;GACnB,MAAM;GACN,UAAU,CAAC;GACX,GAAG;EACL,CAAC;CACH;;CAGA,oBAAoB,QAAsC;EACxD,KAAK,YAAY,KAAK,MAAM;CAC9B;;;;;;CAOA,eAAe,OAAe,QAAgB,QAAsC;EAClF,IAAI,OAAO,SAAS,QAAQ,OAAO,MAAM,SAAS,IAAI,GAAG;GAEvD,MAAM,SAAS;IACb,MAAM;IACN;IACA,QAAQ,OAAO;IACf,QAAQ,OAAO;IACf,MAAM,EAAE,MAAM,UAAU;GAC1B;GACA,MAAM,WAAW;IACf,MAAM;IACN;IACA,QAAQ,OAAO;IACf,QAAQ,OAAO;IACf,MAAM;KACJ,MAAM;KAEN,OAAO,OAAO,MAAM,QAAQ,MAAM,MAAM,IAAI,CAAC,CAAC,KAAK,MAAM,OAAO,QAAQ,CAAC,CAAC;IAC5E;GACF;GAEA,KAAK,YAAY,KAAK;IAAE,MAAM;IAAO,IAAI;IAAM,YAAY,CAAC,QAAQ,QAAQ;GAAE,CAAC;EACjF,OAAO;GACL,MAAM,OAAO;IACX,MAAM;IACN;IACA,QAAQ,OAAO;IACf,QAAQ,OAAO;IAEf,MAAM,QAAQ,QAAQ,MAAM;GAC9B;GACA,KAAK,WAAW,KAAK,IAAI;EAC3B;CACF;;CAGA,qBAAyD;EACvD,MAAM,EAAE,aAAa,eAAe;EACpC,MAAM,YAAyC,CAAC,GAAG,UAAU;EAC7D,IAAI,UAAU,WAAW,KAAK,YAAY,WAAW,GAEnD,OAAO,YAAY;OACd,IAAI,YAAY,WAAW,KAAK,YAAY,EAAE,CAAC,OAAO,OAE3D,OAAO;GAAE,MAAM;GAAO,IAAI;GAAO,YAAY,CAAC,GAAG,WAAW,GAAG,YAAY,EAAE,CAAC,UAAU;EAAE;OACrF,IAAI,UAAU,SAAS,KAAK,YAAY,SAAS,GAEtD,OAAO;GAAE,MAAM;GAAO,IAAI;GAAO,YAAY,CAAC,GAAG,WAAW,GAAG,WAAW;EAAE;CAGhF;AACF;;AAUA,SAAgB,gBACd,YACqC;CAErC,MAAM,CAAC,IAAI,eACT,SAAS,cAAc,WAAW,MAC9B,CAAC,OAAgB,WAAW,GAAG,IAC/B,QAAQ,cAAc,WAAW,KAC/B,CAAC,MAAe,WAAW,EAAE,IAC7B,KAAK,sBAAsB,YAAY;CAE/C,MAAM,aAAa,YAAY,KAAK,QAClC,QAAQ,SAAS,OAAO,QAAQ,OAC5B,gBAAmB,GAAuC,IACzD,GACP;CACA,MAAM,CAAC,MAAM,SAAS,UAAU,aAAa,SAAS,SAAS,KAAA,KAAa,SAAS,aAAa;CAClG,IAAK,KAAK,SAAS,KAAK,WAAW,qBAAqB,SAAU,MAAM,WAAW,GACjF;CAEF,OAAO;EAAE,MAAM;EAAO;EAAI,YAAY,MAAM,OAAO,SAAS;CAAE;AAChE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.cjs","names":[],"sources":["../../src/queries/conditions.ts"],"sourcesContent":["import type { ColumnCondition, RawCondition } from \"src/queries/parsedConditions.ts\";\n\nexport const predicateBrand: unique symbol = Symbol(\"joist.predicate\");\n\n/** Combines conditions without tying AND/OR or optional-filter pruning to either public API. */\nexport type ConditionGroup<C> = AndCondition<C> | OrCondition<C>;\n\n/** Requires every surviving condition to match. */\nexport interface AndCondition<C> {\n and: Array<C | undefined>;\n or?: never;\n pruneIfUndefined?: \"any\" | \"all\";\n}\n\n/** Requires at least one surviving condition to match. */\nexport interface OrCondition<C> {\n or: Array<C | undefined>;\n and?: never;\n pruneIfUndefined?: \"any\" | \"all\";\n}\n\n/** Identifies which API can resolve a predicate's aliases. */\nexport interface PredicateBrand<K extends \"domain\" | \"sql\"> {\n readonly [predicateBrand]: K;\n}\n\n/** A predicate built from alias(...) for em.find and scopes. */\nexport type DomainPredicate = (ColumnCondition | RawCondition) & PredicateBrand<\"domain\">;\n\n/** A predicate built from table(...), an SQL expression, or sql.condition. */\nexport type SqlPredicate = (ColumnCondition | RawCondition) & PredicateBrand<\"sql\">;\n\n/** Existing hand-written conditions remain an escape hatch, but cannot accept a foreign branded predicate. */\nexport type UnbrandedPredicate = (ColumnCondition | RawCondition) & { readonly [predicateBrand]?: never };\n\n/** SQL predicates and nested AND/OR groups, before query-specific clauses such as EXISTS are added. */\nexport type SqlCondition = AndCondition<SqlCondition> | OrCondition<SqlCondition> | SqlPredicate | UnbrandedPredicate;\n\n/** Unbranded compiler input shared by domain filtering and SQL queries after public API validation. */\nexport type ConditionInput =\n | AndCondition<ConditionInput>\n | OrCondition<ConditionInput>\n | ColumnCondition\n | RawCondition;\n\n/** Marks a newly created predicate without changing its enumerable SQL representation. */\nexport function brandPredicate<C extends object, K extends \"domain\" | \"sql\">(cond: C, kind: K): C & PredicateBrand<K> {\n return Object.defineProperty(cond, predicateBrand, { value: kind, enumerable: false }) as C & PredicateBrand<K>;\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"conditions.cjs","names":[],"sources":["../../src/queries/conditions.ts"],"sourcesContent":["import type { ColumnCondition, RawCondition } from \"src/queries/parsedConditions.ts\";\nimport type { DeferredCondition } from \"src/queries/sql/Expr.ts\";\n\nexport const predicateBrand: unique symbol = Symbol(\"joist.predicate\");\n\n/** Combines conditions without tying AND/OR or optional-filter pruning to either public API. */\nexport type ConditionGroup<C> = AndCondition<C> | OrCondition<C>;\n\n/** Requires every surviving condition to match. */\nexport interface AndCondition<C> {\n and: Array<C | undefined>;\n or?: never;\n pruneIfUndefined?: \"any\" | \"all\";\n}\n\n/** Requires at least one surviving condition to match. */\nexport interface OrCondition<C> {\n or: Array<C | undefined>;\n and?: never;\n pruneIfUndefined?: \"any\" | \"all\";\n}\n\n/** Identifies which API can resolve a predicate's aliases. */\nexport interface PredicateBrand<K extends \"domain\" | \"sql\"> {\n readonly [predicateBrand]: K;\n}\n\n/** A predicate built from alias(...) for em.find and scopes. */\nexport type DomainPredicate = (ColumnCondition | RawCondition) & PredicateBrand<\"domain\">;\n\n/** A predicate built from table(...), an SQL expression, or sql.condition. */\nexport type SqlPredicate = (ColumnCondition | RawCondition | DeferredCondition) & PredicateBrand<\"sql\">;\n\n/** Boolean groups shared by both em.find and em.query predicates. */\nexport type ConditionTree<C> = C | AndCondition<ConditionTree<C>> | OrCondition<ConditionTree<C>>;\n\n/** Existing hand-written conditions remain an escape hatch, but cannot accept a foreign branded predicate. */\nexport type UnbrandedPredicate = (ColumnCondition | RawCondition) & { readonly [predicateBrand]?: never };\n\n/** SQL predicates and nested AND/OR groups, before query-specific clauses such as EXISTS are added. */\nexport type SqlCondition = AndCondition<SqlCondition> | OrCondition<SqlCondition> | SqlPredicate | UnbrandedPredicate;\n\n/** Unbranded compiler input shared by domain filtering and SQL queries after public API validation. */\nexport type ConditionInput =\n | AndCondition<ConditionInput>\n | OrCondition<ConditionInput>\n | ColumnCondition\n | RawCondition;\n\n/** Marks a newly created predicate without changing its enumerable SQL representation. */\nexport function brandPredicate<C extends object, K extends \"domain\" | \"sql\">(cond: C, kind: K): C & PredicateBrand<K> {\n return Object.defineProperty(cond, predicateBrand, { value: kind, enumerable: false }) as C & PredicateBrand<K>;\n}\n"],"mappings":";;AAGA,MAAa,iBAAgC,OAAO,iBAAiB;;AA+CrE,SAAgB,eAA6D,MAAS,MAAgC;CACpH,OAAO,OAAO,eAAe,MAAM,gBAAgB;EAAE,OAAO;EAAM,YAAY;CAAM,CAAC;AACvF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ColumnCondition, RawCondition } from "./parsedConditions.cjs";
|
|
2
|
+
import { DeferredCondition } from "./sql/Expr.cjs";
|
|
2
3
|
export declare const predicateBrand: unique symbol;
|
|
3
4
|
/** Combines conditions without tying AND/OR or optional-filter pruning to either public API. */
|
|
4
5
|
export type ConditionGroup<C> = AndCondition<C> | OrCondition<C>;
|
|
@@ -21,7 +22,9 @@ export interface PredicateBrand<K extends "domain" | "sql"> {
|
|
|
21
22
|
/** A predicate built from alias(...) for em.find and scopes. */
|
|
22
23
|
export type DomainPredicate = (ColumnCondition | RawCondition) & PredicateBrand<"domain">;
|
|
23
24
|
/** A predicate built from table(...), an SQL expression, or sql.condition. */
|
|
24
|
-
export type SqlPredicate = (ColumnCondition | RawCondition) & PredicateBrand<"sql">;
|
|
25
|
+
export type SqlPredicate = (ColumnCondition | RawCondition | DeferredCondition) & PredicateBrand<"sql">;
|
|
26
|
+
/** Boolean groups shared by both em.find and em.query predicates. */
|
|
27
|
+
export type ConditionTree<C> = C | AndCondition<ConditionTree<C>> | OrCondition<ConditionTree<C>>;
|
|
25
28
|
/** Existing hand-written conditions remain an escape hatch, but cannot accept a foreign branded predicate. */
|
|
26
29
|
export type UnbrandedPredicate = (ColumnCondition | RawCondition) & {
|
|
27
30
|
readonly [predicateBrand]?: never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.d.cts","names":[],"sources":["../../src/queries/conditions.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"conditions.d.cts","names":[],"sources":["../../src/queries/conditions.ts"],"mappings":";;qBAGa;;YAGD,eAAe,KAAK,aAAa,KAAK,YAAY;;iBAG7C,aAAa;EAC5B,KAAK,MAAM;EACX;EACA;;;iBAIe,YAAY;EAC3B,IAAI,MAAM;EACV;EACA;;;iBAIe,eAAe;YACpB,iBAAiB;;;YAIjB,mBAAmB,kBAAkB,gBAAgB;;YAGrD,gBAAgB,kBAAkB,eAAe,qBAAqB;;YAGtE,cAAc,KAAK,IAAI,aAAa,cAAc,MAAM,YAAY,cAAc;;YAGlF,sBAAsB,kBAAkB;YAA4B;;;YAGpE,eAAe,aAAa,gBAAgB,YAAY,gBAAgB,eAAe;;YAGvF,iBACR,aAAa,kBACb,YAAY,kBACZ,kBACA;;wBAGY,eAAe,kBAAkB,4BAA4B,MAAM,GAAG,MAAM,IAAI,IAAI,eAAe"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ColumnCondition, RawCondition } from "./parsedConditions.mjs";
|
|
2
|
+
import { DeferredCondition } from "./sql/Expr.mjs";
|
|
2
3
|
export declare const predicateBrand: unique symbol;
|
|
3
4
|
/** Combines conditions without tying AND/OR or optional-filter pruning to either public API. */
|
|
4
5
|
export type ConditionGroup<C> = AndCondition<C> | OrCondition<C>;
|
|
@@ -21,7 +22,9 @@ export interface PredicateBrand<K extends "domain" | "sql"> {
|
|
|
21
22
|
/** A predicate built from alias(...) for em.find and scopes. */
|
|
22
23
|
export type DomainPredicate = (ColumnCondition | RawCondition) & PredicateBrand<"domain">;
|
|
23
24
|
/** A predicate built from table(...), an SQL expression, or sql.condition. */
|
|
24
|
-
export type SqlPredicate = (ColumnCondition | RawCondition) & PredicateBrand<"sql">;
|
|
25
|
+
export type SqlPredicate = (ColumnCondition | RawCondition | DeferredCondition) & PredicateBrand<"sql">;
|
|
26
|
+
/** Boolean groups shared by both em.find and em.query predicates. */
|
|
27
|
+
export type ConditionTree<C> = C | AndCondition<ConditionTree<C>> | OrCondition<ConditionTree<C>>;
|
|
25
28
|
/** Existing hand-written conditions remain an escape hatch, but cannot accept a foreign branded predicate. */
|
|
26
29
|
export type UnbrandedPredicate = (ColumnCondition | RawCondition) & {
|
|
27
30
|
readonly [predicateBrand]?: never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.d.mts","names":[],"sources":["../../src/queries/conditions.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"conditions.d.mts","names":[],"sources":["../../src/queries/conditions.ts"],"mappings":";;qBAGa;;YAGD,eAAe,KAAK,aAAa,KAAK,YAAY;;iBAG7C,aAAa;EAC5B,KAAK,MAAM;EACX;EACA;;;iBAIe,YAAY;EAC3B,IAAI,MAAM;EACV;EACA;;;iBAIe,eAAe;YACpB,iBAAiB;;;YAIjB,mBAAmB,kBAAkB,gBAAgB;;YAGrD,gBAAgB,kBAAkB,eAAe,qBAAqB;;YAGtE,cAAc,KAAK,IAAI,aAAa,cAAc,MAAM,YAAY,cAAc;;YAGlF,sBAAsB,kBAAkB;YAA4B;;;YAGpE,eAAe,aAAa,gBAAgB,YAAY,gBAAgB,eAAe;;YAGvF,iBACR,aAAa,kBACb,YAAY,kBACZ,kBACA;;wBAGY,eAAe,kBAAkB,4BAA4B,MAAM,GAAG,MAAM,IAAI,IAAI,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.js","names":[],"sources":["../../src/queries/conditions.ts"],"sourcesContent":["import type { ColumnCondition, RawCondition } from \"src/queries/parsedConditions.ts\";\n\nexport const predicateBrand: unique symbol = Symbol(\"joist.predicate\");\n\n/** Combines conditions without tying AND/OR or optional-filter pruning to either public API. */\nexport type ConditionGroup<C> = AndCondition<C> | OrCondition<C>;\n\n/** Requires every surviving condition to match. */\nexport interface AndCondition<C> {\n and: Array<C | undefined>;\n or?: never;\n pruneIfUndefined?: \"any\" | \"all\";\n}\n\n/** Requires at least one surviving condition to match. */\nexport interface OrCondition<C> {\n or: Array<C | undefined>;\n and?: never;\n pruneIfUndefined?: \"any\" | \"all\";\n}\n\n/** Identifies which API can resolve a predicate's aliases. */\nexport interface PredicateBrand<K extends \"domain\" | \"sql\"> {\n readonly [predicateBrand]: K;\n}\n\n/** A predicate built from alias(...) for em.find and scopes. */\nexport type DomainPredicate = (ColumnCondition | RawCondition) & PredicateBrand<\"domain\">;\n\n/** A predicate built from table(...), an SQL expression, or sql.condition. */\nexport type SqlPredicate = (ColumnCondition | RawCondition) & PredicateBrand<\"sql\">;\n\n/** Existing hand-written conditions remain an escape hatch, but cannot accept a foreign branded predicate. */\nexport type UnbrandedPredicate = (ColumnCondition | RawCondition) & { readonly [predicateBrand]?: never };\n\n/** SQL predicates and nested AND/OR groups, before query-specific clauses such as EXISTS are added. */\nexport type SqlCondition = AndCondition<SqlCondition> | OrCondition<SqlCondition> | SqlPredicate | UnbrandedPredicate;\n\n/** Unbranded compiler input shared by domain filtering and SQL queries after public API validation. */\nexport type ConditionInput =\n | AndCondition<ConditionInput>\n | OrCondition<ConditionInput>\n | ColumnCondition\n | RawCondition;\n\n/** Marks a newly created predicate without changing its enumerable SQL representation. */\nexport function brandPredicate<C extends object, K extends \"domain\" | \"sql\">(cond: C, kind: K): C & PredicateBrand<K> {\n return Object.defineProperty(cond, predicateBrand, { value: kind, enumerable: false }) as C & PredicateBrand<K>;\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"conditions.js","names":[],"sources":["../../src/queries/conditions.ts"],"sourcesContent":["import type { ColumnCondition, RawCondition } from \"src/queries/parsedConditions.ts\";\nimport type { DeferredCondition } from \"src/queries/sql/Expr.ts\";\n\nexport const predicateBrand: unique symbol = Symbol(\"joist.predicate\");\n\n/** Combines conditions without tying AND/OR or optional-filter pruning to either public API. */\nexport type ConditionGroup<C> = AndCondition<C> | OrCondition<C>;\n\n/** Requires every surviving condition to match. */\nexport interface AndCondition<C> {\n and: Array<C | undefined>;\n or?: never;\n pruneIfUndefined?: \"any\" | \"all\";\n}\n\n/** Requires at least one surviving condition to match. */\nexport interface OrCondition<C> {\n or: Array<C | undefined>;\n and?: never;\n pruneIfUndefined?: \"any\" | \"all\";\n}\n\n/** Identifies which API can resolve a predicate's aliases. */\nexport interface PredicateBrand<K extends \"domain\" | \"sql\"> {\n readonly [predicateBrand]: K;\n}\n\n/** A predicate built from alias(...) for em.find and scopes. */\nexport type DomainPredicate = (ColumnCondition | RawCondition) & PredicateBrand<\"domain\">;\n\n/** A predicate built from table(...), an SQL expression, or sql.condition. */\nexport type SqlPredicate = (ColumnCondition | RawCondition | DeferredCondition) & PredicateBrand<\"sql\">;\n\n/** Boolean groups shared by both em.find and em.query predicates. */\nexport type ConditionTree<C> = C | AndCondition<ConditionTree<C>> | OrCondition<ConditionTree<C>>;\n\n/** Existing hand-written conditions remain an escape hatch, but cannot accept a foreign branded predicate. */\nexport type UnbrandedPredicate = (ColumnCondition | RawCondition) & { readonly [predicateBrand]?: never };\n\n/** SQL predicates and nested AND/OR groups, before query-specific clauses such as EXISTS are added. */\nexport type SqlCondition = AndCondition<SqlCondition> | OrCondition<SqlCondition> | SqlPredicate | UnbrandedPredicate;\n\n/** Unbranded compiler input shared by domain filtering and SQL queries after public API validation. */\nexport type ConditionInput =\n | AndCondition<ConditionInput>\n | OrCondition<ConditionInput>\n | ColumnCondition\n | RawCondition;\n\n/** Marks a newly created predicate without changing its enumerable SQL representation. */\nexport function brandPredicate<C extends object, K extends \"domain\" | \"sql\">(cond: C, kind: K): C & PredicateBrand<K> {\n return Object.defineProperty(cond, predicateBrand, { value: kind, enumerable: false }) as C & PredicateBrand<K>;\n}\n"],"mappings":";AAGA,MAAa,iBAAgC,OAAO,iBAAiB;;AA+CrE,SAAgB,eAA6D,MAAS,MAAgC;CACpH,OAAO,OAAO,eAAe,MAAM,gBAAgB;EAAE,OAAO;EAAM,YAAY;CAAM,CAAC;AACvF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_queries_conditions = require("../conditions.cjs");
|
|
3
3
|
const require_queries_skipCondition = require("../skipCondition.cjs");
|
|
4
|
-
const
|
|
4
|
+
const require_queries_sql_ParsedSqlExpression = require("./ParsedSqlExpression.cjs");
|
|
5
5
|
const require_serde_TypeInfo = require("../../serde/TypeInfo.cjs");
|
|
6
6
|
// src/queries/sql/Expr.ts
|
|
7
7
|
/**
|
|
@@ -29,53 +29,20 @@ const deferredSym = Symbol("joist.deferredCondition");
|
|
|
29
29
|
function isDeferredCondition(cond) {
|
|
30
30
|
return typeof cond === "object" && cond !== null && deferredSym in cond;
|
|
31
31
|
}
|
|
32
|
-
/** Creates a `DeferredCondition` that generates its SQL with `fn` once the query's aliases are known. */
|
|
33
|
-
function deferredCondition(fn) {
|
|
34
|
-
const cond = require_queries_conditions.brandPredicate({
|
|
35
|
-
kind: "raw",
|
|
36
|
-
aliases: [],
|
|
37
|
-
condition: "<unresolved>",
|
|
38
|
-
bindings: [],
|
|
39
|
-
pruneable: false,
|
|
40
|
-
[deferredSym]: (ctx) => {
|
|
41
|
-
const { sql, bindings, refs } = fn(ctx);
|
|
42
|
-
return {
|
|
43
|
-
...cond,
|
|
44
|
-
condition: sql,
|
|
45
|
-
bindings,
|
|
46
|
-
aliases: refs
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}, "sql");
|
|
50
|
-
return cond;
|
|
51
|
-
}
|
|
52
32
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
33
|
+
* Defers alias resolution until this predicate is parsed in a particular query.
|
|
34
|
+
*
|
|
35
|
+
* A condition can be created once and reused across em.query calls, where its sources may be
|
|
36
|
+
* assigned different SQL aliases.
|
|
55
37
|
*/
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
and: cond.and.map((c) => resolveDeferredConditions(c, ctx))
|
|
62
|
-
};
|
|
63
|
-
else if ("or" in cond && cond.or) return {
|
|
64
|
-
...cond,
|
|
65
|
-
or: cond.or.map((c) => resolveDeferredConditions(c, ctx))
|
|
66
|
-
};
|
|
67
|
-
return cond;
|
|
68
|
-
}
|
|
69
|
-
/** Concatenates SQL fragments with `sep`, keeping bindings and refs in order. */
|
|
70
|
-
function joinFragments(parts, sep) {
|
|
71
|
-
return {
|
|
72
|
-
sql: parts.map((p) => p.sql).join(sep),
|
|
73
|
-
bindings: parts.flatMap((p) => p.bindings),
|
|
74
|
-
refs: parts.flatMap((p) => p.refs)
|
|
75
|
-
};
|
|
38
|
+
function deferredCondition(fn) {
|
|
39
|
+
return require_queries_conditions.brandPredicate({
|
|
40
|
+
kind: "deferred",
|
|
41
|
+
[deferredSym]: fn
|
|
42
|
+
}, "sql");
|
|
76
43
|
}
|
|
77
44
|
/**
|
|
78
|
-
* The methods every expression shares. Subclasses provide `
|
|
45
|
+
* The methods every expression shares. Subclasses provide `parseSql`, and usually `decode`/`encode`.
|
|
79
46
|
*
|
|
80
47
|
* Table columns can override comparisons to apply column-specific conversions. Domain aliases do not
|
|
81
48
|
* implement this protocol.
|
|
@@ -91,8 +58,8 @@ var BaseExpr = class {
|
|
|
91
58
|
/** The source of a direct column reference, whose value becomes NULL under an unmatched LEFT join. */
|
|
92
59
|
get sqlSource() {}
|
|
93
60
|
/** Produces the SQL without the outer parens a subquery normally gets; only differs for subqueries. */
|
|
94
|
-
|
|
95
|
-
return this.
|
|
61
|
+
parseSqlBare(ctx) {
|
|
62
|
+
return this.parseSql(ctx);
|
|
96
63
|
}
|
|
97
64
|
/** Converts a result-set value into the domain value, i.e. an int into a tagged id. */
|
|
98
65
|
decode(value) {
|
|
@@ -129,7 +96,7 @@ var BaseExpr = class {
|
|
|
129
96
|
/** Prefixes this expression to a SQL template, retaining bindings and referenced aliases. */
|
|
130
97
|
is(strings, ...values) {
|
|
131
98
|
const suffix = new TemplateExpr(strings, values);
|
|
132
|
-
return deferredCondition((ctx) =>
|
|
99
|
+
return deferredCondition((ctx) => require_queries_sql_ParsedSqlExpression.joinSql([this.parseSql(ctx), suffix.parseSql(ctx)], " "));
|
|
133
100
|
}
|
|
134
101
|
/** Orders by this expression in ascending order. */
|
|
135
102
|
asc() {
|
|
@@ -224,43 +191,42 @@ var BaseExpr = class {
|
|
|
224
191
|
if (value === null) {
|
|
225
192
|
const not = op === "=" ? "" : op === "!=" ? "NOT " : fail(`Cannot compare ${op} to null`);
|
|
226
193
|
return deferredCondition((ctx) => {
|
|
227
|
-
const left = this.
|
|
228
|
-
return {
|
|
229
|
-
...left,
|
|
230
|
-
sql: `${left.sql} IS ${not}NULL`
|
|
231
|
-
};
|
|
194
|
+
const left = this.parseSql(ctx);
|
|
195
|
+
return require_queries_sql_ParsedSqlExpression.joinSql([left, ` IS ${not}NULL`]);
|
|
232
196
|
});
|
|
233
197
|
}
|
|
234
|
-
if (isExpr(value)) return deferredCondition((ctx) =>
|
|
198
|
+
if (isExpr(value)) return deferredCondition((ctx) => require_queries_sql_ParsedSqlExpression.joinSql([this.parseSql(ctx), asNode(value).parseSql(ctx)], ` ${op} `));
|
|
235
199
|
return deferredCondition((ctx) => {
|
|
236
|
-
const left = this.
|
|
237
|
-
return
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
200
|
+
const left = this.parseSql(ctx);
|
|
201
|
+
return require_queries_sql_ParsedSqlExpression.joinSql([
|
|
202
|
+
left,
|
|
203
|
+
` ${op} `,
|
|
204
|
+
{ value: this.encode(value) }
|
|
205
|
+
]);
|
|
242
206
|
});
|
|
243
207
|
}
|
|
244
208
|
/** `this IN (subquery)` or `this = ANY(?)` for a list; `NOT IN` / `!= ALL(?)` for `nin`. */
|
|
245
209
|
inList(op, values) {
|
|
246
210
|
if (values === void 0) return require_queries_skipCondition.skipCondition;
|
|
247
211
|
if (isExpr(values)) return deferredCondition((ctx) => {
|
|
248
|
-
const left = this.
|
|
249
|
-
const right = asNode(values).
|
|
250
|
-
return
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
212
|
+
const left = this.parseSql(ctx);
|
|
213
|
+
const right = asNode(values).parseSqlBare(ctx);
|
|
214
|
+
return require_queries_sql_ParsedSqlExpression.joinSql([left, require_queries_sql_ParsedSqlExpression.joinSql([
|
|
215
|
+
"(",
|
|
216
|
+
right,
|
|
217
|
+
")"
|
|
218
|
+
])], ` ${op} `);
|
|
254
219
|
});
|
|
255
220
|
if (!Array.isArray(values)) fail(`Expected an array or subquery for ${op}, got ${values}`);
|
|
256
|
-
const fn = op === "IN" ? "= ANY
|
|
221
|
+
const fn = op === "IN" ? "= ANY" : "!= ALL";
|
|
257
222
|
return deferredCondition((ctx) => {
|
|
258
|
-
const left = this.
|
|
259
|
-
return
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
223
|
+
const left = this.parseSql(ctx);
|
|
224
|
+
return require_queries_sql_ParsedSqlExpression.joinSql([
|
|
225
|
+
left,
|
|
226
|
+
` ${fn}(`,
|
|
227
|
+
{ value: values.map((v) => this.encode(v)) },
|
|
228
|
+
")"
|
|
229
|
+
]);
|
|
264
230
|
});
|
|
265
231
|
}
|
|
266
232
|
};
|
|
@@ -301,28 +267,27 @@ var FnExpr = class extends BaseExpr {
|
|
|
301
267
|
* Renders function arguments, aggregate ordering, and the filter in SQL binding order.
|
|
302
268
|
* Keep references from all three so aggregate-only joins are retained.
|
|
303
269
|
*/
|
|
304
|
-
|
|
305
|
-
const args =
|
|
306
|
-
const ordering =
|
|
270
|
+
parseSql(ctx) {
|
|
271
|
+
const args = require_queries_sql_ParsedSqlExpression.joinSql(this.args.map((a) => a.parseSql(ctx)), ", ");
|
|
272
|
+
const ordering = require_queries_sql_ParsedSqlExpression.joinSql((this.opts.aggregate?.orderBy ?? []).flatMap((entry) => {
|
|
307
273
|
if (entry === void 0) return [];
|
|
308
274
|
const fragment = orderByToSql(entry, ctx);
|
|
309
275
|
return fragment ? [fragment] : [];
|
|
310
276
|
}), ", ");
|
|
311
277
|
const filter = this.opts.aggregate?.filter;
|
|
312
|
-
const condition = filter === void 0 ? void 0 : ctx.
|
|
313
|
-
return
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
};
|
|
278
|
+
const condition = filter === void 0 ? void 0 : ctx.parseCondition(filter);
|
|
279
|
+
return require_queries_sql_ParsedSqlExpression.joinSql([
|
|
280
|
+
`${this.name}(${this.opts.prefix ?? ""}`,
|
|
281
|
+
args,
|
|
282
|
+
...ordering.parts.length ? [" ORDER BY ", ordering] : [],
|
|
283
|
+
")",
|
|
284
|
+
...condition ? [
|
|
285
|
+
" FILTER (WHERE ",
|
|
286
|
+
condition,
|
|
287
|
+
")"
|
|
288
|
+
] : [],
|
|
289
|
+
this.opts.suffix ?? ""
|
|
290
|
+
]);
|
|
326
291
|
}
|
|
327
292
|
decode(value) {
|
|
328
293
|
if (value === null || value === void 0) return value;
|
|
@@ -361,12 +326,14 @@ var OperatorExpr = class extends BaseExpr {
|
|
|
361
326
|
get sqlSource() {
|
|
362
327
|
return this.left.sqlSource;
|
|
363
328
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
329
|
+
parseSql(ctx) {
|
|
330
|
+
return require_queries_sql_ParsedSqlExpression.joinSql([
|
|
331
|
+
"(",
|
|
332
|
+
this.left.parseSql(ctx),
|
|
333
|
+
` ${this.op} `,
|
|
334
|
+
this.right.parseSql(ctx),
|
|
335
|
+
")"
|
|
336
|
+
]);
|
|
370
337
|
}
|
|
371
338
|
};
|
|
372
339
|
/** A bound literal, i.e. the `?` in `coalesce(x, ?)`. */
|
|
@@ -379,12 +346,8 @@ var BindingExpr = class extends BaseExpr {
|
|
|
379
346
|
get sqlNullable() {
|
|
380
347
|
return this.value === null || this.value === void 0;
|
|
381
348
|
}
|
|
382
|
-
|
|
383
|
-
return {
|
|
384
|
-
sql: "?",
|
|
385
|
-
bindings: [this.value],
|
|
386
|
-
refs: []
|
|
387
|
-
};
|
|
349
|
+
parseSql() {
|
|
350
|
+
return require_queries_sql_ParsedSqlExpression.joinSql([{ value: this.value }]);
|
|
388
351
|
}
|
|
389
352
|
};
|
|
390
353
|
/** An unmodeled column on a known source, i.e. `a.column("ts_search")`. */
|
|
@@ -399,13 +362,9 @@ var RefExpr = class extends BaseExpr {
|
|
|
399
362
|
get sqlSource() {
|
|
400
363
|
return this.handle;
|
|
401
364
|
}
|
|
402
|
-
|
|
365
|
+
parseSql(ctx) {
|
|
403
366
|
const alias = ctx.aliasFor(this.handle);
|
|
404
|
-
return
|
|
405
|
-
sql: `${require_queries_sql_keywords.safeKq(alias)}.${require_queries_sql_keywords.safeKq(this.column)}`,
|
|
406
|
-
bindings: [],
|
|
407
|
-
refs: [alias]
|
|
408
|
-
};
|
|
367
|
+
return require_queries_sql_ParsedSqlExpression.columnSql(alias, this.column);
|
|
409
368
|
}
|
|
410
369
|
};
|
|
411
370
|
/**
|
|
@@ -427,38 +386,29 @@ var TemplateExpr = class extends BaseExpr {
|
|
|
427
386
|
this.strings = strings;
|
|
428
387
|
this.values = values;
|
|
429
388
|
}
|
|
430
|
-
|
|
389
|
+
parseSql(ctx) {
|
|
431
390
|
const parts = [];
|
|
432
391
|
this.strings.forEach((s, i) => {
|
|
433
|
-
parts.push(
|
|
434
|
-
sql: s,
|
|
435
|
-
bindings: [],
|
|
436
|
-
refs: []
|
|
437
|
-
});
|
|
392
|
+
parts.push(s);
|
|
438
393
|
if (i < this.values.length) parts.push(interpolationToSql(this.values[i], ctx));
|
|
439
394
|
});
|
|
440
|
-
return
|
|
395
|
+
return {
|
|
396
|
+
kind: "raw",
|
|
397
|
+
parts
|
|
398
|
+
};
|
|
441
399
|
}
|
|
442
400
|
};
|
|
443
401
|
/** Turns one `${...}` of a `sql` template into SQL: an expression, a condition, or a bound value. */
|
|
444
402
|
function interpolationToSql(value, ctx) {
|
|
445
|
-
if (isExpr(value)) return asNode(value).
|
|
446
|
-
else if (isConditionLike(value)) return ctx.
|
|
447
|
-
|
|
448
|
-
bindings: [],
|
|
449
|
-
refs: []
|
|
450
|
-
};
|
|
451
|
-
else return {
|
|
452
|
-
sql: "?",
|
|
453
|
-
bindings: [value],
|
|
454
|
-
refs: []
|
|
455
|
-
};
|
|
403
|
+
if (isExpr(value)) return asNode(value).parseSql(ctx);
|
|
404
|
+
else if (isConditionLike(value)) return ctx.parseCondition(value) ?? require_queries_sql_ParsedSqlExpression.joinSql(["true"]);
|
|
405
|
+
else return require_queries_sql_ParsedSqlExpression.joinSql([{ value }]);
|
|
456
406
|
}
|
|
457
|
-
/**
|
|
407
|
+
/** Recognizes boolean groups, deferred predicates, and explicit column/raw conditions. */
|
|
458
408
|
function isConditionLike(value) {
|
|
459
409
|
if (typeof value !== "object" || value === null) return false;
|
|
460
410
|
const v = value;
|
|
461
|
-
return "and" in v || "or" in v || v.kind === "column" || v.kind === "raw" || v.kind === "exists";
|
|
411
|
+
return "and" in v || "or" in v || v.kind === "deferred" || v.kind === "column" || v.kind === "raw" || v.kind === "exists";
|
|
462
412
|
}
|
|
463
413
|
/**
|
|
464
414
|
* Resolves the SQL result type of supported numeric aggregates; other overloads remain unknown.
|
|
@@ -531,12 +481,9 @@ function orderByToSql(o, ctx) {
|
|
|
531
481
|
if (o.order === void 0) return void 0;
|
|
532
482
|
if (o.order !== "ASC" && o.order !== "DESC") return fail(`Invalid orderBy direction '${o.order}'`);
|
|
533
483
|
if (o.nulls !== void 0 && o.nulls !== "first" && o.nulls !== "last") return fail(`Invalid orderBy nulls '${o.nulls}'`);
|
|
534
|
-
const fragment = o.sort.
|
|
484
|
+
const fragment = o.sort.parseSql(ctx);
|
|
535
485
|
const nulls = o.nulls ? ` NULLS ${o.nulls.toUpperCase()}` : "";
|
|
536
|
-
return {
|
|
537
|
-
...fragment,
|
|
538
|
-
sql: `${fragment.sql} ${o.order}${nulls}`
|
|
539
|
-
};
|
|
486
|
+
return require_queries_sql_ParsedSqlExpression.joinSql([fragment, ` ${o.order}${nulls}`]);
|
|
540
487
|
}
|
|
541
488
|
function identity(value) {
|
|
542
489
|
return value;
|
|
@@ -558,9 +505,7 @@ exports.interpolationToSql = interpolationToSql;
|
|
|
558
505
|
exports.isConditionLike = isConditionLike;
|
|
559
506
|
exports.isDeferredCondition = isDeferredCondition;
|
|
560
507
|
exports.isExpr = isExpr;
|
|
561
|
-
exports.joinFragments = joinFragments;
|
|
562
508
|
exports.orderByToSql = orderByToSql;
|
|
563
|
-
exports.resolveDeferredConditions = resolveDeferredConditions;
|
|
564
509
|
exports.selectKeyBrand = selectKeyBrand;
|
|
565
510
|
|
|
566
511
|
//# sourceMappingURL=Expr.cjs.map
|