@sonicjs-cms/core 2.2.0 → 2.3.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.
Files changed (105) hide show
  1. package/README.md +75 -1
  2. package/dist/app-Db0AfT5F.d.cts +100 -0
  3. package/dist/app-Db0AfT5F.d.ts +100 -0
  4. package/dist/chunk-23VPL6VI.cjs +1828 -0
  5. package/dist/chunk-23VPL6VI.cjs.map +1 -0
  6. package/dist/chunk-3MPQII4R.js +1826 -0
  7. package/dist/chunk-3MPQII4R.js.map +1 -0
  8. package/dist/{chunk-YTMFJLJZ.cjs → chunk-44LBCF3B.cjs} +5 -3
  9. package/dist/chunk-44LBCF3B.cjs.map +1 -0
  10. package/dist/{chunk-2DIWLDCA.cjs → chunk-5QJX2VMP.cjs} +541 -533
  11. package/dist/chunk-5QJX2VMP.cjs.map +1 -0
  12. package/dist/{chunk-UEYMFNBN.cjs → chunk-5UUYHAZT.cjs} +7 -36
  13. package/dist/chunk-5UUYHAZT.cjs.map +1 -0
  14. package/dist/{chunk-ZUK55KZB.js → chunk-6RJU7HL5.js} +5 -3
  15. package/dist/chunk-6RJU7HL5.js.map +1 -0
  16. package/dist/{chunk-K4Z3IHOK.js → chunk-7CXL5K7N.js} +5 -248
  17. package/dist/chunk-7CXL5K7N.js.map +1 -0
  18. package/dist/{chunk-WBX5YMTB.cjs → chunk-7KCDFDRI.cjs} +27 -15
  19. package/dist/chunk-7KCDFDRI.cjs.map +1 -0
  20. package/dist/{chunk-HKEK7UNV.js → chunk-CPXAVWCU.js} +3 -3
  21. package/dist/{chunk-HKEK7UNV.js.map → chunk-CPXAVWCU.js.map} +1 -1
  22. package/dist/{chunk-F5ESJXI2.cjs → chunk-DTLB6UIH.cjs} +3 -3
  23. package/dist/{chunk-F5ESJXI2.cjs.map → chunk-DTLB6UIH.cjs.map} +1 -1
  24. package/dist/{chunk-AINTFRTC.cjs → chunk-ES3BRZQJ.cjs} +252 -2
  25. package/dist/chunk-ES3BRZQJ.cjs.map +1 -0
  26. package/dist/{chunk-HV2I6API.cjs → chunk-NAYD76QF.cjs} +4 -251
  27. package/dist/chunk-NAYD76QF.cjs.map +1 -0
  28. package/dist/{chunk-L232U757.js → chunk-Q52ZQFMB.js} +249 -3
  29. package/dist/chunk-Q52ZQFMB.js.map +1 -0
  30. package/dist/{chunk-NMVOTNSL.js → chunk-RRKXFGIO.js} +28 -16
  31. package/dist/chunk-RRKXFGIO.js.map +1 -0
  32. package/dist/{chunk-OORGXYDA.js → chunk-WK5EUGBO.js} +5 -32
  33. package/dist/chunk-WK5EUGBO.js.map +1 -0
  34. package/dist/{chunk-R57VFNP3.js → chunk-ZPERJATF.js} +441 -433
  35. package/dist/chunk-ZPERJATF.js.map +1 -0
  36. package/dist/collection-config-FLlGtsh9.d.cts +107 -0
  37. package/dist/collection-config-FLlGtsh9.d.ts +107 -0
  38. package/dist/filter-bar.template-By4jeiw_.d.cts +140 -0
  39. package/dist/filter-bar.template-By4jeiw_.d.ts +140 -0
  40. package/dist/index.cjs +146 -165
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +44 -0
  43. package/dist/index.d.ts +43 -5
  44. package/dist/index.js +19 -14
  45. package/dist/index.js.map +1 -1
  46. package/dist/middleware.cjs +24 -33
  47. package/dist/middleware.d.cts +89 -0
  48. package/dist/middleware.d.ts +89 -2
  49. package/dist/middleware.js +3 -4
  50. package/dist/migrations-CCLAGJGP.js +4 -0
  51. package/dist/{migrations-IHERIQVD.js.map → migrations-CCLAGJGP.js.map} +1 -1
  52. package/dist/migrations-O6INOHRD.cjs +13 -0
  53. package/dist/{migrations-POFD5KNG.cjs.map → migrations-O6INOHRD.cjs.map} +1 -1
  54. package/dist/plugin-bootstrap-C0E3jdz-.d.cts +8339 -0
  55. package/dist/plugin-bootstrap-CDh0JHtW.d.ts +8339 -0
  56. package/dist/plugin-manifest-BCMx9CAq.d.cts +35 -0
  57. package/dist/plugin-manifest-BCMx9CAq.d.ts +35 -0
  58. package/dist/plugin-zvZpaiP5.d.cts +357 -0
  59. package/dist/plugin-zvZpaiP5.d.ts +357 -0
  60. package/dist/plugins.cjs +7 -7
  61. package/dist/plugins.d.cts +330 -0
  62. package/dist/plugins.d.ts +330 -2
  63. package/dist/plugins.js +1 -1
  64. package/dist/routes.cjs +27 -27
  65. package/dist/routes.d.cts +224 -0
  66. package/dist/routes.d.ts +224 -2
  67. package/dist/routes.js +7 -7
  68. package/dist/services.cjs +41 -41
  69. package/dist/services.d.cts +236 -0
  70. package/dist/services.d.ts +236 -2
  71. package/dist/services.js +4 -4
  72. package/dist/telemetry-BFBIjBxK.d.cts +36 -0
  73. package/dist/telemetry-BFBIjBxK.d.ts +36 -0
  74. package/dist/templates.d.cts +133 -0
  75. package/dist/templates.d.ts +133 -2
  76. package/dist/types.d.cts +7 -0
  77. package/dist/types.d.ts +7 -2
  78. package/dist/utils.cjs +27 -27
  79. package/dist/utils.d.cts +53 -0
  80. package/dist/utils.d.ts +53 -2
  81. package/dist/utils.js +2 -2
  82. package/dist/version-vktVAxhe.d.cts +195 -0
  83. package/dist/version-vktVAxhe.d.ts +195 -0
  84. package/migrations/001_initial_schema.sql +1 -1
  85. package/migrations/002_faq_plugin.sql +86 -0
  86. package/package.json +3 -1
  87. package/dist/chunk-2DIWLDCA.cjs.map +0 -1
  88. package/dist/chunk-AINTFRTC.cjs.map +0 -1
  89. package/dist/chunk-HV2I6API.cjs.map +0 -1
  90. package/dist/chunk-K4Z3IHOK.js.map +0 -1
  91. package/dist/chunk-L232U757.js.map +0 -1
  92. package/dist/chunk-NMVOTNSL.js.map +0 -1
  93. package/dist/chunk-OORGXYDA.js.map +0 -1
  94. package/dist/chunk-R57VFNP3.js.map +0 -1
  95. package/dist/chunk-T7IYBGGO.cjs +0 -746
  96. package/dist/chunk-T7IYBGGO.cjs.map +0 -1
  97. package/dist/chunk-UEYMFNBN.cjs.map +0 -1
  98. package/dist/chunk-WBX5YMTB.cjs.map +0 -1
  99. package/dist/chunk-YTMFJLJZ.cjs.map +0 -1
  100. package/dist/chunk-ZPMFT2JW.js +0 -744
  101. package/dist/chunk-ZPMFT2JW.js.map +0 -1
  102. package/dist/chunk-ZUK55KZB.js.map +0 -1
  103. package/dist/migrations-IHERIQVD.js +0 -4
  104. package/dist/migrations-POFD5KNG.cjs +0 -13
  105. /package/migrations/{021_add_otp_login.sql → 026_add_otp_login.sql} +0 -0
package/README.md CHANGED
@@ -319,6 +319,7 @@ await migrationService.runAllMigrations()
319
319
  ├── src/
320
320
  │ ├── app.ts # Application factory
321
321
  │ ├── db/ # Database schemas & utilities
322
+ │ │ └── migrations-bundle.ts # Auto-generated migration bundle
322
323
  │ ├── services/ # Business logic
323
324
  │ ├── middleware/ # Request processing
324
325
  │ ├── routes/ # HTTP handlers
@@ -326,10 +327,83 @@ await migrationService.runAllMigrations()
326
327
  │ ├── plugins/ # Plugin system & core plugins
327
328
  │ ├── types/ # TypeScript definitions
328
329
  │ └── utils/ # Utility functions
329
- ├── migrations/ # Core database migrations
330
+ ├── migrations/ # Core database migrations (.sql files)
331
+ ├── scripts/
332
+ │ └── generate-migrations.ts # Migration bundler script
330
333
  └── dist/ # Compiled output
331
334
  ```
332
335
 
336
+ ## 🔄 Development Workflow
337
+
338
+ ### Migration System
339
+
340
+ SonicJS uses a **build-time migration bundler** because Cloudflare Workers cannot access the filesystem at runtime. All migration SQL is bundled into TypeScript during the build process.
341
+
342
+ #### Creating New Migrations
343
+
344
+ 1. **Create the SQL file** in `migrations/`:
345
+ ```bash
346
+ # Use sequential three-digit numbering
347
+ touch migrations/027_add_your_feature.sql
348
+ ```
349
+
350
+ 2. **Write idempotent SQL**:
351
+ ```sql
352
+ -- migrations/027_add_your_feature.sql
353
+ CREATE TABLE IF NOT EXISTS your_table (
354
+ id TEXT PRIMARY KEY,
355
+ name TEXT NOT NULL
356
+ );
357
+
358
+ CREATE INDEX IF NOT EXISTS idx_your_table_name ON your_table(name);
359
+ ```
360
+
361
+ 3. **Regenerate the bundle**:
362
+ ```bash
363
+ npm run generate:migrations
364
+ # Or this runs automatically during: npm run build
365
+ ```
366
+
367
+ 4. **Build the package**:
368
+ ```bash
369
+ npm run build
370
+ ```
371
+
372
+ 5. **Apply to your test database**:
373
+ ```bash
374
+ cd ../my-sonicjs-app
375
+ wrangler d1 migrations apply DB --local
376
+ ```
377
+
378
+ #### Available Scripts
379
+
380
+ ```bash
381
+ # Generate migrations bundle only
382
+ npm run generate:migrations
383
+
384
+ # Build (automatically runs generate:migrations first)
385
+ npm run build
386
+
387
+ # Type check
388
+ npm run type-check
389
+
390
+ # Run tests
391
+ npm run test
392
+ ```
393
+
394
+ #### How It Works
395
+
396
+ ```
397
+ migrations/*.sql → scripts/generate-migrations.ts → src/db/migrations-bundle.ts → dist/
398
+ ```
399
+
400
+ The `generate-migrations.ts` script:
401
+ - Reads all `.sql` files from `migrations/`
402
+ - Generates `src/db/migrations-bundle.ts` with embedded SQL
403
+ - Provides `getMigrationSQLById()` for runtime access
404
+
405
+ **Important**: Always rebuild after modifying migration files. The `.sql` files are not used at runtime.
406
+
333
407
  ## 🔄 Versioning
334
408
 
335
409
  SonicJS follows semantic versioning:
@@ -0,0 +1,100 @@
1
+ import { Hono, Context } from 'hono';
2
+ import { D1Database, KVNamespace, R2Bucket } from '@cloudflare/workers-types';
3
+
4
+ /**
5
+ * Main Application Factory
6
+ *
7
+ * Creates a configured SonicJS application with all core functionality
8
+ */
9
+
10
+ interface Bindings {
11
+ DB: D1Database;
12
+ CACHE_KV: KVNamespace;
13
+ MEDIA_BUCKET: R2Bucket;
14
+ ASSETS: Fetcher;
15
+ EMAIL_QUEUE?: Queue;
16
+ SENDGRID_API_KEY?: string;
17
+ DEFAULT_FROM_EMAIL?: string;
18
+ IMAGES_ACCOUNT_ID?: string;
19
+ IMAGES_API_TOKEN?: string;
20
+ ENVIRONMENT?: string;
21
+ BUCKET_NAME?: string;
22
+ }
23
+ interface Variables {
24
+ user?: {
25
+ userId: string;
26
+ email: string;
27
+ role: string;
28
+ exp: number;
29
+ iat: number;
30
+ };
31
+ requestId?: string;
32
+ startTime?: number;
33
+ appVersion?: string;
34
+ }
35
+ interface SonicJSConfig {
36
+ collections?: {
37
+ directory?: string;
38
+ autoSync?: boolean;
39
+ };
40
+ plugins?: {
41
+ directory?: string;
42
+ autoLoad?: boolean;
43
+ disableAll?: boolean;
44
+ };
45
+ routes?: Array<{
46
+ path: string;
47
+ handler: Hono;
48
+ }>;
49
+ middleware?: {
50
+ beforeAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>;
51
+ afterAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>;
52
+ };
53
+ version?: string;
54
+ name?: string;
55
+ }
56
+ type SonicJSApp = Hono<{
57
+ Bindings: Bindings;
58
+ Variables: Variables;
59
+ }>;
60
+ /**
61
+ * Create a SonicJS application with core functionality
62
+ *
63
+ * @param config - Application configuration
64
+ * @returns Configured Hono application
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * import { createSonicJSApp } from '@sonicjs/core'
69
+ *
70
+ * const app = createSonicJSApp({
71
+ * collections: {
72
+ * directory: './src/collections',
73
+ * autoSync: true
74
+ * },
75
+ * plugins: {
76
+ * directory: './src/plugins',
77
+ * autoLoad: true
78
+ * }
79
+ * })
80
+ *
81
+ * export default app
82
+ * ```
83
+ */
84
+ declare function createSonicJSApp(config?: SonicJSConfig): SonicJSApp;
85
+ /**
86
+ * Setup core middleware (backward compatibility)
87
+ *
88
+ * @param _app - Hono application
89
+ * @deprecated Use createSonicJSApp() instead
90
+ */
91
+ declare function setupCoreMiddleware(_app: SonicJSApp): void;
92
+ /**
93
+ * Setup core routes (backward compatibility)
94
+ *
95
+ * @param _app - Hono application
96
+ * @deprecated Use createSonicJSApp() instead
97
+ */
98
+ declare function setupCoreRoutes(_app: SonicJSApp): void;
99
+
100
+ export { type Bindings as B, type SonicJSConfig as S, type Variables as V, setupCoreRoutes as a, type SonicJSApp as b, createSonicJSApp as c, setupCoreMiddleware as s };
@@ -0,0 +1,100 @@
1
+ import { Hono, Context } from 'hono';
2
+ import { D1Database, KVNamespace, R2Bucket } from '@cloudflare/workers-types';
3
+
4
+ /**
5
+ * Main Application Factory
6
+ *
7
+ * Creates a configured SonicJS application with all core functionality
8
+ */
9
+
10
+ interface Bindings {
11
+ DB: D1Database;
12
+ CACHE_KV: KVNamespace;
13
+ MEDIA_BUCKET: R2Bucket;
14
+ ASSETS: Fetcher;
15
+ EMAIL_QUEUE?: Queue;
16
+ SENDGRID_API_KEY?: string;
17
+ DEFAULT_FROM_EMAIL?: string;
18
+ IMAGES_ACCOUNT_ID?: string;
19
+ IMAGES_API_TOKEN?: string;
20
+ ENVIRONMENT?: string;
21
+ BUCKET_NAME?: string;
22
+ }
23
+ interface Variables {
24
+ user?: {
25
+ userId: string;
26
+ email: string;
27
+ role: string;
28
+ exp: number;
29
+ iat: number;
30
+ };
31
+ requestId?: string;
32
+ startTime?: number;
33
+ appVersion?: string;
34
+ }
35
+ interface SonicJSConfig {
36
+ collections?: {
37
+ directory?: string;
38
+ autoSync?: boolean;
39
+ };
40
+ plugins?: {
41
+ directory?: string;
42
+ autoLoad?: boolean;
43
+ disableAll?: boolean;
44
+ };
45
+ routes?: Array<{
46
+ path: string;
47
+ handler: Hono;
48
+ }>;
49
+ middleware?: {
50
+ beforeAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>;
51
+ afterAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>;
52
+ };
53
+ version?: string;
54
+ name?: string;
55
+ }
56
+ type SonicJSApp = Hono<{
57
+ Bindings: Bindings;
58
+ Variables: Variables;
59
+ }>;
60
+ /**
61
+ * Create a SonicJS application with core functionality
62
+ *
63
+ * @param config - Application configuration
64
+ * @returns Configured Hono application
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * import { createSonicJSApp } from '@sonicjs/core'
69
+ *
70
+ * const app = createSonicJSApp({
71
+ * collections: {
72
+ * directory: './src/collections',
73
+ * autoSync: true
74
+ * },
75
+ * plugins: {
76
+ * directory: './src/plugins',
77
+ * autoLoad: true
78
+ * }
79
+ * })
80
+ *
81
+ * export default app
82
+ * ```
83
+ */
84
+ declare function createSonicJSApp(config?: SonicJSConfig): SonicJSApp;
85
+ /**
86
+ * Setup core middleware (backward compatibility)
87
+ *
88
+ * @param _app - Hono application
89
+ * @deprecated Use createSonicJSApp() instead
90
+ */
91
+ declare function setupCoreMiddleware(_app: SonicJSApp): void;
92
+ /**
93
+ * Setup core routes (backward compatibility)
94
+ *
95
+ * @param _app - Hono application
96
+ * @deprecated Use createSonicJSApp() instead
97
+ */
98
+ declare function setupCoreRoutes(_app: SonicJSApp): void;
99
+
100
+ export { type Bindings as B, type SonicJSConfig as S, type Variables as V, setupCoreRoutes as a, type SonicJSApp as b, createSonicJSApp as c, setupCoreMiddleware as s };