@antelopejs/interface-database-decorators 0.1.6 → 0.1.7
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 +0 -2
- package/dist/antelope.test.js +4 -3
- package/dist/antelope.test.js.map +1 -1
- package/dist/common.d.ts +2 -1
- package/dist/common.js +5 -1
- package/dist/common.js.map +1 -1
- package/dist/database.js +12 -8
- package/dist/database.js.map +1 -1
- package/dist/model.d.ts +2 -2
- package/dist/model.js +10 -10
- package/dist/model.js.map +1 -1
- package/dist/modifiers/autodate.js.map +1 -1
- package/dist/modifiers/common.js.map +1 -1
- package/dist/modifiers/encryption.js +1 -1
- package/dist/modifiers/encryption.js.map +1 -1
- package/dist/modifiers/hash.js +1 -1
- package/dist/modifiers/hash.js.map +1 -1
- package/dist/modifiers/localization.js.map +1 -1
- package/dist/relation.js.map +1 -1
- package/dist/schema.js.map +1 -1
- package/dist/table.d.ts +21 -5
- package/dist/table.js +8 -8
- package/dist/table.js.map +1 -1
- package/dist/tests/common.test.js +1 -1
- package/dist/tests/common.test.js.map +1 -1
- package/dist/tests/database.test.js +80 -2
- package/dist/tests/database.test.js.map +1 -1
- package/dist/tests/integration.test.js +4 -4
- package/dist/tests/integration.test.js.map +1 -1
- package/dist/tests/model.test.js +4 -4
- package/dist/tests/model.test.js.map +1 -1
- package/dist/tests/modifiers/autodate.test.js +3 -3
- package/dist/tests/modifiers/autodate.test.js.map +1 -1
- package/dist/tests/modifiers/common.test.js +2 -2
- package/dist/tests/modifiers/common.test.js.map +1 -1
- package/dist/tests/modifiers/encryption.test.js +2 -2
- package/dist/tests/modifiers/encryption.test.js.map +1 -1
- package/dist/tests/modifiers/hash.test.js +2 -2
- package/dist/tests/modifiers/hash.test.js.map +1 -1
- package/dist/tests/modifiers/localization.test.js +2 -2
- package/dist/tests/modifiers/localization.test.js.map +1 -1
- package/dist/tests/relation.test.js +2 -2
- package/dist/tests/relation.test.js.map +1 -1
- package/dist/tests/schema.test.js +2 -2
- package/dist/tests/schema.test.js.map +1 -1
- package/dist/tests/table.test.js +11 -11
- package/dist/tests/table.test.js.map +1 -1
- package/docs/2.table-definitions.md +68 -17
- package/docs/3.table-modifiers.md +77 -23
- package/docs/4.data-models.md +4 -4
- package/docs/5.parameter-decoration.md +14 -3
- package/package.json +66 -57
- package/skills/database-decorators-interface/SKILL.md +60 -16
package/package.json
CHANGED
|
@@ -1,27 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/interface-database-decorators",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "AntelopeJS interface for database schema decorators and model definitions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
7
|
-
"interface",
|
|
8
7
|
"database",
|
|
9
8
|
"decorators",
|
|
9
|
+
"interface",
|
|
10
10
|
"orm"
|
|
11
11
|
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
14
15
|
"url": "git+https://github.com/AntelopeJS/interface-database-decorators.git"
|
|
15
16
|
},
|
|
16
|
-
"license": "Apache-2.0",
|
|
17
|
-
"packageManager": "pnpm@10.6.5",
|
|
18
|
-
"main": "dist/index.js",
|
|
19
|
-
"types": "dist/index.d.ts",
|
|
20
17
|
"files": [
|
|
21
18
|
"dist",
|
|
22
19
|
"docs",
|
|
23
20
|
"skills"
|
|
24
21
|
],
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"typesVersions": {
|
|
25
|
+
"*": {
|
|
26
|
+
"common": [
|
|
27
|
+
"dist/common.d.ts"
|
|
28
|
+
],
|
|
29
|
+
"database": [
|
|
30
|
+
"dist/database.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"model": [
|
|
33
|
+
"dist/model.d.ts"
|
|
34
|
+
],
|
|
35
|
+
"relation": [
|
|
36
|
+
"dist/relation.d.ts"
|
|
37
|
+
],
|
|
38
|
+
"schema": [
|
|
39
|
+
"dist/schema.d.ts"
|
|
40
|
+
],
|
|
41
|
+
"table": [
|
|
42
|
+
"dist/table.d.ts"
|
|
43
|
+
],
|
|
44
|
+
"modifiers/autodate": [
|
|
45
|
+
"dist/modifiers/autodate.d.ts"
|
|
46
|
+
],
|
|
47
|
+
"modifiers/common": [
|
|
48
|
+
"dist/modifiers/common.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"modifiers/encryption": [
|
|
51
|
+
"dist/modifiers/encryption.d.ts"
|
|
52
|
+
],
|
|
53
|
+
"modifiers/hash": [
|
|
54
|
+
"dist/modifiers/hash.d.ts"
|
|
55
|
+
],
|
|
56
|
+
"modifiers/localization": [
|
|
57
|
+
"dist/modifiers/localization.d.ts"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
},
|
|
25
61
|
"exports": {
|
|
26
62
|
".": {
|
|
27
63
|
"types": "./dist/index.d.ts",
|
|
@@ -73,81 +109,54 @@
|
|
|
73
109
|
},
|
|
74
110
|
"./package.json": "./package.json"
|
|
75
111
|
},
|
|
112
|
+
"publishConfig": {
|
|
113
|
+
"access": "public",
|
|
114
|
+
"provenance": true
|
|
115
|
+
},
|
|
76
116
|
"scripts": {
|
|
77
117
|
"build": "rimraf dist && tsc",
|
|
78
|
-
"format": "
|
|
79
|
-
"lint:fix": "
|
|
80
|
-
"lint": "
|
|
118
|
+
"format": "oxfmt .",
|
|
119
|
+
"lint:fix": "oxlint --fix",
|
|
120
|
+
"lint": "oxlint",
|
|
81
121
|
"prepack": "pnpm run build",
|
|
82
122
|
"release": "pnpm run lint && pnpm run prepack && release-it",
|
|
83
|
-
"test": "pnpm run build && ajs module test ."
|
|
123
|
+
"test": "pnpm run build && ajs module test .",
|
|
124
|
+
"format:check": "oxfmt --check .",
|
|
125
|
+
"knip": "knip"
|
|
84
126
|
},
|
|
85
127
|
"dependencies": {
|
|
86
128
|
"randomstring": "^1.3.1",
|
|
87
129
|
"reflect-metadata": "^0.2.2"
|
|
88
130
|
},
|
|
89
131
|
"devDependencies": {
|
|
90
|
-
"@antelopejs/
|
|
91
|
-
"@antelopejs/interface-
|
|
92
|
-
"@antelopejs/interface-
|
|
93
|
-
"@
|
|
132
|
+
"@antelopejs/core": "^1.9.1",
|
|
133
|
+
"@antelopejs/interface-api": "^0.0.13",
|
|
134
|
+
"@antelopejs/interface-core": "^0.1.1",
|
|
135
|
+
"@antelopejs/interface-database": "^0.1.8",
|
|
136
|
+
"@antelopejs/tooling-configs": "^0.0.6",
|
|
94
137
|
"@types/chai": "^4.3.20",
|
|
95
138
|
"@types/mocha": "^10.0.10",
|
|
96
139
|
"@types/node": "^22.19.15",
|
|
97
140
|
"@types/randomstring": "^1.3.0",
|
|
98
141
|
"@types/semver": "^7.7.1",
|
|
99
142
|
"chai": "^4.5.0",
|
|
143
|
+
"eslint-plugin-perfectionist": "^5.11.0",
|
|
144
|
+
"knip": "^6.34.0",
|
|
100
145
|
"mongodb-memory-server-core": "^10.4.3",
|
|
146
|
+
"oxfmt": "^0.66.0",
|
|
147
|
+
"oxlint": "1.81.0",
|
|
148
|
+
"oxlint-tsgolint": "^7.0.2001",
|
|
101
149
|
"release-it": "^19.2.4",
|
|
102
150
|
"release-it-changelogen": "^0.1.0",
|
|
103
151
|
"rimraf": "^6.1.3",
|
|
104
152
|
"typescript": "^5.9.3"
|
|
105
153
|
},
|
|
106
154
|
"peerDependencies": {
|
|
107
|
-
"@antelopejs/interface-api": ">=0.0.
|
|
108
|
-
"@antelopejs/interface-core": ">=0.
|
|
109
|
-
"@antelopejs/interface-database": ">=0.1.
|
|
110
|
-
},
|
|
111
|
-
"publishConfig": {
|
|
112
|
-
"access": "public"
|
|
113
|
-
},
|
|
114
|
-
"typesVersions": {
|
|
115
|
-
"*": {
|
|
116
|
-
"common": [
|
|
117
|
-
"dist/common.d.ts"
|
|
118
|
-
],
|
|
119
|
-
"database": [
|
|
120
|
-
"dist/database.d.ts"
|
|
121
|
-
],
|
|
122
|
-
"model": [
|
|
123
|
-
"dist/model.d.ts"
|
|
124
|
-
],
|
|
125
|
-
"relation": [
|
|
126
|
-
"dist/relation.d.ts"
|
|
127
|
-
],
|
|
128
|
-
"schema": [
|
|
129
|
-
"dist/schema.d.ts"
|
|
130
|
-
],
|
|
131
|
-
"table": [
|
|
132
|
-
"dist/table.d.ts"
|
|
133
|
-
],
|
|
134
|
-
"modifiers/autodate": [
|
|
135
|
-
"dist/modifiers/autodate.d.ts"
|
|
136
|
-
],
|
|
137
|
-
"modifiers/common": [
|
|
138
|
-
"dist/modifiers/common.d.ts"
|
|
139
|
-
],
|
|
140
|
-
"modifiers/encryption": [
|
|
141
|
-
"dist/modifiers/encryption.d.ts"
|
|
142
|
-
],
|
|
143
|
-
"modifiers/hash": [
|
|
144
|
-
"dist/modifiers/hash.d.ts"
|
|
145
|
-
],
|
|
146
|
-
"modifiers/localization": [
|
|
147
|
-
"dist/modifiers/localization.d.ts"
|
|
148
|
-
]
|
|
149
|
-
}
|
|
155
|
+
"@antelopejs/interface-api": ">=0.0.13 <1.0.0",
|
|
156
|
+
"@antelopejs/interface-core": ">=0.1.1 <1.0.0",
|
|
157
|
+
"@antelopejs/interface-database": ">=0.1.8 <1.0.0"
|
|
150
158
|
},
|
|
159
|
+
"packageManager": "pnpm@10.6.5",
|
|
151
160
|
"antelopeJs": {
|
|
152
161
|
"standalone": true,
|
|
153
162
|
"test": "src/antelope.test.ts",
|
|
@@ -15,17 +15,50 @@ Peer interfaces required: `@antelopejs/interface-core`, `@antelopejs/interface-a
|
|
|
15
15
|
## Imports
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
|
-
import {
|
|
19
|
-
|
|
18
|
+
import {
|
|
19
|
+
Table,
|
|
20
|
+
Field,
|
|
21
|
+
Index,
|
|
22
|
+
Fixture,
|
|
23
|
+
} from "@antelopejs/interface-database-decorators/table";
|
|
24
|
+
import {
|
|
25
|
+
RegisterTable,
|
|
26
|
+
getTablesForSchema,
|
|
27
|
+
} from "@antelopejs/interface-database-decorators/schema";
|
|
20
28
|
import { RegisterSchema } from "@antelopejs/interface-database-decorators/database";
|
|
21
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
BasicDataModel,
|
|
31
|
+
GetModel,
|
|
32
|
+
Model,
|
|
33
|
+
} from "@antelopejs/interface-database-decorators/model";
|
|
22
34
|
import { Relation } from "@antelopejs/interface-database-decorators/relation";
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
import {
|
|
28
|
-
|
|
35
|
+
import {
|
|
36
|
+
DatumStaticMetadata,
|
|
37
|
+
getMetadata,
|
|
38
|
+
} from "@antelopejs/interface-database-decorators/common";
|
|
39
|
+
import {
|
|
40
|
+
CreationTime,
|
|
41
|
+
UpdateTime,
|
|
42
|
+
} from "@antelopejs/interface-database-decorators/modifiers/autodate";
|
|
43
|
+
import {
|
|
44
|
+
Encrypted,
|
|
45
|
+
EncryptionModifier,
|
|
46
|
+
} from "@antelopejs/interface-database-decorators/modifiers/encryption";
|
|
47
|
+
import {
|
|
48
|
+
Hashed,
|
|
49
|
+
HashModifier,
|
|
50
|
+
} from "@antelopejs/interface-database-decorators/modifiers/hash";
|
|
51
|
+
import {
|
|
52
|
+
Localized,
|
|
53
|
+
LocalizationModifier,
|
|
54
|
+
} from "@antelopejs/interface-database-decorators/modifiers/localization";
|
|
55
|
+
import {
|
|
56
|
+
Modifier,
|
|
57
|
+
OneWayModifier,
|
|
58
|
+
TwoWayModifier,
|
|
59
|
+
attachModifier,
|
|
60
|
+
toPlainData,
|
|
61
|
+
} from "@antelopejs/interface-database-decorators/modifiers/common";
|
|
29
62
|
```
|
|
30
63
|
|
|
31
64
|
The package root re-exports everything above and also imports `reflect-metadata` (see gotchas).
|
|
@@ -36,7 +69,8 @@ The package root re-exports everything above and also imports `reflect-metadata`
|
|
|
36
69
|
@RegisterTable("recipes", "cookbook") // (tableName, schemaName)
|
|
37
70
|
class Recipe extends Table {
|
|
38
71
|
// _id: string is inherited as the primary key
|
|
39
|
-
@Index()
|
|
72
|
+
@Index()
|
|
73
|
+
@Field("string")
|
|
40
74
|
declare slug: string;
|
|
41
75
|
@Field("string")
|
|
42
76
|
declare tagline: string;
|
|
@@ -46,7 +80,10 @@ const RecipeModel = BasicDataModel(Recipe); // table name taken from @RegisterTa
|
|
|
46
80
|
await RegisterSchema("cookbook"); // once at startup: provisions all tables registered for "cookbook", runs fixtures
|
|
47
81
|
|
|
48
82
|
const recipes = GetModel(RecipeModel); // cached per (model class, instanceId)
|
|
49
|
-
await recipes.insert(
|
|
83
|
+
await recipes.insert(
|
|
84
|
+
{ slug: "grilled-halloumi", tagline: "Smoky skewers" },
|
|
85
|
+
{ validate: true },
|
|
86
|
+
);
|
|
50
87
|
const bySlug = await recipes.getBy("slug", "grilled-halloumi");
|
|
51
88
|
const one = await recipes.get(bySlug[0]._id);
|
|
52
89
|
await recipes.update(one._id, { tagline: "Smoky halloumi skewers" });
|
|
@@ -68,12 +105,16 @@ class RecipesController extends Controller("/recipes") {
|
|
|
68
105
|
## Field modifiers
|
|
69
106
|
|
|
70
107
|
```typescript
|
|
71
|
-
class Chef extends Table.with(
|
|
72
|
-
|
|
108
|
+
class Chef extends Table.with(
|
|
109
|
+
HashModifier,
|
|
110
|
+
EncryptionModifier,
|
|
111
|
+
LocalizationModifier,
|
|
112
|
+
) {
|
|
113
|
+
@Hashed() declare passphrase: string; // one-way; test via instance.testHash("passphrase", value)
|
|
73
114
|
@Encrypted({ secretKey }) declare supplierCode: string; // transparent encrypt/decrypt (autolock + autounlock)
|
|
74
|
-
@Localized() declare motto: string;
|
|
75
|
-
@CreationTime() declare hiredAt: Date;
|
|
76
|
-
@UpdateTime() declare lastActiveAt: Date;
|
|
115
|
+
@Localized() declare motto: string; // read AND write via instance.localize("en", ["motto"])
|
|
116
|
+
@CreationTime() declare hiredAt: Date; // set on insert, stripped from updates
|
|
117
|
+
@UpdateTime() declare lastActiveAt: Date; // refreshed on insert and update
|
|
77
118
|
}
|
|
78
119
|
```
|
|
79
120
|
|
|
@@ -91,6 +132,9 @@ class Chef extends Table.with(HashModifier, EncryptionModifier, LocalizationModi
|
|
|
91
132
|
io-ts-style codec with `.decode`; plain string field tokens are skipped. Update validates with
|
|
92
133
|
`{ partial: true }` semantics.
|
|
93
134
|
- `update(obj)` without an explicit id asserts that the object carries the primary key (`_id` by default).
|
|
135
|
+
- Indexes are scoped to the schema instance. Add `@Index({ crossInstance: true })` only for indexes also queried
|
|
136
|
+
across all instances (`CROSS_INSTANCE`); it never changes results, only speed. On a group, one member setting it
|
|
137
|
+
applies it to the whole group.
|
|
94
138
|
- `@Fixture` data is only inserted by `RegisterSchema` when the table is empty (count === 0).
|
|
95
139
|
- `GetModel` caches by model class + instanceId; the same pair always returns the same instance.
|
|
96
140
|
- Serialization of modified instances to plain JSON goes through `toPlainData` (auto-attached as `toJSON`).
|