@sonicjs-cms/core 1.0.0-alpha.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/LICENSE +21 -0
- package/README.md +285 -0
- package/dist/chunk-JIINOD2W.js +471 -0
- package/dist/chunk-JIINOD2W.js.map +1 -0
- package/dist/chunk-KYGRJCZM.cjs +44 -0
- package/dist/chunk-KYGRJCZM.cjs.map +1 -0
- package/dist/chunk-LOUJRBXV.js +42 -0
- package/dist/chunk-LOUJRBXV.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-Q7SFCCGT.cjs +11 -0
- package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
- package/dist/chunk-RGCQSFKC.cjs +481 -0
- package/dist/chunk-RGCQSFKC.cjs.map +1 -0
- package/dist/index.cjs +744 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8077 -0
- package/dist/index.d.ts +8077 -0
- package/dist/index.js +660 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.cjs +10 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.cts +8 -0
- package/dist/middleware.d.ts +8 -0
- package/dist/middleware.js +8 -0
- package/dist/middleware.js.map +1 -0
- package/dist/plugins.cjs +10 -0
- package/dist/plugins.cjs.map +1 -0
- package/dist/plugins.d.cts +8 -0
- package/dist/plugins.d.ts +8 -0
- package/dist/plugins.js +8 -0
- package/dist/plugins.js.map +1 -0
- package/dist/routes.cjs +10 -0
- package/dist/routes.cjs.map +1 -0
- package/dist/routes.d.cts +8 -0
- package/dist/routes.d.ts +8 -0
- package/dist/routes.js +8 -0
- package/dist/routes.js.map +1 -0
- package/dist/services.cjs +10 -0
- package/dist/services.cjs.map +1 -0
- package/dist/services.d.cts +8 -0
- package/dist/services.d.ts +8 -0
- package/dist/services.js +8 -0
- package/dist/services.js.map +1 -0
- package/dist/templates.cjs +10 -0
- package/dist/templates.cjs.map +1 -0
- package/dist/templates.d.cts +8 -0
- package/dist/templates.d.ts +8 -0
- package/dist/templates.js +8 -0
- package/dist/templates.js.map +1 -0
- package/dist/types.cjs +13 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +497 -0
- package/dist/types.d.ts +497 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.cjs +45 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +184 -0
- package/dist/utils.d.ts +184 -0
- package/dist/utils.js +4 -0
- package/dist/utils.js.map +1 -0
- package/package.json +131 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SonicJS Team
|
|
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
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# @sonicjs/core
|
|
2
|
+
|
|
3
|
+
Core framework for SonicJS - A modern, TypeScript-first headless CMS built for Cloudflare's edge platform.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Edge-First**: Runs on Cloudflare Workers for sub-50ms global response times
|
|
8
|
+
- 📦 **Zero Cold Starts**: V8 isolates provide instant startup
|
|
9
|
+
- 🔒 **Type-Safe**: Full TypeScript support with strict typing
|
|
10
|
+
- 🔌 **Plugin System**: Extensible architecture with hooks and middleware
|
|
11
|
+
- ⚡ **Three-Tier Caching**: Memory, KV, and database layers for optimal performance
|
|
12
|
+
- 🎨 **Admin Interface**: Beautiful glass morphism design system
|
|
13
|
+
- 🔐 **Authentication**: JWT-based auth with role-based permissions
|
|
14
|
+
- 📝 **Content Management**: Dynamic collections with versioning and workflows
|
|
15
|
+
- 🖼️ **Media Management**: R2 storage with automatic CDN optimization
|
|
16
|
+
- 📊 **API Documentation**: OpenAPI/Swagger with auto-generated docs
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @sonicjs/core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Peer Dependencies
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @cloudflare/workers-types hono drizzle-orm zod
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### 1. Create a new SonicJS project
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
// src/index.ts
|
|
36
|
+
import { createSonicJSApp } from '@sonicjs/core'
|
|
37
|
+
import type { SonicJSConfig } from '@sonicjs/core'
|
|
38
|
+
|
|
39
|
+
const config: SonicJSConfig = {
|
|
40
|
+
collections: {
|
|
41
|
+
directory: './src/collections',
|
|
42
|
+
autoSync: true
|
|
43
|
+
},
|
|
44
|
+
plugins: {
|
|
45
|
+
directory: './src/plugins',
|
|
46
|
+
autoLoad: true
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const app = createSonicJSApp(config)
|
|
51
|
+
|
|
52
|
+
export default app
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 2. Define a collection
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// src/collections/posts.collection.ts
|
|
59
|
+
import type { CollectionConfig } from '@sonicjs/core'
|
|
60
|
+
|
|
61
|
+
export const postsCollection: CollectionConfig = {
|
|
62
|
+
name: 'posts',
|
|
63
|
+
fields: {
|
|
64
|
+
title: {
|
|
65
|
+
type: 'text',
|
|
66
|
+
required: true,
|
|
67
|
+
label: 'Title'
|
|
68
|
+
},
|
|
69
|
+
content: {
|
|
70
|
+
type: 'rich_text',
|
|
71
|
+
required: true,
|
|
72
|
+
label: 'Content'
|
|
73
|
+
},
|
|
74
|
+
published: {
|
|
75
|
+
type: 'boolean',
|
|
76
|
+
default: false,
|
|
77
|
+
label: 'Published'
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 3. Run migrations
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm run db:migrate
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 4. Start development server
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm run dev
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Usage
|
|
96
|
+
|
|
97
|
+
### Importing Core Modules
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// Main API
|
|
101
|
+
import { createSonicJSApp } from '@sonicjs/core'
|
|
102
|
+
import type { SonicJSConfig } from '@sonicjs/core'
|
|
103
|
+
|
|
104
|
+
// Services
|
|
105
|
+
import { CollectionService, MigrationService } from '@sonicjs/core/services'
|
|
106
|
+
|
|
107
|
+
// Middleware
|
|
108
|
+
import { requireAuth, requireRole } from '@sonicjs/core/middleware'
|
|
109
|
+
|
|
110
|
+
// Types
|
|
111
|
+
import type {
|
|
112
|
+
CollectionConfig,
|
|
113
|
+
PluginConfig,
|
|
114
|
+
User,
|
|
115
|
+
Bindings
|
|
116
|
+
} from '@sonicjs/core'
|
|
117
|
+
|
|
118
|
+
// Utilities
|
|
119
|
+
import { validators, templateRenderer } from '@sonicjs/core/utils'
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Custom Routes
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { Hono } from 'hono'
|
|
126
|
+
import { requireAuth } from '@sonicjs/core/middleware'
|
|
127
|
+
import type { Bindings } from '@sonicjs/core'
|
|
128
|
+
|
|
129
|
+
export const customRoutes = new Hono<{ Bindings: Bindings }>()
|
|
130
|
+
|
|
131
|
+
customRoutes.get('/custom', requireAuth(), async (c) => {
|
|
132
|
+
return c.json({ message: 'Custom route' })
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Custom Plugins
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import type { Plugin } from '@sonicjs/core/plugins'
|
|
140
|
+
|
|
141
|
+
export class MyPlugin implements Plugin {
|
|
142
|
+
name = 'my-plugin'
|
|
143
|
+
version = '1.0.0'
|
|
144
|
+
description = 'My custom plugin'
|
|
145
|
+
|
|
146
|
+
async onActivate() {
|
|
147
|
+
console.log('Plugin activated!')
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
hooks = {
|
|
151
|
+
'content.beforeSave': async (content) => {
|
|
152
|
+
// Modify content before saving
|
|
153
|
+
return content
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Configuration
|
|
160
|
+
|
|
161
|
+
### SonicJS Config
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
interface SonicJSConfig {
|
|
165
|
+
// Collections configuration
|
|
166
|
+
collections?: {
|
|
167
|
+
directory: string
|
|
168
|
+
autoSync: boolean
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Plugins configuration
|
|
172
|
+
plugins?: {
|
|
173
|
+
directory: string
|
|
174
|
+
autoLoad: boolean
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Custom routes
|
|
178
|
+
routes?: Array<{
|
|
179
|
+
path: string
|
|
180
|
+
handler: Hono
|
|
181
|
+
}>
|
|
182
|
+
|
|
183
|
+
// Custom middleware
|
|
184
|
+
middleware?: {
|
|
185
|
+
beforeAuth?: Array<MiddlewareHandler>
|
|
186
|
+
afterAuth?: Array<MiddlewareHandler>
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## API Reference
|
|
192
|
+
|
|
193
|
+
### Services
|
|
194
|
+
|
|
195
|
+
- **CollectionService**: Load and manage collections
|
|
196
|
+
- **MigrationService**: Database migration management
|
|
197
|
+
- **PluginService**: Plugin lifecycle management
|
|
198
|
+
- **Logger**: Structured logging system
|
|
199
|
+
|
|
200
|
+
### Middleware
|
|
201
|
+
|
|
202
|
+
- **requireAuth()**: Require authentication
|
|
203
|
+
- **requireRole(roles)**: Require specific roles
|
|
204
|
+
- **requirePermission(permission)**: Require specific permission
|
|
205
|
+
- **bootstrapMiddleware()**: Initialize application
|
|
206
|
+
|
|
207
|
+
### Routes
|
|
208
|
+
|
|
209
|
+
- **apiRoutes**: Public API endpoints
|
|
210
|
+
- **adminRoutes**: Admin dashboard routes
|
|
211
|
+
- **authRoutes**: Authentication routes
|
|
212
|
+
|
|
213
|
+
## Migration from Standalone
|
|
214
|
+
|
|
215
|
+
If you're migrating from a standalone SonicJS project:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
# 1. Install core package
|
|
219
|
+
npm install @sonicjs/core
|
|
220
|
+
|
|
221
|
+
# 2. Run migration tool
|
|
222
|
+
npx @sonicjs/migrate --from=current --to=1.0.0
|
|
223
|
+
|
|
224
|
+
# 3. Update src/index.ts with new config API
|
|
225
|
+
# 4. Run database migrations
|
|
226
|
+
npm run db:migrate
|
|
227
|
+
|
|
228
|
+
# 5. Test
|
|
229
|
+
npm run dev
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
See [Migration Guide](https://docs.sonicjs.com/migration) for detailed instructions.
|
|
233
|
+
|
|
234
|
+
## Documentation
|
|
235
|
+
|
|
236
|
+
- **Getting Started**: https://docs.sonicjs.com/getting-started
|
|
237
|
+
- **API Reference**: https://docs.sonicjs.com/api
|
|
238
|
+
- **Plugin Development**: https://docs.sonicjs.com/plugins
|
|
239
|
+
- **Migration Guide**: https://docs.sonicjs.com/migration
|
|
240
|
+
|
|
241
|
+
## Examples
|
|
242
|
+
|
|
243
|
+
See the [examples](../../examples) directory for complete examples:
|
|
244
|
+
|
|
245
|
+
- **Basic Setup**: Simple SonicJS application
|
|
246
|
+
- **Custom Plugin**: Building custom plugins
|
|
247
|
+
- **API Integration**: Consuming the API
|
|
248
|
+
- **Advanced Configuration**: Complex setups
|
|
249
|
+
|
|
250
|
+
## Architecture
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
@sonicjs/core
|
|
254
|
+
├── services/ # Business logic layer
|
|
255
|
+
├── middleware/ # Request processing
|
|
256
|
+
├── routes/ # HTTP handlers
|
|
257
|
+
├── templates/ # Admin UI templates
|
|
258
|
+
├── plugins/ # Plugin system
|
|
259
|
+
├── types/ # TypeScript definitions
|
|
260
|
+
├── utils/ # Utility functions
|
|
261
|
+
└── migrations/ # Database migrations
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Contributing
|
|
265
|
+
|
|
266
|
+
Contributions welcome! See [CONTRIBUTING.md](../../CONTRIBUTING.md).
|
|
267
|
+
|
|
268
|
+
## License
|
|
269
|
+
|
|
270
|
+
MIT © SonicJS Team
|
|
271
|
+
|
|
272
|
+
## Support
|
|
273
|
+
|
|
274
|
+
- **GitHub Issues**: https://github.com/sonicjs/sonicjs/issues
|
|
275
|
+
- **Discord**: https://discord.gg/sonicjs
|
|
276
|
+
- **Documentation**: https://docs.sonicjs.com
|
|
277
|
+
- **Twitter**: @sonicjscms
|
|
278
|
+
|
|
279
|
+
## Changelog
|
|
280
|
+
|
|
281
|
+
See [CHANGELOG.md](./CHANGELOG.md) for version history.
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
**Built with ❤️ by the SonicJS Team**
|