-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
854 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import type { RPCRequestParams, RPCResponseResult } from '../types'; | ||
import type GestaltGraph from 'gestalts/GestaltGraph'; | ||
import type { DB } from '@matrixai/db'; | ||
import type { IdentityId, ProviderId } from 'ids/index'; | ||
import type { GestaltAction } from 'gestalts/types'; | ||
import { UnaryCaller } from '../../RPC/callers'; | ||
import { UnaryHandler } from '../../RPC/handlers'; | ||
import { validateSync } from '../../validation/index'; | ||
import { matchSync } from '../../utils/index'; | ||
import * as validationUtils from '../../validation/utils'; | ||
|
||
const gestaltsActionsGetByIdentityCaller = new UnaryCaller< | ||
RPCRequestParams<{ | ||
providerId: string; | ||
identityId: string; | ||
}>, | ||
RPCResponseResult<{ | ||
actionsList: Array<string>; | ||
}> | ||
>(); | ||
|
||
class GestaltsActionsGetByIdentityHandler extends UnaryHandler< | ||
{ | ||
gestaltGraph: GestaltGraph; | ||
db: DB; | ||
}, | ||
RPCRequestParams<{ | ||
providerId: string; | ||
identityId: string; | ||
}>, | ||
RPCResponseResult<{ | ||
actionsList: Array<GestaltAction>; | ||
}> | ||
> { | ||
public async handle( | ||
input: RPCRequestParams<{ | ||
providerId: string; | ||
identityId: string; | ||
}>, | ||
): Promise< | ||
RPCResponseResult<{ | ||
actionsList: Array<GestaltAction>; | ||
}> | ||
> { | ||
const { db, gestaltGraph } = this.container; | ||
const { | ||
providerId, | ||
identityId, | ||
}: { providerId: ProviderId; identityId: IdentityId } = validateSync( | ||
(keyPath, value) => { | ||
return matchSync(keyPath)( | ||
[['providerId'], () => validationUtils.parseProviderId(value)], | ||
[['identityId'], () => validationUtils.parseIdentityId(value)], | ||
() => value, | ||
); | ||
}, | ||
{ | ||
providerId: input.providerId, | ||
identityId: input.identityId, | ||
}, | ||
); | ||
const result = await db.withTransactionF((tran) => | ||
gestaltGraph.getGestaltActions( | ||
['identity', [providerId, identityId]], | ||
tran, | ||
), | ||
); | ||
|
||
return { | ||
actionsList: Object.keys(result) as Array<GestaltAction>, | ||
}; | ||
} | ||
} | ||
|
||
export { | ||
gestaltsActionsGetByIdentityCaller, | ||
GestaltsActionsGetByIdentityHandler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { RPCRequestParams, RPCResponseResult } from '../types'; | ||
import type GestaltGraph from 'gestalts/GestaltGraph'; | ||
import type { DB } from '@matrixai/db'; | ||
import type { GestaltAction } from 'gestalts/types'; | ||
import type { NodeId, NodeIdEncoded } from 'ids/index'; | ||
import { UnaryCaller } from '../../RPC/callers'; | ||
import { UnaryHandler } from '../../RPC/handlers'; | ||
import { validateSync } from '../../validation/index'; | ||
import { matchSync } from '../../utils/index'; | ||
import * as validationUtils from '../../validation/utils'; | ||
|
||
const gestaltsActionsGetByNodeCaller = new UnaryCaller< | ||
RPCRequestParams<{ | ||
nodeIdEncoded: NodeIdEncoded; | ||
}>, | ||
RPCResponseResult<{ | ||
actionsList: Array<GestaltAction>; | ||
}> | ||
>(); | ||
|
||
class GestaltsActionsGetByNodeHandler extends UnaryHandler< | ||
{ | ||
gestaltGraph: GestaltGraph; | ||
db: DB; | ||
}, | ||
RPCRequestParams<{ | ||
nodeIdEncoded: NodeIdEncoded; | ||
}>, | ||
RPCResponseResult<{ | ||
actionsList: Array<GestaltAction>; | ||
}> | ||
> { | ||
public async handle( | ||
input: RPCRequestParams<{ | ||
nodeIdEncoded: NodeIdEncoded; | ||
}>, | ||
): Promise< | ||
RPCResponseResult<{ | ||
actionsList: Array<GestaltAction>; | ||
}> | ||
> { | ||
const { db, gestaltGraph } = this.container; | ||
const { nodeId }: { nodeId: NodeId } = validateSync( | ||
(keyPath, value) => { | ||
return matchSync(keyPath)( | ||
[['nodeId'], () => validationUtils.parseNodeId(value)], | ||
() => value, | ||
); | ||
}, | ||
{ | ||
nodeId: input.nodeIdEncoded, | ||
}, | ||
); | ||
const result = await db.withTransactionF((tran) => | ||
gestaltGraph.getGestaltActions(['node', nodeId], tran), | ||
); | ||
|
||
return { | ||
actionsList: Object.keys(result) as Array<GestaltAction>, | ||
}; | ||
} | ||
} | ||
|
||
export { gestaltsActionsGetByNodeCaller, GestaltsActionsGetByNodeHandler }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import type { RPCRequestParams, RPCResponseResult } from '../types'; | ||
import type { DB } from '@matrixai/db'; | ||
import type { IdentityId, ProviderId } from 'ids/index'; | ||
import type { GestaltAction } from '../../gestalts/types'; | ||
import type GestaltGraph from 'gestalts/GestaltGraph'; | ||
import { UnaryCaller } from '../../RPC/callers'; | ||
import { UnaryHandler } from '../../RPC/handlers'; | ||
import { validateSync } from '../../validation/index'; | ||
import { matchSync } from '../../utils/index'; | ||
import * as validationUtils from '../../validation/utils'; | ||
|
||
const gestaltsActionsSetByIdentityCaller = new UnaryCaller< | ||
RPCRequestParams<{ | ||
action: GestaltAction; | ||
providerId: string; | ||
identityId: string; | ||
}>, | ||
RPCResponseResult | ||
>(); | ||
|
||
class GestaltsActionsSetByIdentityHandler extends UnaryHandler< | ||
{ | ||
gestaltGraph: GestaltGraph; | ||
db: DB; | ||
}, | ||
RPCRequestParams<{ | ||
action: GestaltAction; | ||
providerId: string; | ||
identityId: string; | ||
}>, | ||
RPCResponseResult | ||
> { | ||
public async handle( | ||
input: RPCRequestParams<{ | ||
action: GestaltAction; | ||
providerId: string; | ||
identityId: string; | ||
}>, | ||
): Promise<RPCResponseResult> { | ||
const { db, gestaltGraph } = this.container; | ||
const { | ||
action, | ||
providerId, | ||
identityId, | ||
}: { | ||
action: GestaltAction; | ||
providerId: ProviderId; | ||
identityId: IdentityId; | ||
} = validateSync( | ||
(keyPath, value) => { | ||
return matchSync(keyPath)( | ||
[['action'], () => validationUtils.parseGestaltAction(value)], | ||
[['providerId'], () => validationUtils.parseProviderId(value)], | ||
[['identityId'], () => validationUtils.parseIdentityId(value)], | ||
() => value, | ||
); | ||
}, | ||
{ | ||
action: input.action, | ||
providerId: input.providerId, | ||
identityId: input.identityId, | ||
}, | ||
); | ||
await db.withTransactionF((tran) => | ||
gestaltGraph.setGestaltAction( | ||
['identity', [providerId, identityId]], | ||
action, | ||
tran, | ||
), | ||
); | ||
return {}; | ||
} | ||
} | ||
|
||
export { | ||
gestaltsActionsSetByIdentityCaller, | ||
GestaltsActionsSetByIdentityHandler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { RPCRequestParams, RPCResponseResult } from '../types'; | ||
import type { DB } from '@matrixai/db'; | ||
import type { GestaltAction } from '../../gestalts/types'; | ||
import type GestaltGraph from 'gestalts/GestaltGraph'; | ||
import type { NodeId } from 'ids/index'; | ||
import { UnaryCaller } from '../../RPC/callers'; | ||
import { UnaryHandler } from '../../RPC/handlers'; | ||
import { validateSync } from '../../validation/index'; | ||
import { matchSync } from '../../utils/index'; | ||
import * as validationUtils from '../../validation/utils'; | ||
|
||
const gestaltsActionsSetByNodeCaller = new UnaryCaller< | ||
RPCRequestParams<{ | ||
action: GestaltAction; | ||
nodeIdEncoded: string; | ||
}>, | ||
RPCResponseResult | ||
>(); | ||
|
||
class GestaltsActionsSetByNodeHandler extends UnaryHandler< | ||
{ | ||
gestaltGraph: GestaltGraph; | ||
db: DB; | ||
}, | ||
RPCRequestParams<{ | ||
action: GestaltAction; | ||
nodeIdEncoded: string; | ||
}>, | ||
RPCResponseResult | ||
> { | ||
public async handle( | ||
input: RPCRequestParams<{ | ||
action: GestaltAction; | ||
nodeIdEncoded: string; | ||
}>, | ||
): Promise<RPCResponseResult> { | ||
const { db, gestaltGraph } = this.container; | ||
const { nodeId, action }: { nodeId: NodeId; action: GestaltAction } = | ||
validateSync( | ||
(keyPath, value) => { | ||
return matchSync(keyPath)( | ||
[['nodeId'], () => validationUtils.parseNodeId(value)], | ||
[['action'], () => validationUtils.parseGestaltAction(value)], | ||
() => value, | ||
); | ||
}, | ||
{ | ||
nodeId: input.nodeIdEncoded, | ||
action: input.action, | ||
}, | ||
); | ||
await db.withTransactionF((tran) => | ||
gestaltGraph.setGestaltAction(['node', nodeId], action, tran), | ||
); | ||
return {}; | ||
} | ||
} | ||
|
||
export { gestaltsActionsSetByNodeCaller, GestaltsActionsSetByNodeHandler }; |
Oops, something went wrong.