MCPcopy Create free account
hub / github.com/bytebase/bytebase / convertToCELString

Function convertToCELString

frontend/src/utils/issue/cel.ts:253–352  ·  view source on GitHub ↗
(
  conditions: (
    | DatabaseLevelCondition
    | SchemaLevelCondition
    | TableLevelCondition
    | ColumnLevelCondition
  )[]
)

Source from the content-addressed store, hash-verified

251};
252
253const convertToCELString = (
254 conditions: (
255 | DatabaseLevelCondition
256 | SchemaLevelCondition
257 | TableLevelCondition
258 | ColumnLevelCondition
259 )[]
260): string => {
261 if (conditions.length === 0) {
262 return "";
263 }
264
265 const getArrayExpressionString = (resource: string, arr: string[]) => {
266 if (arr.length === 0) {
267 return "";
268 }
269 return `${resource} in ${JSON.stringify(arr)}`;
270 };
271
272 const getStringExpressionString = (resource: string, value: string) => {
273 if (!value) {
274 return "";
275 }
276 return `${resource} == "${value}"`;
277 };
278
279 function buildCondition(
280 condition:
281 | DatabaseLevelCondition
282 | SchemaLevelCondition
283 | TableLevelCondition
284 | ColumnLevelCondition
285 ): string {
286 const databaseExpression = `${CEL_ATTRIBUTE_RESOURCE_DATABASE} == "${condition.database}"`;
287 if ("column" in condition) {
288 return [
289 databaseExpression,
290 getStringExpressionString(
291 CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME,
292 condition.schema
293 ),
294 getStringExpressionString(
295 CEL_ATTRIBUTE_RESOURCE_TABLE_NAME,
296 condition.table
297 ),
298 getArrayExpressionString(
299 CEL_ATTRIBUTE_RESOURCE_COLUMN_NAME,
300 condition.column
301 ),
302 ]
303 .filter((str) => str)
304 .join(" && ");
305 } else if ("table" in condition) {
306 return [
307 databaseExpression,
308 getStringExpressionString(
309 CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME,
310 condition.schema

Callers 1

Calls 1

buildGroupFunction · 0.85

Tested by

no test coverage detected