@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 995 B
Source Map (JSON)
{"version":3,"file":"tenant-scope.mjs","names":[],"sources":["../../../../src/libs/db/query-builder/tenant-scope.ts"],"sourcesContent":["import type { ReferenceExpression, SelectQueryBuilder } from \"kysely\";\n\n/**\n * Scopes a select query to a tenant. Rows with a NULL tenant are treated as global\n * and are included with tenant-scoped reads. Global reads remain unscoped.\n */\nconst applyTenantScope = <DB, TB extends keyof DB, O>(\n\tquery: SelectQueryBuilder<DB, TB, O>,\n\tprops: {\n\t\ttenantKey: string | null | undefined;\n\t\tcolumn: ReferenceExpression<DB, TB>;\n\t},\n) => {\n\tif (props.tenantKey == null) return query;\n\treturn query.where((eb) =>\n\t\teb.or([\n\t\t\teb(props.column, \"=\", props.tenantKey),\n\t\t\teb(props.column, \"is\", null),\n\t\t]),\n\t);\n};\n\nexport default applyTenantScope;\n"],"mappings":"AAMA,MAAM,GACL,EACA,IAKI,EAAM,WAAa,KAAa,EAC7B,EAAM,MAAO,GACnB,EAAG,GAAG,CACL,EAAG,EAAM,OAAQ,IAAK,EAAM,SAAS,EACrC,EAAG,EAAM,OAAQ,KAAM,IAAI,CAC5B,CAAC,CACF"}