one-shared 1.1.1 → 1.1.3
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/client.ts +11 -6
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -3
- package/dist/index.mjs.map +1 -1
- package/index.ts +1 -1
- package/package.json +1 -1
- package/schema.ts +7 -0
- package/types.ts +11 -12
package/client.ts
CHANGED
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
ApiSchemas,
|
|
5
5
|
ProcedureName,
|
|
6
6
|
OptionalParams,
|
|
7
|
-
|
|
7
|
+
} from "./types";
|
|
8
|
+
import { parseOutput } from "./schema";
|
|
8
9
|
|
|
9
10
|
/*
|
|
10
11
|
export const emptyParamsSchema = z.tuple([]).readonly()
|
|
@@ -39,7 +40,7 @@ export const apiSchemas = {
|
|
|
39
40
|
export default async function client<P extends ProcedureName>(
|
|
40
41
|
props: { procedure: P } & OptionalParams<ApiSchemas[P], "params"> &
|
|
41
42
|
OptionalParams<ApiSchemas[P], "input">,
|
|
42
|
-
): Promise<z.infer<ApiSchemas[P][
|
|
43
|
+
): Promise<z.infer<ApiSchemas[P]["output"]>> {
|
|
43
44
|
const base = "http://localhost:3000";
|
|
44
45
|
const procedureSchemas = apiSchemas[props.procedure];
|
|
45
46
|
|
|
@@ -52,7 +53,7 @@ export default async function client<P extends ProcedureName>(
|
|
|
52
53
|
const json = JSON.stringify(parsed);
|
|
53
54
|
init.body = json;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
|
|
56
57
|
// URL
|
|
57
58
|
const parts = [base, procedureSchemas.path];
|
|
58
59
|
if ("params" in procedureSchemas) {
|
|
@@ -65,8 +66,12 @@ export default async function client<P extends ProcedureName>(
|
|
|
65
66
|
const response = await fetch(url, init);
|
|
66
67
|
const data: unknown = await response.json();
|
|
67
68
|
|
|
68
|
-
const
|
|
69
|
-
const output =
|
|
69
|
+
// const parser: ParsersByProcedure[P] = apiSchemas[props.procedure];
|
|
70
|
+
// const output = parser.output.parse(data);
|
|
71
|
+
|
|
72
|
+
const output = parseOutput(apiSchemas[props.procedure], data)
|
|
70
73
|
|
|
71
74
|
return output;
|
|
72
|
-
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Json } from "drizzle-orm";
|
|
2
2
|
import z, { z as z$1 } from "zod";
|
|
3
3
|
//#region schema.d.ts
|
|
4
|
+
export declare const statusSignalEnum: import("drizzle-orm/pg-core").PgEnum<["recovery", "failure"]>;
|
|
4
5
|
export declare const tables: {
|
|
5
6
|
teams: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
6
7
|
name: "teams";
|
|
@@ -5469,7 +5470,7 @@ export type ProcedureName = keyof ApiSchemas;
|
|
|
5469
5470
|
//#region client.d.ts
|
|
5470
5471
|
declare function client<P extends ProcedureName>(props: {
|
|
5471
5472
|
procedure: P;
|
|
5472
|
-
} & OptionalParams<ApiSchemas[P], "params"> & OptionalParams<ApiSchemas[P], "input">): Promise<z.infer<ApiSchemas[P][
|
|
5473
|
+
} & OptionalParams<ApiSchemas[P], "params"> & OptionalParams<ApiSchemas[P], "input">): Promise<z.infer<ApiSchemas[P]["output"]>>;
|
|
5473
5474
|
//#endregion
|
|
5474
5475
|
export { client };
|
|
5475
5476
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Json } from "drizzle-orm";
|
|
2
2
|
import z, { z as z$1 } from "zod";
|
|
3
3
|
//#region schema.d.ts
|
|
4
|
+
export declare const statusSignalEnum: import("drizzle-orm/pg-core").PgEnum<["recovery", "failure"]>;
|
|
4
5
|
export declare const tables: {
|
|
5
6
|
teams: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
6
7
|
name: "teams";
|
|
@@ -5469,7 +5470,7 @@ export type ProcedureName = keyof ApiSchemas;
|
|
|
5469
5470
|
//#region client.d.ts
|
|
5470
5471
|
declare function client<P extends ProcedureName>(props: {
|
|
5471
5472
|
procedure: P;
|
|
5472
|
-
} & OptionalParams<ApiSchemas[P], "params"> & OptionalParams<ApiSchemas[P], "input">): Promise<z.infer<ApiSchemas[P][
|
|
5473
|
+
} & OptionalParams<ApiSchemas[P], "params"> & OptionalParams<ApiSchemas[P], "input">): Promise<z.infer<ApiSchemas[P]["output"]>>;
|
|
5473
5474
|
//#endregion
|
|
5474
5475
|
export { client };
|
|
5475
5476
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
2
24
|
let drizzle_orm = require("drizzle-orm");
|
|
3
25
|
let drizzle_orm_pg_core = require("drizzle-orm/pg-core");
|
|
4
26
|
let zod = require("zod");
|
|
27
|
+
zod = __toESM(zod);
|
|
5
28
|
let drizzle_orm_zod = require("drizzle-orm/zod");
|
|
6
29
|
//#region schema.ts
|
|
7
30
|
const statusSignalEnum = (0, drizzle_orm_pg_core.pgEnum)("status_signal", ["recovery", "failure"]);
|
|
@@ -138,6 +161,9 @@ const relations = (0, drizzle_orm.defineRelations)(tables, (props) => {
|
|
|
138
161
|
}
|
|
139
162
|
};
|
|
140
163
|
});
|
|
164
|
+
function parseOutput(parser, data) {
|
|
165
|
+
return zod.default.parse(parser.output, data);
|
|
166
|
+
}
|
|
141
167
|
//#endregion
|
|
142
168
|
//#region types.ts
|
|
143
169
|
const { createSelectSchema, createInsertSchema } = (0, drizzle_orm_zod.createSchemaFactory)({ coerce: { date: true } });
|
|
@@ -243,7 +269,7 @@ async function client(props) {
|
|
|
243
269
|
}
|
|
244
270
|
const url = parts.join("/");
|
|
245
271
|
const data = await (await fetch(url, init)).json();
|
|
246
|
-
return
|
|
272
|
+
return parseOutput(apiSchemas[props.procedure], data);
|
|
247
273
|
}
|
|
248
274
|
//#endregion
|
|
249
275
|
exports.apiSchemas = apiSchemas;
|
|
@@ -274,6 +300,7 @@ exports.prewatchResultInsertSchema = prewatchResultInsertSchema;
|
|
|
274
300
|
exports.prewatchResultSchema = prewatchResultSchema;
|
|
275
301
|
exports.relations = relations;
|
|
276
302
|
exports.singleParamSchema = singleParamSchema;
|
|
303
|
+
exports.statusSignalEnum = statusSignalEnum;
|
|
277
304
|
exports.statusSignalSchema = statusSignalSchema;
|
|
278
305
|
exports.suspiciousPrewatchGenerationSchema = suspiciousPrewatchGenerationSchema;
|
|
279
306
|
exports.tables = tables;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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): Promise<z.infer<ApiSchemas[P]['output']>> {\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) as unknown as z.infer<ApiSchemas[P]['output']>\n\n return output;\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,KAAAA,CAAK,CAAC,CAAC,MAAM;CACrB,WAAA,GAAUA,oBAAAA,KAAAA,CAAK;CACf,WAAA,GAAUA,oBAAAA,KAAAA,CAAK,CAAC,CAAC,QAAQ;CACzB,YAAA,GAAWA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p","jsonb","integer","index","boolean","varchar","defineRelations","z","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\";\nimport z from \"zod\";\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\nexport function parseOutput<Parser extends { output: z.ZodType; }>(\n parser: Parser,\n data: unknown): z.infer<Parser[\"output\"]> {\n return z.parse<Parser[\"output\"]>(parser.output, data);\n}\n\n","import db from \"./db\";\nimport { output, 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\n// export type OutputByProcedure = {\n// [Name in ProcedureName]: z.infer<ApiSchemas[Name]['output']>\n// }\n\n// export type ParsersByProcedure = {\n// [Name in ProcedureName]: {\n// output: {\n// parse(data: unknown): z.infer<ApiSchemas[Name]['output']>\n// }\n// }\n// }\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\n","import z from \"zod\";\nimport {\n apiSchemas,\n ApiSchemas,\n ProcedureName,\n OptionalParams,\n} from \"./types\";\nimport { parseOutput } from \"./schema\";\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): Promise<z.infer<ApiSchemas[P][\"output\"]>> {\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\n // const parser: ParsersByProcedure[P] = apiSchemas[props.procedure];\n // const output = parser.output.parse(data);\n\n const output = parseOutput(apiSchemas[props.procedure], data)\n\n return output;\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,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,C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AAM,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;CAO1C,OAFe,YAAY,WAAW,MAAM,YAAY,IAE5C;AACd"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineRelations } from "drizzle-orm";
|
|
2
2
|
import { boolean, index, integer, jsonb, pgEnum, pgTable, text, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
|
3
|
-
import { z as z$1 } from "zod";
|
|
3
|
+
import z, { z as z$1 } from "zod";
|
|
4
4
|
import { createSchemaFactory } from "drizzle-orm/zod";
|
|
5
5
|
//#region schema.ts
|
|
6
6
|
const statusSignalEnum = pgEnum("status_signal", ["recovery", "failure"]);
|
|
@@ -137,6 +137,9 @@ const relations = defineRelations(tables, (props) => {
|
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
139
|
});
|
|
140
|
+
function parseOutput(parser, data) {
|
|
141
|
+
return z.parse(parser.output, data);
|
|
142
|
+
}
|
|
140
143
|
//#endregion
|
|
141
144
|
//#region types.ts
|
|
142
145
|
const { createSelectSchema, createInsertSchema } = createSchemaFactory({ coerce: { date: true } });
|
|
@@ -242,9 +245,9 @@ async function client(props) {
|
|
|
242
245
|
}
|
|
243
246
|
const url = parts.join("/");
|
|
244
247
|
const data = await (await fetch(url, init)).json();
|
|
245
|
-
return
|
|
248
|
+
return parseOutput(apiSchemas[props.procedure], data);
|
|
246
249
|
}
|
|
247
250
|
//#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 };
|
|
251
|
+
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, statusSignalEnum, statusSignalSchema, suspiciousPrewatchGenerationSchema, tables, teamInsertSchema, teamSchema, unimportantGenerationSchema, unsuspiciousPrewatchGenerationSchema, watchGenerationSchema, watchResultInsertSchema, watchResultSchema };
|
|
249
252
|
|
|
250
253
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["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): Promise<z.infer<ApiSchemas[P]['output']>> {\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) as unknown as z.infer<ApiSchemas[P]['output']>\n\n return output;\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,QAAQ;CAClC,WAAW,KAAK,CAAC,CAAC,QAAQ;CAC1B,OAAO,KAAK,CAAC,CAAC,QAAQ;AACxB,CAAC;AAED,MAAa,cAAc,QACzB,UACA;CACE,IAAI,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC,cAAc;CACtC,WAAW,KAAK,CAAC,CACd,QAAQ,CAAC,CACT,iBAAiB,cAAc,EAAE;CACpC,eAAe,KAAK,CAAC,CAAC,QAAQ;CAC9B,gBAAgB,KAAK,CAAC,CAAC,QAAQ;CAC/B,aAAa,KAAK,CAAC,CAAC,QAAQ;CAC5B,IAAI,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC,WAAW;CACrC,SAAS,KAAK;CACd,UAAU,KAAK;CACf,SAAS,MAAM,SAAS,CAAC,CAAC,MAAY,CAAC,CAAC,QAAQ;CA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AI;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"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["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\";\nimport z from \"zod\";\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\nexport function parseOutput<Parser extends { output: z.ZodType; }>(\n parser: Parser,\n data: unknown): z.infer<Parser[\"output\"]> {\n return z.parse<Parser[\"output\"]>(parser.output, data);\n}\n\n","import db from \"./db\";\nimport { output, 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\n// export type OutputByProcedure = {\n// [Name in ProcedureName]: z.infer<ApiSchemas[Name]['output']>\n// }\n\n// export type ParsersByProcedure = {\n// [Name in ProcedureName]: {\n// output: {\n// parse(data: unknown): z.infer<ApiSchemas[Name]['output']>\n// }\n// }\n// }\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\n","import z from \"zod\";\nimport {\n apiSchemas,\n ApiSchemas,\n ProcedureName,\n OptionalParams,\n} from \"./types\";\nimport { parseOutput } from \"./schema\";\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): Promise<z.infer<ApiSchemas[P][\"output\"]>> {\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\n // const parser: ParsersByProcedure[P] = apiSchemas[props.procedure];\n // const output = parser.output.parse(data);\n\n const output = parseOutput(apiSchemas[props.procedure], data)\n\n return output;\n}\n\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AK,IAAI,EAAA,CACD,KAAK;CAO1C,OAFe,YAAY,WAAW,MAAM,YAAY,IAE5C;AACd"}
|
package/index.ts
CHANGED
package/package.json
CHANGED
package/schema.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
boolean,
|
|
12
12
|
varchar,
|
|
13
13
|
} from "drizzle-orm/pg-core";
|
|
14
|
+
import z from "zod";
|
|
14
15
|
|
|
15
16
|
export const statusSignalEnum = pgEnum("status_signal", [
|
|
16
17
|
"recovery",
|
|
@@ -209,3 +210,9 @@ export const relations = defineRelations(tables, (props) => {
|
|
|
209
210
|
};
|
|
210
211
|
});
|
|
211
212
|
|
|
213
|
+
export function parseOutput<Parser extends { output: z.ZodType; }>(
|
|
214
|
+
parser: Parser,
|
|
215
|
+
data: unknown): z.infer<Parser["output"]> {
|
|
216
|
+
return z.parse<Parser["output"]>(parser.output, data);
|
|
217
|
+
}
|
|
218
|
+
|
package/types.ts
CHANGED
|
@@ -170,17 +170,17 @@ export type OptionalParams<S, K extends PropertyKey> = S extends {
|
|
|
170
170
|
? { [P in K]: z.infer<T> }
|
|
171
171
|
: { [P in K]?: never };
|
|
172
172
|
|
|
173
|
-
export type OutputByProcedure = {
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export type ParsersByProcedure = {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
173
|
+
// export type OutputByProcedure = {
|
|
174
|
+
// [Name in ProcedureName]: z.infer<ApiSchemas[Name]['output']>
|
|
175
|
+
// }
|
|
176
|
+
|
|
177
|
+
// export type ParsersByProcedure = {
|
|
178
|
+
// [Name in ProcedureName]: {
|
|
179
|
+
// output: {
|
|
180
|
+
// parse(data: unknown): z.infer<ApiSchemas[Name]['output']>
|
|
181
|
+
// }
|
|
182
|
+
// }
|
|
183
|
+
// }
|
|
184
184
|
|
|
185
185
|
export const incidentWithChannelSchema = incidentSchema.extend({
|
|
186
186
|
channel: channelSchema,
|
|
@@ -240,4 +240,3 @@ export type ApiSchemas = typeof apiSchemas;
|
|
|
240
240
|
export type ProcedureName = keyof ApiSchemas;
|
|
241
241
|
// 'getHealth' | 'getIncidents' | 'getIncident' ...
|
|
242
242
|
|
|
243
|
-
const a = await Promise<z.infer<ApiSchemas['getHealth']["output"]>>
|