@an5/orm 1.0.8 → 1.0.9

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 (38) hide show
  1. package/README.md +167 -175
  2. package/dist/an5Metadata.js +64 -0
  3. package/dist/an5Orm.d.ts +92 -3
  4. package/dist/an5Orm.js +697 -206
  5. package/dist/errors.d.ts +1 -1
  6. package/dist/errors.js +1 -1
  7. package/dist/generator/src/code-generator.d.ts +14 -13
  8. package/dist/generator/src/code-generator.js +249 -225
  9. package/dist/generator/src/dotnet-generator.d.ts +13 -11
  10. package/dist/generator/src/dotnet-generator.js +872 -546
  11. package/dist/generator/src/index.d.ts +1 -1
  12. package/dist/generator/src/index.js +104 -88
  13. package/dist/generator/src/metadata-generator.d.ts +11 -8
  14. package/dist/generator/src/metadata-generator.js +104 -90
  15. package/dist/generator/src/parser.d.ts +11 -11
  16. package/dist/generator/src/parser.js +206 -206
  17. package/dist/generator/src/python-generator.d.ts +19 -9
  18. package/dist/generator/src/python-generator.js +345 -105
  19. package/dist/generator/src/types.d.ts +27 -27
  20. package/dist/generator/src/types.js +2 -2
  21. package/dist/index.d.ts +3 -2
  22. package/dist/index.js +19 -8
  23. package/dist/logger.js +1 -1
  24. package/dist/migration-core.d.ts +87 -0
  25. package/dist/migration-core.js +692 -0
  26. package/dist/scripts/release-cli.d.ts +2 -2
  27. package/dist/scripts/release-cli.js +115 -115
  28. package/dist/sql-utils.d.ts +3 -1
  29. package/dist/sql-utils.js +94 -24
  30. package/generator/src/code-generator.ts +259 -230
  31. package/generator/src/dotnet-generator.ts +882 -544
  32. package/generator/src/golang-generator.ts +1242 -0
  33. package/generator/src/index.ts +111 -116
  34. package/generator/src/metadata-generator.ts +116 -101
  35. package/generator/src/parser.ts +202 -202
  36. package/generator/src/python-generator.ts +424 -114
  37. package/generator/src/types.ts +29 -29
  38. package/package.json +12 -6
package/README.md CHANGED
@@ -1,175 +1,167 @@
1
- # @an5/orm
2
-
3
- SQL Server ORM. Proxy client. CRUD. Vector search. Middleware. Raw queries. Transactions.
4
-
5
- ## Features
6
-
7
- - **Proxy Client.** Model access. `db.modelName` syntax.
8
- - **CRUD.** `findMany`, `findFirst`, `findUnique`, `create`, `update`, `delete`, `upsert`.
9
- - **Advanced Queries.** OR/AND, nested relations, aggregates, `groupBy`.
10
- - **Vector Search.** Native SQL Server `VECTOR_DISTANCE`. In-memory fallback.
11
- - **Middleware.** Hook ORM operations: logging, auth, validation.
12
- - **Raw Queries.** `$queryRaw`, `$executeRaw`. Auto `NOLOCK`.
13
- - **Transactions.** `$transaction`. Rollback support.
14
- - **Schema Generator.** Parse `.an5` files. Generate TypeScript/Python/.NET code.
15
-
16
- ## Quick Start
17
-
18
- ### Installation
19
-
20
- #### TypeScript / Node.js
21
- ```bash
22
- npm install @an5/orm
23
- ```
24
-
25
- #### Python
26
- ```bash
27
- pip install an5-orm
28
- ```
29
-
30
- ### Configuration
31
-
32
- ```bash
33
- cp .env.example .env
34
- # Edit .env. Set DATABASE_URL.
35
- ```
36
-
37
- ### Development Commands
38
-
39
- Run from the `an5Orm/` repository directory (no separate CLI binary is shipped):
40
-
41
- ```bash
42
- # Generate client code from schema
43
- npm run generate
44
-
45
- # Push schema to database
46
- npm run db:push
47
-
48
- # Pull schema from database
49
- npm run db:pull
50
-
51
- # Seed database
52
- npm run db:seed
53
-
54
- # Compare schema with database
55
- npm run db:migrate diff
56
-
57
- # Generate migration SQL / show status
58
- npm run db:migrate:generate
59
- npm run db:migrate:status
60
-
61
- # Run tests
62
- npm test
63
- ```
64
-
65
- ## Usage
66
-
67
- ```typescript
68
- import { An5ORM } from '@an5/orm';
69
-
70
- const db = new An5ORM();
71
- ```
72
-
73
- The default executor reads the `DATABASE_URL` environment variable. Schema metadata
74
- (model→table mapping, relations, field types) is auto-loaded from the ORM's own generated
75
- metadata file `an5Metadata.ts` (created by `npm run generate`, configured via
76
- `outputs.typescript.ormMetadataFile`). The ORM owns this metadata locally — it never
77
- imports from the generated client package (the client is generated *from* the ORM).
78
-
79
- To provide metadata explicitly instead:
80
-
81
- ```typescript
82
- import { An5ORM } from '@an5/orm';
83
- import { modelToTable, relationMap, modelFields } from './an5Metadata';
84
-
85
- const db = new An5ORM(undefined, { modelToTable, relationMap, modelFields });
86
- ```
87
-
88
- // CRUD Operations
89
- const users = await db.user.findMany({
90
- where: { email: { contains: '@example.com' } },
91
- orderBy: { createdAt: 'desc' },
92
- take: 10,
93
- });
94
-
95
- const user = await db.user.create({
96
- data: { email: 'john@example.com', name: 'John' },
97
- });
98
-
99
- // Relations
100
- const orders = await db.user.findMany({
101
- include: { orders: true },
102
- });
103
-
104
- // Vector Search
105
- const similar = await db.document.vectorSearch({
106
- vector: [0.1, 0.2, 0.3],
107
- take: 5,
108
- distanceMetric: 'cosine',
109
- });
110
-
111
- // Transactions
112
- await db.$transaction(async (tx) => {
113
- const user = await tx.user.create({ data: { email: 'jane@example.com' } });
114
- await tx.order.create({ data: { userId: user.id, total: 100 } });
115
- });
116
-
117
- // Raw Queries
118
- const results = await db.$queryRaw`SELECT * FROM users WHERE id = ${id}`;
119
- ```
120
-
121
- ## Schema Definition
122
-
123
- Schema files: `.an5`. Path: `an5Schema/`. SQL Server types.
124
-
125
- ```an5
126
- model User {
127
- id NVARCHAR(1000) @id @default(uuid())
128
- email NVARCHAR(255) @unique
129
- name NVARCHAR(255)?
130
- createdAt DATETIME2 @default(now())
131
- orders Order[]
132
-
133
- @@map("users")
134
- }
135
-
136
- model Order {
137
- id NVARCHAR(1000) @id @default(uuid())
138
- userId NVARCHAR(1000)
139
- total INT @default(0)
140
- user User @relation(fields: [userId], references: [id])
141
-
142
- @@map("orders")
143
- }
144
- ```
145
-
146
- ## Supported SQL Server Types
147
-
148
- Type mapping: `.an5` to TypeScript.
149
-
150
- | Schema Type | TypeScript |
151
- |-------------|------------|
152
- | `NVARCHAR(n)`, `VARCHAR(n)`, `CHAR(n)`, `TEXT` | `string` |
153
- | `INT`, `SMALLINT`, `TINYINT`, `FLOAT`, `REAL`, `DECIMAL`, `NUMERIC` | `number` |
154
- | `BIGINT` | `number \| bigint` |
155
- | `BIT` | `boolean` |
156
- | `DATETIME`, `DATETIME2`, `DATE`, `TIME` | `Date` |
157
- | `UNIQUEIDENTIFIER` | `string` |
158
- | `VARBINARY`, `BINARY`, `IMAGE` | `Buffer` |
159
-
160
- ## Testing
161
-
162
- ```bash
163
- # Unit tests
164
- node test/unit.test.js
165
-
166
- # Generator tests
167
- node test/generator.test.js
168
-
169
- # Smoke test
170
- npm test
171
- ```
172
-
173
- ## License
174
-
175
- MIT
1
+ # @an5/orm
2
+
3
+ The Schema, Code Generator, and Migration Toolkit for the AN5 ecosystem.
4
+
5
+ ## Overview
6
+
7
+ `@an5/orm` provides core schema parsing, multi-language code generation (TypeScript, Python, .NET C#, Golang), database introspection (`pull`), schema deployment (`push`), and automated database migrations.
8
+
9
+ Runtime database connections, query building, transactions, and multi-database drivers (MSSQL, PostgreSQL, MySQL, SQLite, Google Sheets) are powered by **[@an5/adapters](https://github.com/an5ORM/an5/tree/main/an5Adapters)**.
10
+
11
+ ## Features
12
+
13
+ - **Schema Definition:** Define models and relationships using concise `.an5` syntax with native database types.
14
+ - **Multi-Language Generator:** Generate typed clients and entity models for TypeScript, Python, .NET (C#), and Golang.
15
+ - **Database Introspection (`db:pull`):** Inspect an existing database schema and generate matching `.an5` models.
16
+ - **Direct Schema Push (`db:push`):** Synchronize `.an5` schema definitions directly to the database.
17
+ - **Automated Migrations (`db:migrate`):** Diff schema against database, generate up/down migration SQL scripts, apply, rollback, and check migration status.
18
+ - **Seeding & Cleanup:** Generic runner for project seed scripts (`seed.ts`/`seed.js`) and database cleanup.
19
+ - **Seamless Adapter Integration:** Built-in connection support via `@an5/adapters`.
20
+
21
+ ## Quick Start
22
+
23
+ ### Installation
24
+
25
+ ```bash
26
+ npm install @an5/orm @an5/adapters
27
+ ```
28
+
29
+ ### Configuration
30
+
31
+ Create `an5Orm.config.js` in your project root:
32
+
33
+ ```javascript
34
+ module.exports = {
35
+ // Schema directory (default: 'an5Schema')
36
+ schemaDir: 'an5Schema',
37
+
38
+ // Generated client outputs
39
+ outputs: {
40
+ typescript: {
41
+ outputDir: 'an5Client/typescript',
42
+ metadataFile: 'an5Client/typescript/an5Metadata.ts',
43
+ },
44
+ python: {
45
+ outputDir: 'an5Client/python',
46
+ metadataFile: 'an5Client/python/an5_metadata.py',
47
+ },
48
+ dotnet: {
49
+ outputDir: 'an5Client/dotnet',
50
+ },
51
+ golang: {
52
+ outputDir: 'an5Client/golang',
53
+ },
54
+ },
55
+
56
+ // Database pull options
57
+ pull: {
58
+ exclude: ['^__', '^sys\\.', '^migrations'],
59
+ preserveRelations: true,
60
+ },
61
+ };
62
+ ```
63
+
64
+ Configure your environment variables in `.env`:
65
+
66
+ ```env
67
+ DATABASE_URL=sqlserver://localhost:1433;database=mydb;user=sa;password=Secret123!;encrypt=false
68
+ ```
69
+
70
+ ### CLI Commands
71
+
72
+ ```bash
73
+ # Generate client code from .an5 schemas
74
+ npm run generate
75
+
76
+ # Push schema directly to database
77
+ npm run db:push
78
+
79
+ # Pull database schema into .an5 files
80
+ npm run db:pull
81
+
82
+ # Check schema diff
83
+ npm run db:migrate diff
84
+
85
+ # Generate new migration script
86
+ npm run db:migrate:generate
87
+
88
+ # Apply pending migrations
89
+ npm run db:migrate:apply
90
+
91
+ # Rollback last migration
92
+ npm run db:migrate:rollback
93
+
94
+ # View migration status
95
+ npm run db:migrate:status
96
+
97
+ # Run database seed script
98
+ npm run db:seed
99
+
100
+ # Clean up database tables
101
+ npm run db:cleanup
102
+ ```
103
+
104
+ ## Runtime Database Usage (via `@an5/adapters`)
105
+
106
+ To connect to your database and perform queries, use `@an5/adapters`:
107
+
108
+ ```typescript
109
+ import { createAn5Adapter } from '@an5/adapters';
110
+
111
+ const db = createAn5Adapter({
112
+ connectionString: process.env.DATABASE_URL!,
113
+ });
114
+
115
+ // Connect to database
116
+ await db.$connect();
117
+
118
+ // Model operations
119
+ const users = await db.user.findMany({
120
+ where: { email: { contains: '@example.com' } },
121
+ orderBy: { createdAt: 'desc' },
122
+ take: 10,
123
+ });
124
+
125
+ // Create record
126
+ const newUser = await db.user.create({
127
+ data: {
128
+ email: 'alex@example.com',
129
+ name: 'Alex',
130
+ },
131
+ });
132
+
133
+ // Transactions
134
+ await db.$transaction(async (tx) => {
135
+ await tx.exec('UPDATE Users SET active = 1 WHERE id = @p_0', { p_0: 'u1' });
136
+ });
137
+
138
+ // Disconnect
139
+ await db.$disconnect();
140
+ ```
141
+
142
+ ## Schema Definition (`.an5`)
143
+
144
+ ```an5
145
+ model User {
146
+ id NVARCHAR(1000) @id @default(uuid())
147
+ email NVARCHAR(255) @unique
148
+ name NVARCHAR(255)?
149
+ createdAt DATETIME2 @default(now())
150
+ orders Order[]
151
+
152
+ @@map("users")
153
+ }
154
+
155
+ model Order {
156
+ id NVARCHAR(1000) @id @default(uuid())
157
+ userId NVARCHAR(1000)
158
+ total INT @default(0)
159
+ user User @relation(fields: [userId], references: [id])
160
+
161
+ @@map("orders")
162
+ }
163
+ ```
164
+
165
+ ## License
166
+
167
+ MIT
@@ -3,27 +3,91 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.relationMap = exports.modelFields = exports.modelDescriptions = exports.modelToTable = void 0;
5
5
  exports.modelToTable = {
6
+ EmbeddingConfig: "[dbo].[embeddingconfigs]",
6
7
  embeddingConfig: "[dbo].[embeddingconfigs]",
8
+ EmbeddingConfigs: "[dbo].[embeddingconfigs]",
9
+ embeddingConfigs: "[dbo].[embeddingconfigs]",
10
+ embedding_config: "[dbo].[embeddingconfigs]",
11
+ embedding_configs: "[dbo].[embeddingconfigs]",
12
+ LlmConfig: "[dbo].[llmconfigs]",
7
13
  llmConfig: "[dbo].[llmconfigs]",
14
+ LlmConfigs: "[dbo].[llmconfigs]",
15
+ llmConfigs: "[dbo].[llmconfigs]",
16
+ llm_config: "[dbo].[llmconfigs]",
17
+ llm_configs: "[dbo].[llmconfigs]",
18
+ User: "[dbo].[users]",
8
19
  user: "[dbo].[users]",
20
+ Users: "[dbo].[users]",
21
+ users: "[dbo].[users]",
22
+ Order: "[dbo].[orders]",
9
23
  order: "[dbo].[orders]",
24
+ Orders: "[dbo].[orders]",
25
+ orders: "[dbo].[orders]",
10
26
  };
11
27
  exports.modelDescriptions = {
28
+ EmbeddingConfig: "Embedding provider configuration. Stores API keys and model settings for RAG features.",
12
29
  embeddingConfig: "Embedding provider configuration. Stores API keys and model settings for RAG features.",
30
+ EmbeddingConfigs: "Embedding provider configuration. Stores API keys and model settings for RAG features.",
31
+ embeddingConfigs: "Embedding provider configuration. Stores API keys and model settings for RAG features.",
32
+ embedding_config: "Embedding provider configuration. Stores API keys and model settings for RAG features.",
33
+ embedding_configs: "Embedding provider configuration. Stores API keys and model settings for RAG features.",
34
+ LlmConfig: "LLM provider configuration. Stores API keys and model settings for AI features.",
13
35
  llmConfig: "LLM provider configuration. Stores API keys and model settings for AI features.",
36
+ LlmConfigs: "LLM provider configuration. Stores API keys and model settings for AI features.",
37
+ llmConfigs: "LLM provider configuration. Stores API keys and model settings for AI features.",
38
+ llm_config: "LLM provider configuration. Stores API keys and model settings for AI features.",
39
+ llm_configs: "LLM provider configuration. Stores API keys and model settings for AI features.",
40
+ User: "Represents a registered user in the database.",
14
41
  user: "Represents a registered user in the database.",
42
+ Users: "Represents a registered user in the database.",
43
+ users: "Represents a registered user in the database.",
44
+ Order: "Represents a customer order in the system.",
15
45
  order: "Represents a customer order in the system.",
46
+ Orders: "Represents a customer order in the system.",
47
+ orders: "Represents a customer order in the system.",
16
48
  };
17
49
  exports.modelFields = {
50
+ EmbeddingConfig: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "Embedding provider: openai, cohere, custom" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the embedding service" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. text-embedding-3-small" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
18
51
  embeddingConfig: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "Embedding provider: openai, cohere, custom" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the embedding service" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. text-embedding-3-small" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
52
+ EmbeddingConfigs: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "Embedding provider: openai, cohere, custom" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the embedding service" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. text-embedding-3-small" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
53
+ embeddingConfigs: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "Embedding provider: openai, cohere, custom" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the embedding service" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. text-embedding-3-small" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
54
+ embedding_config: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "Embedding provider: openai, cohere, custom" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the embedding service" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. text-embedding-3-small" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
55
+ embedding_configs: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "Embedding provider: openai, cohere, custom" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the embedding service" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. text-embedding-3-small" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
56
+ LlmConfig: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "LLM provider: openai, gemini, custom, azure" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the LLM provider" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. gpt-4o, gemini-2.5-flash" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
19
57
  llmConfig: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "LLM provider: openai, gemini, custom, azure" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the LLM provider" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. gpt-4o, gemini-2.5-flash" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
58
+ LlmConfigs: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "LLM provider: openai, gemini, custom, azure" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the LLM provider" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. gpt-4o, gemini-2.5-flash" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
59
+ llmConfigs: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "LLM provider: openai, gemini, custom, azure" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the LLM provider" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. gpt-4o, gemini-2.5-flash" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
60
+ llm_config: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "LLM provider: openai, gemini, custom, azure" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the LLM provider" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. gpt-4o, gemini-2.5-flash" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
61
+ llm_configs: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key" }, provider: { ts: "string", sql: "NVARCHAR(100)", description: "LLM provider: openai, gemini, custom, azure" }, apiKey: { ts: "string", sql: "NVARCHAR(4000)", description: "API key for the LLM provider" }, model: { ts: "string?", sql: "NVARCHAR(500)", description: "Model name, e.g. gpt-4o, gemini-2.5-flash" }, endpoint: { ts: "string?", sql: "NVARCHAR(2000)", description: "Custom endpoint URL" }, isActive: { ts: "boolean", sql: "BIT", description: "Whether this config is active" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Creation timestamp" }, updatedAt: { ts: "Date", sql: "DATETIME2", description: "Last update timestamp" } },
62
+ User: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key for the User table (auto-generated UUID)" }, email: { ts: "string", sql: "NVARCHAR(255)", description: "Unique email address used for login and notifications" }, name: { ts: "string?", sql: "NVARCHAR(255)", description: "Display name of the user" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Timestamp when the user profile was created" } },
20
63
  user: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key for the User table (auto-generated UUID)" }, email: { ts: "string", sql: "NVARCHAR(255)", description: "Unique email address used for login and notifications" }, name: { ts: "string?", sql: "NVARCHAR(255)", description: "Display name of the user" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Timestamp when the user profile was created" } },
64
+ Users: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key for the User table (auto-generated UUID)" }, email: { ts: "string", sql: "NVARCHAR(255)", description: "Unique email address used for login and notifications" }, name: { ts: "string?", sql: "NVARCHAR(255)", description: "Display name of the user" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Timestamp when the user profile was created" } },
65
+ users: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key for the User table (auto-generated UUID)" }, email: { ts: "string", sql: "NVARCHAR(255)", description: "Unique email address used for login and notifications" }, name: { ts: "string?", sql: "NVARCHAR(255)", description: "Display name of the user" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "Timestamp when the user profile was created" } },
66
+ Order: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key for the Order table (auto-generated UUID)" }, userId: { ts: "string", sql: "NVARCHAR(1000)", description: "Foreign key linking to the User model who placed the order" }, total: { ts: "number", sql: "INT", description: "Total cost amount of the order" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "The date and time when the order was created." } },
21
67
  order: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key for the Order table (auto-generated UUID)" }, userId: { ts: "string", sql: "NVARCHAR(1000)", description: "Foreign key linking to the User model who placed the order" }, total: { ts: "number", sql: "INT", description: "Total cost amount of the order" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "The date and time when the order was created." } },
68
+ Orders: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key for the Order table (auto-generated UUID)" }, userId: { ts: "string", sql: "NVARCHAR(1000)", description: "Foreign key linking to the User model who placed the order" }, total: { ts: "number", sql: "INT", description: "Total cost amount of the order" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "The date and time when the order was created." } },
69
+ orders: { id: { ts: "string", sql: "NVARCHAR(1000)", description: "Primary key for the Order table (auto-generated UUID)" }, userId: { ts: "string", sql: "NVARCHAR(1000)", description: "Foreign key linking to the User model who placed the order" }, total: { ts: "number", sql: "INT", description: "Total cost amount of the order" }, createdAt: { ts: "Date", sql: "DATETIME2", description: "The date and time when the order was created." } },
22
70
  };
23
71
  exports.relationMap = {
72
+ EmbeddingConfig: {},
24
73
  embeddingConfig: {},
74
+ EmbeddingConfigs: {},
75
+ embeddingConfigs: {},
76
+ embedding_config: {},
77
+ embedding_configs: {},
78
+ LlmConfig: {},
25
79
  llmConfig: {},
80
+ LlmConfigs: {},
81
+ llmConfigs: {},
82
+ llm_config: {},
83
+ llm_configs: {},
84
+ User: {},
26
85
  user: {},
86
+ Users: {},
87
+ users: {},
88
+ Order: {},
27
89
  order: {},
90
+ Orders: {},
91
+ orders: {},
28
92
  };
29
93
  //# sourceMappingURL=an5Metadata.js.map
package/dist/an5Orm.d.ts CHANGED
@@ -1,5 +1,61 @@
1
+ import { An5Adapter } from "@an5/adapters";
1
2
  import { An5Metadata } from "./metadata";
2
- type ExecutorFn = (queryText: string, params?: Record<string, any>) => Promise<any[]>;
3
+ type ExecutorFn = ((queryText: string, params?: Record<string, any>) => Promise<any[]>) & {
4
+ executeRaw?: (queryText: string, params?: Record<string, any>) => Promise<number>;
5
+ transaction?: <R>(fn: (txExecutor: ExecutorFn) => Promise<R>, options?: {
6
+ timeout?: number;
7
+ }) => Promise<R>;
8
+ beginTransaction?: () => Promise<InteractiveTransactionExecutor>;
9
+ };
10
+ type InteractiveTransactionExecutor = {
11
+ executor: ExecutorFn;
12
+ commit: () => Promise<void>;
13
+ rollback: () => Promise<void>;
14
+ };
15
+ export declare class TableClient<T = any> {
16
+ private modelName;
17
+ private executor;
18
+ private orm;
19
+ constructor(modelName: string, tableName: string, executor: ExecutorFn, orm: An5ORM);
20
+ private tableName;
21
+ private executeRaw;
22
+ findMany(args?: any): Promise<T[]>;
23
+ findFirst(args?: any): Promise<T | null>;
24
+ findUnique(args?: any): Promise<T | null>;
25
+ count(args?: any): Promise<number>;
26
+ private scopedRelationWhere;
27
+ private handleNestedWrites;
28
+ create(args: any): Promise<T>;
29
+ update(args: any): Promise<T>;
30
+ updateMany(args: any): Promise<{
31
+ count: number;
32
+ }>;
33
+ delete(args: any): Promise<T>;
34
+ deleteMany(args?: any): Promise<{
35
+ count: number;
36
+ }>;
37
+ vectorSearch(args: {
38
+ vector: number[];
39
+ take?: number;
40
+ where?: any;
41
+ include?: any;
42
+ vectorField?: string;
43
+ distanceMetric?: 'cosine' | 'euclidean' | 'dot';
44
+ vectorElementType?: 'float32' | 'float16' | 'uint8';
45
+ }): Promise<(T & {
46
+ distance: number;
47
+ })[]>;
48
+ createMany(args: {
49
+ data: any[];
50
+ skipDuplicates?: boolean;
51
+ }): Promise<{
52
+ count: number;
53
+ }>;
54
+ aggregate(args: any): Promise<any>;
55
+ groupBy(args: any): Promise<any[]>;
56
+ private sequentialUpsert;
57
+ upsert(args: any): Promise<T>;
58
+ }
3
59
  export interface MiddlewareParams {
4
60
  model?: string;
5
61
  action: string;
@@ -8,12 +64,42 @@ export interface MiddlewareParams {
8
64
  }
9
65
  export type MiddlewareNext = (params: MiddlewareParams) => Promise<any>;
10
66
  export type Middleware = (params: MiddlewareParams, next: MiddlewareNext) => Promise<any>;
67
+ export declare class ViewClient<T = any> {
68
+ viewName: string;
69
+ rawTableName: string;
70
+ executor: ExecutorFn;
71
+ orm?: An5ORM | undefined;
72
+ private tableClient;
73
+ constructor(viewName: string, rawTableName: string, executor: ExecutorFn, orm?: An5ORM | undefined);
74
+ findMany(args?: any): Promise<T[]>;
75
+ findFirst(args?: any): Promise<T | null>;
76
+ findUnique(args?: any): Promise<T | null>;
77
+ count(args?: any): Promise<number>;
78
+ aggregate(args?: any): Promise<any>;
79
+ groupBy(args?: any): Promise<any[]>;
80
+ vectorSearch(args: any): Promise<T[]>;
81
+ create(): Promise<never>;
82
+ createMany(): Promise<never>;
83
+ update(): Promise<never>;
84
+ updateMany(): Promise<never>;
85
+ delete(): Promise<never>;
86
+ deleteMany(): Promise<never>;
87
+ upsert(): Promise<never>;
88
+ }
11
89
  export declare class An5ORM {
12
- private customExecutor?;
90
+ private readonly inTransaction;
91
+ private transactionControl?;
13
92
  [key: string]: any;
14
93
  private middlewares;
15
94
  readonly metadata: An5Metadata;
16
- constructor(customExecutor?: ExecutorFn | undefined, metadata?: An5Metadata);
95
+ private customExecutor?;
96
+ constructor(customExecutor?: ExecutorFn | An5Adapter | any, metadata?: An5Metadata, inTransaction?: boolean, transactionControl?: Pick<InteractiveTransactionExecutor, "commit" | "rollback"> | undefined);
97
+ table(name: string): TableClient;
98
+ view(name: string): ViewClient;
99
+ $view(name: string): ViewClient;
100
+ $queryProc<T = any>(procName: string, params?: Record<string, any> | any[]): Promise<T[]>;
101
+ $executeProc(procName: string, params?: Record<string, any> | any[]): Promise<number>;
102
+ $queryFunction<T = any>(fnName: string, params?: Record<string, any> | any[]): Promise<T[]>;
17
103
  $use(middleware: Middleware): void;
18
104
  parseWhere(modelName: string, where: any, params: Record<string, any>, prefix?: string): string;
19
105
  _executeMiddleware(params: MiddlewareParams, finalAction: (params: MiddlewareParams) => Promise<any>): Promise<any>;
@@ -26,6 +112,9 @@ export declare class An5ORM {
26
112
  $transaction<R>(fn: ((tx: any) => Promise<R>) | Promise<any>[], options?: {
27
113
  timeout?: number;
28
114
  }): Promise<any>;
115
+ $begin(): Promise<any>;
116
+ $commit(): Promise<void>;
117
+ $rollback(): Promise<void>;
29
118
  }
30
119
  export declare const an5Orm: An5ORM;
31
120
  export default an5Orm;