-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reindex): add basic synchronize method skeleton
- Loading branch information
Showing
20 changed files
with
315 additions
and
36 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/core/src/helpers/fp-ts/catch-task-either-tagged-error-te.ts
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,24 @@ | ||
import * as TE from 'fp-ts/TaskEither'; | ||
import { pipe } from 'fp-ts/function'; | ||
|
||
import type * as RTE from 'fp-ts/ReaderTaskEither'; | ||
import { isTaggedError, type TaggedError } from '../../types'; | ||
|
||
export const catchTaskEitherTagErrorTE = | ||
<const T extends string, E2, B>( | ||
tag: T, | ||
catchTask: RTE.ReaderTaskEither<TaggedError<T>, E2, B>, | ||
) => | ||
<E, A>( | ||
task: TE.TaskEither<E & TaggedError<T> extends never ? never : E, A>, | ||
) => | ||
pipe( | ||
task, | ||
TE.foldW((error): TE.TaskEither<E | E2, A | B> => { | ||
if (isTaggedError(error) && error.tag === tag) { | ||
return catchTask(error); | ||
} | ||
|
||
return TE.left(error); | ||
}, TE.of), | ||
) as TE.TaskEither<E | E2, A | B>; |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './catch-task-either-tagged-error-te'; | ||
export * from './tap-task-either-error-te'; | ||
export * from './tap-task-either-error'; | ||
export * from './tap-task-either'; | ||
export * from './try-tagged-error-task'; |
21 changes: 21 additions & 0 deletions
21
packages/core/src/helpers/fp-ts/tap-task-either-error-te.ts
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 * as TE from 'fp-ts/TaskEither'; | ||
import { pipe } from 'fp-ts/function'; | ||
|
||
export const tapTaskEitherErrorTE = | ||
<A, E, E2 = E>(errorFnTE: (error: E) => TE.TaskEither<E2, unknown>) => | ||
(task: TE.TaskEither<E, A>): TE.TaskEither<E | E2, A> => | ||
pipe( | ||
task, | ||
TE.foldW( | ||
error => | ||
pipe( | ||
error, | ||
errorFnTE, | ||
TE.foldW( | ||
rollbackError => TE.left(rollbackError), | ||
() => TE.left(error), | ||
), | ||
), | ||
TE.right, | ||
), | ||
); |
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,5 @@ | ||
export const getFirstObjKeyValue = <O extends Record<string, any>>(obj: O) => { | ||
const [key] = Object.keys(obj); | ||
|
||
return obj[key]; | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './fp-ts'; | ||
export * from './get-first-obj-key-value'; | ||
export * from './nop'; | ||
export * from './reject-falsy-values'; |
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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
export abstract class TaggedError extends Error { | ||
abstract readonly tag: string; | ||
export abstract class TaggedError<T extends string> extends Error { | ||
abstract readonly tag: T; | ||
|
||
constructor(readonly originalStack?: string) { | ||
super(); | ||
Error.captureStackTrace(this, TaggedError); | ||
} | ||
|
||
static ofLiteral = <const S extends string>(tag: S) => | ||
class TaggedLiteralError extends TaggedError<S> { | ||
readonly tag = tag; | ||
}; | ||
} | ||
|
||
export const isTaggedError = (error: Error): error is TaggedError => | ||
'tag' in error; | ||
export const isTaggedError = (error: any): error is TaggedError<any> => | ||
error && 'tag' in error; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import type { TaskEither } from 'fp-ts/TaskEither'; | ||
import type { TaggedError } from './tagged-error.types'; | ||
|
||
export type TaggedTaskEither<E extends TaggedError, A> = TaskEither<E, A>; | ||
export type TaggedTaskEither<E extends TaggedError<any>, A> = TaskEither<E, A>; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './fp-ts'; | ||
export * from './value-object.types'; |
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,24 @@ | ||
export abstract class ValueObject<T> { | ||
constructor(readonly props: T) {} | ||
|
||
static of: <A>(props: A) => ValueObject<A>; | ||
|
||
unwrap() { | ||
return this.props; | ||
} | ||
|
||
bind<O>(fn: (props: T) => O): O { | ||
return fn(this.props); | ||
} | ||
|
||
extend(props: Partial<T>): this { | ||
return new (this.constructor as any)({ | ||
...this.props, | ||
...props, | ||
}); | ||
} | ||
|
||
map(fn: (props: T) => T): this { | ||
return new (this.constructor as any)(this.bind(fn)); | ||
} | ||
} |
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
20 changes: 8 additions & 12 deletions
20
packages/reindex/src/+internal/client/es-monadic-client.error.ts
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
19 changes: 19 additions & 0 deletions
19
packages/reindex/src/+internal/helpers/create-index-name-with-timestamp.ts
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,19 @@ | ||
const genTimestampSuffix = () => { | ||
const d = new Date(); | ||
const time = [ | ||
d.getMonth(), | ||
d.getDay(), | ||
d.getHours(), | ||
d.getMinutes(), | ||
d.getSeconds(), | ||
].map(num => num.toString().padStart(2, '0')); | ||
|
||
return [ | ||
d.getFullYear(), | ||
...time, | ||
d.getMilliseconds().toString().padStart(3, '0'), | ||
].join(''); | ||
}; | ||
|
||
export const createIndexNameWithTimestamp = (prefix: string) => | ||
`${prefix}-${genTimestampSuffix()}`; |
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 @@ | ||
export * from './create-index-name-with-timestamp'; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './client'; | ||
export * from './helpers'; |
Oops, something went wrong.