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.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -34
  3. package/dist/index.d.ts +23 -28
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +9 -120
  6. package/dist/index.types.d.ts +15 -0
  7. package/dist/index.types.d.ts.map +1 -0
  8. package/dist/index.types.js +1 -0
  9. package/dist/next.d.ts +3 -0
  10. package/dist/next.d.ts.map +1 -0
  11. package/dist/next.js +7 -0
  12. package/dist/paths.d.ts +3 -0
  13. package/dist/paths.d.ts.map +1 -0
  14. package/dist/paths.js +2 -0
  15. package/dist/plugin-api.d.ts +3 -0
  16. package/dist/plugin-api.d.ts.map +1 -0
  17. package/dist/plugin-api.js +5 -0
  18. package/dist/react-types.d.ts +30 -0
  19. package/dist/react-types.d.ts.map +1 -0
  20. package/dist/react-types.js +1 -0
  21. package/dist/react.d.ts +9 -0
  22. package/dist/react.d.ts.map +1 -0
  23. package/dist/react.js +15 -0
  24. package/dist/runtime-types.d.ts +20 -0
  25. package/dist/runtime-types.d.ts.map +1 -0
  26. package/dist/runtime-types.js +1 -0
  27. package/dist/runtime.d.ts +11 -0
  28. package/dist/runtime.d.ts.map +1 -0
  29. package/dist/runtime.js +169 -0
  30. package/dist/types.d.ts +298 -0
  31. package/dist/types.d.ts.map +1 -0
  32. package/dist/types.js +1 -0
  33. package/package.json +69 -56
  34. package/.turbo/turbo-build.log +0 -4
  35. package/.turbo/turbo-lint.log +0 -19
  36. package/.turbo/turbo-type-check.log +0 -4
  37. package/dist/cache.d.ts +0 -16
  38. package/dist/cache.d.ts.map +0 -1
  39. package/dist/cache.js +0 -59
  40. package/dist/cache.js.map +0 -1
  41. package/dist/client.d.ts +0 -816
  42. package/dist/client.d.ts.map +0 -1
  43. package/dist/client.js +0 -23
  44. package/dist/client.js.map +0 -1
  45. package/dist/config/define.d.ts +0 -29
  46. package/dist/config/define.d.ts.map +0 -1
  47. package/dist/config/define.js +0 -13
  48. package/dist/config/define.js.map +0 -1
  49. package/dist/config/index.d.ts +0 -7
  50. package/dist/config/index.d.ts.map +0 -1
  51. package/dist/config/index.js +0 -4
  52. package/dist/config/index.js.map +0 -1
  53. package/dist/config/page.d.ts +0 -30
  54. package/dist/config/page.d.ts.map +0 -1
  55. package/dist/config/page.js +0 -22
  56. package/dist/config/page.js.map +0 -1
  57. package/dist/config/plugin.d.ts +0 -10
  58. package/dist/config/plugin.d.ts.map +0 -1
  59. package/dist/config/plugin.js +0 -10
  60. package/dist/config/plugin.js.map +0 -1
  61. package/dist/index.js.map +0 -1
  62. package/dist/lib/admin.d.ts +0 -33
  63. package/dist/lib/admin.d.ts.map +0 -1
  64. package/dist/lib/admin.js +0 -69
  65. package/dist/lib/admin.js.map +0 -1
  66. package/dist/lib/validation.d.ts +0 -32
  67. package/dist/lib/validation.d.ts.map +0 -1
  68. package/dist/lib/validation.js +0 -80
  69. package/dist/lib/validation.js.map +0 -1
  70. package/dist/server.d.ts +0 -9
  71. package/dist/server.d.ts.map +0 -1
  72. package/dist/server.js +0 -21
  73. package/dist/server.js.map +0 -1
  74. package/src/cache.ts +0 -81
  75. package/src/client.ts +0 -30
  76. package/src/config/define.ts +0 -43
  77. package/src/config/index.ts +0 -6
  78. package/src/config/page.ts +0 -54
  79. package/src/config/plugin.ts +0 -21
  80. package/src/index.ts +0 -160
  81. package/src/server.ts +0 -30
  82. package/tsconfig.json +0 -12
@@ -1,6 +0,0 @@
1
- export { defineConfig } from "./define.js";
2
- export type { Config, InternalConfig } from "./define.js";
3
- export { plugin } from "./plugin.js";
4
- export type { Plugin } from "./plugin.js";
5
- export { page, section } from "./page.js";
6
- export type { Page, Section, PageTree } from "./page.js";
@@ -1,54 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import type { LucideIcon } from "lucide-react";
3
-
4
- export type Page = {
5
- type: "page";
6
- name: string;
7
- slug: string;
8
- icon?: LucideIcon;
9
- content: ReactNode | null;
10
- };
11
-
12
- export type Section = {
13
- type: "section";
14
- name: string;
15
- slug: string;
16
- bottom?: boolean;
17
- children: PageTree[];
18
- };
19
-
20
- export type PageTree = Page | Section;
21
-
22
- function toSlug(name: string): string {
23
- return name.toLowerCase().replace(/\s+/g, "-");
24
- }
25
-
26
- export function page(config: {
27
- name: string;
28
- slug?: string;
29
- icon?: LucideIcon;
30
- content: ReactNode | null;
31
- }): Page {
32
- return {
33
- type: "page",
34
- name: config.name,
35
- slug: config.slug ?? toSlug(config.name),
36
- icon: config.icon,
37
- content: config.content,
38
- };
39
- }
40
-
41
- export function section(config: {
42
- name: string;
43
- slug?: string;
44
- bottom?: boolean;
45
- children: PageTree[];
46
- }): Section {
47
- return {
48
- type: "section",
49
- name: config.name,
50
- slug: config.slug ?? toSlug(config.name),
51
- bottom: config.bottom,
52
- children: config.children,
53
- };
54
- }
@@ -1,21 +0,0 @@
1
- import { type ZodSchema } from "zod";
2
-
3
- export type Plugin = {
4
- name: string;
5
- };
6
-
7
- export type PluginConfig<TParams = never> = {
8
- name: string;
9
- schema?: ZodSchema<TParams>;
10
- };
11
-
12
- export function plugin<TParams = never>(
13
- config: PluginConfig<TParams>
14
- ): (params: TParams) => Plugin {
15
- return (params) => {
16
- if (config.schema) {
17
- config.schema.parse(params);
18
- }
19
- return { name: config.name };
20
- };
21
- }
package/src/index.ts DELETED
@@ -1,160 +0,0 @@
1
- // @deessejs/deesse core package
2
-
3
- import type { InternalConfig } from "./config/define.js";
4
- import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
5
- import { createDeesse, type Deesse } from "./server.js";
6
-
7
- export { defineConfig } from "./config/index.js";
8
- export type { Config, InternalConfig } from "./config/index.js";
9
- export { plugin } from "./config/index.js";
10
- export type { Plugin } from "./config/index.js";
11
- export { page, section } from "./config/index.js";
12
- export type { Page, Section, PageTree } from "./config/index.js";
13
-
14
- export { z } from "zod";
15
- export type { ZodSchema } from "zod";
16
-
17
- export type { Deesse } from "./server.js";
18
-
19
- export { createClient } from "./client.js";
20
- export type { DeesseClientOptions } from "./client.js";
21
-
22
- /**
23
- * Symbol-based global storage for Deesse instance.
24
- * Using Symbol.for ensures uniqueness across the process.
25
- */
26
- const DEESSE_GLOBAL_KEY = Symbol.for("@deessejs/core.instance");
27
-
28
- interface GlobalDeesseCache {
29
- instance: Deesse | undefined;
30
- config: InternalConfig | undefined;
31
- pool: unknown | undefined;
32
- }
33
-
34
- function getGlobalCache(): GlobalDeesseCache {
35
- const g = global as typeof global & {
36
- [DEESSE_GLOBAL_KEY]?: GlobalDeesseCache;
37
- };
38
- if (!g[DEESSE_GLOBAL_KEY]) {
39
- g[DEESSE_GLOBAL_KEY] = {
40
- instance: undefined,
41
- config: undefined,
42
- pool: undefined,
43
- };
44
- }
45
- return g[DEESSE_GLOBAL_KEY]!;
46
- }
47
-
48
- /**
49
- * Deep equality check for config comparison.
50
- * Required because config objects are recreated on HMR.
51
- * Note: We do NOT compare database pools - the pool reference from $client
52
- * may return new wrapper objects on each access, causing false positives.
53
- */
54
- function isConfigEqual(a: InternalConfig, b: InternalConfig): boolean {
55
- if (a.secret !== b.secret) return false;
56
- if (a.name !== b.name) return false;
57
- if (a.auth.baseURL !== b.auth.baseURL) return false;
58
- return true;
59
- }
60
-
61
- /**
62
- * Extract pool reference from database.
63
- * For pg Pool passed to drizzle-orm/node-postgres, the pool is stored in $client.
64
- */
65
- function extractPool(db: PostgresJsDatabase): unknown {
66
- return (db as unknown as { $client?: unknown }).$client;
67
- }
68
-
69
- /**
70
- * Get the Deesse singleton instance.
71
- * Cached on global to persist across HMR.
72
- */
73
- export const getDeesse = async (
74
- config: InternalConfig
75
- ): Promise<Deesse> => {
76
- const cache = getGlobalCache();
77
-
78
- // Case 1: Instance exists and config is semantically equal
79
- if (cache.instance && cache.config && isConfigEqual(cache.config, config)) {
80
- return cache.instance;
81
- }
82
-
83
- // Case 2: Instance exists but config changed - hot reload
84
- if (
85
- cache.instance &&
86
- cache.config &&
87
- !isConfigEqual(cache.config, config)
88
- ) {
89
- console.info("[deesse] Config changed, performing hot reload...");
90
-
91
- // Close the old pool before creating new instance (with 5s timeout)
92
- if (cache.pool) {
93
- const oldPool = cache.pool as { end?: () => Promise<void> };
94
- if (typeof oldPool.end === "function") {
95
- await Promise.race([
96
- oldPool.end(),
97
- new Promise((resolve) => setTimeout(() => resolve(undefined), 5000)),
98
- ]).catch(console.error);
99
- }
100
- }
101
-
102
- // Create new instance with new config
103
- const instance = createDeesse(config);
104
- cache.pool = extractPool(instance.database);
105
- cache.instance = instance;
106
- cache.config = config;
107
-
108
- return instance;
109
- }
110
-
111
- // Case 3: No instance exists - create one
112
- const instance = createDeesse(config);
113
- cache.pool = extractPool(instance.database);
114
- cache.instance = instance;
115
- cache.config = config;
116
-
117
- return instance;
118
- };
119
-
120
- /**
121
- * Clear the Deesse singleton cache.
122
- * Primarily useful for testing.
123
- */
124
- export const clearDeesseCache = (): void => {
125
- const cache = getGlobalCache();
126
- cache.instance = undefined;
127
- cache.config = undefined;
128
- cache.pool = undefined;
129
- };
130
-
131
- /**
132
- * Graceful shutdown - call this on process exit.
133
- * Ensures all database connections are properly closed.
134
- */
135
- export const shutdownDeesse = async (): Promise<void> => {
136
- const cache = getGlobalCache();
137
-
138
- if (cache.pool) {
139
- console.info("[deesse] Closing database pool...");
140
- const pool = cache.pool as { end?: () => Promise<void> };
141
- if (pool && typeof pool.end === "function") {
142
- await pool.end();
143
- }
144
- cache.pool = undefined;
145
- }
146
-
147
- cache.instance = undefined;
148
- cache.config = undefined;
149
- };
150
-
151
- // Register graceful shutdown hooks
152
- if (process.env["NODE_ENV"] !== "test") {
153
- const shutdown = () => {
154
- shutdownDeesse()
155
- .catch(console.error)
156
- .finally(() => process.exit(0));
157
- };
158
- process.on("SIGINT", shutdown);
159
- process.on("SIGTERM", shutdown);
160
- }
package/src/server.ts DELETED
@@ -1,30 +0,0 @@
1
- import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
- import type { Auth } from "better-auth";
3
- import type { InternalConfig } from "./config/define";
4
- import { betterAuth } from "better-auth";
5
- import { drizzleAdapter } from "@better-auth/drizzle-adapter";
6
-
7
- export type Deesse = {
8
- auth: Auth;
9
- database: PostgresJsDatabase;
10
- };
11
-
12
- export function createDeesse(config: InternalConfig): Deesse {
13
- const auth = betterAuth({
14
- database: drizzleAdapter(config.database, {
15
- provider: "pg",
16
- }),
17
- baseURL: config.auth.baseURL,
18
- secret: config.secret,
19
- emailAndPassword: {
20
- enabled: true,
21
- },
22
- trustedOrigins: [config.auth.baseURL],
23
- plugins: config.auth.plugins,
24
- }) as Auth;
25
-
26
- return {
27
- auth,
28
- database: config.database,
29
- };
30
- }
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "composite": false,
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "outDir": "./dist",
8
- "rootDir": "./src"
9
- },
10
- "include": ["src/**/*"],
11
- "exclude": ["node_modules", "dist"]
12
- }