metal-orm 1.0.73 → 1.0.74
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 +10 -10
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/decorators/bootstrap.ts +49 -32
- package/src/decorators/index.ts +12 -12
package/package.json
CHANGED
|
@@ -25,14 +25,14 @@ import {
|
|
|
25
25
|
|
|
26
26
|
import { tableRef, type TableRef } from '../schema/table.js';
|
|
27
27
|
import {
|
|
28
|
-
SelectableKeys,
|
|
29
|
-
ColumnDef,
|
|
30
|
-
HasManyCollection,
|
|
31
|
-
HasOneReference,
|
|
32
|
-
BelongsToReference,
|
|
33
|
-
ManyToManyCollection,
|
|
34
|
-
EntityInstance
|
|
35
|
-
} from '../schema/types.js';
|
|
28
|
+
SelectableKeys,
|
|
29
|
+
ColumnDef,
|
|
30
|
+
HasManyCollection,
|
|
31
|
+
HasOneReference,
|
|
32
|
+
BelongsToReference,
|
|
33
|
+
ManyToManyCollection,
|
|
34
|
+
EntityInstance
|
|
35
|
+
} from '../schema/types.js';
|
|
36
36
|
|
|
37
37
|
const unwrapTarget = (target: EntityOrTableTargetResolver): EntityOrTableTarget => {
|
|
38
38
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
@@ -197,9 +197,9 @@ type NonFunctionKeys<T> = {
|
|
|
197
197
|
type RelationKeys<TEntity extends object> =
|
|
198
198
|
Exclude<NonFunctionKeys<TEntity>, SelectableKeys<TEntity>> & string;
|
|
199
199
|
|
|
200
|
-
type EntityTable<TEntity extends object> =
|
|
201
|
-
Omit<TableDef<{ [K in SelectableKeys<TEntity>]: ColumnDef }>, 'relations'> & {
|
|
202
|
-
relations: {
|
|
200
|
+
type EntityTable<TEntity extends object> =
|
|
201
|
+
Omit<TableDef<{ [K in SelectableKeys<TEntity>]: ColumnDef }>, 'relations'> & {
|
|
202
|
+
relations: {
|
|
203
203
|
[K in RelationKeys<TEntity>]:
|
|
204
204
|
NonNullable<TEntity[K]> extends HasManyCollection<infer TChild>
|
|
205
205
|
? HasManyRelation<EntityTable<NonNullable<TChild> & object>>
|
|
@@ -215,18 +215,18 @@ type EntityTable<TEntity extends object> =
|
|
|
215
215
|
: NonNullable<TEntity[K]> extends object
|
|
216
216
|
? BelongsToRelation<EntityTable<NonNullable<TEntity[K]> & object>>
|
|
217
217
|
: never;
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
export type DecoratedEntityInstance<TEntity extends object> =
|
|
222
|
-
TEntity & EntityInstance<EntityTable<TEntity>>;
|
|
223
|
-
|
|
224
|
-
export const selectFromEntity = <TEntity extends object>(
|
|
225
|
-
ctor: EntityConstructor<TEntity>
|
|
226
|
-
): SelectQueryBuilder<DecoratedEntityInstance<TEntity>, EntityTable<TEntity>> => {
|
|
227
|
-
const table = getTableDefFromEntity(ctor);
|
|
228
|
-
if (!table) {
|
|
229
|
-
throw new Error(`Entity '${ctor.name}' is not registered with decorators or has not been bootstrapped`);
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export type DecoratedEntityInstance<TEntity extends object> =
|
|
222
|
+
TEntity & EntityInstance<EntityTable<TEntity>>;
|
|
223
|
+
|
|
224
|
+
export const selectFromEntity = <TEntity extends object>(
|
|
225
|
+
ctor: EntityConstructor<TEntity>
|
|
226
|
+
): SelectQueryBuilder<DecoratedEntityInstance<TEntity>, EntityTable<TEntity>> => {
|
|
227
|
+
const table = getTableDefFromEntity(ctor);
|
|
228
|
+
if (!table) {
|
|
229
|
+
throw new Error(`Entity '${ctor.name}' is not registered with decorators or has not been bootstrapped`);
|
|
230
230
|
}
|
|
231
231
|
return new SelectQueryBuilder(
|
|
232
232
|
table as unknown as EntityTable<TEntity>,
|
|
@@ -245,12 +245,29 @@ export const selectFromEntity = <TEntity extends object>(
|
|
|
245
245
|
* Lazily bootstraps entity metadata (via getTableDefFromEntity) and returns a
|
|
246
246
|
* `tableRef(...)`-style proxy so users can write `u.id` instead of `u.columns.id`.
|
|
247
247
|
*/
|
|
248
|
-
export const entityRef = <TEntity extends object>(
|
|
249
|
-
ctor: EntityConstructor<TEntity>
|
|
250
|
-
): TableRef<EntityTable<TEntity>> => {
|
|
251
|
-
const table = getTableDefFromEntity(ctor);
|
|
252
|
-
if (!table) {
|
|
253
|
-
throw new Error(`Entity '${ctor.name}' is not registered with decorators or has not been bootstrapped`);
|
|
254
|
-
}
|
|
255
|
-
return tableRef(table as EntityTable<TEntity>);
|
|
256
|
-
};
|
|
248
|
+
export const entityRef = <TEntity extends object>(
|
|
249
|
+
ctor: EntityConstructor<TEntity>
|
|
250
|
+
): TableRef<EntityTable<TEntity>> => {
|
|
251
|
+
const table = getTableDefFromEntity(ctor);
|
|
252
|
+
if (!table) {
|
|
253
|
+
throw new Error(`Entity '${ctor.name}' is not registered with decorators or has not been bootstrapped`);
|
|
254
|
+
}
|
|
255
|
+
return tableRef(table as EntityTable<TEntity>);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
type EntityRefsTuple<T extends readonly EntityConstructor<object>[]> = {
|
|
259
|
+
[K in keyof T]: T[K] extends EntityConstructor<infer TEntity>
|
|
260
|
+
? TableRef<EntityTable<TEntity & object>>
|
|
261
|
+
: never;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Public API: variadic entity references.
|
|
266
|
+
* Usage:
|
|
267
|
+
* const [u, p] = entityRefs(User, Post);
|
|
268
|
+
*/
|
|
269
|
+
export const entityRefs = <T extends readonly EntityConstructor<object>[]>(
|
|
270
|
+
...ctors: T
|
|
271
|
+
): EntityRefsTuple<T> => {
|
|
272
|
+
return ctors.map(ctor => entityRef(ctor)) as EntityRefsTuple<T>;
|
|
273
|
+
};
|
package/src/decorators/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decorators for defining entities, columns, and relations in Metal ORM.
|
|
3
|
-
*/
|
|
4
|
-
export * from './entity.js';
|
|
5
|
-
export * from './column-decorator.js';
|
|
6
|
-
export * from './relations.js';
|
|
7
|
-
export * from './bootstrap.js';
|
|
8
|
-
export { getDecoratorMetadata } from './decorator-metadata.js';
|
|
9
|
-
|
|
10
|
-
// Entity Materialization - convert query results to real class instances
|
|
11
|
-
export { materializeAs, DefaultEntityMaterializer, PrototypeMaterializationStrategy, ConstructorMaterializationStrategy } from '../orm/entity-materializer.js';
|
|
12
|
-
export type { EntityMaterializer, EntityMaterializationStrategy } from '../orm/entity-materializer.js';
|
|
1
|
+
/**
|
|
2
|
+
* Decorators for defining entities, columns, and relations in Metal ORM.
|
|
3
|
+
*/
|
|
4
|
+
export * from './entity.js';
|
|
5
|
+
export * from './column-decorator.js';
|
|
6
|
+
export * from './relations.js';
|
|
7
|
+
export * from './bootstrap.js';
|
|
8
|
+
export { getDecoratorMetadata } from './decorator-metadata.js';
|
|
9
|
+
|
|
10
|
+
// Entity Materialization - convert query results to real class instances
|
|
11
|
+
export { materializeAs, DefaultEntityMaterializer, PrototypeMaterializationStrategy, ConstructorMaterializationStrategy } from '../orm/entity-materializer.js';
|
|
12
|
+
export type { EntityMaterializer, EntityMaterializationStrategy } from '../orm/entity-materializer.js';
|