@codeworksh/schema 0.0.0-stage → 0.1.0-canary.165.2.g336229f9

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.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -2
  3. package/common.d.mts +86 -0
  4. package/common.mjs +88 -0
  5. package/common.mjs.map +1 -0
  6. package/daemon.d.mts +12 -0
  7. package/daemon.mjs +22 -0
  8. package/daemon.mjs.map +1 -0
  9. package/door.d.mts +33 -0
  10. package/door.mjs +52 -0
  11. package/door.mjs.map +1 -0
  12. package/event.d.mts +79 -0
  13. package/event.mjs +35 -0
  14. package/event.mjs.map +1 -0
  15. package/forwarded.d.mts +13 -0
  16. package/forwarded.mjs +25 -0
  17. package/forwarded.mjs.map +1 -0
  18. package/host/envelope.d.mts +36 -0
  19. package/host/envelope.mjs +35 -0
  20. package/host/envelope.mjs.map +1 -0
  21. package/host/part.d.mts +2 -0
  22. package/host/part.mjs +60 -0
  23. package/host/part.mjs.map +1 -0
  24. package/host/principal.d.mts +36 -0
  25. package/host/principal.mjs +24 -0
  26. package/host/principal.mjs.map +1 -0
  27. package/host/records.d.mts +1051 -0
  28. package/host/records.mjs +494 -0
  29. package/host/records.mjs.map +1 -0
  30. package/host.d.mts +2224 -0
  31. package/host.mjs +812 -0
  32. package/host.mjs.map +1 -0
  33. package/ids.d.mts +53 -0
  34. package/ids.mjs +60 -0
  35. package/ids.mjs.map +1 -0
  36. package/jws.d.mts +84 -0
  37. package/jws.mjs +119 -0
  38. package/jws.mjs.map +1 -0
  39. package/location.d.mts +55 -0
  40. package/location.mjs +51 -0
  41. package/location.mjs.map +1 -0
  42. package/machine.d.mts +77 -0
  43. package/machine.mjs +48 -0
  44. package/machine.mjs.map +1 -0
  45. package/mcp.d.mts +24 -0
  46. package/mcp.mjs +36 -0
  47. package/mcp.mjs.map +1 -0
  48. package/model.d.mts +18 -0
  49. package/model.mjs +35 -0
  50. package/model.mjs.map +1 -0
  51. package/package.json +182 -5
  52. package/pairing.d.mts +67 -0
  53. package/pairing.mjs +67 -0
  54. package/pairing.mjs.map +1 -0
  55. package/part-Bzm-yNax.d.mts +69 -0
  56. package/project.d.mts +30 -0
  57. package/project.mjs +27 -0
  58. package/project.mjs.map +1 -0
  59. package/records-316ZUpKX.mjs +127 -0
  60. package/records-316ZUpKX.mjs.map +1 -0
  61. package/relay.d.mts +285 -0
  62. package/relay.mjs +115 -0
  63. package/relay.mjs.map +1 -0
  64. package/repo.d.mts +42 -0
  65. package/repo.mjs +46 -0
  66. package/repo.mjs.map +1 -0
  67. package/rolldown-runtime-D7D4PA-g.mjs +13 -0
  68. package/sandbox/driver.d.mts +10 -0
  69. package/sandbox/driver.mjs +13 -0
  70. package/sandbox/driver.mjs.map +1 -0
  71. package/sandbox/errors.d.mts +130 -0
  72. package/sandbox/errors.mjs +112 -0
  73. package/sandbox/errors.mjs.map +1 -0
  74. package/sandbox/instance.d.mts +152 -0
  75. package/sandbox/instance.mjs +150 -0
  76. package/sandbox/instance.mjs.map +1 -0
  77. package/session.d.mts +59 -0
  78. package/session.mjs +69 -0
  79. package/session.mjs.map +1 -0
  80. package/settings.d.mts +22 -0
  81. package/settings.mjs +32 -0
  82. package/settings.mjs.map +1 -0
  83. package/shell.d.mts +5 -0
  84. package/shell.mjs +7 -0
  85. package/shell.mjs.map +1 -0
  86. package/space-CR-9UxdT.d.mts +25 -0
  87. package/space.d.mts +2 -0
  88. package/space.mjs +33 -0
  89. package/space.mjs.map +1 -0
  90. package/thread.d.mts +50 -0
  91. package/thread.mjs +69 -0
  92. package/thread.mjs.map +1 -0
  93. package/usage-B_TDmpKC.d.mts +15 -0
  94. package/usage.d.mts +2 -0
  95. package/usage.mjs +43 -0
  96. package/usage.mjs.map +1 -0
@@ -0,0 +1,127 @@
1
+ import { Schema } from "effect";
2
+ //#region src/records.ts
3
+ const Role = Schema.Literals([
4
+ "owner",
5
+ "admin",
6
+ "member"
7
+ ]);
8
+ /** A workspace's id, which the relay assigns; anything else is refused at the wire. */
9
+ const WorkspaceId = Schema.String.check(Schema.isUUID());
10
+ /** A machine's id: generated (a UUID) or set with `--machine-id`, lowercase letters, digits and dashes. */
11
+ const MachineId = Schema.String.check(Schema.isPattern(/^[a-z0-9][a-z0-9-]{0,63}$/));
12
+ var Account = class extends Schema.Class("Relay.Account")({
13
+ id: Schema.String,
14
+ email: Schema.String,
15
+ name: Schema.NullOr(Schema.String)
16
+ }) {};
17
+ var Workspace = class extends Schema.Class("Relay.Workspace")({
18
+ id: WorkspaceId,
19
+ name: Schema.String,
20
+ role: Role
21
+ }) {};
22
+ var Me = class extends Schema.Class("Relay.Me")({
23
+ account: Account,
24
+ workspaces: Schema.Array(Workspace)
25
+ }) {};
26
+ /** How a machine got its id: generated on first run, or set with `--machine-id`. */
27
+ const IdSource = Schema.Literals(["generated", "flag"]);
28
+ /** What a machine says about itself when it pairs and on every heartbeat. */
29
+ const MachineInfo = Schema.Struct({
30
+ id: MachineId,
31
+ source: IdSource,
32
+ localHostName: Schema.String,
33
+ givenName: Schema.NullOr(Schema.String),
34
+ os: Schema.String,
35
+ arch: Schema.String,
36
+ version: Schema.String
37
+ });
38
+ var Machine = class extends Schema.Class("Relay.Machine")({
39
+ ...MachineInfo.fields,
40
+ workspaceId: WorkspaceId,
41
+ /** The thumbprint of the key the link is live under; a home holds that key for this workspace. */
42
+ keyId: Schema.String,
43
+ /** The thumbprint of the home's identity key: links with the same one, in any workspace, are one machine. */
44
+ identityKeyId: Schema.String,
45
+ accountId: Schema.String,
46
+ online: Schema.Boolean,
47
+ lastSeenAt: Schema.NullOr(Schema.String)
48
+ }) {};
49
+ const SignedRequest = Schema.Struct({ jws: Schema.String });
50
+ const PairingClaims = Schema.Struct({
51
+ op: Schema.Literal("pairing.create"),
52
+ iat: Schema.Number,
53
+ machine: MachineInfo,
54
+ /** The workspace the connect started from; the approver may pick another when it is null. */
55
+ workspaceId: Schema.NullOr(WorkspaceId),
56
+ /** An {@link IdentityClaims} JWS by the home's identity key, naming this request's key. */
57
+ identity: Schema.String
58
+ });
59
+ /**
60
+ * A home's identity key vouching for one of its link keys. It embeds the identity key and names the link
61
+ * key's thumbprint, so the binding can't be replayed for another link.
62
+ */
63
+ const IdentityClaims = Schema.Struct({
64
+ op: Schema.Literal("identity.bind"),
65
+ iat: Schema.Number,
66
+ keyId: Schema.String
67
+ });
68
+ /** A pairing's poll, signed with the key it registered: only that process learns the outcome. */
69
+ const PollClaims = Schema.Struct({
70
+ op: Schema.Literal("pairing.poll"),
71
+ iat: Schema.Number
72
+ });
73
+ const HeartbeatClaims = Schema.Struct({
74
+ op: Schema.Literal("machine.heartbeat"),
75
+ iat: Schema.Number,
76
+ workspaceId: WorkspaceId,
77
+ machine: MachineInfo
78
+ });
79
+ const RevokeClaims = Schema.Struct({
80
+ op: Schema.Literal("machine.revoke"),
81
+ iat: Schema.Number,
82
+ /** Used once: a replayed revoke is refused. */
83
+ jti: Schema.String,
84
+ workspaceId: WorkspaceId,
85
+ machineId: MachineId
86
+ });
87
+ const PairingCreated = Schema.Struct({
88
+ userCode: Schema.String,
89
+ expiresIn: Schema.Int,
90
+ interval: Schema.Int
91
+ });
92
+ const Connected = Schema.Struct({
93
+ machineId: MachineId,
94
+ workspace: Schema.Struct({
95
+ id: WorkspaceId,
96
+ name: Schema.String
97
+ }),
98
+ account: Schema.Struct({
99
+ id: Schema.String,
100
+ name: Schema.NullOr(Schema.String)
101
+ })
102
+ });
103
+ const PairingStatus = Schema.Union([Schema.Struct({ status: Schema.Literals([
104
+ "pending",
105
+ "expired",
106
+ "declined",
107
+ "superseded"
108
+ ]) }), Schema.Struct({
109
+ status: Schema.Literal("approved"),
110
+ connected: Connected
111
+ })]);
112
+ /** A machine that ran `codework connect` for a workspace and waits for a member to approve its code. */
113
+ var PendingPairing = class extends Schema.Class("Relay.PendingPairing")({
114
+ userCode: Schema.String,
115
+ machine: MachineInfo,
116
+ /** `approved`: a member approved it and the machine's next poll links it. */
117
+ status: Schema.Literals(["pending", "approved"]),
118
+ /** A machine with this id is already in the workspace; approving replaces its link. */
119
+ replaces: Schema.Boolean,
120
+ createdAt: Schema.String,
121
+ expiresAt: Schema.String
122
+ }) {};
123
+ const WorkspaceName = Schema.Trimmed.check(Schema.isNonEmpty(), Schema.isMaxLength(64));
124
+ //#endregion
125
+ export { SignedRequest as _, IdentityClaims as a, WorkspaceName as b, MachineInfo as c, PairingCreated as d, PairingStatus as f, Role as g, RevokeClaims as h, IdSource as i, Me as l, PollClaims as m, Connected as n, Machine as o, PendingPairing as p, HeartbeatClaims as r, MachineId as s, Account as t, PairingClaims as u, Workspace as v, WorkspaceId as y };
126
+
127
+ //# sourceMappingURL=records-316ZUpKX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records-316ZUpKX.mjs","names":[],"sources":["../../src/records.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n// Relay's records and signed request claims, apart from its HTTP API in ./relay.ts, which re-exports them:\n// a module that needs only a record does not load the API.\n\nexport const Role = Schema.Literals([\"owner\", \"admin\", \"member\"]);\n\n/** A workspace's id, which the relay assigns; anything else is refused at the wire. */\nexport const WorkspaceId = Schema.String.check(Schema.isUUID());\n\n/** A machine's id: generated (a UUID) or set with `--machine-id`, lowercase letters, digits and dashes. */\nexport const MachineId = Schema.String.check(Schema.isPattern(/^[a-z0-9][a-z0-9-]{0,63}$/));\n\nexport class Account extends Schema.Class<Account>(\"Relay.Account\")({\n\tid: Schema.String,\n\temail: Schema.String,\n\tname: Schema.NullOr(Schema.String),\n}) {}\n\nexport class Workspace extends Schema.Class<Workspace>(\"Relay.Workspace\")({\n\tid: WorkspaceId,\n\tname: Schema.String,\n\trole: Role,\n}) {}\n\nexport class Me extends Schema.Class<Me>(\"Relay.Me\")({\n\taccount: Account,\n\tworkspaces: Schema.Array(Workspace),\n}) {}\n\n/** How a machine got its id: generated on first run, or set with `--machine-id`. */\nexport const IdSource = Schema.Literals([\"generated\", \"flag\"]);\n\n/** What a machine says about itself when it pairs and on every heartbeat. */\nexport const MachineInfo = Schema.Struct({\n\tid: MachineId,\n\tsource: IdSource,\n\tlocalHostName: Schema.String,\n\tgivenName: Schema.NullOr(Schema.String),\n\tos: Schema.String,\n\tarch: Schema.String,\n\tversion: Schema.String,\n});\nexport type MachineInfo = typeof MachineInfo.Type;\n\nexport class Machine extends Schema.Class<Machine>(\"Relay.Machine\")({\n\t...MachineInfo.fields,\n\tworkspaceId: WorkspaceId,\n\t/** The thumbprint of the key the link is live under; a home holds that key for this workspace. */\n\tkeyId: Schema.String,\n\t/** The thumbprint of the home's identity key: links with the same one, in any workspace, are one machine. */\n\tidentityKeyId: Schema.String,\n\taccountId: Schema.String,\n\tonline: Schema.Boolean,\n\tlastSeenAt: Schema.NullOr(Schema.String),\n}) {}\n\n// Signed machine requests: the body carries one compact JWS whose claims name the operation, so a\n// signature made for one endpoint is refused by every other.\n\nexport const SignedRequest = Schema.Struct({ jws: Schema.String });\n\nexport const PairingClaims = Schema.Struct({\n\top: Schema.Literal(\"pairing.create\"),\n\tiat: Schema.Number,\n\tmachine: MachineInfo,\n\t/** The workspace the connect started from; the approver may pick another when it is null. */\n\tworkspaceId: Schema.NullOr(WorkspaceId),\n\t/** An {@link IdentityClaims} JWS by the home's identity key, naming this request's key. */\n\tidentity: Schema.String,\n});\nexport type PairingClaims = typeof PairingClaims.Type;\n\n/**\n * A home's identity key vouching for one of its link keys. It embeds the identity key and names the link\n * key's thumbprint, so the binding can't be replayed for another link.\n */\nexport const IdentityClaims = Schema.Struct({\n\top: Schema.Literal(\"identity.bind\"),\n\tiat: Schema.Number,\n\tkeyId: Schema.String,\n});\nexport type IdentityClaims = typeof IdentityClaims.Type;\n\n/** A pairing's poll, signed with the key it registered: only that process learns the outcome. */\nexport const PollClaims = Schema.Struct({\n\top: Schema.Literal(\"pairing.poll\"),\n\tiat: Schema.Number,\n});\nexport type PollClaims = typeof PollClaims.Type;\n\nexport const HeartbeatClaims = Schema.Struct({\n\top: Schema.Literal(\"machine.heartbeat\"),\n\tiat: Schema.Number,\n\tworkspaceId: WorkspaceId,\n\tmachine: MachineInfo,\n});\nexport type HeartbeatClaims = typeof HeartbeatClaims.Type;\n\nexport const RevokeClaims = Schema.Struct({\n\top: Schema.Literal(\"machine.revoke\"),\n\tiat: Schema.Number,\n\t/** Used once: a replayed revoke is refused. */\n\tjti: Schema.String,\n\tworkspaceId: WorkspaceId,\n\tmachineId: MachineId,\n});\nexport type RevokeClaims = typeof RevokeClaims.Type;\n\nexport const PairingCreated = Schema.Struct({\n\tuserCode: Schema.String,\n\texpiresIn: Schema.Int,\n\tinterval: Schema.Int,\n});\n\nexport const Connected = Schema.Struct({\n\tmachineId: MachineId,\n\tworkspace: Schema.Struct({ id: WorkspaceId, name: Schema.String }),\n\taccount: Schema.Struct({ id: Schema.String, name: Schema.NullOr(Schema.String) }),\n});\nexport type Connected = typeof Connected.Type;\n\nexport const PairingStatus = Schema.Union([\n\t/** `superseded`: another connect for this machine and workspace was activated first. */\n\tSchema.Struct({ status: Schema.Literals([\"pending\", \"expired\", \"declined\", \"superseded\"]) }),\n\tSchema.Struct({ status: Schema.Literal(\"approved\"), connected: Connected }),\n]);\nexport type PairingStatus = typeof PairingStatus.Type;\n\n/** A machine that ran `codework connect` for a workspace and waits for a member to approve its code. */\nexport class PendingPairing extends Schema.Class<PendingPairing>(\"Relay.PendingPairing\")({\n\tuserCode: Schema.String,\n\tmachine: MachineInfo,\n\t/** `approved`: a member approved it and the machine's next poll links it. */\n\tstatus: Schema.Literals([\"pending\", \"approved\"]),\n\t/** A machine with this id is already in the workspace; approving replaces its link. */\n\treplaces: Schema.Boolean,\n\tcreatedAt: Schema.String,\n\texpiresAt: Schema.String,\n}) {}\n\nexport const WorkspaceName = Schema.Trimmed.check(Schema.isNonEmpty(), Schema.isMaxLength(64));\n"],"mappings":";;AAKA,MAAa,OAAO,OAAO,SAAS;CAAC;CAAS;CAAS;AAAQ,CAAC;;AAGhE,MAAa,cAAc,OAAO,O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O,YAAY,EAAE,CAAC"}
package/relay.d.mts ADDED
@@ -0,0 +1,285 @@
1
+ import { Context, Schema } from "effect";
2
+ import { HttpApi, HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSecurity } from "effect/http-api";
3
+ //#region src/records.d.ts
4
+ export declare const Role: Schema.Literals<readonly ["owner", "admin", "member"]>;
5
+ /** A workspace's id, which the relay assigns; anything else is refused at the wire. */
6
+ export declare const WorkspaceId: Schema.String;
7
+ /** A machine's id: generated (a UUID) or set with `--machine-id`, lowercase letters, digits and dashes. */
8
+ export declare const MachineId: Schema.String;
9
+ declare const Account_base: Schema.Class<Account, Schema.Struct<{
10
+ readonly id: Schema.String;
11
+ readonly email: Schema.String;
12
+ readonly name: Schema.NullOr<Schema.String>;
13
+ }>, {}>;
14
+ export declare class Account extends Account_base {}
15
+ declare const Workspace_base: Schema.Class<Workspace, Schema.Struct<{
16
+ readonly id: Schema.String;
17
+ readonly name: Schema.String;
18
+ readonly role: Schema.Literals<readonly ["owner", "admin", "member"]>;
19
+ }>, {}>;
20
+ export declare class Workspace extends Workspace_base {}
21
+ declare const Me_base: Schema.Class<Me, Schema.Struct<{
22
+ readonly account: typeof Account;
23
+ readonly workspaces: Schema.$Array<typeof Workspace>;
24
+ }>, {}>;
25
+ export declare class Me extends Me_base {}
26
+ /** How a machine got its id: generated on first run, or set with `--machine-id`. */
27
+ export declare const IdSource: Schema.Literals<readonly ["generated", "flag"]>;
28
+ /** What a machine says about itself when it pairs and on every heartbeat. */
29
+ export declare const MachineInfo: Schema.Struct<{
30
+ readonly id: Schema.String;
31
+ readonly source: Schema.Literals<readonly ["generated", "flag"]>;
32
+ readonly localHostName: Schema.String;
33
+ readonly givenName: Schema.NullOr<Schema.String>;
34
+ readonly os: Schema.String;
35
+ readonly arch: Schema.String;
36
+ readonly version: Schema.String;
37
+ }>;
38
+ export type MachineInfo = typeof MachineInfo.Type;
39
+ declare const Machine_base: Schema.Class<Machine, Schema.Struct<{
40
+ readonly id: Schema.String;
41
+ readonly source: Schema.Literals<readonly ["generated", "flag"]>;
42
+ readonly localHostName: Schema.String;
43
+ readonly givenName: Schema.NullOr<Schema.String>;
44
+ readonly os: Schema.String;
45
+ readonly arch: Schema.String;
46
+ readonly version: Schema.String;
47
+ readonly workspaceId: Schema.String;
48
+ /** The thumbprint of the key the link is live under; a home holds that key for this workspace. */
49
+ readonly keyId: Schema.String;
50
+ /** The thumbprint of the home's identity key: links with the same one, in any workspace, are one machine. */
51
+ readonly identityKeyId: Schema.String;
52
+ readonly accountId: Schema.String;
53
+ readonly online: Schema.Boolean;
54
+ readonly lastSeenAt: Schema.NullOr<Schema.String>;
55
+ }>, {}>;
56
+ export declare class Machine extends Machine_base {}
57
+ export declare const SignedRequest: Schema.Struct<{
58
+ readonly jws: Schema.String;
59
+ }>;
60
+ export declare const PairingClaims: Schema.Struct<{
61
+ readonly op: Schema.Literal<"pairing.create">;
62
+ readonly iat: Schema.Number;
63
+ readonly machine: Schema.Struct<{
64
+ readonly id: Schema.String;
65
+ readonly source: Schema.Literals<readonly ["generated", "flag"]>;
66
+ readonly localHostName: Schema.String;
67
+ readonly givenName: Schema.NullOr<Schema.String>;
68
+ readonly os: Schema.String;
69
+ readonly arch: Schema.String;
70
+ readonly version: Schema.String;
71
+ }>;
72
+ /** The workspace the connect started from; the approver may pick another when it is null. */
73
+ readonly workspaceId: Schema.NullOr<Schema.String>;
74
+ /** An {@link IdentityClaims} JWS by the home's identity key, naming this request's key. */
75
+ readonly identity: Schema.String;
76
+ }>;
77
+ export type PairingClaims = typeof PairingClaims.Type;
78
+ /**
79
+ * A home's identity key vouching for one of its link keys. It embeds the identity key and names the link
80
+ * key's thumbprint, so the binding can't be replayed for another link.
81
+ */
82
+ export declare const IdentityClaims: Schema.Struct<{
83
+ readonly op: Schema.Literal<"identity.bind">;
84
+ readonly iat: Schema.Number;
85
+ readonly keyId: Schema.String;
86
+ }>;
87
+ export type IdentityClaims = typeof IdentityClaims.Type;
88
+ /** A pairing's poll, signed with the key it registered: only that process learns the outcome. */
89
+ export declare const PollClaims: Schema.Struct<{
90
+ readonly op: Schema.Literal<"pairing.poll">;
91
+ readonly iat: Schema.Number;
92
+ }>;
93
+ export type PollClaims = typeof PollClaims.Type;
94
+ export declare const HeartbeatClaims: Schema.Struct<{
95
+ readonly op: Schema.Literal<"machine.heartbeat">;
96
+ readonly iat: Schema.Number;
97
+ readonly workspaceId: Schema.String;
98
+ readonly machine: Schema.Struct<{
99
+ readonly id: Schema.String;
100
+ readonly source: Schema.Literals<readonly ["generated", "flag"]>;
101
+ readonly localHostName: Schema.String;
102
+ readonly givenName: Schema.NullOr<Schema.String>;
103
+ readonly os: Schema.String;
104
+ readonly arch: Schema.String;
105
+ readonly version: Schema.String;
106
+ }>;
107
+ }>;
108
+ export type HeartbeatClaims = typeof HeartbeatClaims.Type;
109
+ export declare const RevokeClaims: Schema.Struct<{
110
+ readonly op: Schema.Literal<"machine.revoke">;
111
+ readonly iat: Schema.Number;
112
+ /** Used once: a replayed revoke is refused. */
113
+ readonly jti: Schema.String;
114
+ readonly workspaceId: Schema.String;
115
+ readonly machineId: Schema.String;
116
+ }>;
117
+ export type RevokeClaims = typeof RevokeClaims.Type;
118
+ export declare const PairingCreated: Schema.Struct<{
119
+ readonly userCode: Schema.String;
120
+ readonly expiresIn: Schema.Int;
121
+ readonly interval: Schema.Int;
122
+ }>;
123
+ export declare const Connected: Schema.Struct<{
124
+ readonly machineId: Schema.String;
125
+ readonly workspace: Schema.Struct<{
126
+ readonly id: Schema.String;
127
+ readonly name: Schema.String;
128
+ }>;
129
+ readonly account: Schema.Struct<{
130
+ readonly id: Schema.String;
131
+ readonly name: Schema.NullOr<Schema.String>;
132
+ }>;
133
+ }>;
134
+ export type Connected = typeof Connected.Type;
135
+ export declare const PairingStatus: Schema.Union<readonly [Schema.Struct<{
136
+ readonly status: Schema.Literals<readonly ["pending", "expired", "declined", "superseded"]>;
137
+ }>, Schema.Struct<{
138
+ readonly status: Schema.Literal<"approved">;
139
+ readonly connected: Schema.Struct<{
140
+ readonly machineId: Schema.String;
141
+ readonly workspace: Schema.Struct<{
142
+ readonly id: Schema.String;
143
+ readonly name: Schema.String;
144
+ }>;
145
+ readonly account: Schema.Struct<{
146
+ readonly id: Schema.String;
147
+ readonly name: Schema.NullOr<Schema.String>;
148
+ }>;
149
+ }>;
150
+ }>]>;
151
+ export type PairingStatus = typeof PairingStatus.Type;
152
+ declare const PendingPairing_base: Schema.Class<PendingPairing, Schema.Struct<{
153
+ readonly userCode: Schema.String;
154
+ readonly machine: Schema.Struct<{
155
+ readonly id: Schema.String;
156
+ readonly source: Schema.Literals<readonly ["generated", "flag"]>;
157
+ readonly localHostName: Schema.String;
158
+ readonly givenName: Schema.NullOr<Schema.String>;
159
+ readonly os: Schema.String;
160
+ readonly arch: Schema.String;
161
+ readonly version: Schema.String;
162
+ }>;
163
+ /** `approved`: a member approved it and the machine's next poll links it. */
164
+ readonly status: Schema.Literals<readonly ["pending", "approved"]>;
165
+ /** A machine with this id is already in the workspace; approving replaces its link. */
166
+ readonly replaces: Schema.Boolean;
167
+ readonly createdAt: Schema.String;
168
+ readonly expiresAt: Schema.String;
169
+ }>, {}>;
170
+ /** A machine that ran `codework connect` for a workspace and waits for a member to approve its code. */
171
+ export declare class PendingPairing extends PendingPairing_base {}
172
+ export declare const WorkspaceName: Schema.Trimmed;
173
+ declare namespace relay_d_exports {
174
+ export { Account, Api, Connected, Forbidden, HeartbeatClaims, IdSource, IdentityClaims, Machine, MachineGroup, MachineId, MachineInfo, MachineRevoked, Me, MeGroup, NotFound, PairingClaims, PairingCreated, PairingStatus, PendingPairing, Person, PersonAuth, PollClaims, relay_d_exports as Relay, RevokeClaims, Role, SignedRequest, Unauthorized, Unavailable, Workspace, WorkspaceGroup, WorkspaceId, WorkspaceName };
175
+ }
176
+ declare const Unauthorized_base: Schema.Class<Unauthorized, Schema.TaggedStruct<"Relay.Unauthorized", {
177
+ readonly message: Schema.String;
178
+ }>, import("effect/Cause").YieldableError>;
179
+ export declare class Unauthorized extends Unauthorized_base {}
180
+ declare const Unavailable_base: Schema.Class<Unavailable, Schema.TaggedStruct<"Relay.Unavailable", {
181
+ readonly message: Schema.String;
182
+ }>, import("effect/Cause").YieldableError>;
183
+ /** The relay couldn't check the request just now (its auth vendor is unreachable): try again shortly. */
184
+ export declare class Unavailable extends Unavailable_base {}
185
+ declare const MachineRevoked_base: Schema.Class<MachineRevoked, Schema.TaggedStruct<"Relay.MachineRevoked", {
186
+ readonly message: Schema.String;
187
+ }>, import("effect/Cause").YieldableError>;
188
+ /** The machine's link to the workspace is gone: revoked, replaced, or its owner left. Reconnect to restore it. */
189
+ export declare class MachineRevoked extends MachineRevoked_base {}
190
+ declare const Forbidden_base: Schema.Class<Forbidden, Schema.TaggedStruct<"Relay.Forbidden", {
191
+ readonly message: Schema.String;
192
+ }>, import("effect/Cause").YieldableError>;
193
+ export declare class Forbidden extends Forbidden_base {}
194
+ declare const NotFound_base: Schema.Class<NotFound, Schema.TaggedStruct<"Relay.NotFound", {
195
+ readonly message: Schema.String;
196
+ }>, import("effect/Cause").YieldableError>;
197
+ export declare class NotFound extends NotFound_base {}
198
+ declare const Person_base: Context.ServiceClass<Person, "relay/Person", {
199
+ readonly authId: string;
200
+ }>;
201
+ /** A person whose session token the auth vendor verified: only the vendor's subject id. */
202
+ export declare class Person extends Person_base {}
203
+ declare const PersonAuth_base: HttpApiMiddleware.ServiceClass<PersonAuth, "relay/PersonAuth", {
204
+ requires: never;
205
+ provides: Person;
206
+ error: readonly [typeof Unauthorized, typeof Unavailable];
207
+ clientError: never;
208
+ requiredForClient: false;
209
+ security: {
210
+ readonly bearer: HttpApiSecurity.Http;
211
+ };
212
+ }, HttpApiMiddleware.HttpApiMiddlewareSecurity<{
213
+ readonly bearer: HttpApiSecurity.Http;
214
+ }, Person, readonly [typeof Unauthorized, typeof Unavailable], never>>;
215
+ /** Verifies a person's bearer session token and provides {@link Person}. */
216
+ export declare class PersonAuth extends PersonAuth_base {}
217
+ declare const MeGroup_base: HttpApiGroup.HttpApiGroup<"me", HttpApiEndpoint.HttpApiEndpoint<"get", "GET", "/v1/me", never, never, never, never, Schema.toCodecJson<typeof Me>, never, PersonAuth, never>, false>;
218
+ export declare class MeGroup extends MeGroup_base {}
219
+ declare const WorkspaceGroup_base: HttpApiGroup.HttpApiGroup<"workspace", HttpApiEndpoint.HttpApiEndpoint<"machines", "GET", "/v1/workspaces/:workspaceId/machines", Schema.toCodecStringTree<Schema.Struct<{
220
+ workspaceId: Schema.String;
221
+ }>>, never, never, never, Schema.toCodecJson<Schema.$Array<typeof Machine>>, Schema.toCodecJson<typeof Forbidden>, PersonAuth, never> | HttpApiEndpoint.HttpApiEndpoint<"pairings", "GET", "/v1/workspaces/:workspaceId/pairings", Schema.toCodecStringTree<Schema.Struct<{
222
+ workspaceId: Schema.String;
223
+ }>>, never, never, never, Schema.toCodecJson<Schema.$Array<typeof PendingPairing>>, Schema.toCodecJson<typeof Forbidden>, PersonAuth, never> | HttpApiEndpoint.HttpApiEndpoint<"create", "POST", "/v1/workspaces", never, never, Schema.toCodecJson<Schema.Struct<{
224
+ readonly name: Schema.Trimmed;
225
+ }>>, never, Schema.toCodecJson<typeof Workspace>, never, PersonAuth, never> | HttpApiEndpoint.HttpApiEndpoint<"remove", "POST", "/v1/workspaces/:workspaceId/machines/:machineId/remove", Schema.toCodecStringTree<Schema.Struct<{
226
+ workspaceId: Schema.String;
227
+ machineId: Schema.String;
228
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
229
+ readonly keyId: Schema.String;
230
+ }>>, never, Schema.toCodecJson<import("effect/http-api/HttpApiSchema").NoContent>, Schema.toCodecJson<typeof Forbidden | typeof NotFound>, PersonAuth, never> | HttpApiEndpoint.HttpApiEndpoint<"approve", "POST", "/v1/workspaces/:workspaceId/pairings/approve", Schema.toCodecStringTree<Schema.Struct<{
231
+ workspaceId: Schema.String;
232
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
233
+ readonly userCode: Schema.String;
234
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
235
+ readonly machine: Schema.Struct<{
236
+ readonly id: Schema.String;
237
+ readonly source: Schema.Literals<readonly ["generated", "flag"]>;
238
+ readonly localHostName: Schema.String;
239
+ readonly givenName: Schema.NullOr<Schema.String>;
240
+ readonly os: Schema.String;
241
+ readonly arch: Schema.String;
242
+ readonly version: Schema.String;
243
+ }>;
244
+ }>>, Schema.toCodecJson<typeof Forbidden | typeof NotFound>, PersonAuth, never> | HttpApiEndpoint.HttpApiEndpoint<"decline", "POST", "/v1/workspaces/:workspaceId/pairings/decline", Schema.toCodecStringTree<Schema.Struct<{
245
+ workspaceId: Schema.String;
246
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
247
+ readonly userCode: Schema.String;
248
+ }>>, never, Schema.toCodecJson<import("effect/http-api/HttpApiSchema").NoContent>, Schema.toCodecJson<typeof Forbidden | typeof NotFound>, PersonAuth, never>, false>;
249
+ /** People create workspaces, and manage pairings and machines in a workspace they belong to. */
250
+ export declare class WorkspaceGroup extends WorkspaceGroup_base {}
251
+ declare const MachineGroup_base: HttpApiGroup.HttpApiGroup<"machine", HttpApiEndpoint.HttpApiEndpoint<"heartbeat", "POST", "/v1/machines/heartbeat", never, never, Schema.toCodecJson<Schema.Struct<{
252
+ readonly jws: Schema.String;
253
+ }>>, never, Schema.toCodecJson<import("effect/http-api/HttpApiSchema").NoContent>, Schema.toCodecJson<typeof Unauthorized | typeof MachineRevoked>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"pair", "POST", "/v1/pairings", never, never, Schema.toCodecJson<Schema.Struct<{
254
+ readonly jws: Schema.String;
255
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
256
+ readonly userCode: Schema.String;
257
+ readonly expiresIn: Schema.Int;
258
+ readonly interval: Schema.Int;
259
+ }>>, Schema.toCodecJson<typeof Unauthorized | typeof NotFound>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"poll", "POST", "/v1/pairings/poll", never, never, Schema.toCodecJson<Schema.Struct<{
260
+ readonly jws: Schema.String;
261
+ }>>, never, Schema.toCodecJson<Schema.Union<readonly [Schema.Struct<{
262
+ readonly status: Schema.Literals<readonly ["pending", "expired", "declined", "superseded"]>;
263
+ }>, Schema.Struct<{
264
+ readonly status: Schema.Literal<"approved">;
265
+ readonly connected: Schema.Struct<{
266
+ readonly machineId: Schema.String;
267
+ readonly workspace: Schema.Struct<{
268
+ readonly id: Schema.String;
269
+ readonly name: Schema.String;
270
+ }>;
271
+ readonly account: Schema.Struct<{
272
+ readonly id: Schema.String;
273
+ readonly name: Schema.NullOr<Schema.String>;
274
+ }>;
275
+ }>;
276
+ }>]>>, Schema.toCodecJson<typeof Unauthorized | typeof NotFound>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"revoke", "POST", "/v1/machines/revoke", never, never, Schema.toCodecJson<Schema.Struct<{
277
+ readonly jws: Schema.String;
278
+ }>>, never, Schema.toCodecJson<import("effect/http-api/HttpApiSchema").NoContent>, Schema.toCodecJson<typeof Unauthorized | typeof MachineRevoked>, never, never>, false>;
279
+ /** Machines authenticate each request with a signature, not a session. */
280
+ export declare class MachineGroup extends MachineGroup_base {}
281
+ declare const Api_base: HttpApi.HttpApi<"relay", typeof MeGroup | typeof WorkspaceGroup | typeof MachineGroup>;
282
+ export declare class Api extends Api_base {}
283
+ //#endregion
284
+ export { relay_d_exports as Relay };
285
+ //# sourceMappingURL=relay.d.mts.map
package/relay.mjs ADDED
@@ -0,0 +1,115 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { _ as SignedRequest, a as IdentityClaims, b as WorkspaceName, c as MachineInfo, d as PairingCreated, f as PairingStatus, g as Role, h as RevokeClaims, i as IdSource, l as Me, m as PollClaims, n as Connected, o as Machine, p as PendingPairing, r as HeartbeatClaims, s as MachineId, t as Account, u as PairingClaims, v as Workspace, y as WorkspaceId } from "./records-316ZUpKX.mjs";
3
+ import { Context, Schema } from "effect";
4
+ import { HttpApi, HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSecurity } from "effect/http-api";
5
+ //#region src/relay.ts
6
+ var relay_exports = /* @__PURE__ */ __exportAll({
7
+ Account: () => Account,
8
+ Api: () => Api,
9
+ Connected: () => Connected,
10
+ Forbidden: () => Forbidden,
11
+ HeartbeatClaims: () => HeartbeatClaims,
12
+ IdSource: () => IdSource,
13
+ IdentityClaims: () => IdentityClaims,
14
+ Machine: () => Machine,
15
+ MachineGroup: () => MachineGroup,
16
+ MachineId: () => MachineId,
17
+ MachineInfo: () => MachineInfo,
18
+ MachineRevoked: () => MachineRevoked,
19
+ Me: () => Me,
20
+ MeGroup: () => MeGroup,
21
+ NotFound: () => NotFound,
22
+ PairingClaims: () => PairingClaims,
23
+ PairingCreated: () => PairingCreated,
24
+ PairingStatus: () => PairingStatus,
25
+ PendingPairing: () => PendingPairing,
26
+ Person: () => Person,
27
+ PersonAuth: () => PersonAuth,
28
+ PollClaims: () => PollClaims,
29
+ Relay: () => relay_exports,
30
+ RevokeClaims: () => RevokeClaims,
31
+ Role: () => Role,
32
+ SignedRequest: () => SignedRequest,
33
+ Unauthorized: () => Unauthorized,
34
+ Unavailable: () => Unavailable,
35
+ Workspace: () => Workspace,
36
+ WorkspaceGroup: () => WorkspaceGroup,
37
+ WorkspaceId: () => WorkspaceId,
38
+ WorkspaceName: () => WorkspaceName
39
+ });
40
+ var Unauthorized = class extends Schema.TaggedError()("Relay.Unauthorized", { message: Schema.String }, { httpApiStatus: 401 }) {};
41
+ /** The relay couldn't check the request just now (its auth vendor is unreachable): try again shortly. */
42
+ var Unavailable = class extends Schema.TaggedError()("Relay.Unavailable", { message: Schema.String }, { httpApiStatus: 503 }) {};
43
+ /** The machine's link to the workspace is gone: revoked, replaced, or its owner left. Reconnect to restore it. */
44
+ var MachineRevoked = class extends Schema.TaggedError()("Relay.MachineRevoked", { message: Schema.String }, { httpApiStatus: 401 }) {};
45
+ var Forbidden = class extends Schema.TaggedError()("Relay.Forbidden", { message: Schema.String }, { httpApiStatus: 403 }) {};
46
+ var NotFound = class extends Schema.TaggedError()("Relay.NotFound", { message: Schema.String }, { httpApiStatus: 404 }) {};
47
+ /** A person whose session token the auth vendor verified: only the vendor's subject id. */
48
+ var Person = class extends Context.Service()("relay/Person") {};
49
+ /** Verifies a person's bearer session token and provides {@link Person}. */
50
+ var PersonAuth = class extends HttpApiMiddleware.Service()("relay/PersonAuth", {
51
+ security: { bearer: HttpApiSecurity.bearer },
52
+ error: [Unauthorized, Unavailable]
53
+ }) {};
54
+ var MeGroup = class extends HttpApiGroup.make("me").add(HttpApiEndpoint.get("get", "/v1/me", { success: Me })).middleware(PersonAuth) {};
55
+ /** People create workspaces, and manage pairings and machines in a workspace they belong to. */
56
+ var WorkspaceGroup = class extends HttpApiGroup.make("workspace").add(
57
+ HttpApiEndpoint.post("create", "/v1/workspaces", {
58
+ payload: Schema.Struct({ name: WorkspaceName }),
59
+ success: Workspace
60
+ }),
61
+ /** Approves a code; the machine's next poll links it, so it answers with what the machine said. */
62
+ HttpApiEndpoint.post("approve", "/v1/workspaces/:workspaceId/pairings/approve", {
63
+ params: { workspaceId: WorkspaceId },
64
+ payload: Schema.Struct({ userCode: Schema.String }),
65
+ success: Schema.Struct({ machine: MachineInfo }),
66
+ error: [NotFound, Forbidden]
67
+ }),
68
+ HttpApiEndpoint.get("machines", "/v1/workspaces/:workspaceId/machines", {
69
+ params: { workspaceId: WorkspaceId },
70
+ success: Schema.Array(Machine),
71
+ error: Forbidden
72
+ }),
73
+ /** The workspace's pending connects, each with the code its machine shows. */
74
+ HttpApiEndpoint.get("pairings", "/v1/workspaces/:workspaceId/pairings", {
75
+ params: { workspaceId: WorkspaceId },
76
+ success: Schema.Array(PendingPairing),
77
+ error: Forbidden
78
+ }),
79
+ /** Turns a pending connect away; the waiting machine hears it was declined. */
80
+ HttpApiEndpoint.post("decline", "/v1/workspaces/:workspaceId/pairings/decline", {
81
+ params: { workspaceId: WorkspaceId },
82
+ payload: Schema.Struct({ userCode: Schema.String }),
83
+ error: [NotFound, Forbidden]
84
+ }),
85
+ /** Disconnects a machine from the workspace: its owner, or a workspace owner or admin, may. */
86
+ HttpApiEndpoint.post("remove", "/v1/workspaces/:workspaceId/machines/:machineId/remove", {
87
+ params: {
88
+ workspaceId: WorkspaceId,
89
+ machineId: MachineId
90
+ },
91
+ payload: Schema.Struct({ keyId: Schema.String }),
92
+ error: [NotFound, Forbidden]
93
+ })
94
+ ).middleware(PersonAuth) {};
95
+ /** Machines authenticate each request with a signature, not a session. */
96
+ var MachineGroup = class extends HttpApiGroup.make("machine").add(HttpApiEndpoint.post("pair", "/v1/pairings", {
97
+ payload: SignedRequest,
98
+ success: PairingCreated,
99
+ error: [Unauthorized, NotFound]
100
+ }), HttpApiEndpoint.post("poll", "/v1/pairings/poll", {
101
+ payload: SignedRequest,
102
+ success: PairingStatus,
103
+ error: [Unauthorized, NotFound]
104
+ }), HttpApiEndpoint.post("heartbeat", "/v1/machines/heartbeat", {
105
+ payload: SignedRequest,
106
+ error: [Unauthorized, MachineRevoked]
107
+ }), HttpApiEndpoint.post("revoke", "/v1/machines/revoke", {
108
+ payload: SignedRequest,
109
+ error: [Unauthorized, MachineRevoked]
110
+ })) {};
111
+ var Api = class extends HttpApi.make("relay").add(MeGroup).add(WorkspaceGroup).add(MachineGroup) {};
112
+ //#endregion
113
+ export { Account, Api, Connected, Forbidden, HeartbeatClaims, IdSource, IdentityClaims, Machine, MachineGroup, MachineId, MachineInfo, MachineRevoked, Me, MeGroup, NotFound, PairingClaims, PairingCreated, PairingStatus, PendingPairing, Person, PersonAuth, PollClaims, relay_exports as Relay, RevokeClaims, Role, SignedRequest, Unauthorized, Unavailable, Workspace, WorkspaceGroup, WorkspaceId, WorkspaceName };
114
+
115
+ //# sourceMappingURL=relay.mjs.map
package/relay.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.mjs","names":[],"sources":["../../src/relay.ts"],"sourcesContent":["import { Context, Schema } from \"effect\";\nimport { HttpApi, HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSecurity } from \"effect/http-api\";\nimport {\n\tMachine,\n\tMachineId,\n\tMachineInfo,\n\tMe,\n\tPairingCreated,\n\tPairingStatus,\n\tPendingPairing,\n\tSignedRequest,\n\tWorkspace,\n\tWorkspaceId,\n\tWorkspaceName,\n} from \"./records.ts\";\n\n// The relay's HTTP API (relay.codework.sh): people call it with an auth-vendor session token, machines\n// with requests signed by their own key (see ./jws.ts). The relay implements it; codework is a client.\n\nexport class Unauthorized extends Schema.TaggedError<Unauthorized>()(\n\t\"Relay.Unauthorized\",\n\t{ message: Schema.String },\n\t{ httpApiStatus: 401 },\n) {}\n\n/** The relay couldn't check the request just now (its auth vendor is unreachable): try again shortly. */\nexport class Unavailable extends Schema.TaggedError<Unavailable>()(\n\t\"Relay.Unavailable\",\n\t{ message: Schema.String },\n\t{ httpApiStatus: 503 },\n) {}\n\n/** The machine's link to the workspace is gone: revoked, replaced, or its owner left. Reconnect to restore it. */\nexport class MachineRevoked extends Schema.TaggedError<MachineRevoked>()(\n\t\"Relay.MachineRevoked\",\n\t{ message: Schema.String },\n\t{ httpApiStatus: 401 },\n) {}\n\nexport class Forbidden extends Schema.TaggedError<Forbidden>()(\n\t\"Relay.Forbidden\",\n\t{ message: Schema.String },\n\t{ httpApiStatus: 403 },\n) {}\n\nexport class NotFound extends Schema.TaggedError<NotFound>()(\n\t\"Relay.NotFound\",\n\t{ message: Schema.String },\n\t{ httpApiStatus: 404 },\n) {}\n\n/** A person whose session token the auth vendor verified: only the vendor's subject id. */\nexport class Person extends Context.Service<Person, { readonly authId: string }>()(\"relay/Person\") {}\n\n/** Verifies a person's bearer session token and provides {@link Person}. */\nexport class PersonAuth extends HttpApiMiddleware.Service<PersonAuth, { provides: Person; requires: never }>()(\n\t\"relay/PersonAuth\",\n\t{\n\t\tsecurity: { bearer: HttpApiSecurity.bearer },\n\t\terror: [Unauthorized, Unavailable],\n\t},\n) {}\n\nexport class MeGroup extends HttpApiGroup.make(\"me\")\n\t.add(HttpApiEndpoint.get(\"get\", \"/v1/me\", { success: Me }))\n\t.middleware(PersonAuth) {}\n\n/** People create workspaces, and manage pairings and machines in a workspace they belong to. */\nexport class WorkspaceGroup extends HttpApiGroup.make(\"workspace\")\n\t.add(\n\t\tHttpApiEndpoint.post(\"create\", \"/v1/workspaces\", {\n\t\t\tpayload: Schema.Struct({ name: WorkspaceName }),\n\t\t\tsuccess: Workspace,\n\t\t}),\n\t\t/** Approves a code; the machine's next poll links it, so it answers with what the machine said. */\n\t\tHttpApiEndpoint.post(\"approve\", \"/v1/workspaces/:workspaceId/pairings/approve\", {\n\t\t\tparams: { workspaceId: WorkspaceId },\n\t\t\tpayload: Schema.Struct({ userCode: Schema.String }),\n\t\t\tsuccess: Schema.Struct({ machine: MachineInfo }),\n\t\t\terror: [NotFound, Forbidden],\n\t\t}),\n\t\tHttpApiEndpoint.get(\"machines\", \"/v1/workspaces/:workspaceId/machines\", {\n\t\t\tparams: { workspaceId: WorkspaceId },\n\t\t\tsuccess: Schema.Array(Machine),\n\t\t\terror: Forbidden,\n\t\t}),\n\t\t/** The workspace's pending connects, each with the code its machine shows. */\n\t\tHttpApiEndpoint.get(\"pairings\", \"/v1/workspaces/:workspaceId/pairings\", {\n\t\t\tparams: { workspaceId: WorkspaceId },\n\t\t\tsuccess: Schema.Array(PendingPairing),\n\t\t\terror: Forbidden,\n\t\t}),\n\t\t/** Turns a pending connect away; the waiting machine hears it was declined. */\n\t\tHttpApiEndpoint.post(\"decline\", \"/v1/workspaces/:workspaceId/pairings/decline\", {\n\t\t\tparams: { workspaceId: WorkspaceId },\n\t\t\tpayload: Schema.Struct({ userCode: Schema.String }),\n\t\t\terror: [NotFound, Forbidden],\n\t\t}),\n\t\t/** Disconnects a machine from the workspace: its owner, or a workspace owner or admin, may. */\n\t\tHttpApiEndpoint.post(\"remove\", \"/v1/workspaces/:workspaceId/machines/:machineId/remove\", {\n\t\t\tparams: { workspaceId: WorkspaceId, machineId: MachineId },\n\t\t\tpayload: Schema.Struct({ keyId: Schema.String }),\n\t\t\terror: [NotFound, Forbidden],\n\t\t}),\n\t)\n\t.middleware(PersonAuth) {}\n\n/** Machines authenticate each request with a signature, not a session. */\nexport class MachineGroup extends HttpApiGroup.make(\"machine\").add(\n\tHttpApiEndpoint.post(\"pair\", \"/v1/pairings\", {\n\t\tpayload: SignedRequest,\n\t\tsuccess: PairingCreated,\n\t\terror: [Unauthorized, NotFound],\n\t}),\n\tHttpApiEndpoint.post(\"poll\", \"/v1/pairings/poll\", {\n\t\tpayload: SignedRequest,\n\t\tsuccess: PairingStatus,\n\t\terror: [Unauthorized, NotFound],\n\t}),\n\tHttpApiEndpoint.post(\"heartbeat\", \"/v1/machines/heartbeat\", {\n\t\tpayload: SignedRequest,\n\t\terror: [Unauthorized, MachineRevoked],\n\t}),\n\tHttpApiEndpoint.post(\"revoke\", \"/v1/machines/revoke\", {\n\t\tpayload: SignedRequest,\n\t\terror: [Unauthorized, MachineRevoked],\n\t}),\n) {}\n\nexport class Api extends HttpApi.make(\"relay\").add(MeGroup).add(WorkspaceGroup).add(MachineGroup) {}\n\nexport * from \"./records.ts\";\nexport * as Relay from \"./relay.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAa,eAAb,cAAkC,OAAO,YAA0B,CAAC,CACnE,sBACA,EAAE,SAAS,OAAO,OAAO,GACzB,EAAE,eAAe,IAAI,CACtB,CAAC,CAAC,CAAC;;AAGH,IAAa,cAAb,cAAiC,OAAO,YAAyB,CAAC,CACjE,qBACA,EAAE,SAAS,OAAO,OAAO,GACzB,EAAE,eAAe,IAAI,CACtB,CAAC,CAAC,CAAC;;AAGH,IAAa,iBAAb,cAAoC,OAAO,YAA4B,CAAC,CACvE,wBACA,EAAE,SAAS,OAAO,OAAO,GACzB,EAAE,eAAe,IAAI,CACtB,CAAC,CAAC,CAAC;AAEH,IAA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MAAM,cAAc;EACpC,OAAO;CACR,CAAC;;CAED,gBAAgB,KAAK,WAAW,gDAAgD;EAC/E,QAAQ,EAAE,aAAa,YAAY;EACnC,SAAS,OAAO,OAAO,EAAE,UAAU,OAAO,OAAO,CAAC;EAClD,OAAO,CAAC,UAAU,SAAS;CAC5B,CAAC;;CAED,gBAAgB,KAAK,UAAU,0DAA0D;EACxF,QAAQ;GAAE,aAAa;GAAa,WAAW;EAAU;EACzD,SAAS,OAAO,OAAO,EAAE,OAAO,OAAO,OAAO,CAAC;EAC/C,OAAO,CAAC,UAAU,SAAS;CAC5B,CAAC;AACF,CAAC,CACA,WAAW,UAAU,CAAC,CAAC,CAAC;;AAG1B,IAAa,eAAb,cAAkC,aAAa,KAAK,SAAS,CAAC,CAAC,IAC9D,gBAAgB,KAAK,QAAQ,gBAAgB;CAC5C,SAAS;CACT,SAAS;CACT,OAAO,CAAC,cAAc,QAAQ;AAC/B,CAAC,GACD,gBAAgB,KAAK,QAAQ,qBAAqB;CACjD,SAAS;CACT,SAAS;CACT,OAAO,CAAC,cAAc,QAAQ;AAC/B,CAAC,GACD,gBAAgB,KAAK,aAAa,0BAA0B;CAC3D,SAAS;CACT,OAAO,CAAC,cAAc,cAAc;AACrC,CAAC,GACD,gBAAgB,KAAK,UAAU,uBAAuB;CACrD,SAAS;CACT,OAAO,CAAC,cAAc,cAAc;AACrC,CAAC,CACF,CAAC,CAAC,CAAC;AAEH,IAAa,MAAb,cAAyB,QAAQ,KAAK,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC"}
package/repo.d.mts ADDED
@@ -0,0 +1,42 @@
1
+ import { Schema } from "effect";
2
+ declare namespace repo_d_exports {
3
+ export { Info, repo_d_exports as RepoSchema, Vcs };
4
+ }
5
+ export declare const Vcs: Schema.Union<readonly [Schema.Struct<{
6
+ readonly type: Schema.Literal<"git">;
7
+ readonly store: Schema.brand<Schema.String, "AbsolutePath">;
8
+ }>]>;
9
+ export type Vcs = typeof Vcs.Type;
10
+ export declare const Info: Schema.Struct<{
11
+ /**
12
+ * The root directory of the working tree that contains the input path
13
+ * (`rev-parse --show-toplevel`).
14
+ *
15
+ * For `/home/me/app/src/file.ts` in a normal clone, this is `/home/me/app`.
16
+ * For `/home/me/app-feature/src/file.ts` in a linked worktree, this is
17
+ * `/home/me/app-feature`.
18
+ */
19
+ readonly directory: Schema.brand<Schema.String, "AbsolutePath">;
20
+ /**
21
+ * This checkout's own git directory (`rev-parse --git-dir`).
22
+ *
23
+ * For a normal clone at `/home/me/app`, this is `/home/me/app/.git`. For a
24
+ * linked worktree it lives under the store, e.g.
25
+ * `/home/me/app/.git/worktrees/app-feature`. `gitDir === store` iff this is
26
+ * the main checkout.
27
+ */
28
+ readonly gitDir: Schema.brand<Schema.String, "AbsolutePath">;
29
+ /**
30
+ * The shared Git storage directory used by this repo and any linked
31
+ * worktrees (`rev-parse --git-common-dir`).
32
+ *
33
+ * For a normal clone at `/home/me/app`, this is usually `/home/me/app/.git`.
34
+ * For a linked worktree at `/home/me/app-feature` whose main checkout is
35
+ * `/home/me/app`, this is usually `/home/me/app/.git`.
36
+ */
37
+ readonly store: Schema.brand<Schema.String, "AbsolutePath">;
38
+ }>;
39
+ export type Info = typeof Info.Type;
40
+ //#endregion
41
+ export { repo_d_exports as RepoSchema };
42
+ //# sourceMappingURL=repo.d.mts.map
package/repo.mjs ADDED
@@ -0,0 +1,46 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { AbsolutePath } from "./common.mjs";
3
+ import { Schema } from "effect";
4
+ //#region src/repo.ts
5
+ var repo_exports = /* @__PURE__ */ __exportAll({
6
+ Info: () => Info,
7
+ RepoSchema: () => repo_exports,
8
+ Vcs: () => Vcs
9
+ });
10
+ const Vcs = Schema.Union([Schema.Struct({
11
+ type: Schema.Literal("git"),
12
+ store: AbsolutePath
13
+ })]);
14
+ const Info = Schema.Struct({
15
+ /**
16
+ * The root directory of the working tree that contains the input path
17
+ * (`rev-parse --show-toplevel`).
18
+ *
19
+ * For `/home/me/app/src/file.ts` in a normal clone, this is `/home/me/app`.
20
+ * For `/home/me/app-feature/src/file.ts` in a linked worktree, this is
21
+ * `/home/me/app-feature`.
22
+ */
23
+ directory: AbsolutePath,
24
+ /**
25
+ * This checkout's own git directory (`rev-parse --git-dir`).
26
+ *
27
+ * For a normal clone at `/home/me/app`, this is `/home/me/app/.git`. For a
28
+ * linked worktree it lives under the store, e.g.
29
+ * `/home/me/app/.git/worktrees/app-feature`. `gitDir === store` iff this is
30
+ * the main checkout.
31
+ */
32
+ gitDir: AbsolutePath,
33
+ /**
34
+ * The shared Git storage directory used by this repo and any linked
35
+ * worktrees (`rev-parse --git-common-dir`).
36
+ *
37
+ * For a normal clone at `/home/me/app`, this is usually `/home/me/app/.git`.
38
+ * For a linked worktree at `/home/me/app-feature` whose main checkout is
39
+ * `/home/me/app`, this is usually `/home/me/app/.git`.
40
+ */
41
+ store: AbsolutePath
42
+ });
43
+ //#endregion
44
+ export { Info, repo_exports as RepoSchema, Vcs };
45
+
46
+ //# sourceMappingURL=repo.mjs.map