@sixb/server 0.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.
Files changed (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/dist/auth/access-token-boundary.d.ts +23 -0
  4. package/dist/auth/access-token-boundary.d.ts.map +1 -0
  5. package/dist/auth/application-access.d.ts +4 -0
  6. package/dist/auth/application-access.d.ts.map +1 -0
  7. package/dist/auth/browser-origin.d.ts +62 -0
  8. package/dist/auth/browser-origin.d.ts.map +1 -0
  9. package/dist/auth/csrf.d.ts +2 -0
  10. package/dist/auth/csrf.d.ts.map +1 -0
  11. package/dist/auth/guard.d.ts +35 -0
  12. package/dist/auth/guard.d.ts.map +1 -0
  13. package/dist/auth/public-routes.d.ts +8 -0
  14. package/dist/auth/public-routes.d.ts.map +1 -0
  15. package/dist/auth/responses.d.ts +11 -0
  16. package/dist/auth/responses.d.ts.map +1 -0
  17. package/dist/auth/return-to.d.ts +3 -0
  18. package/dist/auth/return-to.d.ts.map +1 -0
  19. package/dist/auth/scope.d.ts +43 -0
  20. package/dist/auth/scope.d.ts.map +1 -0
  21. package/dist/auth/session-activity.d.ts +4 -0
  22. package/dist/auth/session-activity.d.ts.map +1 -0
  23. package/dist/auth/session-cookies.d.ts +12 -0
  24. package/dist/auth/session-cookies.d.ts.map +1 -0
  25. package/dist/files/content.d.ts +141 -0
  26. package/dist/files/content.d.ts.map +1 -0
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +11522 -0
  30. package/dist/index.js.map +78 -0
  31. package/dist/openapi/security.d.ts +26 -0
  32. package/dist/openapi/security.d.ts.map +1 -0
  33. package/dist/openapi/tags.d.ts +151 -0
  34. package/dist/openapi/tags.d.ts.map +1 -0
  35. package/dist/registerRoutes.d.ts +31 -0
  36. package/dist/registerRoutes.d.ts.map +1 -0
  37. package/dist/routes/action-runs.d.ts +244 -0
  38. package/dist/routes/action-runs.d.ts.map +1 -0
  39. package/dist/routes/actions.d.ts +183 -0
  40. package/dist/routes/actions.d.ts.map +1 -0
  41. package/dist/routes/agent-api-gateway.d.ts +4 -0
  42. package/dist/routes/agent-api-gateway.d.ts.map +1 -0
  43. package/dist/routes/agents.d.ts +1061 -0
  44. package/dist/routes/agents.d.ts.map +1 -0
  45. package/dist/routes/auth.d.ts +1366 -0
  46. package/dist/routes/auth.d.ts.map +1 -0
  47. package/dist/routes/connectors.d.ts +108 -0
  48. package/dist/routes/connectors.d.ts.map +1 -0
  49. package/dist/routes/datasets.d.ts +339 -0
  50. package/dist/routes/datasets.d.ts.map +1 -0
  51. package/dist/routes/events.d.ts +116 -0
  52. package/dist/routes/events.d.ts.map +1 -0
  53. package/dist/routes/files.d.ts +340 -0
  54. package/dist/routes/files.d.ts.map +1 -0
  55. package/dist/routes/links.d.ts +175 -0
  56. package/dist/routes/links.d.ts.map +1 -0
  57. package/dist/routes/logs.d.ts +88 -0
  58. package/dist/routes/logs.d.ts.map +1 -0
  59. package/dist/routes/objects.d.ts +450 -0
  60. package/dist/routes/objects.d.ts.map +1 -0
  61. package/dist/routes/ontology.d.ts +240 -0
  62. package/dist/routes/ontology.d.ts.map +1 -0
  63. package/dist/routes/pipelines.d.ts +399 -0
  64. package/dist/routes/pipelines.d.ts.map +1 -0
  65. package/dist/routes/project.d.ts +56 -0
  66. package/dist/routes/project.d.ts.map +1 -0
  67. package/dist/routes/projections.d.ts +916 -0
  68. package/dist/routes/projections.d.ts.map +1 -0
  69. package/dist/routes/rules.d.ts +165 -0
  70. package/dist/routes/rules.d.ts.map +1 -0
  71. package/dist/routes/status.d.ts +81 -0
  72. package/dist/routes/status.d.ts.map +1 -0
  73. package/dist/routes/syncs.d.ts +294 -0
  74. package/dist/routes/syncs.d.ts.map +1 -0
  75. package/dist/routes/telemetry.d.ts +241 -0
  76. package/dist/routes/telemetry.d.ts.map +1 -0
  77. package/dist/routes/webhook-runs.d.ts +89 -0
  78. package/dist/routes/webhook-runs.d.ts.map +1 -0
  79. package/dist/routes/webhooks.d.ts +60 -0
  80. package/dist/routes/webhooks.d.ts.map +1 -0
  81. package/dist/routes/workflows.d.ts +973 -0
  82. package/dist/routes/workflows.d.ts.map +1 -0
  83. package/dist/routes/ws/agents.d.ts +99 -0
  84. package/dist/routes/ws/agents.d.ts.map +1 -0
  85. package/dist/routes/ws/events.d.ts +89 -0
  86. package/dist/routes/ws/events.d.ts.map +1 -0
  87. package/dist/routes/ws/index.d.ts +31 -0
  88. package/dist/routes/ws/index.d.ts.map +1 -0
  89. package/dist/routes/ws/log-subscription-hub.d.ts +47 -0
  90. package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -0
  91. package/dist/routes/ws/logs.d.ts +110 -0
  92. package/dist/routes/ws/logs.d.ts.map +1 -0
  93. package/dist/schemas/actions.d.ts +644 -0
  94. package/dist/schemas/actions.d.ts.map +1 -0
  95. package/dist/schemas/agents.d.ts +3157 -0
  96. package/dist/schemas/agents.d.ts.map +1 -0
  97. package/dist/schemas/auth.d.ts +2023 -0
  98. package/dist/schemas/auth.d.ts.map +1 -0
  99. package/dist/schemas/common.d.ts +30 -0
  100. package/dist/schemas/common.d.ts.map +1 -0
  101. package/dist/schemas/connectors.d.ts +82 -0
  102. package/dist/schemas/connectors.d.ts.map +1 -0
  103. package/dist/schemas/datasets.d.ts +744 -0
  104. package/dist/schemas/datasets.d.ts.map +1 -0
  105. package/dist/schemas/event-payloads.d.ts +477 -0
  106. package/dist/schemas/event-payloads.d.ts.map +1 -0
  107. package/dist/schemas/events.d.ts +665 -0
  108. package/dist/schemas/events.d.ts.map +1 -0
  109. package/dist/schemas/files.d.ts +241 -0
  110. package/dist/schemas/files.d.ts.map +1 -0
  111. package/dist/schemas/links.d.ts +90 -0
  112. package/dist/schemas/links.d.ts.map +1 -0
  113. package/dist/schemas/logs.d.ts +231 -0
  114. package/dist/schemas/logs.d.ts.map +1 -0
  115. package/dist/schemas/objects.d.ts +288 -0
  116. package/dist/schemas/objects.d.ts.map +1 -0
  117. package/dist/schemas/ontology.d.ts +778 -0
  118. package/dist/schemas/ontology.d.ts.map +1 -0
  119. package/dist/schemas/pipelines.d.ts +1373 -0
  120. package/dist/schemas/pipelines.d.ts.map +1 -0
  121. package/dist/schemas/project.d.ts +9 -0
  122. package/dist/schemas/project.d.ts.map +1 -0
  123. package/dist/schemas/projections.d.ts +6992 -0
  124. package/dist/schemas/projections.d.ts.map +1 -0
  125. package/dist/schemas/rules.d.ts +204 -0
  126. package/dist/schemas/rules.d.ts.map +1 -0
  127. package/dist/schemas/status.d.ts +189 -0
  128. package/dist/schemas/status.d.ts.map +1 -0
  129. package/dist/schemas/syncs.d.ts +538 -0
  130. package/dist/schemas/syncs.d.ts.map +1 -0
  131. package/dist/schemas/telemetry.d.ts +265 -0
  132. package/dist/schemas/telemetry.d.ts.map +1 -0
  133. package/dist/schemas/webhook-runs.d.ts +169 -0
  134. package/dist/schemas/webhook-runs.d.ts.map +1 -0
  135. package/dist/schemas/workflows.d.ts +1720 -0
  136. package/dist/schemas/workflows.d.ts.map +1 -0
  137. package/dist/server.d.ts +64 -0
  138. package/dist/server.d.ts.map +1 -0
  139. package/dist/tsconfig.json +5 -0
  140. package/dist/utils/http.d.ts +23 -0
  141. package/dist/utils/http.d.ts.map +1 -0
  142. package/dist/utils/request-body.d.ts +15 -0
  143. package/dist/utils/request-body.d.ts.map +1 -0
  144. package/dist/utils/ws.d.ts +10 -0
  145. package/dist/utils/ws.d.ts.map +1 -0
  146. package/package.json +68 -0
  147. package/src/auth/access-token-boundary.ts +68 -0
  148. package/src/auth/application-access.ts +16 -0
  149. package/src/auth/browser-origin.ts +367 -0
  150. package/src/auth/csrf.ts +1 -0
  151. package/src/auth/guard.ts +169 -0
  152. package/src/auth/public-routes.ts +87 -0
  153. package/src/auth/responses.ts +54 -0
  154. package/src/auth/return-to.ts +21 -0
  155. package/src/auth/scope.ts +64 -0
  156. package/src/auth/session-activity.ts +19 -0
  157. package/src/auth/session-cookies.ts +43 -0
  158. package/src/files/content.ts +419 -0
  159. package/src/index.ts +2 -0
  160. package/src/openapi/security.ts +37 -0
  161. package/src/openapi/tags.ts +151 -0
  162. package/src/registerRoutes.ts +49 -0
  163. package/src/routes/action-runs.ts +238 -0
  164. package/src/routes/actions.ts +126 -0
  165. package/src/routes/agent-api-gateway.ts +260 -0
  166. package/src/routes/agents.ts +943 -0
  167. package/src/routes/auth.ts +2233 -0
  168. package/src/routes/connectors.ts +69 -0
  169. package/src/routes/datasets.ts +402 -0
  170. package/src/routes/events.ts +55 -0
  171. package/src/routes/files.ts +675 -0
  172. package/src/routes/links.ts +143 -0
  173. package/src/routes/logs.ts +65 -0
  174. package/src/routes/objects.ts +838 -0
  175. package/src/routes/ontology.ts +138 -0
  176. package/src/routes/pipelines.ts +332 -0
  177. package/src/routes/project.ts +16 -0
  178. package/src/routes/projections.ts +251 -0
  179. package/src/routes/rules.ts +124 -0
  180. package/src/routes/status.ts +53 -0
  181. package/src/routes/syncs.ts +243 -0
  182. package/src/routes/telemetry.ts +207 -0
  183. package/src/routes/webhook-runs.ts +81 -0
  184. package/src/routes/webhooks.ts +508 -0
  185. package/src/routes/workflows.ts +1333 -0
  186. package/src/routes/ws/agents.ts +301 -0
  187. package/src/routes/ws/events.ts +278 -0
  188. package/src/routes/ws/index.ts +12 -0
  189. package/src/routes/ws/log-subscription-hub.ts +375 -0
  190. package/src/routes/ws/logs.ts +117 -0
  191. package/src/schemas/actions.ts +123 -0
  192. package/src/schemas/agents.ts +293 -0
  193. package/src/schemas/auth.ts +317 -0
  194. package/src/schemas/common.ts +60 -0
  195. package/src/schemas/connectors.ts +21 -0
  196. package/src/schemas/datasets.ts +107 -0
  197. package/src/schemas/event-payloads.ts +79 -0
  198. package/src/schemas/events.ts +117 -0
  199. package/src/schemas/files.ts +82 -0
  200. package/src/schemas/links.ts +38 -0
  201. package/src/schemas/logs.ts +76 -0
  202. package/src/schemas/objects.ts +759 -0
  203. package/src/schemas/ontology.ts +77 -0
  204. package/src/schemas/pipelines.ts +150 -0
  205. package/src/schemas/project.ts +5 -0
  206. package/src/schemas/projections.ts +144 -0
  207. package/src/schemas/rules.ts +98 -0
  208. package/src/schemas/status.ts +51 -0
  209. package/src/schemas/syncs.ts +83 -0
  210. package/src/schemas/telemetry.ts +59 -0
  211. package/src/schemas/webhook-runs.ts +40 -0
  212. package/src/schemas/workflows.ts +229 -0
  213. package/src/server.ts +383 -0
  214. package/src/utils/http.ts +108 -0
  215. package/src/utils/request-body.ts +62 -0
  216. package/src/utils/ws.ts +59 -0
@@ -0,0 +1,107 @@
1
+ import { z } from "zod"
2
+
3
+ export const DatasetParamsSchema = z.object({
4
+ datasetId: z.string().min(1),
5
+ })
6
+
7
+ export const DatasetVersionParamsSchema = DatasetParamsSchema.extend({
8
+ versionId: z.string().min(1),
9
+ })
10
+
11
+ export const DatasetVersionsQuerySchema = z.object({
12
+ limit: z.string().optional(),
13
+ })
14
+
15
+ export const DatasetRowsQuerySchema = z.object({
16
+ versionId: z.string().optional(),
17
+ columns: z.string().optional(),
18
+ limit: z.string().optional(),
19
+ offset: z.string().optional(),
20
+ })
21
+
22
+ export const DatasetColumnSchema = z.object({
23
+ name: z.string(),
24
+ type: z.enum([
25
+ "string",
26
+ "boolean",
27
+ "int64",
28
+ "float64",
29
+ "decimal",
30
+ "date",
31
+ "timestamp",
32
+ "json",
33
+ "fileRef",
34
+ ]),
35
+ nullable: z.boolean().optional(),
36
+ })
37
+
38
+ export const DatasetSchema = z.object({
39
+ columns: z.array(DatasetColumnSchema),
40
+ })
41
+
42
+ export const DatasetDefinitionSchema = z.object({
43
+ id: z.string(),
44
+ description: z.string().optional(),
45
+ partitionBy: z.array(z.string()).optional(),
46
+ schema: DatasetSchema,
47
+ })
48
+
49
+ export const DatasetVersionRefSchema = z.object({
50
+ datasetId: z.string(),
51
+ versionId: z.string(),
52
+ })
53
+
54
+ export const DatasetProducerSchema = z.object({
55
+ kind: z.enum(["sync", "pipeline"]),
56
+ id: z.string().optional(),
57
+ runId: z.string().optional(),
58
+ })
59
+
60
+ export const DatasetVersionSchema = z.object({
61
+ datasetId: z.string(),
62
+ versionId: z.string(),
63
+ parentVersionId: z.string().optional(),
64
+ mode: z.enum(["snapshot", "append", "schema"]),
65
+ createdAt: z.string(),
66
+ schema: DatasetSchema,
67
+ producer: DatasetProducerSchema.optional(),
68
+ inputs: z.array(DatasetVersionRefSchema).optional(),
69
+ rowCount: z.number().optional(),
70
+ sizeBytes: z.number().optional(),
71
+ })
72
+
73
+ export const DatasetLatestVersionSummarySchema = z.object({
74
+ datasetId: z.string(),
75
+ versionId: z.string(),
76
+ mode: z.enum(["snapshot", "append", "schema"]),
77
+ createdAt: z.string(),
78
+ rowCount: z.number().optional(),
79
+ })
80
+
81
+ export const DatasetCatalogItemSchema = DatasetDefinitionSchema.extend({
82
+ kind: z.literal("dataset"),
83
+ materialized: z.boolean(),
84
+ latestVersion: DatasetLatestVersionSummarySchema.nullable(),
85
+ syncIds: z.array(z.string()),
86
+ sourcePipelineIds: z.array(z.string()),
87
+ targetPipelineIds: z.array(z.string()),
88
+ projectionIds: z.array(z.string()),
89
+ })
90
+
91
+ export const DatasetVersionListResponseSchema = z.object({
92
+ versions: z.array(DatasetVersionSchema),
93
+ count: z.number(),
94
+ })
95
+
96
+ export const DatasetRowsResponseSchema = z.object({
97
+ datasetId: z.string(),
98
+ versionId: z.string(),
99
+ version: DatasetVersionSchema,
100
+ columns: z.array(z.string()),
101
+ rows: z.array(z.record(z.unknown())),
102
+ count: z.number(),
103
+ limit: z.number(),
104
+ offset: z.number(),
105
+ total: z.number().optional(),
106
+ hasMore: z.boolean(),
107
+ })
@@ -0,0 +1,79 @@
1
+ import type { DomainEvent } from "@sixb/core"
2
+ import { z } from "zod"
3
+ import { JsonNullSchema, JsonValueSchema } from "./common"
4
+
5
+ const PropertyChangeSchema = z.discriminatedUnion("operation", [
6
+ z.object({ operation: z.literal("created"), after: JsonValueSchema }),
7
+ z.object({
8
+ operation: z.literal("updated"),
9
+ before: JsonValueSchema,
10
+ after: JsonValueSchema,
11
+ }),
12
+ z.object({
13
+ operation: z.literal("cleared"),
14
+ before: JsonValueSchema,
15
+ after: JsonNullSchema,
16
+ }),
17
+ ])
18
+
19
+ const PropertyChangesSchema = z.record(PropertyChangeSchema)
20
+ const ObjectMutationPayloadSchema = z.object({
21
+ objectTypeId: z.string(),
22
+ primaryId: z.string(),
23
+ properties: z.record(JsonValueSchema),
24
+ propertyChanges: PropertyChangesSchema,
25
+ })
26
+ const ObjectDeletedPayloadSchema = z.object({
27
+ objectTypeId: z.string(),
28
+ primaryId: z.string(),
29
+ propertyChanges: PropertyChangesSchema,
30
+ })
31
+ const LinkSubjectSchema = z.object({
32
+ sourceTypeId: z.string(),
33
+ sourceId: z.string(),
34
+ linkId: z.string(),
35
+ targetTypeId: z.string(),
36
+ targetId: z.string(),
37
+ })
38
+ const LinkMutationPayloadSchema = LinkSubjectSchema.extend({
39
+ properties: z.record(JsonValueSchema).optional(),
40
+ propertyChanges: PropertyChangesSchema,
41
+ })
42
+ const LinkDeletedPayloadSchema = LinkSubjectSchema.extend({
43
+ propertyChanges: PropertyChangesSchema,
44
+ })
45
+
46
+ type OntologyEventType =
47
+ | "object.created"
48
+ | "object.updated"
49
+ | "object.deleted"
50
+ | "link.created"
51
+ | "link.updated"
52
+ | "link.deleted"
53
+ | "telemetry.appended"
54
+
55
+ type OntologyEventPayloadSchemas = {
56
+ readonly [TType in OntologyEventType]: z.ZodType<
57
+ Extract<DomainEvent, { readonly type: TType }>["payload"],
58
+ z.ZodTypeDef,
59
+ unknown
60
+ >
61
+ }
62
+
63
+ /** Exact public payload shapes for authoritative ontology facts. */
64
+ export const ONTOLOGY_EVENT_PAYLOAD_SCHEMAS = {
65
+ "object.created": ObjectMutationPayloadSchema,
66
+ "object.updated": ObjectMutationPayloadSchema,
67
+ "object.deleted": ObjectDeletedPayloadSchema,
68
+ "link.created": LinkMutationPayloadSchema,
69
+ "link.updated": LinkMutationPayloadSchema,
70
+ "link.deleted": LinkDeletedPayloadSchema,
71
+ "telemetry.appended": z.object({
72
+ objectTypeId: z.string(),
73
+ objectId: z.string(),
74
+ propertyId: z.string(),
75
+ value: JsonValueSchema,
76
+ unit: z.string().optional(),
77
+ at: z.string(),
78
+ }),
79
+ } satisfies OntologyEventPayloadSchemas
@@ -0,0 +1,117 @@
1
+ import type { DomainEvent } from "@sixb/core"
2
+ import {
3
+ EVENT_TOPICS as CORE_EVENT_TOPICS,
4
+ EVENT_TYPES as CORE_EVENT_TYPES,
5
+ EVENT_DEFINITIONS,
6
+ isOntologyFactType,
7
+ } from "@sixb/core/internal/events"
8
+ import { z } from "zod"
9
+ import { JsonValueSchema } from "./common"
10
+ import { ONTOLOGY_EVENT_PAYLOAD_SCHEMAS } from "./event-payloads"
11
+
12
+ // z.enum expects a non-empty tuple; the core registry exposes readonly arrays.
13
+ export const EVENT_TOPICS = CORE_EVENT_TOPICS as readonly [
14
+ DomainEvent["topic"],
15
+ ...DomainEvent["topic"][],
16
+ ]
17
+ export const EVENT_TYPES = CORE_EVENT_TYPES as readonly [
18
+ DomainEvent["type"],
19
+ ...DomainEvent["type"][],
20
+ ]
21
+
22
+ export const EventTopicSchema = z.enum(EVENT_TOPICS)
23
+ export const EventTypeSchema = z.enum(EVENT_TYPES)
24
+ const ProjectionEventOriginSchema = z.object({
25
+ kind: z.literal("projection"),
26
+ projectionId: z.string(),
27
+ projectionRunId: z.string(),
28
+ datasetId: z.string(),
29
+ datasetVersionId: z.string(),
30
+ })
31
+
32
+ /** Mirrors the Materializer's commit origin: which ingress produced the fact. */
33
+ export const EventOriginSchema = z.union([
34
+ z.object({
35
+ kind: z.literal("action"),
36
+ actionId: z.string(),
37
+ runId: z.string(),
38
+ }),
39
+ z.object({ kind: z.literal("runtime"), requestId: z.string() }),
40
+ ProjectionEventOriginSchema,
41
+ z.object({
42
+ kind: z.literal("telemetry"),
43
+ source: z.union([
44
+ z.object({ kind: z.literal("runtime"), requestId: z.string() }),
45
+ ProjectionEventOriginSchema.extend({ batchOrdinal: z.number() }),
46
+ ]),
47
+ }),
48
+ ])
49
+
50
+ export const EventsQuerySchema = z.object({
51
+ topic: EventTopicSchema.optional(),
52
+ type: EventTypeSchema.optional(),
53
+ afterCursor: z.string().optional(),
54
+ limit: z.string().optional(),
55
+ })
56
+
57
+ const StoredEventBaseSchema = z.object({
58
+ id: z.string(),
59
+ cursor: z.string(),
60
+ schemaVersion: z.literal(1),
61
+ projectId: z.string(),
62
+ occurredAt: z.string(),
63
+ actor: z
64
+ .object({
65
+ type: z.enum(["user", "serviceAccount", "system"]),
66
+ id: z.string(),
67
+ })
68
+ .optional(),
69
+ partitionKey: z.string(),
70
+ })
71
+
72
+ const StoredAuthorableEventBaseSchema = StoredEventBaseSchema.extend({
73
+ correlationId: z.string().optional(),
74
+ causationId: z.string().optional(),
75
+ idempotencyKey: z.string().optional(),
76
+ origin: EventOriginSchema.optional(),
77
+ metadata: z.record(JsonValueSchema).optional(),
78
+ })
79
+
80
+ const StoredOntologyEventBaseSchema = StoredEventBaseSchema.extend({
81
+ origin: EventOriginSchema,
82
+ commitId: z.string(),
83
+ commitOrdinal: z.number().int().nonnegative(),
84
+ })
85
+
86
+ const ontologyEventTypes = EVENT_TYPES.filter(isOntologyFactType)
87
+ const ontologyEventSchemas = ontologyEventTypes.map((type) =>
88
+ StoredOntologyEventBaseSchema.extend({
89
+ type: z.literal(type),
90
+ topic: z.literal(EVENT_DEFINITIONS[type].topic),
91
+ payload: ONTOLOGY_EVENT_PAYLOAD_SCHEMAS[type],
92
+ })
93
+ )
94
+ const authorableEventTypes = EVENT_TYPES.filter(
95
+ (type) => !isOntologyFactType(type)
96
+ ) as unknown as readonly [
97
+ Exclude<DomainEvent["type"], (typeof ontologyEventTypes)[number]>,
98
+ ...Exclude<DomainEvent["type"], (typeof ontologyEventTypes)[number]>[],
99
+ ]
100
+
101
+ const StoredAuthorableEventSchema = StoredAuthorableEventBaseSchema.extend({
102
+ type: z.enum(authorableEventTypes),
103
+ topic: EventTopicSchema,
104
+ payload: z.record(z.unknown()),
105
+ })
106
+
107
+ type EventSchemaOption = z.ZodDiscriminatedUnionOption<"type">
108
+ const StoredOntologyEventSchema = z.discriminatedUnion(
109
+ "type",
110
+ ontologyEventSchemas as unknown as [EventSchemaOption, EventSchemaOption, ...EventSchemaOption[]]
111
+ )
112
+ export const EventSchema = z.union([StoredOntologyEventSchema, StoredAuthorableEventSchema])
113
+
114
+ export const EventsResponseSchema = z.object({
115
+ count: z.number(),
116
+ events: z.array(EventSchema),
117
+ })
@@ -0,0 +1,82 @@
1
+ import { z } from "zod"
2
+
3
+ export const BlobDigestSchema = z.string().regex(/^sha256:[a-f0-9]{64}$/)
4
+
5
+ export const FileRefSchema = z.object({
6
+ blobId: z.string(),
7
+ digest: BlobDigestSchema,
8
+ sizeBytes: z.number().int().nonnegative(),
9
+ fileName: z.string().optional(),
10
+ mediaType: z.string().optional(),
11
+ logicalPath: z.string().optional(),
12
+ })
13
+
14
+ export const CreateFileUploadBodySchema = z.object({
15
+ fileName: z.string().optional(),
16
+ mediaType: z.string().optional(),
17
+ sizeBytes: z.number().int().nonnegative().optional(),
18
+ digest: BlobDigestSchema.optional(),
19
+ logicalPath: z.string().optional(),
20
+ })
21
+
22
+ export const FileUploadIdParamsSchema = z.object({
23
+ uploadId: z.string().min(1),
24
+ })
25
+
26
+ export const FileUploadPartParamsSchema = FileUploadIdParamsSchema.extend({
27
+ partNumber: z.string().regex(/^\d+$/),
28
+ })
29
+
30
+ export const ServerFileUploadSchema = z.object({
31
+ strategy: z.literal("server"),
32
+ uploadId: z.string(),
33
+ method: z.literal("PUT"),
34
+ url: z.string(),
35
+ expiresAt: z.string(),
36
+ })
37
+
38
+ export const DirectPutFileUploadSchema = z.object({
39
+ strategy: z.literal("direct-put"),
40
+ uploadId: z.string(),
41
+ method: z.literal("PUT"),
42
+ url: z.string(),
43
+ headers: z.record(z.string()),
44
+ expiresAt: z.string(),
45
+ })
46
+
47
+ export const MultipartFileUploadSchema = z.object({
48
+ strategy: z.literal("multipart"),
49
+ uploadId: z.string(),
50
+ partSizeBytes: z.number().int().positive(),
51
+ expiresAt: z.string(),
52
+ })
53
+
54
+ export const CreateFileUploadResponseSchema = z.discriminatedUnion("strategy", [
55
+ ServerFileUploadSchema,
56
+ DirectPutFileUploadSchema,
57
+ MultipartFileUploadSchema,
58
+ ])
59
+
60
+ export const SignedFileUploadPartSchema = z.object({
61
+ partNumber: z.number().int().positive(),
62
+ method: z.literal("PUT"),
63
+ url: z.string(),
64
+ headers: z.record(z.string()),
65
+ expiresAt: z.string(),
66
+ })
67
+
68
+ export const FileUploadPartSchema = z.object({
69
+ partNumber: z.number().int().positive(),
70
+ etag: z.string(),
71
+ })
72
+
73
+ export const CompleteFileUploadBodySchema = z.object({
74
+ sizeBytes: z.number().int().nonnegative().optional(),
75
+ digest: BlobDigestSchema.optional(),
76
+ parts: z.array(FileUploadPartSchema).optional(),
77
+ })
78
+
79
+ export const FileContentQuerySchema = z.object({
80
+ path: z.string().min(1),
81
+ disposition: z.enum(["inline", "attachment"]).optional(),
82
+ })
@@ -0,0 +1,38 @@
1
+ import { z } from "zod"
2
+
3
+ export const LinkSourceParamsSchema = z.object({
4
+ objectTypeId: z.string().min(1),
5
+ objectId: z.string().min(1),
6
+ })
7
+
8
+ export const LinkParamsSchema = LinkSourceParamsSchema.extend({
9
+ linkId: z.string().min(1),
10
+ })
11
+
12
+ export const LinkQuerySchema = z.object({
13
+ linkId: z.string().optional(),
14
+ direction: z.enum(["outgoing", "incoming", "both"]).default("outgoing"),
15
+ })
16
+
17
+ export const RemoveLinkQuerySchema = z.object({
18
+ targetTypeId: z.string().min(1),
19
+ targetId: z.string().min(1),
20
+ })
21
+
22
+ export const UpsertLinkBodySchema = z.object({
23
+ targetTypeId: z.string().min(1),
24
+ targetId: z.string().min(1),
25
+ properties: z.record(z.unknown()).optional(),
26
+ })
27
+
28
+ export const ObjectLinkSchema = z.object({
29
+ projectId: z.string(),
30
+ sourceTypeId: z.string(),
31
+ sourceId: z.string(),
32
+ linkId: z.string(),
33
+ targetTypeId: z.string(),
34
+ targetId: z.string(),
35
+ properties: z.record(z.unknown()).optional(),
36
+ createdAt: z.string(),
37
+ updatedAt: z.string(),
38
+ })
@@ -0,0 +1,76 @@
1
+ import { LOG_LEVELS, SIXB_RUN_KINDS } from "@sixb/core"
2
+ import { z } from "zod"
3
+
4
+ export { LOG_LEVELS, SIXB_RUN_KINDS }
5
+
6
+ export const SixbRunKindSchema = z.enum(SIXB_RUN_KINDS)
7
+ export const LogLevelSchema = z.enum(LOG_LEVELS)
8
+ export const LogRunIdSchema = z.string().regex(/\S/, "run id must not be blank")
9
+ export const DEFAULT_LOGS_PAGE_LIMIT = 200
10
+ export const MAX_LOGS_PAGE_LIMIT = 1_000
11
+
12
+ const LogsLimitSchema = z.coerce.number().int().positive().max(MAX_LOGS_PAGE_LIMIT)
13
+
14
+ export const LogsQuerySchema = z
15
+ .object({
16
+ kind: SixbRunKindSchema.optional(),
17
+ runId: LogRunIdSchema.optional(),
18
+ level: LogLevelSchema.optional(),
19
+ direction: z.enum(["forward", "backward"]).optional(),
20
+ afterCursor: z.string().optional(),
21
+ beforeCursor: z.string().optional(),
22
+ limit: LogsLimitSchema.optional(),
23
+ })
24
+ .superRefine((query, context) => {
25
+ if (query.runId !== undefined && query.kind === undefined) {
26
+ context.addIssue({
27
+ code: z.ZodIssueCode.custom,
28
+ path: ["runId"],
29
+ message: "kind is required when runId is provided",
30
+ })
31
+ }
32
+ if (query.afterCursor && query.beforeCursor) {
33
+ context.addIssue({
34
+ code: z.ZodIssueCode.custom,
35
+ message: "afterCursor and beforeCursor are mutually exclusive",
36
+ })
37
+ }
38
+ if (query.direction === "backward" && query.afterCursor) {
39
+ context.addIssue({
40
+ code: z.ZodIssueCode.custom,
41
+ path: ["afterCursor"],
42
+ message: "afterCursor cannot be used with backward reads",
43
+ })
44
+ }
45
+ if (query.direction !== "backward" && query.beforeCursor) {
46
+ context.addIssue({
47
+ code: z.ZodIssueCode.custom,
48
+ path: ["beforeCursor"],
49
+ message: "beforeCursor requires direction=backward",
50
+ })
51
+ }
52
+ })
53
+
54
+ export const LogLineSchema = z.object({
55
+ level: LogLevelSchema,
56
+ message: z.string(),
57
+ fields: z.record(z.unknown()).optional(),
58
+ at: z.string(),
59
+ context: z.object({
60
+ run: z.object({
61
+ kind: SixbRunKindSchema,
62
+ id: z.string(),
63
+ }),
64
+ stepId: z.string().optional(),
65
+ phase: z.string().optional(),
66
+ attempt: z.number().optional(),
67
+ }),
68
+ cursor: z.string(),
69
+ })
70
+
71
+ export const LogsResponseSchema = z.object({
72
+ count: z.number(),
73
+ lines: z.array(LogLineSchema),
74
+ cursor: z.string().optional(),
75
+ hasMore: z.boolean(),
76
+ })