@t4h.framework/orm 0.11.0 → 0.11.2
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @t4h.framework/orm
|
|
2
2
|
|
|
3
|
+
## 0.11.2
|
|
4
|
+
|
|
5
|
+
## 0.11.1
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#203](https://github.com/tech4humans-brasil/framework/pull/203) [`952e756`](https://github.com/tech4humans-brasil/framework/commit/952e756562fac4cc143d0979c91c04036e133d90) Thanks [@gusteycamargo](https://github.com/gusteycamargo)! - `@OneToMany` receives `mappedBy` as a typed accessor in the second argument,
|
|
10
|
+
like `@OneToMany(() => Post, post => post.author)`, instead of a string in the
|
|
11
|
+
options. `orderBy` is now typed by the target entity's properties.
|
|
12
|
+
|
|
3
13
|
## 0.11.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -235,7 +235,7 @@ usersRef.at(0) // Ref<User> | undefined
|
|
|
235
235
|
```typescript
|
|
236
236
|
@Entity({ tableName: 'users' })
|
|
237
237
|
class User {
|
|
238
|
-
@OneToMany(() => Post,
|
|
238
|
+
@OneToMany(() => Post, post => post.author)
|
|
239
239
|
public posts!: MapCollection<Post>
|
|
240
240
|
}
|
|
241
241
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
orderBy?:
|
|
1
|
+
import type { Ref } from '../models/Ref.js';
|
|
2
|
+
import type { EntityConstructor, EntityData } from '../typings/ORM.js';
|
|
3
|
+
export interface OneToManyOptions<T> {
|
|
4
|
+
orderBy?: {
|
|
5
|
+
[K in keyof EntityData<T>]?: 'asc' | 'desc';
|
|
6
|
+
};
|
|
5
7
|
}
|
|
6
|
-
export declare function OneToMany(entity: () => EntityConstructor, options
|
|
8
|
+
export declare function OneToMany<T>(entity: () => EntityConstructor<T>, mappedBy: (entity: T) => Ref<any> | null | undefined, options?: OneToManyOptions<T>): PropertyDecorator;
|
|
7
9
|
//# sourceMappingURL=OneToMany.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OneToMany.d.ts","sourceRoot":"","sources":["../../src/decorators/OneToMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"OneToMany.d.ts","sourceRoot":"","sources":["../../src/decorators/OneToMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEtE,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE;SAAG,CAAC,IAAI,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM;KAAE,CAAA;CAC1D;AAID,wBAAgB,SAAS,CAAC,CAAC,EACzB,MAAM,EAAE,MAAM,iBAAiB,CAAC,CAAC,CAAC,EAClC,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,EACpD,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC5B,iBAAiB,CAmBnB"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { getEntityMetadata } from './metadata.js';
|
|
2
|
-
|
|
2
|
+
const propertyNames = new Proxy({}, { get: (_, property) => property });
|
|
3
|
+
export function OneToMany(entity, mappedBy, options) {
|
|
3
4
|
return (target, propertyKey) => {
|
|
4
|
-
if (!options?.mappedBy)
|
|
5
|
-
throw new Error(`@OneToMany "${String(propertyKey)}" requires a mappedBy property`);
|
|
6
|
-
const metadata = getEntityMetadata(target.constructor);
|
|
7
5
|
const name = propertyKey;
|
|
8
|
-
|
|
6
|
+
const property = mappedBy(propertyNames);
|
|
7
|
+
if (typeof property !== 'string')
|
|
8
|
+
throw new Error(`@OneToMany "${name}" must be mapped by a property of the target entity, like \`post => post.author\``);
|
|
9
|
+
getEntityMetadata(target.constructor).relations.set(name, {
|
|
9
10
|
name,
|
|
10
11
|
kind: 'one-to-many',
|
|
11
12
|
entity,
|
|
12
|
-
mappedBy:
|
|
13
|
-
orderBy: options
|
|
13
|
+
mappedBy: property,
|
|
14
|
+
orderBy: options?.orderBy,
|
|
14
15
|
});
|
|
15
16
|
};
|
|
16
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OneToMany.js","sourceRoot":"","sources":["../../src/decorators/OneToMany.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAQjD,MAAM,
|
|
1
|
+
{"version":3,"file":"OneToMany.js","sourceRoot":"","sources":["../../src/decorators/OneToMany.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAQjD,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAA;AAEvE,MAAM,UAAU,SAAS,CACvB,MAAkC,EAClC,QAAoD,EACpD,OAA6B;IAE7B,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE;QAC7B,MAAM,IAAI,GAAG,WAAqB,CAAA;QAElC,MAAM,QAAQ,GAAY,QAAQ,CAAC,aAAkB,CAAC,CAAA;QAEtD,IAAI,OAAO,QAAQ,KAAK,QAAQ;YAC9B,MAAM,IAAI,KAAK,CACb,eAAe,IAAI,mFAAmF,CACvG,CAAA;QAEH,iBAAiB,CAAC,MAAM,CAAC,WAA4B,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE;YACzE,IAAI;YACJ,IAAI,EAAE,aAAa;YACnB,MAAM;YACN,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE,OAAO,EAAE,OAAqD;SACxE,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t4h.framework/orm",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "ORM module for the T4H Framework",
|
|
5
5
|
"homepage": "https://github.com/tech4humans-brasil/framework/tree/main/packages/orm",
|
|
6
6
|
"bugs": "https://github.com/tech4humans-brasil/framework/issues",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"reflect-metadata": "^0.2.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@t4h.framework/core": "^0.
|
|
38
|
+
"@t4h.framework/core": "^0.19.0",
|
|
39
39
|
"typescript": "^5.9.3",
|
|
40
40
|
"vitest": "^4.0.18"
|
|
41
41
|
},
|