MCPcopy Create free account
hub / github.com/effect-app/libs / buildWhereCosmosQuery3

Function buildWhereCosmosQuery3

packages/infra/src/Store/Cosmos/query.ts:41–475  ·  view source on GitHub ↗
(
  idKey: PropertyKey,
  filter: readonly FilterResult[],
  name: string,
  defaultValues: Record<string, unknown>,
  select?: NonEmptyReadonlyArray<
    string | {
      key: string
      subKeys: readonly string[]
    } | {
      key: string
      computed: ComputedProjectionIrExpression
    } | {
      key: string
      path: string
    } | {
      key: string
      aggregate: AggregateIrExpression
    }
  >,
  order?: NonEmptyReadonlyArray<{ key: string; direction: "ASC" | "DESC" }>,
  skip?: number,
  limit?: number
)

Source from the content-addressed store, hash-verified

39 .join("")
40
41export function buildWhereCosmosQuery3(
42 idKey: PropertyKey,
43 filter: readonly FilterResult[],
44 name: string,
45 defaultValues: Record<string, unknown>,
46 select?: NonEmptyReadonlyArray<
47 string | {
48 key: string
49 subKeys: readonly string[]
50 } | {
51 key: string
52 computed: ComputedProjectionIrExpression
53 } | {
54 key: string
55 path: string
56 } | {
57 key: string
58 aggregate: AggregateIrExpression
59 }
60 >,
61 order?: NonEmptyReadonlyArray<{ key: string; direction: "ASC" | "DESC" }>,
62 skip?: number,
63 limit?: number
64) {
65 const statement = (x: FilterR, i: number) => {
66 if (x.path === idKey) {
67 x = { ...x, path: "id" }
68 }
69 let k = x.path.includes(".-1.")
70 ? dottedToAccess(`${x.path.split(".-1.")[0]}.${x.path.split(".-1.")[1]!}`)
71 : x.path.endsWith(".length")
72 ? `ARRAY_LENGTH(${dottedToAccess(`f.${x.path.split(".length")[0]}`)})`
73 : dottedToAccess(`f.${x.path}`)
74
75 // would have to map id, but shouldnt allow id in defaultValues anyway..
76 k = x.path in defaultValues ? `(${k} ?? ${JSON.stringify(defaultValues[x.path])})` : k
77
78 const v = "@v" + i
79
80 switch (x.op) {
81 case "in":
82 return `ARRAY_CONTAINS(${v}, ${k})`
83 case "notIn":
84 return `(NOT ARRAY_CONTAINS(${v}, ${k}))`
85
86 case "includes":
87 return `ARRAY_CONTAINS(${k}, ${v})`
88 case "notIncludes":
89 return `(NOT ARRAY_CONTAINS(${k}, ${v}))`
90
91 case "includes-any":
92 return `ARRAY_CONTAINS_ANY(${k}, ${
93 (x.value as unknown as readonly unknown[]).map((_, i) => `${v}__${i}`).join(", ")
94 })`
95 case "notIncludes-any":
96 return `(NOT ARRAY_CONTAINS_ANY(${k}, ${
97 (x.value as unknown as readonly unknown[]).map((_, i) => `${v}__${i}`).join(", ")
98 }))`

Callers 2

Cosmos.tsFile · 0.90

Calls 9

getValuesFunction · 0.85
dottedToAccessFunction · 0.85
buildSelectListFunction · 0.85
orderExprFunction · 0.85
someMethod · 0.80
filterMethod · 0.80
joinMethod · 0.80
printFunction · 0.70
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…