@zyro-sec/schema 1.0.0 → 1.0.1
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/AGENTS.md +95 -0
- package/package.json +9 -15
- package/script/build.ts +9 -0
- package/script/config-schema.ts +86 -0
- package/script/config-v1.json +1312 -0
- package/script/pack.ts +5 -0
- package/src/agent.ts +68 -0
- package/src/artifact.ts +81 -0
- package/src/automation.ts +224 -0
- package/src/blob-store.ts +25 -0
- package/src/command.ts +18 -0
- package/src/config/agent.ts +26 -0
- package/src/config/command.ts +14 -0
- package/src/config/compaction.ts +27 -0
- package/src/config/experimental.ts +72 -0
- package/src/config/flag.ts +39 -0
- package/src/config/formatter.ts +13 -0
- package/src/config/lsp.ts +19 -0
- package/src/config/mcp.ts +22 -0
- package/src/config/media.ts +15 -0
- package/src/config/model.ts +37 -0
- package/src/config/plugin.ts +14 -0
- package/src/config/policy.ts +57 -0
- package/src/config/provider.ts +122 -0
- package/src/config/reference.ts +23 -0
- package/src/config/shell.ts +10 -0
- package/src/config/tool-output.ts +9 -0
- package/src/config/warming.ts +21 -0
- package/src/config/watcher.ts +8 -0
- package/src/config/websearch.ts +17 -0
- package/src/config/worktree.ts +10 -0
- package/src/config.ts +149 -0
- package/src/connection.ts +38 -0
- package/src/credential-legacy.ts +29 -0
- package/src/credential.ts +78 -0
- package/src/durable-event-manifest.ts +7 -0
- package/src/event-log.ts +21 -0
- package/src/event-manifest.ts +108 -0
- package/src/event.ts +205 -0
- package/src/file-diff.ts +25 -0
- package/src/filesystem-v1.ts +1 -0
- package/src/filesystem.ts +48 -0
- package/src/form.ts +177 -0
- package/src/generate.ts +292 -0
- package/src/goal.ts +46 -0
- package/src/identifier.ts +32 -0
- package/src/index.ts +51 -0
- package/src/installation-event.ts +20 -0
- package/src/instruction-entry.ts +40 -0
- package/src/instruction.ts +25 -0
- package/src/integration-id.ts +13 -0
- package/src/integration.ts +129 -0
- package/src/job.ts +79 -0
- package/src/legacy-event.ts +1 -0
- package/src/llm.ts +6 -0
- package/src/location-event.ts +8 -0
- package/src/location.ts +36 -0
- package/src/lsp-event.ts +7 -0
- package/src/mcp-event.ts +63 -0
- package/src/mcp.ts +171 -0
- package/src/model-compatibility.ts +55 -0
- package/src/model.ts +176 -0
- package/src/models-dev.ts +9 -0
- package/src/money.ts +18 -0
- package/src/permission-saved.ts +25 -0
- package/src/permission-v1.ts +1 -0
- package/src/permission.ts +67 -0
- package/src/persistent-pty.ts +73 -0
- package/src/plugin.ts +62 -0
- package/src/project-id.ts +9 -0
- package/src/project.ts +62 -0
- package/src/prompt-input.ts +33 -0
- package/src/prompt.ts +117 -0
- package/src/provider.ts +136 -0
- package/src/pty-ticket.ts +10 -0
- package/src/pty.ts +61 -0
- package/src/push.ts +86 -0
- package/src/question.ts +22 -0
- package/src/reference.ts +40 -0
- package/src/rpc.ts +167 -0
- package/src/schema.ts +41 -0
- package/src/server-event.ts +8 -0
- package/src/session-error.ts +14 -0
- package/src/session-event.ts +739 -0
- package/src/session-fork.ts +10 -0
- package/src/session-id.ts +12 -0
- package/src/session-inbox.ts +102 -0
- package/src/session-legacy.ts +117 -0
- package/src/session-message.ts +352 -0
- package/src/session-metadata.ts +11 -0
- package/src/session-revert.ts +86 -0
- package/src/session-stats.ts +68 -0
- package/src/session-status-event.ts +53 -0
- package/src/session-transfer.ts +11 -0
- package/src/session-v1.ts +1 -0
- package/src/session.ts +147 -0
- package/src/shell.ts +90 -0
- package/src/skill.ts +68 -0
- package/src/snapshot.ts +6 -0
- package/src/token-usage.ts +18 -0
- package/src/tool.ts +143 -0
- package/src/tui-event.ts +59 -0
- package/src/usage-limits.ts +76 -0
- package/src/v1/filesystem.ts +11 -0
- package/src/v1/legacy-event.ts +18 -0
- package/src/v1/permission.ts +66 -0
- package/src/v1/session.ts +667 -0
- package/src/vcs-event.ts +14 -0
- package/src/vcs.ts +41 -0
- package/src/websearch.ts +44 -0
- package/src/workspace-event.ts +32 -0
- package/src/workspace-id.ts +19 -0
- package/src/workspace.ts +20 -0
- package/src/worktree-event.ts +22 -0
- package/src/worktree.ts +109 -0
- package/test/agent.test.ts +10 -0
- package/test/automation.test.ts +48 -0
- package/test/compatibility.test.ts +10 -0
- package/test/config.test.ts +194 -0
- package/test/contract-hygiene.test.ts +352 -0
- package/test/credential-legacy.test.ts +55 -0
- package/test/event-manifest.test.ts +228 -0
- package/test/event.test.ts +52 -0
- package/test/legacy-event.test.ts +46 -0
- package/test/mcp.test.ts +37 -0
- package/test/model.test.ts +104 -0
- package/test/session-cursor.test.ts +16 -0
- package/test/session-error.test.ts +51 -0
- package/test/session-legacy.test.ts +178 -0
- package/test/session-terminal.test.ts +50 -0
- package/test/token-usage.test.ts +18 -0
- package/test/v1-isolation.test.ts +26 -0
- package/test/vcs.test.ts +23 -0
- package/test/worktree.test.ts +45 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +14 -0
package/src/push.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export * as Push from "./push.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { ephemeral, inventory } from "./event.js"
|
|
5
|
+
import { NonNegativeInt, optional } from "./schema.js"
|
|
6
|
+
|
|
7
|
+
export const DeviceID = Schema.String.check(
|
|
8
|
+
Schema.isPattern(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/),
|
|
9
|
+
).pipe(
|
|
10
|
+
Schema.brand("Push.DeviceID"),
|
|
11
|
+
Schema.annotate({ identifier: "Push.DeviceID", description: "A lowercase canonical UUID chosen by the phone" }),
|
|
12
|
+
)
|
|
13
|
+
export type DeviceID = typeof DeviceID.Type
|
|
14
|
+
|
|
15
|
+
export const Time = NonNegativeInt.annotate({
|
|
16
|
+
description: "Milliseconds since the Unix epoch",
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const Level = Schema.Literals(["all", "attention", "none"]).annotate({ identifier: "Push.Level" })
|
|
20
|
+
export type Level = typeof Level.Type
|
|
21
|
+
|
|
22
|
+
export interface Bell extends Schema.Schema.Type<typeof Bell> {}
|
|
23
|
+
export const Bell = Schema.Struct({
|
|
24
|
+
level: Level,
|
|
25
|
+
until: Time.pipe(optional),
|
|
26
|
+
}).annotate({ identifier: "Push.Bell" })
|
|
27
|
+
|
|
28
|
+
export interface Settings extends Schema.Schema.Type<typeof Settings> {}
|
|
29
|
+
export const Settings = Schema.Struct({
|
|
30
|
+
paused: Schema.Boolean,
|
|
31
|
+
until: Time.pipe(optional),
|
|
32
|
+
}).annotate({ identifier: "Push.Settings" })
|
|
33
|
+
|
|
34
|
+
export interface DeviceSettings extends Schema.Schema.Type<typeof DeviceSettings> {}
|
|
35
|
+
export const DeviceSettings = Schema.Struct({
|
|
36
|
+
default: Level,
|
|
37
|
+
}).annotate({ identifier: "Push.DeviceSettings" })
|
|
38
|
+
|
|
39
|
+
export const Platform = Schema.Literals(["android", "ios"]).annotate({ identifier: "Push.Platform" })
|
|
40
|
+
export type Platform = typeof Platform.Type
|
|
41
|
+
|
|
42
|
+
export interface Register extends Schema.Schema.Type<typeof Register> {}
|
|
43
|
+
export const Register = Schema.Struct({
|
|
44
|
+
callbackURL: Schema.String,
|
|
45
|
+
expiresAt: Time,
|
|
46
|
+
publicKey: Schema.String,
|
|
47
|
+
platform: Platform,
|
|
48
|
+
name: Schema.String,
|
|
49
|
+
settings: DeviceSettings.pipe(optional),
|
|
50
|
+
}).annotate({ identifier: "Push.Register" })
|
|
51
|
+
|
|
52
|
+
export interface Registered extends Schema.Schema.Type<typeof Registered> {}
|
|
53
|
+
export const Registered = Schema.Struct({
|
|
54
|
+
publicKey: Schema.String,
|
|
55
|
+
}).annotate({ identifier: "Push.Registered" })
|
|
56
|
+
|
|
57
|
+
export interface DevicePatch extends Schema.Schema.Type<typeof DevicePatch> {}
|
|
58
|
+
export const DevicePatch = Schema.Struct({
|
|
59
|
+
paused: Schema.Boolean.pipe(optional),
|
|
60
|
+
settings: DeviceSettings.pipe(optional),
|
|
61
|
+
}).annotate({ identifier: "Push.DevicePatch" })
|
|
62
|
+
|
|
63
|
+
export interface Device extends Schema.Schema.Type<typeof Device> {}
|
|
64
|
+
export const Device = Schema.Struct({
|
|
65
|
+
id: DeviceID,
|
|
66
|
+
name: Schema.String,
|
|
67
|
+
platform: Platform,
|
|
68
|
+
expiresAt: Time,
|
|
69
|
+
settings: DeviceSettings,
|
|
70
|
+
paused: Schema.Boolean,
|
|
71
|
+
sessions: Schema.Record(Schema.String, Bell),
|
|
72
|
+
time: Schema.Struct({
|
|
73
|
+
created: Time,
|
|
74
|
+
updated: Time,
|
|
75
|
+
}),
|
|
76
|
+
}).annotate({ identifier: "Push.Device" })
|
|
77
|
+
|
|
78
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
|
79
|
+
export const Info = Schema.Struct({
|
|
80
|
+
settings: Settings,
|
|
81
|
+
devices: Schema.Array(Device),
|
|
82
|
+
sessions: Schema.Record(Schema.String, Bell),
|
|
83
|
+
}).annotate({ identifier: "Push.Info" })
|
|
84
|
+
|
|
85
|
+
const Updated = ephemeral({ type: "experimental.push.updated", schema: {} })
|
|
86
|
+
export const Event = { Updated, Definitions: inventory(Updated) }
|
package/src/question.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * as Question from "./question.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "./schema.js"
|
|
5
|
+
|
|
6
|
+
const Option = Schema.Struct({
|
|
7
|
+
label: Schema.String.annotate({ description: "Display text (1-5 words, concise)" }),
|
|
8
|
+
description: Schema.String.annotate({ description: "Explanation of choice" }),
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const base = {
|
|
12
|
+
question: Schema.String.annotate({ description: "Complete question" }),
|
|
13
|
+
header: Schema.String.annotate({ description: "Very short label (max 30 chars)" }),
|
|
14
|
+
options: Schema.Array(Option).annotate({ description: "Available choices" }),
|
|
15
|
+
multiple: Schema.Boolean.pipe(optional).annotate({ description: "Allow selecting multiple choices" }),
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const Prompt = Schema.Struct(base).annotate({ identifier: "Question.Prompt" })
|
|
19
|
+
export interface Prompt extends Schema.Schema.Type<typeof Prompt> {}
|
|
20
|
+
|
|
21
|
+
export const Answer = Schema.Array(Schema.String).annotate({ identifier: "Question.Answer" })
|
|
22
|
+
export type Answer = typeof Answer.Type
|
package/src/reference.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export * as Reference from "./reference.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { optional } from "./schema.js"
|
|
5
|
+
import { ephemeral, inventory } from "./event.js"
|
|
6
|
+
import { AbsolutePath } from "./schema.js"
|
|
7
|
+
|
|
8
|
+
const Updated = ephemeral({ type: "reference.updated", schema: {} })
|
|
9
|
+
export const Event = { Updated, Definitions: inventory(Updated) }
|
|
10
|
+
|
|
11
|
+
export interface LocalSource extends Schema.Schema.Type<typeof LocalSource> {}
|
|
12
|
+
export const LocalSource = Schema.Struct({
|
|
13
|
+
type: Schema.Literal("local"),
|
|
14
|
+
path: AbsolutePath,
|
|
15
|
+
description: Schema.String.pipe(optional),
|
|
16
|
+
hidden: Schema.Boolean.pipe(optional),
|
|
17
|
+
}).annotate({ identifier: "Reference.LocalSource" })
|
|
18
|
+
|
|
19
|
+
export interface GitSource extends Schema.Schema.Type<typeof GitSource> {}
|
|
20
|
+
export const GitSource = Schema.Struct({
|
|
21
|
+
type: Schema.Literal("git"),
|
|
22
|
+
repository: Schema.String,
|
|
23
|
+
branch: Schema.String.pipe(optional),
|
|
24
|
+
description: Schema.String.pipe(optional),
|
|
25
|
+
hidden: Schema.Boolean.pipe(optional),
|
|
26
|
+
}).annotate({ identifier: "Reference.GitSource" })
|
|
27
|
+
|
|
28
|
+
export const Source = Schema.Union([LocalSource, GitSource])
|
|
29
|
+
.pipe(Schema.toTaggedUnion("type"))
|
|
30
|
+
.annotate({ identifier: "Reference.Source" })
|
|
31
|
+
export type Source = typeof Source.Type
|
|
32
|
+
|
|
33
|
+
export const Info = Schema.Struct({
|
|
34
|
+
name: Schema.String,
|
|
35
|
+
path: AbsolutePath,
|
|
36
|
+
description: Schema.String.pipe(optional),
|
|
37
|
+
hidden: Schema.Boolean.pipe(optional),
|
|
38
|
+
source: Source,
|
|
39
|
+
}).annotate({ identifier: "Reference.Info" })
|
|
40
|
+
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
package/src/rpc.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export * as Rpc from "./rpc.js"
|
|
2
|
+
|
|
3
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec"
|
|
4
|
+
import type { JsonSchema, Schema } from "effect"
|
|
5
|
+
import type { Event } from "./event.js"
|
|
6
|
+
import type { Location } from "./location.js"
|
|
7
|
+
import type { Tool } from "./tool.js"
|
|
8
|
+
|
|
9
|
+
export type ErrorMap = Readonly<Record<string, Tool.ValueSchema>> & {
|
|
10
|
+
readonly [Name in `rpc.${string}`]?: never
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Method {
|
|
14
|
+
readonly input: Tool.ValueSchema
|
|
15
|
+
readonly output: Tool.ValueSchema
|
|
16
|
+
readonly errors?: ErrorMap
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type PortableValueSchema = StandardSchemaV1<unknown, unknown> | JsonSchema.JsonSchema
|
|
20
|
+
|
|
21
|
+
export interface PortableMethod extends Method {
|
|
22
|
+
readonly input: PortableValueSchema
|
|
23
|
+
readonly output: PortableValueSchema
|
|
24
|
+
readonly errors?: Readonly<Record<string, PortableValueSchema>> & {
|
|
25
|
+
readonly [Name in `rpc.${string}`]?: never
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type EventDataObject = Readonly<Record<string, unknown>>
|
|
30
|
+
type EventValueSchema =
|
|
31
|
+
| Schema.Codec<EventDataObject, EventDataObject>
|
|
32
|
+
| StandardSchemaV1<unknown, EventDataObject>
|
|
33
|
+
| (JsonSchema.JsonSchema & { readonly type: "object" })
|
|
34
|
+
type PortableEventValueSchema =
|
|
35
|
+
| StandardSchemaV1<unknown, EventDataObject>
|
|
36
|
+
| (JsonSchema.JsonSchema & { readonly type: "object" })
|
|
37
|
+
|
|
38
|
+
export interface EventDefinition {
|
|
39
|
+
readonly schema: EventValueSchema
|
|
40
|
+
}
|
|
41
|
+
export type PortableEventDefinition = EventDefinition & { readonly schema: PortableEventValueSchema }
|
|
42
|
+
|
|
43
|
+
export interface Definition {
|
|
44
|
+
readonly id: string
|
|
45
|
+
readonly methods: Readonly<Record<string, Method>> & { readonly events?: never }
|
|
46
|
+
readonly events: Readonly<Record<string, EventDefinition>>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface PortableDefinition extends Definition {
|
|
50
|
+
readonly methods: Readonly<Record<string, PortableMethod>> & { readonly events?: never }
|
|
51
|
+
readonly events: Readonly<Record<string, PortableEventDefinition>>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function define<const D extends Definition>(definition: D) {
|
|
55
|
+
const reserved = Object.values(definition.methods)
|
|
56
|
+
.flatMap((method) => Object.keys(method.errors ?? {}))
|
|
57
|
+
.find((name) => name.startsWith("rpc."))
|
|
58
|
+
if (reserved) throw new Error(`RPC error names starting with "rpc." are reserved: ${reserved}`)
|
|
59
|
+
return definition
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type Input<S extends Tool.ValueSchema> = S extends Schema.Top
|
|
63
|
+
? S["Encoded"]
|
|
64
|
+
: S extends StandardSchemaV1
|
|
65
|
+
? StandardSchemaV1.InferInput<S>
|
|
66
|
+
: unknown
|
|
67
|
+
|
|
68
|
+
export type Output<S extends Tool.ValueSchema> = S extends Schema.Top
|
|
69
|
+
? S["Type"]
|
|
70
|
+
: S extends StandardSchemaV1
|
|
71
|
+
? StandardSchemaV1.InferOutput<S>
|
|
72
|
+
: unknown
|
|
73
|
+
|
|
74
|
+
// Effect codecs encode handler results; Standard Schema parses them forward.
|
|
75
|
+
export type HandlerOutput<S extends Tool.ValueSchema> = S extends Schema.Top ? Output<S> : Input<S>
|
|
76
|
+
|
|
77
|
+
type MethodErrors<M extends Method> = M extends {
|
|
78
|
+
readonly errors: infer Errors extends ErrorMap
|
|
79
|
+
}
|
|
80
|
+
? Errors
|
|
81
|
+
: never
|
|
82
|
+
type ErrorSchema<M extends Method, Name extends ErrorName<M>> = MethodErrors<M>[Name]
|
|
83
|
+
type ErrorData<Data> = unknown extends Data
|
|
84
|
+
? { readonly data: Data }
|
|
85
|
+
: undefined extends Data
|
|
86
|
+
? { readonly data?: Data }
|
|
87
|
+
: { readonly data: Data }
|
|
88
|
+
type ErrorDataArguments<Data> = unknown extends Data
|
|
89
|
+
? [data: Data]
|
|
90
|
+
: undefined extends Data
|
|
91
|
+
? [data?: Data]
|
|
92
|
+
: [data: Data]
|
|
93
|
+
type Simplify<A> = { readonly [K in keyof A]: A[K] }
|
|
94
|
+
declare const HandlerErrorTypeId: unique symbol
|
|
95
|
+
|
|
96
|
+
export interface Failure<Type extends string = string, Data = unknown> {
|
|
97
|
+
readonly type: Type
|
|
98
|
+
readonly message: string
|
|
99
|
+
readonly data?: Data
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type SystemError = Failure<
|
|
103
|
+
| "rpc.unavailable"
|
|
104
|
+
| "rpc.method_not_found"
|
|
105
|
+
| "rpc.invalid_input"
|
|
106
|
+
| "rpc.invalid_output"
|
|
107
|
+
| "rpc.internal",
|
|
108
|
+
never
|
|
109
|
+
>
|
|
110
|
+
|
|
111
|
+
export type ErrorName<M extends Method> = M extends {
|
|
112
|
+
readonly errors: infer Errors extends ErrorMap
|
|
113
|
+
}
|
|
114
|
+
? Exclude<keyof Errors & string, `rpc.${string}`>
|
|
115
|
+
: never
|
|
116
|
+
export type HandlerErrorFor<M extends Method, Name extends ErrorName<M>> = Simplify<
|
|
117
|
+
{
|
|
118
|
+
readonly type: Name
|
|
119
|
+
readonly message: string
|
|
120
|
+
readonly [HandlerErrorTypeId]: true
|
|
121
|
+
} & ErrorData<HandlerOutput<ErrorSchema<M, Name>>>
|
|
122
|
+
>
|
|
123
|
+
export type HandlerError<M extends Method> = {
|
|
124
|
+
readonly [Name in ErrorName<M>]: HandlerErrorFor<M, Name>
|
|
125
|
+
}[ErrorName<M>]
|
|
126
|
+
export type MethodErrorFor<M extends Method, Name extends ErrorName<M>> = Simplify<
|
|
127
|
+
{
|
|
128
|
+
readonly type: Name
|
|
129
|
+
readonly message: string
|
|
130
|
+
} & ErrorData<Output<ErrorSchema<M, Name>>>
|
|
131
|
+
>
|
|
132
|
+
export type MethodError<M extends Method> = {
|
|
133
|
+
readonly [Name in ErrorName<M>]: MethodErrorFor<M, Name>
|
|
134
|
+
}[ErrorName<M>]
|
|
135
|
+
export type ErrorArguments<M extends Method, Name extends ErrorName<M>> = [
|
|
136
|
+
type: Name,
|
|
137
|
+
message: string,
|
|
138
|
+
...data: ErrorDataArguments<HandlerOutput<ErrorSchema<M, Name>>>,
|
|
139
|
+
]
|
|
140
|
+
export type ErrorFactory<M extends Method> = <Name extends ErrorName<M>>(
|
|
141
|
+
...args: ErrorArguments<M, Name>
|
|
142
|
+
) => HandlerErrorFor<M, Name>
|
|
143
|
+
|
|
144
|
+
export type EventInputData<S extends EventValueSchema> = S extends JsonSchema.JsonSchema
|
|
145
|
+
? EventDataObject
|
|
146
|
+
: HandlerOutput<S>
|
|
147
|
+
export type EventData<S extends EventValueSchema> = S extends JsonSchema.JsonSchema
|
|
148
|
+
? EventDataObject
|
|
149
|
+
: Output<S>
|
|
150
|
+
|
|
151
|
+
// Keep the event name correlated with its payload even when callers use unions.
|
|
152
|
+
export type EventInput<D extends Definition> = {
|
|
153
|
+
[Name in keyof D["events"] & string]: [name: Name, data: EventInputData<D["events"][Name]["schema"]>]
|
|
154
|
+
}[keyof D["events"] & string]
|
|
155
|
+
|
|
156
|
+
type EventPayloadFor<
|
|
157
|
+
D extends Definition,
|
|
158
|
+
Name extends keyof D["events"] & string,
|
|
159
|
+
> = Omit<Event.Payload<Event.EphemeralDefinition>, "type" | "data" | "durable" | "location"> & {
|
|
160
|
+
readonly type: `rpc.${D["id"]}.${Name}`
|
|
161
|
+
readonly data: EventData<D["events"][Name]["schema"]>
|
|
162
|
+
readonly location: Location.Ref
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export type EventPayload<D extends Definition, Name extends keyof D["events"] & string = keyof D["events"] & string> = {
|
|
166
|
+
readonly [K in Name]: EventPayloadFor<D, K>
|
|
167
|
+
}[Name]
|
package/src/schema.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DateTime, Option, Schema, SchemaGetter } from "effect"
|
|
2
|
+
|
|
3
|
+
export const PositiveInt = Schema.Int.check(Schema.isGreaterThan(0))
|
|
4
|
+
export const NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))
|
|
5
|
+
|
|
6
|
+
export const RelativePath = Schema.String.pipe(
|
|
7
|
+
Schema.brand("RelativePath"),
|
|
8
|
+
Schema.annotate({ identifier: "RelativePath" }),
|
|
9
|
+
)
|
|
10
|
+
export type RelativePath = typeof RelativePath.Type
|
|
11
|
+
|
|
12
|
+
export const AbsolutePath = Schema.String.pipe(
|
|
13
|
+
Schema.brand("AbsolutePath"),
|
|
14
|
+
Schema.annotate({ identifier: "AbsolutePath" }),
|
|
15
|
+
)
|
|
16
|
+
export type AbsolutePath = typeof AbsolutePath.Type
|
|
17
|
+
|
|
18
|
+
export const optional = <S extends Schema.Top>(schema: S) =>
|
|
19
|
+
Schema.optionalKey(schema).pipe(
|
|
20
|
+
Schema.decodeTo(Schema.optional(Schema.toType(schema)), {
|
|
21
|
+
decode: SchemaGetter.passthrough({ strict: false }),
|
|
22
|
+
encode: SchemaGetter.transformOptional(Option.filter((value) => value !== undefined)),
|
|
23
|
+
}),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
// Effect schemas expose `make` through prototype getters, so `Object.assign` cannot override it.
|
|
27
|
+
// Defining the properties replaces a constructor as long as the schema's own `make` has not been read.
|
|
28
|
+
export const withStatics = <S extends object, M extends Record<string, unknown>>(schema: S, methods: M): S & M =>
|
|
29
|
+
Object.defineProperties(schema, Object.getOwnPropertyDescriptors(methods)) as S & M
|
|
30
|
+
|
|
31
|
+
export const statics =
|
|
32
|
+
<S extends object, M extends Record<string, unknown>>(methods: (schema: S) => M) =>
|
|
33
|
+
(schema: S): S & M =>
|
|
34
|
+
withStatics(schema, methods(schema))
|
|
35
|
+
|
|
36
|
+
export const DateTimeUtcFromMillis = Schema.Finite.pipe(
|
|
37
|
+
Schema.decodeTo(Schema.DateTimeUtc, {
|
|
38
|
+
decode: SchemaGetter.transform((value) => DateTime.makeUnsafe(value)),
|
|
39
|
+
encode: SchemaGetter.transform((value) => DateTime.toEpochMillis(value)),
|
|
40
|
+
}),
|
|
41
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * as ServerEvent from "./server-event.js"
|
|
2
|
+
|
|
3
|
+
import { Event } from "./event.js"
|
|
4
|
+
|
|
5
|
+
export const Connected = Event.ephemeral({ type: "server.connected", schema: {} })
|
|
6
|
+
export const Disposed = Event.ephemeral({ type: "global.disposed", schema: {} })
|
|
7
|
+
|
|
8
|
+
export const Definitions = Event.inventory(Connected, Disposed)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * as SessionError from "./session-error.js"
|
|
2
|
+
|
|
3
|
+
import { Schema } from "effect"
|
|
4
|
+
import { NonNegativeInt, optional } from "./schema.js"
|
|
5
|
+
|
|
6
|
+
export interface Error extends Schema.Schema.Type<typeof Error> {}
|
|
7
|
+
export const Error = Schema.Struct({
|
|
8
|
+
type: Schema.String,
|
|
9
|
+
message: Schema.String,
|
|
10
|
+
status: Schema.Int.check(Schema.isBetween({ minimum: 100, maximum: 599 })).pipe(optional),
|
|
11
|
+
response: Schema.Struct({ body: Schema.String }).pipe(optional),
|
|
12
|
+
/** How long the provider asked to wait before trying again, counted from when the failure was recorded. */
|
|
13
|
+
retryAfterMs: NonNegativeInt.pipe(optional),
|
|
14
|
+
}).annotate({ identifier: "Session.StructuredError" })
|