Skip to content
Merged
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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@antelopejs/interface-api-util": "^0.1.1",
"@antelopejs/interface-core": "^0.0.5",
"@antelopejs/interface-database": "^0.1.3",
"@antelopejs/interface-database-decorators": "^0.1.3",
"@antelopejs/interface-database-decorators": "^0.1.4",
"@biomejs/biome": "2.3.2",
"@types/chai": "^4.3.20",
"@types/mocha": "^10.0.10",
Expand Down
38 changes: 19 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/tests/components/access_control.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import type { SchemaInstance } from "@antelopejs/interface-database";
import {
BasicDataModel,
Field,
Index,
Model,
RegisterSchema,
Expand All @@ -38,10 +39,16 @@ class User extends Table {
declare _id: string;

@Index()
@Field("string")
declare email: string;

@Field("string")
declare password: string;

@Field("string")
declare name: string;

@Field("number")
declare age: number;
}
class UserModel extends BasicDataModel(User, userTableName) {}
Expand Down
9 changes: 9 additions & 0 deletions src/tests/components/computed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import {
import { Schema, type ValueProxy } from "@antelopejs/interface-database";
import {
BasicDataModel,
Field,
Index,
Model,
RegisterSchema,
RegisterTable,
Relation,
Table,
} from "@antelopejs/interface-database-decorators";
import { expect } from "chai";
Expand All @@ -44,15 +46,22 @@ const schemaName = "default";
@RegisterTable(groupTableName, schemaName)
class Group extends Table {
declare _id: string;

@Field("string")
declare name: string;
}
class GroupModel extends BasicDataModel(Group, groupTableName) {}

@RegisterTable(deviceTableName, schemaName)
class Device extends Table {
declare _id: string;

@Index()
@Field("string")
@Relation({ to: () => Group })
declare group_id: string;

@Field("string")
declare label: string;
}
class DeviceModel extends BasicDataModel(Device, deviceTableName) {}
Expand Down
12 changes: 12 additions & 0 deletions src/tests/components/foreign_joined.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import {
import { Schema } from "@antelopejs/interface-database";
import {
BasicDataModel,
Field,
Model,
RegisterSchema,
RegisterTable,
Relation,
Table,
} from "@antelopejs/interface-database-decorators";
import { expect } from "chai";
Expand All @@ -43,6 +45,8 @@ const schemaName = "default";
@RegisterTable(authorTableName, schemaName)
class Author extends Table {
declare _id: string;

@Field("string")
declare name: string;
}
class AuthorModel extends BasicDataModel(Author, authorTableName) {}
Expand All @@ -52,7 +56,12 @@ class AuthorModel extends BasicDataModel(Author, authorTableName) {}
@RegisterTable(bookTableName, schemaName)
class Book extends Table {
declare _id: string;

@Field("string")
@Relation({ to: () => Author })
declare authorId: string;

@Field("string")
declare title: string;
}
class BookModel extends BasicDataModel(Book, bookTableName) {}
Expand All @@ -62,6 +71,9 @@ class BookModel extends BasicDataModel(Book, bookTableName) {}
@RegisterTable(shelfTableName, schemaName)
class Shelf extends Table {
declare _id: string;

@Field("string")
@Relation({ to: () => Book })
declare book: string; // stores a Book._id
}
class ShelfModel extends BasicDataModel(Shelf, shelfTableName) {}
Expand Down
13 changes: 13 additions & 0 deletions src/tests/components/joined.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import {
import { Schema } from "@antelopejs/interface-database";
import {
BasicDataModel,
Field,
Model,
RegisterSchema,
RegisterTable,
Relation,
Table,
} from "@antelopejs/interface-database-decorators";
import { expect } from "chai";
Expand All @@ -41,16 +43,27 @@ const schemaName = "default";
@RegisterTable(authorTableName, schemaName)
class Author extends Table {
declare _id: string;

@Field("string")
declare name: string;

@Field("string")
declare email: string;
}
class AuthorModel extends BasicDataModel(Author, authorTableName) {}

@RegisterTable(bookTableName, schemaName)
class Book extends Table {
declare _id: string;

@Field("string")
@Relation({ to: () => Author })
declare authorId: string;

@Field("string")
declare title: string;

@Field("number")
declare price: number;
}
class BookModel extends BasicDataModel(Book, bookTableName) {}
Expand Down
13 changes: 13 additions & 0 deletions src/tests/components/listable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { Schema } from "@antelopejs/interface-database";
import {
BasicDataModel,
Field,
Index,
Model,
RegisterSchema,
Expand All @@ -41,13 +42,25 @@ class Product extends Table {
declare _id: string;

@Index()
@Field("string")
declare reference: string;

@Field("string")
declare name: string;

@Field("string")
declare description: string;

@Field("number")
declare price: number;

@Field("date")
declare addedAt: Date;

@Field("string")
declare internalNotes: string;

@Field("string")
declare metadata: string;
}
class ProductModel extends BasicDataModel(Product, productTableName) {}
Expand Down
11 changes: 11 additions & 0 deletions src/tests/components/mandatory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { Schema } from "@antelopejs/interface-database";
import {
BasicDataModel,
Field,
Index,
Model,
RegisterSchema,
Expand Down Expand Up @@ -41,12 +42,22 @@ class Order extends Table {
declare _id: string;

@Index()
@Field("string")
declare internalReference: string;

@Field("string")
declare customerName: string;

@Field("string")
declare customerEmail: string;

@Field("number")
declare totalAmount: number;

@Field("string")
declare status: string;

@Field("string")
declare notes: string;
}
class OrderModel extends BasicDataModel(Order, orderTableName) {}
Expand Down
9 changes: 9 additions & 0 deletions src/tests/components/modifier_key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import {
import { Schema } from "@antelopejs/interface-database";
import {
BasicDataModel,
Field,
LocalizationModifier,
Localized,
Model,
RegisterSchema,
RegisterTable,
Relation,
Table,
} from "@antelopejs/interface-database-decorators";
import { expect } from "chai";
Expand All @@ -42,14 +44,21 @@ const locale = "en";
@RegisterTable(authorTableName, schemaName)
class Author extends Table {
declare _id: string;

@Field("string")
declare name: string;

@Field("string")
declare email: string;
}
class AuthorModel extends BasicDataModel(Author, authorTableName) {}

@RegisterTable(postTableName, schemaName)
class Post extends Table.with(LocalizationModifier) {
declare _id: string;

@Field("string")
@Relation({ to: () => Author })
declare authorId: string | null;
Comment on lines +60 to 62

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The @Field("string") decorator on authorId doesn't reflect the field's nullable TypeScript type (string | null). Every other @Relation field in this PR is non-nullable, so this is the only case where the decorator metadata and the TypeScript type diverge. If the decorator library has a way to express nullability (e.g. a second options argument), annotating it here would make the schema metadata accurate.

Suggested change
@Field("string")
@Relation({ to: () => Author })
declare authorId: string | null;
@Field("string", { nullable: true })
@Relation({ to: () => Author })
declare authorId: string | null;
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/tests/components/modifier_key.test.ts
Line: 60-62

Comment:
The `@Field("string")` decorator on `authorId` doesn't reflect the field's nullable TypeScript type (`string | null`). Every other `@Relation` field in this PR is non-nullable, so this is the only case where the decorator metadata and the TypeScript type diverge. If the decorator library has a way to express nullability (e.g. a second options argument), annotating it here would make the schema metadata accurate.

```suggestion
  @Field("string", { nullable: true })
  @Relation({ to: () => Author })
  declare authorId: string | null;
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


@Localized()
Expand Down
Loading
Loading