surreal-better-auth 0.3.0 → 0.3.2
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/package.json +2 -1
- package/src/index.ts +0 -7
- package/src/utils.ts +20 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "surreal-better-auth",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Oskar Gmerek",
|
|
6
6
|
"url": "https://oskargmerek.com",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"main": "src/index.ts",
|
|
29
29
|
"files": [
|
|
30
30
|
"src/index.ts",
|
|
31
|
+
"src/utils.ts",
|
|
31
32
|
"README.md",
|
|
32
33
|
"LICENSE"
|
|
33
34
|
],
|
package/src/index.ts
CHANGED
|
@@ -17,7 +17,6 @@ const createTransform = (options: BetterAuthOptions) => {
|
|
|
17
17
|
return field;
|
|
18
18
|
}
|
|
19
19
|
const f = schema[model].fields[field];
|
|
20
|
-
console.log({ f })
|
|
21
20
|
return f.fieldName || field;
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -81,7 +80,6 @@ const createTransform = (options: BetterAuthOptions) => {
|
|
|
81
80
|
case "ends_with":
|
|
82
81
|
return `string::ends_with(${field},'${value}')`;
|
|
83
82
|
default:
|
|
84
|
-
console.log({ field, value, recordid: value instanceof RecordId })
|
|
85
83
|
return (field === 'id' || value instanceof RecordId) ?
|
|
86
84
|
`${field} = ${jsonify(value)}`
|
|
87
85
|
:
|
|
@@ -105,7 +103,6 @@ export const surrealAdapter = (db: Surreal) => async (options: BetterAuthOptions
|
|
|
105
103
|
create: async ({ model, data }) => {
|
|
106
104
|
const transformed = transformInput(data, model, "create");
|
|
107
105
|
const [result] = await db.create(model, transformed);
|
|
108
|
-
console.log({ model, transformed })
|
|
109
106
|
return transformOutput(result, model);
|
|
110
107
|
},
|
|
111
108
|
findOne: async ({ model, where, select = [] }) => {
|
|
@@ -113,9 +110,6 @@ export const surrealAdapter = (db: Surreal) => async (options: BetterAuthOptions
|
|
|
113
110
|
const selectClause = select.length > 0 && select.map((f) => getField(model, f)) || []
|
|
114
111
|
const query = select.length > 0 ? `SELECT ${selectClause.join(', ')} FROM ${model} WHERE ${whereClause} LIMIT 1` : `SELECT * FROM ${model} WHERE ${whereClause} LIMIT 1`;
|
|
115
112
|
const result = await db.query<[any[]]>(query)
|
|
116
|
-
console.log({ whereClause, query, result: result[0][0] })
|
|
117
|
-
const output = transformOutput(result[0][0], model, select);
|
|
118
|
-
console.log({ output });
|
|
119
113
|
return transformOutput(result[0][0], model, select);
|
|
120
114
|
},
|
|
121
115
|
findMany: async ({ model, where, sortBy, limit, offset }) => {
|
|
@@ -133,7 +127,6 @@ export const surrealAdapter = (db: Surreal) => async (options: BetterAuthOptions
|
|
|
133
127
|
if (offset !== undefined) {
|
|
134
128
|
query += ` START ${offset}`;
|
|
135
129
|
}
|
|
136
|
-
console.log({ query })
|
|
137
130
|
const [results] = await db.query<[any[]]>(query);
|
|
138
131
|
return results.map(record => transformOutput(record, model));
|
|
139
132
|
},
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FieldAttribute } from "better-auth/db";
|
|
2
|
+
|
|
3
|
+
export function withApplyDefault(
|
|
4
|
+
value: any,
|
|
5
|
+
field: FieldAttribute,
|
|
6
|
+
action: "create" | "update",
|
|
7
|
+
) {
|
|
8
|
+
if (action === "update") {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
if (value === undefined || value === null) {
|
|
12
|
+
if (field.defaultValue) {
|
|
13
|
+
if (typeof field.defaultValue === "function") {
|
|
14
|
+
return field.defaultValue();
|
|
15
|
+
}
|
|
16
|
+
return field.defaultValue;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|