ai-database 2.0.1 → 2.1.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/actions.d.ts +247 -0
  3. package/dist/actions.d.ts.map +1 -0
  4. package/dist/actions.js +260 -0
  5. package/dist/actions.js.map +1 -0
  6. package/dist/ai-promise-db.d.ts +34 -2
  7. package/dist/ai-promise-db.d.ts.map +1 -1
  8. package/dist/ai-promise-db.js +511 -66
  9. package/dist/ai-promise-db.js.map +1 -1
  10. package/dist/constants.d.ts +16 -0
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/constants.js +16 -0
  13. package/dist/constants.js.map +1 -0
  14. package/dist/events.d.ts +153 -0
  15. package/dist/events.d.ts.map +1 -0
  16. package/dist/events.js +154 -0
  17. package/dist/events.js.map +1 -0
  18. package/dist/index.d.ts +8 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +13 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/memory-provider.d.ts +144 -2
  23. package/dist/memory-provider.d.ts.map +1 -1
  24. package/dist/memory-provider.js +569 -13
  25. package/dist/memory-provider.js.map +1 -1
  26. package/dist/schema/cascade.d.ts +96 -0
  27. package/dist/schema/cascade.d.ts.map +1 -0
  28. package/dist/schema/cascade.js +528 -0
  29. package/dist/schema/cascade.js.map +1 -0
  30. package/dist/schema/index.d.ts +197 -0
  31. package/dist/schema/index.d.ts.map +1 -0
  32. package/dist/schema/index.js +1211 -0
  33. package/dist/schema/index.js.map +1 -0
  34. package/dist/schema/parse.d.ts +225 -0
  35. package/dist/schema/parse.d.ts.map +1 -0
  36. package/dist/schema/parse.js +732 -0
  37. package/dist/schema/parse.js.map +1 -0
  38. package/dist/schema/provider.d.ts +176 -0
  39. package/dist/schema/provider.d.ts.map +1 -0
  40. package/dist/schema/provider.js +258 -0
  41. package/dist/schema/provider.js.map +1 -0
  42. package/dist/schema/resolve.d.ts +87 -0
  43. package/dist/schema/resolve.d.ts.map +1 -0
  44. package/dist/schema/resolve.js +474 -0
  45. package/dist/schema/resolve.js.map +1 -0
  46. package/dist/schema/semantic.d.ts +53 -0
  47. package/dist/schema/semantic.d.ts.map +1 -0
  48. package/dist/schema/semantic.js +247 -0
  49. package/dist/schema/semantic.js.map +1 -0
  50. package/dist/schema/types.d.ts +528 -0
  51. package/dist/schema/types.d.ts.map +1 -0
  52. package/dist/schema/types.js +9 -0
  53. package/dist/schema/types.js.map +1 -0
  54. package/dist/schema.d.ts +24 -867
  55. package/dist/schema.d.ts.map +1 -1
  56. package/dist/schema.js +41 -1124
  57. package/dist/schema.js.map +1 -1
  58. package/dist/semantic.d.ts +175 -0
  59. package/dist/semantic.d.ts.map +1 -0
  60. package/dist/semantic.js +338 -0
  61. package/dist/semantic.js.map +1 -0
  62. package/dist/types.d.ts +14 -0
  63. package/dist/types.d.ts.map +1 -1
  64. package/dist/types.js.map +1 -1
  65. package/package.json +13 -4
  66. package/.turbo/turbo-build.log +0 -5
  67. package/TESTING.md +0 -410
  68. package/TEST_SUMMARY.md +0 -250
  69. package/TODO.md +0 -128
  70. package/src/ai-promise-db.ts +0 -1243
  71. package/src/authorization.ts +0 -1102
  72. package/src/durable-clickhouse.ts +0 -596
  73. package/src/durable-promise.ts +0 -582
  74. package/src/execution-queue.ts +0 -608
  75. package/src/index.test.ts +0 -868
  76. package/src/index.ts +0 -337
  77. package/src/linguistic.ts +0 -404
  78. package/src/memory-provider.test.ts +0 -1036
  79. package/src/memory-provider.ts +0 -1119
  80. package/src/schema.test.ts +0 -1254
  81. package/src/schema.ts +0 -2296
  82. package/src/tests.ts +0 -725
  83. package/src/types.ts +0 -1177
  84. package/test/README.md +0 -153
  85. package/test/edge-cases.test.ts +0 -646
  86. package/test/provider-resolution.test.ts +0 -402
  87. package/tsconfig.json +0 -9
  88. package/vitest.config.ts +0 -19
package/test/README.md DELETED
@@ -1,153 +0,0 @@
1
- # ai-database Test Suite
2
-
3
- This directory contains comprehensive tests for the ai-database package.
4
-
5
- ## Test Coverage
6
-
7
- ### Schema Tests (`src/schema.test.ts`)
8
- - **Primitive fields**: All basic types (string, number, boolean, date, datetime, json, markdown, url)
9
- - **Optional fields**: Fields with `?` modifier
10
- - **Array fields**: Both `[]` syntax and `[type]` literal syntax
11
- - **Relations**: Simple and bi-directional relationships
12
- - **Backref generation**: Automatic creation of inverse relationships
13
- - **Complex schemas**: Multi-entity schemas with various field combinations
14
- - **Type inference**: TypeScript type safety verification
15
-
16
- ### Memory Provider Tests (`src/memory-provider.test.ts`)
17
- - **CRUD operations**: Create, read, update, delete
18
- - **List and query**: Filtering, sorting, pagination
19
- - **Search**: Full-text search with scoring
20
- - **Relationships**: Creating and querying related entities
21
- - **Concurrency**: Multiple simultaneous operations
22
- - **Utility methods**: `clear()` and `stats()`
23
-
24
- ### Integration Tests (`src/index.test.ts`)
25
- - **DB factory**: Creating typed database instances
26
- - **Entity operations**: All CRUD methods on typed entities
27
- - **List and pagination**: Query options and result limiting
28
- - **Search**: Entity and global search
29
- - **Relationships**: Managing relations between entities
30
- - **Global methods**: `db.get()` and `db.search()`
31
- - **Type safety**: Verifying TypeScript inference
32
- - **Complex scenarios**: Multi-entity operations and self-referential relations
33
-
34
- ### Provider Resolution Tests (`test/provider-resolution.test.ts`)
35
- - **URL parsing**: All DATABASE_URL formats
36
- - In-memory: `:memory:`
37
- - Filesystem: `./content`
38
- - SQLite: `sqlite://./content`
39
- - Turso: `libsql://db.turso.io`
40
- - ClickHouse (local): `chdb://./content`
41
- - ClickHouse (remote): `clickhouse://host:8123`
42
- - **Provider initialization**: Memory provider setup
43
- - **Interface compliance**: Ensuring providers implement all required methods
44
- - **Error handling**: Invalid URLs and missing dependencies
45
-
46
- ### Edge Cases Tests (`test/edge-cases.test.ts`)
47
- - **Empty schemas**: Handling minimal configurations
48
- - **Special characters**: IDs and data with unicode, symbols, paths
49
- - **Large data**: Big strings, many entities, large result sets
50
- - **Concurrent operations**: Parallel creates, updates, and queries
51
- - **Optional fields**: Missing and undefined values
52
- - **Array fields**: Empty arrays and array updates
53
- - **URL parsing**: Various URL formats and edge cases
54
- - **Search edge cases**: Empty queries, special characters, extreme scores
55
- - **Pagination edge cases**: Out-of-bounds offsets, zero/negative limits
56
-
57
- ## Running Tests
58
-
59
- ```bash
60
- # Run all tests
61
- pnpm test
62
-
63
- # Run tests once (no watch)
64
- pnpm test run
65
-
66
- # Run specific test file
67
- pnpm test src/schema.test.ts
68
-
69
- # Run with coverage
70
- pnpm test --coverage
71
- ```
72
-
73
- ## Test Statistics
74
-
75
- - **Total test files**: 5
76
- - **Total tests**: 174
77
- - **Coverage areas**:
78
- - Schema parsing and validation
79
- - In-memory database operations
80
- - Provider interface compliance
81
- - Database URL parsing
82
- - Edge cases and error handling
83
-
84
- ## Test Patterns
85
-
86
- ### Using the Memory Provider
87
-
88
- ```typescript
89
- import { setProvider, createMemoryProvider } from './index.js'
90
-
91
- beforeEach(() => {
92
- setProvider(createMemoryProvider())
93
- })
94
- ```
95
-
96
- ### Testing Schemas
97
-
98
- ```typescript
99
- const schema = {
100
- User: {
101
- name: 'string',
102
- email: 'string',
103
- },
104
- } as const
105
-
106
- const db = DB(schema)
107
- ```
108
-
109
- ### Testing CRUD Operations
110
-
111
- ```typescript
112
- // Create
113
- const user = await db.User.create('john', { name: 'John' })
114
-
115
- // Read
116
- const retrieved = await db.User.get('john')
117
-
118
- // Update
119
- const updated = await db.User.update('john', { name: 'Jane' })
120
-
121
- // Delete
122
- const deleted = await db.User.delete('john')
123
- ```
124
-
125
- ### Testing Relationships
126
-
127
- ```typescript
128
- const provider = createMemoryProvider()
129
- setProvider(provider)
130
-
131
- await provider.relate('User', 'john', 'posts', 'Post', 'post1')
132
- const posts = await provider.related('User', 'john', 'posts')
133
- ```
134
-
135
- ## Future Test Additions
136
-
137
- Potential areas for additional testing:
138
-
139
- 1. **Provider Adapters**: Tests for filesystem, SQLite, ClickHouse, etc. (once implemented)
140
- 2. **Transactions**: If/when transaction support is added
141
- 3. **Performance**: Benchmarks for large datasets
142
- 4. **Migrations**: Schema evolution and data migration
143
- 5. **Validation**: Runtime validation of data against schema
144
- 6. **Indexes**: Index creation and usage
145
- 7. **Full-text search**: Advanced search features with real embeddings
146
- 8. **Replication**: Multi-provider synchronization
147
-
148
- ## Notes
149
-
150
- - All tests use the in-memory provider for speed and isolation
151
- - Tests are designed to run in parallel safely
152
- - Each test suite is independent and resets state in `beforeEach`
153
- - TypeScript type inference is tested at compile time and runtime