@zenstackhq/better-auth 3.6.2 → 3.6.3-beta.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/dist/adapter-4J4FE5_e.d.mts +36 -0
- package/dist/adapter-Hkvk-P1x.d.cts +36 -0
- package/dist/index.cjs +2 -393
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -36
- package/dist/index.d.mts +2 -36
- package/dist/index.mjs +1 -370
- package/dist/index.mjs.map +1 -1
- package/dist/schema-generator.cjs +398 -0
- package/dist/schema-generator.cjs.map +1 -0
- package/dist/schema-generator.d.cts +10 -0
- package/dist/schema-generator.d.mts +10 -0
- package/dist/schema-generator.mjs +373 -0
- package/dist/schema-generator.mjs.map +1 -0
- package/package.json +19 -9
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
|
|
2
|
+
import { ZModelCodeGenerator, formatDocument, loadDocument } from "@zenstackhq/language";
|
|
3
|
+
import { isDataModel } from "@zenstackhq/language/ast";
|
|
4
|
+
import { hasAttribute } from "@zenstackhq/language/utils";
|
|
5
|
+
import "better-auth";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import { match } from "ts-pattern";
|
|
8
|
+
//#region src/schema-generator.ts
|
|
9
|
+
async function generateSchema(file, tables, config, options) {
|
|
10
|
+
let filePath = file;
|
|
11
|
+
if (!filePath) if (fs.existsSync("./schema.zmodel")) filePath = "./schema.zmodel";
|
|
12
|
+
else filePath = "./zenstack/schema.zmodel";
|
|
13
|
+
const schemaExists = fs.existsSync(filePath);
|
|
14
|
+
const schema = await updateSchema(filePath, tables, config, options);
|
|
15
|
+
return {
|
|
16
|
+
code: schema ?? "",
|
|
17
|
+
path: filePath,
|
|
18
|
+
overwrite: schemaExists && !!schema
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async function updateSchema(schemaPath, tables, config, options) {
|
|
22
|
+
let zmodel;
|
|
23
|
+
if (fs.existsSync(schemaPath)) {
|
|
24
|
+
const loadResult = await loadDocument(schemaPath);
|
|
25
|
+
if (!loadResult.success) throw new Error(`Failed to load existing schema at ${schemaPath}: ${loadResult.errors.join(", ")}`);
|
|
26
|
+
zmodel = loadResult.model;
|
|
27
|
+
} else zmodel = initializeZmodel(config);
|
|
28
|
+
const toManyRelations = /* @__PURE__ */ new Map();
|
|
29
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
30
|
+
const fields = tables[tableName]?.fields;
|
|
31
|
+
for (const field in fields) {
|
|
32
|
+
const attr = fields[field];
|
|
33
|
+
if (attr.references) {
|
|
34
|
+
const referencedOriginalModel = attr.references.model;
|
|
35
|
+
const referencedModelNameCap = upperCaseFirst(tables[referencedOriginalModel]?.modelName || referencedOriginalModel);
|
|
36
|
+
if (!toManyRelations.has(referencedModelNameCap)) toManyRelations.set(referencedModelNameCap, /* @__PURE__ */ new Set());
|
|
37
|
+
const currentModelNameCap = upperCaseFirst(table.modelName ?? tableName);
|
|
38
|
+
toManyRelations.get(referencedModelNameCap).add(currentModelNameCap);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let changed = false;
|
|
43
|
+
for (const [name, table] of Object.entries(tables)) {
|
|
44
|
+
const c = addOrUpdateModel(name, table, zmodel, tables, toManyRelations, !!options.advanced?.database?.useNumberId);
|
|
45
|
+
changed = changed || c;
|
|
46
|
+
}
|
|
47
|
+
if (!changed) return;
|
|
48
|
+
let content = new ZModelCodeGenerator().generate(zmodel);
|
|
49
|
+
try {
|
|
50
|
+
content = await formatDocument(content);
|
|
51
|
+
} catch {}
|
|
52
|
+
return content;
|
|
53
|
+
}
|
|
54
|
+
function addDefaultNow(df) {
|
|
55
|
+
const nowArg = { $type: "AttributeArg" };
|
|
56
|
+
nowArg.value = {
|
|
57
|
+
$type: "InvocationExpr",
|
|
58
|
+
function: { $refText: "now" },
|
|
59
|
+
args: [],
|
|
60
|
+
$container: nowArg
|
|
61
|
+
};
|
|
62
|
+
addFieldAttribute(df, "@default", [nowArg]);
|
|
63
|
+
}
|
|
64
|
+
function createDataModel(modelName, zmodel, numericId) {
|
|
65
|
+
const dataModel = {
|
|
66
|
+
$type: "DataModel",
|
|
67
|
+
name: modelName,
|
|
68
|
+
fields: [],
|
|
69
|
+
attributes: [],
|
|
70
|
+
mixins: [],
|
|
71
|
+
comments: [],
|
|
72
|
+
isView: false,
|
|
73
|
+
$container: zmodel
|
|
74
|
+
};
|
|
75
|
+
let idField;
|
|
76
|
+
if (numericId) idField = addModelField(dataModel, "id", "Int", false, false);
|
|
77
|
+
else idField = addModelField(dataModel, "id", "String", false, false);
|
|
78
|
+
addFieldAttribute(idField, "@id");
|
|
79
|
+
return dataModel;
|
|
80
|
+
}
|
|
81
|
+
function addModelField(dataModel, fieldName, fieldType, array, optional) {
|
|
82
|
+
const field = {
|
|
83
|
+
$type: "DataField",
|
|
84
|
+
name: fieldName,
|
|
85
|
+
attributes: [],
|
|
86
|
+
comments: [],
|
|
87
|
+
$container: dataModel
|
|
88
|
+
};
|
|
89
|
+
field.type = {
|
|
90
|
+
$type: "DataFieldType",
|
|
91
|
+
type: fieldType,
|
|
92
|
+
array,
|
|
93
|
+
optional,
|
|
94
|
+
$container: field
|
|
95
|
+
};
|
|
96
|
+
dataModel.fields.push(field);
|
|
97
|
+
return field;
|
|
98
|
+
}
|
|
99
|
+
function initializeZmodel(config) {
|
|
100
|
+
const zmodel = {
|
|
101
|
+
$type: "Model",
|
|
102
|
+
declarations: [],
|
|
103
|
+
imports: []
|
|
104
|
+
};
|
|
105
|
+
const ds = {
|
|
106
|
+
$type: "DataSource",
|
|
107
|
+
name: "db",
|
|
108
|
+
fields: [],
|
|
109
|
+
$container: zmodel
|
|
110
|
+
};
|
|
111
|
+
zmodel.declarations.push(ds);
|
|
112
|
+
const providerField = {
|
|
113
|
+
$type: "ConfigField",
|
|
114
|
+
name: "provider",
|
|
115
|
+
$container: ds
|
|
116
|
+
};
|
|
117
|
+
providerField.value = {
|
|
118
|
+
$type: "StringLiteral",
|
|
119
|
+
value: config.provider,
|
|
120
|
+
$container: providerField
|
|
121
|
+
};
|
|
122
|
+
const urlField = {
|
|
123
|
+
$type: "ConfigField",
|
|
124
|
+
name: "url",
|
|
125
|
+
$container: ds
|
|
126
|
+
};
|
|
127
|
+
const envCall = {
|
|
128
|
+
$type: "InvocationExpr",
|
|
129
|
+
function: { $refText: "env" },
|
|
130
|
+
args: [],
|
|
131
|
+
$container: urlField
|
|
132
|
+
};
|
|
133
|
+
const dbUrlArg = { $type: "Argument" };
|
|
134
|
+
dbUrlArg.value = {
|
|
135
|
+
$type: "StringLiteral",
|
|
136
|
+
value: "DATABASE_URL",
|
|
137
|
+
$container: dbUrlArg
|
|
138
|
+
};
|
|
139
|
+
envCall.args = [dbUrlArg];
|
|
140
|
+
urlField.value = config.provider === "sqlite" ? {
|
|
141
|
+
$type: "StringLiteral",
|
|
142
|
+
value: "file:./dev.db",
|
|
143
|
+
$container: urlField
|
|
144
|
+
} : envCall;
|
|
145
|
+
ds.fields.push(providerField);
|
|
146
|
+
ds.fields.push(urlField);
|
|
147
|
+
return zmodel;
|
|
148
|
+
}
|
|
149
|
+
function getMappedFieldType({ bigint, type }) {
|
|
150
|
+
return match(type).with("string", () => ({ type: "String" })).with("number", () => bigint ? { type: "BigInt" } : { type: "Int" }).with("boolean", () => ({ type: "Boolean" })).with("date", () => ({ type: "DateTime" })).with("json", () => ({ type: "Json" })).with("string[]", () => ({
|
|
151
|
+
type: "String",
|
|
152
|
+
array: true
|
|
153
|
+
})).with("number[]", () => ({
|
|
154
|
+
type: "Int",
|
|
155
|
+
array: true
|
|
156
|
+
})).when((v) => Array.isArray(v) && v.every((e) => typeof e === "string"), () => {
|
|
157
|
+
return { type: "String" };
|
|
158
|
+
}).otherwise(() => {
|
|
159
|
+
throw new Error(`Unsupported field type: ${type}`);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function addOrUpdateModel(tableName, table, zmodel, tables, toManyRelations, numericId) {
|
|
163
|
+
let changed = false;
|
|
164
|
+
const modelName = upperCaseFirst(tables[tableName]?.modelName ?? tableName);
|
|
165
|
+
let dataModel = zmodel.declarations.find((d) => isDataModel(d) && d.name === modelName);
|
|
166
|
+
if (!dataModel) {
|
|
167
|
+
changed = true;
|
|
168
|
+
dataModel = createDataModel(modelName, zmodel, numericId);
|
|
169
|
+
zmodel.declarations.push(dataModel);
|
|
170
|
+
}
|
|
171
|
+
if (modelName !== tableName && !hasAttribute(dataModel, "@@map")) addModelAttribute(dataModel, "@@map", [createStringAttributeArg(tableName)]);
|
|
172
|
+
for (const [fName, field] of Object.entries(table.fields)) {
|
|
173
|
+
const fieldName = field.fieldName ?? fName;
|
|
174
|
+
if (dataModel.fields.some((f) => f.name === fieldName)) continue;
|
|
175
|
+
changed = true;
|
|
176
|
+
if (!field.references) {
|
|
177
|
+
const { array, type } = getMappedFieldType(field);
|
|
178
|
+
const df = {
|
|
179
|
+
$type: "DataField",
|
|
180
|
+
name: fieldName,
|
|
181
|
+
attributes: [],
|
|
182
|
+
comments: [],
|
|
183
|
+
$container: dataModel
|
|
184
|
+
};
|
|
185
|
+
df.type = {
|
|
186
|
+
$type: "DataFieldType",
|
|
187
|
+
type,
|
|
188
|
+
array: !!array,
|
|
189
|
+
optional: !field.required,
|
|
190
|
+
$container: df
|
|
191
|
+
};
|
|
192
|
+
dataModel.fields.push(df);
|
|
193
|
+
if (fieldName === "id") addFieldAttribute(df, "@id");
|
|
194
|
+
if (field.unique) addFieldAttribute(df, "@unique");
|
|
195
|
+
if (field.defaultValue !== void 0) {
|
|
196
|
+
if (fieldName === "createdAt") addDefaultNow(df);
|
|
197
|
+
else if (typeof field.defaultValue === "boolean") addFieldAttribute(df, "@default", [createBooleanAttributeArg(field.defaultValue)]);
|
|
198
|
+
else if (typeof field.defaultValue === "string") addFieldAttribute(df, "@default", [createStringAttributeArg(field.defaultValue)]);
|
|
199
|
+
else if (typeof field.defaultValue === "number") addFieldAttribute(df, "@default", [createNumberAttributeArg(field.defaultValue)]);
|
|
200
|
+
else if (typeof field.defaultValue === "function") if (field.defaultValue() instanceof Date) addDefaultNow(df);
|
|
201
|
+
else console.warn(`Warning: Unsupported default function for field ${fieldName} in model ${table.modelName}. Please adjust manually.`);
|
|
202
|
+
}
|
|
203
|
+
if (fieldName === "updatedAt" && field.onUpdate) addFieldAttribute(df, "@updatedAt");
|
|
204
|
+
else if (field.onUpdate) console.warn(`Warning: 'onUpdate' is only supported on 'updatedAt' fields. Please adjust manually for field ${fieldName} in model ${table.modelName}.`);
|
|
205
|
+
} else {
|
|
206
|
+
addModelField(dataModel, fieldName, numericId ? "Int" : "String", false, !field.required);
|
|
207
|
+
const referencedOriginalModelName = field.references.model;
|
|
208
|
+
const referencedCustomModelName = tables[referencedOriginalModelName]?.modelName || referencedOriginalModelName;
|
|
209
|
+
const relationField = {
|
|
210
|
+
$type: "DataField",
|
|
211
|
+
name: lowerCaseFirst(referencedCustomModelName),
|
|
212
|
+
attributes: [],
|
|
213
|
+
comments: [],
|
|
214
|
+
$container: dataModel
|
|
215
|
+
};
|
|
216
|
+
relationField.type = {
|
|
217
|
+
$type: "DataFieldType",
|
|
218
|
+
reference: { $refText: upperCaseFirst(referencedCustomModelName) },
|
|
219
|
+
array: field.type.endsWith("[]"),
|
|
220
|
+
optional: !field.required,
|
|
221
|
+
$container: relationField
|
|
222
|
+
};
|
|
223
|
+
let action = "Cascade";
|
|
224
|
+
if (field.references.onDelete === "no action") action = "NoAction";
|
|
225
|
+
else if (field.references.onDelete === "set null") action = "SetNull";
|
|
226
|
+
else if (field.references.onDelete === "set default") action = "SetDefault";
|
|
227
|
+
else if (field.references.onDelete === "restrict") action = "Restrict";
|
|
228
|
+
const relationAttr = {
|
|
229
|
+
$type: "DataFieldAttribute",
|
|
230
|
+
decl: { $refText: "@relation" },
|
|
231
|
+
args: [],
|
|
232
|
+
$container: relationField
|
|
233
|
+
};
|
|
234
|
+
const fieldsArg = {
|
|
235
|
+
$type: "AttributeArg",
|
|
236
|
+
name: "fields",
|
|
237
|
+
$container: relationAttr
|
|
238
|
+
};
|
|
239
|
+
const fieldsExpr = {
|
|
240
|
+
$type: "ArrayExpr",
|
|
241
|
+
items: [],
|
|
242
|
+
$container: fieldsArg
|
|
243
|
+
};
|
|
244
|
+
const fkRefExpr = {
|
|
245
|
+
$type: "ReferenceExpr",
|
|
246
|
+
args: [],
|
|
247
|
+
$container: fieldsExpr,
|
|
248
|
+
target: { $refText: fieldName }
|
|
249
|
+
};
|
|
250
|
+
fieldsExpr.items.push(fkRefExpr);
|
|
251
|
+
fieldsArg.value = fieldsExpr;
|
|
252
|
+
const referencesArg = {
|
|
253
|
+
$type: "AttributeArg",
|
|
254
|
+
name: "references",
|
|
255
|
+
$container: relationAttr
|
|
256
|
+
};
|
|
257
|
+
const referencesExpr = {
|
|
258
|
+
$type: "ArrayExpr",
|
|
259
|
+
items: [],
|
|
260
|
+
$container: referencesArg
|
|
261
|
+
};
|
|
262
|
+
const pkRefExpr = {
|
|
263
|
+
$type: "ReferenceExpr",
|
|
264
|
+
args: [],
|
|
265
|
+
$container: referencesExpr,
|
|
266
|
+
target: { $refText: field.references.field }
|
|
267
|
+
};
|
|
268
|
+
referencesExpr.items.push(pkRefExpr);
|
|
269
|
+
referencesArg.value = referencesExpr;
|
|
270
|
+
const onDeleteArg = {
|
|
271
|
+
$type: "AttributeArg",
|
|
272
|
+
name: "onDelete",
|
|
273
|
+
$container: relationAttr
|
|
274
|
+
};
|
|
275
|
+
onDeleteArg.value = {
|
|
276
|
+
$type: "ReferenceExpr",
|
|
277
|
+
target: { $refText: action },
|
|
278
|
+
args: [],
|
|
279
|
+
$container: onDeleteArg
|
|
280
|
+
};
|
|
281
|
+
relationAttr.args.push(...[
|
|
282
|
+
fieldsArg,
|
|
283
|
+
referencesArg,
|
|
284
|
+
onDeleteArg
|
|
285
|
+
]);
|
|
286
|
+
relationField.attributes.push(relationAttr);
|
|
287
|
+
dataModel.fields.push(relationField);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (toManyRelations.has(modelName)) {
|
|
291
|
+
const relations = toManyRelations.get(modelName);
|
|
292
|
+
for (const relatedModel of relations) {
|
|
293
|
+
const relationName = `${lowerCaseFirst(relatedModel)}s`;
|
|
294
|
+
if (!dataModel.fields.some((f) => f.name === relationName)) {
|
|
295
|
+
const relationField = {
|
|
296
|
+
$type: "DataField",
|
|
297
|
+
name: relationName,
|
|
298
|
+
attributes: [],
|
|
299
|
+
comments: [],
|
|
300
|
+
$container: dataModel
|
|
301
|
+
};
|
|
302
|
+
relationField.type = {
|
|
303
|
+
$type: "DataFieldType",
|
|
304
|
+
reference: { $refText: relatedModel },
|
|
305
|
+
array: true,
|
|
306
|
+
optional: false,
|
|
307
|
+
$container: relationField
|
|
308
|
+
};
|
|
309
|
+
dataModel.fields.push(relationField);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return changed;
|
|
314
|
+
}
|
|
315
|
+
function addModelAttribute(dataModel, name, args = []) {
|
|
316
|
+
const attr = {
|
|
317
|
+
$type: "DataModelAttribute",
|
|
318
|
+
decl: { $refText: name },
|
|
319
|
+
$container: dataModel,
|
|
320
|
+
args: []
|
|
321
|
+
};
|
|
322
|
+
const finalArgs = args.map((arg) => ({
|
|
323
|
+
...arg,
|
|
324
|
+
$container: attr
|
|
325
|
+
}));
|
|
326
|
+
attr.args.push(...finalArgs);
|
|
327
|
+
dataModel.attributes.push(attr);
|
|
328
|
+
}
|
|
329
|
+
function addFieldAttribute(dataField, name, args = []) {
|
|
330
|
+
const attr = {
|
|
331
|
+
$type: "DataFieldAttribute",
|
|
332
|
+
decl: { $refText: name },
|
|
333
|
+
$container: dataField,
|
|
334
|
+
args: []
|
|
335
|
+
};
|
|
336
|
+
const finalArgs = args.map((arg) => ({
|
|
337
|
+
...arg,
|
|
338
|
+
$container: attr
|
|
339
|
+
}));
|
|
340
|
+
attr.args.push(...finalArgs);
|
|
341
|
+
dataField.attributes.push(attr);
|
|
342
|
+
}
|
|
343
|
+
function createBooleanAttributeArg(value) {
|
|
344
|
+
const arg = { $type: "AttributeArg" };
|
|
345
|
+
arg.value = {
|
|
346
|
+
$type: "BooleanLiteral",
|
|
347
|
+
value,
|
|
348
|
+
$container: arg
|
|
349
|
+
};
|
|
350
|
+
return arg;
|
|
351
|
+
}
|
|
352
|
+
function createNumberAttributeArg(value) {
|
|
353
|
+
const arg = { $type: "AttributeArg" };
|
|
354
|
+
arg.value = {
|
|
355
|
+
$type: "NumberLiteral",
|
|
356
|
+
value: value.toString(),
|
|
357
|
+
$container: arg
|
|
358
|
+
};
|
|
359
|
+
return arg;
|
|
360
|
+
}
|
|
361
|
+
function createStringAttributeArg(value) {
|
|
362
|
+
const arg = { $type: "AttributeArg" };
|
|
363
|
+
arg.value = {
|
|
364
|
+
$type: "StringLiteral",
|
|
365
|
+
value,
|
|
366
|
+
$container: arg
|
|
367
|
+
};
|
|
368
|
+
return arg;
|
|
369
|
+
}
|
|
370
|
+
//#endregion
|
|
371
|
+
export { generateSchema };
|
|
372
|
+
|
|
373
|
+
//# sourceMappingURL=schema-generator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-generator.mjs","names":[],"sources":["../src/schema-generator.ts"],"sourcesContent":["import { lowerCaseFirst, upperCaseFirst } from '@zenstackhq/common-helpers';\nimport { formatDocument, loadDocument, ZModelCodeGenerator } from '@zenstackhq/language';\nimport {\n Argument,\n ArrayExpr,\n AttributeArg,\n BooleanLiteral,\n ConfigExpr,\n ConfigField,\n DataField,\n DataFieldAttribute,\n DataFieldType,\n DataModel,\n DataModelAttribute,\n DataSource,\n InvocationExpr,\n isDataModel,\n Model,\n NumberLiteral,\n ReferenceExpr,\n StringLiteral,\n} from '@zenstackhq/language/ast';\nimport { hasAttribute } from '@zenstackhq/language/utils';\nimport { type BetterAuthOptions } from 'better-auth';\nimport type { DBAdapterSchemaCreation } from 'better-auth/adapters';\nimport type { BetterAuthDBSchema, DBFieldAttribute, DBFieldType } from 'better-auth/db';\nimport fs from 'node:fs';\nimport { match } from 'ts-pattern';\nimport type { AdapterConfig } from './adapter';\n\nexport async function generateSchema(\n file: string | undefined,\n tables: BetterAuthDBSchema,\n config: AdapterConfig,\n options: BetterAuthOptions,\n): Promise<DBAdapterSchemaCreation> {\n let filePath = file;\n\n if (!filePath) {\n // TODO: respect \"zenstack\" entry in package.json for default schema file path\n if (fs.existsSync('./schema.zmodel')) {\n filePath = './schema.zmodel';\n } else {\n filePath = './zenstack/schema.zmodel';\n }\n }\n\n const schemaExists = fs.existsSync(filePath);\n\n const schema = await updateSchema(filePath, tables, config, options);\n\n return {\n code: schema ?? '',\n path: filePath,\n overwrite: schemaExists && !!schema,\n };\n}\n\nasync function updateSchema(\n schemaPath: string,\n tables: BetterAuthDBSchema,\n config: AdapterConfig,\n options: BetterAuthOptions,\n) {\n let zmodel: Model | undefined;\n if (fs.existsSync(schemaPath)) {\n const loadResult = await loadDocument(schemaPath);\n if (!loadResult.success) {\n throw new Error(`Failed to load existing schema at ${schemaPath}: ${loadResult.errors.join(', ')}`);\n }\n zmodel = loadResult.model;\n } else {\n zmodel = initializeZmodel(config);\n }\n\n // collect to-many relations\n const toManyRelations = new Map();\n for (const [tableName, table] of Object.entries(tables)) {\n const fields = tables[tableName]?.fields;\n for (const field in fields) {\n const attr = fields[field]!;\n if (attr.references) {\n const referencedOriginalModel = attr.references.model;\n const referencedCustomModel = tables[referencedOriginalModel]?.modelName || referencedOriginalModel;\n const referencedModelNameCap = upperCaseFirst(referencedCustomModel);\n if (!toManyRelations.has(referencedModelNameCap)) {\n toManyRelations.set(referencedModelNameCap, new Set());\n }\n const currentCustomModel = table.modelName ?? tableName;\n const currentModelNameCap = upperCaseFirst(currentCustomModel);\n toManyRelations.get(referencedModelNameCap).add(currentModelNameCap);\n }\n }\n }\n\n let changed = false;\n\n for (const [name, table] of Object.entries(tables)) {\n const c = addOrUpdateModel(\n name,\n table,\n zmodel,\n tables,\n toManyRelations,\n !!options.advanced?.database?.useNumberId,\n );\n changed = changed || c;\n }\n\n if (!changed) {\n return undefined;\n }\n\n const generator = new ZModelCodeGenerator();\n let content = generator.generate(zmodel);\n\n try {\n content = await formatDocument(content);\n } catch {\n // ignore formatting errors\n }\n\n return content;\n}\n\n// @default(now())\nfunction addDefaultNow(df: DataField) {\n const nowArg: AttributeArg = {\n $type: 'AttributeArg',\n } as any;\n const nowExpr: InvocationExpr = {\n $type: 'InvocationExpr',\n function: { $refText: 'now' },\n args: [],\n $container: nowArg,\n };\n nowArg.value = nowExpr;\n addFieldAttribute(df, '@default', [nowArg]);\n}\n\nfunction createDataModel(modelName: string, zmodel: Model, numericId: boolean) {\n const dataModel: DataModel = {\n $type: 'DataModel',\n name: modelName,\n fields: [],\n attributes: [],\n mixins: [],\n comments: [],\n isView: false,\n $container: zmodel,\n };\n\n let idField: DataField;\n if (numericId) {\n idField = addModelField(dataModel, 'id', 'Int', false, false);\n } else {\n idField = addModelField(dataModel, 'id', 'String', false, false);\n }\n addFieldAttribute(idField, '@id');\n\n return dataModel;\n}\n\nfunction addModelField(dataModel: DataModel, fieldName: string, fieldType: string, array: boolean, optional: boolean) {\n const field: DataField = {\n $type: 'DataField',\n name: fieldName,\n attributes: [],\n comments: [],\n $container: dataModel,\n } as any;\n field.type = {\n $type: 'DataFieldType',\n type: fieldType as any,\n array,\n optional,\n $container: field,\n };\n dataModel.fields.push(field);\n return field;\n}\n\nfunction initializeZmodel(config: AdapterConfig) {\n const zmodel: Model = {\n $type: 'Model',\n declarations: [],\n imports: [],\n };\n\n // datasource db { ... }\n const ds: DataSource = {\n $type: 'DataSource',\n name: 'db',\n fields: [],\n $container: zmodel,\n };\n zmodel.declarations.push(ds);\n\n // provider = 'sqlite' | 'postgresql'\n const providerField: ConfigField = {\n $type: 'ConfigField',\n name: 'provider',\n $container: ds,\n } as any;\n providerField.value = {\n $type: 'StringLiteral',\n value: config.provider,\n $container: providerField,\n } satisfies ConfigExpr;\n\n const urlField: ConfigField = {\n $type: 'ConfigField',\n name: 'url',\n $container: ds,\n } as any;\n\n // env('DATABASE_URL')\n const envCall: InvocationExpr = {\n $type: 'InvocationExpr',\n function: {\n $refText: 'env',\n },\n args: [],\n $container: urlField,\n };\n\n // 'DATABASE_URL' arg\n const dbUrlArg: Argument = {\n $type: 'Argument',\n } as any;\n dbUrlArg.value = {\n $type: 'StringLiteral',\n value: 'DATABASE_URL',\n $container: dbUrlArg,\n } satisfies ConfigExpr;\n\n envCall.args = [dbUrlArg];\n\n urlField.value =\n config.provider === 'sqlite'\n ? {\n $type: 'StringLiteral',\n value: 'file:./dev.db',\n $container: urlField,\n }\n : envCall;\n\n ds.fields.push(providerField);\n ds.fields.push(urlField);\n\n return zmodel;\n}\n\nfunction getMappedFieldType({ bigint, type }: DBFieldAttribute) {\n return match<DBFieldType, { type: string; array?: boolean }>(type)\n .with('string', () => ({ type: 'String' }))\n .with('number', () => (bigint ? { type: 'BigInt' } : { type: 'Int' }))\n .with('boolean', () => ({ type: 'Boolean' }))\n .with('date', () => ({ type: 'DateTime' }))\n .with('json', () => ({ type: 'Json' }))\n .with('string[]', () => ({ type: 'String', array: true }))\n .with('number[]', () => ({ type: 'Int', array: true }))\n .when(\n (v) => Array.isArray(v) && v.every((e) => typeof e === 'string'),\n () => {\n // Handle enum types (e.g., ['user', 'admin']), map them to String type for now\n return { type: 'String' };\n },\n )\n .otherwise(() => {\n throw new Error(`Unsupported field type: ${type}`);\n });\n}\n\nfunction addOrUpdateModel(\n tableName: string,\n table: BetterAuthDBSchema[string],\n zmodel: Model,\n tables: BetterAuthDBSchema,\n toManyRelations: Map<string, Set<string>>,\n numericId: boolean,\n): boolean {\n let changed = false;\n const customModelName = tables[tableName]?.modelName ?? tableName;\n const modelName = upperCaseFirst(customModelName);\n\n let dataModel = zmodel.declarations.find((d): d is DataModel => isDataModel(d) && d.name === modelName);\n if (!dataModel) {\n changed = true;\n dataModel = createDataModel(modelName, zmodel, numericId);\n zmodel.declarations.push(dataModel);\n }\n\n if (modelName !== tableName && !hasAttribute(dataModel, '@@map')) {\n addModelAttribute(dataModel, '@@map', [createStringAttributeArg(tableName)]);\n }\n\n for (const [fName, field] of Object.entries(table.fields)) {\n const fieldName = field.fieldName ?? fName;\n if (dataModel.fields.some((f) => f.name === fieldName)) {\n continue;\n }\n\n changed = true;\n\n if (!field.references) {\n // scalar field\n const { array, type } = getMappedFieldType(field);\n\n const df: DataField = {\n $type: 'DataField',\n name: fieldName,\n attributes: [],\n comments: [],\n $container: dataModel,\n } as any;\n df.type = {\n $type: 'DataFieldType',\n type: type as any,\n array: !!array,\n optional: !field.required,\n $container: df,\n };\n dataModel.fields.push(df);\n\n // @id\n if (fieldName === 'id') {\n addFieldAttribute(df, '@id');\n }\n\n // @unique\n if (field.unique) {\n addFieldAttribute(df, '@unique');\n }\n\n // @default\n if (field.defaultValue !== undefined) {\n if (fieldName === 'createdAt') {\n // @default(now())\n addDefaultNow(df);\n } else if (typeof field.defaultValue === 'boolean') {\n addFieldAttribute(df, '@default', [createBooleanAttributeArg(field.defaultValue)]);\n } else if (typeof field.defaultValue === 'string') {\n addFieldAttribute(df, '@default', [createStringAttributeArg(field.defaultValue)]);\n } else if (typeof field.defaultValue === 'number') {\n addFieldAttribute(df, '@default', [createNumberAttributeArg(field.defaultValue)]);\n } else if (typeof field.defaultValue === 'function') {\n // For other function-based defaults, we'll need to check what they return\n const defaultVal = field.defaultValue();\n if (defaultVal instanceof Date) {\n // @default(now())\n addDefaultNow(df);\n } else {\n console.warn(\n `Warning: Unsupported default function for field ${fieldName} in model ${table.modelName}. Please adjust manually.`,\n );\n }\n }\n }\n\n // This is a special handling for updatedAt fields\n if (fieldName === 'updatedAt' && field.onUpdate) {\n addFieldAttribute(df, '@updatedAt');\n } else if (field.onUpdate) {\n console.warn(\n `Warning: 'onUpdate' is only supported on 'updatedAt' fields. Please adjust manually for field ${fieldName} in model ${table.modelName}.`,\n );\n }\n } else {\n // relation\n\n // fk field\n addModelField(dataModel, fieldName, numericId ? 'Int' : 'String', false, !field.required);\n\n // relation field\n const referencedOriginalModelName = field.references.model;\n const referencedCustomModelName =\n tables[referencedOriginalModelName]?.modelName || referencedOriginalModelName;\n\n const relationField: DataField = {\n $type: 'DataField',\n name: lowerCaseFirst(referencedCustomModelName),\n attributes: [],\n comments: [],\n $container: dataModel,\n } as any;\n relationField.type = {\n $type: 'DataFieldType',\n reference: {\n $refText: upperCaseFirst(referencedCustomModelName),\n },\n array: (field.type as string).endsWith('[]'),\n optional: !field.required,\n $container: relationField,\n } satisfies DataFieldType;\n\n let action = 'Cascade';\n if (field.references.onDelete === 'no action') action = 'NoAction';\n else if (field.references.onDelete === 'set null') action = 'SetNull';\n else if (field.references.onDelete === 'set default') action = 'SetDefault';\n else if (field.references.onDelete === 'restrict') action = 'Restrict';\n\n // @relation(fields: [field], references: [referencedField], onDelete: action)\n const relationAttr: DataFieldAttribute = {\n $type: 'DataFieldAttribute',\n decl: {\n $refText: '@relation',\n },\n args: [],\n $container: relationField,\n };\n\n // fields: [field]\n const fieldsArg: AttributeArg = {\n $type: 'AttributeArg',\n name: 'fields',\n $container: relationAttr,\n } as any;\n const fieldsExpr: ArrayExpr = {\n $type: 'ArrayExpr',\n items: [],\n $container: fieldsArg,\n };\n const fkRefExpr: ReferenceExpr = {\n $type: 'ReferenceExpr',\n args: [],\n $container: fieldsExpr,\n target: {\n $refText: fieldName,\n },\n };\n fieldsExpr.items.push(fkRefExpr);\n fieldsArg.value = fieldsExpr;\n\n // references: [referencedField]\n const referencesArg: AttributeArg = {\n $type: 'AttributeArg',\n name: 'references',\n $container: relationAttr,\n } as any;\n const referencesExpr: ArrayExpr = {\n $type: 'ArrayExpr',\n items: [],\n $container: referencesArg,\n };\n const pkRefExpr: ReferenceExpr = {\n $type: 'ReferenceExpr',\n args: [],\n $container: referencesExpr,\n target: {\n $refText: field.references.field,\n },\n };\n referencesExpr.items.push(pkRefExpr);\n referencesArg.value = referencesExpr;\n\n // onDelete: action\n const onDeleteArg: AttributeArg = {\n $type: 'AttributeArg',\n name: 'onDelete',\n $container: relationAttr,\n } as any;\n const onDeleteValueExpr: ReferenceExpr = {\n $type: 'ReferenceExpr',\n target: { $refText: action },\n args: [],\n $container: onDeleteArg,\n };\n onDeleteArg.value = onDeleteValueExpr;\n\n relationAttr.args.push(...[fieldsArg, referencesArg, onDeleteArg]);\n relationField.attributes.push(relationAttr);\n\n dataModel.fields.push(relationField);\n }\n }\n\n // add to-many relations\n if (toManyRelations.has(modelName)) {\n const relations = toManyRelations.get(modelName)!;\n for (const relatedModel of relations) {\n const relationName = `${lowerCaseFirst(relatedModel)}s`;\n if (!dataModel.fields.some((f) => f.name === relationName)) {\n const relationField: DataField = {\n $type: 'DataField',\n name: relationName,\n attributes: [],\n comments: [],\n $container: dataModel,\n } as any;\n const relationType: DataFieldType = {\n $type: 'DataFieldType',\n reference: {\n $refText: relatedModel,\n },\n array: true,\n optional: false,\n $container: relationField,\n };\n relationField.type = relationType;\n dataModel.fields.push(relationField);\n }\n }\n }\n\n return changed;\n}\n\nfunction addModelAttribute(dataModel: DataModel, name: string, args: Omit<AttributeArg, '$container'>[] = []) {\n const attr: DataModelAttribute = {\n $type: 'DataModelAttribute',\n decl: { $refText: name },\n $container: dataModel,\n args: [],\n };\n const finalArgs = args.map((arg) => ({\n ...arg,\n $container: attr,\n }));\n attr.args.push(...finalArgs);\n dataModel.attributes.push(attr);\n}\n\nfunction addFieldAttribute(dataField: DataField, name: string, args: Omit<AttributeArg, '$container'>[] = []) {\n const attr: DataFieldAttribute = {\n $type: 'DataFieldAttribute',\n decl: { $refText: name },\n $container: dataField,\n args: [],\n };\n const finalArgs = args.map((arg) => ({\n ...arg,\n $container: attr,\n }));\n attr.args.push(...finalArgs);\n dataField.attributes.push(attr);\n}\n\nfunction createBooleanAttributeArg(value: boolean) {\n const arg: AttributeArg = {\n $type: 'AttributeArg',\n } as any;\n const expr: BooleanLiteral = {\n $type: 'BooleanLiteral',\n value,\n $container: arg,\n };\n arg.value = expr;\n return arg;\n}\n\nfunction createNumberAttributeArg(value: number) {\n const arg: AttributeArg = {\n $type: 'AttributeArg',\n } as any;\n const expr: NumberLiteral = {\n $type: 'NumberLiteral',\n value: value.toString(),\n $container: arg,\n };\n arg.value = expr;\n return arg;\n}\n\nfunction createStringAttributeArg(value: string) {\n const arg: AttributeArg = {\n $type: 'AttributeArg',\n } as any;\n const expr: StringLiteral = {\n $type: 'StringLiteral',\n value,\n $container: arg,\n };\n arg.value = expr;\n return arg;\n}\n"],"mappings":";;;;;;;;AA8BA,eAAsB,eAClB,MACA,QACA,QACA,SACgC;CAChC,IAAI,WAAW;AAEf,KAAI,CAAC,SAED,KAAI,GAAG,WAAW,kBAAkB,CAChC,YAAW;KAEX,YAAW;CAInB,MAAM,eAAe,GAAG,WAAW,SAAS;CAE5C,MAAM,SAAS,MAAM,aAAa,UAAU,QAAQ,QAAQ,QAAQ;AAEpE,QAAO;EACH,MAAM,UAAU;EAChB,MAAM;EACN,WAAW,gBAAgB,CAAC,CAAC;EAChC;;AAGL,eAAe,aACX,YACA,QACA,QACA,SACF;CACE,IAAI;AACJ,KAAI,GAAG,WAAW,WAAW,EAAE;EAC3B,MAAM,aAAa,MAAM,aAAa,WAAW;AACjD,MAAI,CAAC,WAAW,QACZ,OAAM,IAAI,MAAM,qCAAqC,WAAW,IAAI,WAAW,OAAO,KAAK,KAAK,GAAG;AAEvG,WAAS,WAAW;OAEpB,UAAS,iBAAiB,OAAO;CAIrC,MAAM,kCAAkB,IAAI,KAAK;AACjC,MAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,OAAO,EAAE;EACrD,MAAM,SAAS,OAAO,YAAY;AAClC,OAAK,MAAM,SAAS,QAAQ;GACxB,MAAM,OAAO,OAAO;AACpB,OAAI,KAAK,YAAY;IACjB,MAAM,0BAA0B,KAAK,WAAW;IAEhD,MAAM,yBAAyB,eADD,OAAO,0BAA0B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YAAY;KACf;AAED,cAAU,OAAO,KAAK,cAAc;;;;AAKhD,QAAO;;AAGX,SAAS,kBAAkB,WAAsB,MAAc,OAA2C,EAAE,EAAE;CAC1G,MAAM,OAA2B;EAC7B,OAAO;EACP,MAAM,EAAE,UAAU,MAAM;EACxB,YAAY;EACZ,MAAM,EAAE;EACX;CACD,MAAM,YAAY,KAAK,KAAK,SAAS;EACjC,GAAG;EACH,YAAY;EACf,EAAE;AACH,MAAK,KAAK,KAAK,GAAG,UAAU;AAC5B,WAAU,WAAW,KAAK,KAAK;;AAGnC,SAAS,kBAAkB,WAAsB,MAAc,OAA2C,EAAE,EAAE;CAC1G,MAAM,OAA2B;EAC7B,OAAO;EACP,MAAM,EAAE,UAAU,MAAM;EACxB,YAAY;EACZ,MAAM,EAAE;EACX;CACD,MAAM,YAAY,KAAK,KAAK,SAAS;EACjC,GAAG;EACH,YAAY;EACf,EAAE;AACH,MAAK,KAAK,KAAK,GAAG,UAAU;AAC5B,WAAU,WAAW,KAAK,KAAK;;AAGnC,SAAS,0BAA0B,OAAgB;CAC/C,MAAM,MAAoB,EACtB,OAAO,gBACV;AAMD,KAAI,QALyB;EACzB,OAAO;EACP;EACA,YAAY;EACf;AAED,QAAO;;AAGX,SAAS,yBAAyB,OAAe;CAC7C,MAAM,MAAoB,EACtB,OAAO,gBACV;AAMD,KAAI,QALwB;EACxB,OAAO;EACP,OAAO,MAAM,UAAU;EACvB,YAAY;EACf;AAED,QAAO;;AAGX,SAAS,yBAAyB,OAAe;CAC7C,MAAM,MAAoB,EACtB,OAAO,gBACV;AAMD,KAAI,QALwB;EACxB,OAAO;EACP;EACA,YAAY;EACf;AAED,QAAO"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@zenstackhq/better-auth",
|
|
3
3
|
"displayName": "ZenStack Better Auth Adapter",
|
|
4
4
|
"description": "ZenStack Better Auth Adapter. This adapter is modified from better-auth's Prisma adapter.",
|
|
5
|
-
"version": "3.6.
|
|
5
|
+
"version": "3.6.3-beta.1",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "ZenStack Team",
|
|
@@ -32,6 +32,16 @@
|
|
|
32
32
|
"default": "./dist/index.cjs"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
|
+
"./schema-generator": {
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./dist/schema-generator.d.mts",
|
|
38
|
+
"default": "./dist/schema-generator.mjs"
|
|
39
|
+
},
|
|
40
|
+
"require": {
|
|
41
|
+
"types": "./dist/schema-generator.d.cts",
|
|
42
|
+
"default": "./dist/schema-generator.cjs"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
35
45
|
"./package.json": {
|
|
36
46
|
"import": "./package.json",
|
|
37
47
|
"require": "./package.json"
|
|
@@ -39,9 +49,9 @@
|
|
|
39
49
|
},
|
|
40
50
|
"dependencies": {
|
|
41
51
|
"ts-pattern": "^5.7.1",
|
|
42
|
-
"@zenstackhq/
|
|
43
|
-
"@zenstackhq/
|
|
44
|
-
"@zenstackhq/
|
|
52
|
+
"@zenstackhq/common-helpers": "3.6.3-beta.1",
|
|
53
|
+
"@zenstackhq/orm": "3.6.3-beta.1",
|
|
54
|
+
"@zenstackhq/language": "3.6.3-beta.1"
|
|
45
55
|
},
|
|
46
56
|
"peerDependencies": {
|
|
47
57
|
"@better-auth/core": "^1.3.0",
|
|
@@ -54,11 +64,11 @@
|
|
|
54
64
|
"better-auth": "1.4.19",
|
|
55
65
|
"kysely": "~0.28.16",
|
|
56
66
|
"tmp": "^0.2.4",
|
|
57
|
-
"@zenstackhq/
|
|
58
|
-
"@zenstackhq/eslint-config": "3.6.
|
|
59
|
-
"@zenstackhq/
|
|
60
|
-
"@zenstackhq/
|
|
61
|
-
"@zenstackhq/
|
|
67
|
+
"@zenstackhq/typescript-config": "3.6.3-beta.1",
|
|
68
|
+
"@zenstackhq/eslint-config": "3.6.3-beta.1",
|
|
69
|
+
"@zenstackhq/vitest-config": "3.6.3-beta.1",
|
|
70
|
+
"@zenstackhq/cli": "3.6.3-beta.1",
|
|
71
|
+
"@zenstackhq/tsdown-config": "3.6.3-beta.1"
|
|
62
72
|
},
|
|
63
73
|
"funding": "https://github.com/sponsors/zenstackhq",
|
|
64
74
|
"scripts": {
|