alepha 0.9.2 → 0.9.4

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/postgres.d.ts CHANGED
@@ -1,29 +1,17 @@
1
- import * as _alepha_core24 from "alepha";
2
- import * as _alepha_core0$1 from "alepha";
3
1
  import * as _alepha_core1 from "alepha";
4
- import * as _alepha_core0 from "alepha";
5
- import { Alepha, Descriptor, KIND, Service, Static, TObject, TSchema as TSchema$1 } from "alepha";
2
+ import { Alepha, AlephaError, Descriptor, KIND, Service, Static, TObject, TSchema as TSchema$1 } from "alepha";
6
3
  import * as drizzle_orm7 from "drizzle-orm";
7
- import * as drizzle_orm0$1 from "drizzle-orm";
8
- import * as drizzle_orm0 from "drizzle-orm";
9
- import * as drizzle from "drizzle-orm";
10
4
  import { BuildColumns, BuildExtraConfigColumns, SQL, SQLWrapper, TableConfig, sql } from "drizzle-orm";
11
5
  import * as pg$1 from "drizzle-orm/pg-core";
12
- import * as drizzle_orm_pg_core0$1 from "drizzle-orm/pg-core";
13
- import * as drizzle_orm_pg_core4 from "drizzle-orm/pg-core";
14
- import * as drizzle_orm_pg_core0 from "drizzle-orm/pg-core";
15
- import { AnyPgColumn, AnyPgTable, LockConfig, LockStrength, PgColumn, PgColumnBuilderBase, PgDatabase, PgInsertValue, PgSequenceOptions, PgTableExtraConfigValue, PgTableWithColumns, PgTransaction, PgTransactionConfig, TableConfig as TableConfig$1, UpdateDeleteAction } from "drizzle-orm/pg-core";
6
+ import { AnyPgColumn, LockConfig, LockStrength, PgColumn, PgColumnBuilderBase, PgDatabase, PgInsertValue, PgSequenceOptions, PgTableExtraConfigValue, PgTableWithColumns, PgTransaction, PgTransactionConfig, SelectedFields, TableConfig as TableConfig$1, UpdateDeleteAction } from "drizzle-orm/pg-core";
7
+ import { DateTimeProvider } from "alepha/datetime";
8
+ import * as _alepha_logger1 from "alepha/logger";
16
9
  import * as _alepha_lock0 from "alepha/lock";
17
10
  import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
18
11
  import postgres from "postgres";
19
12
  import * as _alepha_retry0 from "alepha/retry";
20
- import * as _sinclair_typebox9 from "@sinclair/typebox";
21
- import * as _sinclair_typebox16 from "@sinclair/typebox";
22
- import * as _sinclair_typebox17 from "@sinclair/typebox";
23
- import * as _sinclair_typebox18 from "@sinclair/typebox";
24
- import * as _sinclair_typebox6 from "@sinclair/typebox";
25
- import * as _sinclair_typebox0 from "@sinclair/typebox";
26
- import { Evaluate, IntegerOptions, Kind, NumberOptions, ObjectOptions, OptionalKind, Static as Static$1, StringOptions, TAdditionalProperties, TArray, TBoolean, TInteger, TIntersect, TObject as TObject$1, TOptional, TOptionalWithFlag, TPick, TProperties, TReadonly, TRecord, TSchema as TSchema$2 } from "@sinclair/typebox";
13
+ import * as _sinclair_typebox1 from "@sinclair/typebox";
14
+ import { Evaluate, IntegerOptions, Kind, NumberOptions, ObjectOptions, OptionalKind, Static as Static$1, StringOptions, TAdditionalProperties, TArray, TBoolean, TInteger, TIntersect, TNumber, TObject as TObject$1, TOptional, TOptionalWithFlag, TPick, TProperties, TReadonly, TRecord, TSchema as TSchema$2, TString } from "@sinclair/typebox";
27
15
  import { PgTransactionConfig as PgTransactionConfig$1 } from "drizzle-orm/pg-core/session";
28
16
  import * as DrizzleKit from "drizzle-kit/api";
29
17
  import { MigrationConfig } from "drizzle-orm/migrator";
@@ -32,24 +20,21 @@ export * from "drizzle-orm/pg-core";
32
20
 
33
21
  //#region src/constants/PG_SCHEMA.d.ts
34
22
  declare const PG_SCHEMA: unique symbol;
35
- //# sourceMappingURL=PG_SCHEMA.d.ts.map
36
23
  //#endregion
37
24
  //#region src/constants/PG_SYMBOLS.d.ts
38
25
  declare const PG_DEFAULT: unique symbol;
39
26
  declare const PG_PRIMARY_KEY: unique symbol;
40
27
  declare const PG_CREATED_AT: unique symbol;
41
28
  declare const PG_UPDATED_AT: unique symbol;
29
+ declare const PG_DELETED_AT: unique symbol;
42
30
  declare const PG_VERSION: unique symbol;
43
31
  declare const PG_IDENTITY: unique symbol;
44
- declare const PG_MANY: unique symbol;
45
- declare const PG_ONE: unique symbol;
46
32
  declare const PG_REF: unique symbol;
47
33
  /**
48
34
  * @deprecated Use `PG_IDENTITY` instead.
49
35
  */
50
36
  declare const PG_SERIAL: unique symbol;
51
37
  type PgDefault = typeof PG_DEFAULT;
52
- type PgMany = typeof PG_MANY;
53
38
  type PgRef = typeof PG_REF;
54
39
  type PgPrimaryKey = typeof PG_PRIMARY_KEY;
55
40
  type PgSymbols = {
@@ -57,10 +42,9 @@ type PgSymbols = {
57
42
  [PG_PRIMARY_KEY]: {};
58
43
  [PG_CREATED_AT]: {};
59
44
  [PG_UPDATED_AT]: {};
45
+ [PG_DELETED_AT]: {};
60
46
  [PG_VERSION]: {};
61
47
  [PG_IDENTITY]: PgIdentityOptions;
62
- [PG_MANY]: PgManyOptions;
63
- [PG_ONE]: PgManyOptions;
64
48
  [PG_REF]: PgRefOptions;
65
49
  /**
66
50
  * @deprecated Use `PG_IDENTITY` instead.
@@ -73,11 +57,6 @@ type PgIdentityOptions = {
73
57
  } & PgSequenceOptions & {
74
58
  name?: string;
75
59
  };
76
- interface PgManyOptions {
77
- table: AnyPgTable;
78
- schema: TObject$1;
79
- foreignKey: string;
80
- }
81
60
  interface PgRefOptions {
82
61
  ref: () => AnyPgColumn;
83
62
  actions?: {
@@ -85,7 +64,6 @@ interface PgRefOptions {
85
64
  onDelete?: UpdateDeleteAction;
86
65
  };
87
66
  }
88
- //# sourceMappingURL=PG_SYMBOLS.d.ts.map
89
67
  //#endregion
90
68
  //#region src/interfaces/TInsertObject.d.ts
91
69
  /**
@@ -112,7 +90,7 @@ type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProp
112
90
  //#endregion
113
91
  //#region src/helpers/schemaToPgColumns.d.ts
114
92
  /**
115
- * Convert a Typebox Schema to Drizzle ORM Postgres columns (yes)
93
+ * Convert a Typebox Schema to Drizzle ORM Postgres columns
116
94
  */
117
95
  declare const schemaToPgColumns: <T extends TObject>(schema: T) => FromSchema<T>;
118
96
  /**
@@ -122,7 +100,7 @@ declare const schemaToPgColumns: <T extends TObject>(schema: T) => FromSchema<T>
122
100
  * @param value The value of the field.
123
101
  * @returns The PG column.
124
102
  */
125
- declare const mapFieldToColumn: (name: string, value: TSchema$1) => pg$1.PgSerialBuilderInitial<string> | pg$1.PgIntegerBuilderInitial<string> | drizzle_orm7.IsIdentity<pg$1.PgBigInt53BuilderInitial<"">, "always"> | pg$1.PgNumericBuilderInitial<string> | pg$1.PgTimestampBuilderInitial<string> | pg$1.PgUUIDBuilderInitial<string> | pg$1.PgCustomColumnBuilder<{
103
+ declare const mapFieldToColumn: (name: string, value: TSchema$1) => pg$1.PgSerialBuilderInitial<string> | pg$1.PgIntegerBuilderInitial<string> | pg$1.PgBigInt53BuilderInitial<string> | pg$1.PgNumericBuilderInitial<string> | pg$1.PgTimestampBuilderInitial<string> | pg$1.PgUUIDBuilderInitial<string> | pg$1.PgCustomColumnBuilder<{
126
104
  name: string;
127
105
  dataType: "custom";
128
106
  columnType: "PgCustomColumn";
@@ -279,11 +257,30 @@ type PgTableWithColumnsAndSchema<T extends TableConfig, R extends TObject> = PgT
279
257
  interface TableLike<T extends TObject = TObject> {
280
258
  $schema: T;
281
259
  }
282
- //# sourceMappingURL=schemaToPgColumns.d.ts.map
283
260
  //#endregion
284
261
  //#region src/descriptors/$entity.d.ts
285
262
  /**
286
- * Creates a table descriptor for drizzle-orm.
263
+ * Declare a new entity in the database.
264
+ * This descriptor alone does not create the table, it only describes it.
265
+ * It must be used with `$repository` to create the table and perform operations on it.
266
+ *
267
+ * This is a convenience function to create a table with a json schema.
268
+ * For now, it creates a drizzle-orm table under the hood.
269
+ * ```ts
270
+ * import { $entity } from "alepha/postgres";
271
+ *
272
+ * const User = $entity({
273
+ * name: "user",
274
+ * schema: t.object({
275
+ * id: pg.primaryKey(t.uuid()),
276
+ * name: t.string(),
277
+ * email: t.string(),
278
+ * }),
279
+ * indexes: ["email"],
280
+ * });
281
+ * ```
282
+ *
283
+ * @stability 2
287
284
  */
288
285
  declare const $entity: {
289
286
  <TTableName extends string, TSchema extends TObject$1, TColumnsMap extends FromSchema<TSchema>>(options: EntityDescriptorOptions<TTableName, TSchema>): PgTableWithColumnsAndSchema<PgTableConfig<TTableName, TSchema, TColumnsMap>, TSchema>;
@@ -321,11 +318,6 @@ interface EntityDescriptorOptions<TTableName extends string, T extends TObject$1
321
318
  unique?: boolean;
322
319
  name?: string;
323
320
  })[];
324
- relations?: Record<string, {
325
- type: "one" | "many";
326
- table: () => any;
327
- foreignColumn?: keyof Static$1<T>;
328
- }>;
329
321
  foreignKeys?: Array<{
330
322
  name?: string;
331
323
  columns: Array<keyof Static$1<T>>;
@@ -346,25 +338,23 @@ interface EntityDescriptorOptions<TTableName extends string, T extends TObject$1
346
338
  config?: (self: BuildExtraConfigColumns<string, FromSchema<T>, "pg">) => PgTableExtraConfigValue[];
347
339
  }
348
340
  type Entity<T extends TObject$1> = PgTableWithColumnsAndSchema<PgTableConfig<string, T, FromSchema<T>>, T>;
349
- /**
350
- * Create a table with a json schema.
351
- *
352
- * @param name The name of the table.
353
- * @param schema The json schema of the table.
354
- * @param extraConfig Extra configuration for the table.
355
- */
356
- declare const pgTableSchema: <TTableName extends string, TSchema extends TObject$1, TColumnsMap extends FromSchema<TSchema>>(name: TTableName, schema: TSchema, extraConfig?: (self: BuildExtraConfigColumns<TTableName, TColumnsMap, "pg">) => PgTableExtraConfigValue[]) => PgTableWithColumnsAndSchema<PgTableConfig<TTableName, TSchema, TColumnsMap>, TSchema>;
357
341
  type PgTableConfig<TTableName extends string, TSchema extends TObject$1, TColumnsMap extends FromSchema<TSchema>> = {
358
342
  name: TTableName;
359
343
  schema: any;
360
344
  columns: BuildColumns<TTableName, TColumnsMap, "pg">;
361
345
  dialect: "pg";
362
346
  };
363
- //# sourceMappingURL=$entity.d.ts.map
347
+ //#endregion
348
+ //#region src/errors/PgError.d.ts
349
+ declare class PgError extends AlephaError {
350
+ name: string;
351
+ constructor(message: string, cause?: unknown);
352
+ }
364
353
  //#endregion
365
354
  //#region src/helpers/nullToUndefined.d.ts
366
355
  /**
367
356
  * Replaces all null values in an object with undefined.
357
+ * We need this for converting all nulls from Drizzle outputs.
368
358
  *
369
359
  * @param value - The object to be processed.
370
360
  * @return A new object with all null values replaced with undefined.
@@ -375,7 +365,18 @@ declare const nullToUndefined: <T extends object>(value: T) => NullToUndefined<T
375
365
  */
376
366
  type NullToUndefined<T> = T extends null ? undefined : T extends null | undefined | string | number | boolean | symbol | bigint | Function | Date | RegExp ? T : T extends Array<infer U> ? Array<NullToUndefined<U>> : T extends Map<infer K, infer V> ? Map<K, NullToUndefined<V>> : T extends Set<infer U> ? Set<NullToUndefined<U>> : T extends object ? { [K in keyof T]: NullToUndefined<T[K]> } : unknown;
377
367
  type NullifyIfOptional<T> = { [K in keyof T]: undefined extends T[K] ? T[K] | null : T[K] };
378
- //# sourceMappingURL=nullToUndefined.d.ts.map
368
+ //#endregion
369
+ //#region src/helpers/pgAttr.d.ts
370
+ /**
371
+ * Type representation.
372
+ */
373
+ type PgAttr<T extends TSchema$1, TAttr extends PgSymbolKeys> = T & { [K in TAttr]: PgSymbols[K] };
374
+ interface PgAttrField {
375
+ key: string;
376
+ type: TSchema$1;
377
+ data: any;
378
+ nested?: any[];
379
+ }
379
380
  //#endregion
380
381
  //#region src/interfaces/FilterOperators.d.ts
381
382
  interface FilterOperators<TValue> {
@@ -732,7 +733,6 @@ interface FilterOperators<TValue> {
732
733
  */
733
734
  arrayOverlaps?: TValue;
734
735
  }
735
- //# sourceMappingURL=FilterOperators.d.ts.map
736
736
  //#endregion
737
737
  //#region src/interfaces/InferInsert.d.ts
738
738
  /**
@@ -749,10 +749,10 @@ type StaticEntry<T extends TObject$1> = { [K in keyof T["properties"] as T["prop
749
749
  } | {
750
750
  [OptionalKind]: "Optional";
751
751
  } ? never : K]: Static$1<T["properties"][K]> };
752
- //# sourceMappingURL=InferInsert.d.ts.map
753
752
  //#endregion
754
753
  //#region src/interfaces/PgQueryWhere.d.ts
755
- type PgQueryWhere<T extends object> = { [Key in keyof T]?: FilterOperators<T[Key]> } & {
754
+ type PgQueryWhereOrSQL<T extends object> = SQLWrapper | PgQueryWhere<T>;
755
+ type PgQueryWhere<T extends object> = { [Key in keyof T]?: FilterOperators<T[Key]> | T[Key] } & {
756
756
  /**
757
757
  * Combine a list of conditions with the `and` operator. Conditions
758
758
  * that are equal `undefined` are automatically ignored.
@@ -769,7 +769,7 @@ type PgQueryWhere<T extends object> = { [Key in keyof T]?: FilterOperators<T[Key
769
769
  * )
770
770
  * ```
771
771
  */
772
- and?: Array<PgQueryWhere<T> | SQL>;
772
+ and?: Array<PgQueryWhereOrSQL<T>>;
773
773
  /**
774
774
  * Combine a list of conditions with the `or` operator. Conditions
775
775
  * that are equal `undefined` are automatically ignored.
@@ -786,7 +786,7 @@ type PgQueryWhere<T extends object> = { [Key in keyof T]?: FilterOperators<T[Key
786
786
  * )
787
787
  * ```
788
788
  */
789
- or?: Array<PgQueryWhere<T> | SQL>;
789
+ or?: Array<PgQueryWhereOrSQL<T>>;
790
790
  /**
791
791
  * Negate the meaning of an expression using the `not` keyword.
792
792
  *
@@ -798,7 +798,7 @@ type PgQueryWhere<T extends object> = { [Key in keyof T]?: FilterOperators<T[Key
798
798
  * .where(not(inArray(cars.make, ['GM', 'Ford'])))
799
799
  * ```
800
800
  */
801
- not?: PgQueryWhere<T>;
801
+ not?: PgQueryWhereOrSQL<T>;
802
802
  /**
803
803
  * Test whether a subquery evaluates to have any rows.
804
804
  *
@@ -821,36 +821,18 @@ type PgQueryWhere<T extends object> = { [Key in keyof T]?: FilterOperators<T[Key
821
821
  */
822
822
  exists?: SQLWrapper;
823
823
  };
824
- //# sourceMappingURL=PgQueryWhere.d.ts.map
825
824
  //#endregion
826
825
  //#region src/interfaces/PgQuery.d.ts
827
826
  interface PgQuery<T extends TObject$1, Select extends (keyof Static$1<T>)[] = []> {
828
827
  columns?: Select;
829
828
  distinct?: boolean;
830
- where?: PgQueryWhereWithMany<T> | SQLWrapper;
829
+ where?: PgQueryWhereOrSQL<Static$1<T>>;
831
830
  limit?: number;
832
831
  offset?: number;
833
832
  sort?: { [key in keyof Static$1<T>]?: "asc" | "desc" };
834
833
  groupBy?: (keyof Static$1<T>)[];
835
- relations?: PgQueryWithMap<T>;
836
834
  }
837
835
  type PgQueryResult<T extends TObject$1, Select extends (keyof Static$1<T>)[]> = TPick<T, Select>;
838
- type PgQueryWhereWithMany<T extends TObject$1> = PgQueryWhere<Static$1<RemoveManyRelations<T>>> & ExtractManyRelations<T>;
839
- type ExtractManyRelations<T extends TObject$1> = { [K in keyof T["properties"] as T["properties"][K] extends {
840
- [PG_MANY]: any;
841
- } ? T["properties"][K] extends TArray ? T["properties"][K]["items"] extends TObject$1 ? K : never : never : never]?: PgQueryWhere<Static$1<T["properties"][K]["items"]>> };
842
- type RemoveManyRelations<T extends TObject$1> = TObject$1<{ [K in keyof T["properties"] as T["properties"][K] extends {
843
- [PG_MANY]: any;
844
- } ? never : K]: T["properties"][K] }>;
845
- type PgQueryWithMap<T extends TObject$1> = { [K in keyof T["properties"] as T["properties"][K] extends {
846
- [PG_MANY]: any;
847
- } ? K : never]?: T["properties"][K] extends TObject$1 ? PgQueryWith<T["properties"][K]> : T["properties"][K] extends TArray ? PgQueryWith<T["properties"][K]> : never };
848
- type PgQueryWith<T extends TObject$1 | TArray> = true | {
849
- relations?: {
850
- [key: string]: PgQueryWith<T>;
851
- };
852
- };
853
- //# sourceMappingURL=PgQuery.d.ts.map
854
836
  //#endregion
855
837
  //#region src/providers/drivers/PostgresProvider.d.ts
856
838
  type SQLLike = SQLWrapper | string;
@@ -860,18 +842,15 @@ declare abstract class PostgresProvider {
860
842
  abstract get schema(): string;
861
843
  abstract get dialect(): string;
862
844
  abstract execute<T extends TObject$1 = any>(query: SQLLike, schema?: T): Promise<Array<T extends TObject$1 ? Static$1<T> : any>>;
863
- mapResult<T extends TObject$1 = any>(result: Array<any>, schema?: T): Array<T extends TObject$1 ? Static$1<T> : any>;
864
845
  }
865
- //# sourceMappingURL=PostgresProvider.d.ts.map
866
846
  //#endregion
867
847
  //#region src/schemas/pageQuerySchema.d.ts
868
- declare const pageQuerySchema: _sinclair_typebox9.TObject<{
869
- page: _sinclair_typebox9.TOptional<_sinclair_typebox9.TNumber>;
870
- size: _sinclair_typebox9.TOptional<_sinclair_typebox9.TNumber>;
871
- sort: _sinclair_typebox9.TOptional<_sinclair_typebox9.TString>;
848
+ declare const pageQuerySchema: _sinclair_typebox1.TObject<{
849
+ page: _sinclair_typebox1.TOptional<_sinclair_typebox1.TNumber>;
850
+ size: _sinclair_typebox1.TOptional<_sinclair_typebox1.TNumber>;
851
+ sort: _sinclair_typebox1.TOptional<_sinclair_typebox1.TString>;
872
852
  }>;
873
853
  type PageQuery = Static<typeof pageQuerySchema>;
874
- //# sourceMappingURL=pageQuerySchema.d.ts.map
875
854
  //#endregion
876
855
  //#region src/schemas/pageSchema.d.ts
877
856
  /**
@@ -909,11 +888,10 @@ type Page<T> = {
909
888
  countDuration?: number;
910
889
  };
911
890
  };
912
- //# sourceMappingURL=pageSchema.d.ts.map
913
891
  //#endregion
914
892
  //#region src/descriptors/$repository.d.ts
915
893
  /**
916
- *
894
+ * @stability 3
917
895
  */
918
896
  declare const $repository: {
919
897
  <EntityTableConfig extends TableConfig, EntitySchema extends TObject$1>(optionsOrTable: RepositoryDescriptorOptions<EntityTableConfig, EntitySchema> | PgTableWithColumnsAndSchema<EntityTableConfig, EntitySchema>): RepositoryDescriptor<EntityTableConfig, EntitySchema>;
@@ -930,13 +908,11 @@ interface RepositoryDescriptorOptions<EntityTableConfig extends TableConfig, Ent
930
908
  provider?: Service<PostgresProvider>;
931
909
  }
932
910
  declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, EntitySchema extends TObject$1> extends Descriptor<RepositoryDescriptorOptions<EntityTableConfig, EntitySchema>> {
911
+ protected readonly dateTimeProvider: DateTimeProvider;
933
912
  readonly provider: PostgresProvider;
934
913
  protected readonly alepha: Alepha;
935
914
  readonly schema: EntitySchema;
936
- readonly insertSchema: TInsertObject<EntitySchema>;
937
- protected readonly env: {
938
- POSTGRES_PAGINATION_COUNT_ENABLED: boolean;
939
- };
915
+ readonly schemaInsert: TInsertObject<EntitySchema>;
940
916
  /**
941
917
  * Represents the primary key of the table.
942
918
  * - Key is the name of the primary key column.
@@ -960,15 +936,11 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
960
936
  /**
961
937
  * Getter for the database connection from the database provider.
962
938
  */
963
- protected get db(): PgDatabase<any, Record<string, never>, drizzle_orm0$1.ExtractTablesWithRelations<Record<string, never>>>;
964
- protected organization(): PgColumn;
939
+ protected get db(): PgDatabase<any, Record<string, never>, drizzle_orm7.ExtractTablesWithRelations<Record<string, never>>>;
965
940
  /**
966
941
  * Execute a SQL query.
967
- *
968
- * @param query
969
- * @param schema
970
942
  */
971
- execute<T extends TObject$1 = EntitySchema>(query: SQLLike | ((table: PgTableWithColumns<EntityTableConfig>, db: PgDatabase<any>) => SQLLike), schema?: T): Promise<Static$1<T>[]>;
943
+ query<T extends TObject$1 = EntitySchema>(query: SQLLike | ((table: PgTableWithColumns<EntityTableConfig>, db: PgDatabase<any>) => SQLLike), schema?: T): Promise<Static$1<T>[]>;
972
944
  /**
973
945
  * Get a Drizzle column from the table by his name.
974
946
  *
@@ -988,29 +960,34 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
988
960
  *
989
961
  * @returns The SELECT query builder.
990
962
  */
991
- protected select(opts?: StatementOptions): drizzle_orm_pg_core0$1.PgSelectBase<string, Record<string, PgColumn<drizzle_orm0$1.ColumnBaseConfig<drizzle_orm0$1.ColumnDataType, string>, {}, {}>>, "single", Record<string, "not-null">, false, never, {
963
+ protected select(opts?: StatementOptions): pg$1.PgSelectBase<string, Record<string, PgColumn<drizzle_orm7.ColumnBaseConfig<drizzle_orm7.ColumnDataType, string>, {}, {}>>, "single", Record<string, "not-null">, false, never, {
992
964
  [x: string]: unknown;
993
965
  }[], {
994
- [x: string]: PgColumn<drizzle_orm0$1.ColumnBaseConfig<drizzle_orm0$1.ColumnDataType, string>, {}, {}>;
966
+ [x: string]: PgColumn<drizzle_orm7.ColumnBaseConfig<drizzle_orm7.ColumnDataType, string>, {}, {}>;
967
+ }>;
968
+ protected selectDistinct(opts: StatementOptions | undefined, fields: SelectedFields): pg$1.PgSelectBase<string, SelectedFields, "partial", Record<string, "not-null">, false, never, {
969
+ [x: string]: unknown;
970
+ }[], {
971
+ [x: string]: never;
995
972
  }>;
996
973
  /**
997
974
  * Start an INSERT query on the table.
998
975
  *
999
976
  * @returns The INSERT query builder.
1000
977
  */
1001
- protected insert(opts?: StatementOptions): drizzle_orm_pg_core0$1.PgInsertBuilder<PgTableWithColumns<EntityTableConfig>, any, false>;
978
+ protected insert(opts?: StatementOptions): pg$1.PgInsertBuilder<PgTableWithColumns<EntityTableConfig>, any, false>;
1002
979
  /**
1003
980
  * Start an UPDATE query on the table.
1004
981
  *
1005
982
  * @returns The UPDATE query builder.
1006
983
  */
1007
- protected update(opts?: StatementOptions): drizzle_orm_pg_core0$1.PgUpdateBuilder<PgTableWithColumns<EntityTableConfig>, any>;
984
+ protected update(opts?: StatementOptions): pg$1.PgUpdateBuilder<PgTableWithColumns<EntityTableConfig>, any>;
1008
985
  /**
1009
986
  * Start a DELETE query on the table.
1010
987
  *
1011
988
  * @returns The DELETE query builder.
1012
989
  */
1013
- protected delete(opts?: StatementOptions): drizzle_orm_pg_core0$1.PgDeleteBase<PgTableWithColumns<EntityTableConfig>, any, undefined, undefined, false, never>;
990
+ protected delete(opts?: StatementOptions): pg$1.PgDeleteBase<PgTableWithColumns<EntityTableConfig>, any, undefined, undefined, false, never>;
1014
991
  /**
1015
992
  * Find entities.
1016
993
  *
@@ -1029,20 +1006,14 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
1029
1006
  findOne<T extends Static$1<EntitySchema> = Static$1<EntitySchema>>(where: PgQueryWhere<T>, opts?: StatementOptions): Promise<Static$1<EntitySchema>>;
1030
1007
  /**
1031
1008
  * Find an entity by ID.
1032
- *
1033
- * @param id
1034
- * @param opts
1035
1009
  */
1036
1010
  findById(id: string | number, opts?: StatementOptions): Promise<Static$1<EntitySchema>>;
1037
1011
  /**
1038
1012
  * Paginate entities.
1039
- *
1040
- * @param pageQuery The pagination query.
1041
- * @param findQuery The find query.
1042
- * @param opts The statement options.
1043
- * @returns The paginated entities.
1044
1013
  */
1045
- paginate(pageQuery?: PageQuery, findQuery?: PgQuery<EntitySchema>, opts?: StatementOptions): Promise<Page<Static$1<EntitySchema>>>;
1014
+ paginate(pagination?: PageQuery, query?: PgQuery<EntitySchema>, opts?: StatementOptions & {
1015
+ skipCount?: boolean;
1016
+ }): Promise<Page<Static$1<EntitySchema>>>;
1046
1017
  createQuery(query?: PgQuery<EntitySchema>): PgQuery<EntitySchema>;
1047
1018
  createQueryWhere(where?: PgQueryWhere<Static$1<EntitySchema>>): PgQueryWhere<Static$1<EntitySchema>>;
1048
1019
  /**
@@ -1062,61 +1033,72 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
1062
1033
  */
1063
1034
  createMany(values: Array<InferInsert<EntitySchema>>, opts?: StatementOptions): Promise<Static$1<EntitySchema>[]>;
1064
1035
  /**
1065
- * Update an entity.
1066
- *
1067
- * @param query The where clause.
1068
- * @param data The data to update.
1069
- * @param opts The statement options.
1070
- * @returns The updated entity.
1036
+ * Find an entity and update it.
1071
1037
  */
1072
- updateOne(query: PgQueryWhere<Static$1<EntitySchema>>, data: Partial<NullifyIfOptional<Static$1<EntitySchema>>> | {
1073
- $append: Partial<NullifyIfOptional<Static$1<EntitySchema>>>;
1074
- }, opts?: StatementOptions): Promise<Static$1<EntitySchema>>;
1075
- save(data: InferInsert<EntitySchema>, opts?: StatementOptions): Promise<Static$1<EntitySchema>>;
1038
+ updateOne(where: PgQueryWhereOrSQL<Static$1<EntitySchema>>, data: Partial<NullifyIfOptional<Static$1<EntitySchema>>>, opts?: StatementOptions): Promise<Static$1<EntitySchema>>;
1076
1039
  /**
1077
- * Update an entity by ID.
1040
+ * Save a given entity.
1041
+ *
1042
+ * @example
1043
+ * ```ts
1044
+ * const entity = await repository.findById(1);
1045
+ * entity.name = "New Name";
1046
+ * await repository.save(entity);
1047
+ * ```
1048
+ *
1049
+ * Difference with `updateById/updateOne`:
1050
+ *
1051
+ * - requires the entity to be fetched first
1052
+ * - check pg.version() if present - optimistic locking
1053
+ * - validate entity against schema
1078
1054
  *
1079
- * @param id
1080
- * @param data
1081
- * @param opts
1055
+ * @see {@link PostgresTypeProvider#version}
1056
+ * @see {@link PgVersionMismatchError}
1057
+ */
1058
+ save(entity: Static$1<EntitySchema>, opts?: StatementOptions): Promise<Static$1<EntitySchema>>;
1059
+ /**
1060
+ * Find an entity by ID and update it.
1082
1061
  */
1083
1062
  updateById(id: string | number, data: Partial<NullifyIfOptional<Static$1<EntitySchema>>>, opts?: StatementOptions): Promise<Static$1<EntitySchema>>;
1084
1063
  /**
1085
- * Update entities.
1086
- *
1087
- * @param where The where clause.
1088
- * @param data The data to update.
1089
- * @param opts The statement options.
1090
- * @returns The updated entities.
1064
+ * Find many entities and update all of them.
1091
1065
  */
1092
- updateMany(where: PgQueryWhere<Static$1<EntitySchema>>, data: Partial<NullifyIfOptional<Static$1<EntitySchema>>>, opts?: StatementOptions): Promise<Static$1<EntitySchema>[]>;
1066
+ updateMany(where: PgQueryWhereOrSQL<Static$1<EntitySchema>>, data: Partial<NullifyIfOptional<Static$1<EntitySchema>>>, opts?: StatementOptions): Promise<void>;
1093
1067
  /**
1094
- * Delete entities.
1095
- *
1096
- * @param where Query.
1097
- * @param opts The statement options.
1068
+ * Find many and delete all of them.
1098
1069
  */
1099
1070
  deleteMany(where?: PgQueryWhere<Static$1<EntitySchema>>, opts?: StatementOptions): Promise<void>;
1100
1071
  /**
1101
1072
  * Delete all entities.
1102
- * @param opts
1103
1073
  */
1104
1074
  clear(opts?: StatementOptions): Promise<void>;
1105
1075
  /**
1106
- * Delete an entity by ID.
1076
+ * Delete the given entity.
1107
1077
  *
1108
- * @param id
1109
- * @param opts
1078
+ * You must fetch the entity first in order to delete it.
1079
+ */
1080
+ destroy(entity: Static$1<EntitySchema>, opts?: StatementOptions): Promise<void>;
1081
+ /**
1082
+ * Find an entity and delete it.
1083
+ */
1084
+ deleteOne(where?: PgQueryWhere<Static$1<EntitySchema>>, opts?: StatementOptions): Promise<void>;
1085
+ /**
1086
+ * Find an entity by ID and delete it.
1110
1087
  */
1111
1088
  deleteById(id: string | number, opts?: StatementOptions): Promise<void>;
1112
1089
  /**
1113
1090
  * Count entities.
1114
- *
1115
- * @param where The where clause.
1116
- * @param opts The statement options.
1117
- * @returns The count of entities.
1118
1091
  */
1119
- count(where?: PgQueryWhere<Static$1<EntitySchema>>, opts?: StatementOptions): Promise<number>;
1092
+ count(where?: PgQueryWhereOrSQL<Static$1<EntitySchema>>, opts?: StatementOptions): Promise<number>;
1093
+ protected conflictMessagePattern: string;
1094
+ protected handleError(error: unknown, message: string): PgError;
1095
+ protected withDeletedAt(where: PgQueryWhereOrSQL<Static$1<EntitySchema>>, opts?: {
1096
+ force?: boolean;
1097
+ }): PgQueryWhereOrSQL<(EntitySchema & {
1098
+ params: [];
1099
+ })["static"]>;
1100
+ protected get organization(): undefined;
1101
+ protected deletedAt(): PgAttrField | undefined;
1120
1102
  /**
1121
1103
  * Convert a query object to a SQL query.
1122
1104
  *
@@ -1124,7 +1106,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
1124
1106
  * @param schema The schema to use.
1125
1107
  * @param col The column to use.
1126
1108
  */
1127
- protected jsonQueryToSql(query: PgQueryWhere<Static$1<EntitySchema>>, schema?: TObject$1, col?: (key: string) => PgColumn): SQL | undefined;
1109
+ protected jsonQueryToSql(query: PgQueryWhereOrSQL<Static$1<EntitySchema>>, schema?: TObject$1, col?: (key: string) => PgColumn): SQL | undefined;
1128
1110
  /**
1129
1111
  * Map a filter operator to a SQL query.
1130
1112
  *
@@ -1132,7 +1114,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
1132
1114
  * @param column
1133
1115
  * @protected
1134
1116
  */
1135
- protected mapOperatorToSql(operator: FilterOperators<any>, column: PgColumn): SQL | undefined;
1117
+ protected mapOperatorToSql(operator: FilterOperators<any> | any, column: PgColumn): SQL | undefined;
1136
1118
  /**
1137
1119
  * Create a pagination object.
1138
1120
  *
@@ -1168,7 +1150,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
1168
1150
  */
1169
1151
  protected getPrimaryKey(schema: TObject$1): {
1170
1152
  key: string;
1171
- col: PgColumn<drizzle_orm0$1.ColumnBaseConfig<drizzle_orm0$1.ColumnDataType, string>, {}, {}>;
1153
+ col: PgColumn<drizzle_orm7.ColumnBaseConfig<drizzle_orm7.ColumnDataType, string>, {}, {}>;
1172
1154
  type: TSchema$2;
1173
1155
  };
1174
1156
  }
@@ -1188,23 +1170,15 @@ interface StatementOptions {
1188
1170
  strength: LockStrength;
1189
1171
  };
1190
1172
  /**
1191
- * Organization ID.
1192
- *
1193
- * Multi-tenant support.
1194
- *
1195
- * If set, it will be used to filter the results by organization.
1173
+ * If true, ignore soft delete.
1196
1174
  */
1197
- organization?: string;
1198
- }
1199
- interface PgAttrField {
1200
- key: string;
1201
- type: TSchema$2;
1202
- data: any;
1203
- nested?: any[];
1175
+ force?: boolean;
1204
1176
  }
1205
- //# sourceMappingURL=$repository.d.ts.map
1206
1177
  //#endregion
1207
1178
  //#region src/descriptors/$sequence.d.ts
1179
+ /**
1180
+ * @stability 1
1181
+ */
1208
1182
  declare const $sequence: {
1209
1183
  (options?: SequenceDescriptorOptions): SequenceDescriptor;
1210
1184
  [KIND]: typeof SequenceDescriptor;
@@ -1225,11 +1199,10 @@ declare class SequenceDescriptor extends Descriptor<SequenceDescriptorOptions> {
1225
1199
  next(): Promise<number>;
1226
1200
  current(): Promise<number>;
1227
1201
  }
1228
- //# sourceMappingURL=$sequence.d.ts.map
1229
1202
  //#endregion
1230
1203
  //#region src/descriptors/$transaction.d.ts
1231
1204
  /**
1232
- *
1205
+ * @stability 2
1233
1206
  */
1234
1207
  declare const $transaction: <T extends any[], R>(opts: TransactionDescriptorOptions<T, R>) => _alepha_retry0.RetryDescriptorFn<(...args: T) => Promise<R>>;
1235
1208
  interface TransactionDescriptorOptions<T extends any[], R> {
@@ -1237,23 +1210,19 @@ interface TransactionDescriptorOptions<T extends any[], R> {
1237
1210
  config?: PgTransactionConfig$1;
1238
1211
  }
1239
1212
  type TransactionContext = PgTransaction<any, any, any>;
1240
- //# sourceMappingURL=$transaction.d.ts.map
1241
1213
  //#endregion
1242
- //#region src/errors/EntityNotFoundError.d.ts
1243
- declare class EntityNotFoundError extends Error {
1244
- readonly code = "ERR_RESOURCE_NOTFOUND";
1214
+ //#region src/errors/PgEntityNotFoundError.d.ts
1215
+ declare class PgEntityNotFoundError extends PgError {
1216
+ readonly name = "EntityNotFoundError";
1245
1217
  readonly status = 404;
1246
1218
  constructor(entityName: string);
1247
1219
  }
1248
- //# sourceMappingURL=EntityNotFoundError.d.ts.map
1249
1220
  //#endregion
1250
- //#region src/providers/RepositoryDescriptorProvider.d.ts
1251
- declare class RepositoryDescriptorProvider {
1252
- protected readonly log: _alepha_core24.Logger;
1221
+ //#region src/providers/RepositoryProvider.d.ts
1222
+ declare class RepositoryProvider {
1223
+ protected readonly log: _alepha_logger1.Logger;
1253
1224
  protected readonly alepha: Alepha;
1254
- get repositories(): RepositoryDescriptor<TableConfig$1, TObject$1>[];
1255
- constructor();
1256
- clearRepositories(): Promise<void>;
1225
+ protected get repositories(): RepositoryDescriptor<TableConfig$1, TObject$1>[];
1257
1226
  /**
1258
1227
  * Get all repositories.
1259
1228
  *
@@ -1265,20 +1234,20 @@ declare class RepositoryDescriptorProvider {
1265
1234
  *
1266
1235
  * @param provider
1267
1236
  */
1268
- getTables(provider?: PostgresProvider): drizzle_orm_pg_core4.PgTableWithColumns<TableConfig$1>[];
1237
+ getTables(provider?: PostgresProvider): pg$1.PgTableWithColumns<TableConfig$1>[];
1269
1238
  /**
1270
- * Get all providers from the repositories.
1239
+ * Get all pg providers from the repositories.
1271
1240
  */
1272
1241
  getProviders(): PostgresProvider[];
1273
1242
  }
1274
- //# sourceMappingURL=RepositoryDescriptorProvider.d.ts.map
1275
1243
  //#endregion
1276
1244
  //#region src/providers/DrizzleKitProvider.d.ts
1277
1245
  declare class DrizzleKitProvider {
1278
- protected readonly log: _alepha_core0$1.Logger;
1246
+ protected readonly log: _alepha_logger1.Logger;
1279
1247
  protected readonly alepha: Alepha;
1280
- protected readonly repositoryProvider: RepositoryDescriptorProvider;
1248
+ protected readonly repositoryProvider: RepositoryProvider;
1281
1249
  push(provider: PostgresProvider, schema?: string): Promise<void>;
1250
+ setPgSchema(provider: PostgresProvider): Promise<void>;
1282
1251
  /**
1283
1252
  * Try to generate migrations from scratch based on the models.
1284
1253
  * Then, execute the migrations.
@@ -1307,146 +1276,106 @@ declare class DrizzleKitProvider {
1307
1276
  */
1308
1277
  protected importDrizzleKit(): Promise<typeof DrizzleKit>;
1309
1278
  }
1310
- //# sourceMappingURL=DrizzleKitProvider.d.ts.map
1311
1279
  //#endregion
1312
1280
  //#region src/providers/drivers/NodePostgresProvider.d.ts
1313
1281
  declare module "alepha" {
1314
1282
  interface Env extends Partial<Static<typeof envSchema>> {}
1315
1283
  }
1316
1284
  declare const envSchema: TObject$1<{
1317
- PG_HOST: _alepha_core1.TOptional<_alepha_core1.TString>;
1318
- PG_USERNAME: _alepha_core1.TOptional<_alepha_core1.TString>;
1319
- PG_DATABASE: _alepha_core1.TOptional<_alepha_core1.TString>;
1320
- PG_PASSWORD: _alepha_core1.TOptional<_alepha_core1.TString>;
1321
- PG_PORT: _alepha_core1.TOptional<_alepha_core1.TNumber>;
1285
+ /**
1286
+ * Main configuration for database connection.
1287
+ * Accept a string in the format of a Postgres connection URL.
1288
+ * Example: postgres://user:password@localhost:5432/database
1289
+ * or
1290
+ * Example: postgres://user:password@localhost:5432/database?sslmode=require
1291
+ */
1322
1292
  DATABASE_URL: _alepha_core1.TOptional<_alepha_core1.TString>;
1323
- DATABASE_MIGRATIONS_FOLDER: _alepha_core1.TString;
1324
1293
  /**
1325
- * The schema to use.
1326
- * Accept a string.
1294
+ * In addition to the DATABASE_URL, you can specify the postgres schema name.
1295
+ *
1296
+ * It will monkey patch drizzle tables.
1327
1297
  */
1328
1298
  POSTGRES_SCHEMA: _alepha_core1.TOptional<_alepha_core1.TString>;
1329
1299
  /**
1330
1300
  * Synchronize the database schema with the models.
1331
- * Accept a boolean or a postgres schema name.
1301
+ * It uses a custom implementation, it's not related to `drizzle-kit push` command.
1302
+ * It will generate the migration script and save it to the DB.
1303
+ *
1304
+ * This is recommended for development and testing purposes only.
1332
1305
  *
1333
1306
  * @default false
1334
1307
  */
1335
1308
  POSTGRES_SYNCHRONIZE: _alepha_core1.TOptional<_alepha_core1.TBoolean>;
1336
1309
  /**
1337
1310
  * Push the schema to the database.
1311
+ * It's like `drizzle-kit push` command.
1312
+ * It will introspect the models from DB and generate the SQL statements to create or update the tables.
1338
1313
  *
1339
1314
  * @default false
1340
1315
  */
1341
- POSTGRES_PUSH_SCHEMA: _alepha_core1.TOptional<_alepha_core1.TBoolean>;
1342
- /**
1343
- * Reject unauthorized SSL connections.
1344
- *
1345
- * @default false
1346
- */
1347
- POSTGRES_REJECT_UNAUTHORIZED: _alepha_core1.TBoolean;
1316
+ POSTGRES_PUSH: _alepha_core1.TOptional<_alepha_core1.TBoolean>;
1348
1317
  }>;
1349
- interface NodePostgresProviderState {
1350
- client: postgres.Sql;
1351
- db: PostgresJsDatabase;
1318
+ interface NodePostgresProviderOptions {
1319
+ migrations: MigrationConfig;
1320
+ connection: postgres.Options<any>;
1352
1321
  }
1353
1322
  declare class NodePostgresProvider extends PostgresProvider {
1354
1323
  readonly dialect = "postgres";
1355
- protected readonly log: _alepha_core1.Logger;
1324
+ protected readonly sslModes: readonly ["require", "allow", "prefer", "verify-full"];
1325
+ protected readonly log: _alepha_logger1.Logger;
1356
1326
  protected readonly env: {
1357
- PG_HOST?: string | undefined;
1358
- PG_USERNAME?: string | undefined;
1359
- PG_DATABASE?: string | undefined;
1360
- PG_PASSWORD?: string | undefined;
1361
- PG_PORT?: number | undefined;
1362
1327
  DATABASE_URL?: string | undefined;
1363
1328
  POSTGRES_SCHEMA?: string | undefined;
1364
1329
  POSTGRES_SYNCHRONIZE?: boolean | undefined;
1365
- POSTGRES_PUSH_SCHEMA?: boolean | undefined;
1366
- DATABASE_MIGRATIONS_FOLDER: string;
1367
- POSTGRES_REJECT_UNAUTHORIZED: boolean;
1330
+ POSTGRES_PUSH?: boolean | undefined;
1368
1331
  };
1369
1332
  protected readonly alepha: Alepha;
1370
1333
  protected readonly kit: DrizzleKitProvider;
1371
- protected state?: NodePostgresProviderState;
1334
+ protected client?: postgres.Sql;
1335
+ protected pg?: PostgresJsDatabase;
1336
+ readonly options: NodePostgresProviderOptions;
1372
1337
  /**
1373
1338
  * In testing mode, the schema name will be generated and deleted after the test.
1374
1339
  */
1375
- protected testingSchemaName?: string;
1376
- get db(): PostgresJsDatabase;
1377
- protected readonly configure: _alepha_core1.HookDescriptor<"start">;
1378
- protected readonly stop: _alepha_core1.HookDescriptor<"stop">;
1340
+ protected schemaForTesting?: string;
1379
1341
  /**
1380
1342
  * Get Postgres schema.
1381
1343
  */
1382
1344
  get schema(): string;
1345
+ get db(): PostgresJsDatabase;
1346
+ protected readonly configure: _alepha_core1.HookDescriptor<"start">;
1347
+ protected readonly stop: _alepha_core1.HookDescriptor<"stop">;
1383
1348
  execute<T extends TObject$1 = any>(query: SQLLike, schema?: T): Promise<Array<T extends TObject$1 ? Static<T> : any>>;
1384
1349
  connect(): Promise<void>;
1385
1350
  close(): Promise<void>;
1386
1351
  protected migrate: _alepha_lock0.LockDescriptor<() => Promise<void>>;
1387
- protected createClient(): NodePostgresProviderState;
1352
+ protected createClient(): {
1353
+ client: postgres.Sql<{}>;
1354
+ db: PostgresJsDatabase<Record<string, never>> & {
1355
+ $client: postgres.Sql<{}>;
1356
+ };
1357
+ };
1358
+ /**
1359
+ * Generate a minimal migration configuration.
1360
+ */
1388
1361
  protected getMigrationOptions(): MigrationConfig;
1362
+ /**
1363
+ * Map the DATABASE_URL to postgres client options.
1364
+ */
1389
1365
  protected getClientOptions(): postgres.Options<any>;
1390
- protected sslModes: readonly ["require", "allow", "prefer", "verify-full"];
1391
- protected ssl(url: URL | undefined): "require" | "allow" | "prefer" | "verify-full" | undefined;
1366
+ protected ssl(url: URL): "require" | "allow" | "prefer" | "verify-full" | undefined;
1367
+ /**
1368
+ * For testing purposes, generate a unique schema name.
1369
+ * The schema name will be generated based on the current date and time.
1370
+ * It will be in the format of `test_YYYYMMDD_HHMMSS_randomSuffix`.
1371
+ *
1372
+ * TODO: investigate for adding the test file name to the schema name if possible.
1373
+ * TODO: options to skip deletion on failure, in order to inspect the schema?
1374
+ */
1375
+ protected generateTestSchemaName(): string;
1376
+ protected mapResult<T extends TObject$1 = any>(result: Array<any>, schema?: T): Array<T extends TObject$1 ? Static<T> : any>;
1392
1377
  }
1393
1378
  //#endregion
1394
- //#region src/helpers/pgAttr.d.ts
1395
- /**
1396
- * Type representation.
1397
- */
1398
- type PgAttr<T extends TSchema$1, TAttr extends PgSymbolKeys> = T & { [K in TAttr]: PgSymbols[K] };
1399
- //#endregion
1400
- //#region src/schemas/createdAtSchema.d.ts
1401
- declare const createdAtSchema: PgAttr<PgAttr<_sinclair_typebox16.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1402
- //# sourceMappingURL=createdAtSchema.d.ts.map
1403
-
1404
- //#endregion
1405
- //#region src/schemas/legacyIdSchema.d.ts
1406
- /**
1407
- * @deprecated Use `pg.primaryKey()` instead.
1408
- */
1409
- declare const legacyIdSchema: PgAttr<PgAttr<PgAttr<_sinclair_typebox17.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_SERIAL>, typeof PG_DEFAULT>;
1410
- //# sourceMappingURL=legacyIdSchema.d.ts.map
1411
- //#endregion
1412
- //#region src/schemas/updatedAtSchema.d.ts
1413
- declare const updatedAtSchema: PgAttr<PgAttr<_sinclair_typebox18.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
1414
- //# sourceMappingURL=updatedAtSchema.d.ts.map
1415
-
1416
- //#endregion
1417
- //#region src/schemas/entitySchema.d.ts
1418
- /**
1419
- * Entity Schema.
1420
- *
1421
- * Add some common SQL properties to an object.
1422
- */
1423
- declare const entitySchema: TObject$1<{
1424
- id: PgAttr<PgAttr<PgAttr<_sinclair_typebox6.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_SERIAL>, typeof PG_DEFAULT>;
1425
- createdAt: PgAttr<PgAttr<_sinclair_typebox6.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1426
- updatedAt: PgAttr<PgAttr<_sinclair_typebox6.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
1427
- }>;
1428
- /**
1429
- * TypeBox Entity Type.
1430
- */
1431
- type TEntity<T extends TProperties> = TObject$1<T & {
1432
- id: typeof legacyIdSchema;
1433
- createdAt: typeof createdAtSchema;
1434
- updatedAt: typeof updatedAtSchema;
1435
- }>;
1436
- /**
1437
- * The base entity.
1438
- */
1439
- type BaseEntity = Static<typeof entitySchema>;
1440
- /**
1441
- * The keys of the base entity.
1442
- */
1443
- type BaseEntityKeys = keyof BaseEntity;
1444
- /**
1445
- * The keys of the base entity.
1446
- */
1447
- declare const entityKeys: readonly ["id", "createdAt", "updatedAt"];
1448
- //# sourceMappingURL=entitySchema.d.ts.map
1449
- //#endregion
1450
1379
  //#region src/providers/PostgresTypeProvider.d.ts
1451
1380
  declare module "alepha" {
1452
1381
  interface TypeProvider {
@@ -1458,84 +1387,89 @@ declare class PostgresTypeProvider {
1458
1387
  /**
1459
1388
  * Creates a primary key with an identity column.
1460
1389
  */
1461
- readonly identityPrimaryKey: (identity?: PgIdentityOptions, options?: IntegerOptions) => PgAttr<PgAttr<PgAttr<_sinclair_typebox0.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
1390
+ readonly identityPrimaryKey: (identity?: PgIdentityOptions, options?: IntegerOptions) => PgAttr<PgAttr<PgAttr<TInteger, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
1462
1391
  /**
1463
1392
  * Creates a primary key with a big identity column. (default)
1464
1393
  */
1465
- readonly bigIdentityPrimaryKey: (identity?: PgIdentityOptions, options?: NumberOptions) => PgAttr<PgAttr<PgAttr<_sinclair_typebox0.TNumber, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
1394
+ readonly bigIdentityPrimaryKey: (identity?: PgIdentityOptions, options?: NumberOptions) => PgAttr<PgAttr<PgAttr<TNumber, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
1466
1395
  /**
1467
1396
  * Creates a primary key with a UUID column.
1468
1397
  */
1469
- readonly uuidPrimaryKey: () => PgAttr<PgAttr<_sinclair_typebox0.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
1398
+ readonly uuidPrimaryKey: () => PgAttr<PgAttr<TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
1470
1399
  /**
1471
- * @alias bigIdentityPrimaryKey
1400
+ * Creates a primary key for a given type. Supports:
1401
+ * - `t.int()` -> PG INT (default)
1402
+ * - `t.bigint()` -> PG BIGINT
1403
+ * - `t.uuid()` -> PG UUID
1472
1404
  */
1473
- readonly primaryKey: (identity?: PgIdentityOptions, options?: NumberOptions) => PgAttr<PgAttr<PgAttr<_sinclair_typebox0.TNumber, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
1405
+ primaryKey(): PgAttr<PgAttr<TInteger, PgPrimaryKey>, PgDefault>;
1406
+ primaryKey(type: TString, options?: StringOptions): PgAttr<PgAttr<TString, PgPrimaryKey>, PgDefault>;
1407
+ primaryKey(type: TInteger, options?: IntegerOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TInteger, PgPrimaryKey>, PgDefault>;
1408
+ primaryKey(type: TNumber, options?: NumberOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TNumber, PgPrimaryKey>, PgDefault>;
1474
1409
  /**
1475
1410
  * Wrap a schema with "default" attribute.
1476
1411
  * This is used to set a default value for a column in the database.
1477
1412
  */
1478
1413
  readonly default: <T extends TSchema$2>(type: T, value?: Static$1<T>) => PgAttr<T, PgDefault>;
1479
1414
  /**
1480
- * Creates a column version.
1415
+ * Creates a column 'version'.
1416
+ *
1481
1417
  * This is used to track the version of a row in the database.
1482
- * You can use it for optimistic concurrency control.
1418
+ *
1419
+ * You can use it for optimistic concurrency control (OCC) with {@link RepositoryDescriptor#save}.
1420
+ *
1421
+ * @see {@link RepositoryDescriptor#save}
1422
+ * @see {@link PgVersionMismatchError}
1483
1423
  */
1484
- readonly version: (options?: IntegerOptions) => PgAttr<PgAttr<_sinclair_typebox0.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
1424
+ readonly version: (options?: IntegerOptions) => PgAttr<PgAttr<TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
1485
1425
  /**
1486
1426
  * Creates a column Created At. So just a datetime column with a default value of the current timestamp.
1487
1427
  */
1488
- readonly createdAt: (options?: StringOptions) => PgAttr<PgAttr<_sinclair_typebox0.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1428
+ readonly createdAt: (options?: StringOptions) => PgAttr<PgAttr<TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1489
1429
  /**
1490
1430
  * Creates a column Updated At. Like createdAt, but it is updated on every update of the row.
1491
1431
  */
1492
- readonly updatedAt: (options?: StringOptions) => PgAttr<PgAttr<_sinclair_typebox0.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
1432
+ readonly updatedAt: (options?: StringOptions) => PgAttr<PgAttr<TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
1493
1433
  /**
1494
- * @deprecated Build your own entity schema.
1434
+ * Creates a column Deleted At for soft delete functionality.
1435
+ * This is used to mark rows as deleted without actually removing them from the database.
1436
+ * The column is nullable - NULL means not deleted, timestamp means deleted.
1495
1437
  */
1496
- readonly entity: <T extends TProperties>(properties: T, options?: ObjectOptions) => TEntity<T>;
1438
+ readonly deletedAt: (options?: StringOptions) => PgAttr<_sinclair_typebox1.TOptional<TString>, typeof PG_DELETED_AT>;
1497
1439
  /**
1498
- * Creates an insert schema for a given object schema.
1499
- * - pg.default will be optional
1500
- */
1501
- readonly insert: <T extends TObject$1>(obj: T) => TInsertObject<T>;
1502
- /**
1503
- * @alias insert
1504
- */
1505
- readonly input: <T extends TObject$1>(obj: T) => TInsertObject<T>;
1506
- /**
1507
- * Creates a page schema for a given object schema.
1508
- */
1509
- readonly page: <T extends TObject$1>(resource: T, options?: ObjectOptions) => TPage<T>;
1510
- /**
1511
- * Creates a reference to another table or schema.
1440
+ * Creates a reference to another table or schema. Basically a foreign key.
1512
1441
  */
1513
1442
  readonly ref: <T extends TSchema$2>(type: T, ref: () => any, actions?: {
1514
1443
  onUpdate?: UpdateDeleteAction$1;
1515
1444
  onDelete?: UpdateDeleteAction$1;
1516
1445
  }) => PgAttr<T, PgRef>;
1517
1446
  /**
1518
- * @alias ref
1447
+ * Convert a schema to a schema for INSERT operations.
1448
+ * It means that:
1449
+ * - All pg.default() will be optional
1450
+ *
1451
+ * @internal
1519
1452
  */
1520
- references: <T extends TSchema$2>(type: T, ref: () => any, actions?: {
1521
- onUpdate?: UpdateDeleteAction$1;
1522
- onDelete?: UpdateDeleteAction$1;
1523
- }) => PgAttr<T, PgRef>;
1453
+ readonly insert: <T extends TObject$1>(obj: T) => TInsertObject<T>;
1524
1454
  /**
1525
- * Creates a reference to another table or schema with a foreign key.
1526
- *
1527
- * @experimental
1455
+ * Creates a page schema for a given object schema.
1456
+ * It's used by {@link RepositoryDescriptor#paginate} method.
1528
1457
  */
1529
- readonly many: <T extends TObject$1, Config extends TableConfig$1>(table: PgTableWithColumnsAndSchema<Config, T>, foreignKey: keyof T["properties"]) => TOptionalWithFlag<PgAttr<PgAttr<TArray<T>, PgMany>, PgDefault>, true>;
1458
+ readonly page: <T extends TObject$1>(resource: T, options?: ObjectOptions) => TPage<T>;
1530
1459
  }
1531
1460
  declare const pg: PostgresTypeProvider;
1532
- //# sourceMappingURL=PostgresTypeProvider.d.ts.map
1461
+ //#endregion
1462
+ //#region src/schemas/legacyIdSchema.d.ts
1463
+ /**
1464
+ * @deprecated Use `pg.primaryKey()` instead.
1465
+ */
1466
+ declare const legacyIdSchema: PgAttr<PgAttr<PgAttr<_sinclair_typebox1.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_SERIAL>, typeof PG_DEFAULT>;
1533
1467
  //#endregion
1534
1468
  //#region src/types/schema.d.ts
1535
1469
  /**
1536
1470
  * Postgres schema type.
1537
1471
  */
1538
- declare const schema: <TDocument extends TSchema$2>(name: string, document: TDocument) => drizzle_orm0.$Type<drizzle_orm_pg_core0.PgCustomColumnBuilder<{
1472
+ declare const schema: <TDocument extends TSchema$2>(name: string, document: TDocument) => drizzle_orm7.$Type<pg$1.PgCustomColumnBuilder<{
1539
1473
  name: string;
1540
1474
  dataType: "custom";
1541
1475
  columnType: "PgCustomColumn";
@@ -1547,25 +1481,49 @@ declare const schema: <TDocument extends TSchema$2>(name: string, document: TDoc
1547
1481
  }>, (TDocument & {
1548
1482
  params: [];
1549
1483
  })["static"]>;
1550
- //# sourceMappingURL=schema.d.ts.map
1551
-
1552
1484
  //#endregion
1553
1485
  //#region src/index.d.ts
1554
1486
  /**
1555
- * Provides PostgreSQL (and SQLite!) database integration with type-safe ORM capabilities through Drizzle.
1487
+ * Postgres client based on Drizzle ORM, Alepha type-safe friendly.
1488
+ *
1489
+ * ```ts
1490
+ * const users = $entity({
1491
+ * name: "users",
1492
+ * schema: t.object({
1493
+ * id: pg.primaryKey(),
1494
+ * name: t.string(),
1495
+ * email: t.string(),
1496
+ * }),
1497
+ * });
1498
+ *
1499
+ * class Db {
1500
+ * users = $repository(users);
1501
+ * }
1502
+ *
1503
+ * const db = alepha.inject(Db);
1504
+ * const user = await db.users.one({ name: { eq: "John Doe" } });
1505
+ * ```
1556
1506
  *
1557
- * The postgres module enables declarative database operations using descriptors like `$entity`, `$repository`.
1558
- * It offers automatic schema generation, type-safe queries, transactions,
1559
- * and database migrations with support for PostgreSQLs.
1507
+ * This is not a full ORM, but rather a set of tools to work with Postgres databases in a type-safe way.
1508
+ *
1509
+ * It provides:
1510
+ * - A type-safe way to define entities and repositories. (via `$entity` and `$repository`)
1511
+ * - Custom query builders and filters.
1512
+ * - Built-in special columns like `createdAt`, `updatedAt`, `deletedAt`, `version`.
1513
+ * - Automatic JSONB support.
1514
+ * - Automatic synchronization of entities with the database schema (for testing and development).
1515
+ * - Fallback to raw SQL via Drizzle ORM `sql` function.
1516
+ *
1517
+ * Migrations are supported via Drizzle ORM, you need to use the `drizzle-kit` CLI tool to generate and run migrations.
1518
+ *
1519
+ * Relations are **NOT SUPPORTED** yet. If you need relations, please use the `drizzle-orm` package directly.
1560
1520
  *
1561
1521
  * @see {@link $entity}
1562
1522
  * @see {@link $repository}
1563
1523
  * @see {@link $transaction}
1564
1524
  * @module alepha.postgres
1565
1525
  */
1566
- declare const AlephaPostgres: _alepha_core0.ModuleDescriptor;
1567
- //# sourceMappingURL=index.d.ts.map
1568
-
1526
+ declare const AlephaPostgres: _alepha_core1.Service<_alepha_core1.Module>;
1569
1527
  //#endregion
1570
- export { $entity, $repository, $sequence, $transaction, AlephaPostgres, BaseEntity, BaseEntityKeys, DrizzleKitProvider, Entity, EntityDescriptorOptions, EntityNotFoundError, ExtractManyRelations, FilterOperators, FromSchema, NodePostgresProvider, NodePostgresProviderState, NullToUndefined, NullifyIfOptional, PG_CREATED_AT, PG_DEFAULT, PG_IDENTITY, PG_MANY, PG_ONE, PG_PRIMARY_KEY, PG_REF, PG_SCHEMA, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, Page, PageQuery, PgAttrField, PgDefault, PgIdentityOptions, PgMany, PgManyOptions, PgPrimaryKey, PgQuery, PgQueryResult, PgQueryWhere, PgQueryWhereWithMany, PgQueryWith, PgQueryWithMap, PgRef, PgRefOptions, PgSymbolKeys, PgSymbols, PgTableConfig, PgTableWithColumnsAndSchema, PostgresProvider, PostgresTypeProvider, RemoveManyRelations, RepositoryDescriptor, RepositoryDescriptorOptions, RepositoryDescriptorProvider, SQLLike, SequenceDescriptor, SequenceDescriptorOptions, StatementOptions, TEntity, TInsertObject, TPage, TableLike, TransactionContext, TransactionDescriptorOptions, camelToSnakeCase, drizzle, entityKeys, entitySchema, mapFieldToColumn, mapStringToColumn, nullToUndefined, pageQuerySchema, pageSchema, pg, pgTableSchema, schema, schemaToPgColumns, sql };
1528
+ export { $entity, $repository, $sequence, $transaction, AlephaPostgres, DrizzleKitProvider, Entity, EntityDescriptorOptions, FilterOperators, FromSchema, NodePostgresProvider, NodePostgresProviderOptions, NullToUndefined, NullifyIfOptional, PG_CREATED_AT, PG_DEFAULT, PG_DELETED_AT, PG_IDENTITY, PG_PRIMARY_KEY, PG_REF, PG_SCHEMA, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, Page, PageQuery, PgDefault, PgEntityNotFoundError, PgIdentityOptions, PgPrimaryKey, PgQuery, PgQueryResult, PgQueryWhere, PgQueryWhereOrSQL, PgRef, PgRefOptions, PgSymbolKeys, PgSymbols, PgTableConfig, PgTableWithColumnsAndSchema, PostgresProvider, PostgresTypeProvider, RepositoryDescriptor, RepositoryDescriptorOptions, RepositoryProvider, SQLLike, SequenceDescriptor, SequenceDescriptorOptions, StatementOptions, TInsertObject, TPage, TableLike, TransactionContext, TransactionDescriptorOptions, camelToSnakeCase, drizzle_orm7 as drizzle, legacyIdSchema, mapFieldToColumn, mapStringToColumn, nullToUndefined, pageQuerySchema, pageSchema, pg, schema, schemaToPgColumns, sql };
1571
1529
  //# sourceMappingURL=index.d.ts.map