@sonicjs-cms/core 2.1.0 → 2.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/README.md +75 -1
- package/dist/app-Db0AfT5F.d.cts +100 -0
- package/dist/app-Db0AfT5F.d.ts +100 -0
- package/dist/{chunk-KZ5XDGE6.js → chunk-3ZLCMOCM.js} +441 -433
- package/dist/chunk-3ZLCMOCM.js.map +1 -0
- package/dist/{chunk-K5JZ4JI3.js → chunk-4C433FET.js} +5 -3
- package/dist/chunk-4C433FET.js.map +1 -0
- package/dist/{chunk-UJ4K4B23.js → chunk-5TRX2JHU.js} +4 -4
- package/dist/{chunk-UJ4K4B23.js.map → chunk-5TRX2JHU.js.map} +1 -1
- package/dist/{chunk-LWMMMW43.js → chunk-7CXL5K7N.js} +4 -3
- package/dist/chunk-7CXL5K7N.js.map +1 -0
- package/dist/{chunk-WBX5YMTB.cjs → chunk-7KCDFDRI.cjs} +27 -15
- package/dist/chunk-7KCDFDRI.cjs.map +1 -0
- package/dist/chunk-CAMM3MJV.js +1550 -0
- package/dist/chunk-CAMM3MJV.js.map +1 -0
- package/dist/{chunk-HKEK7UNV.js → chunk-CPXAVWCU.js} +3 -3
- package/dist/{chunk-HKEK7UNV.js.map → chunk-CPXAVWCU.js.map} +1 -1
- package/dist/{chunk-F5ESJXI2.cjs → chunk-DTLB6UIH.cjs} +3 -3
- package/dist/{chunk-F5ESJXI2.cjs.map → chunk-DTLB6UIH.cjs.map} +1 -1
- package/dist/{chunk-YP52USGX.cjs → chunk-ES3BRZQJ.cjs} +15 -12
- package/dist/{chunk-YP52USGX.cjs.map → chunk-ES3BRZQJ.cjs.map} +1 -1
- package/dist/chunk-HBJU3I2Y.cjs +1552 -0
- package/dist/chunk-HBJU3I2Y.cjs.map +1 -0
- package/dist/{chunk-7EGKU7OO.cjs → chunk-KP4DVEX5.cjs} +7 -7
- package/dist/{chunk-7EGKU7OO.cjs.map → chunk-KP4DVEX5.cjs.map} +1 -1
- package/dist/{chunk-LPM3NPAX.cjs → chunk-MPFSSBIY.cjs} +541 -533
- package/dist/chunk-MPFSSBIY.cjs.map +1 -0
- package/dist/{chunk-22EFGHAX.cjs → chunk-NAYD76QF.cjs} +4 -3
- package/dist/chunk-NAYD76QF.cjs.map +1 -0
- package/dist/{chunk-F4K5QAN6.js → chunk-Q52ZQFMB.js} +7 -4
- package/dist/{chunk-F4K5QAN6.js.map → chunk-Q52ZQFMB.js.map} +1 -1
- package/dist/{chunk-NMVOTNSL.js → chunk-RRKXFGIO.js} +28 -16
- package/dist/chunk-RRKXFGIO.js.map +1 -0
- package/dist/{chunk-2MBNRFS5.cjs → chunk-TT266RYM.cjs} +5 -3
- package/dist/chunk-TT266RYM.cjs.map +1 -0
- package/dist/collection-config-FLlGtsh9.d.cts +107 -0
- package/dist/collection-config-FLlGtsh9.d.ts +107 -0
- package/dist/filter-bar.template-By4jeiw_.d.cts +140 -0
- package/dist/filter-bar.template-By4jeiw_.d.ts +140 -0
- package/dist/index.cjs +146 -141
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -0
- package/dist/index.d.ts +43 -5
- package/dist/index.js +19 -14
- package/dist/index.js.map +1 -1
- package/dist/middleware.cjs +24 -24
- package/dist/middleware.d.cts +89 -0
- package/dist/middleware.d.ts +89 -2
- package/dist/middleware.js +3 -3
- package/dist/migrations-B2CDNN76.js +4 -0
- package/dist/{migrations-IHERIQVD.js.map → migrations-B2CDNN76.js.map} +1 -1
- package/dist/migrations-IBKKBIKR.cjs +13 -0
- package/dist/{migrations-POFD5KNG.cjs.map → migrations-IBKKBIKR.cjs.map} +1 -1
- package/dist/plugin-bootstrap-C0E3jdz-.d.cts +8339 -0
- package/dist/plugin-bootstrap-CDh0JHtW.d.ts +8339 -0
- package/dist/plugin-manifest-BCMx9CAq.d.cts +35 -0
- package/dist/plugin-manifest-BCMx9CAq.d.ts +35 -0
- package/dist/plugin-zvZpaiP5.d.cts +357 -0
- package/dist/plugin-zvZpaiP5.d.ts +357 -0
- package/dist/plugins.cjs +7 -7
- package/dist/plugins.d.cts +330 -0
- package/dist/plugins.d.ts +330 -2
- package/dist/plugins.js +1 -1
- package/dist/routes.cjs +27 -27
- package/dist/routes.d.cts +224 -0
- package/dist/routes.d.ts +224 -2
- package/dist/routes.js +7 -7
- package/dist/services.cjs +29 -29
- package/dist/services.d.cts +236 -0
- package/dist/services.d.ts +236 -2
- package/dist/services.js +4 -4
- package/dist/telemetry-BFBIjBxK.d.cts +36 -0
- package/dist/telemetry-BFBIjBxK.d.ts +36 -0
- package/dist/templates.d.cts +133 -0
- package/dist/templates.d.ts +133 -2
- package/dist/types.d.cts +7 -0
- package/dist/types.d.ts +7 -2
- package/dist/utils.cjs +23 -23
- package/dist/utils.d.cts +53 -0
- package/dist/utils.d.ts +53 -2
- package/dist/utils.js +2 -2
- package/dist/version-vktVAxhe.d.cts +195 -0
- package/dist/version-vktVAxhe.d.ts +195 -0
- package/migrations/001_initial_schema.sql +1 -1
- package/package.json +3 -1
- package/dist/chunk-22EFGHAX.cjs.map +0 -1
- package/dist/chunk-2MBNRFS5.cjs.map +0 -1
- package/dist/chunk-K5JZ4JI3.js.map +0 -1
- package/dist/chunk-KZ5XDGE6.js.map +0 -1
- package/dist/chunk-LPM3NPAX.cjs.map +0 -1
- package/dist/chunk-LWMMMW43.js.map +0 -1
- package/dist/chunk-NMVOTNSL.js.map +0 -1
- package/dist/chunk-T7IYBGGO.cjs +0 -746
- package/dist/chunk-T7IYBGGO.cjs.map +0 -1
- package/dist/chunk-WBX5YMTB.cjs.map +0 -1
- package/dist/chunk-ZPMFT2JW.js +0 -744
- package/dist/chunk-ZPMFT2JW.js.map +0 -1
- package/dist/migrations-IHERIQVD.js +0 -4
- package/dist/migrations-POFD5KNG.cjs +0 -13
- package/migrations/013_code_examples_plugin.sql +0 -177
- /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 };
|