faire-auth 1.0.0 → 1.0.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/dist/{access-Crt-IJ2P.cjs → access-BZ7-AbTM.cjs} +1 -1
- package/dist/{adapter-factory-DT-_2aHJ.cjs → adapter-factory-D1I7joki.cjs} +2 -2
- package/dist/adapters/drizzle-adapter/index.cjs +5 -5
- package/dist/adapters/drizzle-adapter/index.d.cts +1 -1
- package/dist/adapters/drizzle-adapter/index.d.mts +2 -2
- package/dist/adapters/drizzle-adapter/index.mjs +3 -3
- package/dist/adapters/index.cjs +4 -4
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.mts +2 -2
- package/dist/adapters/index.mjs +3 -3
- package/dist/adapters/kysely-adapter/index.cjs +5 -5
- package/dist/adapters/kysely-adapter/index.d.cts +1 -1
- package/dist/adapters/kysely-adapter/index.d.mts +2 -2
- package/dist/adapters/kysely-adapter/index.mjs +4 -4
- package/dist/adapters/memory-adapter/index.cjs +5 -5
- package/dist/adapters/memory-adapter/index.d.cts +1 -1
- package/dist/adapters/memory-adapter/index.d.mts +2 -2
- package/dist/adapters/memory-adapter/index.mjs +4 -4
- package/dist/adapters/mongodb-adapter/index.cjs +294 -6
- package/dist/adapters/mongodb-adapter/index.d.cts +34 -2
- package/dist/adapters/mongodb-adapter/index.d.mts +35 -3
- package/dist/adapters/mongodb-adapter/index.mjs +291 -4
- package/dist/adapters/prisma-adapter/index.cjs +5 -5
- package/dist/adapters/prisma-adapter/index.d.cts +1 -1
- package/dist/adapters/prisma-adapter/index.d.mts +2 -2
- package/dist/adapters/prisma-adapter/index.mjs +3 -3
- package/dist/adapters/test.cjs +3 -3
- package/dist/adapters/test.d.cts +1 -1
- package/dist/adapters/test.d.mts +2 -2
- package/dist/adapters/test.mjs +2 -2
- package/dist/api/index.cjs +15 -15
- package/dist/api/index.d.cts +1 -1
- package/dist/api/index.d.mts +2 -2
- package/dist/api/index.mjs +8 -8
- package/dist/api/middleware/index.cjs +8 -8
- package/dist/api/middleware/index.d.cts +3 -3
- package/dist/api/middleware/index.d.mts +4 -4
- package/dist/api/middleware/index.mjs +3 -3
- package/dist/{api-_B7qO28y.mjs → api-B4RDwBty.mjs} +7 -7
- package/dist/{api-Bm89BLgN.cjs → api-CaRC1Gio.cjs} +12 -12
- package/dist/{bearer-CHeREcGT.cjs → bearer-DDzrp5M7.cjs} +2 -2
- package/dist/{bearer-0SeEmaS4.mjs → bearer-WZcs7gxL.mjs} +1 -1
- package/dist/{bun-sqlite-dialect-wuaC2-gh.cjs → bun-sqlite-dialect-DPgTzc0w.cjs} +1 -1
- package/dist/{chunk-Ceigfy4P.mjs → chunk-BFnQceUY.mjs} +1 -13
- package/dist/{chunk-oakRccI5.cjs → chunk-fPmz2rbM.cjs} +0 -9
- package/dist/client/index.cjs +26 -7
- package/dist/client/index.d.cts +27 -4
- package/dist/client/index.d.mts +28 -5
- package/dist/client/index.mjs +25 -6
- package/dist/client/lynx/index.cjs +5 -5
- package/dist/client/lynx/index.d.cts +15 -15
- package/dist/client/lynx/index.d.mts +27 -27
- package/dist/client/lynx/index.mjs +3 -3
- package/dist/client/plugins/index.d.cts +1 -1
- package/dist/client/plugins/index.d.mts +2 -2
- package/dist/client/react/index.cjs +5 -5
- package/dist/client/react/index.d.cts +26 -26
- package/dist/client/react/index.d.mts +16 -16
- package/dist/client/react/index.mjs +3 -3
- package/dist/client/solid/index.cjs +5 -5
- package/dist/client/solid/index.d.cts +16 -16
- package/dist/client/solid/index.d.mts +17 -17
- package/dist/client/solid/index.mjs +3 -3
- package/dist/client/svelte/index.cjs +4 -4
- package/dist/client/svelte/index.d.cts +11 -11
- package/dist/client/svelte/index.d.mts +16 -16
- package/dist/client/svelte/index.mjs +3 -3
- package/dist/client/vue/index.cjs +5 -5
- package/dist/client/vue/index.d.cts +27 -27
- package/dist/client/vue/index.d.mts +28 -28
- package/dist/client/vue/index.mjs +3 -3
- package/dist/{cookies-B5xeA6i8.cjs → cookies-BTl72THv.cjs} +3 -3
- package/dist/{cookies-Ch1JfQIz.mjs → cookies-BTs1o992.mjs} +2 -2
- package/dist/crypto/index.cjs +1 -1
- package/dist/crypto/index.d.cts +2 -2
- package/dist/crypto/index.d.mts +3 -3
- package/dist/crypto/index.mjs +1 -1
- package/dist/{crypto-CyQRFtkq.mjs → crypto-DH2Aa7jN.mjs} +1 -1
- package/dist/{crypto-CcTxYH82.cjs → crypto-DpSCnrTp.cjs} +1 -1
- package/dist/db/index.cjs +10 -10
- package/dist/db/index.d.cts +1 -1
- package/dist/db/index.d.mts +2 -2
- package/dist/db/index.mjs +6 -6
- package/dist/{db-xiJtoDgz.mjs → db-4tUsQJXd.mjs} +3 -3
- package/dist/{db-BTKyYu-_.cjs → db-ChMbb_U-.cjs} +8 -8
- package/dist/{email-verification-CWhj2qfb.mjs → email-verification-C_lBu_JY.mjs} +3 -3
- package/dist/{email-verification-C-AsfJsb.cjs → email-verification-DI_0H4JC.cjs} +5 -5
- package/dist/{hono-Cdukwu5K.cjs → hono-C14rpOEa.cjs} +1 -1
- package/dist/{hono-Covz10jU.mjs → hono-CO-zsqI-.mjs} +2 -2
- package/dist/{hono-BEq1NYVX.cjs → hono-DnW5crl1.cjs} +4 -4
- package/dist/{index-BVHscLQl.d.cts → index-4PEF72Mq.d.cts} +20 -20
- package/dist/{index-B-WeOMzg.d.cts → index-BCzB3uDD.d.cts} +833 -833
- package/dist/{index-B09P9p5_.d.cts → index-Bw8dyZTc.d.cts} +6 -6
- package/dist/{index-Qu-iJGNr.d.mts → index-C0b8eC8h.d.mts} +16 -16
- package/dist/{index-jlessPI0.d.mts → index-CrmLTEj8.d.mts} +382 -382
- package/dist/index-Dfgobqa-.d.mts +33 -0
- package/dist/index.cjs +721 -27
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +711 -16
- package/dist/integrations/next-js.cjs +3 -3
- package/dist/integrations/next-js.d.cts +5 -5
- package/dist/integrations/next-js.d.mts +6 -6
- package/dist/integrations/next-js.mjs +2 -2
- package/dist/integrations/node.d.cts +1 -1
- package/dist/integrations/node.d.mts +2 -2
- package/dist/integrations/react-start.cjs +3 -3
- package/dist/integrations/react-start.d.cts +5 -5
- package/dist/integrations/react-start.d.mts +5 -5
- package/dist/integrations/react-start.mjs +2 -2
- package/dist/integrations/svelte-kit.cjs +3 -3
- package/dist/integrations/svelte-kit.d.cts +5 -5
- package/dist/integrations/svelte-kit.d.mts +6 -6
- package/dist/integrations/svelte-kit.mjs +2 -2
- package/dist/{ip-B5SwXaMB.cjs → ip-C17Qdq-G.cjs} +2 -2
- package/dist/{json-CcJ2HjGo.cjs → json--tl7Grvs.cjs} +1 -1
- package/dist/{kysely-adapter-DRuoT_X8.mjs → kysely-adapter-CtIdoHa8.mjs} +3 -3
- package/dist/{kysely-adapter-Bxi7sPdG.cjs → kysely-adapter-QZTx077T.cjs} +4 -4
- package/dist/{logged-DQK3C64b.cjs → logged-Dv3st5qc.cjs} +1 -1
- package/dist/{memory-adapter-BlnDIAAX.cjs → memory-adapter-17RZd5df.cjs} +2 -2
- package/dist/{memory-adapter-Db3tsJTn.mjs → memory-adapter-Dp4XdCZK.mjs} +1 -1
- package/dist/{node-sqlite-dialect-mJWC8LWQ.cjs → node-sqlite-dialect-DP11CB0y.cjs} +1 -1
- package/dist/oauth2/index.cjs +11 -11
- package/dist/oauth2/index.d.cts +1 -1
- package/dist/oauth2/index.d.mts +2 -2
- package/dist/oauth2/index.mjs +6 -6
- package/dist/{oauth2-BLeOEi7Y.cjs → oauth2-5RL4cVNS.cjs} +3 -3
- package/dist/{oauth2-B8M0lW9l.mjs → oauth2-C56wz-n9.mjs} +2 -2
- package/dist/{origin-check-id9lTnqZ.cjs → origin-check-DjLTuZQ8.cjs} +2 -2
- package/dist/{passkey-B6N20LSS.cjs → passkey-BTT-v5c-.cjs} +4 -4
- package/dist/{passkey-DJsR_GX3.mjs → passkey-CzY_W2us.mjs} +2 -2
- package/dist/plugins/access/index.cjs +1 -1
- package/dist/plugins/access/index.d.cts +1 -1
- package/dist/plugins/access/index.d.mts +1 -1
- package/dist/plugins/access/index.mjs +1 -1
- package/dist/plugins/bearer/index.cjs +4 -4
- package/dist/plugins/bearer/index.d.cts +2 -2
- package/dist/plugins/bearer/index.d.mts +3 -3
- package/dist/plugins/bearer/index.mjs +3 -3
- package/dist/plugins/index.cjs +5215 -31
- package/dist/plugins/index.d.cts +351 -351
- package/dist/plugins/index.d.mts +268 -268
- package/dist/plugins/index.mjs +5202 -19
- package/dist/plugins/passkey/index.cjs +10 -10
- package/dist/plugins/passkey/index.d.cts +2 -2
- package/dist/plugins/passkey/index.d.mts +3 -3
- package/dist/plugins/passkey/index.mjs +5 -5
- package/dist/{schema-D-qjygfE.cjs → schema-CirKflVs.cjs} +2 -2
- package/dist/{session-rH8ougDl.mjs → session-CM3rmOYF.mjs} +1 -1
- package/dist/{session-De9POJTW.cjs → session-Cwrj4GfV.cjs} +5 -5
- package/dist/social-providers/index.cjs +1 -1
- package/dist/social-providers/index.d.cts +1 -1
- package/dist/social-providers/index.d.mts +1 -1
- package/dist/social-providers/index.mjs +1 -1
- package/dist/{social-providers-DoYJhBe3.mjs → social-providers-B8RK5yqI.mjs} +1 -1
- package/dist/{social-providers-DcFNUT0S.cjs → social-providers-BmFOIIPk.cjs} +1 -1
- package/dist/{state-CqJfCIl9.mjs → state-CQghgH9I.mjs} +1 -1
- package/dist/{state--f7fwIGh.cjs → state-CvSihlVT.cjs} +2 -2
- package/dist/test-utils/bun-sqlite-dialect-BSWhhKNs.mjs +155 -0
- package/dist/test-utils/bun-sqlite-dialect-BZBvHchL.cjs +156 -0
- package/dist/test-utils/index.cjs +8927 -482
- package/dist/test-utils/index.d.cts +8395 -337
- package/dist/test-utils/index.d.mts +8394 -334
- package/dist/test-utils/index.mjs +8712 -265
- package/dist/test-utils/node-sqlite-dialect-BgJqjBOu.cjs +156 -0
- package/dist/test-utils/node-sqlite-dialect-DAQXiobH.mjs +155 -0
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.mts +2 -2
- package/dist/{url-D2yvKaM7.cjs → url-Ce7CVaQD.cjs} +1 -1
- package/dist/utils/cookies.cjs +4 -4
- package/dist/utils/cookies.d.cts +1 -1
- package/dist/utils/cookies.d.mts +2 -2
- package/dist/utils/cookies.mjs +2 -2
- package/package.json +2 -2
- package/dist/auth-Bo9PDt5j.cjs +0 -739
- package/dist/auth-Ds4AG4h4.mjs +0 -709
- package/dist/index-C2-2QDyS.d.cts +0 -35
- package/dist/index-CWAqWfoZ.d.cts +0 -27
- package/dist/index-CYSShrFx.d.mts +0 -27
- package/dist/index-ppgcFe12.d.mts +0 -33
- package/dist/index-to0RO38U.d.mts +0 -35
- package/dist/mongodb-adapter-C_qGQED5.mjs +0 -291
- package/dist/mongodb-adapter-C_qfK87x.cjs +0 -297
- package/dist/plugins-C1lm2Wj3.cjs +0 -5254
- package/dist/plugins-Dai1QkRU.mjs +0 -5199
- package/dist/vanilla-Bu2PmFzE.cjs +0 -30
- package/dist/vanilla-TfHqeiC7.mjs +0 -25
- /package/dist/{access-B5bBI4uT.mjs → access-D0DRqUKC.mjs} +0 -0
- /package/dist/{adapter-factory-BXei1QRX.mjs → adapter-factory-lKIOf2OR.mjs} +0 -0
- /package/dist/{bun-sqlite-dialect-CfkBo2v5.mjs → bun-sqlite-dialect-6NqeV3px.mjs} +0 -0
- /package/dist/{defu-B0Svx_x4.cjs → defu-BmOYq4PU.cjs} +0 -0
- /package/dist/{defu-SZkpHhbR.mjs → defu-D9ZTXqlo.mjs} +0 -0
- /package/dist/{hono-DuE14mmj.d.mts → hono-D0VqxVy1.d.mts} +0 -0
- /package/dist/{index-B5_0QTLg.d.mts → index-BDhhaE6Y.d.cts} +0 -0
- /package/dist/{index-B7SKyR_a.d.cts → index-CF9iq55a.d.mts} +0 -0
- /package/dist/{index-CTwrVluH.d.mts → index-CRt_fppq.d.mts} +0 -0
- /package/dist/{index-cs4Sh0En.d.cts → index-CdLyn7qP.d.cts} +0 -0
- /package/dist/{node-sqlite-dialect-BfBzyOAg.mjs → node-sqlite-dialect-w4DAg0PH.mjs} +0 -0
- /package/dist/{parser-CeAer-RM.mjs → parser-B25ylT5u.mjs} +0 -0
- /package/dist/{parser-CdncAl9i.cjs → parser-B_wxvaAr.cjs} +0 -0
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-oakRccI5.cjs');
|
|
2
|
-
const require_adapter_factory = require('./adapter-factory-DT-_2aHJ.cjs');
|
|
3
|
-
let mongodb = require("mongodb");
|
|
4
|
-
|
|
5
|
-
//#region src/adapters/mongodb-adapter/mongodb-adapter.ts
|
|
6
|
-
const mongodbAdapter = (db, config) => {
|
|
7
|
-
let lazyOptions;
|
|
8
|
-
const createCustomAdapter = (db$1, session) => ({ options, getFieldName, schema, getDefaultModelName }) => {
|
|
9
|
-
function serializeID({ field, value, model }) {
|
|
10
|
-
model = getDefaultModelName(model);
|
|
11
|
-
if (field === "id" || field === "_id" || schema[model].fields[field]?.references?.field === "id") {
|
|
12
|
-
if (typeof value !== "string") {
|
|
13
|
-
if (value instanceof mongodb.ObjectId) return value;
|
|
14
|
-
if (Array.isArray(value)) return value.map((v) => {
|
|
15
|
-
if (typeof v === "string") try {
|
|
16
|
-
return new mongodb.ObjectId(v);
|
|
17
|
-
} catch (e) {
|
|
18
|
-
return v;
|
|
19
|
-
}
|
|
20
|
-
if (v instanceof mongodb.ObjectId) return v;
|
|
21
|
-
throw new Error("Invalid id value");
|
|
22
|
-
});
|
|
23
|
-
throw new Error("Invalid id value");
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
return new mongodb.ObjectId(value);
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
function convertWhereClause({ where, model }) {
|
|
34
|
-
if (!where.length) return {};
|
|
35
|
-
const conditions = where.map((w) => {
|
|
36
|
-
const { field: field_, value, operator = "eq", connector = "AND" } = w;
|
|
37
|
-
let condition;
|
|
38
|
-
let field = getFieldName({
|
|
39
|
-
model,
|
|
40
|
-
field: field_
|
|
41
|
-
});
|
|
42
|
-
if (field === "id") field = "_id";
|
|
43
|
-
switch (operator.toLowerCase()) {
|
|
44
|
-
case "eq":
|
|
45
|
-
condition = { [field]: serializeID({
|
|
46
|
-
field,
|
|
47
|
-
value,
|
|
48
|
-
model
|
|
49
|
-
}) };
|
|
50
|
-
break;
|
|
51
|
-
case "in":
|
|
52
|
-
condition = { [field]: { $in: Array.isArray(value) ? value.map((v) => serializeID({
|
|
53
|
-
field,
|
|
54
|
-
value: v,
|
|
55
|
-
model
|
|
56
|
-
})) : [serializeID({
|
|
57
|
-
field,
|
|
58
|
-
value,
|
|
59
|
-
model
|
|
60
|
-
})] } };
|
|
61
|
-
break;
|
|
62
|
-
case "not_in":
|
|
63
|
-
condition = { [field]: { $nin: Array.isArray(value) ? value.map((v) => serializeID({
|
|
64
|
-
field,
|
|
65
|
-
value: v,
|
|
66
|
-
model
|
|
67
|
-
})) : [serializeID({
|
|
68
|
-
field,
|
|
69
|
-
value,
|
|
70
|
-
model
|
|
71
|
-
})] } };
|
|
72
|
-
break;
|
|
73
|
-
case "gt":
|
|
74
|
-
condition = { [field]: { $gt: value } };
|
|
75
|
-
break;
|
|
76
|
-
case "gte":
|
|
77
|
-
condition = { [field]: { $gte: value } };
|
|
78
|
-
break;
|
|
79
|
-
case "lt":
|
|
80
|
-
condition = { [field]: { $lt: value } };
|
|
81
|
-
break;
|
|
82
|
-
case "lte":
|
|
83
|
-
condition = { [field]: { $lte: value } };
|
|
84
|
-
break;
|
|
85
|
-
case "ne":
|
|
86
|
-
condition = { [field]: { $ne: value } };
|
|
87
|
-
break;
|
|
88
|
-
case "contains":
|
|
89
|
-
condition = { [field]: { $regex: `.*${escapeForMongoRegex(value)}.*` } };
|
|
90
|
-
break;
|
|
91
|
-
case "starts_with":
|
|
92
|
-
condition = { [field]: { $regex: `^${escapeForMongoRegex(value)}` } };
|
|
93
|
-
break;
|
|
94
|
-
case "ends_with":
|
|
95
|
-
condition = { [field]: { $regex: `${escapeForMongoRegex(value)}$` } };
|
|
96
|
-
break;
|
|
97
|
-
default: throw new Error(`Unsupported operator: ${operator}`);
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
condition,
|
|
101
|
-
connector
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
if (conditions.length === 1) return conditions[0].condition;
|
|
105
|
-
const andConditions = conditions.filter((c) => c.connector === "AND").map((c) => c.condition);
|
|
106
|
-
const orConditions = conditions.filter((c) => c.connector === "OR").map((c) => c.condition);
|
|
107
|
-
let clause = {};
|
|
108
|
-
if (andConditions.length) clause = {
|
|
109
|
-
...clause,
|
|
110
|
-
$and: andConditions
|
|
111
|
-
};
|
|
112
|
-
if (orConditions.length) clause = {
|
|
113
|
-
...clause,
|
|
114
|
-
$or: orConditions
|
|
115
|
-
};
|
|
116
|
-
return clause;
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
async create({ model, data: values }) {
|
|
120
|
-
return {
|
|
121
|
-
_id: (await db$1.collection(model).insertOne(values, { ...session && { session } })).insertedId.toString(),
|
|
122
|
-
...values
|
|
123
|
-
};
|
|
124
|
-
},
|
|
125
|
-
async findOne({ model, where, select }) {
|
|
126
|
-
const clause = convertWhereClause({
|
|
127
|
-
where,
|
|
128
|
-
model
|
|
129
|
-
});
|
|
130
|
-
const projection = select ? Object.fromEntries(select.map((field) => [getFieldName({
|
|
131
|
-
field,
|
|
132
|
-
model
|
|
133
|
-
}), 1])) : void 0;
|
|
134
|
-
const res = await db$1.collection(model).findOne(clause, {
|
|
135
|
-
...session && { session },
|
|
136
|
-
...projection && { projection }
|
|
137
|
-
});
|
|
138
|
-
if (!res) return null;
|
|
139
|
-
return res;
|
|
140
|
-
},
|
|
141
|
-
async findMany({ model, where, limit, offset, sortBy }) {
|
|
142
|
-
const clause = where ? convertWhereClause({
|
|
143
|
-
where,
|
|
144
|
-
model
|
|
145
|
-
}) : {};
|
|
146
|
-
const cursor = db$1.collection(model).find(clause, { ...session && { session } });
|
|
147
|
-
if (limit) cursor.limit(limit);
|
|
148
|
-
if (offset) cursor.skip(offset);
|
|
149
|
-
if (sortBy) cursor.sort(getFieldName({
|
|
150
|
-
field: sortBy.field,
|
|
151
|
-
model
|
|
152
|
-
}), sortBy.direction === "desc" ? -1 : 1);
|
|
153
|
-
return await cursor.toArray();
|
|
154
|
-
},
|
|
155
|
-
async count({ model, where }) {
|
|
156
|
-
const clause = where ? convertWhereClause({
|
|
157
|
-
where,
|
|
158
|
-
model
|
|
159
|
-
}) : {};
|
|
160
|
-
return await db$1.collection(model).countDocuments(clause, { ...session && { session } });
|
|
161
|
-
},
|
|
162
|
-
async update({ model, where, update: values }) {
|
|
163
|
-
const clause = convertWhereClause({
|
|
164
|
-
where,
|
|
165
|
-
model
|
|
166
|
-
});
|
|
167
|
-
const res = await db$1.collection(model).findOneAndUpdate(clause, { $set: values }, {
|
|
168
|
-
...session && { session },
|
|
169
|
-
returnDocument: "after"
|
|
170
|
-
});
|
|
171
|
-
if (!res) return null;
|
|
172
|
-
return res;
|
|
173
|
-
},
|
|
174
|
-
async updateMany({ model, where, update: values }) {
|
|
175
|
-
const clause = convertWhereClause({
|
|
176
|
-
where,
|
|
177
|
-
model
|
|
178
|
-
});
|
|
179
|
-
return (await db$1.collection(model).updateMany(clause, { $set: values }, { ...session && { session } })).modifiedCount;
|
|
180
|
-
},
|
|
181
|
-
async delete({ model, where }) {
|
|
182
|
-
const clause = convertWhereClause({
|
|
183
|
-
where,
|
|
184
|
-
model
|
|
185
|
-
});
|
|
186
|
-
await db$1.collection(model).deleteOne(clause, { ...session && { session } });
|
|
187
|
-
},
|
|
188
|
-
async deleteMany({ model, where }) {
|
|
189
|
-
const clause = convertWhereClause({
|
|
190
|
-
where,
|
|
191
|
-
model
|
|
192
|
-
});
|
|
193
|
-
return (await db$1.collection(model).deleteMany(clause, { ...session && { session } })).deletedCount;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
};
|
|
197
|
-
let lazyAdapter = null;
|
|
198
|
-
let adapterOptions = null;
|
|
199
|
-
adapterOptions = {
|
|
200
|
-
config: {
|
|
201
|
-
adapterId: "mongodb-adapter",
|
|
202
|
-
adapterName: "MongoDB Adapter",
|
|
203
|
-
usePlural: config?.usePlural ?? false,
|
|
204
|
-
debugLogs: config?.debugLogs ?? false,
|
|
205
|
-
mapKeysTransformInput: { id: "_id" },
|
|
206
|
-
mapKeysTransformOutput: { _id: "id" },
|
|
207
|
-
supportsNumericIds: false,
|
|
208
|
-
transaction: config?.client && (config?.transaction ?? true) ? async (cb) => {
|
|
209
|
-
if (!config.client) return cb(lazyAdapter(lazyOptions));
|
|
210
|
-
const session = config.client.startSession();
|
|
211
|
-
try {
|
|
212
|
-
session.startTransaction();
|
|
213
|
-
const result = await cb(require_adapter_factory.createAdapterFactory({
|
|
214
|
-
config: adapterOptions.config,
|
|
215
|
-
adapter: createCustomAdapter(db, session)
|
|
216
|
-
})(lazyOptions));
|
|
217
|
-
await session.commitTransaction();
|
|
218
|
-
return result;
|
|
219
|
-
} catch (err) {
|
|
220
|
-
await session.abortTransaction();
|
|
221
|
-
throw err;
|
|
222
|
-
} finally {
|
|
223
|
-
await session.endSession();
|
|
224
|
-
}
|
|
225
|
-
} : false,
|
|
226
|
-
customTransformInput({ action, data, field, fieldAttributes, schema, model, options }) {
|
|
227
|
-
if (field === "_id" || fieldAttributes.references?.field === "id") {
|
|
228
|
-
if (action === "update") {
|
|
229
|
-
if (typeof data === "string") try {
|
|
230
|
-
return new mongodb.ObjectId(data);
|
|
231
|
-
} catch (error) {
|
|
232
|
-
return data;
|
|
233
|
-
}
|
|
234
|
-
return data;
|
|
235
|
-
}
|
|
236
|
-
if (Array.isArray(data)) return data.map((v) => {
|
|
237
|
-
if (typeof v === "string") try {
|
|
238
|
-
return new mongodb.ObjectId(v);
|
|
239
|
-
} catch (error) {
|
|
240
|
-
return v;
|
|
241
|
-
}
|
|
242
|
-
return v;
|
|
243
|
-
});
|
|
244
|
-
if (typeof data === "string") try {
|
|
245
|
-
return new mongodb.ObjectId(data);
|
|
246
|
-
} catch (error) {
|
|
247
|
-
return new mongodb.ObjectId();
|
|
248
|
-
}
|
|
249
|
-
if (data === null && fieldAttributes.references?.field === "id") return null;
|
|
250
|
-
return new mongodb.ObjectId();
|
|
251
|
-
}
|
|
252
|
-
return data;
|
|
253
|
-
},
|
|
254
|
-
customTransformOutput({ data, field, fieldAttributes }) {
|
|
255
|
-
if (field === "id" || fieldAttributes.references?.field === "id") {
|
|
256
|
-
if (data instanceof mongodb.ObjectId) return data.toHexString();
|
|
257
|
-
if (Array.isArray(data)) return data.map((v) => {
|
|
258
|
-
if (v instanceof mongodb.ObjectId) return v.toHexString();
|
|
259
|
-
return v;
|
|
260
|
-
});
|
|
261
|
-
return data;
|
|
262
|
-
}
|
|
263
|
-
return data;
|
|
264
|
-
},
|
|
265
|
-
customIdGenerator(props) {
|
|
266
|
-
return new mongodb.ObjectId().toString();
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
adapter: createCustomAdapter(db)
|
|
270
|
-
};
|
|
271
|
-
lazyAdapter = require_adapter_factory.createAdapterFactory(adapterOptions);
|
|
272
|
-
return (options) => {
|
|
273
|
-
lazyOptions = options;
|
|
274
|
-
return lazyAdapter(options);
|
|
275
|
-
};
|
|
276
|
-
};
|
|
277
|
-
/**
|
|
278
|
-
* Safely escape user input for use in a MongoDB regex.
|
|
279
|
-
* This ensures the resulting pattern is treated as literal text,
|
|
280
|
-
* and not as a regex with special syntax.
|
|
281
|
-
*
|
|
282
|
-
* @param input - The input string to escape. Any type that isn't a string will be converted to an empty string.
|
|
283
|
-
* @param maxLength - The maximum length of the input string to escape. Defaults to 256. This is to prevent DOS attacks.
|
|
284
|
-
* @returns The escaped string.
|
|
285
|
-
*/
|
|
286
|
-
function escapeForMongoRegex(input, maxLength = 256) {
|
|
287
|
-
if (typeof input !== "string") return "";
|
|
288
|
-
return input.slice(0, maxLength).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
//#endregion
|
|
292
|
-
Object.defineProperty(exports, 'mongodbAdapter', {
|
|
293
|
-
enumerable: true,
|
|
294
|
-
get: function () {
|
|
295
|
-
return mongodbAdapter;
|
|
296
|
-
}
|
|
297
|
-
});
|