@cheetah.js/orm 0.1.74 → 0.1.75

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.
@@ -73,3 +73,14 @@ export declare class Reference<T> {
73
73
  constructor(entity: T);
74
74
  get(): T;
75
75
  }
76
+ /**
77
+ * Creates a lightweight entity reference by class and id without hitting the DB.
78
+ * Useful to assign many-to-one relations when only the id is known.
79
+ *
80
+ * Example:
81
+ * const library = await UserLibrary.create({
82
+ * user: refById(User, userId),
83
+ * course: refById(Course, courseId),
84
+ * });
85
+ */
86
+ export declare function refById<C extends new () => any, T = InstanceType<C>, PK = any>(Cls: C, id: PK): T;
@@ -4,6 +4,7 @@ exports.Reference = void 0;
4
4
  exports.ref = ref;
5
5
  exports.unwrap = unwrap;
6
6
  exports.isLoaded = isLoaded;
7
+ exports.refById = refById;
7
8
  /**
8
9
  * Creates a reference to an entity.
9
10
  * This is an identity function - it returns the input unchanged.
@@ -68,3 +69,18 @@ class Reference {
68
69
  }
69
70
  }
70
71
  exports.Reference = Reference;
72
+ /**
73
+ * Creates a lightweight entity reference by class and id without hitting the DB.
74
+ * Useful to assign many-to-one relations when only the id is known.
75
+ *
76
+ * Example:
77
+ * const library = await UserLibrary.create({
78
+ * user: refById(User, userId),
79
+ * course: refById(Course, courseId),
80
+ * });
81
+ */
82
+ function refById(Cls, id) {
83
+ const entity = new Cls();
84
+ entity.id = id;
85
+ return entity;
86
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cheetah.js/orm",
3
- "version": "0.1.74",
3
+ "version": "0.1.75",
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": "8df23352a8be4a868d1ce60e6309cb062066267b"
58
+ "gitHead": "fd5625d62854bb94b4ddd6ea93a8e4d15dc2b180"
59
59
  }