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

Function statement

packages/infra/src/Store/Cosmos/query.ts:65–146  ·  view source on GitHub ↗
(x: FilterR, i: number)

Source from the content-addressed store, hash-verified

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 }))`
99
100 case "includes-all":
101 return `ARRAY_CONTAINS_ALL(${k}, ${
102 (x.value as unknown as readonly unknown[]).map((_, i) => `${v}__${i}`).join(", ")
103 })`
104 case "notIncludes-all":
105 return `(NOT ARRAY_CONTAINS_ALL(${k}, ${
106 (x.value as unknown as readonly unknown[]).map((_, i) => `${v}__${i}`).join(", ")
107 }))`
108
109 case "contains":
110 return `CONTAINS(${k}, ${v}, true)`
111
112 case "startsWith":
113 return `STARTSWITH(${k}, ${v}, true)`
114 case "endsWith":
115 return `ENDSWITH(${k}, ${v}, true)`
116 case "notContains":
117 return `NOT(CONTAINS(${k}, ${v}, true))`
118 case "notStartsWith":
119 return `NOT(STARTSWITH(${k}, ${v}, true))`
120 case "notEndsWith":
121 return `NOT(ENDSWITH(${k}, ${v}, true))`
122 }

Callers 1

printFunction · 0.70

Calls 5

assertUnreachableFunction · 0.90
dottedToAccessFunction · 0.85
joinMethod · 0.80
splitMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…