@sonicjs-cms/core 1.0.0-alpha.4 → 2.0.0-alpha.10
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 +268 -166
- package/dist/chunk-3MNMOLSA.js +133 -0
- package/dist/chunk-3MNMOLSA.js.map +1 -0
- package/dist/chunk-4USDL3UP.cjs +15565 -0
- package/dist/chunk-4USDL3UP.cjs.map +1 -0
- package/dist/{chunk-CXZDAR6S.js → chunk-7N3HK7ZK.js} +3 -3
- package/dist/{chunk-CXZDAR6S.js.map → chunk-7N3HK7ZK.js.map} +1 -1
- package/dist/chunk-AGOE25LF.cjs +137 -0
- package/dist/chunk-AGOE25LF.cjs.map +1 -0
- package/dist/{chunk-NRSL6BQI.js → chunk-BITQ4MFX.js} +3 -3
- package/dist/{chunk-NRSL6BQI.js.map → chunk-BITQ4MFX.js.map} +1 -1
- package/dist/{chunk-24PWAFUT.cjs → chunk-BUKT6HP5.cjs} +13 -13
- package/dist/{chunk-24PWAFUT.cjs.map → chunk-BUKT6HP5.cjs.map} +1 -1
- package/dist/{chunk-L3NXO7Y4.cjs → chunk-FVMV5DKA.cjs} +49 -49
- package/dist/{chunk-L3NXO7Y4.cjs.map → chunk-FVMV5DKA.cjs.map} +1 -1
- package/dist/chunk-GGBHOIDD.js +15552 -0
- package/dist/chunk-GGBHOIDD.js.map +1 -0
- package/dist/{chunk-EMMSS5I5.cjs → chunk-IGJUBJBW.cjs} +8 -2
- package/dist/{chunk-ALTMI5Y2.cjs.map → chunk-IGJUBJBW.cjs.map} +1 -1
- package/dist/{chunk-WJ7QYVR2.cjs → chunk-RNR4HA23.cjs} +4 -4
- package/dist/{chunk-WJ7QYVR2.cjs.map → chunk-RNR4HA23.cjs.map} +1 -1
- package/dist/{chunk-G3PMV62Z.js → chunk-V4OQ3NZ2.js} +7 -3
- package/dist/{chunk-G3PMV62Z.js.map → chunk-V4OQ3NZ2.js.map} +1 -1
- package/dist/{chunk-PTQZ5FEI.js → chunk-WESS2U3K.js} +3 -3
- package/dist/{chunk-PTQZ5FEI.js.map → chunk-WESS2U3K.js.map} +1 -1
- package/dist/index.cjs +105 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -8
- package/dist/index.js.map +1 -1
- package/dist/middleware.cjs +23 -23
- package/dist/middleware.js +3 -3
- package/dist/plugins.cjs +8 -8
- package/dist/plugins.js +2 -2
- package/dist/routes.cjs +51 -3
- package/dist/routes.js +6 -2
- package/dist/services.cjs +31 -19
- package/dist/services.js +3 -3
- package/dist/templates.cjs +1 -1
- package/dist/templates.js +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/migrations/001_initial_schema.sql +198 -0
- package/migrations/002_faq_plugin.sql +86 -0
- package/migrations/003_stage5_enhancements.sql +121 -0
- package/migrations/004_stage6_user_management.sql +183 -0
- package/migrations/005_stage7_workflow_automation.sql +294 -0
- package/migrations/006_plugin_system.sql +155 -0
- package/migrations/007_demo_login_plugin.sql +23 -0
- package/migrations/008_fix_slug_validation.sql +22 -0
- package/migrations/009_system_logging.sql +57 -0
- package/migrations/011_config_managed_collections.sql +14 -0
- package/migrations/012_testimonials_plugin.sql +80 -0
- package/migrations/013_code_examples_plugin.sql +177 -0
- package/migrations/014_fix_plugin_registry.sql +88 -0
- package/migrations/015_add_remaining_plugins.sql +89 -0
- package/migrations/016_remove_duplicate_cache_plugin.sql +17 -0
- package/migrations/017_auth_configurable_fields.sql +49 -0
- package/package.json +24 -24
- package/dist/chunk-4URGXJP7.js +0 -3
- package/dist/chunk-4URGXJP7.js.map +0 -1
- package/dist/chunk-ALTMI5Y2.cjs +0 -4
- package/dist/chunk-BOLQHE4J.cjs +0 -11
- package/dist/chunk-BOLQHE4J.cjs.map +0 -1
- package/dist/chunk-EMMSS5I5.cjs.map +0 -1
- package/dist/chunk-HD7R6T6I.js +0 -9
- package/dist/chunk-HD7R6T6I.js.map +0 -1
- package/dist/collection-config-FLlGtsh9.d.cts +0 -107
- package/dist/collection-config-FLlGtsh9.d.ts +0 -107
- package/dist/index-BlsY5XNH.d.ts +0 -8333
- package/dist/index-D45jaIlr.d.cts +0 -8333
- package/dist/index.d.cts +0 -136
- package/dist/index.d.ts +0 -136
- package/dist/middleware.d.cts +0 -206
- package/dist/middleware.d.ts +0 -206
- package/dist/plugin-UzmDImQc.d.cts +0 -357
- package/dist/plugin-UzmDImQc.d.ts +0 -357
- package/dist/plugins.d.cts +0 -330
- package/dist/plugins.d.ts +0 -330
- package/dist/routes.d.cts +0 -17
- package/dist/routes.d.ts +0 -17
- package/dist/services.d.cts +0 -5
- package/dist/services.d.ts +0 -5
- package/dist/templates.d.cts +0 -140
- package/dist/templates.d.ts +0 -140
- package/dist/types.d.cts +0 -41
- package/dist/types.d.ts +0 -41
- package/dist/utils.d.cts +0 -184
- package/dist/utils.d.ts +0 -184
package/README.md
CHANGED
|
@@ -1,40 +1,49 @@
|
|
|
1
|
-
# @sonicjs/core
|
|
1
|
+
# @sonicjs-cms/core
|
|
2
2
|
|
|
3
|
-
Core framework for SonicJS - A modern, TypeScript-first headless CMS built for Cloudflare's edge platform.
|
|
3
|
+
> Core framework for SonicJS - A modern, TypeScript-first headless CMS built for Cloudflare's edge platform.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@sonicjs-cms/core)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
8
|
+
## ✨ Features
|
|
6
9
|
|
|
7
10
|
- 🚀 **Edge-First**: Runs on Cloudflare Workers for sub-50ms global response times
|
|
8
11
|
- 📦 **Zero Cold Starts**: V8 isolates provide instant startup
|
|
9
|
-
- 🔒 **Type-Safe**: Full TypeScript support with
|
|
12
|
+
- 🔒 **Type-Safe**: Full TypeScript support with comprehensive type definitions
|
|
10
13
|
- 🔌 **Plugin System**: Extensible architecture with hooks and middleware
|
|
11
14
|
- ⚡ **Three-Tier Caching**: Memory, KV, and database layers for optimal performance
|
|
12
15
|
- 🎨 **Admin Interface**: Beautiful glass morphism design system
|
|
13
16
|
- 🔐 **Authentication**: JWT-based auth with role-based permissions
|
|
14
17
|
- 📝 **Content Management**: Dynamic collections with versioning and workflows
|
|
15
|
-
- 🖼️ **Media Management**: R2 storage with automatic
|
|
16
|
-
-
|
|
18
|
+
- 🖼️ **Media Management**: R2 storage with automatic optimization
|
|
19
|
+
- 🌐 **REST API**: Auto-generated endpoints for all collections
|
|
17
20
|
|
|
18
|
-
## Installation
|
|
21
|
+
## 📦 Installation
|
|
19
22
|
|
|
20
23
|
```bash
|
|
21
|
-
npm install @sonicjs/core
|
|
24
|
+
npm install @sonicjs-cms/core
|
|
22
25
|
```
|
|
23
26
|
|
|
24
|
-
### Peer Dependencies
|
|
27
|
+
### Required Peer Dependencies
|
|
25
28
|
|
|
26
29
|
```bash
|
|
27
30
|
npm install @cloudflare/workers-types hono drizzle-orm zod
|
|
28
31
|
```
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
### Optional Dependencies
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install wrangler drizzle-kit # For development
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 🚀 Quick Start
|
|
31
40
|
|
|
32
|
-
### 1. Create
|
|
41
|
+
### 1. Create Your Application
|
|
33
42
|
|
|
34
43
|
```typescript
|
|
35
44
|
// src/index.ts
|
|
36
|
-
import { createSonicJSApp } from '@sonicjs/core'
|
|
37
|
-
import type { SonicJSConfig } from '@sonicjs/core'
|
|
45
|
+
import { createSonicJSApp } from '@sonicjs-cms/core'
|
|
46
|
+
import type { SonicJSConfig } from '@sonicjs-cms/core'
|
|
38
47
|
|
|
39
48
|
const config: SonicJSConfig = {
|
|
40
49
|
collections: {
|
|
@@ -43,243 +52,336 @@ const config: SonicJSConfig = {
|
|
|
43
52
|
},
|
|
44
53
|
plugins: {
|
|
45
54
|
directory: './src/plugins',
|
|
46
|
-
autoLoad:
|
|
55
|
+
autoLoad: false
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
58
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export default app
|
|
59
|
+
export default createSonicJSApp(config)
|
|
53
60
|
```
|
|
54
61
|
|
|
55
|
-
### 2. Define
|
|
62
|
+
### 2. Define Collections
|
|
56
63
|
|
|
57
64
|
```typescript
|
|
58
|
-
// src/collections/posts.collection.ts
|
|
59
|
-
import type { CollectionConfig } from '@sonicjs/core'
|
|
60
|
-
|
|
61
|
-
export
|
|
62
|
-
name: 'posts',
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
// src/collections/blog-posts.collection.ts
|
|
66
|
+
import type { CollectionConfig } from '@sonicjs-cms/core'
|
|
67
|
+
|
|
68
|
+
export default {
|
|
69
|
+
name: 'blog-posts',
|
|
70
|
+
displayName: 'Blog Posts',
|
|
71
|
+
description: 'Manage your blog posts',
|
|
72
|
+
|
|
73
|
+
schema: {
|
|
74
|
+
type: 'object',
|
|
75
|
+
properties: {
|
|
76
|
+
title: {
|
|
77
|
+
type: 'string',
|
|
78
|
+
title: 'Title',
|
|
79
|
+
required: true,
|
|
80
|
+
maxLength: 200
|
|
81
|
+
},
|
|
82
|
+
content: {
|
|
83
|
+
type: 'markdown',
|
|
84
|
+
title: 'Content',
|
|
85
|
+
required: true
|
|
86
|
+
},
|
|
87
|
+
publishedAt: {
|
|
88
|
+
type: 'datetime',
|
|
89
|
+
title: 'Published Date'
|
|
90
|
+
},
|
|
91
|
+
status: {
|
|
92
|
+
type: 'select',
|
|
93
|
+
title: 'Status',
|
|
94
|
+
enum: ['draft', 'published', 'archived'],
|
|
95
|
+
default: 'draft'
|
|
96
|
+
}
|
|
73
97
|
},
|
|
74
|
-
|
|
75
|
-
type: 'boolean',
|
|
76
|
-
default: false,
|
|
77
|
-
label: 'Published'
|
|
78
|
-
}
|
|
98
|
+
required: ['title', 'content']
|
|
79
99
|
}
|
|
80
|
-
}
|
|
100
|
+
} satisfies CollectionConfig
|
|
81
101
|
```
|
|
82
102
|
|
|
83
|
-
### 3.
|
|
103
|
+
### 3. Configure Cloudflare Workers
|
|
84
104
|
|
|
85
|
-
```
|
|
86
|
-
|
|
105
|
+
```toml
|
|
106
|
+
# wrangler.toml
|
|
107
|
+
name = "my-sonicjs-app"
|
|
108
|
+
main = "src/index.ts"
|
|
109
|
+
compatibility_date = "2024-01-01"
|
|
110
|
+
|
|
111
|
+
[[d1_databases]]
|
|
112
|
+
binding = "DB"
|
|
113
|
+
database_name = "my-sonicjs-db"
|
|
114
|
+
database_id = "your-database-id"
|
|
115
|
+
migrations_dir = "./node_modules/@sonicjs-cms/core/migrations"
|
|
116
|
+
|
|
117
|
+
[[r2_buckets]]
|
|
118
|
+
binding = "BUCKET"
|
|
119
|
+
bucket_name = "my-sonicjs-media"
|
|
87
120
|
```
|
|
88
121
|
|
|
89
|
-
### 4. Start
|
|
122
|
+
### 4. Start Development
|
|
90
123
|
|
|
91
124
|
```bash
|
|
92
|
-
|
|
125
|
+
# Run migrations
|
|
126
|
+
wrangler d1 migrations apply DB --local
|
|
127
|
+
|
|
128
|
+
# Start dev server
|
|
129
|
+
wrangler dev
|
|
93
130
|
```
|
|
94
131
|
|
|
95
|
-
|
|
132
|
+
Visit `http://localhost:8787/admin` to access the admin interface.
|
|
96
133
|
|
|
97
|
-
|
|
134
|
+
## 📚 Core Exports
|
|
135
|
+
|
|
136
|
+
### Main Application
|
|
98
137
|
|
|
99
138
|
```typescript
|
|
100
|
-
|
|
101
|
-
import {
|
|
102
|
-
|
|
139
|
+
import { createSonicJSApp } from '@sonicjs-cms/core'
|
|
140
|
+
import type { SonicJSConfig, SonicJSApp, Bindings, Variables } from '@sonicjs-cms/core'
|
|
141
|
+
```
|
|
103
142
|
|
|
104
|
-
|
|
105
|
-
import { CollectionService, MigrationService } from '@sonicjs/core/services'
|
|
143
|
+
### Services
|
|
106
144
|
|
|
107
|
-
|
|
108
|
-
import {
|
|
145
|
+
```typescript
|
|
146
|
+
import {
|
|
147
|
+
loadCollectionConfigs,
|
|
148
|
+
syncCollections,
|
|
149
|
+
MigrationService,
|
|
150
|
+
Logger,
|
|
151
|
+
PluginService
|
|
152
|
+
} from '@sonicjs-cms/core'
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Middleware
|
|
109
156
|
|
|
110
|
-
|
|
157
|
+
```typescript
|
|
158
|
+
import {
|
|
159
|
+
requireAuth,
|
|
160
|
+
requireRole,
|
|
161
|
+
requirePermission,
|
|
162
|
+
loggingMiddleware,
|
|
163
|
+
cacheHeaders,
|
|
164
|
+
securityHeaders
|
|
165
|
+
} from '@sonicjs-cms/core'
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Types
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
111
171
|
import type {
|
|
112
172
|
CollectionConfig,
|
|
113
|
-
|
|
173
|
+
FieldConfig,
|
|
174
|
+
Plugin,
|
|
175
|
+
PluginContext,
|
|
114
176
|
User,
|
|
115
|
-
|
|
116
|
-
|
|
177
|
+
Content,
|
|
178
|
+
Media
|
|
179
|
+
} from '@sonicjs-cms/core'
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Templates
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import {
|
|
186
|
+
renderForm,
|
|
187
|
+
renderTable,
|
|
188
|
+
renderPagination,
|
|
189
|
+
renderAlert
|
|
190
|
+
} from '@sonicjs-cms/core'
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Utilities
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
import {
|
|
197
|
+
sanitizeInput,
|
|
198
|
+
TemplateRenderer,
|
|
199
|
+
QueryFilterBuilder,
|
|
200
|
+
metricsTracker
|
|
201
|
+
} from '@sonicjs-cms/core'
|
|
202
|
+
```
|
|
117
203
|
|
|
118
|
-
|
|
119
|
-
|
|
204
|
+
### Database
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
import {
|
|
208
|
+
createDb,
|
|
209
|
+
users,
|
|
210
|
+
collections,
|
|
211
|
+
content,
|
|
212
|
+
media
|
|
213
|
+
} from '@sonicjs-cms/core'
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## 🔌 Subpath Exports
|
|
217
|
+
|
|
218
|
+
The package provides organized subpath exports:
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
// Services only
|
|
222
|
+
import { MigrationService } from '@sonicjs-cms/core/services'
|
|
223
|
+
|
|
224
|
+
// Middleware only
|
|
225
|
+
import { requireAuth } from '@sonicjs-cms/core/middleware'
|
|
226
|
+
|
|
227
|
+
// Types only
|
|
228
|
+
import type { CollectionConfig } from '@sonicjs-cms/core/types'
|
|
229
|
+
|
|
230
|
+
// Templates only
|
|
231
|
+
import { renderForm } from '@sonicjs-cms/core/templates'
|
|
232
|
+
|
|
233
|
+
// Utilities only
|
|
234
|
+
import { sanitizeInput } from '@sonicjs-cms/core/utils'
|
|
235
|
+
|
|
236
|
+
// Plugins only
|
|
237
|
+
import { HookSystemImpl } from '@sonicjs-cms/core/plugins'
|
|
120
238
|
```
|
|
121
239
|
|
|
240
|
+
## 🎯 Usage Examples
|
|
241
|
+
|
|
122
242
|
### Custom Routes
|
|
123
243
|
|
|
124
244
|
```typescript
|
|
125
245
|
import { Hono } from 'hono'
|
|
126
|
-
import { requireAuth } from '@sonicjs/core/middleware'
|
|
127
|
-
import type { Bindings } from '@sonicjs/core'
|
|
246
|
+
import { requireAuth } from '@sonicjs-cms/core/middleware'
|
|
247
|
+
import type { Bindings } from '@sonicjs-cms/core'
|
|
128
248
|
|
|
129
|
-
|
|
249
|
+
const customRoutes = new Hono<{ Bindings: Bindings }>()
|
|
130
250
|
|
|
131
|
-
customRoutes.get('/custom', requireAuth(), async (c) => {
|
|
132
|
-
|
|
251
|
+
customRoutes.get('/api/custom', requireAuth(), async (c) => {
|
|
252
|
+
const db = c.env.DB
|
|
253
|
+
// Your custom logic
|
|
254
|
+
return c.json({ message: 'Custom endpoint' })
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
// In your app config
|
|
258
|
+
export default createSonicJSApp({
|
|
259
|
+
routes: [{ path: '/custom', handler: customRoutes }]
|
|
133
260
|
})
|
|
134
261
|
```
|
|
135
262
|
|
|
136
|
-
### Custom
|
|
263
|
+
### Custom Plugin
|
|
137
264
|
|
|
138
265
|
```typescript
|
|
139
|
-
import type { Plugin } from '@sonicjs/core
|
|
266
|
+
import type { Plugin } from '@sonicjs-cms/core'
|
|
140
267
|
|
|
141
|
-
export
|
|
142
|
-
name
|
|
143
|
-
version
|
|
144
|
-
description
|
|
268
|
+
export default {
|
|
269
|
+
name: 'my-plugin',
|
|
270
|
+
version: '1.0.0',
|
|
271
|
+
description: 'My custom plugin',
|
|
145
272
|
|
|
146
273
|
async onActivate() {
|
|
147
274
|
console.log('Plugin activated!')
|
|
148
|
-
}
|
|
275
|
+
},
|
|
149
276
|
|
|
150
|
-
hooks
|
|
277
|
+
hooks: {
|
|
151
278
|
'content.beforeSave': async (content) => {
|
|
152
|
-
//
|
|
279
|
+
// Transform content before saving
|
|
280
|
+
content.metadata = { modified: new Date() }
|
|
153
281
|
return content
|
|
154
282
|
}
|
|
155
283
|
}
|
|
156
|
-
}
|
|
284
|
+
} satisfies Plugin
|
|
157
285
|
```
|
|
158
286
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
### SonicJS Config
|
|
287
|
+
### Accessing Services
|
|
162
288
|
|
|
163
289
|
```typescript
|
|
164
|
-
|
|
165
|
-
// Collections configuration
|
|
166
|
-
collections?: {
|
|
167
|
-
directory: string
|
|
168
|
-
autoSync: boolean
|
|
169
|
-
}
|
|
290
|
+
import { Logger, MigrationService } from '@sonicjs-cms/core'
|
|
170
291
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
directory: string
|
|
174
|
-
autoLoad: boolean
|
|
175
|
-
}
|
|
292
|
+
const logger = new Logger({ category: 'custom', level: 'info' })
|
|
293
|
+
logger.info('Application started')
|
|
176
294
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
path: string
|
|
180
|
-
handler: Hono
|
|
181
|
-
}>
|
|
182
|
-
|
|
183
|
-
// Custom middleware
|
|
184
|
-
middleware?: {
|
|
185
|
-
beforeAuth?: Array<MiddlewareHandler>
|
|
186
|
-
afterAuth?: Array<MiddlewareHandler>
|
|
187
|
-
}
|
|
188
|
-
}
|
|
295
|
+
const migrationService = new MigrationService(db)
|
|
296
|
+
await migrationService.runAllMigrations()
|
|
189
297
|
```
|
|
190
298
|
|
|
191
|
-
##
|
|
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
|
|
299
|
+
## 🏗️ Architecture
|
|
199
300
|
|
|
200
|
-
|
|
301
|
+
```
|
|
302
|
+
@sonicjs-cms/core
|
|
303
|
+
├── src/
|
|
304
|
+
│ ├── app.ts # Application factory
|
|
305
|
+
│ ├── db/ # Database schemas & utilities
|
|
306
|
+
│ ├── services/ # Business logic
|
|
307
|
+
│ ├── middleware/ # Request processing
|
|
308
|
+
│ ├── routes/ # HTTP handlers
|
|
309
|
+
│ ├── templates/ # Admin UI components
|
|
310
|
+
│ ├── plugins/ # Plugin system & core plugins
|
|
311
|
+
│ ├── types/ # TypeScript definitions
|
|
312
|
+
│ └── utils/ # Utility functions
|
|
313
|
+
├── migrations/ # Core database migrations
|
|
314
|
+
└── dist/ # Compiled output
|
|
315
|
+
```
|
|
201
316
|
|
|
202
|
-
|
|
203
|
-
- **requireRole(roles)**: Require specific roles
|
|
204
|
-
- **requirePermission(permission)**: Require specific permission
|
|
205
|
-
- **bootstrapMiddleware()**: Initialize application
|
|
317
|
+
## 🔄 Versioning
|
|
206
318
|
|
|
207
|
-
|
|
319
|
+
SonicJS follows semantic versioning:
|
|
208
320
|
|
|
209
|
-
- **
|
|
210
|
-
- **
|
|
211
|
-
- **authRoutes**: Authentication routes
|
|
321
|
+
- **v2.x.x** - Current npm package (core extracted)
|
|
322
|
+
- **v1.x.x** - Legacy monolith (deprecated)
|
|
212
323
|
|
|
213
|
-
|
|
324
|
+
**Current Version**: `2.0.0-alpha.1`
|
|
214
325
|
|
|
215
|
-
|
|
326
|
+
### Upgrade Path
|
|
216
327
|
|
|
217
328
|
```bash
|
|
218
|
-
#
|
|
219
|
-
npm install @sonicjs/core
|
|
220
|
-
|
|
221
|
-
# 2. Run migration tool
|
|
222
|
-
npx @sonicjs/migrate --from=current --to=1.0.0
|
|
329
|
+
# Install the new package
|
|
330
|
+
npm install @sonicjs-cms/core@2.0.0-alpha.1
|
|
223
331
|
|
|
224
|
-
#
|
|
225
|
-
|
|
226
|
-
npm run db:migrate
|
|
332
|
+
# Run any new migrations
|
|
333
|
+
wrangler d1 migrations apply DB
|
|
227
334
|
|
|
228
|
-
#
|
|
335
|
+
# Test your application
|
|
229
336
|
npm run dev
|
|
230
337
|
```
|
|
231
338
|
|
|
232
|
-
|
|
339
|
+
## 📖 Documentation
|
|
233
340
|
|
|
234
|
-
|
|
341
|
+
- [Getting Started](https://docs.sonicjs.com/getting-started)
|
|
342
|
+
- [API Reference](https://docs.sonicjs.com/api)
|
|
343
|
+
- [Collections Guide](https://docs.sonicjs.com/collections)
|
|
344
|
+
- [Plugin Development](https://docs.sonicjs.com/plugins)
|
|
345
|
+
- [Deployment](https://docs.sonicjs.com/deployment)
|
|
235
346
|
|
|
236
|
-
|
|
237
|
-
- **API Reference**: https://docs.sonicjs.com/api
|
|
238
|
-
- **Plugin Development**: https://docs.sonicjs.com/plugins
|
|
239
|
-
- **Migration Guide**: https://docs.sonicjs.com/migration
|
|
347
|
+
## 🤝 Contributing
|
|
240
348
|
|
|
241
|
-
|
|
349
|
+
We welcome contributions! Please see [CONTRIBUTING.md](../../CONTRIBUTING.md).
|
|
242
350
|
|
|
243
|
-
|
|
351
|
+
## 📄 License
|
|
244
352
|
|
|
245
|
-
-
|
|
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
|
-
```
|
|
353
|
+
MIT © SonicJS Team - See [LICENSE](./LICENSE) for details.
|
|
263
354
|
|
|
264
|
-
##
|
|
355
|
+
## 💬 Support & Community
|
|
265
356
|
|
|
266
|
-
|
|
357
|
+
- **Issues**: [GitHub Issues](https://github.com/sonicjs/sonicjs/issues)
|
|
358
|
+
- **Discord**: [Join our community](https://discord.gg/sonicjs)
|
|
359
|
+
- **Docs**: [docs.sonicjs.com](https://docs.sonicjs.com)
|
|
360
|
+
- **Twitter**: [@sonicjscms](https://twitter.com/sonicjscms)
|
|
267
361
|
|
|
268
|
-
##
|
|
362
|
+
## 🔖 Resources
|
|
269
363
|
|
|
270
|
-
|
|
364
|
+
- [Starter Template](../../templates/starter) - Greenfield project template
|
|
365
|
+
- [Cloudflare Workers Docs](https://developers.cloudflare.com/workers/)
|
|
366
|
+
- [D1 Database](https://developers.cloudflare.com/d1/)
|
|
367
|
+
- [R2 Storage](https://developers.cloudflare.com/r2/)
|
|
271
368
|
|
|
272
|
-
##
|
|
369
|
+
## ⚡ Performance
|
|
273
370
|
|
|
274
|
-
-
|
|
275
|
-
-
|
|
276
|
-
-
|
|
277
|
-
-
|
|
371
|
+
- Global edge deployment
|
|
372
|
+
- Sub-50ms response times
|
|
373
|
+
- Zero cold starts
|
|
374
|
+
- Automatic scaling
|
|
375
|
+
- Built-in caching
|
|
278
376
|
|
|
279
|
-
##
|
|
377
|
+
## 🛡️ Security
|
|
280
378
|
|
|
281
|
-
|
|
379
|
+
- JWT authentication
|
|
380
|
+
- Role-based access control (RBAC)
|
|
381
|
+
- Permission system
|
|
382
|
+
- Secure headers
|
|
383
|
+
- Input sanitization
|
|
282
384
|
|
|
283
385
|
---
|
|
284
386
|
|
|
285
|
-
**Built with ❤️
|
|
387
|
+
**Built with ❤️ for the edge** | v2.0.0-alpha.1
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// src/services/cache.ts
|
|
2
|
+
var CacheService = class {
|
|
3
|
+
config;
|
|
4
|
+
memoryCache = /* @__PURE__ */ new Map();
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.config = config;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Generate cache key with prefix
|
|
10
|
+
*/
|
|
11
|
+
generateKey(type, identifier) {
|
|
12
|
+
const parts = [this.config.keyPrefix, type];
|
|
13
|
+
if (identifier) {
|
|
14
|
+
parts.push(identifier);
|
|
15
|
+
}
|
|
16
|
+
return parts.join(":");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get value from cache
|
|
20
|
+
*/
|
|
21
|
+
async get(key) {
|
|
22
|
+
const cached = this.memoryCache.get(key);
|
|
23
|
+
if (!cached) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (Date.now() > cached.expires) {
|
|
27
|
+
this.memoryCache.delete(key);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return cached.value;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get value from cache with source information
|
|
34
|
+
*/
|
|
35
|
+
async getWithSource(key) {
|
|
36
|
+
const cached = this.memoryCache.get(key);
|
|
37
|
+
if (!cached) {
|
|
38
|
+
return {
|
|
39
|
+
hit: false,
|
|
40
|
+
data: null,
|
|
41
|
+
source: "none"
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (Date.now() > cached.expires) {
|
|
45
|
+
this.memoryCache.delete(key);
|
|
46
|
+
return {
|
|
47
|
+
hit: false,
|
|
48
|
+
data: null,
|
|
49
|
+
source: "expired"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
hit: true,
|
|
54
|
+
data: cached.value,
|
|
55
|
+
source: "memory",
|
|
56
|
+
ttl: (cached.expires - Date.now()) / 1e3
|
|
57
|
+
// TTL in seconds
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Set value in cache
|
|
62
|
+
*/
|
|
63
|
+
async set(key, value, ttl) {
|
|
64
|
+
const expires = Date.now() + (ttl || this.config.ttl) * 1e3;
|
|
65
|
+
this.memoryCache.set(key, { value, expires });
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Delete specific key from cache
|
|
69
|
+
*/
|
|
70
|
+
async delete(key) {
|
|
71
|
+
this.memoryCache.delete(key);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Invalidate cache keys matching a pattern
|
|
75
|
+
* For memory cache, we do simple string matching
|
|
76
|
+
*/
|
|
77
|
+
async invalidate(pattern) {
|
|
78
|
+
const regexPattern = pattern.replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
79
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
80
|
+
for (const key of this.memoryCache.keys()) {
|
|
81
|
+
if (regex.test(key)) {
|
|
82
|
+
this.memoryCache.delete(key);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Clear all cache
|
|
88
|
+
*/
|
|
89
|
+
async clear() {
|
|
90
|
+
this.memoryCache.clear();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get value from cache or set it using a callback
|
|
94
|
+
*/
|
|
95
|
+
async getOrSet(key, callback, ttl) {
|
|
96
|
+
const cached = await this.get(key);
|
|
97
|
+
if (cached !== null) {
|
|
98
|
+
return cached;
|
|
99
|
+
}
|
|
100
|
+
const value = await callback();
|
|
101
|
+
await this.set(key, value, ttl);
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var CACHE_CONFIGS = {
|
|
106
|
+
api: {
|
|
107
|
+
ttl: 300,
|
|
108
|
+
// 5 minutes
|
|
109
|
+
keyPrefix: "api"
|
|
110
|
+
},
|
|
111
|
+
user: {
|
|
112
|
+
ttl: 600,
|
|
113
|
+
// 10 minutes
|
|
114
|
+
keyPrefix: "user"
|
|
115
|
+
},
|
|
116
|
+
content: {
|
|
117
|
+
ttl: 300,
|
|
118
|
+
// 5 minutes
|
|
119
|
+
keyPrefix: "content"
|
|
120
|
+
},
|
|
121
|
+
collection: {
|
|
122
|
+
ttl: 600,
|
|
123
|
+
// 10 minutes
|
|
124
|
+
keyPrefix: "collection"
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
function getCacheService(config) {
|
|
128
|
+
return new CacheService(config);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { CACHE_CONFIGS, CacheService, getCacheService };
|
|
132
|
+
//# sourceMappingURL=chunk-3MNMOLSA.js.map
|
|
133
|
+
//# sourceMappingURL=chunk-3MNMOLSA.js.map
|