11import { HttpApiBuilder } from "@effect/platform" ;
22import { AuthWorkspace , SyncApi } from "@local/sync" ;
33import { SnapshotToLoroDoc } from "@local/sync/loro" ;
4- import { and , desc , eq } from "drizzle-orm" ;
4+ import { and , desc , eq , gt , isNull , or } from "drizzle-orm" ;
55import { Array , Effect , Layer , Schema } from "effect" ;
66import { tokenTable , workspaceTable } from "../db/schema" ;
77import { AuthorizationLive } from "../middleware/authorization" ;
@@ -24,8 +24,7 @@ export const SyncDataGroupLive = HttpApiBuilder.group(
2424
2525 yield * Effect . log ( `Pushing workspace ${ workspaceId } ` ) ;
2626
27- doc . import ( workspace . snapshot ) ; // 🪄
28-
27+ doc . import ( workspace . snapshot ) ;
2928 const newSnapshot = yield * Schema . encode ( SnapshotToLoroDoc ) ( doc ) ;
3029
3130 const newWorkspace = yield * query ( {
@@ -69,7 +68,15 @@ export const SyncDataGroupLive = HttpApiBuilder.group(
6968 . where (
7069 and (
7170 eq ( tokenTable . workspaceId , workspaceId ) ,
72- eq ( tokenTable . clientId , clientId )
71+ eq ( tokenTable . clientId , clientId ) ,
72+ or (
73+ isNull ( tokenTable . revokedAt ) ,
74+ gt ( tokenTable . revokedAt , new Date ( ) )
75+ ) ,
76+ or (
77+ isNull ( tokenTable . expiresAt ) ,
78+ gt ( tokenTable . expiresAt , new Date ( ) )
79+ )
7380 )
7481 )
7582 . orderBy ( desc ( tokenTable . issuedAt ) )
0 commit comments