alepha 0.10.6 → 0.10.7
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/api/files.d.ts +395 -171
- package/api/jobs.d.ts +208 -189
- package/api/notifications.cjs +8 -0
- package/api/notifications.d.ts +377 -0
- package/api/notifications.js +1 -0
- package/api/users.d.ts +1070 -254
- package/api/verifications.cjs +8 -0
- package/api/verifications.d.ts +1 -0
- package/api/verifications.js +1 -0
- package/batch.d.ts +8 -8
- package/bucket.d.ts +0 -194
- package/cache.d.ts +12 -12
- package/command.d.ts +11 -11
- package/core.d.ts +63 -42
- package/email.d.ts +41 -225
- package/lock.d.ts +8 -8
- package/logger.d.ts +0 -1
- package/package.json +69 -48
- package/postgres.d.ts +402 -378
- package/queue.d.ts +14 -14
- package/react/form.d.ts +17 -17
- package/react/i18n.d.ts +10 -7
- package/react.d.ts +48 -48
- package/retry.d.ts +8 -8
- package/scheduler.d.ts +11 -1
- package/security.d.ts +4 -4
- package/server/cache.d.ts +86 -11
- package/server/cookies.d.ts +10 -10
- package/server/links.d.ts +3 -3
- package/server/swagger.d.ts +2 -1
- package/server.d.ts +69 -56
- package/topic.d.ts +17 -17
- package/ui.cjs +8 -0
- package/ui.d.ts +300 -0
- package/ui.js +1 -0
- package/vite.d.ts +5 -3
package/postgres.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { Alepha, AlephaError, Descriptor, KIND, Service, Static, TArray, TBigInt
|
|
|
3
3
|
import * as drizzle_orm6 from "drizzle-orm";
|
|
4
4
|
import { BuildColumns, BuildExtraConfigColumns, SQL, SQLWrapper, TableConfig, sql } from "drizzle-orm";
|
|
5
5
|
import * as pg$1 from "drizzle-orm/pg-core";
|
|
6
|
-
import { AnyPgColumn, AnyPgTable, LockConfig, LockStrength, PgColumn, PgColumnBuilderBase, PgDatabase, PgInsertValue, PgSequenceOptions, PgTableExtraConfigValue, PgTableWithColumns, PgTransaction, PgTransactionConfig,
|
|
6
|
+
import { AnyPgColumn, AnyPgTable, LockConfig, LockStrength, PgColumn, PgColumnBuilderBase, PgDatabase, PgInsertValue, PgSelectBase, PgSequenceOptions, PgTableExtraConfigValue, PgTableWithColumns, PgTransaction, PgTransactionConfig, TableConfig as TableConfig$1, UpdateDeleteAction } from "drizzle-orm/pg-core";
|
|
7
7
|
import { DateTime, DateTimeProvider } from "alepha/datetime";
|
|
8
8
|
import * as _alepha_logger1 from "alepha/logger";
|
|
9
9
|
import * as _alepha_lock0 from "alepha/lock";
|
|
10
10
|
import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
11
11
|
import postgres from "postgres";
|
|
12
12
|
import * as _alepha_retry0 from "alepha/retry";
|
|
13
|
-
import * as
|
|
13
|
+
import * as typebox0 from "typebox";
|
|
14
14
|
import { PgTransactionConfig as PgTransactionConfig$1 } from "drizzle-orm/pg-core/session";
|
|
15
15
|
import * as DrizzleKit from "drizzle-kit/api";
|
|
16
16
|
import { MigrationConfig } from "drizzle-orm/migrator";
|
|
@@ -84,11 +84,11 @@ interface PgRefOptions {
|
|
|
84
84
|
* Before: { name: string; age: number(default=0); }
|
|
85
85
|
* After: { name: string; age?: number; }
|
|
86
86
|
*/
|
|
87
|
-
type TObjectInsert<T extends TObject> = TObject<{ [K in keyof T["properties"]]: T["properties"][K] extends {
|
|
87
|
+
type TObjectInsert<T$1 extends TObject> = TObject<{ [K in keyof T$1["properties"]]: T$1["properties"][K] extends {
|
|
88
88
|
[PG_DEFAULT]: any;
|
|
89
89
|
} | {
|
|
90
90
|
"~optional": true;
|
|
91
|
-
} ? TOptional<T["properties"][K]> : T["properties"][K] }>;
|
|
91
|
+
} ? TOptional<T$1["properties"][K]> : T$1["properties"][K] }>;
|
|
92
92
|
declare const insertSchema: <T extends TObject>(obj: T) => TObjectInsert<T>;
|
|
93
93
|
//#endregion
|
|
94
94
|
//#region src/schemas/updateSchema.d.ts
|
|
@@ -101,7 +101,7 @@ declare const insertSchema: <T extends TObject>(obj: T) => TObjectInsert<T>;
|
|
|
101
101
|
* Before: { name?: string; age: number; }
|
|
102
102
|
* After: { name?: string | null; age: number; }
|
|
103
103
|
*/
|
|
104
|
-
type TObjectUpdate<T extends TObject> = TObject<{ [K in keyof T["properties"]]: T["properties"][K] extends TOptional<infer U> ? TOptional<TUnion<[U, TNull]>> : T["properties"][K] }>;
|
|
104
|
+
type TObjectUpdate<T$1 extends TObject> = TObject<{ [K in keyof T$1["properties"]]: T$1["properties"][K] extends TOptional<infer U> ? TOptional<TUnion<[U, TNull]>> : T$1["properties"][K] }>;
|
|
105
105
|
declare const updateSchema: <T extends TObject>(schema: T) => TObjectUpdate<T>;
|
|
106
106
|
//#endregion
|
|
107
107
|
//#region src/helpers/schemaToPgColumns.d.ts
|
|
@@ -263,15 +263,16 @@ declare const camelToSnakeCase: (str: string) => string;
|
|
|
263
263
|
/**
|
|
264
264
|
* Convert a schema to columns.
|
|
265
265
|
*/
|
|
266
|
-
type FromSchema<T extends TObject> = { [key in keyof T["properties"]]: PgColumnBuilderBase };
|
|
266
|
+
type FromSchema<T$1 extends TObject> = { [key in keyof T$1["properties"]]: PgColumnBuilderBase };
|
|
267
267
|
/**
|
|
268
268
|
* A table with columns and schema.
|
|
269
269
|
*/
|
|
270
|
-
type PgTableWithColumnsAndSchema<T extends TableConfig, R extends TObject> = PgTableWithColumns<T> & {
|
|
271
|
-
get $table(): PgTableWithColumns<T>;
|
|
272
|
-
get $schema(): R;
|
|
273
|
-
get $insertSchema(): TObjectInsert<R>;
|
|
274
|
-
get $updateSchema(): TObjectUpdate<R>;
|
|
270
|
+
type PgTableWithColumnsAndSchema<T$1 extends TableConfig, R$1 extends TObject> = PgTableWithColumns<T$1> & {
|
|
271
|
+
get $table(): PgTableWithColumns<T$1>;
|
|
272
|
+
get $schema(): R$1;
|
|
273
|
+
get $insertSchema(): TObjectInsert<R$1>;
|
|
274
|
+
get $updateSchema(): TObjectUpdate<R$1>;
|
|
275
|
+
alias: (alias: string) => PgTableWithColumnsAndSchema<T$1, R$1>;
|
|
275
276
|
};
|
|
276
277
|
//#endregion
|
|
277
278
|
//#region src/descriptors/$entity.d.ts
|
|
@@ -481,107 +482,22 @@ type PgTableWithColumnsAndSchema<T extends TableConfig, R extends TObject> = PgT
|
|
|
481
482
|
* ]
|
|
482
483
|
* });
|
|
483
484
|
* ```
|
|
484
|
-
*
|
|
485
|
-
* @stability 2
|
|
486
485
|
*/
|
|
487
486
|
declare const $entity: {
|
|
488
487
|
<TTableName extends string, TSchema extends TObject, TColumnsMap extends FromSchema<TSchema>>(options: EntityDescriptorOptions<TTableName, TSchema>): PgTableWithColumnsAndSchema<PgTableConfig<TTableName, TSchema, TColumnsMap>, TSchema>;
|
|
489
488
|
[KIND]: string;
|
|
490
489
|
};
|
|
491
|
-
interface EntityDescriptorOptions<TTableName extends string, T extends TObject, Keys = keyof Static<T>> {
|
|
490
|
+
interface EntityDescriptorOptions<TTableName$1 extends string, T$1 extends TObject, Keys = keyof Static<T$1>> {
|
|
492
491
|
/**
|
|
493
492
|
* The database table name that will be created for this entity.
|
|
494
|
-
*
|
|
495
|
-
* This name:
|
|
496
|
-
* - Must be unique within your database schema
|
|
497
|
-
* - Should follow your database naming conventions (typically snake_case)
|
|
498
|
-
* - Will be used in generated SQL queries and migrations
|
|
499
|
-
* - Should be descriptive of the entity's purpose
|
|
500
|
-
*
|
|
501
|
-
* **Naming Guidelines**:
|
|
502
|
-
* - Use plural nouns for table names ("users", "products", "orders")
|
|
503
|
-
* - Use snake_case for multi-word names ("user_profiles", "order_items")
|
|
504
|
-
* - Keep names concise but descriptive
|
|
505
|
-
* - Avoid SQL reserved words
|
|
506
|
-
*
|
|
507
|
-
* @example "users"
|
|
508
|
-
* @example "product_categories"
|
|
509
|
-
* @example "user_roles"
|
|
510
|
-
* @example "audit_logs"
|
|
511
493
|
*/
|
|
512
|
-
name: TTableName;
|
|
494
|
+
name: TTableName$1;
|
|
513
495
|
/**
|
|
514
496
|
* TypeBox schema defining the table structure and column types.
|
|
515
|
-
*
|
|
516
|
-
* This schema:
|
|
517
|
-
* - Defines all table columns with their types and constraints
|
|
518
|
-
* - Provides full TypeScript type inference for the entity
|
|
519
|
-
* - Supports validation rules and default values
|
|
520
|
-
* - Enables automatic insert/update schema generation
|
|
521
|
-
* - Must include exactly one primary key field marked with `pg.primaryKey()`
|
|
522
|
-
*
|
|
523
|
-
* **Supported PostgreSQL Types**:
|
|
524
|
-
* - `pg.primaryKey(t.uuid())` - UUID primary key
|
|
525
|
-
* - `t.text()` - VARCHAR column
|
|
526
|
-
* - `t.integer()`, `t.number()` - Numeric columns
|
|
527
|
-
* - `t.boolean()` - Boolean column
|
|
528
|
-
* - `t.array(t.text())` - PostgreSQL array column
|
|
529
|
-
* - `t.record(t.text(), t.any())` - JSONB column
|
|
530
|
-
* - `pg.createdAt()`, `pg.updatedAt()`, `pg.deletedAt()` - Audit timestamps
|
|
531
|
-
* - `pg.version()` - Optimistic locking version field
|
|
532
|
-
*
|
|
533
|
-
* **Schema Best Practices**:
|
|
534
|
-
* - Always include a primary key
|
|
535
|
-
* - Use appropriate TypeBox constraints (minLength, format, etc.)
|
|
536
|
-
* - Add audit fields for trackability
|
|
537
|
-
* - Use optional fields for nullable columns
|
|
538
|
-
* - Include foreign key columns for relationships
|
|
539
|
-
*
|
|
540
|
-
* @example
|
|
541
|
-
* ```ts
|
|
542
|
-
* t.object({
|
|
543
|
-
* id: pg.primaryKey(t.uuid()),
|
|
544
|
-
* email: t.text({ format: "email" }),
|
|
545
|
-
* firstName: t.text({ minLength: 1, maxLength: 100 }),
|
|
546
|
-
* lastName: t.text({ minLength: 1, maxLength: 100 }),
|
|
547
|
-
* age: t.optional(t.integer({ minimum: 0, maximum: 150 })),
|
|
548
|
-
* isActive: t.boolean({ default: true }),
|
|
549
|
-
* preferences: t.optional(t.record(t.text(), t.any())),
|
|
550
|
-
* tags: t.optional(t.array(t.text())),
|
|
551
|
-
* createdAt: pg.createdAt(),
|
|
552
|
-
* updatedAt: pg.updatedAt(),
|
|
553
|
-
* version: pg.version()
|
|
554
|
-
* })
|
|
555
|
-
* ```
|
|
556
497
|
*/
|
|
557
|
-
schema: T;
|
|
498
|
+
schema: T$1;
|
|
558
499
|
/**
|
|
559
500
|
* Database indexes to create for query optimization.
|
|
560
|
-
*
|
|
561
|
-
* Indexes improve query performance but consume disk space and slow down writes.
|
|
562
|
-
* Choose indexes based on your actual query patterns and performance requirements.
|
|
563
|
-
*
|
|
564
|
-
* **Index Types**:
|
|
565
|
-
* - **Simple string**: Creates a single-column index
|
|
566
|
-
* - **Single column object**: Creates index on one column with options
|
|
567
|
-
* - **Multi-column object**: Creates composite index on multiple columns
|
|
568
|
-
*
|
|
569
|
-
* **Index Guidelines**:
|
|
570
|
-
* - Index frequently queried columns (WHERE, ORDER BY, JOIN conditions)
|
|
571
|
-
* - Create unique indexes for business constraints
|
|
572
|
-
* - Use composite indexes for multi-column queries
|
|
573
|
-
* - Index foreign key columns for join performance
|
|
574
|
-
* - Monitor index usage and remove unused indexes
|
|
575
|
-
*
|
|
576
|
-
* **Performance Considerations**:
|
|
577
|
-
* - Each index increases storage requirements
|
|
578
|
-
* - Indexes slow down INSERT/UPDATE/DELETE operations
|
|
579
|
-
* - PostgreSQL can use multiple indexes in complex queries
|
|
580
|
-
* - Partial indexes can be more efficient for filtered queries
|
|
581
|
-
*
|
|
582
|
-
* @example ["email", "createdAt", { column: "username", unique: true }]
|
|
583
|
-
* @example [{ columns: ["userId", "status"], name: "idx_user_status" }]
|
|
584
|
-
* @example ["categoryId", { columns: ["price", "inStock"] }]
|
|
585
501
|
*/
|
|
586
502
|
indexes?: (Keys | {
|
|
587
503
|
/**
|
|
@@ -612,35 +528,6 @@ interface EntityDescriptorOptions<TTableName extends string, T extends TObject,
|
|
|
612
528
|
})[];
|
|
613
529
|
/**
|
|
614
530
|
* Foreign key constraints to maintain referential integrity.
|
|
615
|
-
*
|
|
616
|
-
* Foreign keys ensure that values in specified columns must exist in the referenced table.
|
|
617
|
-
* They prevent orphaned records and maintain database consistency.
|
|
618
|
-
*
|
|
619
|
-
* **Foreign Key Benefits**:
|
|
620
|
-
* - Prevents invalid references to non-existent records
|
|
621
|
-
* - Maintains data integrity automatically
|
|
622
|
-
* - Provides clear schema documentation of relationships
|
|
623
|
-
* - Enables cascade operations (DELETE, UPDATE)
|
|
624
|
-
*
|
|
625
|
-
* **Considerations**:
|
|
626
|
-
* - Foreign keys can impact performance on large tables
|
|
627
|
-
* - They prevent deletion of referenced records
|
|
628
|
-
* - Consider cascade options for related data cleanup
|
|
629
|
-
*
|
|
630
|
-
* @example
|
|
631
|
-
* ```ts
|
|
632
|
-
* foreignKeys: [
|
|
633
|
-
* {
|
|
634
|
-
* name: "fk_user_role",
|
|
635
|
-
* columns: ["roleId"],
|
|
636
|
-
* foreignColumns: [Role.id]
|
|
637
|
-
* },
|
|
638
|
-
* {
|
|
639
|
-
* columns: ["createdBy"],
|
|
640
|
-
* foreignColumns: [User.id]
|
|
641
|
-
* }
|
|
642
|
-
* ]
|
|
643
|
-
* ```
|
|
644
531
|
*/
|
|
645
532
|
foreignKeys?: Array<{
|
|
646
533
|
/**
|
|
@@ -650,7 +537,7 @@ interface EntityDescriptorOptions<TTableName extends string, T extends TObject,
|
|
|
650
537
|
/**
|
|
651
538
|
* Local columns that reference the foreign table.
|
|
652
539
|
*/
|
|
653
|
-
columns: Array<keyof Static<T>>;
|
|
540
|
+
columns: Array<keyof Static<T$1>>;
|
|
654
541
|
/**
|
|
655
542
|
* Referenced columns in the foreign table.
|
|
656
543
|
*/
|
|
@@ -697,7 +584,7 @@ interface EntityDescriptorOptions<TTableName extends string, T extends TObject,
|
|
|
697
584
|
/**
|
|
698
585
|
* Columns involved in this constraint.
|
|
699
586
|
*/
|
|
700
|
-
columns: Array<keyof Static<T>>;
|
|
587
|
+
columns: Array<keyof Static<T$1>>;
|
|
701
588
|
/**
|
|
702
589
|
* Optional name for the constraint.
|
|
703
590
|
*/
|
|
@@ -750,13 +637,13 @@ interface EntityDescriptorOptions<TTableName extends string, T extends TObject,
|
|
|
750
637
|
* ]
|
|
751
638
|
* ```
|
|
752
639
|
*/
|
|
753
|
-
config?: (self: BuildExtraConfigColumns<string, FromSchema<T>, "pg">) => PgTableExtraConfigValue[];
|
|
640
|
+
config?: (self: BuildExtraConfigColumns<string, FromSchema<T$1>, "pg">) => PgTableExtraConfigValue[];
|
|
754
641
|
}
|
|
755
|
-
type Entity<T extends TObject> = PgTableWithColumnsAndSchema<PgTableConfig<string, T, FromSchema<T>>, T>;
|
|
756
|
-
type PgTableConfig<TTableName extends string, TSchema extends TObject, TColumnsMap extends FromSchema<TSchema>> = {
|
|
757
|
-
name: TTableName;
|
|
642
|
+
type Entity<T$1 extends TObject> = PgTableWithColumnsAndSchema<PgTableConfig<string, T$1, FromSchema<T$1>>, T$1>;
|
|
643
|
+
type PgTableConfig<TTableName$1 extends string, TSchema$2 extends TObject, TColumnsMap$1 extends FromSchema<TSchema$2>> = {
|
|
644
|
+
name: TTableName$1;
|
|
758
645
|
schema: any;
|
|
759
|
-
columns: BuildColumns<TTableName, TColumnsMap, "pg">;
|
|
646
|
+
columns: BuildColumns<TTableName$1, TColumnsMap$1, "pg">;
|
|
760
647
|
dialect: "pg";
|
|
761
648
|
};
|
|
762
649
|
//#endregion
|
|
@@ -766,39 +653,6 @@ declare class PgError extends AlephaError {
|
|
|
766
653
|
constructor(message: string, cause?: unknown);
|
|
767
654
|
}
|
|
768
655
|
//#endregion
|
|
769
|
-
//#region src/helpers/pgAttr.d.ts
|
|
770
|
-
/**
|
|
771
|
-
* Decorates a typebox schema with a Postgres attribute.
|
|
772
|
-
*
|
|
773
|
-
* > It's just a fancy way to add Symbols to a field.
|
|
774
|
-
*
|
|
775
|
-
* @example
|
|
776
|
-
* ```ts
|
|
777
|
-
* import { t } from "alepha";
|
|
778
|
-
* import { PG_UPDATED_AT } from "../constants/PG_SYMBOLS";
|
|
779
|
-
*
|
|
780
|
-
* export const updatedAtSchema = pgAttr(
|
|
781
|
-
* t.datetime(), PG_UPDATED_AT,
|
|
782
|
-
* );
|
|
783
|
-
* ```
|
|
784
|
-
*/
|
|
785
|
-
declare const pgAttr: <T extends TSchema$1, Attr extends PgSymbolKeys>(type: T, attr: Attr, value?: PgSymbols[Attr]) => PgAttr<T, Attr>;
|
|
786
|
-
/**
|
|
787
|
-
* Retrieves the fields of a schema that have a specific attribute.
|
|
788
|
-
*/
|
|
789
|
-
declare const getAttrFields: (schema: TObject, name: PgSymbolKeys) => PgAttrField[];
|
|
790
|
-
/**
|
|
791
|
-
* Type representation.
|
|
792
|
-
*/
|
|
793
|
-
type PgAttr<T extends TSchema$1, TAttr extends PgSymbolKeys> = T & { [K in TAttr]: PgSymbols[K] };
|
|
794
|
-
interface PgAttrField {
|
|
795
|
-
key: string;
|
|
796
|
-
type: TSchema$1;
|
|
797
|
-
data: any;
|
|
798
|
-
nested?: any[];
|
|
799
|
-
one?: boolean;
|
|
800
|
-
}
|
|
801
|
-
//#endregion
|
|
802
656
|
//#region src/interfaces/FilterOperators.d.ts
|
|
803
657
|
interface FilterOperators<TValue> {
|
|
804
658
|
/**
|
|
@@ -1155,8 +1009,55 @@ interface FilterOperators<TValue> {
|
|
|
1155
1009
|
arrayOverlaps?: TValue;
|
|
1156
1010
|
}
|
|
1157
1011
|
//#endregion
|
|
1012
|
+
//#region src/interfaces/PgQuery.d.ts
|
|
1013
|
+
/**
|
|
1014
|
+
* Order direction for sorting
|
|
1015
|
+
*/
|
|
1016
|
+
type OrderDirection = "asc" | "desc";
|
|
1017
|
+
/**
|
|
1018
|
+
* Single order by clause with column and direction
|
|
1019
|
+
*/
|
|
1020
|
+
interface OrderByClause<T$1> {
|
|
1021
|
+
column: keyof T$1;
|
|
1022
|
+
direction?: OrderDirection;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Order by parameter - supports 3 modes:
|
|
1026
|
+
* 1. String: orderBy: "name" (defaults to ASC)
|
|
1027
|
+
* 2. Single object: orderBy: { column: "name", direction: "desc" }
|
|
1028
|
+
* 3. Array: orderBy: [{ column: "name", direction: "asc" }, { column: "age", direction: "desc" }]
|
|
1029
|
+
*/
|
|
1030
|
+
type OrderBy<T$1> = keyof T$1 | OrderByClause<T$1> | Array<OrderByClause<T$1>>;
|
|
1031
|
+
/**
|
|
1032
|
+
* Generic query interface for PostgreSQL entities
|
|
1033
|
+
*/
|
|
1034
|
+
interface PgQuery<T$1 extends TObject = TObject> {
|
|
1035
|
+
distinct?: (keyof Static<T$1>)[];
|
|
1036
|
+
columns?: (keyof Static<T$1>)[];
|
|
1037
|
+
where?: PgQueryWhereOrSQL<T$1>;
|
|
1038
|
+
limit?: number;
|
|
1039
|
+
offset?: number;
|
|
1040
|
+
orderBy?: OrderBy<Static<T$1>>;
|
|
1041
|
+
groupBy?: (keyof Static<T$1>)[];
|
|
1042
|
+
}
|
|
1043
|
+
type PgStatic<T$1 extends TObject, Relations extends PgRelationMap<T$1>> = Static<T$1> & { [K in keyof Relations]: Static<Relations[K]["join"]["$schema"]> & (Relations[K]["with"] extends PgRelationMap<TObject> ? PgStatic<Relations[K]["join"]["$schema"], Relations[K]["with"]> : {}) };
|
|
1044
|
+
interface PgQueryRelations<T$1 extends TObject = TObject, Relations extends PgRelationMap<T$1> | undefined = undefined> extends PgQuery<T$1> {
|
|
1045
|
+
with?: Relations;
|
|
1046
|
+
where?: PgQueryWhereOrSQL<T$1, Relations>;
|
|
1047
|
+
}
|
|
1048
|
+
type PgRelationMap<Base extends TObject> = Record<string, PgRelation<Base>>;
|
|
1049
|
+
type PgRelation<Base extends TObject> = {
|
|
1050
|
+
type?: "left" | "inner" | "right";
|
|
1051
|
+
join: PgTableWithColumnsAndSchema<any, TObject>;
|
|
1052
|
+
on: SQLWrapper | [keyof Static<Base>, PgColumn];
|
|
1053
|
+
with?: PgRelationMap<TObject>;
|
|
1054
|
+
};
|
|
1055
|
+
//#endregion
|
|
1158
1056
|
//#region src/interfaces/PgQueryWhere.d.ts
|
|
1159
|
-
type PgQueryWhere<T extends TObject>
|
|
1057
|
+
type PgQueryWhere<T$1 extends TObject, Relations extends PgRelationMap<TObject> | undefined = undefined> = (PgQueryWhereOperators<T$1> & PgQueryWhereConditions<T$1>) | (PgQueryWhereRelations<Relations> & PgQueryWhereOperators<T$1> & PgQueryWhereConditions<T$1, Relations>);
|
|
1058
|
+
type PgQueryWhereOrSQL<T$1 extends TObject, Relations extends PgRelationMap<TObject> | undefined = undefined> = SQLWrapper | PgQueryWhere<T$1, Relations>;
|
|
1059
|
+
type PgQueryWhereOperators<T$1 extends TObject> = { [Key in keyof Static<T$1>]?: FilterOperators<Static<T$1>[Key]> | Static<T$1>[Key] | (Static<T$1>[Key] extends object ? NestedJsonbQuery<Static<T$1>[Key]> : never) };
|
|
1060
|
+
type PgQueryWhereConditions<T$1 extends TObject, Relations extends PgRelationMap<TObject> | undefined = undefined> = {
|
|
1160
1061
|
/**
|
|
1161
1062
|
* Combine a list of conditions with the `and` operator. Conditions
|
|
1162
1063
|
* that are equal `undefined` are automatically ignored.
|
|
@@ -1173,7 +1074,7 @@ type PgQueryWhere<T extends TObject> = { [Key in keyof Static<T>]?: FilterOperat
|
|
|
1173
1074
|
* )
|
|
1174
1075
|
* ```
|
|
1175
1076
|
*/
|
|
1176
|
-
and?: Array<PgQueryWhereOrSQL<T>>;
|
|
1077
|
+
and?: Array<PgQueryWhereOrSQL<T$1, Relations>>;
|
|
1177
1078
|
/**
|
|
1178
1079
|
* Combine a list of conditions with the `or` operator. Conditions
|
|
1179
1080
|
* that are equal `undefined` are automatically ignored.
|
|
@@ -1190,7 +1091,7 @@ type PgQueryWhere<T extends TObject> = { [Key in keyof Static<T>]?: FilterOperat
|
|
|
1190
1091
|
* )
|
|
1191
1092
|
* ```
|
|
1192
1093
|
*/
|
|
1193
|
-
or?: Array<PgQueryWhereOrSQL<T>>;
|
|
1094
|
+
or?: Array<PgQueryWhereOrSQL<T$1, Relations>>;
|
|
1194
1095
|
/**
|
|
1195
1096
|
* Negate the meaning of an expression using the `not` keyword.
|
|
1196
1097
|
*
|
|
@@ -1202,7 +1103,7 @@ type PgQueryWhere<T extends TObject> = { [Key in keyof Static<T>]?: FilterOperat
|
|
|
1202
1103
|
* .where(not(inArray(cars.make, ['GM', 'Ford'])))
|
|
1203
1104
|
* ```
|
|
1204
1105
|
*/
|
|
1205
|
-
not?: PgQueryWhereOrSQL<T>;
|
|
1106
|
+
not?: PgQueryWhereOrSQL<T$1, Relations>;
|
|
1206
1107
|
/**
|
|
1207
1108
|
* Test whether a subquery evaluates to have any rows.
|
|
1208
1109
|
*
|
|
@@ -1225,88 +1126,29 @@ type PgQueryWhere<T extends TObject> = { [Key in keyof Static<T>]?: FilterOperat
|
|
|
1225
1126
|
*/
|
|
1226
1127
|
exists?: SQLWrapper;
|
|
1227
1128
|
};
|
|
1228
|
-
type
|
|
1229
|
-
type PgQueryWhereWithManyOrSQL<T extends TObject> = SQLWrapper | PgQueryWhereWithMany<T>;
|
|
1230
|
-
type PgQueryWhereWithMany<T extends TObject> = PgQueryWhere<RemoveManyRelations<T>> & ExtractManyRelations<T>;
|
|
1231
|
-
type RelField = {
|
|
1232
|
-
[PG_MANY]: any;
|
|
1233
|
-
} | {
|
|
1234
|
-
[PG_ONE]: any;
|
|
1235
|
-
};
|
|
1236
|
-
type ExtractManyRelations<T extends TObject> = { [K in keyof T["properties"] as T["properties"][K] extends RelField ? T["properties"][K] extends TArray ? T["properties"][K]["items"] extends TObject ? K : never : never : T["properties"][K] extends TObject ? K : never]?: PgQueryWhere<T["properties"][K] extends TArray ? T["properties"][K]["items"] extends TObject ? T["properties"][K]["items"] : TObject : T["properties"][K] extends TObject ? T["properties"][K] : TObject> };
|
|
1237
|
-
type RemoveManyRelations<T extends TObject> = TObject<{ [K in keyof T["properties"] as T["properties"][K] extends RelField ? never : K]: T["properties"][K] }>;
|
|
1238
|
-
type PgQueryWithMap<T extends TObject> = { [K in keyof T["properties"] as T["properties"][K] extends RelField ? K : never]?: T["properties"][K] extends TArray ? T["properties"][K]["items"] extends TObject ? PgQueryWithMany<T["properties"][K]["items"]> : never : T["properties"][K] extends TObject ? PgQueryWithOne<T["properties"][K]> : T["properties"][K] extends PgAttr<PgAttr<TOptionalAdd<infer U>, PgOne>, PgDefault> ? U extends TObject ? PgQueryWithOne<U> : never : never };
|
|
1239
|
-
type PgQueryWithOne<T extends TObject> = true | {
|
|
1240
|
-
columns?: (keyof Static<T>)[];
|
|
1241
|
-
relations?: PgQueryWithMap<T>;
|
|
1242
|
-
};
|
|
1243
|
-
type PgQueryWithMany<T extends TObject> = true | {
|
|
1244
|
-
limit?: number;
|
|
1245
|
-
columns?: (keyof Static<T>)[];
|
|
1246
|
-
relations?: PgQueryWithMap<T>;
|
|
1247
|
-
};
|
|
1248
|
-
//#endregion
|
|
1249
|
-
//#region src/interfaces/PgQuery.d.ts
|
|
1250
|
-
/**
|
|
1251
|
-
* Order direction for sorting
|
|
1252
|
-
*/
|
|
1253
|
-
type OrderDirection = "asc" | "desc";
|
|
1254
|
-
/**
|
|
1255
|
-
* Single order by clause with column and direction
|
|
1256
|
-
*/
|
|
1257
|
-
interface OrderByClause<T> {
|
|
1258
|
-
column: keyof T;
|
|
1259
|
-
direction?: OrderDirection;
|
|
1260
|
-
}
|
|
1129
|
+
type PgQueryWhereRelations<Relations extends PgRelationMap<TObject> | undefined = undefined> = Relations extends PgRelationMap<TObject> ? { [K in keyof Relations]?: PgQueryWhere<Relations[K]["join"]["$schema"], Relations[K]["with"]> } : {};
|
|
1261
1130
|
/**
|
|
1262
|
-
*
|
|
1263
|
-
* 1. String: orderBy: "name" (defaults to ASC)
|
|
1264
|
-
* 2. Single object: orderBy: { column: "name", direction: "desc" }
|
|
1265
|
-
* 3. Array: orderBy: [{ column: "name", direction: "asc" }, { column: "age", direction: "desc" }]
|
|
1131
|
+
* Recursively allow nested queries for JSONB object/array types
|
|
1266
1132
|
*/
|
|
1267
|
-
type
|
|
1268
|
-
interface PgQuery<T extends TObject = TObject> {
|
|
1269
|
-
distinct?: boolean;
|
|
1270
|
-
where?: PgQueryWhereWithMany<T> | SQLWrapper;
|
|
1271
|
-
limit?: number;
|
|
1272
|
-
offset?: number;
|
|
1273
|
-
orderBy?: OrderBy<Static<T>>;
|
|
1274
|
-
groupBy?: (keyof Static<T>)[];
|
|
1275
|
-
relations?: PgQueryWithMap<T>;
|
|
1276
|
-
}
|
|
1277
|
-
//#endregion
|
|
1278
|
-
//#region src/providers/drivers/PostgresProvider.d.ts
|
|
1279
|
-
type SQLLike = SQLWrapper | string;
|
|
1280
|
-
declare abstract class PostgresProvider {
|
|
1281
|
-
protected readonly alepha: Alepha;
|
|
1282
|
-
abstract get db(): PgDatabase<any>;
|
|
1283
|
-
readonly dialect: "postgres" | "sqlite";
|
|
1284
|
-
get schema(): string;
|
|
1285
|
-
execute<T extends TObject | undefined>(query: SQLLike, schema?: T): Promise<Array<T extends TObject ? Static<T> : any>>;
|
|
1286
|
-
protected mapResult<T extends TObject = any>(result: Array<any>, schema?: T): Array<T extends TObject ? Static<T> : any>;
|
|
1287
|
-
}
|
|
1288
|
-
//#endregion
|
|
1289
|
-
//#region src/schemas/pageQuerySchema.d.ts
|
|
1290
|
-
declare const pageQuerySchema: typebox1.TObject<{
|
|
1291
|
-
page: typebox1.TOptional<typebox1.TInteger>;
|
|
1292
|
-
size: typebox1.TOptional<typebox1.TInteger>;
|
|
1293
|
-
sort: typebox1.TOptional<typebox1.TString>;
|
|
1294
|
-
}>;
|
|
1295
|
-
type PageQuery = Static<typeof pageQuerySchema>;
|
|
1133
|
+
type NestedJsonbQuery<T$1> = T$1 extends object ? T$1 extends Array<infer U> ? U extends object ? { [K in keyof U]?: FilterOperators<U[K]> | U[K] } : FilterOperators<U> | U : { [K in keyof T$1]?: FilterOperators<T$1[K]> | T$1[K] | (T$1[K] extends object ? NestedJsonbQuery<T$1[K]> : never) } : FilterOperators<T$1> | T$1;
|
|
1296
1134
|
//#endregion
|
|
1297
1135
|
//#region src/schemas/pageSchema.d.ts
|
|
1298
1136
|
/**
|
|
1299
1137
|
* Create a pagination schema for the given object schema.
|
|
1300
1138
|
*
|
|
1139
|
+
* > use `pg.page` directly.
|
|
1140
|
+
*
|
|
1301
1141
|
* @example
|
|
1142
|
+
* ```ts
|
|
1302
1143
|
* const userSchema = t.object({ id: t.int(), name: t.text() });
|
|
1303
|
-
* const
|
|
1144
|
+
* const userPageSchema = pageSchema(userSchema);
|
|
1145
|
+
* ```
|
|
1304
1146
|
*
|
|
1305
1147
|
* @see {@link $repository#paginate}
|
|
1306
1148
|
*/
|
|
1307
1149
|
declare const pageSchema: <T extends TObject | TRecord>(objectSchema: T, options?: TObjectOptions) => TPage<T>;
|
|
1308
|
-
type TPage<T extends TObject | TRecord> = TObject<{
|
|
1309
|
-
content: TArray<T>;
|
|
1150
|
+
type TPage<T$1 extends TObject | TRecord> = TObject<{
|
|
1151
|
+
content: TArray<T$1>;
|
|
1310
1152
|
can: TObject<{
|
|
1311
1153
|
next: TBoolean;
|
|
1312
1154
|
previous: TBoolean;
|
|
@@ -1317,22 +1159,244 @@ type TPage<T extends TObject | TRecord> = TObject<{
|
|
|
1317
1159
|
totalElements: TOptionalAdd<TInteger>;
|
|
1318
1160
|
}>;
|
|
1319
1161
|
}>;
|
|
1320
|
-
|
|
1321
|
-
|
|
1162
|
+
/**
|
|
1163
|
+
* Opinionated type definition for a paginated response.
|
|
1164
|
+
*
|
|
1165
|
+
* @example
|
|
1166
|
+
* ```ts
|
|
1167
|
+
* const page = {
|
|
1168
|
+
* content: [ ... ]
|
|
1169
|
+
* can: {
|
|
1170
|
+
* next: true,
|
|
1171
|
+
* previous: false
|
|
1172
|
+
* },
|
|
1173
|
+
* page: {
|
|
1174
|
+
* number: 0,
|
|
1175
|
+
* size: 10,
|
|
1176
|
+
* totalElements: 1200
|
|
1177
|
+
* }
|
|
1178
|
+
* }
|
|
1179
|
+
* ```
|
|
1180
|
+
*/
|
|
1181
|
+
type Page<T$1> = {
|
|
1182
|
+
/**
|
|
1183
|
+
* Array of items on the current page.
|
|
1184
|
+
*/
|
|
1185
|
+
content: T$1[];
|
|
1322
1186
|
can: {
|
|
1187
|
+
/**
|
|
1188
|
+
* Indicates if there is a next page.
|
|
1189
|
+
*/
|
|
1323
1190
|
next: boolean;
|
|
1191
|
+
/**
|
|
1192
|
+
* Indicates if there is a previous page.
|
|
1193
|
+
*/
|
|
1324
1194
|
previous: boolean;
|
|
1325
1195
|
};
|
|
1326
1196
|
page: {
|
|
1197
|
+
/**
|
|
1198
|
+
* Page number, starting from 0.
|
|
1199
|
+
*/
|
|
1327
1200
|
number: number;
|
|
1201
|
+
/**
|
|
1202
|
+
* Number of items per page.
|
|
1203
|
+
*/
|
|
1328
1204
|
size: number;
|
|
1205
|
+
/**
|
|
1206
|
+
* Requires `count: true` in the paginate options.
|
|
1207
|
+
*/
|
|
1329
1208
|
totalElements?: number;
|
|
1330
1209
|
};
|
|
1331
1210
|
};
|
|
1332
1211
|
//#endregion
|
|
1212
|
+
//#region src/helpers/PgJsonQueryManager.d.ts
|
|
1213
|
+
/**
|
|
1214
|
+
* Manages JSONB query generation for nested object and array queries in PostgreSQL.
|
|
1215
|
+
* This class handles complex nested queries using PostgreSQL's JSONB operators.
|
|
1216
|
+
*/
|
|
1217
|
+
declare class PgJsonQueryManager {
|
|
1218
|
+
/**
|
|
1219
|
+
* Check if a query contains nested JSONB queries.
|
|
1220
|
+
* A nested query is when the value is an object with operator keys.
|
|
1221
|
+
*/
|
|
1222
|
+
hasNestedQuery(where: PgQueryWhere<TObject>): boolean;
|
|
1223
|
+
/**
|
|
1224
|
+
* Build a JSONB query condition for nested object queries.
|
|
1225
|
+
* Supports deep nesting like: { profile: { contact: { email: { eq: "test@example.com" } } } }
|
|
1226
|
+
*
|
|
1227
|
+
* @param column The JSONB column
|
|
1228
|
+
* @param path The path to the nested property (e.g., ['profile', 'contact', 'email'])
|
|
1229
|
+
* @param operator The filter operator (e.g., { eq: "test@example.com" })
|
|
1230
|
+
* @returns SQL condition
|
|
1231
|
+
*/
|
|
1232
|
+
buildJsonbCondition(column: PgColumn, path: string[], operator: FilterOperators<any>): SQL | undefined;
|
|
1233
|
+
/**
|
|
1234
|
+
* Build JSONB array query conditions.
|
|
1235
|
+
* Supports queries like: { addresses: { city: { eq: "Wonderland" } } }
|
|
1236
|
+
* which translates to: EXISTS (SELECT 1 FROM jsonb_array_elements(addresses) elem WHERE elem->>'city' = 'Wonderland')
|
|
1237
|
+
*/
|
|
1238
|
+
buildJsonbArrayCondition(column: PgColumn, path: string[], arrayPath: string, operator: FilterOperators<any>): SQL | undefined;
|
|
1239
|
+
/**
|
|
1240
|
+
* Apply a filter operator to a JSONB value.
|
|
1241
|
+
*/
|
|
1242
|
+
private applyOperatorToJsonValue;
|
|
1243
|
+
/**
|
|
1244
|
+
* Parse a nested query object and extract the path and operator.
|
|
1245
|
+
* For example: { profile: { contact: { email: { eq: "test@example.com" } } } }
|
|
1246
|
+
* Returns: { path: ['profile', 'contact', 'email'], operator: { eq: "test@example.com" } }
|
|
1247
|
+
*/
|
|
1248
|
+
parseNestedQuery(nestedQuery: any, currentPath?: string[]): Array<{
|
|
1249
|
+
path: string[];
|
|
1250
|
+
operator: FilterOperators<any>;
|
|
1251
|
+
}>;
|
|
1252
|
+
/**
|
|
1253
|
+
* Determine if a property is a JSONB column based on the schema.
|
|
1254
|
+
* A column is JSONB if it's defined as an object or array in the TypeBox schema.
|
|
1255
|
+
*/
|
|
1256
|
+
isJsonbColumn(schema: TObject, columnName: string): boolean;
|
|
1257
|
+
/**
|
|
1258
|
+
* Check if an array property contains primitive types (string, number, boolean, etc.)
|
|
1259
|
+
* rather than objects. Primitive arrays should use native Drizzle operators.
|
|
1260
|
+
* @returns true if the array contains primitives, false if it contains objects
|
|
1261
|
+
*/
|
|
1262
|
+
isPrimitiveArray(schema: TObject, columnName: string): boolean;
|
|
1263
|
+
/**
|
|
1264
|
+
* Check if a nested path points to an array property.
|
|
1265
|
+
*/
|
|
1266
|
+
isArrayProperty(schema: TObject, path: string[]): boolean;
|
|
1267
|
+
}
|
|
1268
|
+
//#endregion
|
|
1269
|
+
//#region src/helpers/PgQueryManager.d.ts
|
|
1270
|
+
declare class PgQueryManager {
|
|
1271
|
+
protected readonly jsonQueryManager: PgJsonQueryManager;
|
|
1272
|
+
/**
|
|
1273
|
+
* Convert a query object to a SQL query.
|
|
1274
|
+
*/
|
|
1275
|
+
toSQL(query: PgQueryWhereOrSQL<TObject>, options: {
|
|
1276
|
+
schema: TObject;
|
|
1277
|
+
col: (key: string) => PgColumn;
|
|
1278
|
+
joins?: PgJoin[];
|
|
1279
|
+
}): SQL | undefined;
|
|
1280
|
+
/**
|
|
1281
|
+
* Build a JSONB query for nested object/array queries.
|
|
1282
|
+
*/
|
|
1283
|
+
protected buildJsonbQuery(column: PgColumn, nestedQuery: any, schema: TObject, columnName: string): SQL | undefined;
|
|
1284
|
+
/**
|
|
1285
|
+
* Map a filter operator to a SQL query.
|
|
1286
|
+
*/
|
|
1287
|
+
mapOperatorToSql(operator: FilterOperators<any> | any, column: PgColumn): SQL | undefined;
|
|
1288
|
+
/**
|
|
1289
|
+
* Parse pagination sort string to orderBy format.
|
|
1290
|
+
* Format: "firstName,-lastName" -> [{ column: "firstName", direction: "asc" }, { column: "lastName", direction: "desc" }]
|
|
1291
|
+
* - Columns separated by comma
|
|
1292
|
+
* - Prefix with '-' for DESC direction
|
|
1293
|
+
*
|
|
1294
|
+
* @param sort Pagination sort string
|
|
1295
|
+
* @returns OrderBy array or single object
|
|
1296
|
+
*/
|
|
1297
|
+
parsePaginationSort(sort: string): Array<{
|
|
1298
|
+
column: string;
|
|
1299
|
+
direction: "asc" | "desc";
|
|
1300
|
+
}> | {
|
|
1301
|
+
column: string;
|
|
1302
|
+
direction: "asc" | "desc";
|
|
1303
|
+
};
|
|
1304
|
+
/**
|
|
1305
|
+
* Normalize orderBy parameter to array format.
|
|
1306
|
+
* Supports 3 modes:
|
|
1307
|
+
* 1. String: "name" -> [{ column: "name", direction: "asc" }]
|
|
1308
|
+
* 2. Object: { column: "name", direction: "desc" } -> [{ column: "name", direction: "desc" }]
|
|
1309
|
+
* 3. Array: [{ column: "name" }, { column: "age", direction: "desc" }] -> normalized array
|
|
1310
|
+
*
|
|
1311
|
+
* @param orderBy The orderBy parameter
|
|
1312
|
+
* @returns Normalized array of order by clauses
|
|
1313
|
+
*/
|
|
1314
|
+
normalizeOrderBy(orderBy: any): Array<{
|
|
1315
|
+
column: string;
|
|
1316
|
+
direction: "asc" | "desc";
|
|
1317
|
+
}>;
|
|
1318
|
+
/**
|
|
1319
|
+
* Create a pagination object.
|
|
1320
|
+
*
|
|
1321
|
+
* @param entities The entities to paginate.
|
|
1322
|
+
* @param limit The limit of the pagination.
|
|
1323
|
+
* @param offset The offset of the pagination.
|
|
1324
|
+
*/
|
|
1325
|
+
createPagination<T>(entities: T[], limit?: number, offset?: number): Page<T>;
|
|
1326
|
+
}
|
|
1327
|
+
interface PgJoin {
|
|
1328
|
+
table: string;
|
|
1329
|
+
schema: TObject;
|
|
1330
|
+
key: string;
|
|
1331
|
+
col: (key: string) => PgColumn;
|
|
1332
|
+
parent?: string;
|
|
1333
|
+
}
|
|
1334
|
+
//#endregion
|
|
1335
|
+
//#region src/helpers/PgRelationManager.d.ts
|
|
1336
|
+
declare class PgRelationManager {
|
|
1337
|
+
buildJoins(builder: PgSelectBase<any, any, any>, joins: Array<PgJoin>, withRelations: PgRelationMap<TObject>, table: PgTableWithColumnsAndSchema<any, any>, parentKey?: string): void;
|
|
1338
|
+
mapRowWithJoins(record: Record<string, unknown>, row: Record<string, unknown>, schema: TObject, joins: PgJoin[], parentKey?: string): Record<string, unknown>;
|
|
1339
|
+
/**
|
|
1340
|
+
* Check if all values in an object are null (indicates a left join with no match)
|
|
1341
|
+
*/
|
|
1342
|
+
private isAllNull;
|
|
1343
|
+
}
|
|
1344
|
+
//#endregion
|
|
1345
|
+
//#region src/helpers/pgAttr.d.ts
|
|
1346
|
+
/**
|
|
1347
|
+
* Decorates a typebox schema with a Postgres attribute.
|
|
1348
|
+
*
|
|
1349
|
+
* > It's just a fancy way to add Symbols to a field.
|
|
1350
|
+
*
|
|
1351
|
+
* @example
|
|
1352
|
+
* ```ts
|
|
1353
|
+
* import { t } from "alepha";
|
|
1354
|
+
* import { PG_UPDATED_AT } from "../constants/PG_SYMBOLS";
|
|
1355
|
+
*
|
|
1356
|
+
* export const updatedAtSchema = pgAttr(
|
|
1357
|
+
* t.datetime(), PG_UPDATED_AT,
|
|
1358
|
+
* );
|
|
1359
|
+
* ```
|
|
1360
|
+
*/
|
|
1361
|
+
declare const pgAttr: <T extends TSchema$1, Attr extends PgSymbolKeys>(type: T, attr: Attr, value?: PgSymbols[Attr]) => PgAttr<T, Attr>;
|
|
1362
|
+
/**
|
|
1363
|
+
* Retrieves the fields of a schema that have a specific attribute.
|
|
1364
|
+
*/
|
|
1365
|
+
declare const getAttrFields: (schema: TObject, name: PgSymbolKeys) => PgAttrField[];
|
|
1366
|
+
/**
|
|
1367
|
+
* Type representation.
|
|
1368
|
+
*/
|
|
1369
|
+
type PgAttr<T$1 extends TSchema$1, TAttr extends PgSymbolKeys> = T$1 & { [K in TAttr]: PgSymbols[K] };
|
|
1370
|
+
interface PgAttrField {
|
|
1371
|
+
key: string;
|
|
1372
|
+
type: TSchema$1;
|
|
1373
|
+
data: any;
|
|
1374
|
+
nested?: any[];
|
|
1375
|
+
one?: boolean;
|
|
1376
|
+
}
|
|
1377
|
+
//#endregion
|
|
1378
|
+
//#region src/providers/drivers/PostgresProvider.d.ts
|
|
1379
|
+
type SQLLike = SQLWrapper | string;
|
|
1380
|
+
declare abstract class PostgresProvider {
|
|
1381
|
+
protected readonly alepha: Alepha;
|
|
1382
|
+
abstract get db(): PgDatabase<any>;
|
|
1383
|
+
readonly dialect: "postgres" | "sqlite";
|
|
1384
|
+
get schema(): string;
|
|
1385
|
+
execute<T extends TObject | undefined>(query: SQLLike, schema?: T): Promise<Array<T extends TObject ? Static<T> : any>>;
|
|
1386
|
+
protected mapResult<T extends TObject = any>(result: Array<any>, schema?: T): Array<T extends TObject ? Static<T> : any>;
|
|
1387
|
+
}
|
|
1388
|
+
//#endregion
|
|
1389
|
+
//#region src/schemas/pageQuerySchema.d.ts
|
|
1390
|
+
declare const pageQuerySchema: typebox0.TObject<{
|
|
1391
|
+
page: typebox0.TOptional<typebox0.TInteger>;
|
|
1392
|
+
size: typebox0.TOptional<typebox0.TInteger>;
|
|
1393
|
+
sort: typebox0.TOptional<typebox0.TString>;
|
|
1394
|
+
}>;
|
|
1395
|
+
type PageQuery = Static<typeof pageQuerySchema>;
|
|
1396
|
+
//#endregion
|
|
1333
1397
|
//#region src/descriptors/$repository.d.ts
|
|
1334
1398
|
/**
|
|
1335
|
-
* Creates a repository
|
|
1399
|
+
* Creates a repository for database operations on a defined entity.
|
|
1336
1400
|
*
|
|
1337
1401
|
* This descriptor provides a comprehensive, type-safe interface for performing all
|
|
1338
1402
|
* database operations on entities defined with $entity. It offers a rich set of
|
|
@@ -1355,15 +1419,6 @@ type Page<T> = {
|
|
|
1355
1419
|
* - Entity schema must include exactly one primary key field
|
|
1356
1420
|
* - Database tables must be created via migrations before use
|
|
1357
1421
|
*
|
|
1358
|
-
* **Use Cases**
|
|
1359
|
-
*
|
|
1360
|
-
* Essential for all database-driven applications:
|
|
1361
|
-
* - User management and authentication systems
|
|
1362
|
-
* - E-commerce product and order management
|
|
1363
|
-
* - Content management and blogging platforms
|
|
1364
|
-
* - Financial and accounting applications
|
|
1365
|
-
* - Any application requiring persistent data storage
|
|
1366
|
-
*
|
|
1367
1422
|
* @example
|
|
1368
1423
|
* **Basic repository with CRUD operations:**
|
|
1369
1424
|
* ```ts
|
|
@@ -1371,14 +1426,14 @@ type Page<T> = {
|
|
|
1371
1426
|
* import { pg, t } from "alepha";
|
|
1372
1427
|
*
|
|
1373
1428
|
* // First, define the entity
|
|
1374
|
-
* const
|
|
1429
|
+
* const users = $entity({
|
|
1375
1430
|
* name: "users",
|
|
1376
1431
|
* schema: t.object({
|
|
1377
1432
|
* id: pg.primaryKey(t.uuid()),
|
|
1378
1433
|
* email: t.text({ format: "email" }),
|
|
1379
1434
|
* firstName: t.text(),
|
|
1380
1435
|
* lastName: t.text(),
|
|
1381
|
-
* isActive: t.boolean(
|
|
1436
|
+
* isActive: pg.default(t.boolean(), true),
|
|
1382
1437
|
* createdAt: pg.createdAt(),
|
|
1383
1438
|
* updatedAt: pg.updatedAt()
|
|
1384
1439
|
* }),
|
|
@@ -1386,15 +1441,14 @@ type Page<T> = {
|
|
|
1386
1441
|
* });
|
|
1387
1442
|
*
|
|
1388
1443
|
* class UserService {
|
|
1389
|
-
* users = $repository(
|
|
1444
|
+
* users = $repository(users);
|
|
1390
1445
|
*
|
|
1391
1446
|
* async createUser(userData: { email: string; firstName: string; lastName: string }) {
|
|
1392
1447
|
* return await this.users.create({
|
|
1393
1448
|
* id: generateUUID(),
|
|
1394
1449
|
* email: userData.email,
|
|
1395
1450
|
* firstName: userData.firstName,
|
|
1396
|
-
* lastName: userData.lastName
|
|
1397
|
-
* isActive: true
|
|
1451
|
+
* lastName: userData.lastName
|
|
1398
1452
|
* });
|
|
1399
1453
|
* }
|
|
1400
1454
|
*
|
|
@@ -1416,7 +1470,7 @@ declare const $repository: {
|
|
|
1416
1470
|
<EntityTableConfig extends TableConfig, EntitySchema extends TObject>(optionsOrTable: RepositoryDescriptorOptions<EntityTableConfig, EntitySchema> | PgTableWithColumnsAndSchema<EntityTableConfig, EntitySchema>): RepositoryDescriptor<EntityTableConfig, EntitySchema>;
|
|
1417
1471
|
[KIND]: typeof RepositoryDescriptor;
|
|
1418
1472
|
};
|
|
1419
|
-
interface RepositoryDescriptorOptions<EntityTableConfig extends TableConfig, EntitySchema extends TObject> {
|
|
1473
|
+
interface RepositoryDescriptorOptions<EntityTableConfig$1 extends TableConfig, EntitySchema$1 extends TObject> {
|
|
1420
1474
|
/**
|
|
1421
1475
|
* The entity table definition created with $entity.
|
|
1422
1476
|
*
|
|
@@ -1451,7 +1505,7 @@ interface RepositoryDescriptorOptions<EntityTableConfig extends TableConfig, Ent
|
|
|
1451
1505
|
* const userRepository = $repository({ table: User });
|
|
1452
1506
|
* ```
|
|
1453
1507
|
*/
|
|
1454
|
-
table: PgTableWithColumnsAndSchema<EntityTableConfig, EntitySchema>;
|
|
1508
|
+
table: PgTableWithColumnsAndSchema<EntityTableConfig$1, EntitySchema$1>;
|
|
1455
1509
|
/**
|
|
1456
1510
|
* Override the default PostgreSQL database provider.
|
|
1457
1511
|
*
|
|
@@ -1476,12 +1530,14 @@ interface RepositoryDescriptorOptions<EntityTableConfig extends TableConfig, Ent
|
|
|
1476
1530
|
*/
|
|
1477
1531
|
provider?: Service<PostgresProvider>;
|
|
1478
1532
|
}
|
|
1479
|
-
declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, EntitySchema extends TObject> extends Descriptor<RepositoryDescriptorOptions<EntityTableConfig, EntitySchema>> {
|
|
1533
|
+
declare class RepositoryDescriptor<EntityTableConfig$1 extends TableConfig, EntitySchema$1 extends TObject> extends Descriptor<RepositoryDescriptorOptions<EntityTableConfig$1, EntitySchema$1>> {
|
|
1534
|
+
protected readonly pgRelationManager: PgRelationManager;
|
|
1535
|
+
protected readonly pgQueryManager: PgQueryManager;
|
|
1480
1536
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
1481
1537
|
protected readonly alepha: Alepha;
|
|
1482
1538
|
readonly provider: PostgresProvider;
|
|
1483
|
-
readonly schema: EntitySchema;
|
|
1484
|
-
readonly schemaInsert: TObjectInsert<EntitySchema>;
|
|
1539
|
+
readonly schema: EntitySchema$1;
|
|
1540
|
+
readonly schemaInsert: TObjectInsert<EntitySchema$1>;
|
|
1485
1541
|
/**
|
|
1486
1542
|
* Represents the primary key of the table.
|
|
1487
1543
|
* - Key is the name of the primary key column.
|
|
@@ -1491,13 +1547,13 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1491
1547
|
*/
|
|
1492
1548
|
readonly id: {
|
|
1493
1549
|
type: TSchema$1;
|
|
1494
|
-
key: keyof EntitySchema["properties"];
|
|
1550
|
+
key: keyof EntitySchema$1["properties"];
|
|
1495
1551
|
col: PgColumn;
|
|
1496
1552
|
};
|
|
1497
1553
|
/**
|
|
1498
1554
|
* Get Drizzle table object.
|
|
1499
1555
|
*/
|
|
1500
|
-
get table(): PgTableWithColumns<EntityTableConfig>;
|
|
1556
|
+
get table(): PgTableWithColumns<EntityTableConfig$1>;
|
|
1501
1557
|
/**
|
|
1502
1558
|
* Get SQL table name. (from Drizzle table object)
|
|
1503
1559
|
*/
|
|
@@ -1508,84 +1564,94 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1508
1564
|
protected get db(): PgDatabase<any, Record<string, never>, drizzle_orm6.ExtractTablesWithRelations<Record<string, never>>>;
|
|
1509
1565
|
/**
|
|
1510
1566
|
* Execute a SQL query.
|
|
1567
|
+
*
|
|
1568
|
+
* This method allows executing raw SQL queries against the database.
|
|
1569
|
+
* This is by far the easiest way to run custom queries that are not covered by the repository's built-in methods!
|
|
1570
|
+
*
|
|
1571
|
+
* You must use the `sql` tagged template function from Drizzle ORM to create the query. https://orm.drizzle.team/docs/sql
|
|
1572
|
+
*
|
|
1573
|
+
* @example
|
|
1574
|
+
* ```ts
|
|
1575
|
+
* const users = $entity({ ... });
|
|
1576
|
+
* const result = await repository.query(sql`SELECT * FROM ${users} WHERE ${users.age} > ${18}`, users.$schema);
|
|
1577
|
+
* ```
|
|
1578
|
+
*/
|
|
1579
|
+
query<T extends TObject = EntitySchema$1>(query: SQLLike | ((table: PgTableWithColumns<EntityTableConfig$1>, db: PgDatabase<any>) => SQLLike), schema?: T): Promise<Static<T>[]>;
|
|
1580
|
+
/**
|
|
1581
|
+
* Map raw database fields to entity fields. (handles column name differences)
|
|
1511
1582
|
*/
|
|
1512
|
-
|
|
1513
|
-
protected mapRawFieldsToEntity(row: any[]): any;
|
|
1583
|
+
protected mapRawFieldsToEntity(row: Record<string, unknown>): any;
|
|
1514
1584
|
/**
|
|
1515
1585
|
* Get a Drizzle column from the table by his name.
|
|
1516
|
-
*
|
|
1517
|
-
* @param name - The name of the column to get.
|
|
1518
|
-
* @returns The column from the table.
|
|
1519
1586
|
*/
|
|
1520
|
-
protected col(name: keyof PgTableWithColumns<EntityTableConfig>["_"]["columns"]): PgColumn;
|
|
1587
|
+
protected col(name: keyof PgTableWithColumns<EntityTableConfig$1>["_"]["columns"]): PgColumn;
|
|
1521
1588
|
/**
|
|
1522
1589
|
* Run a transaction.
|
|
1523
|
-
*
|
|
1524
|
-
* @param transaction
|
|
1525
|
-
* @param config
|
|
1526
1590
|
*/
|
|
1527
1591
|
transaction<T>(transaction: (tx: PgTransaction<any, Record<string, any>, any>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
1528
1592
|
/**
|
|
1529
1593
|
* Start a SELECT query on the table.
|
|
1530
|
-
*
|
|
1531
|
-
* @returns The SELECT query builder.
|
|
1532
1594
|
*/
|
|
1533
1595
|
protected select(opts?: StatementOptions): pg$1.PgSelectBase<string, Record<string, PgColumn<drizzle_orm6.ColumnBaseConfig<drizzle_orm6.ColumnDataType, string>, {}, {}>>, "single", Record<string, "not-null">, false, never, {
|
|
1534
1596
|
[x: string]: unknown;
|
|
1535
1597
|
}[], {
|
|
1536
1598
|
[x: string]: PgColumn<drizzle_orm6.ColumnBaseConfig<drizzle_orm6.ColumnDataType, string>, {}, {}>;
|
|
1537
1599
|
}>;
|
|
1538
|
-
|
|
1539
|
-
|
|
1600
|
+
/**
|
|
1601
|
+
* Start a SELECT DISTINCT query on the table.
|
|
1602
|
+
*/
|
|
1603
|
+
protected selectDistinct(opts?: StatementOptions, columns?: (keyof Static<EntitySchema$1>)[]): pg$1.PgSelectBase<string, Record<string, any>, "partial", Record<string, "not-null">, false, never, {
|
|
1604
|
+
[x: string]: any;
|
|
1540
1605
|
}[], {
|
|
1541
|
-
[x: string]:
|
|
1606
|
+
[x: string]: any;
|
|
1542
1607
|
}>;
|
|
1543
1608
|
/**
|
|
1544
1609
|
* Start an INSERT query on the table.
|
|
1545
|
-
*
|
|
1546
|
-
* @returns The INSERT query builder.
|
|
1547
1610
|
*/
|
|
1548
|
-
protected insert(opts?: StatementOptions): pg$1.PgInsertBuilder<PgTableWithColumns<EntityTableConfig>, any, false>;
|
|
1611
|
+
protected insert(opts?: StatementOptions): pg$1.PgInsertBuilder<PgTableWithColumns<EntityTableConfig$1>, any, false>;
|
|
1549
1612
|
/**
|
|
1550
1613
|
* Start an UPDATE query on the table.
|
|
1551
|
-
*
|
|
1552
|
-
* @returns The UPDATE query builder.
|
|
1553
1614
|
*/
|
|
1554
|
-
protected update(opts?: StatementOptions): pg$1.PgUpdateBuilder<PgTableWithColumns<EntityTableConfig>, any>;
|
|
1615
|
+
protected update(opts?: StatementOptions): pg$1.PgUpdateBuilder<PgTableWithColumns<EntityTableConfig$1>, any>;
|
|
1555
1616
|
/**
|
|
1556
1617
|
* Start a DELETE query on the table.
|
|
1557
|
-
*
|
|
1558
|
-
* @returns The DELETE query builder.
|
|
1559
1618
|
*/
|
|
1560
|
-
protected delete(opts?: StatementOptions): pg$1.PgDeleteBase<PgTableWithColumns<EntityTableConfig>, any, undefined, undefined, false, never>;
|
|
1619
|
+
protected delete(opts?: StatementOptions): pg$1.PgDeleteBase<PgTableWithColumns<EntityTableConfig$1>, any, undefined, undefined, false, never>;
|
|
1561
1620
|
/**
|
|
1562
|
-
*
|
|
1621
|
+
* Create a Drizzle `select` query based on a JSON query object.
|
|
1563
1622
|
*
|
|
1564
|
-
*
|
|
1565
|
-
* @param opts The statement options.
|
|
1566
|
-
* @returns The found entities.
|
|
1623
|
+
* > This method is the base for `find`, `findOne`, `findById`, and `paginate`.
|
|
1567
1624
|
*/
|
|
1568
|
-
find(query?:
|
|
1625
|
+
find<R extends PgRelationMap<EntitySchema$1>>(query?: PgQueryRelations<EntitySchema$1, R>, opts?: StatementOptions): Promise<PgStatic<EntitySchema$1, R>[]>;
|
|
1569
1626
|
/**
|
|
1570
1627
|
* Find a single entity.
|
|
1628
|
+
*/
|
|
1629
|
+
findOne<R extends PgRelationMap<EntitySchema$1>>(query: Pick<PgQueryRelations<EntitySchema$1, R>, "with" | "where">, opts?: StatementOptions): Promise<PgStatic<EntitySchema$1, R>>;
|
|
1630
|
+
/**
|
|
1631
|
+
* Find entities with pagination.
|
|
1571
1632
|
*
|
|
1572
|
-
*
|
|
1573
|
-
*
|
|
1574
|
-
*
|
|
1633
|
+
* It uses the same parameters as `find()`, but adds pagination metadata to the response.
|
|
1634
|
+
*
|
|
1635
|
+
* > Pagination CAN also do a count query to get the total number of elements.
|
|
1575
1636
|
*/
|
|
1576
|
-
|
|
1637
|
+
paginate<R extends PgRelationMap<EntitySchema$1>>(pagination?: PageQuery, query?: PgQueryRelations<EntitySchema$1, R>, opts?: StatementOptions & {
|
|
1638
|
+
count?: boolean;
|
|
1639
|
+
}): Promise<Page<PgStatic<EntitySchema$1, R>>>;
|
|
1577
1640
|
/**
|
|
1578
1641
|
* Find an entity by ID.
|
|
1642
|
+
*
|
|
1643
|
+
* This is a convenience method for `findOne` with a where clause on the primary key.
|
|
1644
|
+
* If you need more complex queries, use `findOne` instead.
|
|
1579
1645
|
*/
|
|
1580
|
-
findById(id: string | number, opts?: StatementOptions): Promise<Static<EntitySchema>>;
|
|
1646
|
+
findById(id: string | number, opts?: StatementOptions): Promise<Static<EntitySchema$1>>;
|
|
1581
1647
|
/**
|
|
1582
|
-
*
|
|
1648
|
+
* Helper to create a type-safe query object.
|
|
1583
1649
|
*/
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
createQueryWhere(
|
|
1650
|
+
createQuery(): PgQuery<EntitySchema$1>;
|
|
1651
|
+
/**
|
|
1652
|
+
* Helper to create a type-safe where clause.
|
|
1653
|
+
*/
|
|
1654
|
+
createQueryWhere(): PgQueryWhere<EntitySchema$1>;
|
|
1589
1655
|
/**
|
|
1590
1656
|
* Create an entity.
|
|
1591
1657
|
*
|
|
@@ -1593,7 +1659,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1593
1659
|
* @param opts The options for creating the entity.
|
|
1594
1660
|
* @returns The ID of the created entity.
|
|
1595
1661
|
*/
|
|
1596
|
-
create(data: Static<TObjectInsert<EntitySchema>>, opts?: StatementOptions): Promise<Static<EntitySchema>>;
|
|
1662
|
+
create(data: Static<TObjectInsert<EntitySchema$1>>, opts?: StatementOptions): Promise<Static<EntitySchema$1>>;
|
|
1597
1663
|
/**
|
|
1598
1664
|
* Create many entities.
|
|
1599
1665
|
*
|
|
@@ -1601,11 +1667,11 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1601
1667
|
* @param opts The statement options.
|
|
1602
1668
|
* @returns The created entities.
|
|
1603
1669
|
*/
|
|
1604
|
-
createMany(values: Array<Static<TObjectInsert<EntitySchema>>>, opts?: StatementOptions): Promise<Static<EntitySchema>[]>;
|
|
1670
|
+
createMany(values: Array<Static<TObjectInsert<EntitySchema$1>>>, opts?: StatementOptions): Promise<Static<EntitySchema$1>[]>;
|
|
1605
1671
|
/**
|
|
1606
1672
|
* Find an entity and update it.
|
|
1607
1673
|
*/
|
|
1608
|
-
updateOne(where: PgQueryWhereOrSQL<EntitySchema>, data: Partial<Static<TObjectUpdate<EntitySchema>>>, opts?: StatementOptions): Promise<Static<EntitySchema>>;
|
|
1674
|
+
updateOne(where: PgQueryWhereOrSQL<EntitySchema$1>, data: Partial<Static<TObjectUpdate<EntitySchema$1>>>, opts?: StatementOptions): Promise<Static<EntitySchema$1>>;
|
|
1609
1675
|
/**
|
|
1610
1676
|
* Save a given entity.
|
|
1611
1677
|
*
|
|
@@ -1627,19 +1693,19 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1627
1693
|
* @see {@link PostgresTypeProvider#version}
|
|
1628
1694
|
* @see {@link PgVersionMismatchError}
|
|
1629
1695
|
*/
|
|
1630
|
-
save(entity: Static<EntitySchema>, opts?: StatementOptions): Promise<Static<EntitySchema>>;
|
|
1696
|
+
save(entity: Static<EntitySchema$1>, opts?: StatementOptions): Promise<Static<EntitySchema$1>>;
|
|
1631
1697
|
/**
|
|
1632
1698
|
* Find an entity by ID and update it.
|
|
1633
1699
|
*/
|
|
1634
|
-
updateById(id: string | number, data: Partial<Static<TObjectUpdate<EntitySchema>>>, opts?: StatementOptions): Promise<Static<EntitySchema>>;
|
|
1700
|
+
updateById(id: string | number, data: Partial<Static<TObjectUpdate<EntitySchema$1>>>, opts?: StatementOptions): Promise<Static<EntitySchema$1>>;
|
|
1635
1701
|
/**
|
|
1636
1702
|
* Find many entities and update all of them.
|
|
1637
1703
|
*/
|
|
1638
|
-
updateMany(where: PgQueryWhereOrSQL<EntitySchema>, data: Partial<Static<TObjectUpdate<EntitySchema>>>, opts?: StatementOptions): Promise<void>;
|
|
1704
|
+
updateMany(where: PgQueryWhereOrSQL<EntitySchema$1>, data: Partial<Static<TObjectUpdate<EntitySchema$1>>>, opts?: StatementOptions): Promise<void>;
|
|
1639
1705
|
/**
|
|
1640
1706
|
* Find many and delete all of them.
|
|
1641
1707
|
*/
|
|
1642
|
-
deleteMany(where?: PgQueryWhereOrSQL<EntitySchema>, opts?: StatementOptions): Promise<void>;
|
|
1708
|
+
deleteMany(where?: PgQueryWhereOrSQL<EntitySchema$1>, opts?: StatementOptions): Promise<void>;
|
|
1643
1709
|
/**
|
|
1644
1710
|
* Delete all entities.
|
|
1645
1711
|
*/
|
|
@@ -1649,11 +1715,11 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1649
1715
|
*
|
|
1650
1716
|
* You must fetch the entity first in order to delete it.
|
|
1651
1717
|
*/
|
|
1652
|
-
destroy(entity: Static<EntitySchema>, opts?: StatementOptions): Promise<void>;
|
|
1718
|
+
destroy(entity: Static<EntitySchema$1>, opts?: StatementOptions): Promise<void>;
|
|
1653
1719
|
/**
|
|
1654
1720
|
* Find an entity and delete it.
|
|
1655
1721
|
*/
|
|
1656
|
-
deleteOne(where?: PgQueryWhereOrSQL<EntitySchema>, opts?: StatementOptions): Promise<void>;
|
|
1722
|
+
deleteOne(where?: PgQueryWhereOrSQL<EntitySchema$1>, opts?: StatementOptions): Promise<void>;
|
|
1657
1723
|
/**
|
|
1658
1724
|
* Find an entity by ID and delete it.
|
|
1659
1725
|
*/
|
|
@@ -1661,87 +1727,45 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1661
1727
|
/**
|
|
1662
1728
|
* Count entities.
|
|
1663
1729
|
*/
|
|
1664
|
-
count(where?: PgQueryWhereOrSQL<EntitySchema>, opts?: StatementOptions): Promise<number>;
|
|
1730
|
+
count(where?: PgQueryWhereOrSQL<EntitySchema$1>, opts?: StatementOptions): Promise<number>;
|
|
1665
1731
|
protected conflictMessagePattern: string;
|
|
1666
1732
|
protected handleError(error: unknown, message: string): PgError;
|
|
1667
|
-
protected withDeletedAt(where: PgQueryWhereOrSQL<EntitySchema>, opts?: {
|
|
1733
|
+
protected withDeletedAt(where: PgQueryWhereOrSQL<EntitySchema$1>, opts?: {
|
|
1668
1734
|
force?: boolean;
|
|
1669
|
-
}): PgQueryWhereOrSQL<EntitySchema>;
|
|
1670
|
-
protected get organization(): undefined;
|
|
1735
|
+
}): PgQueryWhereOrSQL<EntitySchema$1>;
|
|
1671
1736
|
protected deletedAt(): PgAttrField | undefined;
|
|
1672
1737
|
/**
|
|
1673
|
-
* Convert
|
|
1674
|
-
*
|
|
1675
|
-
* @param query The query object.
|
|
1676
|
-
* @param schema The schema to use.
|
|
1677
|
-
* @param col The column to use.
|
|
1738
|
+
* Convert something to valid Pg Insert Value.
|
|
1678
1739
|
*/
|
|
1679
|
-
protected
|
|
1740
|
+
protected cast(data: any, insert: boolean): PgInsertValue<PgTableWithColumns<EntityTableConfig$1>>;
|
|
1680
1741
|
/**
|
|
1681
|
-
*
|
|
1742
|
+
* Transform a row from the database into a clean entity.
|
|
1682
1743
|
*
|
|
1683
|
-
*
|
|
1684
|
-
*
|
|
1685
|
-
*
|
|
1744
|
+
* - Validate against schema
|
|
1745
|
+
* - Replace all null values by undefined
|
|
1746
|
+
* - Fix date-time and date fields to ISO strings
|
|
1747
|
+
* - Cast BigInt to string
|
|
1686
1748
|
*/
|
|
1687
|
-
protected
|
|
1749
|
+
protected clean<T extends TObject = EntitySchema$1>(row: Record<string, unknown>, schema?: T): Static<T>;
|
|
1688
1750
|
/**
|
|
1689
|
-
*
|
|
1690
|
-
*
|
|
1691
|
-
* @param entities The entities to paginate.
|
|
1692
|
-
* @param limit The limit of the pagination.
|
|
1693
|
-
* @param offset The offset of the pagination.
|
|
1694
|
-
*/
|
|
1695
|
-
protected createPagination(entities: Static<EntitySchema>[], limit?: number, offset?: number): Page<Static<EntitySchema>>;
|
|
1696
|
-
/**
|
|
1697
|
-
* Convert something to valid Pg Insert Value.
|
|
1698
|
-
*/
|
|
1699
|
-
protected cast(data: any, insert: boolean): PgInsertValue<PgTableWithColumns<EntityTableConfig>>;
|
|
1700
|
-
/**
|
|
1701
|
-
* Clean a row. Remove all null values.
|
|
1702
|
-
*
|
|
1703
|
-
* @param row The row to clean.
|
|
1704
|
-
* @param schema The schema to use.
|
|
1705
|
-
* @returns The cleaned row.
|
|
1751
|
+
* Clean a row with joins recursively
|
|
1706
1752
|
*/
|
|
1707
|
-
protected
|
|
1753
|
+
protected cleanWithJoins<T extends TObject = EntitySchema$1>(row: Record<string, unknown>, schema: T, joins: PgJoin[], parentPath?: string): Static<T>;
|
|
1708
1754
|
/**
|
|
1709
|
-
*
|
|
1710
|
-
* Format: "firstName,-lastName" -> [{ column: "firstName", direction: "asc" }, { column: "lastName", direction: "desc" }]
|
|
1711
|
-
* - Columns separated by comma
|
|
1712
|
-
* - Prefix with '-' for DESC direction
|
|
1713
|
-
*
|
|
1714
|
-
* @param sort Pagination sort string
|
|
1715
|
-
* @returns OrderBy array or single object
|
|
1755
|
+
* Build a schema that includes all join properties recursively
|
|
1716
1756
|
*/
|
|
1717
|
-
protected
|
|
1718
|
-
column: string;
|
|
1719
|
-
direction: "asc" | "desc";
|
|
1720
|
-
}> | {
|
|
1721
|
-
column: string;
|
|
1722
|
-
direction: "asc" | "desc";
|
|
1723
|
-
};
|
|
1757
|
+
protected buildSchemaWithJoins(baseSchema: TObject, joins: PgJoin[], parentPath?: string): TObject;
|
|
1724
1758
|
/**
|
|
1725
|
-
*
|
|
1726
|
-
* Supports 3 modes:
|
|
1727
|
-
* 1. String: "name" -> [{ column: "name", direction: "asc" }]
|
|
1728
|
-
* 2. Object: { column: "name", direction: "desc" } -> [{ column: "name", direction: "desc" }]
|
|
1729
|
-
* 3. Array: [{ column: "name" }, { column: "age", direction: "desc" }] -> normalized array
|
|
1730
|
-
*
|
|
1731
|
-
* @param orderBy The orderBy parameter
|
|
1732
|
-
* @returns Normalized array of order by clauses
|
|
1759
|
+
* Convert a where clause to SQL.
|
|
1733
1760
|
*/
|
|
1734
|
-
protected
|
|
1735
|
-
column: string;
|
|
1736
|
-
direction: "asc" | "desc";
|
|
1737
|
-
}>;
|
|
1761
|
+
protected toSQL(where: PgQueryWhereOrSQL<EntitySchema$1>, joins?: PgJoin[]): SQL | undefined;
|
|
1738
1762
|
/**
|
|
1739
1763
|
* Get the where clause for an ID.
|
|
1740
1764
|
*
|
|
1741
1765
|
* @param id The ID to get the where clause for.
|
|
1742
1766
|
* @returns The where clause for the ID.
|
|
1743
1767
|
*/
|
|
1744
|
-
protected getWhereId(id: string | number):
|
|
1768
|
+
protected getWhereId(id: string | number): PgQueryWhere<EntitySchema$1>;
|
|
1745
1769
|
/**
|
|
1746
1770
|
* Find a primary key in the schema.
|
|
1747
1771
|
*
|
|
@@ -2164,7 +2188,7 @@ declare class SequenceDescriptor extends Descriptor<SequenceDescriptorOptions> {
|
|
|
2164
2188
|
* - Use appropriate isolation levels based on your consistency requirements
|
|
2165
2189
|
*/
|
|
2166
2190
|
declare const $transaction: <T extends any[], R>(opts: TransactionDescriptorOptions<T, R>) => _alepha_retry0.RetryDescriptorFn<(...args: T) => Promise<R>>;
|
|
2167
|
-
interface TransactionDescriptorOptions<T extends any[], R> {
|
|
2191
|
+
interface TransactionDescriptorOptions<T$1 extends any[], R$1> {
|
|
2168
2192
|
/**
|
|
2169
2193
|
* Transaction handler function that contains all database operations to be executed atomically.
|
|
2170
2194
|
*
|
|
@@ -2224,7 +2248,7 @@ interface TransactionDescriptorOptions<T extends any[], R> {
|
|
|
2224
2248
|
* }
|
|
2225
2249
|
* ```
|
|
2226
2250
|
*/
|
|
2227
|
-
handler: (tx: PgTransaction<any, any, any>, ...args: T) => Promise<R>;
|
|
2251
|
+
handler: (tx: PgTransaction<any, any, any>, ...args: T$1) => Promise<R$1>;
|
|
2228
2252
|
/**
|
|
2229
2253
|
* PostgreSQL transaction configuration options.
|
|
2230
2254
|
*
|
|
@@ -2503,7 +2527,7 @@ declare class PostgresTypeProvider {
|
|
|
2503
2527
|
* This is used to mark rows as deleted without actually removing them from the database.
|
|
2504
2528
|
* The column is nullable - NULL means not deleted, timestamp means deleted.
|
|
2505
2529
|
*/
|
|
2506
|
-
readonly deletedAt: (options?: TStringOptions) => PgAttr<
|
|
2530
|
+
readonly deletedAt: (options?: TStringOptions) => PgAttr<typebox0.TOptional<TString>, typeof PG_DELETED_AT>;
|
|
2507
2531
|
/**
|
|
2508
2532
|
* Creates a reference to another table or schema. Basically a foreign key.
|
|
2509
2533
|
*/
|
|
@@ -2525,7 +2549,7 @@ declare const pg: PostgresTypeProvider;
|
|
|
2525
2549
|
/**
|
|
2526
2550
|
* @deprecated Use `pg.primaryKey()` instead.
|
|
2527
2551
|
*/
|
|
2528
|
-
declare const legacyIdSchema: PgAttr<PgAttr<PgAttr<
|
|
2552
|
+
declare const legacyIdSchema: PgAttr<PgAttr<PgAttr<typebox0.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_SERIAL>, typeof PG_DEFAULT>;
|
|
2529
2553
|
//#endregion
|
|
2530
2554
|
//#region src/types/schema.d.ts
|
|
2531
2555
|
/**
|
|
@@ -2583,5 +2607,5 @@ declare const schema: <TDocument extends TSchema$1>(name: string, document: TDoc
|
|
|
2583
2607
|
*/
|
|
2584
2608
|
declare const AlephaPostgres: _alepha_core1.Service<_alepha_core1.Module<{}>>;
|
|
2585
2609
|
//#endregion
|
|
2586
|
-
export { $entity, $repository, $sequence, $transaction, AlephaPostgres, DrizzleKitProvider, Entity, EntityDescriptorOptions,
|
|
2610
|
+
export { $entity, $repository, $sequence, $transaction, AlephaPostgres, DrizzleKitProvider, Entity, EntityDescriptorOptions, FilterOperators, FromSchema, NodePostgresProvider, NodePostgresProviderOptions, OrderBy, OrderByClause, OrderDirection, PG_CREATED_AT, PG_DEFAULT, PG_DELETED_AT, PG_IDENTITY, PG_MANY, PG_ONE, PG_PRIMARY_KEY, PG_REF, PG_SCHEMA, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, Page, PageQuery, PgAttr, PgAttrField, PgConflictError, PgDefault, PgEntityNotFoundError, PgError, PgIdentityOptions, PgMany, PgManyOptions, PgMigrationError, PgOne, PgPrimaryKey, PgQuery, PgQueryRelations, PgQueryWhere, PgQueryWhereOrSQL, PgRef, PgRefOptions, PgRelation, PgRelationMap, PgStatic, PgSymbolKeys, PgSymbols, PgTableConfig, PgTableWithColumnsAndSchema, PgVersionMismatchError, PostgresProvider, PostgresTypeProvider, RepositoryDescriptor, RepositoryDescriptorOptions, RepositoryProvider, SQLLike, SequenceDescriptor, SequenceDescriptorOptions, StatementOptions, TObjectInsert, TObjectUpdate, TPage, TransactionContext, TransactionDescriptorOptions, camelToSnakeCase, drizzle_orm6 as drizzle, getAttrFields, insertSchema, legacyIdSchema, mapFieldToColumn, mapStringToColumn, pageQuerySchema, pageSchema, pg, pgAttr, schema, schemaToPgColumns, sql, updateSchema };
|
|
2587
2611
|
//# sourceMappingURL=index.d.ts.map
|