-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename caller to client, and some improvements
- Loading branch information
Showing
26 changed files
with
330 additions
and
296 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
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
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,10 @@ | ||
import type { Lazy } from './lazy' | ||
import type { ANY_PROCEDURE } from './procedure' | ||
import { lazy } from './lazy' | ||
import { createLazyProcedureFormAnyLazy } from './lazy-utils' | ||
|
||
it('createLazyProcedureFormAnyLazy return a Lazy<ANY_PROCEDURE>', async () => { | ||
const lazyPing = lazy(() => Promise.resolve({ default: {} as unknown })) | ||
const lazyProcedure = createLazyProcedureFormAnyLazy(lazyPing) | ||
expectTypeOf(lazyProcedure).toEqualTypeOf<Lazy<ANY_PROCEDURE>>() | ||
}) |
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,37 @@ | ||
import { ContractProcedure } from '@orpc/contract' | ||
import { isLazy, lazy, unlazy } from './lazy' | ||
import { createLazyProcedureFormAnyLazy } from './lazy-utils' | ||
import { Procedure } from './procedure' | ||
|
||
describe('createLazyProcedureFormAnyLazy', () => { | ||
const ping = new Procedure({ | ||
contract: new ContractProcedure({ | ||
InputSchema: undefined, | ||
OutputSchema: undefined, | ||
}), | ||
func: vi.fn(), | ||
}) | ||
|
||
it('return a Lazy<ANY_PROCEDURE>', async () => { | ||
const lazyPing = lazy(() => Promise.resolve({ default: ping })) | ||
|
||
const lazyProcedure = createLazyProcedureFormAnyLazy(lazyPing) | ||
|
||
expect(lazyProcedure).toSatisfy(isLazy) | ||
expect(unlazy(lazyProcedure)).resolves.toEqual({ default: ping }) | ||
}) | ||
|
||
it('throw un unlazy non-procedure', () => { | ||
const lazyPing = lazy(() => Promise.resolve({ default: {} as unknown })) | ||
const lazyProcedure = createLazyProcedureFormAnyLazy(lazyPing) | ||
|
||
expect(unlazy(lazyProcedure)).rejects.toThrow('Expected a lazy<procedure> but got lazy<unknown>') | ||
}) | ||
|
||
it('flat lazy', () => { | ||
const lazyPing = lazy(() => Promise.resolve({ default: lazy(() => Promise.resolve({ default: ping })) })) | ||
const lazyProcedure = createLazyProcedureFormAnyLazy(lazyPing) | ||
|
||
expect(unlazy(lazyProcedure)).resolves.toEqual({ default: ping }) | ||
}) | ||
}) |
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,21 @@ | ||
import type { Lazy } from './lazy' | ||
import { flatLazy, lazy, unlazy } from './lazy' | ||
import { type ANY_PROCEDURE, isProcedure } from './procedure' | ||
|
||
export function createLazyProcedureFormAnyLazy(lazied: Lazy<any>): Lazy<ANY_PROCEDURE> { | ||
const lazyProcedure = lazy(async () => { | ||
const { default: maybeProcedure } = await unlazy(flatLazy(lazied)) | ||
|
||
if (!isProcedure(maybeProcedure)) { | ||
throw new Error(` | ||
Expected a lazy<procedure> but got lazy<unknown>. | ||
This should be caught by TypeScript compilation. | ||
Please report this issue if this makes you feel uncomfortable. | ||
`) | ||
} | ||
|
||
return { default: maybeProcedure } | ||
}) | ||
|
||
return lazyProcedure | ||
} |
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
Oops, something went wrong.