deesse 0.2.12 → 0.3.0
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/LICENSE +21 -0
- package/README.md +17 -34
- package/dist/index.d.ts +23 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -120
- package/dist/index.types.d.ts +15 -0
- package/dist/index.types.d.ts.map +1 -0
- package/dist/index.types.js +1 -0
- package/dist/next.d.ts +3 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +7 -0
- package/dist/paths.d.ts +3 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +2 -0
- package/dist/plugin-api.d.ts +3 -0
- package/dist/plugin-api.d.ts.map +1 -0
- package/dist/plugin-api.js +5 -0
- package/dist/react-types.d.ts +30 -0
- package/dist/react-types.d.ts.map +1 -0
- package/dist/react-types.js +1 -0
- package/dist/react.d.ts +9 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +15 -0
- package/dist/runtime-types.d.ts +20 -0
- package/dist/runtime-types.d.ts.map +1 -0
- package/dist/runtime-types.js +1 -0
- package/dist/runtime.d.ts +11 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +169 -0
- package/dist/types.d.ts +298 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +69 -56
- package/.turbo/turbo-build.log +0 -4
- package/.turbo/turbo-lint.log +0 -19
- package/.turbo/turbo-type-check.log +0 -4
- package/dist/cache.d.ts +0 -16
- package/dist/cache.d.ts.map +0 -1
- package/dist/cache.js +0 -59
- package/dist/cache.js.map +0 -1
- package/dist/client.d.ts +0 -816
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -23
- package/dist/client.js.map +0 -1
- package/dist/config/define.d.ts +0 -29
- package/dist/config/define.d.ts.map +0 -1
- package/dist/config/define.js +0 -13
- package/dist/config/define.js.map +0 -1
- package/dist/config/index.d.ts +0 -7
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -4
- package/dist/config/index.js.map +0 -1
- package/dist/config/page.d.ts +0 -30
- package/dist/config/page.d.ts.map +0 -1
- package/dist/config/page.js +0 -22
- package/dist/config/page.js.map +0 -1
- package/dist/config/plugin.d.ts +0 -10
- package/dist/config/plugin.d.ts.map +0 -1
- package/dist/config/plugin.js +0 -10
- package/dist/config/plugin.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/admin.d.ts +0 -33
- package/dist/lib/admin.d.ts.map +0 -1
- package/dist/lib/admin.js +0 -69
- package/dist/lib/admin.js.map +0 -1
- package/dist/lib/validation.d.ts +0 -32
- package/dist/lib/validation.d.ts.map +0 -1
- package/dist/lib/validation.js +0 -80
- package/dist/lib/validation.js.map +0 -1
- package/dist/server.d.ts +0 -9
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -21
- package/dist/server.js.map +0 -1
- package/src/cache.ts +0 -81
- package/src/client.ts +0 -30
- package/src/config/define.ts +0 -43
- package/src/config/index.ts +0 -6
- package/src/config/page.ts +0 -54
- package/src/config/plugin.ts +0 -21
- package/src/index.ts +0 -160
- package/src/server.ts +0 -30
- package/tsconfig.json +0 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Deessejs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,48 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# deesse
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DeesseJS core and its typed React client. This PR adds the first bounded PostgreSQL runtime slice. It is not a complete V1 framework implementation.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Executable runtime slice
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
npm install deesse
|
|
9
|
-
```
|
|
7
|
+
`createDeesse()` validates plugin IDs and dependency edges, orders root-level plugins, and invokes each handler once during composition. It creates Better Auth from the configured auth options and adapter, composes application and plugin routers, and exposes a Hono Fetch handler. Hono mounts Better Auth at `/api/auth/*` and oRPC at `/api/rpc/*`. Each RPC request resolves its Better Auth session and passes request headers, user, and session into the oRPC context. No migration or database write is performed during startup.
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
`deesse/next` exports `toNextJsHandler(instance)` as a Hono Vercel/Next host bridge. `deesse/react` creates a Better Auth React client and a router-derived oRPC client with the same `/api/auth` and `/api/rpc` paths. A client uses one explicit options object: `createClient({ server: deesseServer<typeof deesse>(), auth: { plugins: [...] } })`. `DeesseServer<typeof deesse>` projects only the composed oRPC router from the type-only server reference. The `server` field is separate from Better Auth's client options, and it is removed before Better Auth client construction. Apps without extra auth fields can omit `auth` entirely; they do not need `inferAdditionalFields`. Better Auth client plugins retain their own inferred methods and session/user types through the nested `auth.plugins` option. Use Better Auth helpers for genuinely configured extra auth fields, and pair custom auth endpoints with Better Auth client plugins carrying `$InferServerPlugin`. The compile-time fixtures assert exact oRPC procedure input/output types, the router-only server projection, and Better Auth plugin method/session types from the same client call.
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
import { defineConfig } from 'deesse';
|
|
15
|
-
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
16
|
-
import { Pool } from 'pg';
|
|
11
|
+
`createPluginApi(schema)` creates an oRPC builder whose request context uses the stable Deesse database service and standard request-scoped auth fields. The schema argument infers the plugin's model operations without rebuilding the context type in the host app.
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
database: drizzle({
|
|
20
|
-
client: new Pool({ connectionString: process.env.DATABASE_URL }),
|
|
21
|
-
schema,
|
|
22
|
-
}),
|
|
23
|
-
});
|
|
24
|
-
```
|
|
13
|
+
Runtime tests use Better Auth's in-memory adapter only as an isolated test double for composition and host behavior. The PostgreSQL adapter integration suite uses a real PostgreSQL URL, and proves the operations, transactions, auth persistence and session flow described below when run with the CI PostgreSQL service.
|
|
25
14
|
|
|
26
|
-
##
|
|
15
|
+
## Bounded database type contract
|
|
27
16
|
|
|
28
|
-
|
|
17
|
+
The revised RFC's V1 schema and service contract is represented in public types. `DeesseDatabaseSchema` models named models, typed fields, static defaults, nullability, uniqueness, and indexes. `DeesseModelRow` maps schema fields to row values and adds the generated string `id`. `DeesseDatabaseService` types `findById`, bounded `findMany` with equality and `in` filters plus ordering, `insert`, `updateById`, `deleteById`, and a transaction-scoped service without nested transactions. Results include the RFC's typed `NOT_FOUND` outcome and the declared conflict, unsupported-capability, and infrastructure categories. JSON fields accept JSON values only.
|
|
29
18
|
|
|
30
|
-
|
|
19
|
+
Plugin schema contributions are merged with the adapter schema in the inferred instance service type. The compile-time fixture exercises adapter-owned and plugin-owned models through that composed type, and rejects unknown models, fields, query values, invalid limits, and invalid writes. `DatabaseAdapter` pairs the portable service with Better Auth's official database-adapter option type. The portable service does not expose a provider client.
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
34
|
-
import { Pool } from 'pg';
|
|
21
|
+
`@deessejs/drizzle-adapter` implements the bounded PostgreSQL service using an app-owned postgres-js Drizzle client and derives Better Auth's official Drizzle adapter from that same client. It implements the declared CRUD/query and transaction behavior, and has a real PostgreSQL integration suite. The schema generator invokes plugin handlers and emits a Deesse-owned Drizzle schema without database access. In a consuming application, Better Auth's CLI remains authoritative for auth schema output, and the application runs its own Drizzle Kit migration workflow. Server startup performs schema registration only, never DDL.
|
|
35
22
|
|
|
36
|
-
|
|
37
|
-
client: new Pool({ connectionString: process.env.DATABASE_URL }),
|
|
38
|
-
schema,
|
|
39
|
-
});
|
|
23
|
+
The adapter's PostgreSQL schemas and migrations used by its integration tests are isolated under `apps/deesse-drizzle-adapter/tests/fixtures`. They do not participate in the monorepo product database schema or migrations. Applications own their postgres-js client and pool lifecycle and pass their configured Drizzle database to the adapter.
|
|
40
24
|
|
|
41
|
-
|
|
42
|
-
database: db,
|
|
43
|
-
});
|
|
44
|
-
```
|
|
25
|
+
## Type model boundaries
|
|
45
26
|
|
|
46
|
-
|
|
27
|
+
Compile-time assertions preserve `DeesseConfig` and direct `createDeesse({ database, auth, api, plugins })` inference, including optional API/plugins, Zod raw versus parsed args, no-config plugins, router input/output, Better Auth plugin types, the exact instance shape, and the standalone `DeessePluginContributionRegistry<TPlugins>`. The registry is type-only and is not a runtime registry or a property on `DeesseInstance`.
|
|
47
28
|
|
|
48
|
-
|
|
29
|
+
The oRPC request context type includes the stable database service, request, headers, user, and session; the runtime passes those request-scoped values. Plugin auth schema contributions are collected in the type-only contribution registry. Extension values are checked manually with `PluginExtension`; `requires` does not infer provider-to-consumer extension validation. Runtime dependency ordering and missing/cycle/duplicate checks are implemented, but schema conflict and provider extension compatibility checks are not. The app supplies Better Auth client plugins when it constructs the React client; they are not automatically derived from server contributions. The contribution registry remains type-only and is not exposed on `DeesseInstance`.
|
|
30
|
+
|
|
31
|
+
The package build emits declarations and typechecks a consumer fixture through the public `deesse`, `deesse/react`, and `deesse/next` exports. The database adapter integration requires a real PostgreSQL service and is exercised in CI. This slice supports postgres-js only, the bounded plugin-declared schema and operations above, and the current installed compatibility baseline. It does not implement general collections or relationship behavior, node-postgres or other dialects, admin, a production example application, or the rest of V1. Runtime detection of incompatible schemas is limited to registration and operation validation; migration review and application remain explicit operator steps.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Graceful shutdown - call this on process exit.
|
|
26
|
-
* Ensures all database connections are properly closed.
|
|
27
|
-
*/
|
|
28
|
-
export declare const shutdownDeesse: () => Promise<void>;
|
|
1
|
+
import type { AnyRouter, BetterAuthOptions, DeesseConfig, ZodInput, ZodType } from "./types.js";
|
|
2
|
+
import type { AnyPlugin, ApiRouter, BetterAuthInstance, ComposedBetterAuthOptions, DeesseDatabaseAdapterContract, DeesseInstance, PluginContribution } from "./types.js";
|
|
3
|
+
export { createPluginApi } from "./plugin-api.js";
|
|
4
|
+
import type { ConfiguredRegistration, Definition, NoArgsRegistration } from "./index.types.js";
|
|
5
|
+
export type { ApiRouter, BetterAuthInstance, BoundedLimit, BetterAuthServerInstance, CapabilitiesOf, ComposedBetterAuthOptions, ComposedDatabaseSchema, DatabaseAdapter, DeesseApiOptions, DeesseAuthAdapter, DeesseAuthSchema, DeesseBetterAuthOptions, DeesseConfig, DeesseDatabase, DeesseDatabaseAdapter, DeesseDatabaseAdapterContract, DeesseDatabaseCapabilities, DeesseDatabaseErrorCode, DeesseDatabaseErrorFields, DeesseDatabaseFailure, DeesseDatabaseOperations, DeesseDatabaseResult, DeesseDatabaseSchema, DeesseDatabaseService, DeesseFetchHandler, DeesseFieldDefinition, DeesseFieldType, DeesseFindManyOptions, DeesseIndexDefinition, DeesseInsert, DeesseInstance, DeesseJsonValue, DeesseModelDefinition, DeesseModelResult, DeesseModelRow, DeesseNotFound, DeessePatch, DeessePluginContributionRegistry, DeesseRequestContext, DeesseRequestUser, DeesseTransactionService, PluginContribution, PluginExtension } from "./types.js";
|
|
6
|
+
export type { ConfiguredRegistration, Definition, NoArgsRegistration } from "./index.types.js";
|
|
7
|
+
export declare function plugin<const TDefinition extends {
|
|
8
|
+
id: string;
|
|
9
|
+
args?: never;
|
|
10
|
+
requires?: readonly string[];
|
|
11
|
+
extensionPoints?: Readonly<Record<string, unknown>>;
|
|
12
|
+
handler: () => PluginContribution;
|
|
13
|
+
}>(definition: TDefinition): (() => NoArgsRegistration<TDefinition>) & {
|
|
14
|
+
definition: TDefinition;
|
|
15
|
+
};
|
|
16
|
+
export declare function plugin<const TId extends string, TSchema extends ZodType, TContribution extends PluginContribution, const TRequires extends readonly string[] = readonly [], const TPoints extends Readonly<Record<string, unknown>> = Readonly<Record<never, never>>>(definition: Definition<TSchema, TContribution, TRequires, TPoints> & {
|
|
17
|
+
id: TId;
|
|
18
|
+
}): ((args: ZodInput<TSchema>) => ConfiguredRegistration<typeof definition>) & {
|
|
19
|
+
definition: typeof definition;
|
|
20
|
+
};
|
|
21
|
+
export declare function createDeesse<TDatabase extends DeesseDatabaseAdapterContract, TAuth extends BetterAuthOptions, TApi extends {
|
|
22
|
+
router?: AnyRouter;
|
|
23
|
+
} = Record<never, never>, const TPlugins extends readonly AnyPlugin[] = readonly []>(options: DeesseConfig<TDatabase, TAuth, TApi, TPlugins>): DeesseInstance<TDatabase, BetterAuthInstance<ComposedBetterAuthOptions<TAuth, TPlugins>>, ApiRouter<TApi, TPlugins>, TPlugins>;
|
|
29
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,6BAA6B,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAExK,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAE9F,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,YAAY,EAAE,wBAAwB,EAAE,cAAc,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,eAAe,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,gCAAgC,EAAE,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6B,EAC/C,KAAK,SAAS,iBAAiB,EAC/B,IAAI,SAAS;IAAE,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAC1D,KAAK,CAAC,QAAQ,SAAS,SAAS,SAAS,EAAE,GAAG,SAAS,EAAE,EACzD,OAAO,EAAE,YAAY,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,cAAc,CACxE,SAAS,EAAE,kBAAkB,CAAC,yBAAyB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAC/G,CAOA"}
|
package/dist/index.js
CHANGED
|
@@ -1,122 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Symbol-based global storage for Deesse instance.
|
|
10
|
-
* Using Symbol.for ensures uniqueness across the process.
|
|
11
|
-
*/
|
|
12
|
-
const DEESSE_GLOBAL_KEY = Symbol.for("@deessejs/core.instance");
|
|
13
|
-
function getGlobalCache() {
|
|
14
|
-
const g = global;
|
|
15
|
-
if (!g[DEESSE_GLOBAL_KEY]) {
|
|
16
|
-
g[DEESSE_GLOBAL_KEY] = {
|
|
17
|
-
instance: undefined,
|
|
18
|
-
config: undefined,
|
|
19
|
-
pool: undefined,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return g[DEESSE_GLOBAL_KEY];
|
|
1
|
+
import { createRuntime } from "./runtime.js";
|
|
2
|
+
export { createPluginApi } from "./plugin-api.js";
|
|
3
|
+
export function plugin(definition) {
|
|
4
|
+
const factory = (args) => definition.args
|
|
5
|
+
? { id: definition.id, args, definition }
|
|
6
|
+
: { id: definition.id, definition };
|
|
7
|
+
return Object.assign(factory, { definition });
|
|
23
8
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* Required because config objects are recreated on HMR.
|
|
27
|
-
* Note: We do NOT compare database pools - the pool reference from $client
|
|
28
|
-
* may return new wrapper objects on each access, causing false positives.
|
|
29
|
-
*/
|
|
30
|
-
function isConfigEqual(a, b) {
|
|
31
|
-
if (a.secret !== b.secret)
|
|
32
|
-
return false;
|
|
33
|
-
if (a.name !== b.name)
|
|
34
|
-
return false;
|
|
35
|
-
if (a.auth.baseURL !== b.auth.baseURL)
|
|
36
|
-
return false;
|
|
37
|
-
return true;
|
|
9
|
+
export function createDeesse(options) {
|
|
10
|
+
return createRuntime(options);
|
|
38
11
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Extract pool reference from database.
|
|
41
|
-
* For pg Pool passed to drizzle-orm/node-postgres, the pool is stored in $client.
|
|
42
|
-
*/
|
|
43
|
-
function extractPool(db) {
|
|
44
|
-
return db.$client;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Get the Deesse singleton instance.
|
|
48
|
-
* Cached on global to persist across HMR.
|
|
49
|
-
*/
|
|
50
|
-
export const getDeesse = async (config) => {
|
|
51
|
-
const cache = getGlobalCache();
|
|
52
|
-
// Case 1: Instance exists and config is semantically equal
|
|
53
|
-
if (cache.instance && cache.config && isConfigEqual(cache.config, config)) {
|
|
54
|
-
return cache.instance;
|
|
55
|
-
}
|
|
56
|
-
// Case 2: Instance exists but config changed - hot reload
|
|
57
|
-
if (cache.instance &&
|
|
58
|
-
cache.config &&
|
|
59
|
-
!isConfigEqual(cache.config, config)) {
|
|
60
|
-
console.info("[deesse] Config changed, performing hot reload...");
|
|
61
|
-
// Close the old pool before creating new instance (with 5s timeout)
|
|
62
|
-
if (cache.pool) {
|
|
63
|
-
const oldPool = cache.pool;
|
|
64
|
-
if (typeof oldPool.end === "function") {
|
|
65
|
-
await Promise.race([
|
|
66
|
-
oldPool.end(),
|
|
67
|
-
new Promise((resolve) => setTimeout(() => resolve(undefined), 5000)),
|
|
68
|
-
]).catch(console.error);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// Create new instance with new config
|
|
72
|
-
const instance = createDeesse(config);
|
|
73
|
-
cache.pool = extractPool(instance.database);
|
|
74
|
-
cache.instance = instance;
|
|
75
|
-
cache.config = config;
|
|
76
|
-
return instance;
|
|
77
|
-
}
|
|
78
|
-
// Case 3: No instance exists - create one
|
|
79
|
-
const instance = createDeesse(config);
|
|
80
|
-
cache.pool = extractPool(instance.database);
|
|
81
|
-
cache.instance = instance;
|
|
82
|
-
cache.config = config;
|
|
83
|
-
return instance;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Clear the Deesse singleton cache.
|
|
87
|
-
* Primarily useful for testing.
|
|
88
|
-
*/
|
|
89
|
-
export const clearDeesseCache = () => {
|
|
90
|
-
const cache = getGlobalCache();
|
|
91
|
-
cache.instance = undefined;
|
|
92
|
-
cache.config = undefined;
|
|
93
|
-
cache.pool = undefined;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Graceful shutdown - call this on process exit.
|
|
97
|
-
* Ensures all database connections are properly closed.
|
|
98
|
-
*/
|
|
99
|
-
export const shutdownDeesse = async () => {
|
|
100
|
-
const cache = getGlobalCache();
|
|
101
|
-
if (cache.pool) {
|
|
102
|
-
console.info("[deesse] Closing database pool...");
|
|
103
|
-
const pool = cache.pool;
|
|
104
|
-
if (pool && typeof pool.end === "function") {
|
|
105
|
-
await pool.end();
|
|
106
|
-
}
|
|
107
|
-
cache.pool = undefined;
|
|
108
|
-
}
|
|
109
|
-
cache.instance = undefined;
|
|
110
|
-
cache.config = undefined;
|
|
111
|
-
};
|
|
112
|
-
// Register graceful shutdown hooks
|
|
113
|
-
if (process.env["NODE_ENV"] !== "test") {
|
|
114
|
-
const shutdown = () => {
|
|
115
|
-
shutdownDeesse()
|
|
116
|
-
.catch(console.error)
|
|
117
|
-
.finally(() => process.exit(0));
|
|
118
|
-
};
|
|
119
|
-
process.on("SIGINT", shutdown);
|
|
120
|
-
process.on("SIGTERM", shutdown);
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PluginContribution, PluginDefinition, PluginRegistration, ZodType } from "./types.js";
|
|
2
|
+
export type Definition<TSchema extends ZodType, TContribution extends PluginContribution, TRequires extends readonly string[], TPoints extends Readonly<Record<string, unknown>>> = PluginDefinition<TSchema, TContribution, TRequires, TPoints>;
|
|
3
|
+
export type NoArgsRegistration<TDefinition extends {
|
|
4
|
+
id: string;
|
|
5
|
+
handler: () => PluginContribution;
|
|
6
|
+
}> = {
|
|
7
|
+
id: TDefinition["id"];
|
|
8
|
+
definition: TDefinition;
|
|
9
|
+
};
|
|
10
|
+
export type ConfiguredRegistration<TDefinition extends {
|
|
11
|
+
id: string;
|
|
12
|
+
args: ZodType;
|
|
13
|
+
handler: (...args: never[]) => unknown;
|
|
14
|
+
}> = PluginRegistration<TDefinition>;
|
|
15
|
+
//# sourceMappingURL=index.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.types.d.ts","sourceRoot":"","sources":["../src/index.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEnG,MAAM,MAAM,UAAU,CACpB,OAAO,SAAS,OAAO,EACvB,aAAa,SAAS,kBAAkB,EACxC,SAAS,SAAS,SAAS,MAAM,EAAE,EACnC,OAAO,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,IAC/C,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;AAEhE,MAAM,MAAM,kBAAkB,CAAC,WAAW,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,kBAAkB,CAAA;CAAE,IAAI;IACtG,EAAE,EAAE,WAAW,CAAC,IAAI,CAAC,CAAA;IACrB,UAAU,EAAE,WAAW,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,sBAAsB,CAAC,WAAW,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAA;CAAE,IAAI,kBAAkB,CAAC,WAAW,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../src/next.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEpD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,UAAU,kDAInD"}
|
package/dist/next.js
ADDED
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,cAAc,CAAA;AAC3C,eAAO,MAAM,eAAe,aAAa,CAAA"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { DeesseDatabaseSchema, DeesseRequestContext } from "./types.js";
|
|
2
|
+
export declare function createPluginApi<TSchema extends DeesseDatabaseSchema>(schema: TSchema): import("@orpc/server").Builder<DeesseRequestContext<TSchema> & Record<never, never>, DeesseRequestContext<TSchema>, import("@orpc/server").Schema<unknown, unknown>, import("@orpc/server").Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
3
|
+
//# sourceMappingURL=plugin-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-api.d.ts","sourceRoot":"","sources":["../src/plugin-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAE5E,wBAAgB,eAAe,CAAC,OAAO,SAAS,oBAAoB,EAAE,MAAM,EAAE,OAAO,qQAGpF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AnyRouter } from "@orpc/server";
|
|
2
|
+
import type { BetterAuthClientOptions } from "better-auth/client";
|
|
3
|
+
type DeesseServerSource = {
|
|
4
|
+
readonly api: {
|
|
5
|
+
readonly router: AnyRouter;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export type DeesseServer<TServer extends DeesseServerSource = DeesseServerSource> = {
|
|
9
|
+
readonly api: {
|
|
10
|
+
readonly router: TServer["api"]["router"];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
declare const serverTypeReference: unique symbol;
|
|
14
|
+
export type DeesseServerReference<TServer extends DeesseServer> = {
|
|
15
|
+
readonly [serverTypeReference]: TServer;
|
|
16
|
+
};
|
|
17
|
+
export type DeesseClientOptions = {
|
|
18
|
+
server: DeesseServerReference<DeesseServer>;
|
|
19
|
+
auth?: BetterAuthClientOptions;
|
|
20
|
+
baseURL?: string;
|
|
21
|
+
fetch?: typeof globalThis.fetch;
|
|
22
|
+
};
|
|
23
|
+
type ServerFromOptions<TOptions extends DeesseClientOptions> = TOptions["server"] extends DeesseServerReference<infer TServer> ? TServer : DeesseServer;
|
|
24
|
+
type AuthOptionsFromOptions<TOptions extends DeesseClientOptions> = TOptions extends {
|
|
25
|
+
readonly auth: infer TAuthOptions extends BetterAuthClientOptions;
|
|
26
|
+
} ? TAuthOptions : BetterAuthClientOptions;
|
|
27
|
+
export type DeesseClientAuth<TOptions extends DeesseClientOptions> = AuthOptionsFromOptions<TOptions>;
|
|
28
|
+
export type DeesseClientRouter<TOptions extends DeesseClientOptions> = ServerFromOptions<TOptions>["api"]["router"];
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=react-types.d.ts.map
|
|
@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AClE,GAAG,YAAY,GAAG,uBAAuB,CAAA;AAE1C,MAAM,MAAM,gBAAgB,CAAC,QAAQ,SAAS,mBAAmB,IAAI,sBAAsB,CAAC,QAAQ,CAAC,CAAA;AAErG,MAAM,MAAM,kBAAkB,CAAC,QAAQ,SAAS,mBAAmB,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RouterClient } from "@orpc/server";
|
|
2
|
+
import type { DeesseClientAuth, DeesseClientOptions, DeesseClientRouter, DeesseServer, DeesseServerReference } from "./react-types.js";
|
|
3
|
+
export type { DeesseClientOptions, DeesseServer } from "./react-types.js";
|
|
4
|
+
export declare function deesseServer<TServer extends DeesseServer>(): DeesseServerReference<DeesseServer<TServer>>;
|
|
5
|
+
export declare function createClient<const TOptions extends DeesseClientOptions>(options: TOptions): {
|
|
6
|
+
auth: import("better-auth/react").ReactAuthClient<DeesseClientAuth<TOptions>>;
|
|
7
|
+
api: RouterClient<DeesseClientRouter<TOptions>>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAEtI,YAAY,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEzE,wBAAgB,YAAY,CAAC,OAAO,SAAS,YAAY,KAAK,qBAAqB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAEzG;AAED,wBAAgB,YAAY,CAAC,KAAK,CAAC,QAAQ,SAAS,mBAAmB,EAAE,OAAO,EAAE,QAAQ;;SAM1C,YAAY,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;EACzF"}
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createAuthClient } from "better-auth/react";
|
|
2
|
+
import { createORPCClient } from "@orpc/client";
|
|
3
|
+
import { RPCLink } from "@orpc/client/fetch";
|
|
4
|
+
import { DEESSE_RPC_PATH } from "./paths.js";
|
|
5
|
+
export function deesseServer() {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
export function createClient(options) {
|
|
9
|
+
const location = globalThis.location;
|
|
10
|
+
const baseURL = options.baseURL ?? location?.origin ?? "http://localhost";
|
|
11
|
+
const authOptions = { ...options.auth, baseURL, ...(options.fetch ? { fetch: options.fetch } : {}) };
|
|
12
|
+
const auth = createAuthClient(authOptions);
|
|
13
|
+
const link = new RPCLink({ url: new URL(DEESSE_RPC_PATH, baseURL).toString(), ...(options.fetch ? { fetch: options.fetch } : {}) });
|
|
14
|
+
return { auth, api: createORPCClient(link) };
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BetterAuthOptions, DatabaseAdapter, DeesseApiOptions, PluginContribution, ZodType } from "./types.js";
|
|
2
|
+
export type RuntimePlugin = {
|
|
3
|
+
id: string;
|
|
4
|
+
args?: unknown;
|
|
5
|
+
definition: {
|
|
6
|
+
args?: ZodType;
|
|
7
|
+
requires?: readonly string[];
|
|
8
|
+
handler: ((args: never) => PluginContribution) | (() => PluginContribution);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type RuntimeOptions = {
|
|
12
|
+
database: DatabaseAdapter;
|
|
13
|
+
auth: BetterAuthOptions;
|
|
14
|
+
api?: DeesseApiOptions;
|
|
15
|
+
plugins?: readonly RuntimePlugin[];
|
|
16
|
+
};
|
|
17
|
+
export type DeesseHost = {
|
|
18
|
+
readonly handler: (request: Request) => Promise<Response>;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=runtime-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-types.d.ts","sourceRoot":"","sources":["../src/runtime-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEnH,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,UAAU,EAAE;QACV,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;QAC5B,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,KAAK,kBAAkB,CAAC,GAAG,CAAC,MAAM,kBAAkB,CAAC,CAAA;KAC5E,CAAA;CACF,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,eAAe,CAAA;IACzB,IAAI,EAAE,iBAAiB,CAAA;IACvB,GAAG,CAAC,EAAE,gBAAgB,CAAA;IACtB,OAAO,CAAC,EAAE,SAAS,aAAa,EAAE,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnyRouter, DeesseFetchHandler } from "./types.js";
|
|
2
|
+
import type { RuntimeOptions } from "./runtime-types.js";
|
|
3
|
+
export declare function createRuntime(options: RuntimeOptions): {
|
|
4
|
+
database: RuntimeOptions["database"]["database"];
|
|
5
|
+
auth: unknown;
|
|
6
|
+
api: {
|
|
7
|
+
router: AnyRouter;
|
|
8
|
+
};
|
|
9
|
+
handler: DeesseFetchHandler;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAwB,kBAAkB,EAAoE,MAAM,YAAY,CAAA;AACvJ,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,oBAAoB,CAAA;AAkHvE,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG;IACtD,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,CAAA;IAChD,IAAI,EAAE,OAAO,CAAA;IACb,GAAG,EAAE;QAAE,MAAM,EAAE,SAAS,CAAA;KAAE,CAAA;IAC1B,OAAO,EAAE,kBAAkB,CAAA;CAC5B,CAuCA"}
|