diff --git a/packages/core/src/account.ts b/packages/core/src/account.ts deleted file mode 100644 index d9d29d742d..0000000000 --- a/packages/core/src/account.ts +++ /dev/null @@ -1,101 +0,0 @@ -export * as Account from "./account" - -import { Schema } from "effect" -import type { HttpClientError } from "effect/unstable/http" - -export const ID = Schema.String.pipe(Schema.brand("AccountID")) -export type ID = Schema.Schema.Type - -export const OrgID = Schema.String.pipe(Schema.brand("OrgID")) -export type OrgID = Schema.Schema.Type - -export const AccessToken = Schema.String.pipe(Schema.brand("AccessToken")) -export type AccessToken = Schema.Schema.Type - -export const RefreshToken = Schema.String.pipe(Schema.brand("RefreshToken")) -export type RefreshToken = Schema.Schema.Type - -export const DeviceCode = Schema.String.pipe(Schema.brand("DeviceCode")) -export type DeviceCode = Schema.Schema.Type - -export const UserCode = Schema.String.pipe(Schema.brand("UserCode")) -export type UserCode = Schema.Schema.Type - -export class Info extends Schema.Class("Account")({ - id: ID, - email: Schema.String, - url: Schema.String, - active_org_id: Schema.NullOr(OrgID), -}) {} - -export class Org extends Schema.Class("Org")({ - id: OrgID, - name: Schema.String, -}) {} - -export class AccountRepoError extends Schema.TaggedErrorClass()("AccountRepoError", { - message: Schema.String, - cause: Schema.optional(Schema.Defect()), -}) {} - -export class AccountServiceError extends Schema.TaggedErrorClass()("AccountServiceError", { - message: Schema.String, - cause: Schema.optional(Schema.Defect()), -}) {} - -export class AccountTransportError extends Schema.TaggedErrorClass()("AccountTransportError", { - method: Schema.String, - url: Schema.String, - description: Schema.optional(Schema.String), - cause: Schema.optional(Schema.Defect()), -}) { - static fromHttpClientError(error: HttpClientError.TransportError): AccountTransportError { - return new AccountTransportError({ - method: error.request.method, - url: error.request.url, - description: error.description, - cause: error.cause, - }) - } - - override get message(): string { - return [ - `Could not reach ${this.method} ${this.url}.`, - `This failed before the server returned an HTTP response.`, - this.description, - `Check your network, proxy, or VPN configuration and try again.`, - ] - .filter(Boolean) - .join("\n") - } -} - -export type AccountError = AccountRepoError | AccountServiceError | AccountTransportError - -export class Login extends Schema.Class("Login")({ - code: DeviceCode, - user: UserCode, - url: Schema.String, - server: Schema.String, - expiry: Schema.Duration, - interval: Schema.Duration, -}) {} - -export class PollSuccess extends Schema.TaggedClass()("PollSuccess", { - email: Schema.String, -}) {} - -export class PollPending extends Schema.TaggedClass()("PollPending", {}) {} - -export class PollSlow extends Schema.TaggedClass()("PollSlow", {}) {} - -export class PollExpired extends Schema.TaggedClass()("PollExpired", {}) {} - -export class PollDenied extends Schema.TaggedClass()("PollDenied", {}) {} - -export class PollError extends Schema.TaggedClass()("PollError", { - cause: Schema.Defect(), -}) {} - -export const PollResult = Schema.Union([PollSuccess, PollPending, PollSlow, PollExpired, PollDenied, PollError]) -export type PollResult = Schema.Schema.Type diff --git a/packages/core/src/account/sql.ts b/packages/core/src/account/sql.ts index 706ddd34a5..8783af3118 100644 --- a/packages/core/src/account/sql.ts +++ b/packages/core/src/account/sql.ts @@ -1,24 +1,21 @@ import { sqliteTable, text, integer, primaryKey } from "drizzle-orm/sqlite-core" -import { Account } from "../account" import { Timestamps } from "../database/schema.sql" export const AccountTable = sqliteTable("account", { - id: text().$type().primaryKey(), + id: text().primaryKey(), email: text().notNull(), url: text().notNull(), - access_token: text().$type().notNull(), - refresh_token: text().$type().notNull(), + access_token: text().notNull(), + refresh_token: text().notNull(), token_expiry: integer(), ...Timestamps, }) export const AccountStateTable = sqliteTable("account_state", { id: integer().primaryKey(), - active_account_id: text() - .$type() - .references(() => AccountTable.id, { onDelete: "set null" }), - active_org_id: text().$type(), + active_account_id: text().references(() => AccountTable.id, { onDelete: "set null" }), + active_org_id: text(), }) // LEGACY @@ -27,8 +24,8 @@ export const ControlAccountTable = sqliteTable( { email: text().notNull(), url: text().notNull(), - access_token: text().$type().notNull(), - refresh_token: text().$type().notNull(), + access_token: text().notNull(), + refresh_token: text().notNull(), token_expiry: integer(), active: integer({ mode: "boolean" }) .notNull()