@an5/orm 1.0.7 → 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.
- package/README.md +97 -83
- package/dist/an5Metadata.d.ts +10 -0
- package/dist/an5Metadata.js +93 -0
- package/dist/an5Orm.d.ts +95 -3
- package/dist/an5Orm.js +808 -512
- package/dist/config.d.ts +2 -0
- package/dist/config.js +24 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +16 -0
- package/dist/generator/src/code-generator.d.ts +1 -0
- package/dist/generator/src/code-generator.js +44 -20
- package/dist/generator/src/dotnet-generator.d.ts +2 -0
- package/dist/generator/src/dotnet-generator.js +332 -6
- package/dist/generator/src/index.js +18 -2
- package/dist/generator/src/metadata-generator.d.ts +4 -1
- package/dist/generator/src/metadata-generator.js +22 -8
- package/dist/generator/src/python-generator.d.ts +10 -0
- package/dist/generator/src/python-generator.js +242 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +23 -8
- package/dist/logger.d.ts +53 -0
- package/dist/logger.js +117 -0
- package/dist/metadata.d.ts +24 -0
- package/dist/metadata.js +15 -0
- package/dist/migration-core.d.ts +87 -0
- package/dist/migration-core.js +692 -0
- package/dist/sql-utils.d.ts +31 -0
- package/dist/sql-utils.js +290 -0
- package/generator/src/code-generator.ts +45 -20
- package/generator/src/dotnet-generator.ts +344 -6
- package/generator/src/golang-generator.ts +1242 -0
- package/generator/src/index.ts +8 -1
- package/generator/src/metadata-generator.ts +29 -12
- package/generator/src/python-generator.ts +314 -4
- package/package.json +12 -10
- package/dist/cleanup.d.ts +0 -2
- package/dist/cleanup.js +0 -120
- package/dist/cli.js +0 -64
- package/dist/migrate.d.ts +0 -11
- package/dist/migrate.js +0 -301
- package/dist/pull.d.ts +0 -2
- package/dist/pull.js +0 -339
- package/dist/push.d.ts +0 -2
- package/dist/push.js +0 -281
- package/dist/seed.d.ts +0 -2
- package/dist/seed.js +0 -401
package/README.md
CHANGED
|
@@ -1,104 +1,145 @@
|
|
|
1
1
|
# @an5/orm
|
|
2
2
|
|
|
3
|
-
|
|
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)**.
|
|
4
10
|
|
|
5
11
|
## Features
|
|
6
12
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
- **Schema Generator.** Parse `.an5` files. Generate TypeScript/Python/.NET code.
|
|
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`.
|
|
15
20
|
|
|
16
21
|
## Quick Start
|
|
17
22
|
|
|
18
23
|
### Installation
|
|
19
24
|
|
|
20
|
-
#### TypeScript / Node.js
|
|
21
25
|
```bash
|
|
22
|
-
npm install @an5/orm
|
|
26
|
+
npm install @an5/orm @an5/adapters
|
|
23
27
|
```
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
};
|
|
28
62
|
```
|
|
29
63
|
|
|
30
|
-
|
|
64
|
+
Configure your environment variables in `.env`:
|
|
31
65
|
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
# Edit .env. Set DATABASE_URL.
|
|
66
|
+
```env
|
|
67
|
+
DATABASE_URL=sqlserver://localhost:1433;database=mydb;user=sa;password=Secret123!;encrypt=false
|
|
35
68
|
```
|
|
36
69
|
|
|
37
|
-
###
|
|
70
|
+
### CLI Commands
|
|
38
71
|
|
|
39
72
|
```bash
|
|
40
|
-
# Generate code from
|
|
41
|
-
|
|
73
|
+
# Generate client code from .an5 schemas
|
|
74
|
+
npm run generate
|
|
42
75
|
|
|
43
|
-
# Push schema to database
|
|
44
|
-
|
|
76
|
+
# Push schema directly to database
|
|
77
|
+
npm run db:push
|
|
45
78
|
|
|
46
|
-
# Pull schema
|
|
47
|
-
|
|
79
|
+
# Pull database schema into .an5 files
|
|
80
|
+
npm run db:pull
|
|
48
81
|
|
|
49
|
-
#
|
|
50
|
-
|
|
82
|
+
# Check schema diff
|
|
83
|
+
npm run db:migrate diff
|
|
51
84
|
|
|
52
|
-
#
|
|
53
|
-
|
|
85
|
+
# Generate new migration script
|
|
86
|
+
npm run db:migrate:generate
|
|
54
87
|
|
|
55
|
-
#
|
|
56
|
-
npm
|
|
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
|
|
57
102
|
```
|
|
58
103
|
|
|
59
|
-
## Usage
|
|
104
|
+
## Runtime Database Usage (via `@an5/adapters`)
|
|
105
|
+
|
|
106
|
+
To connect to your database and perform queries, use `@an5/adapters`:
|
|
60
107
|
|
|
61
108
|
```typescript
|
|
62
|
-
import {
|
|
109
|
+
import { createAn5Adapter } from '@an5/adapters';
|
|
110
|
+
|
|
111
|
+
const db = createAn5Adapter({
|
|
112
|
+
connectionString: process.env.DATABASE_URL!,
|
|
113
|
+
});
|
|
63
114
|
|
|
64
|
-
|
|
115
|
+
// Connect to database
|
|
116
|
+
await db.$connect();
|
|
65
117
|
|
|
66
|
-
//
|
|
118
|
+
// Model operations
|
|
67
119
|
const users = await db.user.findMany({
|
|
68
120
|
where: { email: { contains: '@example.com' } },
|
|
69
121
|
orderBy: { createdAt: 'desc' },
|
|
70
122
|
take: 10,
|
|
71
123
|
});
|
|
72
124
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
include: { orders: true },
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Vector Search
|
|
83
|
-
const similar = await db.document.vectorSearch({
|
|
84
|
-
vector: [0.1, 0.2, 0.3],
|
|
85
|
-
take: 5,
|
|
86
|
-
distanceMetric: 'cosine',
|
|
125
|
+
// Create record
|
|
126
|
+
const newUser = await db.user.create({
|
|
127
|
+
data: {
|
|
128
|
+
email: 'alex@example.com',
|
|
129
|
+
name: 'Alex',
|
|
130
|
+
},
|
|
87
131
|
});
|
|
88
132
|
|
|
89
133
|
// Transactions
|
|
90
134
|
await db.$transaction(async (tx) => {
|
|
91
|
-
|
|
92
|
-
await tx.order.create({ data: { userId: user.id, total: 100 } });
|
|
135
|
+
await tx.exec('UPDATE Users SET active = 1 WHERE id = @p_0', { p_0: 'u1' });
|
|
93
136
|
});
|
|
94
137
|
|
|
95
|
-
//
|
|
96
|
-
|
|
138
|
+
// Disconnect
|
|
139
|
+
await db.$disconnect();
|
|
97
140
|
```
|
|
98
141
|
|
|
99
|
-
## Schema Definition
|
|
100
|
-
|
|
101
|
-
Schema files: `.an5`. Path: `an5Schema/`. SQL Server types.
|
|
142
|
+
## Schema Definition (`.an5`)
|
|
102
143
|
|
|
103
144
|
```an5
|
|
104
145
|
model User {
|
|
@@ -121,33 +162,6 @@ model Order {
|
|
|
121
162
|
}
|
|
122
163
|
```
|
|
123
164
|
|
|
124
|
-
## Supported SQL Server Types
|
|
125
|
-
|
|
126
|
-
Type mapping: `.an5` to TypeScript.
|
|
127
|
-
|
|
128
|
-
| Schema Type | TypeScript |
|
|
129
|
-
|-------------|------------|
|
|
130
|
-
| `NVARCHAR(n)`, `VARCHAR(n)`, `CHAR(n)`, `TEXT` | `string` |
|
|
131
|
-
| `INT`, `SMALLINT`, `TINYINT`, `FLOAT`, `REAL`, `DECIMAL`, `NUMERIC` | `number` |
|
|
132
|
-
| `BIGINT` | `number \| bigint` |
|
|
133
|
-
| `BIT` | `boolean` |
|
|
134
|
-
| `DATETIME`, `DATETIME2`, `DATE`, `TIME` | `Date` |
|
|
135
|
-
| `UNIQUEIDENTIFIER` | `string` |
|
|
136
|
-
| `VARBINARY`, `BINARY`, `IMAGE` | `Buffer` |
|
|
137
|
-
|
|
138
|
-
## Testing
|
|
139
|
-
|
|
140
|
-
```bash
|
|
141
|
-
# Unit tests
|
|
142
|
-
node test/unit.test.js
|
|
143
|
-
|
|
144
|
-
# Generator tests
|
|
145
|
-
node test/generator.test.js
|
|
146
|
-
|
|
147
|
-
# Smoke test
|
|
148
|
-
npm test
|
|
149
|
-
```
|
|
150
|
-
|
|
151
165
|
## License
|
|
152
166
|
|
|
153
167
|
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RelationDef } from "./metadata";
|
|
2
|
+
export declare const modelToTable: Record<string, string>;
|
|
3
|
+
export declare const modelDescriptions: Record<string, string | undefined>;
|
|
4
|
+
export declare const modelFields: Record<string, Record<string, {
|
|
5
|
+
ts: string;
|
|
6
|
+
sql: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
}>>;
|
|
9
|
+
export declare const relationMap: Record<string, Record<string, RelationDef>>;
|
|
10
|
+
//# sourceMappingURL=an5Metadata.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is auto-generated. Do not edit directly.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.relationMap = exports.modelFields = exports.modelDescriptions = exports.modelToTable = void 0;
|
|
5
|
+
exports.modelToTable = {
|
|
6
|
+
EmbeddingConfig: "[dbo].[embeddingconfigs]",
|
|
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]",
|
|
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]",
|
|
19
|
+
user: "[dbo].[users]",
|
|
20
|
+
Users: "[dbo].[users]",
|
|
21
|
+
users: "[dbo].[users]",
|
|
22
|
+
Order: "[dbo].[orders]",
|
|
23
|
+
order: "[dbo].[orders]",
|
|
24
|
+
Orders: "[dbo].[orders]",
|
|
25
|
+
orders: "[dbo].[orders]",
|
|
26
|
+
};
|
|
27
|
+
exports.modelDescriptions = {
|
|
28
|
+
EmbeddingConfig: "Embedding provider configuration. Stores API keys and model settings for RAG features.",
|
|
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.",
|
|
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.",
|
|
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.",
|
|
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.",
|
|
48
|
+
};
|
|
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" } },
|
|
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" } },
|
|
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" } },
|
|
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." } },
|
|
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." } },
|
|
70
|
+
};
|
|
71
|
+
exports.relationMap = {
|
|
72
|
+
EmbeddingConfig: {},
|
|
73
|
+
embeddingConfig: {},
|
|
74
|
+
EmbeddingConfigs: {},
|
|
75
|
+
embeddingConfigs: {},
|
|
76
|
+
embedding_config: {},
|
|
77
|
+
embedding_configs: {},
|
|
78
|
+
LlmConfig: {},
|
|
79
|
+
llmConfig: {},
|
|
80
|
+
LlmConfigs: {},
|
|
81
|
+
llmConfigs: {},
|
|
82
|
+
llm_config: {},
|
|
83
|
+
llm_configs: {},
|
|
84
|
+
User: {},
|
|
85
|
+
user: {},
|
|
86
|
+
Users: {},
|
|
87
|
+
users: {},
|
|
88
|
+
Order: {},
|
|
89
|
+
order: {},
|
|
90
|
+
Orders: {},
|
|
91
|
+
orders: {},
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=an5Metadata.js.map
|
package/dist/an5Orm.d.ts
CHANGED
|
@@ -1,4 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
import { An5Adapter } from "@an5/adapters";
|
|
2
|
+
import { An5Metadata } from "./metadata";
|
|
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
|
+
}
|
|
2
59
|
export interface MiddlewareParams {
|
|
3
60
|
model?: string;
|
|
4
61
|
action: string;
|
|
@@ -7,12 +64,44 @@ export interface MiddlewareParams {
|
|
|
7
64
|
}
|
|
8
65
|
export type MiddlewareNext = (params: MiddlewareParams) => Promise<any>;
|
|
9
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
|
+
}
|
|
10
89
|
export declare class An5ORM {
|
|
11
|
-
private
|
|
90
|
+
private readonly inTransaction;
|
|
91
|
+
private transactionControl?;
|
|
12
92
|
[key: string]: any;
|
|
13
93
|
private middlewares;
|
|
14
|
-
|
|
94
|
+
readonly 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[]>;
|
|
15
103
|
$use(middleware: Middleware): void;
|
|
104
|
+
parseWhere(modelName: string, where: any, params: Record<string, any>, prefix?: string): string;
|
|
16
105
|
_executeMiddleware(params: MiddlewareParams, finalAction: (params: MiddlewareParams) => Promise<any>): Promise<any>;
|
|
17
106
|
$connect(): Promise<void>;
|
|
18
107
|
$disconnect(): Promise<void>;
|
|
@@ -23,6 +112,9 @@ export declare class An5ORM {
|
|
|
23
112
|
$transaction<R>(fn: ((tx: any) => Promise<R>) | Promise<any>[], options?: {
|
|
24
113
|
timeout?: number;
|
|
25
114
|
}): Promise<any>;
|
|
115
|
+
$begin(): Promise<any>;
|
|
116
|
+
$commit(): Promise<void>;
|
|
117
|
+
$rollback(): Promise<void>;
|
|
26
118
|
}
|
|
27
119
|
export declare const an5Orm: An5ORM;
|
|
28
120
|
export default an5Orm;
|