Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event log #3978

Draft
wants to merge 46 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5759130
add EventLog modules to /experimental and /sql
tim-smart Nov 18, 2024
da259c9
add UuidV4Insert to Model
tim-smart Nov 21, 2024
b318fcd
accept branded schema for UuidV4Insert
tim-smart Nov 21, 2024
91d7725
fix Overrideable with brands
tim-smart Nov 21, 2024
28dfb02
use constructorDefault for UuidV4WithGenerate
tim-smart Nov 21, 2024
2c3680a
add BooleanFromNumber
tim-smart Nov 21, 2024
06ab64f
add .destroy
tim-smart Nov 21, 2024
8ac9f6d
fix decoding in EventLog
tim-smart Nov 21, 2024
bf7c06f
only process one event at a time
tim-smart Nov 21, 2024
e2171b2
don't write 0 entries
tim-smart Nov 21, 2024
da57150
add decode support to Overrideable
tim-smart Nov 21, 2024
56cabf3
absorb EventLogServer errors
tim-smart Nov 21, 2024
513593c
fix indexeddb ordering
tim-smart Nov 22, 2024
59c7a31
fix destroy
tim-smart Nov 22, 2024
65b7835
drop withTransaction from SqlEventLogServer
tim-smart Nov 22, 2024
3f5152e
add log compaction
tim-smart Nov 23, 2024
8459173
wip
tim-smart Nov 24, 2024
91bd804
wip compaction
tim-smart Nov 24, 2024
bf83b42
fix circular dep
tim-smart Nov 25, 2024
87b70b9
wip
tim-smart Nov 25, 2024
4612113
codegen
tim-smart Nov 25, 2024
9fce2a0
fix query
tim-smart Nov 25, 2024
2e1d38b
ensure remotes are written to journal
tim-smart Nov 25, 2024
1f045ee
makeIndexedDb fixes
tim-smart Nov 25, 2024
1328fc8
fix
tim-smart Nov 25, 2024
b5b49b6
compact on remote writes
tim-smart Nov 26, 2024
35b684f
wip
tim-smart Nov 26, 2024
09fa685
wip
tim-smart Nov 26, 2024
d00ac37
wip
tim-smart Nov 26, 2024
b44b05e
reactivity hooks
tim-smart Nov 29, 2024
23feac8
ensure Reactivity rerenders on duplicate events
tim-smart Nov 30, 2024
0695676
update
tim-smart Dec 9, 2024
90217da
add Socket handler
tim-smart Dec 9, 2024
3224e18
fork write
tim-smart Dec 9, 2024
561976f
chunking
tim-smart Dec 9, 2024
f173a47
add insertBatchSize to sql layers
tim-smart Dec 9, 2024
f6750b2
remove subscriptionId
tim-smart Dec 11, 2024
2423c6d
allow remote pings to be disabled
tim-smart Dec 12, 2024
2016da5
return EncryptedRemoteEntry from storage.write
tim-smart Dec 12, 2024
b1f77f0
add .entries to Storage
tim-smart Dec 12, 2024
b22452b
only send changes if needed
tim-smart Dec 12, 2024
bec080f
add Cloudflare EventLogServer
tim-smart Dec 12, 2024
8eb24f6
fix circular
tim-smart Dec 12, 2024
743f01e
fix docgen
tim-smart Dec 12, 2024
3531b6f
add EventLog exports
tim-smart Dec 12, 2024
9d7160f
WriteEntries length 0
tim-smart Dec 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/effect/src/Inspectable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @since 2.0.0
*/

import type * as FiberRefs from "./FiberRefs.js"
import { globalValue } from "./GlobalValue.js"
import { hasProperty, isFunction } from "./Predicate.js"
Expand Down
6 changes: 5 additions & 1 deletion packages/experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"coverage": "vitest --coverage"
},
"dependencies": {
"msgpackr": "^1.10.2"
"msgpackr": "^1.10.2",
"uuid": "^11.0.3"
},
"peerDependencies": {
"@effect/platform": "workspace:^",
Expand All @@ -64,6 +65,7 @@
}
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240806.0",
"@types/ws": "^8.5.12",
"ioredis": "^5.4.1",
"lmdb": "^3.0.13",
Expand All @@ -75,6 +77,8 @@
"include": [
"*.ts",
"DevTools/*.ts",
"EventLogRemote/*.ts",
"EventLogServer/*.ts",
"Machine/*.ts",
"Persistence/*.ts",
"SocketServer/*.ts"
Expand Down
261 changes: 261 additions & 0 deletions packages/experimental/src/Event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
/**
* @since 1.0.0
*/
import { pipeArguments } from "effect/Pipeable"
import * as Predicate from "effect/Predicate"
import * as Schema from "effect/Schema"
import * as MsgPack from "./MsgPack.js"

/**
* @since 1.0.0
* @category type ids
*/
export const TypeId: unique symbol = Symbol.for("@effect/experimental/Event")

/**
* @since 1.0.0
* @category type ids
*/
export type TypeId = typeof TypeId

/**
* @since 1.0.0
* @category guards
*/
export const isEvent = (u: unknown): u is Event<any, any, any, any> => Predicate.hasProperty(u, TypeId)

/**
* Represents an event in an EventLog.
*
* @since 1.0.0
* @category models
*/
export interface Event<
out Tag extends string,
in out Payload extends Schema.Schema.Any = typeof Schema.Void,
in out Success extends Schema.Schema.Any = typeof Schema.Void,
in out Error extends Schema.Schema.All = typeof Schema.Never
> {
readonly [TypeId]: TypeId
readonly tag: Tag
readonly primaryKey: (payload: Schema.Schema.Type<Payload>) => string
readonly payload: Payload
readonly payloadMsgPack: MsgPack.schema<Payload>
readonly success: Success
readonly error: Error
}

/**
* @since 1.0.0
* @category models
*/
export interface EventHandler<in out Tag extends string> {
readonly _: unique symbol
readonly tag: Tag
}

/**
* @since 1.0.0
* @category models
*/
export declare namespace Event {
/**
* @since 1.0.0
* @category models
*/
export interface Any {
readonly [TypeId]: TypeId
readonly tag: string
}

/**
* @since 1.0.0
* @category models
*/
export interface AnyWithProps extends Event<string, Schema.Schema.Any, Schema.Schema.Any, Schema.Schema.Any> {}

/**
* @since 1.0.0
* @category models
*/
export type ToService<A> = A extends Event<
infer _Tag,
infer _Payload,
infer _Success,
infer _Error
> ? EventHandler<_Tag> :
never

/**
* @since 1.0.0
* @category models
*/
export type Tag<A> = A extends Event<
infer _Tag,
infer _Payload,
infer _Success,
infer _Error
> ? _Tag :
never

/**
* @since 1.0.0
* @category models
*/
export type ErrorSchema<A extends Any> = A extends Event<
infer _Tag,
infer _Payload,
infer _Success,
infer _Error
> ? _Error
: never

/**
* @since 1.0.0
* @category models
*/
export type Error<A extends Any> = Schema.Schema.Type<ErrorSchema<A>>

/**
* @since 1.0.0
* @category models
*/
export type AddError<A extends Any, Error extends Schema.Schema.Any> = A extends Event<
infer _Tag,
infer _Payload,
infer _Success,
infer _Error
> ? Event<_Tag, _Payload, _Success, _Error | Error>
: never

/**
* @since 1.0.0
* @category models
*/
export type PayloadSchema<A extends Any> = A extends Event<
infer _Tag,
infer _Payload,
infer _Success,
infer _Error
> ? _Payload
: never

/**
* @since 1.0.0
* @category models
*/
export type Payload<A extends Any> = Schema.Schema.Type<PayloadSchema<A>>

/**
* @since 1.0.0
* @category models
*/
export type TaggedPayload<A extends Any> = A extends Event<
infer _Tag,
infer _Payload,
infer _Success,
infer _Error
> ? {
readonly _tag: _Tag
readonly payload: Schema.Schema.Type<_Payload>
}
: never

/**
* @since 1.0.0
* @category models
*/
export type SuccessSchema<A extends Any> = A extends Event<
infer _Tag,
infer _Payload,
infer _Success,
infer _Error
> ? _Success
: never

/**
* @since 1.0.0
* @category models
*/
export type Success<A extends Any> = Schema.Schema.Type<SuccessSchema<A>>

/**
* @since 1.0.0
* @category models
*/
export type Context<A> = A extends Event<
infer _Name,
infer _Payload,
infer _Success,
infer _Error
> ? Schema.Schema.Context<_Payload> | Schema.Schema.Context<_Success> | Schema.Schema.Context<_Error>
: never

/**
* @since 1.0.0
* @category models
*/
export type WithTag<Events extends Any, Tag extends string> = Extract<Events, { readonly tag: Tag }>

/**
* @since 1.0.0
* @category models
*/
export type ExcludeTag<Events extends Any, Tag extends string> = Exclude<Events, { readonly tag: Tag }>

/**
* @since 1.0.0
* @category models
*/
export type PayloadWithTag<Events extends Any, Tag extends string> = Payload<WithTag<Events, Tag>>

/**
* @since 1.0.0
* @category models
*/
export type SuccessWithTag<Events extends Any, Tag extends string> = Success<WithTag<Events, Tag>>

/**
* @since 1.0.0
* @category models
*/
export type ErrorWithTag<Events extends Any, Tag extends string> = Error<WithTag<Events, Tag>>

/**
* @since 1.0.0
* @category models
*/
export type ContextWithTag<Events extends Any, Tag extends string> = Context<WithTag<Events, Tag>>
}

const Proto = {
[TypeId]: TypeId,
pipe() {
return pipeArguments(this, arguments)
}
}

/**
* @since 1.0.0
* @category constructors
*/
export const make = <
Tag extends string,
Payload extends Schema.Schema.Any = typeof Schema.Void,
Success extends Schema.Schema.Any = typeof Schema.Void,
Error extends Schema.Schema.All = typeof Schema.Never
>(options: {
readonly tag: Tag
readonly primaryKey: (payload: Schema.Schema.Type<Payload>) => string
readonly payload?: Payload
readonly success?: Success
readonly error?: Error
}): Event<Tag, Payload, Success, Error> =>
Object.assign(Object.create(Proto), {
tag: options.tag,
primaryKey: options.primaryKey,
payload: options.payload ?? Schema.Void,
payloadMsgPack: MsgPack.schema(options.payload ?? Schema.Void),
success: options.success ?? Schema.Void,
error: options.error ?? Schema.Never
})
Loading
Loading