Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,31 @@ const auditRows = [
{ id: 2, action: 'logout' },
]

async function introspectedClient(resultData: unknown) {
const encryption = registryEnforcingFactory()
const supabase = createMockSupabase(resultData)
const es = await makeEncryptedSupabase(encryption.factory, introspector)(
supabase.client as never,
{ databaseUrl: 'postgres://x' },
)
return { es, encryption, supabase }
}

const users = encryptedTable('users', { email: types.TextSearch('email') })
const auditLog = encryptedTable('audit_log', {})

async function declaredClient(resultData: unknown) {
const encryption = registryEnforcingFactory()
const supabase = createMockSupabase(resultData)
const es = await makeEncryptedSupabase(encryption.factory, null)(
supabase.client as never,
{ schemas: { users, audit_log: auditLog } },
)
return { es, encryption, supabase }
function clientFor<C>(
connect: (factory: EncryptionFactory, client: never) => Promise<C>,
) {
return async (resultData: unknown) => {
const encryption = registryEnforcingFactory()
const supabase = createMockSupabase(resultData)
const es = await connect(encryption.factory, supabase.client as never)
return { es, encryption, supabase }
}
}

const introspectedClient = clientFor((factory, client) =>
makeEncryptedSupabase(factory, introspector)(client, {
databaseUrl: 'postgres://x',
}),
)
const declaredClient = clientFor((factory, client) =>
makeEncryptedSupabase(factory, null)(client, {
schemas: { users, audit_log: auditLog },
}),
)

describe.each([
['introspection mode', introspectedClient],
['declared mode', declaredClient],
Expand Down
11 changes: 5 additions & 6 deletions languages/typescript/packages/stack-supabase/src/column-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export class ColumnMap {
* Filters and select strings address columns by both, so recognition must
* cover both. */
readonly encryptedColumnNames: string[]
/** False for a plaintext table, which the encrypt and decrypt steps must keep
* away from the encryption client. Read from {@link tableHasEncryptedColumns},
* the same rule `create.ts` uses to choose what `Encryption` receives. */
readonly hasEncryptedColumns: boolean

/** DB column name → JS property name — the inverse of {@link propToDb}, used
* to expand `select('*')` back into property names. Null prototype: a DB
Expand Down Expand Up @@ -210,12 +214,7 @@ export class ColumnMap {
}

this.encryptedColumnNames = Object.keys(this.v3Columns)
}

/** False for a plaintext table, which the encrypt and decrypt steps must keep
* away from the encryption client (see {@link tableHasEncryptedColumns}). */
get hasEncryptedColumns(): boolean {
return this.encryptedColumnNames.length > 0
this.hasEncryptedColumns = tableHasEncryptedColumns(table)
}

/** Resolve a JS property name to its DB column name. `Object.hasOwn` guards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,8 @@ export async function decryptResults<T extends object, TData = T[]>(

// If there's an error from Supabase, pass it through
if (result.error) {
return {
data: null,
error: {
message: result.error.message,
details: result.error.details,
hint: result.error.hint,
code: result.error.code,
},
count: result.count ?? null,
status: result.status,
statusText: result.statusText,
}
const { message, details, hint, code } = result.error
return { ...respond(null), error: { message, details, hint, code } }
}

// No data to decrypt
Expand Down
Loading