orange-orm 4.7.10-beta.2 → 4.7.10
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 +2 -4
- package/docs/changelog.md +2 -0
- package/package.json +1 -1
- package/src/map2.d.ts +84 -44
package/README.md
CHANGED
|
@@ -94,8 +94,7 @@ const map = orange.map(x => ({
|
|
|
94
94
|
})).map(x => ({
|
|
95
95
|
orderLine: x.orderLine.map(({ hasMany }) => ({
|
|
96
96
|
packages: hasMany(x.package).by('lineId')
|
|
97
|
-
}))
|
|
98
|
-
})).map(x => ({
|
|
97
|
+
})),
|
|
99
98
|
order: x.order.map(v => ({
|
|
100
99
|
customer: v.references(x.customer).by('customerId'),
|
|
101
100
|
lines: v.hasMany(x.orderLine).by('orderId'),
|
|
@@ -200,8 +199,7 @@ const map = orange.map(x => ({
|
|
|
200
199
|
})).map(x => ({
|
|
201
200
|
orderLine: x.orderLine.map(({ hasMany }) => ({
|
|
202
201
|
packages: hasMany(x.package).by('lineId')
|
|
203
|
-
}))
|
|
204
|
-
})).map(x => ({
|
|
202
|
+
})),
|
|
205
203
|
order: x.order.map(({ hasOne, hasMany, references }) => ({
|
|
206
204
|
customer: references(x.customer).by('customerId'),
|
|
207
205
|
deliveryAddress: hasOne(x.deliveryAddress).by('orderId'),
|
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
## Changelog
|
|
2
|
+
__4.7.10__
|
|
3
|
+
Enabled cyclic dependencies in type mapping to support true bidirectional relationships. See [#132](https://github.com/alfateam/orange-orm/issues/132)
|
|
2
4
|
__4.7.9__
|
|
3
5
|
Bugfix: MsSql: Validation failed for parameter '0'. Value must be between -2147483648 and 2147483647, inclusive. See [#131](https://github.com/alfateam/orange-orm/issues/131)
|
|
4
6
|
__4.7.8__
|
package/package.json
CHANGED
package/src/map2.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//map2.d.ts -
|
|
1
|
+
//map2.d.ts - Extended Row Types with Relations Support
|
|
2
2
|
import type { PGliteOptions } from './pglite.d.ts';
|
|
3
3
|
import type { ConnectionConfiguration } from 'tedious';
|
|
4
4
|
import type { D1Database } from '@cloudflare/workers-types';
|
|
@@ -90,6 +90,7 @@ export type ColumnFilterType<Val, ColumnType = any> = {
|
|
|
90
90
|
ne(value: Val | null | undefined): Filter;
|
|
91
91
|
lessThan(value: Val | null | undefined): Filter;
|
|
92
92
|
lt(value: Val | null | undefined): Filter;
|
|
93
|
+
lessThanOrEqual(value: Val | null | undefined): Filter;
|
|
93
94
|
le(value: Val | null | undefined): Filter;
|
|
94
95
|
greaterThan(value: Val | null | undefined): Filter;
|
|
95
96
|
gt(value: Val | null | undefined): Filter;
|
|
@@ -549,6 +550,55 @@ type UpdateChangesRow<M extends Record<string, TableDefinition<M>>, K extends ke
|
|
|
549
550
|
: ColumnTypeToTS<M[K]['columns'][C]> | null | undefined;
|
|
550
551
|
};
|
|
551
552
|
|
|
553
|
+
// NEW: Extended row types with relations support
|
|
554
|
+
|
|
555
|
+
// Type for relation rows - only respects notNull, ignores notNullExceptInsert
|
|
556
|
+
type RelationRow<M extends Record<string, TableDefinition<M>>, K extends keyof M> = {
|
|
557
|
+
// Required columns (notNull = true, ignoring notNullExceptInsert)
|
|
558
|
+
[C in keyof M[K]['columns'] as IsRequired<M[K]['columns'][C]> extends true ? C : never]: ColumnTypeToTS<M[K]['columns'][C]>;
|
|
559
|
+
} & {
|
|
560
|
+
// Optional columns (all others)
|
|
561
|
+
[C in keyof M[K]['columns'] as IsRequired<M[K]['columns'][C]> extends true ? never : C]?: ColumnTypeToTS<M[K]['columns'][C]> | null | undefined;
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
// Helper type to create relation data for insert/update operations
|
|
565
|
+
type RelationData<M extends Record<string, TableDefinition<M>>, K extends keyof M> =
|
|
566
|
+
M[K] extends { relations: infer R }
|
|
567
|
+
? {
|
|
568
|
+
[RName in keyof R]?: R[RName] extends RelationDefinition<M>
|
|
569
|
+
? R[RName]['type'] extends 'hasMany'
|
|
570
|
+
? R[RName]['target'] extends keyof M
|
|
571
|
+
? Array<RelationRowWithRelations<M, R[RName]['target']>>
|
|
572
|
+
: never
|
|
573
|
+
: R[RName]['type'] extends 'hasOne' | 'references'
|
|
574
|
+
? R[RName]['target'] extends keyof M
|
|
575
|
+
? RelationRowWithRelations<M, R[RName]['target']> | null
|
|
576
|
+
: never
|
|
577
|
+
: never
|
|
578
|
+
: never;
|
|
579
|
+
}
|
|
580
|
+
: {};
|
|
581
|
+
|
|
582
|
+
// Relation row type with nested relations support
|
|
583
|
+
type RelationRowWithRelations<M extends Record<string, TableDefinition<M>>, K extends keyof M> =
|
|
584
|
+
RelationRow<M, K> & RelationData<M, K>;
|
|
585
|
+
|
|
586
|
+
// Extended insert row type with optional relations
|
|
587
|
+
type InsertRowWithRelations<M extends Record<string, TableDefinition<M>>, K extends keyof M> =
|
|
588
|
+
InsertRow<M, K> & RelationData<M, K>;
|
|
589
|
+
|
|
590
|
+
// Extended update/replace row type with optional relations
|
|
591
|
+
type UpdateChangesRowWithRelations<M extends Record<string, TableDefinition<M>>, K extends keyof M> =
|
|
592
|
+
UpdateChangesRow<M, K> & RelationData<M, K>;
|
|
593
|
+
|
|
594
|
+
// Extended type for bulk update operations with optional relations
|
|
595
|
+
type UpdateRowWithRelations<M extends Record<string, TableDefinition<M>>, K extends keyof M> =
|
|
596
|
+
Partial<{
|
|
597
|
+
[C in keyof M[K]['columns']]: IsRequired<M[K]['columns'][C]> extends true
|
|
598
|
+
? ColumnTypeToTS<M[K]['columns'][C]>
|
|
599
|
+
: ColumnTypeToTS<M[K]['columns'][C]> | null | undefined;
|
|
600
|
+
}> & RelationData<M, K>;
|
|
601
|
+
|
|
552
602
|
// REFACTORED: Separate Active Record Methods for Individual Rows vs Arrays
|
|
553
603
|
|
|
554
604
|
// Active record methods for individual rows
|
|
@@ -626,22 +676,20 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
626
676
|
// Array methods - return arrays with array-level active record methods, but individual items are plain
|
|
627
677
|
getAll(): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
|
|
628
678
|
getAll<strategy extends FetchStrategy<M, K>>(strategy: strategy): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
629
|
-
getMany(filter
|
|
630
|
-
getMany<strategy extends FetchStrategy<M, K>>(filter
|
|
679
|
+
getMany(filter?: RawFilter | Array<PrimaryKeyObject<M, K>>): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
|
|
680
|
+
getMany<strategy extends FetchStrategy<M, K>>(filter?: RawFilter | Array<PrimaryKeyObject<M, K>>, strategy?: strategy): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
631
681
|
|
|
632
682
|
// Aggregate methods - return plain objects (no active record methods)
|
|
633
683
|
aggregate<strategy extends AggregateStrategy<M, K>>(strategy: strategy): Promise<Array<DeepExpand<AggregateCustomSelectorProperties<M, K, strategy>>>>;
|
|
634
684
|
|
|
635
|
-
|
|
636
|
-
|
|
637
685
|
// Single item methods - return individual objects with individual active record methods
|
|
638
686
|
getOne<strategy extends FetchStrategy<M, K>>(
|
|
639
|
-
filter
|
|
687
|
+
filter?: RawFilter | Array<PrimaryKeyObject<M, K>>
|
|
640
688
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, strategy>>, M, K>>;
|
|
641
689
|
|
|
642
690
|
getOne<strategy extends FetchStrategy<M, K>>(
|
|
643
|
-
filter
|
|
644
|
-
strategy
|
|
691
|
+
filter?: RawFilter | Array<PrimaryKeyObject<M, K>>,
|
|
692
|
+
strategy?: strategy
|
|
645
693
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, strategy>>, M, K>>;
|
|
646
694
|
|
|
647
695
|
getById<strategy extends FetchStrategy<M, K>>(
|
|
@@ -652,22 +700,14 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
652
700
|
...args: [...PrimaryKeyArgs<M, K>]
|
|
653
701
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, {}>>, M, K>>;
|
|
654
702
|
|
|
655
|
-
// Bulk update methods
|
|
703
|
+
// UPDATED: Bulk update methods with relations support
|
|
656
704
|
update(
|
|
657
|
-
row:
|
|
658
|
-
[C in keyof M[K]['columns']]: IsRequired<M[K]['columns'][C]> extends true
|
|
659
|
-
? ColumnTypeToTS<M[K]['columns'][C]>
|
|
660
|
-
: ColumnTypeToTS<M[K]['columns'][C]> | null | undefined;
|
|
661
|
-
}>,
|
|
705
|
+
row: UpdateRowWithRelations<M, K>,
|
|
662
706
|
opts: { where: (row: RootTableRefs<M, K>) => RawFilter }
|
|
663
707
|
): Promise<void>;
|
|
664
708
|
|
|
665
709
|
update<strategy extends FetchStrategy<M, K>>(
|
|
666
|
-
row:
|
|
667
|
-
[C in keyof M[K]['columns']]: IsRequired<M[K]['columns'][C]> extends true
|
|
668
|
-
? ColumnTypeToTS<M[K]['columns'][C]>
|
|
669
|
-
: ColumnTypeToTS<M[K]['columns'][C]> | null | undefined;
|
|
670
|
-
}>,
|
|
710
|
+
row: UpdateRowWithRelations<M, K>,
|
|
671
711
|
opts: { where: (row: RootTableRefs<M, K>) => RawFilter },
|
|
672
712
|
strategy: strategy
|
|
673
713
|
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
@@ -677,87 +717,87 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
677
717
|
delete(filter: RawFilter | Array<PrimaryKeyObject<M, K>>,): Promise<void>;
|
|
678
718
|
deleteCascade(filter: RawFilter | Array<PrimaryKeyObject<M, K>>,): Promise<void>;
|
|
679
719
|
|
|
680
|
-
// Replace methods
|
|
720
|
+
// UPDATED: Replace methods with relations support
|
|
681
721
|
replace(
|
|
682
|
-
row: Array<
|
|
722
|
+
row: Array<UpdateChangesRowWithRelations<M, K>>
|
|
683
723
|
): Promise<void>;
|
|
684
724
|
|
|
685
725
|
replace<strategy extends FetchStrategy<M, K>>(
|
|
686
|
-
row:
|
|
726
|
+
row: UpdateChangesRowWithRelations<M, K>,
|
|
687
727
|
strategy: strategy
|
|
688
728
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, strategy>>, M, K>>;
|
|
689
729
|
|
|
690
730
|
replace<strategy extends FetchStrategy<M, K>>(
|
|
691
|
-
rows: Array<
|
|
731
|
+
rows: Array<UpdateChangesRowWithRelations<M, K>>,
|
|
692
732
|
strategy: strategy
|
|
693
733
|
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
694
734
|
|
|
695
|
-
// UpdateChanges methods
|
|
735
|
+
// UPDATED: UpdateChanges methods with relations support
|
|
696
736
|
updateChanges(
|
|
697
|
-
row:
|
|
698
|
-
originalRow:
|
|
737
|
+
row: UpdateChangesRowWithRelations<M, K>,
|
|
738
|
+
originalRow: UpdateChangesRowWithRelations<M, K>
|
|
699
739
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, {}>>, M, K>>;
|
|
700
740
|
|
|
701
741
|
updateChanges(
|
|
702
|
-
rows: Array<
|
|
703
|
-
originalRows: Array<
|
|
742
|
+
rows: Array<UpdateChangesRowWithRelations<M, K>>,
|
|
743
|
+
originalRows: Array<UpdateChangesRowWithRelations<M, K>>
|
|
704
744
|
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
|
|
705
745
|
|
|
706
746
|
updateChanges<strategy extends FetchStrategy<M, K>>(
|
|
707
|
-
row:
|
|
708
|
-
originalRow:
|
|
747
|
+
row: UpdateChangesRowWithRelations<M, K>,
|
|
748
|
+
originalRow: UpdateChangesRowWithRelations<M, K>,
|
|
709
749
|
strategy: strategy
|
|
710
750
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, strategy>>, M, K>>;
|
|
711
751
|
|
|
712
752
|
updateChanges<strategy extends FetchStrategy<M, K>>(
|
|
713
|
-
rows: Array<
|
|
714
|
-
originalRows: Array<
|
|
753
|
+
rows: Array<UpdateChangesRowWithRelations<M, K>>,
|
|
754
|
+
originalRows: Array<UpdateChangesRowWithRelations<M, K>>,
|
|
715
755
|
strategy: strategy
|
|
716
756
|
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
717
757
|
|
|
718
|
-
// Insert methods - no active record methods for insertAndForget, appropriate methods for others
|
|
758
|
+
// UPDATED: Insert methods with relations support - no active record methods for insertAndForget, appropriate methods for others
|
|
719
759
|
insertAndForget(
|
|
720
|
-
row:
|
|
760
|
+
row: InsertRowWithRelations<M, K>
|
|
721
761
|
): Promise<void>;
|
|
722
762
|
|
|
723
763
|
insertAndForget(
|
|
724
|
-
rows: Array<
|
|
764
|
+
rows: Array<InsertRowWithRelations<M, K>>
|
|
725
765
|
): Promise<void>;
|
|
726
766
|
|
|
727
767
|
insert(
|
|
728
|
-
row:
|
|
768
|
+
row: InsertRowWithRelations<M, K>
|
|
729
769
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, {}>>, M, K>>;
|
|
730
770
|
|
|
731
771
|
insert(
|
|
732
|
-
rows: Array<
|
|
772
|
+
rows: Array<InsertRowWithRelations<M, K>>
|
|
733
773
|
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
|
|
734
774
|
|
|
735
775
|
insert<strategy extends FetchStrategy<M, K>>(
|
|
736
|
-
row:
|
|
776
|
+
row: InsertRowWithRelations<M, K>,
|
|
737
777
|
strategy: strategy
|
|
738
778
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, strategy>>, M, K>>;
|
|
739
779
|
|
|
740
780
|
insert<strategy extends FetchStrategy<M, K>>(
|
|
741
|
-
rows: Array<
|
|
781
|
+
rows: Array<InsertRowWithRelations<M, K>>,
|
|
742
782
|
strategy: strategy
|
|
743
783
|
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
744
784
|
|
|
745
|
-
// Proxify methods
|
|
785
|
+
// UPDATED: Proxify methods with relations support
|
|
746
786
|
proxify(
|
|
747
|
-
row:
|
|
787
|
+
row: UpdateChangesRowWithRelations<M, K>
|
|
748
788
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, {}>>, M, K>>;
|
|
749
789
|
|
|
750
790
|
proxify(
|
|
751
|
-
rows: Array<
|
|
791
|
+
rows: Array<UpdateChangesRowWithRelations<M, K>>
|
|
752
792
|
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
|
|
753
793
|
|
|
754
794
|
proxify<strategy extends FetchStrategy<M, K>>(
|
|
755
|
-
row:
|
|
795
|
+
row: UpdateChangesRowWithRelations<M, K>,
|
|
756
796
|
strategy: strategy
|
|
757
797
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, strategy>>, M, K>>;
|
|
758
798
|
|
|
759
799
|
proxify<strategy extends FetchStrategy<M, K>>(
|
|
760
|
-
rows: Array<
|
|
800
|
+
rows: Array<UpdateChangesRowWithRelations<M, K>>,
|
|
761
801
|
strategy: strategy
|
|
762
802
|
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
763
803
|
|