one-shared 0.0.0-stage → 1.0.0

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/dist/index.js ADDED
@@ -0,0 +1,288 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let drizzle_orm = require("drizzle-orm");
3
+ let drizzle_orm_pg_core = require("drizzle-orm/pg-core");
4
+ let zod = require("zod");
5
+ let drizzle_orm_zod = require("drizzle-orm/zod");
6
+ //#region schema.ts
7
+ const statusSignalEnum = (0, drizzle_orm_pg_core.pgEnum)("status_signal", ["recovery", "failure"]);
8
+ const teamsTable = (0, drizzle_orm_pg_core.pgTable)("teams", {
9
+ id: (0, drizzle_orm_pg_core.uuid)().primaryKey().defaultRandom(),
10
+ slackTeamId: (0, drizzle_orm_pg_core.text)().notNull(),
11
+ installerId: (0, drizzle_orm_pg_core.text)().notNull(),
12
+ installerToken: (0, drizzle_orm_pg_core.text)(),
13
+ scopes: (0, drizzle_orm_pg_core.text)().array(),
14
+ teamName: (0, drizzle_orm_pg_core.text)(),
15
+ botToken: (0, drizzle_orm_pg_core.text)().notNull(),
16
+ botScopes: (0, drizzle_orm_pg_core.text)().array().notNull(),
17
+ botUserId: (0, drizzle_orm_pg_core.text)().notNull(),
18
+ botId: (0, drizzle_orm_pg_core.text)().notNull()
19
+ });
20
+ const eventsTable = (0, drizzle_orm_pg_core.pgTable)("events", {
21
+ id: (0, drizzle_orm_pg_core.uuid)().primaryKey().defaultRandom(),
22
+ channelId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => channelsTable.id),
23
+ slackAuthorId: (0, drizzle_orm_pg_core.text)().notNull(),
24
+ slackChannelId: (0, drizzle_orm_pg_core.text)().notNull(),
25
+ slackTeamId: (0, drizzle_orm_pg_core.text)().notNull(),
26
+ ts: (0, drizzle_orm_pg_core.timestamp)().notNull().defaultNow(),
27
+ textRaw: (0, drizzle_orm_pg_core.text)(),
28
+ textNorm: (0, drizzle_orm_pg_core.text)(),
29
+ payload: (0, drizzle_orm_pg_core.jsonb)("payload").$type().notNull(),
30
+ mlClassification: (0, drizzle_orm_pg_core.integer)().notNull(),
31
+ permalink: (0, drizzle_orm_pg_core.text)().notNull()
32
+ }, (t) => [
33
+ (0, drizzle_orm_pg_core.index)("events_stream_ts_idx").on(t.channelId, t.ts),
34
+ (0, drizzle_orm_pg_core.index)("events_stream_ts_event_idx").on(t.channelId, t.ts, t.id),
35
+ (0, drizzle_orm_pg_core.index)("events_stream_idx").on(t.channelId)
36
+ ]);
37
+ const channelsTable = (0, drizzle_orm_pg_core.pgTable)("channels", {
38
+ id: (0, drizzle_orm_pg_core.uuid)().primaryKey().defaultRandom(),
39
+ slackChannelId: (0, drizzle_orm_pg_core.text)().notNull(),
40
+ slackName: (0, drizzle_orm_pg_core.text)().notNull()
41
+ });
42
+ const prewatchResultsTable = (0, drizzle_orm_pg_core.pgTable)("prewatchResults", {
43
+ id: (0, drizzle_orm_pg_core.uuid)().primaryKey().defaultRandom(),
44
+ triggerEventId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => eventsTable.id),
45
+ channelId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => channelsTable.id),
46
+ suspicious: (0, drizzle_orm_pg_core.boolean)().notNull(),
47
+ reasoning: (0, drizzle_orm_pg_core.text)().notNull(),
48
+ title: (0, drizzle_orm_pg_core.text)(),
49
+ incidentId: (0, drizzle_orm_pg_core.uuid)().references(() => incidentsTable.id)
50
+ });
51
+ const prewatchPromptEventsTable = (0, drizzle_orm_pg_core.pgTable)("prewatchPromptEvents", {
52
+ id: (0, drizzle_orm_pg_core.uuid)().primaryKey().defaultRandom(),
53
+ prewatchResultId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => prewatchResultsTable.id),
54
+ eventId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => eventsTable.id)
55
+ });
56
+ const prewatchEvidenceEventsTable = (0, drizzle_orm_pg_core.pgTable)("prewatchEvidenceIds", {
57
+ id: (0, drizzle_orm_pg_core.uuid)().primaryKey().defaultRandom(),
58
+ prewatchResultId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => prewatchResultsTable.id),
59
+ eventId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => eventsTable.id)
60
+ });
61
+ const watchResultsTable = (0, drizzle_orm_pg_core.pgTable)("watchResults", {
62
+ id: (0, drizzle_orm_pg_core.uuid)().primaryKey().defaultRandom(),
63
+ incidentId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => incidentsTable.id),
64
+ triggerEventId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => eventsTable.id),
65
+ channelId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => channelsTable.id),
66
+ statusSignal: statusSignalEnum(),
67
+ important: (0, drizzle_orm_pg_core.boolean)().notNull(),
68
+ description: (0, drizzle_orm_pg_core.text)(),
69
+ summary: (0, drizzle_orm_pg_core.text)()
70
+ });
71
+ const incidentsTable = (0, drizzle_orm_pg_core.pgTable)("incidents", {
72
+ id: (0, drizzle_orm_pg_core.uuid)().primaryKey().defaultRandom(),
73
+ channelId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => channelsTable.id),
74
+ ts: (0, drizzle_orm_pg_core.timestamp)().notNull().defaultNow()
75
+ });
76
+ const incidentCommentsTable = (0, drizzle_orm_pg_core.pgTable)("incidentComments", {
77
+ id: (0, drizzle_orm_pg_core.uuid)().primaryKey().defaultRandom(),
78
+ incidentId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => incidentsTable.id),
79
+ content: (0, drizzle_orm_pg_core.varchar)({ length: 1e4 }).notNull(),
80
+ ts: (0, drizzle_orm_pg_core.timestamp)().notNull().defaultNow()
81
+ });
82
+ const incidentEventsTable = (0, drizzle_orm_pg_core.pgTable)("incidentEvents", {
83
+ id: (0, drizzle_orm_pg_core.uuid)().primaryKey().defaultRandom(),
84
+ eventId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => eventsTable.id),
85
+ incidentId: (0, drizzle_orm_pg_core.uuid)().notNull().references(() => incidentsTable.id)
86
+ });
87
+ const tables = {
88
+ teams: teamsTable,
89
+ events: eventsTable,
90
+ channels: channelsTable,
91
+ prewatchResults: prewatchResultsTable,
92
+ prewatchPromptEvents: prewatchPromptEventsTable,
93
+ prewatchEvidenceEvents: prewatchEvidenceEventsTable,
94
+ watchResults: watchResultsTable,
95
+ incidents: incidentsTable,
96
+ incidentEvents: incidentEventsTable,
97
+ incidentComments: incidentCommentsTable
98
+ };
99
+ const relations = (0, drizzle_orm.defineRelations)(tables, (props) => {
100
+ return {
101
+ incidents: {
102
+ incidentEvents: props.many.incidentEvents(),
103
+ incidentComments: props.many.incidentComments(),
104
+ channel: props.one.channels({
105
+ from: props.incidents.channelId,
106
+ to: props.channels.id,
107
+ optional: false
108
+ })
109
+ },
110
+ incidentComments: { incident: props.one.incidents({
111
+ from: props.incidentComments.incidentId,
112
+ to: props.incidents.id,
113
+ optional: false
114
+ }) },
115
+ incidentEvents: {
116
+ incident: props.one.incidents({
117
+ from: props.incidentEvents.incidentId,
118
+ to: props.incidents.id,
119
+ optional: false
120
+ }),
121
+ event: props.one.events({
122
+ from: props.incidentEvents.eventId,
123
+ to: props.events.id,
124
+ optional: false
125
+ })
126
+ },
127
+ events: {
128
+ prewatchResult: props.one.prewatchResults({
129
+ from: props.events.id,
130
+ to: props.prewatchResults.triggerEventId,
131
+ optional: true
132
+ }),
133
+ watchResult: props.one.watchResults({
134
+ from: props.events.id,
135
+ to: props.watchResults.triggerEventId,
136
+ optional: true
137
+ })
138
+ }
139
+ };
140
+ });
141
+ //#endregion
142
+ //#region types.ts
143
+ const { createSelectSchema, createInsertSchema } = (0, drizzle_orm_zod.createSchemaFactory)({ coerce: { date: true } });
144
+ const statusSignalSchema = createSelectSchema(statusSignalEnum);
145
+ const eventSchema = createSelectSchema(eventsTable);
146
+ const eventInsertSchema = createInsertSchema(eventsTable);
147
+ const channelSchema = createSelectSchema(channelsTable);
148
+ const teamSchema = createSelectSchema(teamsTable);
149
+ const teamInsertSchema = createInsertSchema(teamsTable);
150
+ const prewatchResultSchema = createSelectSchema(prewatchResultsTable);
151
+ const prewatchResultInsertSchema = createInsertSchema(prewatchResultsTable);
152
+ const prewatchPromptEventSchema = createSelectSchema(prewatchPromptEventsTable);
153
+ const prewatchPromptEventInsertSchema = createInsertSchema(prewatchPromptEventsTable);
154
+ const watchResultSchema = createSelectSchema(watchResultsTable);
155
+ const watchResultInsertSchema = createInsertSchema(watchResultsTable);
156
+ const incidentSchema = createSelectSchema(incidentsTable);
157
+ const incidentInsertSchema = createInsertSchema(incidentsTable);
158
+ const incidentCommentsSchema = createSelectSchema(incidentCommentsTable);
159
+ const incidentCommentsInsertSchema = createInsertSchema(incidentCommentsTable);
160
+ const incidentEventSchema = createSelectSchema(incidentEventsTable);
161
+ const incidentEventInsertSchema = createInsertSchema(incidentEventsTable);
162
+ const prewatchEvidenceEventSchema = createSelectSchema(prewatchEvidenceEventsTable);
163
+ const prewatchEvidenceEventInsertSchema = createInsertSchema(prewatchEvidenceEventsTable);
164
+ const relatedEventSchema = eventSchema.extend({
165
+ prewatchResult: prewatchResultSchema.nullish(),
166
+ watchResult: watchResultSchema.nullish()
167
+ });
168
+ const relatedIncidentEventSchema = incidentEventSchema.extend({ event: relatedEventSchema });
169
+ const unsuspiciousPrewatchGenerationSchema = zod.z.object({
170
+ suspicious: zod.z.literal(false),
171
+ reasoning: zod.z.string()
172
+ });
173
+ const suspiciousPrewatchGenerationSchema = zod.z.object({
174
+ suspicious: zod.z.literal(true),
175
+ reasoning: zod.z.string(),
176
+ title: zod.z.string(),
177
+ evidenceEventIds: zod.z.string().array()
178
+ });
179
+ const importantGenerationSchema = zod.z.object({
180
+ important: zod.z.literal(true),
181
+ statusSignal: statusSignalSchema,
182
+ description: zod.z.string(),
183
+ summary: zod.z.string()
184
+ }).strict();
185
+ const unimportantGenerationSchema = zod.z.object({ important: zod.z.literal(false) }).strict();
186
+ const watchGenerationSchema = zod.z.union([importantGenerationSchema, unimportantGenerationSchema]);
187
+ const prewatchGenerationSchema = zod.z.union([suspiciousPrewatchGenerationSchema, unsuspiciousPrewatchGenerationSchema]);
188
+ const emptyParamsSchema = zod.z.tuple([]).readonly();
189
+ const singleParamSchema = zod.z.tuple([zod.z.string()]).readonly();
190
+ const incidentWithChannelSchema = incidentSchema.extend({ channel: channelSchema });
191
+ const getHealthOutputSchema = zod.z.object({
192
+ startupTime: zod.z.string(),
193
+ memoryLoad: zod.z.number()
194
+ });
195
+ const getIncidentsOutputSchema = incidentWithChannelSchema.array();
196
+ const getIncidentOutputSchema = incidentSchema.extend({
197
+ incidentEvents: relatedIncidentEventSchema.array(),
198
+ channel: channelSchema
199
+ });
200
+ const postIncidentCommentInputSchema = incidentCommentsInsertSchema.pick({
201
+ incidentId: true,
202
+ content: true
203
+ });
204
+ const postIncidentCommentOutputSchema = incidentCommentsSchema;
205
+ const apiSchemas = {
206
+ getHealth: {
207
+ method: "GET",
208
+ path: "health",
209
+ output: getHealthOutputSchema
210
+ },
211
+ getIncidents: {
212
+ method: "GET",
213
+ path: "incidents",
214
+ output: getIncidentsOutputSchema
215
+ },
216
+ getIncident: {
217
+ method: "GET",
218
+ path: "incidents",
219
+ output: getIncidentOutputSchema,
220
+ params: singleParamSchema
221
+ },
222
+ postIncidentComment: {
223
+ method: "POST",
224
+ path: "incidents",
225
+ output: postIncidentCommentOutputSchema,
226
+ input: postIncidentCommentInputSchema
227
+ }
228
+ };
229
+ //#endregion
230
+ //#region client.ts
231
+ async function client(props) {
232
+ const base = "http://localhost:3000";
233
+ const procedureSchemas = apiSchemas[props.procedure];
234
+ const init = { method: procedureSchemas.method };
235
+ if ("input" in procedureSchemas) {
236
+ const parsed = procedureSchemas.input.parse(props.input);
237
+ init.body = JSON.stringify(parsed);
238
+ }
239
+ const parts = [base, procedureSchemas.path];
240
+ if ("params" in procedureSchemas) {
241
+ const encoded = procedureSchemas.params.parse(props.params).map((param) => encodeURIComponent(param));
242
+ parts.push(...encoded);
243
+ }
244
+ const url = parts.join("/");
245
+ const data = await (await fetch(url, init)).json();
246
+ return procedureSchemas.output.parse(data);
247
+ }
248
+ //#endregion
249
+ exports.apiSchemas = apiSchemas;
250
+ exports.channelSchema = channelSchema;
251
+ exports.client = client;
252
+ exports.emptyParamsSchema = emptyParamsSchema;
253
+ exports.eventInsertSchema = eventInsertSchema;
254
+ exports.eventSchema = eventSchema;
255
+ exports.getHealthOutputSchema = getHealthOutputSchema;
256
+ exports.getIncidentOutputSchema = getIncidentOutputSchema;
257
+ exports.getIncidentsOutputSchema = getIncidentsOutputSchema;
258
+ exports.importantGenerationSchema = importantGenerationSchema;
259
+ exports.incidentCommentsInsertSchema = incidentCommentsInsertSchema;
260
+ exports.incidentCommentsSchema = incidentCommentsSchema;
261
+ exports.incidentEventInsertSchema = incidentEventInsertSchema;
262
+ exports.incidentEventSchema = incidentEventSchema;
263
+ exports.incidentInsertSchema = incidentInsertSchema;
264
+ exports.incidentSchema = incidentSchema;
265
+ exports.incidentWithChannelSchema = incidentWithChannelSchema;
266
+ exports.postIncidentCommentInputSchema = postIncidentCommentInputSchema;
267
+ exports.postIncidentCommentOutputSchema = postIncidentCommentOutputSchema;
268
+ exports.prewatchEvidenceEventInsertSchema = prewatchEvidenceEventInsertSchema;
269
+ exports.prewatchEvidenceEventSchema = prewatchEvidenceEventSchema;
270
+ exports.prewatchGenerationSchema = prewatchGenerationSchema;
271
+ exports.prewatchPromptEventInsertSchema = prewatchPromptEventInsertSchema;
272
+ exports.prewatchPromptEventSchema = prewatchPromptEventSchema;
273
+ exports.prewatchResultInsertSchema = prewatchResultInsertSchema;
274
+ exports.prewatchResultSchema = prewatchResultSchema;
275
+ exports.relations = relations;
276
+ exports.singleParamSchema = singleParamSchema;
277
+ exports.statusSignalSchema = statusSignalSchema;
278
+ exports.suspiciousPrewatchGenerationSchema = suspiciousPrewatchGenerationSchema;
279
+ exports.tables = tables;
280
+ exports.teamInsertSchema = teamInsertSchema;
281
+ exports.teamSchema = teamSchema;
282
+ exports.unimportantGenerationSchema = unimportantGenerationSchema;
283
+ exports.unsuspiciousPrewatchGenerationSchema = unsuspiciousPrewatchGenerationSchema;
284
+ exports.watchGenerationSchema = watchGenerationSchema;
285
+ exports.watchResultInsertSchema = watchResultInsertSchema;
286
+ exports.watchResultSchema = watchResultSchema;
287
+
288
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["pgEnum","pgTable","uuid","text","timestamp","jsonb","integer","index","boolean","varchar","defineRelations","createSchemaFactory","z"],"sources":["../schema.ts","../types.ts","../client.ts"],"sourcesContent":["import { defineRelations, type Json } from \"drizzle-orm\";\nimport {\n pgEnum,\n pgTable,\n uuid,\n text,\n timestamp,\n jsonb,\n index,\n integer,\n boolean,\n varchar,\n} from \"drizzle-orm/pg-core\";\n\nexport const statusSignalEnum = pgEnum(\"status_signal\", [\n \"recovery\",\n \"failure\",\n]);\n\nexport const teamsTable = pgTable(\"teams\", {\n id: uuid().primaryKey().defaultRandom(),\n slackTeamId: text().notNull(),\n installerId: text().notNull(),\n installerToken: text(),\n scopes: text().array(),\n teamName: text(),\n botToken: text().notNull(),\n botScopes: text().array().notNull(),\n botUserId: text().notNull(),\n botId: text().notNull(),\n});\n\nexport const eventsTable = pgTable(\n \"events\",\n {\n id: uuid().primaryKey().defaultRandom(),\n channelId: uuid()\n .notNull()\n .references(() => channelsTable.id),\n slackAuthorId: text().notNull(),\n slackChannelId: text().notNull(),\n slackTeamId: text().notNull(),\n ts: timestamp().notNull().defaultNow(),\n textRaw: text(),\n textNorm: text(),\n payload: jsonb(\"payload\").$type<Json>().notNull(),\n mlClassification: integer().notNull(),\n permalink: text().notNull(),\n },\n (t) => [\n index(\"events_stream_ts_idx\").on(t.channelId, t.ts),\n index(\"events_stream_ts_event_idx\").on(\n t.channelId,\n t.ts,\n t.id,\n ),\n index(\"events_stream_idx\").on(t.channelId),\n ],\n);\n\nexport const channelsTable = pgTable(\"channels\", {\n id: uuid().primaryKey().defaultRandom(),\n slackChannelId: text().notNull(),\n slackName: text().notNull(),\n});\n\nexport const prewatchResultsTable = pgTable(\"prewatchResults\", {\n id: uuid().primaryKey().defaultRandom(),\n triggerEventId: uuid()\n .notNull()\n .references(() => eventsTable.id),\n channelId: uuid()\n .notNull()\n .references(() => channelsTable.id),\n suspicious: boolean().notNull(),\n reasoning: text().notNull(),\n title: text(),\n incidentId: uuid().references(() => incidentsTable.id),\n});\n\nexport const prewatchPromptEventsTable = pgTable(\"prewatchPromptEvents\", {\n id: uuid().primaryKey().defaultRandom(),\n prewatchResultId: uuid()\n .notNull()\n .references(() => prewatchResultsTable.id),\n eventId: uuid()\n .notNull()\n .references(() => eventsTable.id),\n});\n\nexport const prewatchEvidenceEventsTable = pgTable(\"prewatchEvidenceIds\", {\n id: uuid().primaryKey().defaultRandom(),\n prewatchResultId: uuid()\n .notNull()\n .references(() => prewatchResultsTable.id),\n eventId: uuid()\n .notNull()\n .references(() => eventsTable.id),\n});\n\nexport const watchResultsTable = pgTable(\"watchResults\", {\n id: uuid().primaryKey().defaultRandom(),\n incidentId: uuid()\n .notNull()\n .references(() => incidentsTable.id),\n triggerEventId: uuid()\n .notNull()\n .references(() => eventsTable.id),\n channelId: uuid()\n .notNull()\n .references(() => channelsTable.id),\n statusSignal: statusSignalEnum(),\n important: boolean().notNull(),\n description: text(),\n summary: text(),\n});\n\nexport const incidentsTable = pgTable(\"incidents\", {\n id: uuid().primaryKey().defaultRandom(),\n channelId: uuid()\n .notNull()\n .references(() => channelsTable.id),\n ts: timestamp().notNull().defaultNow(),\n});\n\nexport const incidentCommentsTable = pgTable(\"incidentComments\", {\n id: uuid().primaryKey().defaultRandom(),\n incidentId: uuid().notNull().references(() => incidentsTable.id),\n content: varchar({ length: 10000 }).notNull(),\n ts: timestamp().notNull().defaultNow()\n})\n\nexport const incidentEventsTable = pgTable(\"incidentEvents\", {\n id: uuid().primaryKey().defaultRandom(),\n eventId: uuid()\n .notNull()\n .references(() => eventsTable.id),\n incidentId: uuid()\n .notNull()\n .references(() => incidentsTable.id),\n});\n\nexport const tables = {\n teams: teamsTable,\n events: eventsTable,\n channels: channelsTable,\n prewatchResults: prewatchResultsTable,\n prewatchPromptEvents: prewatchPromptEventsTable,\n prewatchEvidenceEvents: prewatchEvidenceEventsTable,\n watchResults: watchResultsTable,\n incidents: incidentsTable,\n incidentEvents: incidentEventsTable,\n incidentComments: incidentCommentsTable\n};\n\n/*\nconst comment = db.query.incidentComments.findFirst({\n with: {\n incident: true\n }\n})\n\nconsole.log('The comment was made on this incident:', comment.incident) // GOOD\nconsole.log('The comment was made on this incident:', comment.incidents) // BAD\n*/\n\nexport const relations = defineRelations(tables, (props) => {\n return {\n incidents: {\n incidentEvents: props.many.incidentEvents(),\n incidentComments: props.many.incidentComments(),\n channel: props.one.channels({\n from: props.incidents.channelId,\n to: props.channels.id,\n optional: false,\n }),\n },\n incidentComments: {\n incident: props.one.incidents({\n from: props.incidentComments.incidentId,\n to: props.incidents.id,\n optional: false\n })\n },\n incidentEvents: {\n incident: props.one.incidents({\n from: props.incidentEvents.incidentId,\n to: props.incidents.id,\n optional: false,\n }),\n event: props.one.events({\n from: props.incidentEvents.eventId,\n to: props.events.id,\n optional: false,\n }),\n },\n events: {\n prewatchResult: props.one.prewatchResults({\n from: props.events.id,\n to: props.prewatchResults.triggerEventId,\n optional: true,\n }),\n watchResult: props.one.watchResults({\n from: props.events.id,\n to: props.watchResults.triggerEventId,\n optional: true,\n }),\n },\n };\n});\n\n","import db from \"./db\";\nimport { z } from \"zod\";\nimport {\n channelsTable,\n eventsTable,\n prewatchEvidenceEventsTable,\n prewatchPromptEventsTable,\n prewatchResultsTable,\n teamsTable,\n incidentEventsTable,\n incidentsTable,\n watchResultsTable,\n statusSignalEnum,\n incidentCommentsTable,\n} from \"./schema\";\n\nexport type Db = typeof db;\n\nimport { createSchemaFactory } from \"drizzle-orm/zod\";\n\nconst { createSelectSchema, createInsertSchema } = createSchemaFactory({\n coerce: {\n date: true,\n },\n});\n\n// Enums\nexport const statusSignalSchema = createSelectSchema(statusSignalEnum);\nexport type StatusSignal = z.infer<typeof statusSignalSchema>;\n\n// Tables\nexport const eventSchema = createSelectSchema(eventsTable);\nexport type Event = z.infer<typeof eventSchema>;\n\nexport const eventInsertSchema = createInsertSchema(eventsTable);\nexport type EventInsert = z.infer<typeof eventInsertSchema>;\n\nexport const channelSchema = createSelectSchema(channelsTable);\nexport type Channel = z.infer<typeof channelSchema>;\n\nexport const teamSchema = createSelectSchema(teamsTable);\nexport type Team = z.infer<typeof teamSchema>;\n\nexport const teamInsertSchema = createInsertSchema(teamsTable);\nexport type TeamInsert = z.infer<typeof teamInsertSchema>;\n\nexport const prewatchResultSchema = createSelectSchema(prewatchResultsTable);\nexport type PrewatchResult = z.infer<typeof prewatchResultSchema>;\nexport const prewatchResultInsertSchema =\n createInsertSchema(prewatchResultsTable);\nexport type PrewatchResultInsert = z.infer<typeof prewatchResultInsertSchema>;\n\nexport const prewatchPromptEventSchema = createSelectSchema(\n prewatchPromptEventsTable,\n);\nexport type PrewatchPromptEvent = z.infer<typeof prewatchPromptEventSchema>;\nexport const prewatchPromptEventInsertSchema = createInsertSchema(\n prewatchPromptEventsTable,\n);\nexport type PrewatchPromptEventInsert = z.infer<\n typeof prewatchPromptEventInsertSchema\n>;\n\nexport const watchResultSchema = createSelectSchema(watchResultsTable);\nexport type WatchResult = z.infer<typeof watchResultSchema>;\nexport const watchResultInsertSchema = createInsertSchema(watchResultsTable);\nexport type WatchResultInsert = z.infer<typeof watchResultInsertSchema>;\n\nexport const incidentSchema = createSelectSchema(incidentsTable);\nexport type Incident = z.infer<typeof incidentSchema>;\nexport const incidentInsertSchema = createInsertSchema(incidentsTable);\nexport type IncidentInsert = z.infer<typeof incidentInsertSchema>;\n\nexport const incidentCommentsSchema = createSelectSchema(incidentCommentsTable);\nexport type IncidentComments = z.infer<typeof incidentCommentsSchema>;\nexport const incidentCommentsInsertSchema = createInsertSchema(\n incidentCommentsTable,\n);\nexport type IncidentCommentsInsert = z.infer<\n typeof incidentCommentsInsertSchema\n>;\n\nexport const incidentEventSchema = createSelectSchema(incidentEventsTable);\nexport type IncidentEvent = z.infer<typeof incidentEventSchema>;\nexport const incidentEventInsertSchema =\n createInsertSchema(incidentEventsTable);\nexport type IncidentEventInsert = z.infer<typeof incidentEventInsertSchema>;\n\nexport const prewatchEvidenceEventSchema = createSelectSchema(\n prewatchEvidenceEventsTable,\n);\nexport type PrewatchEvidenceEvent = z.infer<typeof prewatchEvidenceEventSchema>;\nexport const prewatchEvidenceEventInsertSchema = createInsertSchema(\n prewatchEvidenceEventsTable,\n);\nexport type PrewatchEvidenceEventInsert = z.infer<\n typeof prewatchEvidenceEventInsertSchema\n>;\n\nconst relatedEventSchema = eventSchema.extend({\n prewatchResult: prewatchResultSchema.nullish(),\n watchResult: watchResultSchema.nullish(),\n});\n\nconst relatedIncidentEventSchema = incidentEventSchema.extend({\n event: relatedEventSchema,\n});\n\nexport interface PromptEvent {\n id: string;\n ts: string;\n slackAuthorId: string;\n textRaw: string | null;\n textNorm: string | null;\n}\n\nexport const unsuspiciousPrewatchGenerationSchema = z.object({\n suspicious: z.literal(false),\n reasoning: z.string(),\n});\n\nexport const suspiciousPrewatchGenerationSchema = z.object({\n suspicious: z.literal(true),\n reasoning: z.string(),\n title: z.string(),\n evidenceEventIds: z.string().array(),\n});\nexport type SuspiciousPrewatchGeneration = z.infer<\n typeof suspiciousPrewatchGenerationSchema\n>;\n\nexport const importantGenerationSchema = z\n .object({\n important: z.literal(true),\n statusSignal: statusSignalSchema,\n description: z.string(),\n summary: z.string(),\n })\n .strict();\n\nexport const unimportantGenerationSchema = z\n .object({\n important: z.literal(false),\n })\n .strict();\n\nexport const watchGenerationSchema = z.union([\n importantGenerationSchema,\n unimportantGenerationSchema,\n]);\nexport type WatchGeneration = z.infer<typeof watchGenerationSchema>;\n\nexport const prewatchGenerationSchema = z.union([\n suspiciousPrewatchGenerationSchema,\n unsuspiciousPrewatchGenerationSchema,\n]);\nexport type PrewatchGeneration = z.infer<typeof prewatchGenerationSchema>;\n\n// API\n\nexport const emptyParamsSchema = z.tuple([]).readonly();\nexport type EmptyParams = z.infer<typeof emptyParamsSchema>;\n\nexport const singleParamSchema = z.tuple([z.string()]).readonly();\nexport type SingleParam = z.infer<typeof singleParamSchema>;\n\nexport type OptionalParams<S, K extends PropertyKey> = S extends {\n [P in K]: infer T extends z.ZodType;\n}\n ? { [P in K]: z.infer<T> }\n : { [P in K]?: never };\n\nexport const incidentWithChannelSchema = incidentSchema.extend({\n channel: channelSchema,\n});\n\n// GET /health\nexport const getHealthOutputSchema = z.object({\n startupTime: z.string(),\n memoryLoad: z.number(),\n});\n\n// GET /incidents\nexport const getIncidentsOutputSchema = incidentWithChannelSchema.array();\n\n// GET /incidents/:incidentId\nexport const getIncidentOutputSchema = incidentSchema.extend({\n incidentEvents: relatedIncidentEventSchema.array(),\n channel: channelSchema,\n});\n\nexport const postIncidentCommentInputSchema = incidentCommentsInsertSchema.pick(\n {\n incidentId: true,\n content: true,\n },\n);\n\nexport const postIncidentCommentOutputSchema = incidentCommentsSchema;\n\nexport const apiSchemas = {\n getHealth: {\n method: \"GET\",\n path: \"health\",\n output: getHealthOutputSchema,\n },\n getIncidents: {\n method: \"GET\",\n path: \"incidents\",\n output: getIncidentsOutputSchema,\n },\n getIncident: {\n method: \"GET\",\n path: \"incidents\",\n output: getIncidentOutputSchema,\n params: singleParamSchema,\n },\n postIncidentComment: {\n method: \"POST\",\n path: \"incidents\",\n output: postIncidentCommentOutputSchema,\n input: postIncidentCommentInputSchema,\n },\n};\n\nexport type ApiSchemas = typeof apiSchemas;\n\nexport type ProcedureName = keyof ApiSchemas;\n// 'getHealth' | 'getIncidents' | 'getIncident' ...\n","import z from \"zod\";\nimport {\n apiSchemas,\n ApiSchemas,\n ProcedureName,\n OptionalParams,\n} from \"./types\";\n\n/*\nexport const emptyParamsSchema = z.tuple([]).readonly()\n// [] GOOD\n// [string] BAD\n// [string, string] BAD\n\nexport const singleParamSchema = z.tuple([z.string()]).readonly()\n// [string] GOOD\n// [] BAD\n// [string, string] BAD\n\nexport const apiSchemas = {\n getHealth: {\n path: 'health',\n output: getHealthOutputSchema,\n params: emptyParamsSchema\n },\n getIncidents: {\n path: 'incidents',\n output: getIncidentsOutputSchema,\n params: emptyParamsSchema\n },\n getIncident: {\n path: 'incidents',\n output: getIncidentOutputSchema,\n params: singleParamSchema\n },\n}\n*/\n\nexport default async function client<P extends ProcedureName>(\n props: { procedure: P } & OptionalParams<ApiSchemas[P], \"params\"> &\n OptionalParams<ApiSchemas[P], \"input\">,\n) {\n const base = \"http://localhost:3000\";\n const procedureSchemas = apiSchemas[props.procedure];\n\n // Body\n const init: RequestInit = {\n method: procedureSchemas.method,\n };\n if (\"input\" in procedureSchemas) {\n const parsed = procedureSchemas.input.parse(props.input);\n const json = JSON.stringify(parsed);\n init.body = json;\n }\n \n // URL\n const parts = [base, procedureSchemas.path];\n if (\"params\" in procedureSchemas) {\n const parsed = procedureSchemas.params.parse(props.params);\n const encoded = parsed.map((param) => encodeURIComponent(param));\n parts.push(...encoded);\n }\n const url = parts.join(\"/\");\n\n const response = await fetch(url, init);\n const data: unknown = await response.json();\n const output = procedureSchemas.output.parse(data);\n\n return output;\n}\n"],"mappings":";;;;;;AAcA,MAAa,oBAAA,GAAmBA,oBAAAA,OAAAA,CAAO,iBAAiB,CACtD,YACA,SACF,CAAC;AAED,MAAa,cAAA,GAAaC,oBAAAA,QAAAA,CAAQ,SAAS;CACzC,KAAA,GAAIC,oBAAAA,KAAAA,CAAK,CAAC,CAAC,WAAW,CAAC,CAAC,cAAc;CACtC,cAAA,GAAaC,oBAAAA,KAAAA,CAAK,CAAC,CAAC,QAAQ;CAC5B,cAAA,GAAaA,oBAAAA,KAAAA,CAAK,CAAC,CAAC,QAAQ;CAC5B,iBAAA,GAAgBA,oBAAAA,KAAAA,CAAK;CACrB,SAAA,GAAQA,oBAAAA,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,MADL,MAAM,KAAK,IAAI,EAAA,CACD,KAAK;CAG1C,OAFe,iBAAiB,OAAO,MAAM,IAEjC;AACd"}
package/dist/index.mjs ADDED
@@ -0,0 +1,250 @@
1
+ import { defineRelations } from "drizzle-orm";
2
+ import { boolean, index, integer, jsonb, pgEnum, pgTable, text, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
3
+ import { z } from "zod";
4
+ import { createSchemaFactory } from "drizzle-orm/zod";
5
+ //#region schema.ts
6
+ const statusSignalEnum = pgEnum("status_signal", ["recovery", "failure"]);
7
+ const teamsTable = pgTable("teams", {
8
+ id: uuid().primaryKey().defaultRandom(),
9
+ slackTeamId: text().notNull(),
10
+ installerId: text().notNull(),
11
+ installerToken: text(),
12
+ scopes: text().array(),
13
+ teamName: text(),
14
+ botToken: text().notNull(),
15
+ botScopes: text().array().notNull(),
16
+ botUserId: text().notNull(),
17
+ botId: text().notNull()
18
+ });
19
+ const eventsTable = pgTable("events", {
20
+ id: uuid().primaryKey().defaultRandom(),
21
+ channelId: uuid().notNull().references(() => channelsTable.id),
22
+ slackAuthorId: text().notNull(),
23
+ slackChannelId: text().notNull(),
24
+ slackTeamId: text().notNull(),
25
+ ts: timestamp().notNull().defaultNow(),
26
+ textRaw: text(),
27
+ textNorm: text(),
28
+ payload: jsonb("payload").$type().notNull(),
29
+ mlClassification: integer().notNull(),
30
+ permalink: text().notNull()
31
+ }, (t) => [
32
+ index("events_stream_ts_idx").on(t.channelId, t.ts),
33
+ index("events_stream_ts_event_idx").on(t.channelId, t.ts, t.id),
34
+ index("events_stream_idx").on(t.channelId)
35
+ ]);
36
+ const channelsTable = pgTable("channels", {
37
+ id: uuid().primaryKey().defaultRandom(),
38
+ slackChannelId: text().notNull(),
39
+ slackName: text().notNull()
40
+ });
41
+ const prewatchResultsTable = pgTable("prewatchResults", {
42
+ id: uuid().primaryKey().defaultRandom(),
43
+ triggerEventId: uuid().notNull().references(() => eventsTable.id),
44
+ channelId: uuid().notNull().references(() => channelsTable.id),
45
+ suspicious: boolean().notNull(),
46
+ reasoning: text().notNull(),
47
+ title: text(),
48
+ incidentId: uuid().references(() => incidentsTable.id)
49
+ });
50
+ const prewatchPromptEventsTable = pgTable("prewatchPromptEvents", {
51
+ id: uuid().primaryKey().defaultRandom(),
52
+ prewatchResultId: uuid().notNull().references(() => prewatchResultsTable.id),
53
+ eventId: uuid().notNull().references(() => eventsTable.id)
54
+ });
55
+ const prewatchEvidenceEventsTable = pgTable("prewatchEvidenceIds", {
56
+ id: uuid().primaryKey().defaultRandom(),
57
+ prewatchResultId: uuid().notNull().references(() => prewatchResultsTable.id),
58
+ eventId: uuid().notNull().references(() => eventsTable.id)
59
+ });
60
+ const watchResultsTable = pgTable("watchResults", {
61
+ id: uuid().primaryKey().defaultRandom(),
62
+ incidentId: uuid().notNull().references(() => incidentsTable.id),
63
+ triggerEventId: uuid().notNull().references(() => eventsTable.id),
64
+ channelId: uuid().notNull().references(() => channelsTable.id),
65
+ statusSignal: statusSignalEnum(),
66
+ important: boolean().notNull(),
67
+ description: text(),
68
+ summary: text()
69
+ });
70
+ const incidentsTable = pgTable("incidents", {
71
+ id: uuid().primaryKey().defaultRandom(),
72
+ channelId: uuid().notNull().references(() => channelsTable.id),
73
+ ts: timestamp().notNull().defaultNow()
74
+ });
75
+ const incidentCommentsTable = pgTable("incidentComments", {
76
+ id: uuid().primaryKey().defaultRandom(),
77
+ incidentId: uuid().notNull().references(() => incidentsTable.id),
78
+ content: varchar({ length: 1e4 }).notNull(),
79
+ ts: timestamp().notNull().defaultNow()
80
+ });
81
+ const incidentEventsTable = pgTable("incidentEvents", {
82
+ id: uuid().primaryKey().defaultRandom(),
83
+ eventId: uuid().notNull().references(() => eventsTable.id),
84
+ incidentId: uuid().notNull().references(() => incidentsTable.id)
85
+ });
86
+ const tables = {
87
+ teams: teamsTable,
88
+ events: eventsTable,
89
+ channels: channelsTable,
90
+ prewatchResults: prewatchResultsTable,
91
+ prewatchPromptEvents: prewatchPromptEventsTable,
92
+ prewatchEvidenceEvents: prewatchEvidenceEventsTable,
93
+ watchResults: watchResultsTable,
94
+ incidents: incidentsTable,
95
+ incidentEvents: incidentEventsTable,
96
+ incidentComments: incidentCommentsTable
97
+ };
98
+ const relations = defineRelations(tables, (props) => {
99
+ return {
100
+ incidents: {
101
+ incidentEvents: props.many.incidentEvents(),
102
+ incidentComments: props.many.incidentComments(),
103
+ channel: props.one.channels({
104
+ from: props.incidents.channelId,
105
+ to: props.channels.id,
106
+ optional: false
107
+ })
108
+ },
109
+ incidentComments: { incident: props.one.incidents({
110
+ from: props.incidentComments.incidentId,
111
+ to: props.incidents.id,
112
+ optional: false
113
+ }) },
114
+ incidentEvents: {
115
+ incident: props.one.incidents({
116
+ from: props.incidentEvents.incidentId,
117
+ to: props.incidents.id,
118
+ optional: false
119
+ }),
120
+ event: props.one.events({
121
+ from: props.incidentEvents.eventId,
122
+ to: props.events.id,
123
+ optional: false
124
+ })
125
+ },
126
+ events: {
127
+ prewatchResult: props.one.prewatchResults({
128
+ from: props.events.id,
129
+ to: props.prewatchResults.triggerEventId,
130
+ optional: true
131
+ }),
132
+ watchResult: props.one.watchResults({
133
+ from: props.events.id,
134
+ to: props.watchResults.triggerEventId,
135
+ optional: true
136
+ })
137
+ }
138
+ };
139
+ });
140
+ //#endregion
141
+ //#region types.ts
142
+ const { createSelectSchema, createInsertSchema } = createSchemaFactory({ coerce: { date: true } });
143
+ const statusSignalSchema = createSelectSchema(statusSignalEnum);
144
+ const eventSchema = createSelectSchema(eventsTable);
145
+ const eventInsertSchema = createInsertSchema(eventsTable);
146
+ const channelSchema = createSelectSchema(channelsTable);
147
+ const teamSchema = createSelectSchema(teamsTable);
148
+ const teamInsertSchema = createInsertSchema(teamsTable);
149
+ const prewatchResultSchema = createSelectSchema(prewatchResultsTable);
150
+ const prewatchResultInsertSchema = createInsertSchema(prewatchResultsTable);
151
+ const prewatchPromptEventSchema = createSelectSchema(prewatchPromptEventsTable);
152
+ const prewatchPromptEventInsertSchema = createInsertSchema(prewatchPromptEventsTable);
153
+ const watchResultSchema = createSelectSchema(watchResultsTable);
154
+ const watchResultInsertSchema = createInsertSchema(watchResultsTable);
155
+ const incidentSchema = createSelectSchema(incidentsTable);
156
+ const incidentInsertSchema = createInsertSchema(incidentsTable);
157
+ const incidentCommentsSchema = createSelectSchema(incidentCommentsTable);
158
+ const incidentCommentsInsertSchema = createInsertSchema(incidentCommentsTable);
159
+ const incidentEventSchema = createSelectSchema(incidentEventsTable);
160
+ const incidentEventInsertSchema = createInsertSchema(incidentEventsTable);
161
+ const prewatchEvidenceEventSchema = createSelectSchema(prewatchEvidenceEventsTable);
162
+ const prewatchEvidenceEventInsertSchema = createInsertSchema(prewatchEvidenceEventsTable);
163
+ const relatedEventSchema = eventSchema.extend({
164
+ prewatchResult: prewatchResultSchema.nullish(),
165
+ watchResult: watchResultSchema.nullish()
166
+ });
167
+ const relatedIncidentEventSchema = incidentEventSchema.extend({ event: relatedEventSchema });
168
+ const unsuspiciousPrewatchGenerationSchema = z.object({
169
+ suspicious: z.literal(false),
170
+ reasoning: z.string()
171
+ });
172
+ const suspiciousPrewatchGenerationSchema = z.object({
173
+ suspicious: z.literal(true),
174
+ reasoning: z.string(),
175
+ title: z.string(),
176
+ evidenceEventIds: z.string().array()
177
+ });
178
+ const importantGenerationSchema = z.object({
179
+ important: z.literal(true),
180
+ statusSignal: statusSignalSchema,
181
+ description: z.string(),
182
+ summary: z.string()
183
+ }).strict();
184
+ const unimportantGenerationSchema = z.object({ important: z.literal(false) }).strict();
185
+ const watchGenerationSchema = z.union([importantGenerationSchema, unimportantGenerationSchema]);
186
+ const prewatchGenerationSchema = z.union([suspiciousPrewatchGenerationSchema, unsuspiciousPrewatchGenerationSchema]);
187
+ const emptyParamsSchema = z.tuple([]).readonly();
188
+ const singleParamSchema = z.tuple([z.string()]).readonly();
189
+ const incidentWithChannelSchema = incidentSchema.extend({ channel: channelSchema });
190
+ const getHealthOutputSchema = z.object({
191
+ startupTime: z.string(),
192
+ memoryLoad: z.number()
193
+ });
194
+ const getIncidentsOutputSchema = incidentWithChannelSchema.array();
195
+ const getIncidentOutputSchema = incidentSchema.extend({
196
+ incidentEvents: relatedIncidentEventSchema.array(),
197
+ channel: channelSchema
198
+ });
199
+ const postIncidentCommentInputSchema = incidentCommentsInsertSchema.pick({
200
+ incidentId: true,
201
+ content: true
202
+ });
203
+ const postIncidentCommentOutputSchema = incidentCommentsSchema;
204
+ const apiSchemas = {
205
+ getHealth: {
206
+ method: "GET",
207
+ path: "health",
208
+ output: getHealthOutputSchema
209
+ },
210
+ getIncidents: {
211
+ method: "GET",
212
+ path: "incidents",
213
+ output: getIncidentsOutputSchema
214
+ },
215
+ getIncident: {
216
+ method: "GET",
217
+ path: "incidents",
218
+ output: getIncidentOutputSchema,
219
+ params: singleParamSchema
220
+ },
221
+ postIncidentComment: {
222
+ method: "POST",
223
+ path: "incidents",
224
+ output: postIncidentCommentOutputSchema,
225
+ input: postIncidentCommentInputSchema
226
+ }
227
+ };
228
+ //#endregion
229
+ //#region client.ts
230
+ async function client(props) {
231
+ const base = "http://localhost:3000";
232
+ const procedureSchemas = apiSchemas[props.procedure];
233
+ const init = { method: procedureSchemas.method };
234
+ if ("input" in procedureSchemas) {
235
+ const parsed = procedureSchemas.input.parse(props.input);
236
+ init.body = JSON.stringify(parsed);
237
+ }
238
+ const parts = [base, procedureSchemas.path];
239
+ if ("params" in procedureSchemas) {
240
+ const encoded = procedureSchemas.params.parse(props.params).map((param) => encodeURIComponent(param));
241
+ parts.push(...encoded);
242
+ }
243
+ const url = parts.join("/");
244
+ const data = await (await fetch(url, init)).json();
245
+ return procedureSchemas.output.parse(data);
246
+ }
247
+ //#endregion
248
+ export { apiSchemas, channelSchema, client, emptyParamsSchema, eventInsertSchema, eventSchema, getHealthOutputSchema, getIncidentOutputSchema, getIncidentsOutputSchema, importantGenerationSchema, incidentCommentsInsertSchema, incidentCommentsSchema, incidentEventInsertSchema, incidentEventSchema, incidentInsertSchema, incidentSchema, incidentWithChannelSchema, postIncidentCommentInputSchema, postIncidentCommentOutputSchema, prewatchEvidenceEventInsertSchema, prewatchEvidenceEventSchema, prewatchGenerationSchema, prewatchPromptEventInsertSchema, prewatchPromptEventSchema, prewatchResultInsertSchema, prewatchResultSchema, relations, singleParamSchema, statusSignalSchema, suspiciousPrewatchGenerationSchema, tables, teamInsertSchema, teamSchema, unimportantGenerationSchema, unsuspiciousPrewatchGenerationSchema, watchGenerationSchema, watchResultInsertSchema, watchResultSchema };
249
+
250
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../schema.ts","../types.ts","../client.ts"],"sourcesContent":["import { defineRelations, type Json } from \"drizzle-orm\";\nimport {\n pgEnum,\n pgTable,\n uuid,\n text,\n timestamp,\n jsonb,\n index,\n integer,\n boolean,\n varchar,\n} from \"drizzle-orm/pg-core\";\n\nexport const statusSignalEnum = pgEnum(\"status_signal\", [\n \"recovery\",\n \"failure\",\n]);\n\nexport const teamsTable = pgTable(\"teams\", {\n id: uuid().primaryKey().defaultRandom(),\n slackTeamId: text().notNull(),\n installerId: text().notNull(),\n installerToken: text(),\n scopes: text().array(),\n teamName: text(),\n botToken: text().notNull(),\n botScopes: text().array().notNull(),\n botUserId: text().notNull(),\n botId: text().notNull(),\n});\n\nexport const eventsTable = pgTable(\n \"events\",\n {\n id: uuid().primaryKey().defaultRandom(),\n channelId: uuid()\n .notNull()\n .references(() => channelsTable.id),\n slackAuthorId: text().notNull(),\n slackChannelId: text().notNull(),\n slackTeamId: text().notNull(),\n ts: timestamp().notNull().defaultNow(),\n textRaw: text(),\n textNorm: text(),\n payload: jsonb(\"payload\").$type<Json>().notNull(),\n mlClassification: integer().notNull(),\n permalink: text().notNull(),\n },\n (t) => [\n index(\"events_stream_ts_idx\").on(t.channelId, t.ts),\n index(\"events_stream_ts_event_idx\").on(\n t.channelId,\n t.ts,\n t.id,\n ),\n index(\"events_stream_idx\").on(t.channelId),\n ],\n);\n\nexport const channelsTable = pgTable(\"channels\", {\n id: uuid().primaryKey().defaultRandom(),\n slackChannelId: text().notNull(),\n slackName: text().notNull(),\n});\n\nexport const prewatchResultsTable = pgTable(\"prewatchResults\", {\n id: uuid().primaryKey().defaultRandom(),\n triggerEventId: uuid()\n .notNull()\n .references(() => eventsTable.id),\n channelId: uuid()\n .notNull()\n .references(() => channelsTable.id),\n suspicious: boolean().notNull(),\n reasoning: text().notNull(),\n title: text(),\n incidentId: uuid().references(() => incidentsTable.id),\n});\n\nexport const prewatchPromptEventsTable = pgTable(\"prewatchPromptEvents\", {\n id: uuid().primaryKey().defaultRandom(),\n prewatchResultId: uuid()\n .notNull()\n .references(() => prewatchResultsTable.id),\n eventId: uuid()\n .notNull()\n .references(() => eventsTable.id),\n});\n\nexport const prewatchEvidenceEventsTable = pgTable(\"prewatchEvidenceIds\", {\n id: uuid().primaryKey().defaultRandom(),\n prewatchResultId: uuid()\n .notNull()\n .references(() => prewatchResultsTable.id),\n eventId: uuid()\n .notNull()\n .references(() => eventsTable.id),\n});\n\nexport const watchResultsTable = pgTable(\"watchResults\", {\n id: uuid().primaryKey().defaultRandom(),\n incidentId: uuid()\n .notNull()\n .references(() => incidentsTable.id),\n triggerEventId: uuid()\n .notNull()\n .references(() => eventsTable.id),\n channelId: uuid()\n .notNull()\n .references(() => channelsTable.id),\n statusSignal: statusSignalEnum(),\n important: boolean().notNull(),\n description: text(),\n summary: text(),\n});\n\nexport const incidentsTable = pgTable(\"incidents\", {\n id: uuid().primaryKey().defaultRandom(),\n channelId: uuid()\n .notNull()\n .references(() => channelsTable.id),\n ts: timestamp().notNull().defaultNow(),\n});\n\nexport const incidentCommentsTable = pgTable(\"incidentComments\", {\n id: uuid().primaryKey().defaultRandom(),\n incidentId: uuid().notNull().references(() => incidentsTable.id),\n content: varchar({ length: 10000 }).notNull(),\n ts: timestamp().notNull().defaultNow()\n})\n\nexport const incidentEventsTable = pgTable(\"incidentEvents\", {\n id: uuid().primaryKey().defaultRandom(),\n eventId: uuid()\n .notNull()\n .references(() => eventsTable.id),\n incidentId: uuid()\n .notNull()\n .references(() => incidentsTable.id),\n});\n\nexport const tables = {\n teams: teamsTable,\n events: eventsTable,\n channels: channelsTable,\n prewatchResults: prewatchResultsTable,\n prewatchPromptEvents: prewatchPromptEventsTable,\n prewatchEvidenceEvents: prewatchEvidenceEventsTable,\n watchResults: watchResultsTable,\n incidents: incidentsTable,\n incidentEvents: incidentEventsTable,\n incidentComments: incidentCommentsTable\n};\n\n/*\nconst comment = db.query.incidentComments.findFirst({\n with: {\n incident: true\n }\n})\n\nconsole.log('The comment was made on this incident:', comment.incident) // GOOD\nconsole.log('The comment was made on this incident:', comment.incidents) // BAD\n*/\n\nexport const relations = defineRelations(tables, (props) => {\n return {\n incidents: {\n incidentEvents: props.many.incidentEvents(),\n incidentComments: props.many.incidentComments(),\n channel: props.one.channels({\n from: props.incidents.channelId,\n to: props.channels.id,\n optional: false,\n }),\n },\n incidentComments: {\n incident: props.one.incidents({\n from: props.incidentComments.incidentId,\n to: props.incidents.id,\n optional: false\n })\n },\n incidentEvents: {\n incident: props.one.incidents({\n from: props.incidentEvents.incidentId,\n to: props.incidents.id,\n optional: false,\n }),\n event: props.one.events({\n from: props.incidentEvents.eventId,\n to: props.events.id,\n optional: false,\n }),\n },\n events: {\n prewatchResult: props.one.prewatchResults({\n from: props.events.id,\n to: props.prewatchResults.triggerEventId,\n optional: true,\n }),\n watchResult: props.one.watchResults({\n from: props.events.id,\n to: props.watchResults.triggerEventId,\n optional: true,\n }),\n },\n };\n});\n\n","import db from \"./db\";\nimport { z } from \"zod\";\nimport {\n channelsTable,\n eventsTable,\n prewatchEvidenceEventsTable,\n prewatchPromptEventsTable,\n prewatchResultsTable,\n teamsTable,\n incidentEventsTable,\n incidentsTable,\n watchResultsTable,\n statusSignalEnum,\n incidentCommentsTable,\n} from \"./schema\";\n\nexport type Db = typeof db;\n\nimport { createSchemaFactory } from \"drizzle-orm/zod\";\n\nconst { createSelectSchema, createInsertSchema } = createSchemaFactory({\n coerce: {\n date: true,\n },\n});\n\n// Enums\nexport const statusSignalSchema = createSelectSchema(statusSignalEnum);\nexport type StatusSignal = z.infer<typeof statusSignalSchema>;\n\n// Tables\nexport const eventSchema = createSelectSchema(eventsTable);\nexport type Event = z.infer<typeof eventSchema>;\n\nexport const eventInsertSchema = createInsertSchema(eventsTable);\nexport type EventInsert = z.infer<typeof eventInsertSchema>;\n\nexport const channelSchema = createSelectSchema(channelsTable);\nexport type Channel = z.infer<typeof channelSchema>;\n\nexport const teamSchema = createSelectSchema(teamsTable);\nexport type Team = z.infer<typeof teamSchema>;\n\nexport const teamInsertSchema = createInsertSchema(teamsTable);\nexport type TeamInsert = z.infer<typeof teamInsertSchema>;\n\nexport const prewatchResultSchema = createSelectSchema(prewatchResultsTable);\nexport type PrewatchResult = z.infer<typeof prewatchResultSchema>;\nexport const prewatchResultInsertSchema =\n createInsertSchema(prewatchResultsTable);\nexport type PrewatchResultInsert = z.infer<typeof prewatchResultInsertSchema>;\n\nexport const prewatchPromptEventSchema = createSelectSchema(\n prewatchPromptEventsTable,\n);\nexport type PrewatchPromptEvent = z.infer<typeof prewatchPromptEventSchema>;\nexport const prewatchPromptEventInsertSchema = createInsertSchema(\n prewatchPromptEventsTable,\n);\nexport type PrewatchPromptEventInsert = z.infer<\n typeof prewatchPromptEventInsertSchema\n>;\n\nexport const watchResultSchema = createSelectSchema(watchResultsTable);\nexport type WatchResult = z.infer<typeof watchResultSchema>;\nexport const watchResultInsertSchema = createInsertSchema(watchResultsTable);\nexport type WatchResultInsert = z.infer<typeof watchResultInsertSchema>;\n\nexport const incidentSchema = createSelectSchema(incidentsTable);\nexport type Incident = z.infer<typeof incidentSchema>;\nexport const incidentInsertSchema = createInsertSchema(incidentsTable);\nexport type IncidentInsert = z.infer<typeof incidentInsertSchema>;\n\nexport const incidentCommentsSchema = createSelectSchema(incidentCommentsTable);\nexport type IncidentComments = z.infer<typeof incidentCommentsSchema>;\nexport const incidentCommentsInsertSchema = createInsertSchema(\n incidentCommentsTable,\n);\nexport type IncidentCommentsInsert = z.infer<\n typeof incidentCommentsInsertSchema\n>;\n\nexport const incidentEventSchema = createSelectSchema(incidentEventsTable);\nexport type IncidentEvent = z.infer<typeof incidentEventSchema>;\nexport const incidentEventInsertSchema =\n createInsertSchema(incidentEventsTable);\nexport type IncidentEventInsert = z.infer<typeof incidentEventInsertSchema>;\n\nexport const prewatchEvidenceEventSchema = createSelectSchema(\n prewatchEvidenceEventsTable,\n);\nexport type PrewatchEvidenceEvent = z.infer<typeof prewatchEvidenceEventSchema>;\nexport const prewatchEvidenceEventInsertSchema = createInsertSchema(\n prewatchEvidenceEventsTable,\n);\nexport type PrewatchEvidenceEventInsert = z.infer<\n typeof prewatchEvidenceEventInsertSchema\n>;\n\nconst relatedEventSchema = eventSchema.extend({\n prewatchResult: prewatchResultSchema.nullish(),\n watchResult: watchResultSchema.nullish(),\n});\n\nconst relatedIncidentEventSchema = incidentEventSchema.extend({\n event: relatedEventSchema,\n});\n\nexport interface PromptEvent {\n id: string;\n ts: string;\n slackAuthorId: string;\n textRaw: string | null;\n textNorm: string | null;\n}\n\nexport const unsuspiciousPrewatchGenerationSchema = z.object({\n suspicious: z.literal(false),\n reasoning: z.string(),\n});\n\nexport const suspiciousPrewatchGenerationSchema = z.object({\n suspicious: z.literal(true),\n reasoning: z.string(),\n title: z.string(),\n evidenceEventIds: z.string().array(),\n});\nexport type SuspiciousPrewatchGeneration = z.infer<\n typeof suspiciousPrewatchGenerationSchema\n>;\n\nexport const importantGenerationSchema = z\n .object({\n important: z.literal(true),\n statusSignal: statusSignalSchema,\n description: z.string(),\n summary: z.string(),\n })\n .strict();\n\nexport const unimportantGenerationSchema = z\n .object({\n important: z.literal(false),\n })\n .strict();\n\nexport const watchGenerationSchema = z.union([\n importantGenerationSchema,\n unimportantGenerationSchema,\n]);\nexport type WatchGeneration = z.infer<typeof watchGenerationSchema>;\n\nexport const prewatchGenerationSchema = z.union([\n suspiciousPrewatchGenerationSchema,\n unsuspiciousPrewatchGenerationSchema,\n]);\nexport type PrewatchGeneration = z.infer<typeof prewatchGenerationSchema>;\n\n// API\n\nexport const emptyParamsSchema = z.tuple([]).readonly();\nexport type EmptyParams = z.infer<typeof emptyParamsSchema>;\n\nexport const singleParamSchema = z.tuple([z.string()]).readonly();\nexport type SingleParam = z.infer<typeof singleParamSchema>;\n\nexport type OptionalParams<S, K extends PropertyKey> = S extends {\n [P in K]: infer T extends z.ZodType;\n}\n ? { [P in K]: z.infer<T> }\n : { [P in K]?: never };\n\nexport const incidentWithChannelSchema = incidentSchema.extend({\n channel: channelSchema,\n});\n\n// GET /health\nexport const getHealthOutputSchema = z.object({\n startupTime: z.string(),\n memoryLoad: z.number(),\n});\n\n// GET /incidents\nexport const getIncidentsOutputSchema = incidentWithChannelSchema.array();\n\n// GET /incidents/:incidentId\nexport const getIncidentOutputSchema = incidentSchema.extend({\n incidentEvents: relatedIncidentEventSchema.array(),\n channel: channelSchema,\n});\n\nexport const postIncidentCommentInputSchema = incidentCommentsInsertSchema.pick(\n {\n incidentId: true,\n content: true,\n },\n);\n\nexport const postIncidentCommentOutputSchema = incidentCommentsSchema;\n\nexport const apiSchemas = {\n getHealth: {\n method: \"GET\",\n path: \"health\",\n output: getHealthOutputSchema,\n },\n getIncidents: {\n method: \"GET\",\n path: \"incidents\",\n output: getIncidentsOutputSchema,\n },\n getIncident: {\n method: \"GET\",\n path: \"incidents\",\n output: getIncidentOutputSchema,\n params: singleParamSchema,\n },\n postIncidentComment: {\n method: \"POST\",\n path: \"incidents\",\n output: postIncidentCommentOutputSchema,\n input: postIncidentCommentInputSchema,\n },\n};\n\nexport type ApiSchemas = typeof apiSchemas;\n\nexport type ProcedureName = keyof ApiSchemas;\n// 'getHealth' | 'getIncidents' | 'getIncident' ...\n","import z from \"zod\";\nimport {\n apiSchemas,\n ApiSchemas,\n ProcedureName,\n OptionalParams,\n} from \"./types\";\n\n/*\nexport const emptyParamsSchema = z.tuple([]).readonly()\n// [] GOOD\n// [string] BAD\n// [string, string] BAD\n\nexport const singleParamSchema = z.tuple([z.string()]).readonly()\n// [string] GOOD\n// [] BAD\n// [string, string] BAD\n\nexport const apiSchemas = {\n getHealth: {\n path: 'health',\n output: getHealthOutputSchema,\n params: emptyParamsSchema\n },\n getIncidents: {\n path: 'incidents',\n output: getIncidentsOutputSchema,\n params: emptyParamsSchema\n },\n getIncident: {\n path: 'incidents',\n output: getIncidentOutputSchema,\n params: singleParamSchema\n },\n}\n*/\n\nexport default async function client<P extends ProcedureName>(\n props: { procedure: P } & OptionalParams<ApiSchemas[P], \"params\"> &\n OptionalParams<ApiSchemas[P], \"input\">,\n) {\n const base = \"http://localhost:3000\";\n const procedureSchemas = apiSchemas[props.procedure];\n\n // Body\n const init: RequestInit = {\n method: procedureSchemas.method,\n };\n if (\"input\" in procedureSchemas) {\n const parsed = procedureSchemas.input.parse(props.input);\n const json = JSON.stringify(parsed);\n init.body = json;\n }\n \n // URL\n const parts = [base, procedureSchemas.path];\n if (\"params\" in procedureSchemas) {\n const parsed = procedureSchemas.params.parse(props.params);\n const encoded = parsed.map((param) => encodeURIComponent(param));\n parts.push(...encoded);\n }\n const url = parts.join(\"/\");\n\n const response = await fetch(url, init);\n const data: unknown = await response.json();\n const output = procedureSchemas.output.parse(data);\n\n return output;\n}\n"],"mappings":";;;;;AAcA,MAAa,mBAAmB,OAAO,iBAAiB,CACtD,YACA,SACF,CAAC;AAED,MAAa,aAAa,QAAQ,SAAS;CACzC,IAAI,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC,cAAc;CACtC,aAAa,KAAK,CAAC,CAAC,QAAQ;CAC5B,aAAa,KAAK,CAAC,CAAC,QAAQ;CAC5B,gBAAgB,KAAK;CACrB,QAAQ,KAAK,CAAC,CAAC,MAAM;CACrB,UAAU,KAAK;CACf,UAAU,KAAK,CAAC,CAAC,QAAQ;CACzB,WAAW,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,Q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QAAQ;CACV;CACA,cAAc;EACZ,QAAQ;EACR,MAAM;EACN,QAAQ;CACV;CACA,aAAa;EACX,QAAQ;EACR,MAAM;EACN,QAAQ;EACR,QAAQ;CACV;CACA,qBAAqB;EACnB,QAAQ;EACR,MAAM;EACN,QAAQ;EACR,OAAO;CACT;AACF;;;ACzLA,eAA8B,OAC5B,OAEA;CACA,MAAM,OAAO;CACb,MAAM,mBAAmB,WAAW,MAAM;CAG1C,MAAM,OAAoB,EACxB,QAAQ,iBAAiB,OAC3B;CACA,IAAI,WAAW,kBAAkB;EAC/B,MAAM,SAAS,iBAAiB,MAAM,MAAM,MAAM,KAAK;EAEvD,KAAK,OADQ,KAAK,UAAU,MACb;CACjB;CAGA,MAAM,QAAQ,CAAC,MAAM,iBAAiB,IAAI;CAC1C,IAAI,YAAY,kBAAkB;EAEhC,MAAM,UADS,iBAAiB,OAAO,MAAM,MAAM,MAC9B,CAAC,CAAC,KAAK,UAAU,mBAAmB,KAAK,CAAC;EAC/D,MAAM,KAAK,GAAG,OAAO;CACvB;CACA,MAAM,MAAM,MAAM,KAAK,GAAG;CAG1B,MAAM,OAAgB,OAAM,MADL,MAAM,KAAK,IAAI,EAAA,CACD,KAAK;CAG1C,OAFe,iBAAiB,OAAO,MAAM,IAEjC;AACd"}
package/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { tables, relations} from './schema'
2
+
3
+ export { default as client } from './client'
4
+
5
+ export * from './types'