bunsane 0.1.0 โ 0.1.2
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/.github/workflows/deploy-docs.yml +57 -0
- package/LICENSE.md +1 -1
- package/README.md +2 -28
- package/TODO.md +8 -1
- package/bun.lock +3 -0
- package/config/upload.config.ts +135 -0
- package/core/App.ts +168 -4
- package/core/ArcheType.ts +122 -0
- package/core/BatchLoader.ts +100 -0
- package/core/ComponentRegistry.ts +4 -3
- package/core/Components.ts +2 -2
- package/core/Decorators.ts +15 -8
- package/core/Entity.ts +193 -14
- package/core/EntityCache.ts +15 -0
- package/core/EntityHookManager.ts +855 -0
- package/core/EntityManager.ts +12 -2
- package/core/ErrorHandler.ts +64 -7
- package/core/FileValidator.ts +284 -0
- package/core/Query.ts +503 -85
- package/core/RequestContext.ts +24 -0
- package/core/RequestLoaders.ts +89 -0
- package/core/SchedulerManager.ts +710 -0
- package/core/UploadManager.ts +261 -0
- package/core/components/UploadComponent.ts +206 -0
- package/core/decorators/EntityHooks.ts +190 -0
- package/core/decorators/ScheduledTask.ts +83 -0
- package/core/events/EntityLifecycleEvents.ts +177 -0
- package/core/processors/ImageProcessor.ts +423 -0
- package/core/storage/LocalStorageProvider.ts +290 -0
- package/core/storage/StorageProvider.ts +112 -0
- package/database/DatabaseHelper.ts +183 -58
- package/database/index.ts +5 -5
- package/database/sqlHelpers.ts +7 -0
- package/docs/README.md +149 -0
- package/docs/_coverpage.md +36 -0
- package/docs/_sidebar.md +23 -0
- package/docs/api/core.md +568 -0
- package/docs/api/hooks.md +554 -0
- package/docs/api/index.md +222 -0
- package/docs/api/query.md +678 -0
- package/docs/api/service.md +744 -0
- package/docs/core-concepts/archetypes.md +512 -0
- package/docs/core-concepts/components.md +498 -0
- package/docs/core-concepts/entity.md +314 -0
- package/docs/core-concepts/hooks.md +683 -0
- package/docs/core-concepts/query.md +588 -0
- package/docs/core-concepts/services.md +647 -0
- package/docs/examples/code-examples.md +425 -0
- package/docs/getting-started.md +337 -0
- package/docs/index.html +97 -0
- package/gql/Generator.ts +58 -35
- package/gql/decorators/Upload.ts +176 -0
- package/gql/helpers.ts +67 -0
- package/gql/index.ts +65 -31
- package/gql/types.ts +1 -1
- package/index.ts +79 -11
- package/package.json +19 -10
- package/rest/Generator.ts +3 -0
- package/rest/index.ts +22 -0
- package/service/Service.ts +1 -1
- package/service/ServiceRegistry.ts +10 -6
- package/service/index.ts +12 -1
- package/tests/bench/insert.bench.ts +59 -0
- package/tests/bench/relations.bench.ts +269 -0
- package/tests/bench/sorting.bench.ts +415 -0
- package/tests/component-hooks.test.ts +1409 -0
- package/tests/component.test.ts +338 -0
- package/tests/errorHandling.test.ts +155 -0
- package/tests/hooks.test.ts +666 -0
- package/tests/query-sorting.test.ts +101 -0
- package/tests/relations.test.ts +169 -0
- package/tests/scheduler.test.ts +724 -0
- package/tsconfig.json +35 -34
- package/types/graphql.types.ts +87 -0
- package/types/hooks.types.ts +141 -0
- package/types/scheduler.types.ts +165 -0
- package/types/upload.types.ts +184 -0
- package/upload/index.ts +140 -0
- package/utils/UploadHelper.ts +305 -0
- package/utils/cronParser.ts +366 -0
- package/utils/errorMessages.ts +151 -0
- package/core/Events.ts +0 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
This section provides comprehensive API reference documentation for BunSane framework components, classes, and utilities.
|
|
4
|
+
|
|
5
|
+
## ๐ API Overview
|
|
6
|
+
|
|
7
|
+
BunSane's API is organized into several key modules:
|
|
8
|
+
|
|
9
|
+
- **[Core API](core.md)** - Entity, Component, ArcheType, and base classes
|
|
10
|
+
- **[Query API](query.md)** - Database querying and filtering
|
|
11
|
+
- **[Service API](service.md)** - GraphQL services and resolvers
|
|
12
|
+
- **[Hooks API](hooks.md)** - Lifecycle hooks and event system
|
|
13
|
+
- **[Upload API](upload.md)** - File upload and storage system
|
|
14
|
+
- **[Scheduler API](scheduler.md)** - Background tasks and scheduling
|
|
15
|
+
- **[Database API](database.md)** - Database helpers and utilities
|
|
16
|
+
- **[Utils API](utils.md)** - Utility functions and helpers
|
|
17
|
+
|
|
18
|
+
## ๐ Quick Reference
|
|
19
|
+
|
|
20
|
+
### Core Classes
|
|
21
|
+
|
|
22
|
+
| Class | Description | Location |
|
|
23
|
+
|-------|-------------|----------|
|
|
24
|
+
| `Entity` | Core entity container | `core/Entity.ts` |
|
|
25
|
+
| `BaseComponent` | Component base class | `core/Components.ts` |
|
|
26
|
+
| `ArcheType` | Entity template system | `core/ArcheType.ts` |
|
|
27
|
+
| `Query` | Database query builder | `core/Query.ts` |
|
|
28
|
+
| `BaseService` | Service base class | `service/Service.ts` |
|
|
29
|
+
| `App` | Application bootstrap | `core/App.ts` |
|
|
30
|
+
|
|
31
|
+
### Decorators
|
|
32
|
+
|
|
33
|
+
| Decorator | Description | Usage |
|
|
34
|
+
|-----------|-------------|-------|
|
|
35
|
+
| `@Component` | Mark class as component | `core/Components.ts` |
|
|
36
|
+
| `@CompData` | Mark property as data field | `core/Components.ts` |
|
|
37
|
+
| `@EntityHook` | Register entity lifecycle hook | `core/decorators/EntityHooks.ts` |
|
|
38
|
+
| `@ComponentHook` | Register component lifecycle hook | `core/decorators/EntityHooks.ts` |
|
|
39
|
+
| `@LifecycleHook` | Register general lifecycle hook | `core/decorators/EntityHooks.ts` |
|
|
40
|
+
|
|
41
|
+
### Key Functions
|
|
42
|
+
|
|
43
|
+
| Function | Description | Module |
|
|
44
|
+
|----------|-------------|--------|
|
|
45
|
+
| `Entity.Create()` | Create new entity | `core/Entity.ts` |
|
|
46
|
+
| `Entity.FindById()` | Find entity by ID | `core/Entity.ts` |
|
|
47
|
+
| `Entity.LoadMultiple()` | Load multiple entities | `core/Entity.ts` |
|
|
48
|
+
| `new Query()` | Create query builder | `core/Query.ts` |
|
|
49
|
+
| `ServiceRegistry.register()` | Register service | `service/ServiceRegistry.ts` |
|
|
50
|
+
| `App.start()` | Start application | `core/App.ts` |
|
|
51
|
+
|
|
52
|
+
## ๐ API Documentation Structure
|
|
53
|
+
|
|
54
|
+
Each API reference page includes:
|
|
55
|
+
|
|
56
|
+
- **Class/Function Overview** - Purpose and usage
|
|
57
|
+
- **Constructor Parameters** - Initialization options
|
|
58
|
+
- **Methods** - Available operations with signatures
|
|
59
|
+
- **Properties** - Public properties and their types
|
|
60
|
+
- **Examples** - Practical usage examples
|
|
61
|
+
- **Related Classes** - Connected components
|
|
62
|
+
|
|
63
|
+
## ๐ฏ Getting Started with API Reference
|
|
64
|
+
|
|
65
|
+
### 1. Import Statements
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
// Core imports
|
|
69
|
+
import { Entity, Component, CompData, BaseComponent } from 'bunsane';
|
|
70
|
+
import { ArcheType } from 'bunsane';
|
|
71
|
+
import { Query } from 'bunsane';
|
|
72
|
+
|
|
73
|
+
// Service imports
|
|
74
|
+
import { BaseService, ServiceRegistry } from 'bunsane';
|
|
75
|
+
|
|
76
|
+
// Hook imports
|
|
77
|
+
import { EntityHook, ComponentHook } from 'bunsane';
|
|
78
|
+
|
|
79
|
+
// Advanced imports
|
|
80
|
+
import { BatchLoader } from 'bunsane';
|
|
81
|
+
import { UploadManager } from 'bunsane';
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 2. Type Definitions
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// Component data types
|
|
88
|
+
type UserProfileData = {
|
|
89
|
+
name: string;
|
|
90
|
+
email: string;
|
|
91
|
+
username: string;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Service method signatures
|
|
95
|
+
interface UserService {
|
|
96
|
+
createUser(input: CreateUserInput): Promise<User>;
|
|
97
|
+
getUser(id: string): Promise<User | null>;
|
|
98
|
+
updateUser(id: string, input: UpdateUserInput): Promise<User>;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 3. Error Types
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// Common error types
|
|
106
|
+
class ValidationError extends Error {
|
|
107
|
+
constructor(message: string, field: string) {
|
|
108
|
+
super(message);
|
|
109
|
+
this.field = field;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
class DatabaseError extends Error {
|
|
114
|
+
constructor(message: string, code: string) {
|
|
115
|
+
super(message);
|
|
116
|
+
this.code = code;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## ๐ง API Patterns
|
|
122
|
+
|
|
123
|
+
### Builder Pattern
|
|
124
|
+
|
|
125
|
+
Many BunSane APIs use the builder pattern for fluent interfaces:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Query builder
|
|
129
|
+
const users = await new Query()
|
|
130
|
+
.with(UserProfile)
|
|
131
|
+
.filter('status', 'active')
|
|
132
|
+
.orderBy('name')
|
|
133
|
+
.limit(10)
|
|
134
|
+
.exec();
|
|
135
|
+
|
|
136
|
+
// ArcheType builder
|
|
137
|
+
const userEntity = UserArcheType
|
|
138
|
+
.fill(userData)
|
|
139
|
+
.createEntity();
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Decorator Pattern
|
|
143
|
+
|
|
144
|
+
Decorators are used extensively for metadata and behavior:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
@Component
|
|
148
|
+
class UserProfile extends BaseComponent {
|
|
149
|
+
@CompData({ indexed: true })
|
|
150
|
+
email: string = '';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@EntityHook('entity.created')
|
|
154
|
+
async onUserCreated(event: EntityCreatedEvent) {
|
|
155
|
+
// Hook implementation
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Factory Pattern
|
|
160
|
+
|
|
161
|
+
Factory functions for complex object creation:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
// Service factory
|
|
165
|
+
function createUserService(db: Database): UserService {
|
|
166
|
+
return new UserService(db);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Component factory
|
|
170
|
+
function createUserProfile(data: UserProfileData): UserProfile {
|
|
171
|
+
const component = new UserProfile();
|
|
172
|
+
Object.assign(component, data);
|
|
173
|
+
return component;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## ๐ API Stability
|
|
178
|
+
|
|
179
|
+
### Version Compatibility
|
|
180
|
+
|
|
181
|
+
- **Stable APIs** - Marked with โ
, guaranteed compatibility
|
|
182
|
+
- **Beta APIs** - Marked with โ ๏ธ, may change in future versions
|
|
183
|
+
- **Experimental APIs** - Marked with ๐งช, subject to change
|
|
184
|
+
- **Deprecated APIs** - Marked with โ, will be removed
|
|
185
|
+
|
|
186
|
+
### Breaking Changes
|
|
187
|
+
|
|
188
|
+
Breaking changes follow semantic versioning:
|
|
189
|
+
- **Major version** (X.0.0) - Breaking changes allowed
|
|
190
|
+
- **Minor version** (x.X.0) - New features, backward compatible
|
|
191
|
+
- **Patch version** (x.x.X) - Bug fixes, backward compatible
|
|
192
|
+
|
|
193
|
+
## ๐ Search and Navigation
|
|
194
|
+
|
|
195
|
+
Use the search functionality to quickly find:
|
|
196
|
+
|
|
197
|
+
- Class and method names
|
|
198
|
+
- Property definitions
|
|
199
|
+
- Type definitions
|
|
200
|
+
- Error types
|
|
201
|
+
- Usage examples
|
|
202
|
+
|
|
203
|
+
## ๐ Contributing to API Documentation
|
|
204
|
+
|
|
205
|
+
When contributing to the API documentation:
|
|
206
|
+
|
|
207
|
+
1. **Keep Examples Current** - Update examples when APIs change
|
|
208
|
+
2. **Document Breaking Changes** - Clearly mark breaking changes
|
|
209
|
+
3. **Add Migration Guides** - Provide upgrade paths for breaking changes
|
|
210
|
+
4. **Include Type Information** - Show TypeScript types and interfaces
|
|
211
|
+
5. **Test Examples** - Ensure code examples are runnable
|
|
212
|
+
|
|
213
|
+
## ๐ฏ Next Steps
|
|
214
|
+
|
|
215
|
+
- **[Core API](core.md)** - Start with fundamental classes
|
|
216
|
+
- **[Query API](query.md)** - Learn database operations
|
|
217
|
+
- **[Service API](service.md)** - Build GraphQL services
|
|
218
|
+
- **[Hooks API](hooks.md)** - Add lifecycle behavior
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
*Ready to dive into the APIs? Start with the [Core API](core.md)!* ๐
|