one-shared 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.ts +6 -4
- package/dist/index.d.mts +138 -201
- package/dist/index.d.ts +138 -201
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/types.ts +15 -1
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) {\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,KAA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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.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,WA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AEjC;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 } from "zod";
|
|
3
|
+
import { 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"]);
|
|
@@ -165,31 +165,31 @@ const relatedEventSchema = eventSchema.extend({
|
|
|
165
165
|
watchResult: watchResultSchema.nullish()
|
|
166
166
|
});
|
|
167
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),
|
|
168
|
+
const unsuspiciousPrewatchGenerationSchema = z$1.object({
|
|
169
|
+
suspicious: z$1.literal(false),
|
|
170
|
+
reasoning: z$1.string()
|
|
171
|
+
});
|
|
172
|
+
const suspiciousPrewatchGenerationSchema = z$1.object({
|
|
173
|
+
suspicious: z$1.literal(true),
|
|
174
|
+
reasoning: z$1.string(),
|
|
175
|
+
title: z$1.string(),
|
|
176
|
+
evidenceEventIds: z$1.string().array()
|
|
177
|
+
});
|
|
178
|
+
const importantGenerationSchema = z$1.object({
|
|
179
|
+
important: z$1.literal(true),
|
|
180
180
|
statusSignal: statusSignalSchema,
|
|
181
|
-
description: z.string(),
|
|
182
|
-
summary: z.string()
|
|
181
|
+
description: z$1.string(),
|
|
182
|
+
summary: z$1.string()
|
|
183
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();
|
|
184
|
+
const unimportantGenerationSchema = z$1.object({ important: z$1.literal(false) }).strict();
|
|
185
|
+
const watchGenerationSchema = z$1.union([importantGenerationSchema, unimportantGenerationSchema]);
|
|
186
|
+
const prewatchGenerationSchema = z$1.union([suspiciousPrewatchGenerationSchema, unsuspiciousPrewatchGenerationSchema]);
|
|
187
|
+
const emptyParamsSchema = z$1.tuple([]).readonly();
|
|
188
|
+
const singleParamSchema = z$1.tuple([z$1.string()]).readonly();
|
|
189
189
|
const incidentWithChannelSchema = incidentSchema.extend({ channel: channelSchema });
|
|
190
|
-
const getHealthOutputSchema = z.object({
|
|
191
|
-
startupTime: z.string(),
|
|
192
|
-
memoryLoad: z.number()
|
|
190
|
+
const getHealthOutputSchema = z$1.object({
|
|
191
|
+
startupTime: z$1.string(),
|
|
192
|
+
memoryLoad: z$1.number()
|
|
193
193
|
});
|
|
194
194
|
const getIncidentsOutputSchema = incidentWithChannelSchema.array();
|
|
195
195
|
const getIncidentOutputSchema = incidentSchema.extend({
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +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,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;CAChD,kBAAkB,QAAQ,CAAC,CAAC,QAAQ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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\";\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;C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c;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,OAE2C;CAC3C,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/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import db from "./db";
|
|
2
|
-
import { z } from "zod";
|
|
2
|
+
import { output, z } from "zod";
|
|
3
3
|
import {
|
|
4
4
|
channelsTable,
|
|
5
5
|
eventsTable,
|
|
@@ -170,6 +170,18 @@ 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
|
+
[Name in ProcedureName]: z.infer<ApiSchemas[Name]['output']>
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export type ParsersByProcedure = {
|
|
178
|
+
[Name in ProcedureName]: {
|
|
179
|
+
output: {
|
|
180
|
+
parse(data: unknown): OutputByProcedure[Name]
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
173
185
|
export const incidentWithChannelSchema = incidentSchema.extend({
|
|
174
186
|
channel: channelSchema,
|
|
175
187
|
});
|
|
@@ -227,3 +239,5 @@ export type ApiSchemas = typeof apiSchemas;
|
|
|
227
239
|
|
|
228
240
|
export type ProcedureName = keyof ApiSchemas;
|
|
229
241
|
// 'getHealth' | 'getIncidents' | 'getIncident' ...
|
|
242
|
+
|
|
243
|
+
const a = await Promise<z.infer<ApiSchemas['getHealth']["output"]>>
|