@cheetah.js/orm 0.1.69 → 0.1.71
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/dist/domain/reference.d.ts +71 -0
- package/dist/domain/reference.js +61 -1
- package/dist/driver/driver.interface.d.ts +1 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
|
@@ -1,4 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transparent wrapper type to prevent circular dependencies in TypeScript.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // Instead of direct import causing circular dependency:
|
|
7
|
+
* import { User } from './User';
|
|
8
|
+
* class Post {
|
|
9
|
+
* @ManyToOne()
|
|
10
|
+
* author: User; // Circular dependency!
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* // Use Ref to break the cycle:
|
|
14
|
+
* import type { User } from './User';
|
|
15
|
+
* class Post {
|
|
16
|
+
* @ManyToOne()
|
|
17
|
+
* author: Ref<User>; // No circular dependency!
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type Ref<T> = T;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a reference to an entity.
|
|
24
|
+
* This is an identity function - it returns the input unchanged.
|
|
25
|
+
* Useful for explicit ref creation when needed.
|
|
26
|
+
*
|
|
27
|
+
* @param entity - The entity to wrap in a reference
|
|
28
|
+
* @returns The same entity (identity function)
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const user = new User();
|
|
33
|
+
* const userRef = ref(user); // userRef === user (same reference)
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function ref<T>(entity: T): Ref<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Unwraps a reference to get the underlying entity.
|
|
39
|
+
* This is an identity function - it returns the input unchanged.
|
|
40
|
+
* Provided for API consistency and explicitness.
|
|
41
|
+
*
|
|
42
|
+
* @param reference - The reference to unwrap
|
|
43
|
+
* @returns The underlying entity (same as input)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const post = await Post.findOne({ id: 1 });
|
|
48
|
+
* const author = unwrap(post.author); // author === post.author
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function unwrap<T>(reference: Ref<T>): T;
|
|
52
|
+
/**
|
|
53
|
+
* Type guard to check if a value is not null or undefined.
|
|
54
|
+
* Useful when working with optional references.
|
|
55
|
+
*
|
|
56
|
+
* @param value - The value to check
|
|
57
|
+
* @returns True if value is not null/undefined
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const post = await Post.findOne({ id: 1 });
|
|
62
|
+
* if (isLoaded(post.author)) {
|
|
63
|
+
* console.log(post.author.name); // TypeScript knows author is defined
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function isLoaded<T>(value: Ref<T> | null | undefined): value is Ref<T>;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Use `Ref<T>` type instead. This class is kept for backward compatibility.
|
|
70
|
+
*/
|
|
1
71
|
export declare class Reference<T> {
|
|
2
72
|
private entity;
|
|
3
73
|
constructor(entity: T);
|
|
74
|
+
get(): T;
|
|
4
75
|
}
|
package/dist/domain/reference.js
CHANGED
|
@@ -1,10 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Reference = void 0;
|
|
4
|
+
exports.ref = ref;
|
|
5
|
+
exports.unwrap = unwrap;
|
|
6
|
+
exports.isLoaded = isLoaded;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a reference to an entity.
|
|
9
|
+
* This is an identity function - it returns the input unchanged.
|
|
10
|
+
* Useful for explicit ref creation when needed.
|
|
11
|
+
*
|
|
12
|
+
* @param entity - The entity to wrap in a reference
|
|
13
|
+
* @returns The same entity (identity function)
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const user = new User();
|
|
18
|
+
* const userRef = ref(user); // userRef === user (same reference)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function ref(entity) {
|
|
22
|
+
return entity;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Unwraps a reference to get the underlying entity.
|
|
26
|
+
* This is an identity function - it returns the input unchanged.
|
|
27
|
+
* Provided for API consistency and explicitness.
|
|
28
|
+
*
|
|
29
|
+
* @param reference - The reference to unwrap
|
|
30
|
+
* @returns The underlying entity (same as input)
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const post = await Post.findOne({ id: 1 });
|
|
35
|
+
* const author = unwrap(post.author); // author === post.author
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function unwrap(reference) {
|
|
39
|
+
return reference;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Type guard to check if a value is not null or undefined.
|
|
43
|
+
* Useful when working with optional references.
|
|
44
|
+
*
|
|
45
|
+
* @param value - The value to check
|
|
46
|
+
* @returns True if value is not null/undefined
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const post = await Post.findOne({ id: 1 });
|
|
51
|
+
* if (isLoaded(post.author)) {
|
|
52
|
+
* console.log(post.author.name); // TypeScript knows author is defined
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function isLoaded(value) {
|
|
57
|
+
return value != null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Use `Ref<T>` type instead. This class is kept for backward compatibility.
|
|
61
|
+
*/
|
|
4
62
|
class Reference {
|
|
5
63
|
constructor(entity) {
|
|
6
64
|
this.entity = entity;
|
|
7
|
-
|
|
65
|
+
}
|
|
66
|
+
get() {
|
|
67
|
+
return this.entity;
|
|
8
68
|
}
|
|
9
69
|
}
|
|
10
70
|
exports.Reference = Reference;
|
|
@@ -266,13 +266,9 @@ export type Relationship<T> = {
|
|
|
266
266
|
} & Partial<PropertyOptions>;
|
|
267
267
|
export type Cast<T, R> = T extends R ? T : R;
|
|
268
268
|
export type IsUnknown<T> = T extends unknown ? unknown extends T ? true : never : never;
|
|
269
|
-
export type IdentifiedReference<T, PK extends keyof T | unknown = PrimaryProperty<T>> = true extends IsUnknown<PK> ? Reference<T> : ({
|
|
270
|
-
[K in Cast<PK, keyof T>]: T[K];
|
|
271
|
-
} & Reference<T>);
|
|
272
|
-
export type Ref<T, PK extends keyof T | unknown = PrimaryProperty<T>> = IdentifiedReference<T, PK>;
|
|
273
269
|
type Loadable<T extends object> = Collection<T, any> | Reference<T> | readonly T[];
|
|
274
270
|
type ExtractType<T> = T extends Loadable<infer U> ? U : T;
|
|
275
|
-
type StringKeys<T, E extends string = never> = T extends Collection<any, any> ? `${Exclude<keyof ExtractType<T> | E, symbol>}` : T extends
|
|
271
|
+
type StringKeys<T, E extends string = never> = T extends Collection<any, any> ? `${Exclude<keyof ExtractType<T> | E, symbol>}` : T extends Reference<any> ? `${Exclude<keyof ExtractType<T> | E, symbol>}` : T extends object ? `${Exclude<keyof ExtractType<T> | E, symbol>}` : never;
|
|
276
272
|
type Defined<T> = Exclude<T, null | undefined>;
|
|
277
273
|
type GetStringKey<T, K extends StringKeys<T, string>, E extends string> = K extends keyof T ? ExtractType<T[K]> : (K extends E ? keyof T : never);
|
|
278
274
|
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './decorators/enum.decorator';
|
|
|
8
8
|
export * from './orm';
|
|
9
9
|
export * from './orm.service';
|
|
10
10
|
export * from './domain/base-entity';
|
|
11
|
+
export * from './domain/reference';
|
|
11
12
|
export { EntityStorage } from './domain/entities';
|
|
12
13
|
export * from './driver/bun-pg.driver';
|
|
13
14
|
export * from './driver/bun-mysql.driver';
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __exportStar(require("./decorators/enum.decorator"), exports);
|
|
|
25
25
|
__exportStar(require("./orm"), exports);
|
|
26
26
|
__exportStar(require("./orm.service"), exports);
|
|
27
27
|
__exportStar(require("./domain/base-entity"), exports);
|
|
28
|
+
__exportStar(require("./domain/reference"), exports);
|
|
28
29
|
var entities_1 = require("./domain/entities");
|
|
29
30
|
Object.defineProperty(exports, "EntityStorage", { enumerable: true, get: function () { return entities_1.EntityStorage; } });
|
|
30
31
|
__exportStar(require("./driver/bun-pg.driver"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cheetah.js/orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.71",
|
|
4
4
|
"description": "A simple ORM for Cheetah.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"bun",
|
|
56
56
|
"value-object"
|
|
57
57
|
],
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "45c36a4d8125e8937524a7a586bda671ef7725e3"
|
|
59
59
|
}
|