Skip to content

Commit e17abf0

Browse files
Copilothotlong
andcommitted
Fix TypeScript errors and test ObjectQL adapter implementation
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 2ea215b commit e17abf0

3 files changed

Lines changed: 22 additions & 43 deletions

File tree

packages/plugins/plugin-auth/src/auth-plugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { Plugin, PluginContext, IHttpServer } from '@objectstack/core';
44
import { AuthConfig } from '@objectstack/spec/system';
55
import { AuthManager } from './auth-manager.js';
6-
import { AuthUser, AuthSession, AuthAccount, AuthVerification } from './objects/index.js';
76

87
/**
98
* Auth Plugin Options

packages/plugins/plugin-auth/src/objectql-adapter.ts

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import type { IDataEngine } from '@objectstack/core';
4-
import { createAdapter, type CleanedWhere, type JoinConfig } from 'better-auth/adapters';
4+
import type { CleanedWhere } from 'better-auth/adapters';
55

66
/**
77
* ObjectQL Adapter for better-auth
@@ -11,7 +11,7 @@ import { createAdapter, type CleanedWhere, type JoinConfig } from 'better-auth/a
1111
* third-party ORMs like drizzle-orm.
1212
*
1313
* @param dataEngine - ObjectQL data engine instance
14-
* @returns better-auth Adapter instance
14+
* @returns better-auth CustomAdapter
1515
*/
1616
export function createObjectQLAdapter(dataEngine: IDataEngine) {
1717
/**
@@ -100,58 +100,54 @@ export function createObjectQLAdapter(dataEngine: IDataEngine) {
100100
return converted;
101101
}
102102

103-
return createAdapter({
104-
id: 'objectql',
105-
106-
async create({ model, data, select }) {
103+
return {
104+
create: async <T extends Record<string, any>>({ model, data }: { model: string; data: T; select?: string[] }): Promise<T> => {
107105
const objectName = toObjectName(model);
108106
const objectData = convertDataToObjectQL(data);
109107

110108
const result = await dataEngine.insert(objectName, objectData);
111-
return convertDataFromObjectQL(result);
109+
return convertDataFromObjectQL(result) as T;
112110
},
113111

114-
async findOne({ model, where, select, join }) {
112+
findOne: async <T>({ model, where, select }: { model: string; where: CleanedWhere[]; select?: string[]; join?: any }): Promise<T | null> => {
115113
const objectName = toObjectName(model);
116114
const filter = convertWhere(where);
117115

118-
const fields = select?.map(toFieldName);
119-
120116
const result = await dataEngine.findOne(objectName, {
121117
filter,
122-
fields,
118+
select: select?.map(toFieldName),
123119
});
124120

125-
return result ? convertDataFromObjectQL(result) : null;
121+
return result ? convertDataFromObjectQL(result) as T : null;
126122
},
127123

128-
async findMany({ model, where, limit, offset, sortBy, join }) {
124+
findMany: async <T>({ model, where, limit, offset, sortBy }: { model: string; where?: CleanedWhere[]; limit: number; offset?: number; sortBy?: { field: string; direction: 'asc' | 'desc' }; join?: any }): Promise<T[]> => {
129125
const objectName = toObjectName(model);
130126
const filter = where ? convertWhere(where) : {};
131127

132-
const sort = sortBy ? {
128+
const sort = sortBy ? [{
133129
field: toFieldName(sortBy.field),
134-
direction: sortBy.direction,
135-
} : undefined;
130+
order: sortBy.direction as 'asc' | 'desc',
131+
}] : undefined;
136132

137133
const results = await dataEngine.find(objectName, {
138134
filter,
139135
limit: limit || 100,
140-
offset,
141-
sort: sort ? [sort] : undefined,
136+
skip: offset,
137+
sort,
142138
});
143139

144-
return results.map(convertDataFromObjectQL);
140+
return results.map(r => convertDataFromObjectQL(r)) as T[];
145141
},
146142

147-
async count({ model, where }) {
143+
count: async ({ model, where }: { model: string; where?: CleanedWhere[] }): Promise<number> => {
148144
const objectName = toObjectName(model);
149145
const filter = where ? convertWhere(where) : {};
150146

151147
return await dataEngine.count(objectName, { filter });
152148
},
153149

154-
async update({ model, where, update }) {
150+
update: async <T>({ model, where, update }: { model: string; where: CleanedWhere[]; update: Record<string, any> }): Promise<T | null> => {
155151
const objectName = toObjectName(model);
156152
const filter = convertWhere(where);
157153
const updateData = convertDataToObjectQL(update);
@@ -167,10 +163,10 @@ export function createObjectQLAdapter(dataEngine: IDataEngine) {
167163
id: record.id,
168164
});
169165

170-
return result ? convertDataFromObjectQL(result) : null;
166+
return result ? convertDataFromObjectQL(result) as T : null;
171167
},
172168

173-
async updateMany({ model, where, update }) {
169+
updateMany: async ({ model, where, update }: { model: string; where: CleanedWhere[]; update: Record<string, any> }): Promise<number> => {
174170
const objectName = toObjectName(model);
175171
const filter = convertWhere(where);
176172
const updateData = convertDataToObjectQL(update);
@@ -189,7 +185,7 @@ export function createObjectQLAdapter(dataEngine: IDataEngine) {
189185
return records.length;
190186
},
191187

192-
async delete({ model, where }) {
188+
delete: async ({ model, where }: { model: string; where: CleanedWhere[] }): Promise<void> => {
193189
const objectName = toObjectName(model);
194190
const filter = convertWhere(where);
195191

@@ -202,7 +198,7 @@ export function createObjectQLAdapter(dataEngine: IDataEngine) {
202198
await dataEngine.delete(objectName, { filter: { id: record.id } });
203199
},
204200

205-
async deleteMany({ model, where }) {
201+
deleteMany: async ({ model, where }: { model: string; where: CleanedWhere[] }): Promise<number> => {
206202
const objectName = toObjectName(model);
207203
const filter = convertWhere(where);
208204

@@ -216,17 +212,5 @@ export function createObjectQLAdapter(dataEngine: IDataEngine) {
216212

217213
return records.length;
218214
},
219-
}, {
220-
// Adapter configuration
221-
adapterId: 'objectql',
222-
adapterName: 'ObjectQL',
223-
supportsNumericIds: false,
224-
supportsUUIDs: true,
225-
supportsJSON: true,
226-
supportsDates: true,
227-
supportsBooleans: true,
228-
supportsArrays: false,
229-
// ObjectQL handles ID generation
230-
disableIdGeneration: false,
231-
});
215+
};
232216
}

packages/plugins/plugin-auth/src/objects/auth-account.object.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,16 @@ export const AuthAccount = ObjectSchema.create({
6969
access_token: Field.textarea({
7070
label: 'Access Token',
7171
required: false,
72-
encrypted: true, // Sensitive data should be encrypted
7372
}),
7473

7574
refresh_token: Field.textarea({
7675
label: 'Refresh Token',
7776
required: false,
78-
encrypted: true,
7977
}),
8078

8179
id_token: Field.textarea({
8280
label: 'ID Token',
8381
required: false,
84-
encrypted: true,
8582
}),
8683

8784
access_token_expires_at: Field.datetime({
@@ -102,7 +99,6 @@ export const AuthAccount = ObjectSchema.create({
10299
password: Field.text({
103100
label: 'Password Hash',
104101
required: false,
105-
encrypted: true,
106102
description: 'Hashed password for email/password provider',
107103
}),
108104
},

0 commit comments

Comments
 (0)