metal-orm 1.0.98 → 1.0.100

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.
@@ -1,31 +1,31 @@
1
- import type {
2
- BelongsToReference,
3
- HasManyCollection,
4
- HasOneReference,
5
- ManyToManyCollection
6
- } from '../schema/types.js';
7
-
8
- type AnyId = number | string;
9
- type AnyFn = (...args: unknown[]) => unknown;
10
-
11
- type RelationWrapper =
12
- | HasManyCollection<unknown>
13
- | HasOneReference
14
- | BelongsToReference
15
- | ManyToManyCollection<unknown>;
16
-
17
- type FunctionKeys<T> = {
18
- [K in keyof T & string]-?: T[K] extends AnyFn ? K : never;
19
- }[keyof T & string];
20
-
21
- type RelationKeys<T> = {
22
- [K in keyof T & string]-?: NonNullable<T[K]> extends RelationWrapper ? K : never;
23
- }[keyof T & string];
24
-
25
- type ColumnKeys<T> = Exclude<keyof T & string, FunctionKeys<T> | RelationKeys<T>>;
26
-
27
- export type SaveGraphJsonScalar<T> = T extends Date ? string : T;
28
-
1
+ import type {
2
+ BelongsToReference,
3
+ HasManyCollection,
4
+ HasOneReference,
5
+ ManyToManyCollection
6
+ } from '../schema/types.js';
7
+
8
+ type AnyId = number | string;
9
+ type AnyFn = (...args: unknown[]) => unknown;
10
+
11
+ type RelationWrapper =
12
+ | HasManyCollection<unknown>
13
+ | HasOneReference
14
+ | BelongsToReference
15
+ | ManyToManyCollection<unknown>;
16
+
17
+ type FunctionKeys<T> = {
18
+ [K in keyof T & string]-?: T[K] extends AnyFn ? K : never;
19
+ }[keyof T & string];
20
+
21
+ type RelationKeys<T> = {
22
+ [K in keyof T & string]-?: NonNullable<T[K]> extends RelationWrapper ? K : never;
23
+ }[keyof T & string];
24
+
25
+ type ColumnKeys<T> = Exclude<keyof T & string, FunctionKeys<T> | RelationKeys<T>>;
26
+
27
+ export type SaveGraphJsonScalar<T> = T extends Date ? string : T;
28
+
29
29
  /**
30
30
  * Input scalar type for `OrmSession.saveGraph` payloads.
31
31
  *
@@ -33,24 +33,31 @@ export type SaveGraphJsonScalar<T> = T extends Date ? string : T;
33
33
  * For Date columns, string input is only safe when using `coerce: 'json-in'`.
34
34
  */
35
35
  export type SaveGraphInputScalar<T> = T extends Date ? T | string | number : T;
36
-
37
- type ColumnInput<TEntity> = {
38
- [K in ColumnKeys<TEntity>]?: SaveGraphInputScalar<TEntity[K]>;
39
- };
40
-
41
- type RelationInputValue<T> =
42
- T extends HasManyCollection<infer C> ? Array<SaveGraphInputPayload<C> | AnyId> :
43
- T extends HasOneReference<infer C> ? SaveGraphInputPayload<C> | AnyId | null :
44
- T extends BelongsToReference<infer P> ? SaveGraphInputPayload<P> | AnyId | null :
45
- T extends ManyToManyCollection<infer Tgt> ? Array<SaveGraphInputPayload<Tgt> | AnyId> :
46
- never;
47
-
48
- type RelationInput<TEntity> = {
49
- [K in RelationKeys<TEntity>]?: RelationInputValue<NonNullable<TEntity[K]>>;
50
- };
51
-
52
- /**
53
- * Typed payload accepted by `OrmSession.saveGraph`:
54
- * - Only entity scalar keys + relation keys are accepted.
55
- */
56
- export type SaveGraphInputPayload<TEntity> = ColumnInput<TEntity> & RelationInput<TEntity>;
36
+
37
+ type ColumnInput<TEntity> = {
38
+ [K in ColumnKeys<TEntity>]?: SaveGraphInputScalar<TEntity[K]>;
39
+ };
40
+
41
+ type RelationInputValue<T> =
42
+ T extends HasManyCollection<infer C> ? Array<SaveGraphInputPayload<C> | AnyId> :
43
+ T extends HasOneReference<infer C> ? SaveGraphInputPayload<C> | AnyId | null :
44
+ T extends BelongsToReference<infer P> ? SaveGraphInputPayload<P> | AnyId | null :
45
+ T extends ManyToManyCollection<infer Tgt> ? Array<SaveGraphInputPayload<Tgt> | AnyId> :
46
+ never;
47
+
48
+ type RelationInput<TEntity> = {
49
+ [K in RelationKeys<TEntity>]?: RelationInputValue<NonNullable<TEntity[K]>>;
50
+ };
51
+
52
+ /**
53
+ * Typed payload accepted by `OrmSession.saveGraph`:
54
+ * - Only entity scalar keys + relation keys are accepted.
55
+ */
56
+ export type SaveGraphInputPayload<TEntity> = ColumnInput<TEntity> & RelationInput<TEntity>;
57
+
58
+ /**
59
+ * Typed payload accepted by `OrmSession.patchGraph`:
60
+ * - All keys are optional (partial update semantics).
61
+ * - Only entity scalar keys + relation keys are accepted.
62
+ */
63
+ export type PatchGraphInputPayload<TEntity> = Partial<ColumnInput<TEntity>> & Partial<RelationInput<TEntity>>;