Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Formatted with oxfmt when the repository moved off Biome.
60a18ac11e6276341d471268d169b7d2bf4f0eaa
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ jobs:
- run: pnpm add --global @antelopejs/core
- run: pnpm prepack
- run: pnpm lint
- run: pnpm format:check
- run: pnpm knip
- run: pnpm test
8 changes: 4 additions & 4 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: 'Close stale issues'
name: "Close stale issues"

on:
schedule:
- cron: '30 * * * *'
- cron: "30 * * * *"
workflow_dispatch:

permissions:
Expand All @@ -17,8 +17,8 @@ jobs:
- uses: actions/stale@v9
with:
exempt-issue-labels: pending
stale-issue-message: 'This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.'
close-issue-message: 'This issue was closed because it has been stalled for 30 days with no activity.'
stale-issue-message: "This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days."
close-issue-message: "This issue was closed because it has been stalled for 30 days with no activity."
days-before-stale: 60
days-before-close: 30
operations-per-run: 200
Expand Down
18 changes: 9 additions & 9 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
| --------------------- | --------------------------------------------------------------------------------------- |
| English only | All code must be in English: variable names, function names, comments |
| PNPM only | Always use pnpm, never npm or yarn |
| NO COMMENTS | Code must be self-documenting through clear naming. TSDoc is allowed for public APIs |
| NO COMMENTS | Code must be self-documenting through clear naming. TSDoc is allowed for public APIs |
| NO switch/case | Use objects, maps, or arrays instead |
| NO inline types | Define proper interfaces/types, never use anonymous types like `{a: string, b: number}` |
| Functions ≤ 40 lines | Split into subfunctions if longer |
Expand All @@ -35,23 +35,23 @@ Never use `switch/case` or `if param === 'XXX'` chains. Instead:
// BAD
function getStatus(code: string) {
switch (code) {
case 'A':
return 'Active';
case 'I':
return 'Inactive';
case "A":
return "Active";
case "I":
return "Inactive";
default:
return 'Unknown';
return "Unknown";
}
}

// GOOD
const STATUS_MAP: Record<string, string> = {
A: 'Active',
I: 'Inactive',
A: "Active",
I: "Inactive",
};

function getStatus(code: string) {
return STATUS_MAP[code] ?? 'Unknown';
return STATUS_MAP[code] ?? "Unknown";
}
```

Expand Down
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Changelog


## v0.1.6

[compare changes](https://github.com/AntelopeJS/interface-database-decorators/compare/v0.1.5...v0.1.6)
Expand Down Expand Up @@ -134,7 +133,6 @@

## v0.0.2


### 🚀 Enhancements

- Add database decorators interface implementation ([f470fb9](https://github.com/AntelopeJS/interface-database-decorators/commit/f470fb9))
Expand All @@ -158,4 +156,3 @@

- Antony Rizzitelli <upd4ting@gmail.com>
- Glastis ([@Glastis](http://github.com/Glastis))

56 changes: 0 additions & 56 deletions biome.json

This file was deleted.

66 changes: 50 additions & 16 deletions docs/2.table-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ class User extends Table {
The `Table.with()` static method incorporates modifier mixins into the table class, adding capabilities like encryption, hashing, or localization:

```typescript
import { Table, Field, EncryptionModifier, Encrypted } from "@antelopejs/interface-database-decorators";
import {
Table,
Field,
EncryptionModifier,
Encrypted,
} from "@antelopejs/interface-database-decorators";

class SensitiveData extends Table.with(EncryptionModifier) {
@Field("string")
Expand Down Expand Up @@ -56,16 +61,21 @@ class User extends Table {

### Options

| Option | Type | Description |
| ------- | -------- | ----------------------------------------------- |
| Option | Type | Description |
| ------- | -------- | ------------------------------------------------- |
| `group` | `string` | Assign the field to a named compound index group. |

### Compound Indexes

Assign multiple fields to the same index group to create a compound index:

```typescript
import { Table, Field, Index, Relation } from "@antelopejs/interface-database-decorators";
import {
Table,
Field,
Index,
Relation,
} from "@antelopejs/interface-database-decorators";

class User extends Table {
@Field("string")
Expand Down Expand Up @@ -93,7 +103,12 @@ class UserActivity extends Table {

```typescript
import * as t from "io-ts";
import { Table, Field, Index, RegisterTable } from "@antelopejs/interface-database-decorators";
import {
Table,
Field,
Index,
RegisterTable,
} from "@antelopejs/interface-database-decorators";

@RegisterTable("orders", "shop")
class Order extends Table {
Expand All @@ -116,7 +131,12 @@ Properties without `@Field` are omitted from `fields`. `@Field` stacks freely wi
The `Relation` decorator declares a link from a field to another table. It is **declarative metadata only**: database implementations do not enforce it (no foreign key constraint, no referential validation). Introspection tooling consumes it to expose the links between tables — for example to render schema diagrams or navigate related records.

```typescript
import { Table, Field, Index, Relation } from "@antelopejs/interface-database-decorators";
import {
Table,
Field,
Index,
Relation,
} from "@antelopejs/interface-database-decorators";

class Comment extends Table {
@Index()
Expand All @@ -132,11 +152,11 @@ class Comment extends Table {

### Options

| Option | Type | Description |
| --------- | ------------------- | ---------------------------------------------------------------------- |
| `to` | `() => typeof Table` | Thunk returning the target table class (lazy to allow forward references). |
| `toField` | `string` | Target field name. Defaults to the target table's primary key. |
| `many` | `boolean` | The decorated field holds multiple target keys (many targets per source record). |
| Option | Type | Description |
| --------- | -------------------- | -------------------------------------------------------------------------------- |
| `to` | `() => typeof Table` | Thunk returning the target table class (lazy to allow forward references). |
| `toField` | `string` | Target field name. Defaults to the target table's primary key. |
| `many` | `boolean` | The decorated field holds multiple target keys (many targets per source record). |

`@Relation` stacks freely with `@Field` and `@Index`.

Expand All @@ -145,7 +165,12 @@ class Comment extends Table {
The `RegisterTable` class decorator associates a table class with a specific table name and schema. This registration is used by `RegisterSchema` to build the schema definition automatically.

```typescript
import { Table, Field, Index, RegisterTable } from "@antelopejs/interface-database-decorators";
import {
Table,
Field,
Index,
RegisterTable,
} from "@antelopejs/interface-database-decorators";

@RegisterTable("users", "myapp")
class User extends Table {
Expand All @@ -165,7 +190,11 @@ The first argument is the table name in the database, and the second is the sche
The `Fixture` decorator defines default data to insert when a table is first created. It receives a generator function that produces initial records.

```typescript
import { Table, Field, Fixture } from "@antelopejs/interface-database-decorators";
import {
Table,
Field,
Fixture,
} from "@antelopejs/interface-database-decorators";

@Fixture(() => [
{ _id: "admin", name: "Administrator" },
Expand Down Expand Up @@ -205,7 +234,12 @@ class SystemConfig extends Table {
Tables support standard class inheritance. Define a base table with common fields and extend it for specific use cases:

```typescript
import { Table, Field, Index, Relation } from "@antelopejs/interface-database-decorators";
import {
Table,
Field,
Index,
Relation,
} from "@antelopejs/interface-database-decorators";

class BaseEntity extends Table {
@Field("date")
Expand Down Expand Up @@ -253,8 +287,8 @@ await RegisterSchema("myapp");

### Parameters

| Parameter | Type | Description |
| ---------- | -------- | ----------------------------------------------------------------- |
| Parameter | Type | Description |
| ---------- | -------- | ------------------------------------------------------------------ |
| `schemaId` | `string` | Schema id matching the `@RegisterTable(_, schemaId)` declarations. |

`RegisterSchema` returns `Promise<void>`.
Loading
Loading