orange-orm 4.7.10-beta.0 → 4.7.10-beta.1
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/package.json +1 -1
- package/src/map2.d.ts +52 -43
package/package.json
CHANGED
package/src/map2.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//map2.d.ts
|
|
1
|
+
//map2.d.ts - Refactored Active Record Methods
|
|
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';
|
|
@@ -98,8 +98,6 @@ export type ColumnFilterType<Val, ColumnType = any> = {
|
|
|
98
98
|
in(values: (Val | null | undefined)[]): Filter;
|
|
99
99
|
between(from: Val | null | undefined, to: Val | null | undefined): Filter;
|
|
100
100
|
notIn(values: (Val | null | undefined)[]): Filter;
|
|
101
|
-
// isNull(): Filter;
|
|
102
|
-
// isNotNull(): Filter;
|
|
103
101
|
} & (ColumnType extends 'string' ? StringOnlyMethods : {});
|
|
104
102
|
|
|
105
103
|
export type JsonArray = Array<JsonValue>;
|
|
@@ -216,7 +214,6 @@ type ColumnSelectionRefs<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
216
214
|
[C in keyof M[K]['columns'] as IsRequired<M[K]['columns'][C]> extends true ? never : C]?: ColumnTypeToTS<M[K]['columns'][C]> | null | undefined;
|
|
217
215
|
};
|
|
218
216
|
|
|
219
|
-
|
|
220
217
|
// Relation selection refs without filter methods - supports deep nesting
|
|
221
218
|
// In selectors, all relation types just provide access to the target table structure
|
|
222
219
|
// But WITHOUT aggregate functions (only available at root level)
|
|
@@ -378,9 +375,6 @@ type RequiredColumnKeys<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
378
375
|
type OptionalColumnKeys<M extends Record<string, TableDefinition<M>>, K extends keyof M, FS extends Record<string, any>> =
|
|
379
376
|
Exclude<SelectedColumns<M, K, FS>, RequiredColumnKeys<M, K, FS>>;
|
|
380
377
|
|
|
381
|
-
// Helper type to check if a value is actually a column reference from the row object
|
|
382
|
-
// This is a bit of a hack - we check if the type has the structure of a ColumnFilterType
|
|
383
|
-
// but without the filter methods (which is what ColumnSelectionRefs provides)
|
|
384
378
|
type IsActualColumnReference<T, M extends Record<string, TableDefinition<M>>, K extends keyof M> =
|
|
385
379
|
T extends ColumnTypeToTS<infer CT>
|
|
386
380
|
? CT extends ORMColumnDefinition | ORMJsonColumnDefinition
|
|
@@ -388,7 +382,6 @@ type IsActualColumnReference<T, M extends Record<string, TableDefinition<M>>, K
|
|
|
388
382
|
: false
|
|
389
383
|
: false;
|
|
390
384
|
|
|
391
|
-
// Alternative approach: Check if the type matches what we'd get from accessing ColumnSelectionRefs
|
|
392
385
|
type IsFromColumnSelectionRefs<M extends Record<string, TableDefinition<M>>, K extends keyof M, T = any> =
|
|
393
386
|
T extends ColumnSelectionRefs<M, K>[keyof ColumnSelectionRefs<M, K>] ? true :
|
|
394
387
|
T extends (M[K] extends { relations: infer R }
|
|
@@ -401,24 +394,19 @@ type IsFromColumnSelectionRefs<M extends Record<string, TableDefinition<M>>, K e
|
|
|
401
394
|
T extends number ? true : // Allow aggregate function return type (number)
|
|
402
395
|
false;
|
|
403
396
|
|
|
404
|
-
// Helper type to infer the TypeScript type from selector return values
|
|
405
|
-
// Only allows types that come from actual column selections or aggregate functions
|
|
406
397
|
type InferSelectorReturnType<T, M extends Record<string, TableDefinition<M>>, K extends keyof M> =
|
|
407
398
|
IsFromColumnSelectionRefs<M, K, T> extends true ? T : never;
|
|
408
399
|
|
|
409
|
-
// ADD helper to check if return type is an aggregate function:
|
|
410
400
|
type IsAggregateFunction<T> = T extends BaseAggregateFunction ? true : false;
|
|
411
401
|
|
|
412
402
|
type IsRequiredAggregate<T> = T extends BaseAggregateFunction & { __functionType: infer FType }
|
|
413
403
|
? FType extends 'count' | 'sum' | 'avg' ? true : false
|
|
414
404
|
: false;
|
|
415
405
|
|
|
416
|
-
// Helper to check if it's a min/max function that should preserve column type
|
|
417
406
|
type IsMinMaxAggregate<T> = T extends AggregateMinMaxFunction<any> & { __functionType: infer FType }
|
|
418
407
|
? FType extends 'max' | 'min' ? true : false
|
|
419
408
|
: false;
|
|
420
409
|
|
|
421
|
-
// Helper to extract the column type from min/max aggregate
|
|
422
410
|
type ExtractMinMaxColumnType<T> = T extends AggregateMinMaxFunction<infer ColType>
|
|
423
411
|
? ColumnDefinitionToTS<ColType>
|
|
424
412
|
: never;
|
|
@@ -556,7 +544,9 @@ type UpdateChangesRow<M extends Record<string, TableDefinition<M>>, K extends ke
|
|
|
556
544
|
: ColumnTypeToTS<M[K]['columns'][C]> | null | undefined;
|
|
557
545
|
};
|
|
558
546
|
|
|
559
|
-
// Active
|
|
547
|
+
// REFACTORED: Separate Active Record Methods for Individual Rows vs Arrays
|
|
548
|
+
|
|
549
|
+
// Active record methods for individual rows
|
|
560
550
|
type ActiveRecordMethods<M extends Record<string, TableDefinition<M>>, K extends keyof M> = {
|
|
561
551
|
saveChanges(): Promise<void>;
|
|
562
552
|
saveChanges(concurrency: ConcurrencyConfig<M>[K]): Promise<void>;
|
|
@@ -568,18 +558,37 @@ type ActiveRecordMethods<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
568
558
|
delete<strategy extends FetchStrategy<M, K>>(strategy: strategy): Promise<void>;
|
|
569
559
|
};
|
|
570
560
|
|
|
571
|
-
//
|
|
561
|
+
// Active record methods for arrays of rows
|
|
562
|
+
type ArrayActiveRecordMethods<M extends Record<string, TableDefinition<M>>, K extends keyof M> = {
|
|
563
|
+
saveChanges(): Promise<void>;
|
|
564
|
+
saveChanges(concurrency: ConcurrencyConfig<M>[K]): Promise<void>;
|
|
565
|
+
acceptChanges(): void;
|
|
566
|
+
clearChanges(): void;
|
|
567
|
+
refresh(): Promise<void>;
|
|
568
|
+
refresh<strategy extends FetchStrategy<M, K>>(strategy: strategy): Promise<Array<DeepExpand<Selection<M, K, strategy>>>>;
|
|
569
|
+
delete(): Promise<void>;
|
|
570
|
+
delete<strategy extends FetchStrategy<M, K>>(strategy: strategy): Promise<void>;
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
// Helper type to add individual active record methods to selection results
|
|
572
574
|
type WithActiveRecord<T, M extends Record<string, TableDefinition<M>>, K extends keyof M> =
|
|
573
575
|
T & ActiveRecordMethods<M, K>;
|
|
574
576
|
|
|
577
|
+
// Helper type to add array active record methods to arrays without adding them to individual items
|
|
578
|
+
type WithArrayActiveRecord<T extends Array<any>, M extends Record<string, TableDefinition<M>>, K extends keyof M> =
|
|
579
|
+
T & ArrayActiveRecordMethods<M, K>;
|
|
580
|
+
|
|
575
581
|
export type TableClient<M extends Record<string, TableDefinition<M>>, K extends keyof M> = {
|
|
576
|
-
|
|
577
|
-
getAll
|
|
578
|
-
|
|
579
|
-
getMany
|
|
582
|
+
// Array methods - return arrays with array-level active record methods, but individual items are plain
|
|
583
|
+
getAll(): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
|
|
584
|
+
getAll<strategy extends FetchStrategy<M, K>>(strategy: strategy): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
585
|
+
getMany(filter: RawFilter | Array<PrimaryKeyObject<M, K>>): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
|
|
586
|
+
getMany<strategy extends FetchStrategy<M, K>>(filter: RawFilter | Array<PrimaryKeyObject<M, K>>, strategy: strategy): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
580
587
|
|
|
588
|
+
// Aggregate methods - return plain objects (no active record methods)
|
|
581
589
|
aggregate<strategy extends AggregateStrategy<M, K>>(strategy: strategy): Promise<Array<DeepExpand<CustomSelectorProperties<M, K, strategy>>>>;
|
|
582
590
|
|
|
591
|
+
// Single item methods - return individual objects with individual active record methods
|
|
583
592
|
getOne<strategy extends FetchStrategy<M, K>>(
|
|
584
593
|
filter: RawFilter | Array<PrimaryKeyObject<M, K>>
|
|
585
594
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, strategy>>, M, K>>;
|
|
@@ -597,6 +606,7 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
597
606
|
...args: [...PrimaryKeyArgs<M, K>]
|
|
598
607
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, {}>>, M, K>>;
|
|
599
608
|
|
|
609
|
+
// Bulk update methods
|
|
600
610
|
update(
|
|
601
611
|
row: Partial<{
|
|
602
612
|
[C in keyof M[K]['columns']]: IsRequired<M[K]['columns'][C]> extends true
|
|
@@ -606,10 +616,6 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
606
616
|
opts: { where: (row: RootTableRefs<M, K>) => RawFilter }
|
|
607
617
|
): Promise<void>;
|
|
608
618
|
|
|
609
|
-
count(filter: RawFilter | Array<PrimaryKeyObject<M, K>>,): Promise<number>;
|
|
610
|
-
delete(filter: RawFilter | Array<PrimaryKeyObject<M, K>>,): Promise<void>;
|
|
611
|
-
deleteCascade(filter: RawFilter | Array<PrimaryKeyObject<M, K>>,): Promise<void>;
|
|
612
|
-
|
|
613
619
|
update<strategy extends FetchStrategy<M, K>>(
|
|
614
620
|
row: Partial<{
|
|
615
621
|
[C in keyof M[K]['columns']]: IsRequired<M[K]['columns'][C]> extends true
|
|
@@ -618,8 +624,14 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
618
624
|
}>,
|
|
619
625
|
opts: { where: (row: RootTableRefs<M, K>) => RawFilter },
|
|
620
626
|
strategy: strategy
|
|
621
|
-
): Promise<Array<
|
|
627
|
+
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
628
|
+
|
|
629
|
+
// Count and delete methods (no active record methods needed)
|
|
630
|
+
count(filter: RawFilter | Array<PrimaryKeyObject<M, K>>,): Promise<number>;
|
|
631
|
+
delete(filter: RawFilter | Array<PrimaryKeyObject<M, K>>,): Promise<void>;
|
|
632
|
+
deleteCascade(filter: RawFilter | Array<PrimaryKeyObject<M, K>>,): Promise<void>;
|
|
622
633
|
|
|
634
|
+
// Replace methods - can return single or array with appropriate active record methods
|
|
623
635
|
replace(
|
|
624
636
|
row: Array<UpdateChangesRow<M, K>>
|
|
625
637
|
): Promise<void>;
|
|
@@ -632,8 +644,9 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
632
644
|
replace<strategy extends FetchStrategy<M, K>>(
|
|
633
645
|
rows: Array<UpdateChangesRow<M, K>>,
|
|
634
646
|
strategy: strategy
|
|
635
|
-
): Promise<Array<
|
|
647
|
+
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
636
648
|
|
|
649
|
+
// UpdateChanges methods - can return single or array with appropriate active record methods
|
|
637
650
|
updateChanges(
|
|
638
651
|
row: UpdateChangesRow<M, K>,
|
|
639
652
|
originalRow: UpdateChangesRow<M, K>
|
|
@@ -642,7 +655,7 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
642
655
|
updateChanges(
|
|
643
656
|
rows: Array<UpdateChangesRow<M, K>>,
|
|
644
657
|
originalRows: Array<UpdateChangesRow<M, K>>
|
|
645
|
-
): Promise<Array<
|
|
658
|
+
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
|
|
646
659
|
|
|
647
660
|
updateChanges<strategy extends FetchStrategy<M, K>>(
|
|
648
661
|
row: UpdateChangesRow<M, K>,
|
|
@@ -654,8 +667,9 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
654
667
|
rows: Array<UpdateChangesRow<M, K>>,
|
|
655
668
|
originalRows: Array<UpdateChangesRow<M, K>>,
|
|
656
669
|
strategy: strategy
|
|
657
|
-
): Promise<Array<
|
|
670
|
+
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
658
671
|
|
|
672
|
+
// Insert methods - no active record methods for insertAndForget, appropriate methods for others
|
|
659
673
|
insertAndForget(
|
|
660
674
|
row: InsertRow<M, K>
|
|
661
675
|
): Promise<void>;
|
|
@@ -670,7 +684,7 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
670
684
|
|
|
671
685
|
insert(
|
|
672
686
|
rows: Array<InsertRow<M, K>>
|
|
673
|
-
): Promise<Array<
|
|
687
|
+
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
|
|
674
688
|
|
|
675
689
|
insert<strategy extends FetchStrategy<M, K>>(
|
|
676
690
|
row: InsertRow<M, K>,
|
|
@@ -680,15 +694,16 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
680
694
|
insert<strategy extends FetchStrategy<M, K>>(
|
|
681
695
|
rows: Array<InsertRow<M, K>>,
|
|
682
696
|
strategy: strategy
|
|
683
|
-
): Promise<Array<
|
|
697
|
+
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
684
698
|
|
|
699
|
+
// Proxify methods - can return single or array with appropriate active record methods
|
|
685
700
|
proxify(
|
|
686
701
|
row: UpdateChangesRow<M, K>
|
|
687
702
|
): Promise<WithActiveRecord<DeepExpand<Selection<M, K, {}>>, M, K>>;
|
|
688
703
|
|
|
689
704
|
proxify(
|
|
690
705
|
rows: Array<UpdateChangesRow<M, K>>
|
|
691
|
-
): Promise<Array<
|
|
706
|
+
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
|
|
692
707
|
|
|
693
708
|
proxify<strategy extends FetchStrategy<M, K>>(
|
|
694
709
|
row: UpdateChangesRow<M, K>,
|
|
@@ -698,14 +713,16 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
698
713
|
proxify<strategy extends FetchStrategy<M, K>>(
|
|
699
714
|
rows: Array<UpdateChangesRow<M, K>>,
|
|
700
715
|
strategy: strategy
|
|
701
|
-
): Promise<Array<
|
|
716
|
+
): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
|
|
702
717
|
|
|
703
|
-
|
|
718
|
+
// Patch method
|
|
719
|
+
patch<strategy extends FetchStrategy<M, K>>(
|
|
704
720
|
patches: JsonPatch,
|
|
705
721
|
strategy: strategy,
|
|
706
722
|
concurrency?: ConcurrencyConfig<M>[K]
|
|
707
723
|
): Promise<void>;
|
|
708
724
|
|
|
725
|
+
// TypeScript type helpers
|
|
709
726
|
tsType(): DeepExpand<Selection<M, K, {}>>;
|
|
710
727
|
|
|
711
728
|
tsType<strategy extends FetchStrategy<M, K>>(
|
|
@@ -713,6 +730,8 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
|
|
|
713
730
|
): DeepExpand<Selection<M, K, strategy>>;
|
|
714
731
|
};
|
|
715
732
|
|
|
733
|
+
// Rest of the type definitions remain the same...
|
|
734
|
+
|
|
716
735
|
export type ConcurrencyStrategy = 'optimistic' | 'overwrite' | 'skipOnConflict';
|
|
717
736
|
|
|
718
737
|
export interface ColumnConcurrency {
|
|
@@ -740,15 +759,6 @@ export type DbOptions<M extends Record<string, TableDefinition<M>>> =
|
|
|
740
759
|
db?: Pool | ((connectors: Connectors) => Pool | Promise<Pool>);
|
|
741
760
|
};
|
|
742
761
|
|
|
743
|
-
|
|
744
|
-
// type NegotiateDbInstance<T, C> = C extends WithDb
|
|
745
|
-
// ? DbConnectable<SchemaFromMappedDb<MappedDb<T>>>
|
|
746
|
-
// : MappedDb<T>;
|
|
747
|
-
|
|
748
|
-
// type WithDb = {
|
|
749
|
-
// db: Pool | ((connectors: Connectors) => Pool | Promise<Pool>)
|
|
750
|
-
// };
|
|
751
|
-
|
|
752
762
|
export type DbConcurrency<M extends Record<string, TableDefinition<M>>> =
|
|
753
763
|
ConcurrencyConfig<M>
|
|
754
764
|
& ColumnConcurrency;
|
|
@@ -817,13 +827,12 @@ export type DBClient<M extends Record<string, TableDefinition<M>>> = {
|
|
|
817
827
|
transaction(
|
|
818
828
|
fn: (db: DBClient<M>) => Promise<unknown>
|
|
819
829
|
): Promise<void>;
|
|
820
|
-
// saveChanges(arraysOrRow: { saveChanges(): Promise<void> }): Promise<void>;
|
|
821
830
|
express(): import('express').RequestHandler;
|
|
822
831
|
express(config: ExpressConfig<M>): import('express').RequestHandler;
|
|
823
832
|
readonly metaData: DbConcurrency<M>;
|
|
824
833
|
|
|
825
834
|
interceptors: WithInterceptors;
|
|
826
|
-
} & WithInterceptors
|
|
835
|
+
} & WithInterceptors & DbConnectable<M>;
|
|
827
836
|
|
|
828
837
|
type ExpressConfig<M extends Record<string, TableDefinition<M>>> = {
|
|
829
838
|
[TableName in keyof M]?: ExpressTableConfig<M>;
|