neoorm 0.6.2 → 0.6.3
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 +4 -2
- package/dist/bin/neoorm.js +28 -1
- package/dist/bin/neoorm.js.map +1 -1
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/generate.js +12 -2
- package/dist/codegen/generate.js.map +1 -1
- package/dist/codegen/schema-to-manifest.d.ts +6 -1
- package/dist/codegen/schema-to-manifest.d.ts.map +1 -1
- package/dist/codegen/schema-to-manifest.js +78 -22
- package/dist/codegen/schema-to-manifest.js.map +1 -1
- package/dist/docs/pages.d.ts +9 -0
- package/dist/docs/pages.d.ts.map +1 -0
- package/dist/docs/pages.js +64 -0
- package/dist/docs/pages.js.map +1 -0
- package/dist/docs/render.d.ts +4 -0
- package/dist/docs/render.d.ts.map +1 -0
- package/dist/docs/render.js +245 -0
- package/dist/docs/render.js.map +1 -0
- package/dist/docs/resolve-docs-dir.d.ts +2 -0
- package/dist/docs/resolve-docs-dir.d.ts.map +1 -0
- package/dist/docs/resolve-docs-dir.js +27 -0
- package/dist/docs/resolve-docs-dir.js.map +1 -0
- package/dist/docs/server.d.ts +11 -0
- package/dist/docs/server.d.ts.map +1 -0
- package/dist/docs/server.js +99 -0
- package/dist/docs/server.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime/client.d.ts.map +1 -1
- package/dist/runtime/client.js +2 -5
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/error-builders.d.ts +14 -0
- package/dist/runtime/error-builders.d.ts.map +1 -0
- package/dist/runtime/error-builders.js +54 -0
- package/dist/runtime/error-builders.js.map +1 -0
- package/dist/runtime/error-hints.d.ts +19 -0
- package/dist/runtime/error-hints.d.ts.map +1 -0
- package/dist/runtime/error-hints.js +181 -0
- package/dist/runtime/error-hints.js.map +1 -0
- package/dist/runtime/errors.d.ts +5 -0
- package/dist/runtime/errors.d.ts.map +1 -1
- package/dist/runtime/errors.js +19 -2
- package/dist/runtime/errors.js.map +1 -1
- package/dist/runtime/pg-error.d.ts.map +1 -1
- package/dist/runtime/pg-error.js +86 -0
- package/dist/runtime/pg-error.js.map +1 -1
- package/dist/runtime/query/compile.d.ts.map +1 -1
- package/dist/runtime/query/compile.js +5 -12
- package/dist/runtime/query/compile.js.map +1 -1
- package/dist/runtime/query/cursor.d.ts.map +1 -1
- package/dist/runtime/query/cursor.js +2 -5
- package/dist/runtime/query/cursor.js.map +1 -1
- package/dist/runtime/query/execute.d.ts.map +1 -1
- package/dist/runtime/query/execute.js +28 -9
- package/dist/runtime/query/execute.js.map +1 -1
- package/dist/runtime/query/group-by.d.ts.map +1 -1
- package/dist/runtime/query/group-by.js +3 -7
- package/dist/runtime/query/group-by.js.map +1 -1
- package/dist/runtime/query/projection.d.ts.map +1 -1
- package/dist/runtime/query/projection.js +2 -4
- package/dist/runtime/query/projection.js.map +1 -1
- package/dist/runtime/query/relation-planner.d.ts.map +1 -1
- package/dist/runtime/query/relation-planner.js +6 -1
- package/dist/runtime/query/relation-planner.js.map +1 -1
- package/dist/runtime/query/strip.d.ts.map +1 -1
- package/dist/runtime/query/strip.js +2 -4
- package/dist/runtime/query/strip.js.map +1 -1
- package/dist/runtime/query/table-index.d.ts +4 -0
- package/dist/runtime/query/table-index.d.ts.map +1 -1
- package/dist/runtime/query/table-index.js +45 -0
- package/dist/runtime/query/table-index.js.map +1 -1
- package/dist/runtime/schema-error.d.ts +1 -1
- package/dist/runtime/schema-error.d.ts.map +1 -1
- package/dist/runtime/schema-error.js +7 -2
- package/dist/runtime/schema-error.js.map +1 -1
- package/dist/runtime/sqlite-error.d.ts +12 -0
- package/dist/runtime/sqlite-error.d.ts.map +1 -0
- package/dist/runtime/sqlite-error.js +169 -0
- package/dist/runtime/sqlite-error.js.map +1 -0
- package/docs/cli.md +107 -0
- package/docs/configuration.md +51 -0
- package/docs/errors.md +72 -0
- package/docs/examples.md +498 -0
- package/docs/getting-started.md +122 -0
- package/docs/migrations.md +67 -0
- package/docs/plugins.md +47 -0
- package/docs/queries.md +465 -0
- package/docs/relations.md +75 -0
- package/docs/schema.md +260 -0
- package/docs/sqlite.md +105 -0
- package/docs/transactions.md +54 -0
- package/package.json +3 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-error.js","sourceRoot":"","sources":["../../src/runtime/sqlite-error.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAO5C,MAAM,UAAU,aAAa,CAAC,GAAY;IACzC,IAAI,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IAC5B,OAAO,CACN,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC3B,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;QACjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAClC,CAAC;AACH,CAAC;AAED,MAAM,qBAAqB,GAAG;IAC7B,gBAAgB;IAChB,iBAAiB;IACjB,gCAAgC;CAChC,CAAC;AAEF,MAAM,UAAU,0BAA0B,CAAC,OAAe;IACzD,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,kBAAkB,CAC1B,QAAkB,EAClB,OAA2B;IAE3B,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CACzC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,KAAK,OAAO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AC;QACjC,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;IACvC,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC;IACpD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAED,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAED,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;IACvC,CAAC;IAED,MAAM,WAAW,GAAG,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;IACtE,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;IAED,IAAI,0BAA0B,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACnE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
package/docs/cli.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# CLI reference
|
|
2
|
+
|
|
3
|
+
## `neoorm init`
|
|
4
|
+
|
|
5
|
+
Scaffold a new NeoOrm project.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
neoorm init [options]
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Creates `neoorm.config.ts`, `schema.ts`, and `.env.example` only — no codegen or migrations. Run `neoorm migrate dev` afterwards to generate the client and first migration.
|
|
12
|
+
|
|
13
|
+
Options:
|
|
14
|
+
- `--provider <provider>` — `postgresql` (default) or `sqlite`. If omitted and running interactively, prompts to choose.
|
|
15
|
+
- `--database-url <url>` — override database URL / file path (default: `postgresql://postgres:postgres@localhost:5432/myapp` for postgres, `./dev.db` for sqlite)
|
|
16
|
+
- `--schema <path>` — schema file path (default: `./schema.ts`)
|
|
17
|
+
- `--out <dir>` — generated output directory (default: `./neoorm`)
|
|
18
|
+
- `--force` — overwrite existing scaffold files
|
|
19
|
+
|
|
20
|
+
## `neoorm generate`
|
|
21
|
+
|
|
22
|
+
Generate manifest, typed client, models, includes, and migrations from your schema.
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
neoorm generate [options]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Options:
|
|
29
|
+
- `--accept-data-loss` — include destructive DDL changes (column drops, type changes)
|
|
30
|
+
|
|
31
|
+
## `neoorm migrate dev`
|
|
32
|
+
|
|
33
|
+
Apply pending migrations, then generate a new migration if the schema changed.
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
neoorm migrate dev
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## `neoorm migrate deploy`
|
|
40
|
+
|
|
41
|
+
Apply all pending migrations.
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
neoorm migrate deploy
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## `neoorm migrate status`
|
|
48
|
+
|
|
49
|
+
List applied vs pending migrations.
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
neoorm migrate status
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Shows timestamps, pending folders on disk, and warnings for applied migrations missing on disk.
|
|
56
|
+
|
|
57
|
+
## `neoorm migrate down`
|
|
58
|
+
|
|
59
|
+
Roll back the most recently applied migration(s).
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
neoorm migrate down [--steps N]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
- `--steps` — number of migrations to roll back (default: 1)
|
|
66
|
+
|
|
67
|
+
Requires `down.sql` and `snapshot.before.json` in each migration folder (written automatically by `neoorm generate` and `neoorm migrate dev`).
|
|
68
|
+
|
|
69
|
+
## `neoorm migrate reset`
|
|
70
|
+
|
|
71
|
+
Drop the `public` schema (PostgreSQL) or all tables (SQLite) and re-apply all migrations.
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
neoorm migrate reset --force [--skip-apply]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- `--force` — required (safety guard)
|
|
78
|
+
- `--skip-apply` — only drop, don't re-apply
|
|
79
|
+
|
|
80
|
+
## `neoorm docs`
|
|
81
|
+
|
|
82
|
+
Serve the NeoOrm documentation locally in your browser.
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
neoorm docs [options]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Options:
|
|
89
|
+
- `-p, --port <port>` — port to listen on (default: `7583`)
|
|
90
|
+
- `-H, --host <host>` — host to bind (default: `127.0.0.1`)
|
|
91
|
+
- `--open` — open the docs site in your default browser
|
|
92
|
+
|
|
93
|
+
## `neoorm db push`
|
|
94
|
+
|
|
95
|
+
Push the current snapshot schema to the database without going through the migration ledger.
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
neoorm db push
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## `neoorm db pull`
|
|
102
|
+
|
|
103
|
+
Introspect the database and write a schema file.
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
neoorm db pull
|
|
107
|
+
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
The `neoorm.config.ts` file configures schema location, output directory, and datasource.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
// neoorm.config.ts
|
|
7
|
+
import { defineConfig } from "neoorm";
|
|
8
|
+
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
schema: "./schema.ts",
|
|
11
|
+
out: "./neoorm",
|
|
12
|
+
datasource: {
|
|
13
|
+
provider: "postgresql",
|
|
14
|
+
url: process.env.DATABASE_URL!,
|
|
15
|
+
schema: "public",
|
|
16
|
+
enum: "check",
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Options
|
|
22
|
+
|
|
23
|
+
| Key | Type | Default | Description |
|
|
24
|
+
|-----|------|---------|-------------|
|
|
25
|
+
| `schema` | `string` | required | Path to the schema file |
|
|
26
|
+
| `out` | `string` | required | Output directory for generated files |
|
|
27
|
+
| `datasource.provider` | `"postgresql" \| "sqlite"` | required | Database provider |
|
|
28
|
+
| `datasource.url` | `string` | required | Connection string (PostgreSQL) or database file path / `:memory:` (SQLite) |
|
|
29
|
+
| `datasource.schema` | `string` | `"public"` | PostgreSQL schema for migrations and queries (SQLite: not applicable) |
|
|
30
|
+
| `datasource.enum` | `"check" \| "union" \| "native"` | `"check"` | How to store enum columns |
|
|
31
|
+
|
|
32
|
+
### SQLite
|
|
33
|
+
|
|
34
|
+
Set `provider: "sqlite"` and `url` to a file path or `":memory:"`:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
datasource: {
|
|
38
|
+
provider: "sqlite",
|
|
39
|
+
url: "./dev.db",
|
|
40
|
+
},
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`datasource.schema` and `datasource.enum: "native"` are PostgreSQL-only and ignored on SQLite. See [SQLite](sqlite.md).
|
|
44
|
+
|
|
45
|
+
### Enum modes
|
|
46
|
+
|
|
47
|
+
| Mode | SQL | DB enforcement |
|
|
48
|
+
|------|-----|----------------|
|
|
49
|
+
| `check` (default) | `TEXT` + `CHECK (...)` | yes |
|
|
50
|
+
| `union` | `TEXT` | no (TypeScript union only) |
|
|
51
|
+
| `native` | Postgres `CREATE TYPE ... AS ENUM` | yes (PostgreSQL only) |
|
package/docs/errors.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Common errors
|
|
2
|
+
|
|
3
|
+
NeoOrm surfaces structured errors with explanations and fix suggestions. Catch them programmatically or read the CLI output after `neoorm generate` / query failures.
|
|
4
|
+
|
|
5
|
+
## Error types
|
|
6
|
+
|
|
7
|
+
- **`NeoOrmSchemaError`** — schema compilation (`neoorm generate`) or migration failures
|
|
8
|
+
- **`NeoOrmQueryError`** — query builder mistakes (compile phase) or database runtime failures
|
|
9
|
+
|
|
10
|
+
Both expose a `.context` object with `detail`, optional `code`, and `suggestions: string[]`.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { NeoOrmQueryError, NeoOrmSchemaError } from "neoorm";
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
await db.users.create({ data: { email: "a@b.com" } });
|
|
17
|
+
} catch (err) {
|
|
18
|
+
if (err instanceof NeoOrmQueryError) {
|
|
19
|
+
console.error(err.message);
|
|
20
|
+
console.error(err.context.suggestions);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Schema: use accessors, not SQL names
|
|
26
|
+
|
|
27
|
+
Foreign keys and `manyToMany()` targets refer to **schema accessors** (the keys in `defineSchema({ ... })`), not SQL table names.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
// Wrong — "server_members" is the SQL table name
|
|
31
|
+
userId: fk("server_members")
|
|
32
|
+
|
|
33
|
+
// Right — "serverMembers" is the accessor
|
|
34
|
+
userId: fk("serverMembers")
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
If you see `Foreign key references unknown table accessor "server_members"`, check the suggestions block for the correct camelCase accessor.
|
|
38
|
+
|
|
39
|
+
## Queries: use TypeScript column names
|
|
40
|
+
|
|
41
|
+
Filters, `select`, `omit`, `orderBy`, and `groupBy` use **TypeScript property names** from your schema, not SQL `snake_case` names.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
// Wrong
|
|
45
|
+
db.users.findMany({ where: { created_at: { gt: date } } });
|
|
46
|
+
|
|
47
|
+
// Right
|
|
48
|
+
db.users.findMany({ where: { createdAt: { gt: date } } });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Schema drift
|
|
52
|
+
|
|
53
|
+
Runtime errors like missing tables/columns often mean the database is behind your schema:
|
|
54
|
+
|
|
55
|
+
1. Run `neoorm migrate dev` (or `neoorm migrate deploy` in production)
|
|
56
|
+
2. Regenerate the client with `neoorm generate`
|
|
57
|
+
|
|
58
|
+
`NeoOrmQueryError` may include a **Migration** line with pending migration info when schema drift is detected.
|
|
59
|
+
|
|
60
|
+
## After changing the schema
|
|
61
|
+
|
|
62
|
+
Always regenerate after editing `schema.ts`:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
neoorm generate
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
If migrations are enabled, create and apply them:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
neoorm migrate dev
|
|
72
|
+
```
|