@classytic/arc 2.11.4 → 2.13.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/README.md +16 -12
- package/dist/{BaseController-swXruJ2_.mjs → BaseController-DX_T-bDB.mjs} +388 -423
- package/dist/EventTransport-CT_52aWU.d.mts +34 -0
- package/dist/EventTransport-DLWoUMHy.mjs +103 -0
- package/dist/{ResourceRegistry-DkAeAuTX.mjs → ResourceRegistry-CTERg_2x.mjs} +139 -66
- package/dist/audit/index.d.mts +2 -2
- package/dist/audit/index.mjs +1 -1
- package/dist/auth/audit.d.mts +199 -0
- package/dist/auth/audit.mjs +288 -0
- package/dist/auth/index.d.mts +3 -3
- package/dist/auth/index.mjs +117 -191
- package/dist/{betterAuthOpenApi-DwxtK3uG.mjs → betterAuthOpenApi--M_i87dQ.mjs} +1 -1
- package/dist/buildHandler-olo-gt94.mjs +610 -0
- package/dist/cache/index.mjs +3 -3
- package/dist/cli/commands/describe.d.mts +89 -13
- package/dist/cli/commands/describe.mjs +56 -2
- package/dist/cli/commands/docs.mjs +2 -2
- package/dist/cli/commands/generate.mjs +147 -48
- package/dist/cli/commands/init.d.mts +13 -0
- package/dist/cli/commands/init.mjs +130 -87
- package/dist/cli/commands/introspect.mjs +8 -1
- package/dist/context/index.mjs +1 -1
- package/dist/core/index.d.mts +3 -3
- package/dist/core/index.mjs +5 -5
- package/dist/core-D72ia0EH.mjs +1399 -0
- package/dist/{createActionRouter-CIKOcNA7.mjs → createActionRouter-CEvzKcy8.mjs} +7 -20
- package/dist/createAggregationRouter-CyecOxnO.mjs +114 -0
- package/dist/{createApp-C9bRrqlX.mjs → createApp-XX2-N0Yd.mjs} +28 -22
- package/dist/{defineEvent-D1Ky9M1D.mjs → defineEvent-D5h7EvAx.mjs} +1 -1
- package/dist/docs/index.d.mts +1 -1
- package/dist/docs/index.mjs +2 -2
- package/dist/{elevation-DOFoxoDs.mjs → elevation-DgoeTyfX.mjs} +1 -1
- package/dist/errorHandler-Bk-AGhkU.mjs +174 -0
- package/dist/errorHandler-DFr45ZG4.d.mts +45 -0
- package/dist/errors-j4aJm1Wg.mjs +184 -0
- package/dist/{eventPlugin-Cts2-Tfj.mjs → eventPlugin-CaKTYkYM.mjs} +28 -4
- package/dist/{eventPlugin-DDJoNEPL.d.mts → eventPlugin-qXpqTebY.d.mts} +24 -1
- package/dist/events/index.d.mts +6 -6
- package/dist/events/index.mjs +11 -35
- package/dist/events/transports/redis-stream-entry.d.mts +1 -1
- package/dist/events/transports/redis.d.mts +1 -1
- package/dist/factory/index.d.mts +2 -2
- package/dist/factory/index.mjs +2 -2
- package/dist/{fields-BRjxOAFp.d.mts → fields-COhcH3fk.d.mts} +23 -2
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.mjs +1 -1
- package/dist/idempotency/index.d.mts +1 -1
- package/dist/idempotency/index.mjs +1 -20
- package/dist/idempotency/redis.mjs +1 -1
- package/dist/{index-rHjXmJar.d.mts → index-BTqLEvhu.d.mts} +163 -3
- package/dist/{index-CXXRbnf8.d.mts → index-BtW7qYwa.d.mts} +660 -326
- package/dist/{index-m8mOOlFW.d.mts → index-Ds61mrJE.d.mts} +50 -4
- package/dist/{index-D9t1KNaB.d.mts → index-Dz5IKsrE.d.mts} +360 -219
- package/dist/index.d.mts +6 -7
- package/dist/index.mjs +9 -10
- package/dist/integrations/event-gateway.d.mts +1 -1
- package/dist/integrations/event-gateway.mjs +1 -1
- package/dist/integrations/index.d.mts +1 -1
- package/dist/integrations/mcp/index.d.mts +2 -2
- package/dist/integrations/mcp/index.mjs +1 -1
- package/dist/integrations/mcp/testing.d.mts +1 -1
- package/dist/integrations/mcp/testing.mjs +1 -1
- package/dist/integrations/streamline.d.mts +60 -11
- package/dist/integrations/streamline.mjs +75 -85
- package/dist/integrations/websocket.mjs +2 -8
- package/dist/middleware/index.d.mts +1 -1
- package/dist/middleware/index.mjs +2 -2
- package/dist/migrations/index.d.mts +23 -3
- package/dist/migrations/index.mjs +0 -7
- package/dist/{multipartBody-CvTR1Un6.mjs → multipartBody-BOvVSVCD.mjs} +11 -8
- package/dist/{openapi-D7G1V7ex.mjs → openapi-CiOMVW1p.mjs} +143 -13
- package/dist/org/index.d.mts +2 -2
- package/dist/org/index.mjs +1 -1
- package/dist/permissions/index.d.mts +3 -3
- package/dist/permissions/index.mjs +3 -3
- package/dist/{permissions-gd_aUWrR.mjs → permissions-ohQyv50e.mjs} +404 -176
- package/dist/{pipe-DVoIheVC.mjs → pipe-Zr0KXjQe.mjs} +1 -1
- package/dist/pipeline/index.d.mts +1 -1
- package/dist/pipeline/index.mjs +1 -1
- package/dist/plugins/index.d.mts +16 -31
- package/dist/plugins/index.mjs +33 -13
- package/dist/plugins/response-cache.mjs +1 -1
- package/dist/plugins/tracing-entry.mjs +1 -1
- package/dist/presets/filesUpload.d.mts +4 -4
- package/dist/presets/filesUpload.mjs +6 -9
- package/dist/presets/index.d.mts +1 -1
- package/dist/presets/index.mjs +1 -1
- package/dist/presets/multiTenant.d.mts +1 -1
- package/dist/presets/multiTenant.mjs +2 -2
- package/dist/presets/search.d.mts +2 -2
- package/dist/presets/search.mjs +6 -8
- package/dist/{presets-Z7P5w4gF.mjs → presets-BbkjdPeH.mjs} +6 -28
- package/dist/{queryCachePlugin-Bq6bO6vc.mjs → queryCachePlugin-m1XsgAIJ.mjs} +3 -3
- package/dist/{redis-stream-xTGxB2bm.d.mts → redis-stream-D6HzR1Z_.d.mts} +1 -1
- package/dist/registry/index.d.mts +1 -1
- package/dist/registry/index.mjs +2 -2
- package/dist/{replyHelpers-ByllIXXV.mjs → replyHelpers-CK-FNO8E.mjs} +3 -21
- package/dist/{resourceToTools-CxNmI6xF.mjs → resourceToTools-C5coh64w.mjs} +224 -71
- package/dist/{routerShared-BqLRb5l7.mjs → routerShared-D6_fEGHh.mjs} +40 -36
- package/dist/{schemaIR-Dy2p4MxS.mjs → schemaIR-7Vl611Qs.mjs} +1 -1
- package/dist/schemas/index.d.mts +100 -30
- package/dist/schemas/index.mjs +86 -29
- package/dist/scim/index.d.mts +264 -0
- package/dist/scim/index.mjs +963 -0
- package/dist/scope/index.d.mts +3 -3
- package/dist/scope/index.mjs +4 -4
- package/dist/{sse-V7aXc3bW.mjs → sse-Bz-5ZeTt.mjs} +1 -1
- package/dist/{store-helpers-Cp4uKC1U.mjs → store-helpers-BkIN9-vu.mjs} +1 -1
- package/dist/testing/index.d.mts +2 -8
- package/dist/testing/index.mjs +16 -24
- package/dist/types/index.d.mts +4 -4
- package/dist/{types-D7KpfiL1.d.mts → types-BvqwCCSx.d.mts} +73 -25
- package/dist/{types-DDyTPc6y.d.mts → types-CTYvcwHe.d.mts} +195 -1
- package/dist/{types-AOD8fxIw.mjs → types-C_s5moIu.mjs} +117 -1
- package/dist/{types-BQ9TJQNy.d.mts → types-DQHFc8PM.d.mts} +1 -1
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.mjs +5 -5
- package/dist/{utils-CcYTj09l.mjs → utils-_h9B3c57.mjs} +1269 -1334
- package/dist/{versioning-DsglKfM_.d.mts → versioning-DTTvc80y.d.mts} +1 -1
- package/package.json +24 -34
- package/skills/arc/SKILL.md +147 -51
- package/skills/arc/references/agent-auth.md +238 -0
- package/skills/arc/references/api-reference.md +187 -0
- package/skills/arc/references/auth.md +354 -7
- package/skills/arc/references/enterprise-auth.md +94 -0
- package/skills/arc/references/events.md +8 -6
- package/skills/arc/references/mcp.md +2 -2
- package/skills/arc/references/multi-tenancy.md +11 -2
- package/skills/arc/references/production.md +10 -9
- package/skills/arc/references/scim.md +247 -0
- package/skills/arc/references/testing.md +1 -1
- package/skills/arc-code-review/SKILL.md +141 -0
- package/skills/arc-code-review/references/anti-patterns.md +911 -0
- package/skills/arc-code-review/references/arc-cheatsheet.md +380 -0
- package/skills/arc-code-review/references/migration-recipes.md +700 -0
- package/skills/arc-code-review/references/mongokit-migration.md +386 -0
- package/skills/arc-code-review/references/scaffolding.md +230 -0
- package/skills/arc-code-review/references/severity.md +127 -0
- package/dist/EventTransport-BFQjw9pB.mjs +0 -133
- package/dist/EventTransport-CYNUXdCJ.d.mts +0 -293
- package/dist/adapters/index.d.mts +0 -3
- package/dist/adapters/index.mjs +0 -2
- package/dist/adapters-DUUiiimH.mjs +0 -964
- package/dist/auth/mongoose.d.mts +0 -191
- package/dist/auth/mongoose.mjs +0 -73
- package/dist/core-CbcQRIch.mjs +0 -1054
- package/dist/errorHandler-BQm8ZxTK.mjs +0 -173
- package/dist/errorHandler-DEWmGWPz.d.mts +0 -114
- package/dist/errors-D5c-5BJL.mjs +0 -232
- package/dist/index-Rg8axYPz.d.mts +0 -370
- /package/dist/{HookSystem-CGsMd6oK.mjs → HookSystem-Iiebom92.mjs} +0 -0
- /package/dist/{actionPermissions-sUUKDhtP.mjs → actionPermissions-CyUkQu6O.mjs} +0 -0
- /package/dist/{caching-CheW3m-S.mjs → caching-SM8gghN6.mjs} +0 -0
- /package/dist/{constants-BhY1OHoH.mjs → constants-Cxde4rpC.mjs} +0 -0
- /package/dist/{elevation-BQQXZ_VR.d.mts → elevation-BXOWoGCF.d.mts} +0 -0
- /package/dist/{keys-CARyUjiR.mjs → keys-CGcCbNyu.mjs} +0 -0
- /package/dist/{loadResources-CPpkyKfM.mjs → loadResources-DBMQg_Aj.mjs} +0 -0
- /package/dist/{memory-DikHSvWa.mjs → memory-UBydS5ku.mjs} +0 -0
- /package/dist/{metrics-Csh4nsvv.mjs → metrics-Qnvwc-LQ.mjs} +0 -0
- /package/dist/{pluralize-CWP6MB39.mjs → pluralize-DQgqgifU.mjs} +0 -0
- /package/dist/{registry-D63ee7fl.mjs → registry-I-ogLgL9.mjs} +0 -0
- /package/dist/{requestContext-C5XeK3VA.mjs → requestContext-SSaaTgW8.mjs} +0 -0
- /package/dist/{schemaConverter-B0oKLuqI.mjs → schemaConverter-De34B1ZG.mjs} +0 -0
- /package/dist/{typeGuards-CcFZXgU7.mjs → typeGuards-BzkXkvVv.mjs} +0 -0
- /package/dist/{types-DV9WDfeg.mjs → types-D57iXYb8.mjs} +0 -0
- /package/dist/{versioning-CGPjkqAg.mjs → versioning-BUrT5aP4.mjs} +0 -0
package/dist/auth/mongoose.d.mts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
//#region src/auth/mongoose.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Better Auth × Mongoose Bridge
|
|
4
|
-
*
|
|
5
|
-
* Optional helper that registers stub Mongoose models for the collections
|
|
6
|
-
* that Better Auth's MongoDB adapter writes to. This is a one-way *read*
|
|
7
|
-
* bridge: Better Auth still writes via its own native `mongodb` driver
|
|
8
|
-
* (through `@better-auth/mongo-adapter`), but stub models let arc resources
|
|
9
|
-
* built on Mongoose use `.populate()` against BA-owned collections.
|
|
10
|
-
*
|
|
11
|
-
* **Why this is needed**: Mongoose's `populate()` looks up the target model
|
|
12
|
-
* by name. BA never registers anything with Mongoose, so a schema like
|
|
13
|
-
* `new Schema({ userId: { ref: 'user' } })` throws `MissingSchemaError`
|
|
14
|
-
* the first time you call `.populate('userId')`. This helper registers an
|
|
15
|
-
* empty `strict: false` schema for each BA collection, so populate works
|
|
16
|
-
* without interfering with BA's writes.
|
|
17
|
-
*
|
|
18
|
-
* **DB-agnostic by design**: this file lives at the dedicated subpath
|
|
19
|
-
* `@classytic/arc/auth/mongoose`. Users on Prisma/Drizzle/Kysely never
|
|
20
|
-
* import it and never get Mongoose pulled into their bundle. Mongoose is
|
|
21
|
-
* passed in as a parameter so this module has zero runtime imports of it.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* import mongoose from 'mongoose';
|
|
26
|
-
* import { betterAuth } from 'better-auth';
|
|
27
|
-
* import { mongodbAdapter } from '@better-auth/mongo-adapter';
|
|
28
|
-
* import { organization } from 'better-auth/plugins';
|
|
29
|
-
* import { registerBetterAuthMongooseModels } from '@classytic/arc/auth/mongoose';
|
|
30
|
-
*
|
|
31
|
-
* const auth = betterAuth({
|
|
32
|
-
* database: mongodbAdapter(mongoose.connection.getClient().db()),
|
|
33
|
-
* plugins: [organization({ teams: { enabled: true } })],
|
|
34
|
-
* // ...
|
|
35
|
-
* });
|
|
36
|
-
*
|
|
37
|
-
* // Register stub models AFTER betterAuth() so collections are known.
|
|
38
|
-
* // For plugins shipped as separate @better-auth/* packages (passkey, sso,
|
|
39
|
-
* // api-key, oauth-provider, etc.), add their collection names via
|
|
40
|
-
* // `extraCollections` — see the JSDoc on that option for known names.
|
|
41
|
-
* registerBetterAuthMongooseModels(mongoose, {
|
|
42
|
-
* plugins: ['organization', 'organization-teams', 'mcp'],
|
|
43
|
-
* extraCollections: ['passkey', 'ssoProvider'], // @better-auth/passkey, @better-auth/sso
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* // Now an arc resource can populate BA-owned references:
|
|
47
|
-
* const PostSchema = new mongoose.Schema({
|
|
48
|
-
* title: String,
|
|
49
|
-
* authorId: { type: String, ref: 'user' },
|
|
50
|
-
* });
|
|
51
|
-
* const Post = mongoose.model('Post', PostSchema);
|
|
52
|
-
* await Post.findOne().populate('authorId'); // resolves against BA's user collection
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
/**
|
|
56
|
-
* Minimal structural type for the subset of Mongoose we touch.
|
|
57
|
-
* Declared structurally so this file has zero `import` of mongoose —
|
|
58
|
-
* mongoose stays a peer dep and is never bundled with arc.
|
|
59
|
-
*/
|
|
60
|
-
interface MongooseLike {
|
|
61
|
-
models: Record<string, unknown>;
|
|
62
|
-
Schema: new (definition: Record<string, unknown>, options?: {
|
|
63
|
-
strict?: boolean;
|
|
64
|
-
collection?: string;
|
|
65
|
-
_id?: boolean;
|
|
66
|
-
}) => unknown;
|
|
67
|
-
model: (name: string, schema?: unknown) => unknown;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Plugin keys that map to Better Auth collection sets.
|
|
71
|
-
*
|
|
72
|
-
* Only plugins that ship inside the **core `better-auth` package** are listed
|
|
73
|
-
* here. Plugins distributed as separate `@better-auth/*` packages
|
|
74
|
-
* (api-key, passkey, sso, oauth-provider, etc.) evolve independently and
|
|
75
|
-
* should be handled via `extraCollections` — see the JSDoc on that option.
|
|
76
|
-
*
|
|
77
|
-
* Plugins that only add *fields* to existing tables (admin, username,
|
|
78
|
-
* phoneNumber, magicLink, emailOtp, anonymous, bearer, multiSession, siwe,
|
|
79
|
-
* lastLoginMethod, genericOAuth, etc.) don't need an entry here — the stub
|
|
80
|
-
* schemas are registered with `strict: false`, so extra fields round-trip
|
|
81
|
-
* automatically.
|
|
82
|
-
*
|
|
83
|
-
* - `core` — always included; covers `user`, `session`, `account`, `verification`.
|
|
84
|
-
* - `organization` — adds `organization`, `member`, `invitation`.
|
|
85
|
-
* - `organization-teams` — adds `team`, `teamMember` (only when `teams.enabled`).
|
|
86
|
-
* - `twoFactor` — adds `twoFactor`.
|
|
87
|
-
* - `jwt` — adds `jwks`.
|
|
88
|
-
* - `oidcProvider` — adds `oauthApplication`, `oauthAccessToken`, `oauthConsent`.
|
|
89
|
-
* - `oauthProvider` — alias of `oidcProvider` (same schema). Use this key if
|
|
90
|
-
* you've migrated to `@better-auth/oauth-provider` per BA 1.6 release notes
|
|
91
|
-
* — the collections are identical.
|
|
92
|
-
* - `mcp` — MCP plugin **reuses the oidcProvider schema** (docs: "The MCP
|
|
93
|
-
* plugin uses the same schema as the OIDC Provider plugin"). Selecting this
|
|
94
|
-
* registers the oauth* collections.
|
|
95
|
-
* - `deviceAuthorization` — adds `deviceCode` (RFC 8628 device authorization).
|
|
96
|
-
*/
|
|
97
|
-
type BetterAuthPluginKey = "core" | "organization" | "organization-teams" | "twoFactor" | "jwt" | "oidcProvider" | "oauthProvider" | "mcp" | "deviceAuthorization";
|
|
98
|
-
interface RegisterBetterAuthMongooseModelsOptions {
|
|
99
|
-
/**
|
|
100
|
-
* Which Better Auth plugin collection sets to register stubs for.
|
|
101
|
-
* `'core'` is always included implicitly (covers `user`, `session`,
|
|
102
|
-
* `account`, `verification`).
|
|
103
|
-
*
|
|
104
|
-
* **Default is `[]` (core only) on purpose** — the helper should never
|
|
105
|
-
* register stubs for plugins you haven't enabled. Opt in explicitly to
|
|
106
|
-
* each plugin you've added to your `betterAuth({ plugins: [...] })` config.
|
|
107
|
-
*
|
|
108
|
-
* @default []
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* // Just core BA (email/password, sessions)
|
|
112
|
-
* registerBetterAuthMongooseModels(mongoose);
|
|
113
|
-
*
|
|
114
|
-
* // Core + organization plugin
|
|
115
|
-
* registerBetterAuthMongooseModels(mongoose, { plugins: ['organization'] });
|
|
116
|
-
*
|
|
117
|
-
* // Core + organization with teams + MCP server
|
|
118
|
-
* registerBetterAuthMongooseModels(mongoose, {
|
|
119
|
-
* plugins: ['organization', 'organization-teams', 'mcp'],
|
|
120
|
-
* });
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
plugins?: BetterAuthPluginKey[];
|
|
124
|
-
/**
|
|
125
|
-
* Whether Better Auth's mongo adapter was configured with `usePlural: true`.
|
|
126
|
-
* When true, model names and collection names are pluralized
|
|
127
|
-
* (`user` → `users`, `organization` → `organizations`, etc).
|
|
128
|
-
*
|
|
129
|
-
* **Must match** the `usePlural` value passed to `mongodbAdapter()`.
|
|
130
|
-
*
|
|
131
|
-
* @default false
|
|
132
|
-
*/
|
|
133
|
-
usePlural?: boolean;
|
|
134
|
-
/**
|
|
135
|
-
* Override the model name for specific Better Auth collections.
|
|
136
|
-
* Use this when you've passed `user: { modelName: 'profiles' }` (or similar)
|
|
137
|
-
* to `betterAuth()` — pass the same map here so populate names line up.
|
|
138
|
-
*
|
|
139
|
-
* Keys are the canonical BA names (`user`, `session`, etc.); values are
|
|
140
|
-
* the model name to register with Mongoose. The collection name is also
|
|
141
|
-
* set to the override value.
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```ts
|
|
145
|
-
* registerBetterAuthMongooseModels(mongoose, {
|
|
146
|
-
* modelOverrides: { user: 'profile', member: 'orgMember' },
|
|
147
|
-
* });
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
modelOverrides?: Partial<Record<string, string>>;
|
|
151
|
-
/**
|
|
152
|
-
* Additional collection names to register beyond the built-in plugin set.
|
|
153
|
-
*
|
|
154
|
-
* **Use this for plugins that ship as separate `@better-auth/*` packages**
|
|
155
|
-
* (they're intentionally not hardcoded in `BetterAuthPluginKey` because
|
|
156
|
-
* their collection names live in their own packages and can evolve
|
|
157
|
-
* independently of the core `better-auth` release cycle).
|
|
158
|
-
*
|
|
159
|
-
* Known collection names for official separate-package plugins:
|
|
160
|
-
* - `@better-auth/passkey` → `'passkey'`
|
|
161
|
-
* - `@better-auth/sso` → `'ssoProvider'`
|
|
162
|
-
* - `@better-auth/oauth-provider` → already covered by `plugins: ['oauthProvider']`
|
|
163
|
-
* (same schema as the in-core `oidcProvider`)
|
|
164
|
-
* - `@better-auth/api-key` → consult the plugin's docs for the current
|
|
165
|
-
* model name; it's one collection
|
|
166
|
-
*
|
|
167
|
-
* For your own custom Better Auth plugins, pass whatever collection names
|
|
168
|
-
* they write to.
|
|
169
|
-
*
|
|
170
|
-
* @default []
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* registerBetterAuthMongooseModels(mongoose, {
|
|
174
|
-
* plugins: ['organization'],
|
|
175
|
-
* extraCollections: ['passkey', 'ssoProvider'],
|
|
176
|
-
* });
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
179
|
-
extraCollections?: string[];
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Register stub Mongoose models for Better Auth's collections so that
|
|
183
|
-
* Mongoose-based arc resources can `.populate()` references to BA-owned
|
|
184
|
-
* documents. Idempotent — safe to call multiple times.
|
|
185
|
-
*
|
|
186
|
-
* Returns the list of model names that were newly registered (excluding
|
|
187
|
-
* any that already existed on `mongoose.models`).
|
|
188
|
-
*/
|
|
189
|
-
declare function registerBetterAuthMongooseModels(mongoose: MongooseLike, options?: RegisterBetterAuthMongooseModelsOptions): string[];
|
|
190
|
-
//#endregion
|
|
191
|
-
export { BetterAuthPluginKey, MongooseLike, RegisterBetterAuthMongooseModelsOptions, registerBetterAuthMongooseModels };
|
package/dist/auth/mongoose.mjs
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
//#region src/auth/mongoose.ts
|
|
2
|
-
const COLLECTIONS_BY_PLUGIN = {
|
|
3
|
-
core: [
|
|
4
|
-
"user",
|
|
5
|
-
"session",
|
|
6
|
-
"account",
|
|
7
|
-
"verification"
|
|
8
|
-
],
|
|
9
|
-
organization: [
|
|
10
|
-
"organization",
|
|
11
|
-
"member",
|
|
12
|
-
"invitation"
|
|
13
|
-
],
|
|
14
|
-
"organization-teams": ["team", "teamMember"],
|
|
15
|
-
twoFactor: ["twoFactor"],
|
|
16
|
-
jwt: ["jwks"],
|
|
17
|
-
oidcProvider: [
|
|
18
|
-
"oauthApplication",
|
|
19
|
-
"oauthAccessToken",
|
|
20
|
-
"oauthConsent"
|
|
21
|
-
],
|
|
22
|
-
oauthProvider: [
|
|
23
|
-
"oauthApplication",
|
|
24
|
-
"oauthAccessToken",
|
|
25
|
-
"oauthConsent"
|
|
26
|
-
],
|
|
27
|
-
mcp: [
|
|
28
|
-
"oauthApplication",
|
|
29
|
-
"oauthAccessToken",
|
|
30
|
-
"oauthConsent"
|
|
31
|
-
],
|
|
32
|
-
deviceAuthorization: ["deviceCode"]
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Naive English pluralization that matches Better Auth's `usePlural` behavior.
|
|
36
|
-
* BA's mongo adapter just appends `s` (it doesn't handle irregular nouns —
|
|
37
|
-
* none of its collection names are irregular). We mirror that exactly.
|
|
38
|
-
*/
|
|
39
|
-
function pluralize(name) {
|
|
40
|
-
return name.endsWith("s") ? name : `${name}s`;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Register stub Mongoose models for Better Auth's collections so that
|
|
44
|
-
* Mongoose-based arc resources can `.populate()` references to BA-owned
|
|
45
|
-
* documents. Idempotent — safe to call multiple times.
|
|
46
|
-
*
|
|
47
|
-
* Returns the list of model names that were newly registered (excluding
|
|
48
|
-
* any that already existed on `mongoose.models`).
|
|
49
|
-
*/
|
|
50
|
-
function registerBetterAuthMongooseModels(mongoose, options = {}) {
|
|
51
|
-
const { plugins = [], usePlural = false, modelOverrides = {}, extraCollections = [] } = options;
|
|
52
|
-
const pluginSet = new Set(["core", ...plugins]);
|
|
53
|
-
const collected = [];
|
|
54
|
-
for (const key of pluginSet) for (const name of COLLECTIONS_BY_PLUGIN[key]) collected.push(name);
|
|
55
|
-
for (const name of extraCollections) collected.push(name);
|
|
56
|
-
const seen = /* @__PURE__ */ new Set();
|
|
57
|
-
const unique = collected.filter((n) => seen.has(n) ? false : (seen.add(n), true));
|
|
58
|
-
const registered = [];
|
|
59
|
-
for (const canonical of unique) {
|
|
60
|
-
const finalName = modelOverrides[canonical] ?? (usePlural ? pluralize(canonical) : canonical);
|
|
61
|
-
if (mongoose.models[finalName]) continue;
|
|
62
|
-
const schema = new mongoose.Schema({}, {
|
|
63
|
-
strict: false,
|
|
64
|
-
collection: finalName,
|
|
65
|
-
_id: false
|
|
66
|
-
});
|
|
67
|
-
mongoose.model(finalName, schema);
|
|
68
|
-
registered.push(finalName);
|
|
69
|
-
}
|
|
70
|
-
return registered;
|
|
71
|
-
}
|
|
72
|
-
//#endregion
|
|
73
|
-
export { registerBetterAuthMongooseModels };
|