@passlock/client 0.9.6 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/authentication/authenticate.d.ts +6 -5
- package/dist/authentication/authenticate.d.ts.map +1 -1
- package/dist/authentication/authenticate.fixture.d.ts +8 -5
- package/dist/authentication/authenticate.fixture.d.ts.map +1 -1
- package/dist/authentication/authenticate.fixture.js +12 -7
- package/dist/authentication/authenticate.fixture.js.map +1 -1
- package/dist/authentication/authenticate.js +6 -6
- package/dist/authentication/authenticate.js.map +1 -1
- package/dist/authentication/authenticate.test.js +4 -4
- package/dist/capabilities/capabilities.js +3 -3
- package/dist/connection/connection.fixture.d.ts +1 -1
- package/dist/connection/connection.fixture.d.ts.map +1 -1
- package/dist/connection/connection.fixture.js +13 -10
- package/dist/connection/connection.fixture.js.map +1 -1
- package/dist/connection/connection.js +3 -3
- package/dist/effect.d.ts +21 -5
- package/dist/effect.d.ts.map +1 -1
- package/dist/effect.js +12 -9
- package/dist/effect.js.map +1 -1
- package/dist/email/email.d.ts +24 -8
- package/dist/email/email.d.ts.map +1 -1
- package/dist/email/email.fixture.d.ts +8 -8
- package/dist/email/email.fixture.d.ts.map +1 -1
- package/dist/email/email.fixture.js +12 -10
- package/dist/email/email.fixture.js.map +1 -1
- package/dist/email/email.js +5 -5
- package/dist/email/email.js.map +1 -1
- package/dist/email/email.test.js +4 -4
- package/dist/email/email.test.js.map +1 -1
- package/dist/index.d.ts +52 -37
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -14
- package/dist/index.js.map +1 -1
- package/dist/registration/register.d.ts +3 -4
- package/dist/registration/register.d.ts.map +1 -1
- package/dist/registration/register.fixture.d.ts +4 -4
- package/dist/registration/register.fixture.d.ts.map +1 -1
- package/dist/registration/register.fixture.js +12 -8
- package/dist/registration/register.fixture.js.map +1 -1
- package/dist/registration/register.js +4 -13
- package/dist/registration/register.js.map +1 -1
- package/dist/social/social.d.ts +22 -0
- package/dist/social/social.d.ts.map +1 -0
- package/dist/social/social.js +29 -0
- package/dist/social/social.js.map +1 -0
- package/dist/storage/storage.d.ts +1 -1
- package/dist/storage/storage.d.ts.map +1 -1
- package/dist/storage/storage.fixture.d.ts +1 -2
- package/dist/storage/storage.fixture.d.ts.map +1 -1
- package/dist/storage/storage.fixture.js +1 -16
- package/dist/storage/storage.fixture.js.map +1 -1
- package/dist/storage/storage.js +4 -3
- package/dist/storage/storage.js.map +1 -1
- package/dist/test/fixtures.d.ts +4 -0
- package/dist/test/fixtures.d.ts.map +1 -1
- package/dist/test/fixtures.js +13 -9
- package/dist/test/fixtures.js.map +1 -1
- package/dist/user/user.d.ts +9 -2
- package/dist/user/user.d.ts.map +1 -1
- package/dist/user/user.fixture.d.ts +3 -2
- package/dist/user/user.fixture.d.ts.map +1 -1
- package/dist/user/user.fixture.js +13 -9
- package/dist/user/user.fixture.js.map +1 -1
- package/dist/user/user.js +11 -1
- package/dist/user/user.js.map +1 -1
- package/package.json +14 -13
- package/src/authentication/authenticate.fixture.ts +14 -7
- package/src/authentication/authenticate.test.ts +4 -4
- package/src/authentication/authenticate.ts +15 -12
- package/src/capabilities/capabilities.ts +3 -3
- package/src/connection/connection.fixture.ts +14 -11
- package/src/connection/connection.ts +4 -4
- package/src/effect.ts +28 -26
- package/src/email/email.fixture.ts +15 -13
- package/src/email/email.test.ts +4 -4
- package/src/email/email.ts +13 -12
- package/src/index.ts +91 -34
- package/src/registration/register.fixture.ts +12 -8
- package/src/registration/register.test.ts +8 -43
- package/src/registration/register.ts +8 -24
- package/src/social/social.ts +86 -0
- package/src/storage/storage.fixture.ts +2 -19
- package/src/storage/storage.ts +5 -4
- package/src/test/fixtures.ts +15 -10
- package/src/user/user.fixture.ts +14 -11
- package/src/user/user.ts +22 -3
- package/dist/exit.d.ts +0 -64
- package/dist/exit.d.ts.map +0 -1
- package/dist/exit.js +0 -106
- package/dist/exit.js.map +0 -1
package/src/test/fixtures.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { Principal } from '@passlock/shared/dist/schema/schema.js'
|
|
|
2
2
|
import { Effect as E, Layer as L } from 'effect'
|
|
3
3
|
import { Capabilities } from '../capabilities/capabilities.js'
|
|
4
4
|
import { StorageService, type StoredToken } from '../storage/storage.js'
|
|
5
|
+
import { BadRequest } from '@passlock/shared/dist/error/error.js'
|
|
6
|
+
import { PreConnectRes } from '@passlock/shared/dist/rpc/connection.js'
|
|
5
7
|
|
|
6
8
|
export const session = 'session'
|
|
7
9
|
export const token = 'token'
|
|
@@ -11,15 +13,15 @@ export const expireAt = Date.now() + 10000
|
|
|
11
13
|
|
|
12
14
|
export const principal: Principal = {
|
|
13
15
|
token: 'token',
|
|
14
|
-
|
|
16
|
+
user: {
|
|
15
17
|
id: '1',
|
|
16
18
|
email: 'john.doe@gmail.com',
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
givenName: 'john',
|
|
20
|
+
familyName: 'doe',
|
|
19
21
|
emailVerified: false,
|
|
20
22
|
},
|
|
21
23
|
authStatement: {
|
|
22
|
-
authType: '
|
|
24
|
+
authType: 'passkey',
|
|
23
25
|
userVerified: false,
|
|
24
26
|
authTimestamp: new Date(0),
|
|
25
27
|
},
|
|
@@ -29,9 +31,9 @@ export const principal: Principal = {
|
|
|
29
31
|
export const capabilitiesTest = L.succeed(
|
|
30
32
|
Capabilities,
|
|
31
33
|
Capabilities.of({
|
|
32
|
-
passkeySupport: E.
|
|
34
|
+
passkeySupport: E.void,
|
|
33
35
|
isPasskeySupport: E.succeed(true),
|
|
34
|
-
autofillSupport: E.
|
|
36
|
+
autofillSupport: E.void,
|
|
35
37
|
isAutofillSupport: E.succeed(true),
|
|
36
38
|
}),
|
|
37
39
|
)
|
|
@@ -41,10 +43,13 @@ export const storedToken: StoredToken = { token, authType, expireAt }
|
|
|
41
43
|
export const storageServiceTest = L.succeed(
|
|
42
44
|
StorageService,
|
|
43
45
|
StorageService.of({
|
|
44
|
-
storeToken: () => E.
|
|
46
|
+
storeToken: () => E.void,
|
|
45
47
|
getToken: () => E.succeed(storedToken),
|
|
46
|
-
clearToken: () => E.
|
|
47
|
-
clearExpiredToken: () => E.
|
|
48
|
-
clearExpiredTokens: E.
|
|
48
|
+
clearToken: () => E.void,
|
|
49
|
+
clearExpiredToken: () => E.void,
|
|
50
|
+
clearExpiredTokens: E.void,
|
|
49
51
|
}),
|
|
50
52
|
)
|
|
53
|
+
|
|
54
|
+
export const preConnectRes = new PreConnectRes({ warmed: true })
|
|
55
|
+
export const notImplemented = new BadRequest({ message: 'Not implemented' })
|
package/src/user/user.fixture.ts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import { BadRequest } from '@passlock/shared/dist/error/error.js'
|
|
2
1
|
import { RpcClient } from '@passlock/shared/dist/rpc/rpc.js'
|
|
3
|
-
import { IsExistingUserReq, IsExistingUserRes } from '@passlock/shared/dist/rpc/user.js'
|
|
2
|
+
import { IsExistingUserReq, IsExistingUserRes, VerifyEmailRes } from '@passlock/shared/dist/rpc/user.js'
|
|
4
3
|
import { Effect as E, Layer as L } from 'effect'
|
|
4
|
+
import * as Fixtures from '../test/fixtures.js'
|
|
5
5
|
|
|
6
6
|
export const email = 'jdoe@gmail.com'
|
|
7
|
+
export const isRegisteredReq = new IsExistingUserReq({ email })
|
|
8
|
+
export const isRegisteredRes = new IsExistingUserRes({ existingUser: false })
|
|
9
|
+
export const verifyEmailRes = new VerifyEmailRes({ principal: Fixtures.principal })
|
|
7
10
|
|
|
8
11
|
export const rpcClientTest = L.succeed(
|
|
9
12
|
RpcClient,
|
|
10
13
|
RpcClient.of({
|
|
11
14
|
preConnect: () => E.succeed({ warmed: true }),
|
|
12
15
|
isExistingUser: () => E.succeed({ existingUser: true }),
|
|
13
|
-
verifyEmail: () => E.succeed(
|
|
14
|
-
getRegistrationOptions: () => E.fail(
|
|
15
|
-
verifyRegistrationCredential: () => E.fail(
|
|
16
|
-
getAuthenticationOptions: () => E.fail(
|
|
17
|
-
verifyAuthenticationCredential: () => E.fail(
|
|
16
|
+
verifyEmail: () => E.succeed(verifyEmailRes),
|
|
17
|
+
getRegistrationOptions: () => E.fail(Fixtures.notImplemented),
|
|
18
|
+
verifyRegistrationCredential: () => E.fail(Fixtures.notImplemented),
|
|
19
|
+
getAuthenticationOptions: () => E.fail(Fixtures.notImplemented),
|
|
20
|
+
verifyAuthenticationCredential: () => E.fail(Fixtures.notImplemented),
|
|
21
|
+
registerOidc: () => E.fail(Fixtures.notImplemented),
|
|
22
|
+
authenticateOidc: () => E.fail(Fixtures.notImplemented),
|
|
23
|
+
resendVerificationEmail: () => E.fail(Fixtures.notImplemented),
|
|
18
24
|
}),
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
export const isRegisteredReq = new IsExistingUserReq({ email })
|
|
22
|
-
export const isRegisteredRes = new IsExistingUserRes({ existingUser: false })
|
|
25
|
+
)
|
package/src/user/user.ts
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Check for an existing user
|
|
3
3
|
*/
|
|
4
|
-
import type { BadRequest } from '@passlock/shared/dist/error/error.js'
|
|
4
|
+
import type { BadRequest, Disabled, NotFound } from '@passlock/shared/dist/error/error.js'
|
|
5
5
|
import { RpcClient } from '@passlock/shared/dist/rpc/rpc.js'
|
|
6
|
-
import { IsExistingUserReq } from '@passlock/shared/dist/rpc/user.js'
|
|
6
|
+
import { IsExistingUserReq, ResendEmailReq } from '@passlock/shared/dist/rpc/user.js'
|
|
7
|
+
import type { VerifyEmail } from '@passlock/shared/dist/schema/schema.js'
|
|
7
8
|
import { Context, Effect as E, Layer, flow } from 'effect'
|
|
8
9
|
|
|
9
10
|
/* Requests */
|
|
10
11
|
|
|
11
12
|
export type Email = { email: string }
|
|
13
|
+
export type ResendEmail = VerifyEmail & { userId: string }
|
|
14
|
+
|
|
15
|
+
/* Errors */
|
|
16
|
+
|
|
17
|
+
export type ResendEmailErrors = BadRequest | NotFound | Disabled
|
|
12
18
|
|
|
13
19
|
/* Service */
|
|
14
20
|
|
|
15
21
|
export type UserService = {
|
|
16
|
-
isExistingUser: (
|
|
22
|
+
isExistingUser: (request: Email) => E.Effect<boolean, BadRequest>
|
|
23
|
+
resendVerificationEmail: (request: ResendEmail) => E.Effect<void, ResendEmailErrors>
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
export const UserService = Context.GenericTag<UserService>('@services/UserService')
|
|
@@ -34,6 +41,17 @@ export const isExistingUser = (request: Email): E.Effect<boolean, BadRequest, De
|
|
|
34
41
|
})
|
|
35
42
|
}
|
|
36
43
|
|
|
44
|
+
export const resendVerificationEmail = (request: ResendEmail): E.Effect<void, ResendEmailErrors, Dependencies> => {
|
|
45
|
+
return E.gen(function* (_) {
|
|
46
|
+
yield* _(E.logInfo('Resending verification email'))
|
|
47
|
+
const rpcClient = yield* _(RpcClient)
|
|
48
|
+
|
|
49
|
+
yield* _(E.logDebug('Making RPC request'))
|
|
50
|
+
const { userId, ...verifyEmail } = request
|
|
51
|
+
yield* _(rpcClient.resendVerificationEmail(new ResendEmailReq({ userId, verifyEmail })))
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
37
55
|
/* Live */
|
|
38
56
|
|
|
39
57
|
/* v8 ignore start */
|
|
@@ -43,6 +61,7 @@ export const UserServiceLive = Layer.effect(
|
|
|
43
61
|
const context = yield* _(E.context<RpcClient>())
|
|
44
62
|
return UserService.of({
|
|
45
63
|
isExistingUser: flow(isExistingUser, E.provide(context)),
|
|
64
|
+
resendVerificationEmail: flow(resendVerificationEmail, E.provide(context))
|
|
46
65
|
})
|
|
47
66
|
}),
|
|
48
67
|
)
|
package/dist/exit.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Effect } from 'effect';
|
|
2
|
-
import { Cause, Exit as EX, Runtime } from 'effect';
|
|
3
|
-
declare const AbortError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Cause.YieldableError & {
|
|
4
|
-
readonly _tag: "AbortError";
|
|
5
|
-
} & Readonly<A>;
|
|
6
|
-
export declare class AbortError extends AbortError_base<{
|
|
7
|
-
message: string;
|
|
8
|
-
}> {
|
|
9
|
-
}
|
|
10
|
-
export declare class PasslockError extends Error {
|
|
11
|
-
readonly code: string;
|
|
12
|
-
readonly detail?: unknown;
|
|
13
|
-
constructor(args: {
|
|
14
|
-
code: string;
|
|
15
|
-
message?: string;
|
|
16
|
-
detail?: unknown;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export declare const isPasslockError: (data: unknown) => data is PasslockError;
|
|
20
|
-
type PasslockRuntime<R> = Runtime.Runtime<R>;
|
|
21
|
-
type Abort = {
|
|
22
|
-
abort?: AbortSignal;
|
|
23
|
-
};
|
|
24
|
-
type EffectFn<I, A, E, R> = (input: I) => Effect.Effect<A, E, R>;
|
|
25
|
-
type UnionFn<I, A> = (input: I & Abort) => Promise<A | PasslockError>;
|
|
26
|
-
type UnsafeFn<I, A> = (input: I & Abort) => Promise<A>;
|
|
27
|
-
/**
|
|
28
|
-
* Poor man's either - transform an Exit into a union of
|
|
29
|
-
* PasslockError | T
|
|
30
|
-
*
|
|
31
|
-
* @param exit
|
|
32
|
-
* @returns
|
|
33
|
-
*/
|
|
34
|
-
export declare const transformExit: <A, E>(exit: EX.Exit<A, E>) => PasslockError | A;
|
|
35
|
-
/**
|
|
36
|
-
* Run an effect to generate promise with an error or value
|
|
37
|
-
*
|
|
38
|
-
* @param input Effect
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
export declare const runUnion: <A, E, R>(input: Effect.Effect<A, E, R>, runtime: PasslockRuntime<R>, controller?: AbortSignal) => Promise<PasslockError | A>;
|
|
42
|
-
/**
|
|
43
|
-
* Transform a function that returns an effect to one that returns a promise with an error or value
|
|
44
|
-
*
|
|
45
|
-
* @param fn Function that returns an Effect
|
|
46
|
-
* @returns Function that returns a Promise wrapping a union
|
|
47
|
-
*/
|
|
48
|
-
export declare const makeUnionFn: <I, A, E, R>(fn: EffectFn<I, A, E, R>, runtime: PasslockRuntime<R>) => UnionFn<I, A>;
|
|
49
|
-
/**
|
|
50
|
-
* Transform an effect into one that potentially throws a PasslockError
|
|
51
|
-
*
|
|
52
|
-
* @param effect Effect
|
|
53
|
-
* @returns Promise that could throw
|
|
54
|
-
*/
|
|
55
|
-
export declare const runUnsafe: <A, E, R>(effect: Effect.Effect<A, E, R>, runtime: PasslockRuntime<R>) => Promise<A>;
|
|
56
|
-
/**
|
|
57
|
-
* Transform a function that returns an effect to one that returns a promise that could reject
|
|
58
|
-
*
|
|
59
|
-
* @param fn Function that returns an Effect
|
|
60
|
-
* @returns Function that returns a Promise that could reject
|
|
61
|
-
*/
|
|
62
|
-
export declare const makeUnsafeFn: <I, A, E, R>(fn: EffectFn<I, A, E, R>, runtime: PasslockRuntime<R>) => UnsafeFn<I, A>;
|
|
63
|
-
export {};
|
|
64
|
-
//# sourceMappingURL=exit.d.ts.map
|
package/dist/exit.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exit.d.ts","sourceRoot":"","sources":["../src/exit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,IAAI,IAAI,EAAE,EAAE,OAAO,EAAQ,MAAM,QAAQ,CAAA;;;;AAEzD,qBAAa,UAAW,SAAQ,gBAA+B;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;CAAG;AAEtF,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;gBAEb,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE;CAKvE;AAED,eAAO,MAAM,eAAe,SAAU,OAAO,0BAI5C,CAAA;AAED,KAAK,eAAe,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AAE5C,KAAK,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,WAAW,CAAA;CAAE,CAAA;AAGpC,KAAK,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;AAGhE,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,KAAK,OAAO,CAAC,CAAC,GAAG,aAAa,CAAC,CAAA;AAGrE,KAAK,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;AActD;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,kDAczB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,qFAGN,WAAW,+BAWzB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,sFAKvB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,sFAQrB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,uFAKxB,CAAA"}
|
package/dist/exit.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Data, Effect } from 'effect';
|
|
2
|
-
import { Cause, Exit as EX, Runtime, flow } from 'effect';
|
|
3
|
-
export class AbortError extends Data.TaggedError('AbortError') {
|
|
4
|
-
}
|
|
5
|
-
export class PasslockError extends Error {
|
|
6
|
-
code;
|
|
7
|
-
detail;
|
|
8
|
-
constructor(args) {
|
|
9
|
-
super(args.message);
|
|
10
|
-
this.code = args.code;
|
|
11
|
-
this.detail = args.detail;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export const isPasslockError = (data) => {
|
|
15
|
-
if (typeof data !== "object")
|
|
16
|
-
return false;
|
|
17
|
-
if (data === null)
|
|
18
|
-
return false;
|
|
19
|
-
return data instanceof PasslockError;
|
|
20
|
-
};
|
|
21
|
-
const hasTag = (data) => {
|
|
22
|
-
if (typeof data !== "object")
|
|
23
|
-
return false;
|
|
24
|
-
if (data === null)
|
|
25
|
-
return false;
|
|
26
|
-
return '_tag' in data && typeof data._tag === "string";
|
|
27
|
-
};
|
|
28
|
-
const hasMessage = (data) => {
|
|
29
|
-
if (typeof data !== "object")
|
|
30
|
-
return false;
|
|
31
|
-
if (data === null)
|
|
32
|
-
return false;
|
|
33
|
-
return 'message' in data && typeof data.message === "string";
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Poor man's either - transform an Exit into a union of
|
|
37
|
-
* PasslockError | T
|
|
38
|
-
*
|
|
39
|
-
* @param exit
|
|
40
|
-
* @returns
|
|
41
|
-
*/
|
|
42
|
-
export const transformExit = (exit) => {
|
|
43
|
-
return EX.getOrElse(exit, cause => {
|
|
44
|
-
if (Cause.isFailType(cause) && hasTag(cause.error) && hasMessage(cause.error)) {
|
|
45
|
-
return new PasslockError({ code: cause.error._tag, message: cause.error.message });
|
|
46
|
-
}
|
|
47
|
-
else if (Cause.isFailType(cause) && hasTag(cause.error)) {
|
|
48
|
-
return new PasslockError({ code: cause.error._tag });
|
|
49
|
-
}
|
|
50
|
-
else if (Cause.isDieType(cause)) {
|
|
51
|
-
return new PasslockError({ code: 'UnexpectedError', detail: cause.defect });
|
|
52
|
-
}
|
|
53
|
-
else if (Cause.isInterruptType(cause)) {
|
|
54
|
-
return new PasslockError({ code: 'AbortedError', message: 'Operation aborted' });
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return new PasslockError({ code: 'UnexpectedError', detail: cause });
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Run an effect to generate promise with an error or value
|
|
63
|
-
*
|
|
64
|
-
* @param input Effect
|
|
65
|
-
* @returns
|
|
66
|
-
*/
|
|
67
|
-
export const runUnion = (input, runtime, controller) => {
|
|
68
|
-
const abort = Effect.async((resume) => {
|
|
69
|
-
if (controller) {
|
|
70
|
-
controller.onabort = () => resume(Effect.interrupt);
|
|
71
|
-
}
|
|
72
|
-
else
|
|
73
|
-
resume(Effect.never);
|
|
74
|
-
});
|
|
75
|
-
const withInterrupt = Effect.race(input, abort);
|
|
76
|
-
return Runtime.runPromiseExit(runtime)(withInterrupt).then(transformExit);
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* Transform a function that returns an effect to one that returns a promise with an error or value
|
|
80
|
-
*
|
|
81
|
-
* @param fn Function that returns an Effect
|
|
82
|
-
* @returns Function that returns a Promise wrapping a union
|
|
83
|
-
*/
|
|
84
|
-
export const makeUnionFn = (fn, runtime) => {
|
|
85
|
-
return (input) => runUnion(fn(input), runtime, input.abort);
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Transform an effect into one that potentially throws a PasslockError
|
|
89
|
-
*
|
|
90
|
-
* @param effect Effect
|
|
91
|
-
* @returns Promise that could throw
|
|
92
|
-
*/
|
|
93
|
-
export const runUnsafe = (effect, runtime) => {
|
|
94
|
-
const controller = new AbortController();
|
|
95
|
-
return runUnion(effect, runtime, controller.signal).then(t => isPasslockError(t) ? Promise.reject(t) : Promise.resolve(t));
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Transform a function that returns an effect to one that returns a promise that could reject
|
|
99
|
-
*
|
|
100
|
-
* @param fn Function that returns an Effect
|
|
101
|
-
* @returns Function that returns a Promise that could reject
|
|
102
|
-
*/
|
|
103
|
-
export const makeUnsafeFn = (fn, runtime) => {
|
|
104
|
-
return flow(fn, e => runUnsafe(e, runtime));
|
|
105
|
-
};
|
|
106
|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