bunsane 0.3.2 → 0.4.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/CHANGELOG.md +445 -370
- package/core/BatchLoader.ts +56 -32
- package/core/Entity.ts +85 -1020
- package/core/EntityHookManager.ts +52 -754
- package/core/Logger.ts +10 -0
- package/core/RequestContext.ts +94 -85
- package/core/RequestLoaders.ts +98 -5
- package/core/SchedulerManager.ts +28 -600
- package/core/app/cors.ts +2 -11
- package/core/app/preparedStatementWarmup.ts +9 -49
- package/core/app/requestRouter.ts +9 -8
- package/core/app/restRegistry.ts +8 -0
- package/core/archetype/fieldResolvers.ts +85 -40
- package/core/archetype/relationLoader.ts +135 -92
- package/core/cache/CacheManager.ts +91 -302
- package/core/cache/CompressionUtils.ts +34 -3
- package/core/cache/MemoryCache.ts +40 -37
- package/core/cache/RedisCache.ts +4 -4
- package/core/cache/health.ts +30 -0
- package/core/cache/invalidation.ts +96 -0
- package/core/cache/strategies/writeInvalidate.ts +111 -0
- package/core/cache/strategies/writeThrough.ts +233 -0
- package/core/components/BaseComponent.ts +16 -8
- package/core/components/ComponentRegistry.ts +28 -0
- package/core/decorators/IndexedField.ts +1 -1
- package/core/entity/cacheStrategies.ts +97 -0
- package/core/entity/componentAccess.ts +364 -0
- package/core/entity/finders.ts +202 -0
- package/core/entity/pendingOps.ts +72 -0
- package/core/entity/saveEntity.ts +377 -0
- package/core/hooks/dispatcher.ts +439 -0
- package/core/hooks/guards.ts +155 -0
- package/core/hooks/registry.ts +247 -0
- package/core/metadata/definitions/Component.ts +1 -1
- package/core/metadata/index.ts +15 -4
- package/core/middleware/RateLimit.ts +102 -105
- package/core/middleware/RequestId.ts +2 -9
- package/core/middleware/SecurityHeaders.ts +2 -11
- package/core/middleware/headers.ts +28 -0
- package/core/remote/OutboxWorker.ts +213 -183
- package/core/remote/RemoteManager.ts +401 -400
- package/core/remote/types.ts +153 -151
- package/core/requestScope.ts +34 -0
- package/core/scheduler/cronEvaluator.ts +174 -0
- package/core/scheduler/lifecycleHooks.ts +21 -0
- package/core/scheduler/lockCoordinator.ts +27 -0
- package/core/scheduler/metrics.ts +14 -0
- package/core/scheduler/taskRunner.ts +420 -0
- package/database/DatabaseHelper.ts +128 -101
- package/database/IndexingStrategy.ts +72 -2
- package/database/PreparedStatementCache.ts +8 -2
- package/database/cancellable.ts +35 -22
- package/database/index.ts +15 -3
- package/database/instrumentedDb.ts +141 -141
- package/endpoints/archetypes.ts +2 -8
- package/endpoints/tables.ts +6 -1
- package/gql/index.ts +1 -1
- package/gql/visitors/ResolverGeneratorVisitor.ts +25 -4
- package/package.json +22 -1
- package/query/CTENode.ts +5 -3
- package/query/ComponentInclusionNode.ts +240 -13
- package/query/OrNode.ts +6 -5
- package/query/Query.ts +157 -46
- package/query/QueryContext.ts +6 -0
- package/query/QueryDAG.ts +7 -2
- package/query/membershipSource.ts +66 -0
- package/storage/LocalStorageProvider.ts +8 -3
- package/studio/dist/assets/index-BMZ67Npg.js +254 -0
- package/studio/dist/assets/index-BpbuYz9g.css +1 -0
- package/studio/{index.html → dist/index.html} +3 -2
- package/swagger/generator.ts +11 -1
- package/upload/UploadManager.ts +8 -6
- package/utils/uuid.ts +40 -10
- package/.claude/scheduled_tasks.lock +0 -1
- package/.claude/settings.local.json +0 -47
- package/.prettierrc +0 -4
- package/.serena/memories/architectural-decision-no-dependency-injection.md +0 -76
- package/.serena/memories/architecture.md +0 -154
- package/.serena/memories/cache-interface-refactoring-2026-01-24.md +0 -165
- package/.serena/memories/code_style_and_conventions.md +0 -76
- package/.serena/memories/project_overview.md +0 -43
- package/.serena/memories/schema-dsl-plan.md +0 -107
- package/.serena/memories/suggested_commands.md +0 -80
- package/.serena/memories/typescript-compilation-status.md +0 -54
- package/.serena/project.yml +0 -114
- package/BunSane.jpg +0 -0
- package/CLAUDE.md +0 -198
- package/TODO.md +0 -2
- package/bun.lock +0 -302
- package/bunfig.toml +0 -10
- package/docs/RFC_APP_REFACTOR.md +0 -248
- package/docs/RFC_REFACTOR_TARGETS.md +0 -251
- package/docs/SCALABILITY_PLAN.md +0 -175
- package/studio/bun.lock +0 -482
- package/studio/package.json +0 -39
- package/studio/postcss.config.js +0 -6
- package/studio/src/components/DataTable.tsx +0 -211
- package/studio/src/components/Layout.tsx +0 -13
- package/studio/src/components/PageContainer.tsx +0 -9
- package/studio/src/components/PageHeader.tsx +0 -13
- package/studio/src/components/SearchBar.tsx +0 -57
- package/studio/src/components/Sidebar.tsx +0 -294
- package/studio/src/components/ui/button.tsx +0 -56
- package/studio/src/components/ui/checkbox.tsx +0 -26
- package/studio/src/components/ui/input.tsx +0 -25
- package/studio/src/hooks/useDataTable.ts +0 -131
- package/studio/src/index.css +0 -36
- package/studio/src/lib/api.ts +0 -186
- package/studio/src/lib/utils.ts +0 -13
- package/studio/src/main.tsx +0 -17
- package/studio/src/pages/ArcheType.tsx +0 -239
- package/studio/src/pages/Components.tsx +0 -124
- package/studio/src/pages/EntityInspector.tsx +0 -302
- package/studio/src/pages/QueryRunner.tsx +0 -246
- package/studio/src/pages/Table.tsx +0 -94
- package/studio/src/pages/Welcome.tsx +0 -241
- package/studio/src/routes.tsx +0 -45
- package/studio/src/store/archeTypeSettings.ts +0 -30
- package/studio/src/store/studio.ts +0 -65
- package/studio/src/utils/columnHelpers.tsx +0 -114
- package/studio/studio-instructions.md +0 -81
- package/studio/tailwind.config.js +0 -77
- package/studio/utils.ts +0 -54
- package/studio/vite.config.js +0 -19
- package/tests/benchmark/BENCHMARK_DATABASES_PLAN.md +0 -338
- package/tests/benchmark/bunfig.toml +0 -9
- package/tests/benchmark/fixtures/EcommerceComponents.ts +0 -283
- package/tests/benchmark/fixtures/EcommerceDataGenerators.ts +0 -301
- package/tests/benchmark/fixtures/RelationTracker.ts +0 -159
- package/tests/benchmark/fixtures/index.ts +0 -6
- package/tests/benchmark/index.ts +0 -22
- package/tests/benchmark/noop-preload.ts +0 -3
- package/tests/benchmark/query-lateral-benchmark.test.ts +0 -372
- package/tests/benchmark/runners/BenchmarkLoader.ts +0 -132
- package/tests/benchmark/runners/index.ts +0 -4
- package/tests/benchmark/scenarios/query-benchmarks.test.ts +0 -465
- package/tests/benchmark/scripts/generate-db.ts +0 -344
- package/tests/benchmark/scripts/run-benchmarks.ts +0 -97
- package/tests/e2e/http.test.ts +0 -130
- package/tests/fixtures/archetypes/TestUserArchetype.ts +0 -21
- package/tests/fixtures/components/TestOrder.ts +0 -23
- package/tests/fixtures/components/TestProduct.ts +0 -23
- package/tests/fixtures/components/TestUser.ts +0 -20
- package/tests/fixtures/components/index.ts +0 -6
- package/tests/graphql/SchemaGeneration.test.ts +0 -90
- package/tests/graphql/builders/ResolverBuilder.test.ts +0 -223
- package/tests/graphql/builders/TypeDefBuilder.test.ts +0 -153
- package/tests/helpers/MockRedisClient.ts +0 -113
- package/tests/helpers/MockRedisStreamServer.ts +0 -448
- package/tests/integration/archetype/ArcheType.persistence.test.ts +0 -241
- package/tests/integration/cache/CacheInvalidation.test.ts +0 -259
- package/tests/integration/entity/Entity.persistence.test.ts +0 -333
- package/tests/integration/entity/Entity.saveTimeout.test.ts +0 -110
- package/tests/integration/loaders/RequestLoaders.abort.test.ts +0 -82
- package/tests/integration/query/Query.abort.test.ts +0 -66
- package/tests/integration/query/Query.complexAnalysis.test.ts +0 -557
- package/tests/integration/query/Query.edgeCases.test.ts +0 -595
- package/tests/integration/query/Query.exec.test.ts +0 -576
- package/tests/integration/query/Query.explainAnalyze.test.ts +0 -233
- package/tests/integration/query/Query.jsonbArray.test.ts +0 -214
- package/tests/integration/remote/dlq.test.ts +0 -175
- package/tests/integration/remote/event-dispatch.test.ts +0 -114
- package/tests/integration/remote/outbox.test.ts +0 -130
- package/tests/integration/remote/rpc.test.ts +0 -177
- package/tests/pglite-setup.ts +0 -62
- package/tests/setup.ts +0 -164
- package/tests/stress/BenchmarkRunner.ts +0 -203
- package/tests/stress/DataSeeder.ts +0 -190
- package/tests/stress/StressTestReporter.ts +0 -229
- package/tests/stress/cursor-perf-test.ts +0 -171
- package/tests/stress/fixtures/RealisticComponents.ts +0 -235
- package/tests/stress/fixtures/StressTestComponents.ts +0 -58
- package/tests/stress/index.ts +0 -7
- package/tests/stress/scenarios/query-benchmarks.test.ts +0 -285
- package/tests/stress/scenarios/realistic-scenarios.test.ts +0 -1081
- package/tests/stress/scenarios/timeout-investigation.test.ts +0 -522
- package/tests/unit/BatchLoader.test.ts +0 -196
- package/tests/unit/archetype/ArcheType.test.ts +0 -107
- package/tests/unit/cache/CacheManager.test.ts +0 -498
- package/tests/unit/cache/MemoryCache.test.ts +0 -260
- package/tests/unit/cache/RedisCache.test.ts +0 -411
- package/tests/unit/database/cancellable.test.ts +0 -81
- package/tests/unit/database/instrumentedDb.test.ts +0 -160
- package/tests/unit/entity/Entity.components.test.ts +0 -317
- package/tests/unit/entity/Entity.drainSideEffects.test.ts +0 -51
- package/tests/unit/entity/Entity.reload.test.ts +0 -63
- package/tests/unit/entity/Entity.requireComponents.test.ts +0 -72
- package/tests/unit/entity/Entity.test.ts +0 -345
- package/tests/unit/gql/depthLimit.test.ts +0 -203
- package/tests/unit/gql/operationMiddleware.test.ts +0 -293
- package/tests/unit/health/Health.test.ts +0 -129
- package/tests/unit/middleware/AccessLog.test.ts +0 -37
- package/tests/unit/middleware/Middleware.test.ts +0 -98
- package/tests/unit/middleware/RequestId.test.ts +0 -54
- package/tests/unit/middleware/SecurityHeaders.test.ts +0 -66
- package/tests/unit/query/FilterBuilder.test.ts +0 -111
- package/tests/unit/query/JsonbArrayBuilder.test.ts +0 -178
- package/tests/unit/query/Query.emptyString.test.ts +0 -69
- package/tests/unit/query/Query.test.ts +0 -310
- package/tests/unit/remote/CircuitBreaker.test.ts +0 -159
- package/tests/unit/remote/RemoteError.test.ts +0 -55
- package/tests/unit/remote/decorators.test.ts +0 -195
- package/tests/unit/remote/metrics.test.ts +0 -115
- package/tests/unit/remote/mockRedisStreamServer.test.ts +0 -104
- package/tests/unit/scheduler/DistributedLock.test.ts +0 -274
- package/tests/unit/scheduler/SchedulerManager.timeBased.test.ts +0 -95
- package/tests/unit/schema/schema-integration.test.ts +0 -426
- package/tests/unit/schema/schema.test.ts +0 -580
- package/tests/unit/storage/S3StorageProvider.test.ts +0 -567
- package/tests/unit/upload/RestUpload.test.ts +0 -267
- package/tests/unit/validateEnv.test.ts +0 -82
- package/tests/utils/entity-tracker.ts +0 -57
- package/tests/utils/index.ts +0 -13
- package/tests/utils/test-context.ts +0 -149
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
# Code Style and Conventions
|
|
2
|
-
|
|
3
|
-
## Formatting
|
|
4
|
-
- **Indentation**: 4 spaces (configured in `.prettierrc`)
|
|
5
|
-
- **No tabs**: Spaces only
|
|
6
|
-
- **Prettier**: Used for formatting
|
|
7
|
-
|
|
8
|
-
## TypeScript Configuration
|
|
9
|
-
- **Strict mode**: Enabled
|
|
10
|
-
- **Experimental decorators**: Enabled
|
|
11
|
-
- **Emit decorator metadata**: Enabled
|
|
12
|
-
- **Module**: ESNext/Preserve
|
|
13
|
-
- **Path alias**: `@/*` maps to `./*`
|
|
14
|
-
|
|
15
|
-
## Naming Conventions
|
|
16
|
-
- **Classes**: PascalCase (e.g., `Entity`, `BaseComponent`, `CacheManager`)
|
|
17
|
-
- **Methods/Functions**: camelCase (e.g., `createEntity`, `getEntityWithID`)
|
|
18
|
-
- **Variables**: camelCase
|
|
19
|
-
- **Constants**: camelCase or UPPER_SNAKE_CASE for environment-like values
|
|
20
|
-
- **Private properties**: Prefix with underscore (e.g., `_dirty`, `_persisted`)
|
|
21
|
-
- **Interfaces**: PascalCase, often prefixed with `I` (e.g., `IEntity`)
|
|
22
|
-
- **Types**: PascalCase
|
|
23
|
-
|
|
24
|
-
## Decorators Usage
|
|
25
|
-
The framework heavily uses TypeScript decorators:
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
// Component definition
|
|
29
|
-
@Component
|
|
30
|
-
class MyComponent extends BaseComponent {
|
|
31
|
-
@CompData()
|
|
32
|
-
myField!: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// ArcheType definition
|
|
36
|
-
class MyArcheType extends BaseArcheType {
|
|
37
|
-
@ArcheTypeField(MyComponent)
|
|
38
|
-
myComponent!: MyComponent;
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Import Style
|
|
43
|
-
- **ALWAYS use relative imports** (`./`, `../`) for all internal modules
|
|
44
|
-
- Do NOT use bare imports like `from "core/Logger"` - they rely on `baseUrl` and break consumer typechecking
|
|
45
|
-
- The `@/` path alias is configured but not used in practice; prefer relative imports
|
|
46
|
-
- Group imports: external packages first, then internal modules
|
|
47
|
-
- **Type-only imports**: Use `import type` for interface/type imports when only used for type checking:
|
|
48
|
-
```typescript
|
|
49
|
-
import type { CacheProvider } from './CacheProvider';
|
|
50
|
-
```
|
|
51
|
-
Benefits: Clearer intent, reduced runtime dependencies, better tree-shaking
|
|
52
|
-
|
|
53
|
-
## Testing Conventions
|
|
54
|
-
- Test files: `*.test.ts`
|
|
55
|
-
- Use Bun's built-in test runner (`bun:test`)
|
|
56
|
-
- Structure: `describe` blocks for grouping, `test` for individual cases
|
|
57
|
-
- Use `beforeAll`/`afterAll` for setup/cleanup
|
|
58
|
-
- Integration tests should clean up created entities
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
|
|
62
|
-
|
|
63
|
-
describe('FeatureName', () => {
|
|
64
|
-
beforeAll(async () => { /* setup */ });
|
|
65
|
-
afterAll(async () => { /* cleanup */ });
|
|
66
|
-
|
|
67
|
-
test('should do something', async () => {
|
|
68
|
-
expect(result).toBe(expected);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Documentation
|
|
74
|
-
- Use JSDoc comments for public APIs
|
|
75
|
-
- Block comments for file headers explaining purpose
|
|
76
|
-
- Inline comments sparingly, only when logic is complex
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# BunSane Project Overview
|
|
2
|
-
|
|
3
|
-
## Purpose
|
|
4
|
-
BunSane is a batteries-included TypeScript API framework for Bun with:
|
|
5
|
-
- Entity–Component storage on PostgreSQL (auto-migrates base tables on first run)
|
|
6
|
-
- Fluent, performant Query builder
|
|
7
|
-
- Zero-boilerplate GraphQL with GraphQL Yoga
|
|
8
|
-
- Declarative Components with decorators and indexed fields
|
|
9
|
-
|
|
10
|
-
**Status**: EXPERIMENTAL - Not Production Ready
|
|
11
|
-
|
|
12
|
-
## Tech Stack
|
|
13
|
-
- **Runtime**: Bun
|
|
14
|
-
- **Language**: TypeScript 5.9+ (strict mode, experimental decorators)
|
|
15
|
-
- **Database**: PostgreSQL
|
|
16
|
-
- **GraphQL**: GraphQL Yoga + GQLoom (@gqloom/core, @gqloom/zod)
|
|
17
|
-
- **Validation**: Zod 4.x
|
|
18
|
-
- **Logging**: Pino (with pino-pretty for development)
|
|
19
|
-
- **Cache**: Memory and Redis support (ioredis)
|
|
20
|
-
- **Data Loading**: dataloader for batching
|
|
21
|
-
|
|
22
|
-
## Key Concepts
|
|
23
|
-
1. **Entity**: Base unit of data storage, identified by UUID
|
|
24
|
-
2. **Component**: Data attached to entities (decorators: @Component, @CompData)
|
|
25
|
-
3. **ArcheType**: Defines a template of components an entity should have
|
|
26
|
-
4. **Query**: Fluent query builder for retrieving entities with components
|
|
27
|
-
5. **Service**: Business logic layer with auto-generated GraphQL schema
|
|
28
|
-
|
|
29
|
-
## Environment Variables
|
|
30
|
-
Database configuration via environment variables:
|
|
31
|
-
- `POSTGRES_HOST`, `POSTGRES_DB`, `POSTGRES_USER`, `POSTGRES_PASSWORD`
|
|
32
|
-
- `POSTGRES_MAX_CONNECTIONS`
|
|
33
|
-
- `LOG_LEVEL`, `LOG_PRETTY`
|
|
34
|
-
|
|
35
|
-
## Cache Configuration
|
|
36
|
-
Cache system supports multiple providers (configured in `config/cache.config.ts`):
|
|
37
|
-
- **Providers**: `memory`, `redis`, `multilevel`
|
|
38
|
-
- **Query cache**: Can be enabled with configurable TTL and max size
|
|
39
|
-
- All providers implement standardized `CacheProvider` interface
|
|
40
|
-
- Wrapper providers available: Analytics, MultiLevel, AdaptiveTTL
|
|
41
|
-
|
|
42
|
-
## Repository
|
|
43
|
-
https://github.com/yaaruu/bunsane
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
# Schema DSL for GraphQL Operation Inputs
|
|
2
|
-
|
|
3
|
-
## Status: Planning Complete, Ready for Implementation
|
|
4
|
-
|
|
5
|
-
**Date**: 2026-02-02
|
|
6
|
-
|
|
7
|
-
## Problem Statement
|
|
8
|
-
|
|
9
|
-
The current Zod → @gqloom → GraphQL pipeline is broken for complex input types:
|
|
10
|
-
- `zod: 4.1.5` (Zod v4 has breaking internal changes)
|
|
11
|
-
- `@gqloom/zod: ^0.12.2` (designed for Zod v3)
|
|
12
|
-
- `generateInputTypeFromZod()` is 360 lines of workarounds that still fail
|
|
13
|
-
|
|
14
|
-
### What's Broken
|
|
15
|
-
- Nested `z.object()` - Broken
|
|
16
|
-
- `.omit()`, `.extend()`, `.partial()` - Broken (empty `_def`)
|
|
17
|
-
- Arrays of objects - Broken
|
|
18
|
-
- Unions - Broken
|
|
19
|
-
- Effects/transforms - Broken
|
|
20
|
-
- Only basic scalars work: `z.string()`, `z.number()`, `z.boolean()`
|
|
21
|
-
|
|
22
|
-
## Solution: Custom Schema DSL
|
|
23
|
-
|
|
24
|
-
Build a purpose-built DSL (~400 lines) that:
|
|
25
|
-
1. Generates GraphQL SDL directly (bypasses @gqloom for inputs)
|
|
26
|
-
2. Uses Zod only for runtime validation
|
|
27
|
-
3. Coexists with existing system (ArcheTypes still use @gqloom for outputs)
|
|
28
|
-
|
|
29
|
-
## API Design
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
import { t } from 'bunsane/schema';
|
|
33
|
-
|
|
34
|
-
@GraphQLOperation({
|
|
35
|
-
type: "Mutation",
|
|
36
|
-
input: {
|
|
37
|
-
email: t.string().email().required(),
|
|
38
|
-
password: t.string().minLength(8).required(),
|
|
39
|
-
settings: t.object({
|
|
40
|
-
theme: t.enum(['light', 'dark'] as const, 'Theme'),
|
|
41
|
-
notifications: t.boolean(),
|
|
42
|
-
}, 'SettingsInput'),
|
|
43
|
-
},
|
|
44
|
-
output: User
|
|
45
|
-
})
|
|
46
|
-
async createUser(input: InferInput<typeof input>) { ... }
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## File Structure
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
schema/
|
|
53
|
-
├── index.ts # Public exports: t, InferInput, SchemaType
|
|
54
|
-
├── types.ts # Core interfaces and constraint types
|
|
55
|
-
├── builders/
|
|
56
|
-
│ ├── index.ts # Export all builders
|
|
57
|
-
│ ├── base.ts # BaseSchemaType abstract class
|
|
58
|
-
│ ├── scalars.ts # StringType, IntType, FloatType, BooleanType, IDType
|
|
59
|
-
│ ├── enum.ts # EnumType
|
|
60
|
-
│ ├── object.ts # ObjectType (nested inputs)
|
|
61
|
-
│ ├── list.ts # ListType (arrays)
|
|
62
|
-
│ └── ref.ts # RefType (reference existing GraphQL types)
|
|
63
|
-
├── generators/
|
|
64
|
-
│ ├── graphql.ts # Generate GraphQL SDL from schema
|
|
65
|
-
│ └── zod.ts # Generate Zod schema from schema
|
|
66
|
-
└── inference.ts # TypeScript type inference helpers
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Implementation Phases
|
|
70
|
-
|
|
71
|
-
### Phase 1: Foundation (Design Complete)
|
|
72
|
-
- [x] Core types and interfaces
|
|
73
|
-
- [x] Scalar types (String, Int, Float, Boolean, ID)
|
|
74
|
-
- [x] `.required()` / `.optional()` / `.nullable()`
|
|
75
|
-
- [x] Basic `toGraphQL()` and `toZod()` generation
|
|
76
|
-
- [ ] Integration point in SchemaGeneratorVisitor
|
|
77
|
-
- [ ] Basic tests
|
|
78
|
-
|
|
79
|
-
### Phase 2: Validation Constraints
|
|
80
|
-
- [ ] String: `.minLength()`, `.maxLength()`, `.email()`, `.url()`, `.uuid()`, `.pattern()`
|
|
81
|
-
- [ ] Number: `.min()`, `.max()`, `.positive()`, `.negative()`
|
|
82
|
-
- [ ] Zod schema generation with constraints
|
|
83
|
-
|
|
84
|
-
### Phase 3: Complex Types
|
|
85
|
-
- [ ] `ObjectType` for nested inputs
|
|
86
|
-
- [ ] `ListType` for arrays
|
|
87
|
-
- [ ] `EnumType` with proper GraphQL enum generation
|
|
88
|
-
- [ ] Nested type definition collection
|
|
89
|
-
|
|
90
|
-
### Phase 4: Polish & Migration
|
|
91
|
-
- [ ] `InferInput<>` type helper
|
|
92
|
-
- [ ] Error messages with field paths
|
|
93
|
-
- [ ] Documentation
|
|
94
|
-
- [ ] Migration guide
|
|
95
|
-
|
|
96
|
-
## Key Design Decisions
|
|
97
|
-
|
|
98
|
-
1. **Single source of truth** - One declaration generates GraphQL SDL + Zod validation + TypeScript types
|
|
99
|
-
2. **No @gqloom for inputs** - Generate SDL directly, use Zod only for runtime validation
|
|
100
|
-
3. **Coexist with existing system** - ArcheTypes still use @gqloom for output types
|
|
101
|
-
4. **Incremental adoption** - Support legacy `GraphQLFieldTypes` alongside new `t.` API
|
|
102
|
-
|
|
103
|
-
## Related Files
|
|
104
|
-
|
|
105
|
-
- Plan document: `plan/schema-dsl-analysis.md`
|
|
106
|
-
- Current broken implementation: `gql/generators/SchemaGeneratorVisitor.ts` (`generateInputTypeFromZod()`)
|
|
107
|
-
- Integration target: `gql/generators/SchemaGeneratorVisitor.ts`
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# Suggested Commands
|
|
2
|
-
|
|
3
|
-
## Development Commands
|
|
4
|
-
|
|
5
|
-
### Running Tests
|
|
6
|
-
```bash
|
|
7
|
-
# Run all tests
|
|
8
|
-
bun test
|
|
9
|
-
|
|
10
|
-
# Run specific test file
|
|
11
|
-
bun test path/to/file.test.ts
|
|
12
|
-
|
|
13
|
-
# Run tests matching a pattern
|
|
14
|
-
bun test --filter "pattern"
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Test configuration is in `bunfig.toml`:
|
|
18
|
-
- Preloads `./test/setup.ts` for database initialization
|
|
19
|
-
- 30-second timeout for integration tests
|
|
20
|
-
- Uses `smol = true` to limit parallelism (avoids DB connection pool exhaustion)
|
|
21
|
-
|
|
22
|
-
### Building
|
|
23
|
-
```bash
|
|
24
|
-
# Full build (includes studio)
|
|
25
|
-
bun run build
|
|
26
|
-
|
|
27
|
-
# Build studio only
|
|
28
|
-
bun run build:studio
|
|
29
|
-
|
|
30
|
-
# Watch mode for development
|
|
31
|
-
bun run dev
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Type Checking
|
|
35
|
-
```bash
|
|
36
|
-
# Run TypeScript compiler
|
|
37
|
-
tsc
|
|
38
|
-
|
|
39
|
-
# Watch mode
|
|
40
|
-
tsc --watch
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Dead Code Detection
|
|
44
|
-
```bash
|
|
45
|
-
# Run knip for dead code detection
|
|
46
|
-
bunx knip
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Git Commands (Windows)
|
|
50
|
-
```bash
|
|
51
|
-
git status
|
|
52
|
-
git add .
|
|
53
|
-
git commit -m "message"
|
|
54
|
-
git push
|
|
55
|
-
git pull
|
|
56
|
-
git log --oneline -10
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## File Operations (Windows)
|
|
60
|
-
```bash
|
|
61
|
-
# List directory
|
|
62
|
-
dir
|
|
63
|
-
ls # works in Git Bash / PowerShell
|
|
64
|
-
|
|
65
|
-
# Find files
|
|
66
|
-
dir /s /b *.ts
|
|
67
|
-
Get-ChildItem -Recurse -Filter "*.ts" # PowerShell
|
|
68
|
-
|
|
69
|
-
# Search in files
|
|
70
|
-
findstr /s /i "pattern" *.ts
|
|
71
|
-
Select-String -Path "*.ts" -Pattern "pattern" -Recurse # PowerShell
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Database
|
|
75
|
-
The framework uses PostgreSQL. Ensure a PostgreSQL instance is running and configured via `.env.test` or environment variables.
|
|
76
|
-
|
|
77
|
-
## Environment Setup
|
|
78
|
-
1. Copy `.env.test` to `.env` for local development
|
|
79
|
-
2. Configure PostgreSQL connection
|
|
80
|
-
3. Run `bun install` for dependencies
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# TypeScript Compilation Status
|
|
2
|
-
|
|
3
|
-
**Last Updated**: 2026-02-05
|
|
4
|
-
**Current Error Count**: 69 (down from 100+)
|
|
5
|
-
|
|
6
|
-
## Recent Improvements
|
|
7
|
-
|
|
8
|
-
### Cache Interface Standardization (2026-01-24)
|
|
9
|
-
**Errors Resolved**: 30+ cache-related errors
|
|
10
|
-
**Status**: COMPLETE
|
|
11
|
-
|
|
12
|
-
All cache-related TypeScript errors have been resolved by standardizing implementations of the `CacheProvider` interface. See `cache-interface-refactoring-2026-01-24` memory for details.
|
|
13
|
-
|
|
14
|
-
## Remaining Error Categories
|
|
15
|
-
|
|
16
|
-
### 1. SchedulerManager (Priority: High)
|
|
17
|
-
- Location: `scheduler/` directory
|
|
18
|
-
- Issue: Interface or implementation mismatches
|
|
19
|
-
- Status: Not yet addressed
|
|
20
|
-
|
|
21
|
-
### 2. GraphQL Builders (Priority: Medium)
|
|
22
|
-
- Location: `gql/builders/` directory
|
|
23
|
-
- Issue: Schema generation type issues
|
|
24
|
-
- Status: Not yet addressed
|
|
25
|
-
|
|
26
|
-
### 3. Test Access to Private Members (Priority: Low)
|
|
27
|
-
- Location: Various test files
|
|
28
|
-
- Issue: Tests accessing private class members
|
|
29
|
-
- Status: Not yet addressed
|
|
30
|
-
- Note: These are test-specific and don't affect production code
|
|
31
|
-
|
|
32
|
-
## Strategy for Further Reduction
|
|
33
|
-
|
|
34
|
-
1. **Next Target**: SchedulerManager errors (highest priority)
|
|
35
|
-
2. **Approach**: Similar to cache refactoring - identify interface, ensure implementations match
|
|
36
|
-
3. **Goal**: Reduce to <50 errors by addressing scheduler issues
|
|
37
|
-
4. **Long-term**: Aim for zero compilation errors
|
|
38
|
-
|
|
39
|
-
## Metrics
|
|
40
|
-
|
|
41
|
-
| Date | Error Count | Category Resolved | Notes |
|
|
42
|
-
|------|-------------|-------------------|-------|
|
|
43
|
-
| 2026-02-05 | 69 | Import Resolution | Converted 37 bare imports to relative paths across 18 files |
|
|
44
|
-
| 2026-01-24 | 69 | Cache System | Standardized CacheProvider interface |
|
|
45
|
-
| Prior | 100+ | - | Baseline before cache refactoring |
|
|
46
|
-
|
|
47
|
-
## Best Practices Established
|
|
48
|
-
|
|
49
|
-
1. Define clear interfaces before implementations
|
|
50
|
-
2. Use `import type` for type-only imports
|
|
51
|
-
3. Keep wrapper classes in sync with base interfaces
|
|
52
|
-
4. Add explicit type parameters in tests for type safety
|
|
53
|
-
5. Document interface contracts in code and memories
|
|
54
|
-
6. Always use relative imports - bare imports relying on baseUrl break consumer typechecking
|
package/.serena/project.yml
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
# list of languages for which language servers are started; choose from:
|
|
2
|
-
# al bash clojure cpp csharp
|
|
3
|
-
# csharp_omnisharp dart elixir elm erlang
|
|
4
|
-
# fortran fsharp go groovy haskell
|
|
5
|
-
# java julia kotlin lua markdown
|
|
6
|
-
# matlab nix pascal perl php
|
|
7
|
-
# powershell python python_jedi r rego
|
|
8
|
-
# ruby ruby_solargraph rust scala swift
|
|
9
|
-
# terraform toml typescript typescript_vts vue
|
|
10
|
-
# yaml zig
|
|
11
|
-
# (This list may be outdated. For the current list, see values of Language enum here:
|
|
12
|
-
# https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py
|
|
13
|
-
# For some languages, there are alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
|
|
14
|
-
# Note:
|
|
15
|
-
# - For C, use cpp
|
|
16
|
-
# - For JavaScript, use typescript
|
|
17
|
-
# - For Free Pascal/Lazarus, use pascal
|
|
18
|
-
# Special requirements:
|
|
19
|
-
# - csharp: Requires the presence of a .sln file in the project folder.
|
|
20
|
-
# - pascal: Requires Free Pascal Compiler (fpc) and optionally Lazarus.
|
|
21
|
-
# When using multiple languages, the first language server that supports a given file will be used for that file.
|
|
22
|
-
# The first language is the default language and the respective language server will be used as a fallback.
|
|
23
|
-
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
|
|
24
|
-
languages:
|
|
25
|
-
- typescript
|
|
26
|
-
|
|
27
|
-
# the encoding used by text files in the project
|
|
28
|
-
# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
|
|
29
|
-
encoding: "utf-8"
|
|
30
|
-
|
|
31
|
-
# whether to use project's .gitignore files to ignore files
|
|
32
|
-
ignore_all_files_in_gitignore: true
|
|
33
|
-
|
|
34
|
-
# list of additional paths to ignore in all projects
|
|
35
|
-
# same syntax as gitignore, so you can use * and **
|
|
36
|
-
ignored_paths: []
|
|
37
|
-
|
|
38
|
-
# whether the project is in read-only mode
|
|
39
|
-
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
|
|
40
|
-
# Added on 2025-04-18
|
|
41
|
-
read_only: false
|
|
42
|
-
|
|
43
|
-
# list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.
|
|
44
|
-
# Below is the complete list of tools for convenience.
|
|
45
|
-
# To make sure you have the latest list of tools, and to view their descriptions,
|
|
46
|
-
# execute `uv run scripts/print_tool_overview.py`.
|
|
47
|
-
#
|
|
48
|
-
# * `activate_project`: Activates a project by name.
|
|
49
|
-
# * `check_onboarding_performed`: Checks whether project onboarding was already performed.
|
|
50
|
-
# * `create_text_file`: Creates/overwrites a file in the project directory.
|
|
51
|
-
# * `delete_lines`: Deletes a range of lines within a file.
|
|
52
|
-
# * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
|
|
53
|
-
# * `execute_shell_command`: Executes a shell command.
|
|
54
|
-
# * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
|
|
55
|
-
# * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
|
|
56
|
-
# * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
|
|
57
|
-
# * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
|
|
58
|
-
# * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.
|
|
59
|
-
# * `initial_instructions`: Gets the initial instructions for the current project.
|
|
60
|
-
# Should only be used in settings where the system prompt cannot be set,
|
|
61
|
-
# e.g. in clients you have no control over, like Claude Desktop.
|
|
62
|
-
# * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
|
|
63
|
-
# * `insert_at_line`: Inserts content at a given line in a file.
|
|
64
|
-
# * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
|
|
65
|
-
# * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
|
|
66
|
-
# * `list_memories`: Lists memories in Serena's project-specific memory store.
|
|
67
|
-
# * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
|
|
68
|
-
# * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
|
|
69
|
-
# * `read_file`: Reads a file within the project directory.
|
|
70
|
-
# * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
|
|
71
|
-
# * `remove_project`: Removes a project from the Serena configuration.
|
|
72
|
-
# * `replace_lines`: Replaces a range of lines within a file with new content.
|
|
73
|
-
# * `replace_symbol_body`: Replaces the full definition of a symbol.
|
|
74
|
-
# * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
|
|
75
|
-
# * `search_for_pattern`: Performs a search for a pattern in the project.
|
|
76
|
-
# * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
|
|
77
|
-
# * `switch_modes`: Activates modes by providing a list of their names
|
|
78
|
-
# * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
|
|
79
|
-
# * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
|
|
80
|
-
# * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
|
|
81
|
-
# * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
|
|
82
|
-
excluded_tools: []
|
|
83
|
-
|
|
84
|
-
# initial prompt for the project. It will always be given to the LLM upon activating the project
|
|
85
|
-
# (contrary to the memories, which are loaded on demand).
|
|
86
|
-
initial_prompt: ""
|
|
87
|
-
# the name by which the project can be referenced within Serena
|
|
88
|
-
project_name: "bunsane"
|
|
89
|
-
|
|
90
|
-
# list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default)
|
|
91
|
-
included_optional_tools: []
|
|
92
|
-
|
|
93
|
-
# list of mode names to that are always to be included in the set of active modes
|
|
94
|
-
# The full set of modes to be activated is base_modes + default_modes.
|
|
95
|
-
# If the setting is undefined, the base_modes from the global configuration (serena_config.yml) apply.
|
|
96
|
-
# Otherwise, this setting overrides the global configuration.
|
|
97
|
-
# Set this to [] to disable base modes for this project.
|
|
98
|
-
# Set this to a list of mode names to always include the respective modes for this project.
|
|
99
|
-
base_modes:
|
|
100
|
-
|
|
101
|
-
# list of mode names that are to be activated by default.
|
|
102
|
-
# The full set of modes to be activated is base_modes + default_modes.
|
|
103
|
-
# If the setting is undefined, the default_modes from the global configuration (serena_config.yml) apply.
|
|
104
|
-
# Otherwise, this overrides the setting from the global configuration (serena_config.yml).
|
|
105
|
-
# This setting can, in turn, be overridden by CLI parameters (--mode).
|
|
106
|
-
default_modes:
|
|
107
|
-
|
|
108
|
-
# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.
|
|
109
|
-
# This cannot be combined with non-empty excluded_tools or included_optional_tools.
|
|
110
|
-
fixed_tools: []
|
|
111
|
-
|
|
112
|
-
# override of the corresponding setting in serena_config.yml, see the documentation there.
|
|
113
|
-
# If null or missing, the value from the global config is used.
|
|
114
|
-
symbol_info_budget:
|
package/BunSane.jpg
DELETED
|
Binary file
|
package/CLAUDE.md
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Project Overview
|
|
6
|
-
|
|
7
|
-
BunSane is an experimental TypeScript API framework for Bun using Entity-Component-System (ECS) architecture with PostgreSQL storage. It provides GraphQL Yoga integration with automatic schema generation from decorated services.
|
|
8
|
-
|
|
9
|
-
**Stack**: Bun, TypeScript, PostgreSQL, GraphQL Yoga, GQLoom, Zod 4.x, Pino logging
|
|
10
|
-
|
|
11
|
-
## Commands
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
# Install dependencies
|
|
15
|
-
bun install
|
|
16
|
-
|
|
17
|
-
# Build (includes studio + typecheck)
|
|
18
|
-
bun run build
|
|
19
|
-
|
|
20
|
-
# Typecheck only
|
|
21
|
-
tsc --noEmit
|
|
22
|
-
|
|
23
|
-
# Tests (requires PostgreSQL)
|
|
24
|
-
bun test # Unit + integration + GraphQL tests
|
|
25
|
-
bun run test:unit # Unit tests only
|
|
26
|
-
bun run test:integration # Integration tests only
|
|
27
|
-
bun run test:graphql # GraphQL schema tests only
|
|
28
|
-
|
|
29
|
-
# Tests with PGlite (no PostgreSQL required)
|
|
30
|
-
bun run test:pglite # All tests with PGlite
|
|
31
|
-
bun run test:pglite:unit # Unit tests only with PGlite
|
|
32
|
-
|
|
33
|
-
# E2E and stress tests
|
|
34
|
-
bun run test:e2e # HTTP tests (no DB needed)
|
|
35
|
-
bun run test:stress # Performance benchmarks
|
|
36
|
-
|
|
37
|
-
# Run single test file
|
|
38
|
-
bun test path/to/file.test.ts
|
|
39
|
-
|
|
40
|
-
# Run tests matching pattern
|
|
41
|
-
bun test --grep "pattern"
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Architecture
|
|
45
|
-
|
|
46
|
-
### ECS Model
|
|
47
|
-
- **Entities**: Generic containers with UUID, stored in `entities` table
|
|
48
|
-
- **Components**: Data containers attached to entities, stored in `components` table with JSONB data
|
|
49
|
-
- **Services**: Business logic with GraphQL operations
|
|
50
|
-
|
|
51
|
-
### Core Classes
|
|
52
|
-
|
|
53
|
-
**Entity** (`core/Entity.ts`):
|
|
54
|
-
```typescript
|
|
55
|
-
const entity = Entity.Create();
|
|
56
|
-
entity.add(Position, { x: 0, y: 0 }); // Add component
|
|
57
|
-
await entity.set(Position, { x: 10 }); // Update component
|
|
58
|
-
const pos = await entity.get(Position); // Get component data
|
|
59
|
-
await entity.save();
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
**BaseComponent** (`core/components/BaseComponent.ts`):
|
|
63
|
-
```typescript
|
|
64
|
-
@Component
|
|
65
|
-
class Position extends BaseComponent {
|
|
66
|
-
@CompData() x: number = 0;
|
|
67
|
-
@CompData({ indexed: true }) y: number = 0; // Creates DB index
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
**BaseArcheType** (`core/ArcheType.ts`):
|
|
72
|
-
- Predefined entity templates with required components
|
|
73
|
-
- Auto-generates GraphQL types and CRUD operations
|
|
74
|
-
|
|
75
|
-
**Query** (`query/Query.ts`):
|
|
76
|
-
```typescript
|
|
77
|
-
const entities = await new Query()
|
|
78
|
-
.with(Position) // Require component
|
|
79
|
-
.with(Velocity, { filters: [...] }) // With filters
|
|
80
|
-
.populate() // Load all components
|
|
81
|
-
.limit(10)
|
|
82
|
-
.exec();
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
**BaseService** (`service/Service.ts`):
|
|
86
|
-
```typescript
|
|
87
|
-
class UserService extends BaseService {
|
|
88
|
-
@GraphQLOperation({ type: "Query", input: { id: t.id() }, output: User })
|
|
89
|
-
async getUser(input: { id: string }, ctx: GraphQLContext) { ... }
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### GraphQL
|
|
94
|
-
|
|
95
|
-
- Schema generated automatically from decorated services and archetypes
|
|
96
|
-
- Input types use Schema DSL (`gql/schema/index.ts`) via `t.` API
|
|
97
|
-
- Operations: `@GraphQLOperation`, `@GraphQLSubscription`
|
|
98
|
-
- Archetypes: `@ArcheTypeFunction` for computed fields
|
|
99
|
-
|
|
100
|
-
### Database
|
|
101
|
-
|
|
102
|
-
- PostgreSQL with Bun's native SQL driver (`Bun.SQL`)
|
|
103
|
-
- Auto-migrations on startup for base tables
|
|
104
|
-
- Component data stored as JSONB
|
|
105
|
-
- Indexed fields create GIN indexes automatically
|
|
106
|
-
|
|
107
|
-
### Caching
|
|
108
|
-
|
|
109
|
-
- Multi-level cache: L1 (memory) + L2 (Redis)
|
|
110
|
-
- `CacheManager.initialize(config)` is async - always await it
|
|
111
|
-
- Strategies: write-through, write-invalidate
|
|
112
|
-
- Cross-instance invalidation via Redis pub/sub
|
|
113
|
-
|
|
114
|
-
### File Uploads
|
|
115
|
-
|
|
116
|
-
- `UploadManager` handles file validation and storage
|
|
117
|
-
- `S3StorageProvider` for S3-compatible storage (AWS, MinIO, R2)
|
|
118
|
-
- REST: `handleUpload(req)` from `upload/RestUpload.ts`
|
|
119
|
-
- GraphQL: `@Upload()` decorator
|
|
120
|
-
|
|
121
|
-
## Critical Rules
|
|
122
|
-
|
|
123
|
-
### Import Style
|
|
124
|
-
**ALWAYS use relative imports** (`./`, `../`) for internal modules. Never use bare imports like `from "core/Logger"` - this breaks consumer typechecking.
|
|
125
|
-
|
|
126
|
-
### Architecture Decisions
|
|
127
|
-
- No Dependency Injection - uses singletons + global exports
|
|
128
|
-
- Singleton access: `CacheManager.getInstance()`, `EntityManager.instance`, etc.
|
|
129
|
-
- Services registered via `ServiceRegistry.register()`
|
|
130
|
-
|
|
131
|
-
### Test Database Setup
|
|
132
|
-
- Tests require `.env.test` with PostgreSQL config (or use PGlite mode)
|
|
133
|
-
- `bunfig.toml` preloads `tests/setup.ts`
|
|
134
|
-
- PGlite: `CREATE INDEX CONCURRENTLY` must check `process.env.USE_PGLITE`
|
|
135
|
-
- PGlite JSONB: pass JS objects directly, never `JSON.stringify() + ::jsonb`
|
|
136
|
-
|
|
137
|
-
### Running Tests with PGlite
|
|
138
|
-
|
|
139
|
-
**IMPORTANT**: To run tests with PGlite, always use `tests/pglite-setup.ts` as the entry point. This script starts an in-memory PostgreSQL server before spawning the test runner.
|
|
140
|
-
|
|
141
|
-
```bash
|
|
142
|
-
# Correct - uses pglite-setup.ts wrapper
|
|
143
|
-
bun run test:pglite # All tests
|
|
144
|
-
bun run test:pglite:unit # Unit tests only
|
|
145
|
-
bun tests/pglite-setup.ts tests/unit/ # Specific directory
|
|
146
|
-
bun tests/pglite-setup.ts path/to/file.test.ts # Single file
|
|
147
|
-
|
|
148
|
-
# WRONG - will fail with connection errors
|
|
149
|
-
USE_PGLITE=true bun test path/to/file.test.ts # Won't work!
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
The wrapper script:
|
|
153
|
-
1. Starts PGlite Socket server on port 54321
|
|
154
|
-
2. Sets required env vars (`USE_PGLITE`, `POSTGRES_*`)
|
|
155
|
-
3. Spawns `bun test` with correct configuration
|
|
156
|
-
4. Cleans up server on exit
|
|
157
|
-
|
|
158
|
-
**PGlite limitations:**
|
|
159
|
-
- `?|` and `?&` operators not supported (use `@>` / `<@` instead)
|
|
160
|
-
- `CREATE INDEX CONCURRENTLY` not supported
|
|
161
|
-
- Single connection only (`POSTGRES_MAX_CONNECTIONS=1`)
|
|
162
|
-
- **Known Bun SQL + PGlite visibility race**: under a single-connection
|
|
163
|
-
pool with background work from a prior test file, `await entity.save()`
|
|
164
|
-
may resolve ≥1ms before the `INSERT INTO entity_components` row is
|
|
165
|
-
visible to a subsequent `db.unsafe('SELECT ...')` on the same driver.
|
|
166
|
-
The per-component partition INSERT (e.g. `components_<compname>`) in
|
|
167
|
-
the same transaction is visible immediately; only the flat
|
|
168
|
-
`entity_components` row lags. This causes multi-component Query
|
|
169
|
-
INTERSECTs to return 0 rows when run immediately after save.
|
|
170
|
-
|
|
171
|
-
**Mitigation (not a full fix):**
|
|
172
|
-
1. Shut down application-owned background workers (AI processors,
|
|
173
|
-
outbox workers, hook-driven save chains) in `afterAll` of each test
|
|
174
|
-
file — prevents cross-file bleed that amplifies the race.
|
|
175
|
-
2. Call `await Entity.drainPendingSideEffects()` in `beforeAll` / test
|
|
176
|
-
`setup` to settle hook-triggered post-commit work (helpful but
|
|
177
|
-
insufficient on its own).
|
|
178
|
-
3. Skip the affected test or poll with a short `setTimeout(1)`.
|
|
179
|
-
|
|
180
|
-
Root cause lives in the Bun SQL adapter's ACK handling, not bunsane.
|
|
181
|
-
File upstream with a minimal repro if you hit this.
|
|
182
|
-
|
|
183
|
-
## Directory Structure
|
|
184
|
-
|
|
185
|
-
```
|
|
186
|
-
core/ # ECS core: Entity, Component, ArcheType, App
|
|
187
|
-
cache/ # CacheManager, Redis, Memory caches
|
|
188
|
-
components/ # BaseComponent, decorators, registry
|
|
189
|
-
middleware/ # HTTP middleware (AccessLog, RequestId, SecurityHeaders)
|
|
190
|
-
database/ # DatabaseHelper, SQL utilities
|
|
191
|
-
gql/ # GraphQL generation, Schema DSL
|
|
192
|
-
schema/ # t.* Schema DSL for inputs
|
|
193
|
-
query/ # Fluent Query builder, FilterBuilder
|
|
194
|
-
service/ # BaseService, ServiceRegistry
|
|
195
|
-
upload/ # File uploads, S3StorageProvider
|
|
196
|
-
scheduler/ # Cron-style task scheduling
|
|
197
|
-
tests/ # Unit, integration, GraphQL, E2E, stress tests
|
|
198
|
-
```
|
package/TODO.md
DELETED