@sqb/connect 4.12.0 → 4.13.0

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.
Files changed (65) hide show
  1. package/cjs/client/cursor.js +1 -1
  2. package/cjs/client/extensions.js +38 -11
  3. package/cjs/client/helpers.js +7 -6
  4. package/cjs/client/sqb-client.js +2 -2
  5. package/cjs/client/sqb-connection.js +7 -4
  6. package/cjs/index.js +19 -20
  7. package/cjs/orm/backward.js +5 -5
  8. package/cjs/orm/commands/command.helper.js +39 -11
  9. package/cjs/orm/commands/create.command.js +2 -1
  10. package/cjs/orm/commands/find.command.js +21 -35
  11. package/cjs/orm/commands/row-converter.js +5 -10
  12. package/cjs/orm/decorators/column.decorator.js +6 -3
  13. package/cjs/orm/decorators/embedded.decorator.js +1 -2
  14. package/cjs/orm/decorators/entity.decorator.js +1 -2
  15. package/cjs/orm/decorators/events.decorator.js +6 -7
  16. package/cjs/orm/decorators/foreignkey.decorator.js +1 -2
  17. package/cjs/orm/decorators/index.decorator.js +1 -2
  18. package/cjs/orm/decorators/link.decorator.js +7 -5
  19. package/cjs/orm/decorators/primarykey.decorator.js +3 -3
  20. package/cjs/orm/decorators/transform.decorator.js +2 -3
  21. package/cjs/orm/model/association.js +9 -11
  22. package/cjs/orm/model/entity-metadata.js +4 -2
  23. package/cjs/orm/orm.const.js +2 -1
  24. package/cjs/orm/repository.class.js +31 -36
  25. package/cjs/orm/util/apply-mixins.js +3 -3
  26. package/cjs/orm/util/extract-keyvalues.js +7 -5
  27. package/cjs/orm/util/orm.helper.js +8 -12
  28. package/cjs/orm/util/parse-fields-projection.js +64 -0
  29. package/cjs/orm/util/serialize-field.js +1 -2
  30. package/esm/client/cursor.js +1 -1
  31. package/esm/client/extensions.js +36 -8
  32. package/esm/client/helpers.js +2 -0
  33. package/esm/client/sqb-client.js +3 -3
  34. package/esm/client/sqb-connection.js +7 -4
  35. package/esm/index.js +18 -17
  36. package/esm/orm/commands/command.helper.js +36 -7
  37. package/esm/orm/commands/create.command.js +2 -1
  38. package/esm/orm/commands/find.command.js +21 -35
  39. package/esm/orm/commands/row-converter.js +5 -10
  40. package/esm/orm/decorators/column.decorator.js +5 -1
  41. package/esm/orm/decorators/link.decorator.js +6 -3
  42. package/esm/orm/decorators/primarykey.decorator.js +2 -1
  43. package/esm/orm/model/association.js +9 -11
  44. package/esm/orm/model/entity-metadata.js +4 -2
  45. package/esm/orm/orm.const.js +1 -0
  46. package/esm/orm/repository.class.js +31 -36
  47. package/esm/orm/util/apply-mixins.js +2 -1
  48. package/esm/orm/util/extract-keyvalues.js +6 -3
  49. package/esm/orm/util/orm.helper.js +2 -6
  50. package/esm/orm/util/parse-fields-projection.js +59 -0
  51. package/package.json +10 -6
  52. package/types/client/adapter.d.ts +1 -1
  53. package/types/client/cursor-stream.d.ts +0 -1
  54. package/types/client/extensions.d.ts +14 -3
  55. package/types/client/sqb-client.d.ts +1 -1
  56. package/types/client/sqb-connection.d.ts +1 -1
  57. package/types/client/types.d.ts +1 -1
  58. package/types/index.d.ts +18 -17
  59. package/types/orm/commands/find.command.d.ts +3 -4
  60. package/types/orm/commands/row-converter.d.ts +1 -1
  61. package/types/orm/decorators/column.decorator.d.ts +1 -0
  62. package/types/orm/model/field-metadata.d.ts +1 -1
  63. package/types/orm/orm.const.d.ts +1 -0
  64. package/types/orm/repository.class.d.ts +11 -8
  65. package/types/orm/util/parse-fields-projection.d.ts +10 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/connect",
3
3
  "description": "Multi-dialect database connection framework written with TypeScript",
4
- "version": "4.12.0",
4
+ "version": "4.13.0",
5
5
  "author": "Panates",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>",
@@ -25,19 +25,22 @@
25
25
  "build:esm": "tsc -b tsconfig-build-esm.json",
26
26
  "postbuild": "cp README.md package.json ../../LICENSE ../../build/connect && cp ../../package.cjs.json ../../build/connect/cjs/package.json",
27
27
  "lint": "eslint . --max-warnings=0",
28
+ "lint:fix": "eslint . --max-warnings=0 --fix",
29
+ "format": "prettier . --write --log-level=warn",
28
30
  "test": "jest",
29
31
  "cover": "jest --collect-coverage",
30
32
  "clean": "npm run clean:src | npm run clean:dist | npm run clean:cover",
31
33
  "clean:src": "ts-cleanup -s src --all",
32
34
  "clean:dist": "rimraf ../../build/connectt",
33
- "clean:cover": "rimraf ../../coverage/connect",
34
- "format": "prettier . --write --log-level=warn"
35
+ "clean:cover": "rimraf ../../coverage/connect"
35
36
  },
36
37
  "dependencies": {
37
38
  "debug": "^4.3.5",
39
+ "doublylinked": "^2.5.4",
40
+ "fast-tokenizer": "^1.3.0",
38
41
  "lightning-pool": "^4.2.2",
39
42
  "lodash": "^4.17.21",
40
- "power-tasks": "^1.7.3",
43
+ "power-tasks": "^1.7.4",
41
44
  "putil-isplainobject": "^1.1.5",
42
45
  "putil-merge": "^3.12.1",
43
46
  "putil-promisify": "^1.10.1",
@@ -47,10 +50,11 @@
47
50
  },
48
51
  "devDependencies": {
49
52
  "@types/debug": "^4.1.12",
50
- "@types/lodash": "^4.17.4"
53
+ "@types/lodash": "^4.17.7",
54
+ "postgresql-client": "^2.12.0"
51
55
  },
52
56
  "peerDependencies": {
53
- "@sqb/builder": "^4.12.0",
57
+ "@sqb/builder": "^4.13.0",
54
58
  "reflect-metadata": "^0.2.2"
55
59
  },
56
60
  "engines": {
@@ -1,5 +1,5 @@
1
- import { Maybe } from 'ts-gems';
2
1
  import { classes } from '@sqb/builder';
2
+ import { Maybe } from 'ts-gems';
3
3
  import { ClientConfiguration, DataType, QueryRequest, RowType } from './types.js';
4
4
  export interface Adapter {
5
5
  driver: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Readable } from 'stream';
3
2
  import { Cursor } from './cursor.js';
4
3
  export interface CursorStreamOptions {
@@ -1,4 +1,15 @@
1
+ import { SerializerExtension } from '@sqb/builder';
1
2
  import { Adapter } from './adapter.js';
2
- export declare let adapters: Adapter[];
3
- export declare function registerAdapter(adapter: Adapter): void;
4
- export declare function unRegisterAdapter(...adapter: Adapter[]): void;
3
+ export declare class AdapterRegistry {
4
+ protected static adapters: Adapter[];
5
+ static get size(): number;
6
+ static register(...adapters: Adapter[]): void;
7
+ static forEach(callback: (value: Adapter, index: number) => void, thisArg?: any): void;
8
+ static items(): IterableIterator<Adapter>;
9
+ static unRegister(...extensions: Adapter[]): void;
10
+ static getAll(dialect: string): Adapter[];
11
+ static get(index: number): SerializerExtension | undefined;
12
+ static findDialect(dialect: string): SerializerExtension | undefined;
13
+ static findDriver(dialect: string): SerializerExtension | undefined;
14
+ static has(extension: Adapter): boolean;
15
+ }
@@ -1,6 +1,6 @@
1
+ import { classes } from '@sqb/builder';
1
2
  import { Pool as LightningPool } from 'lightning-pool';
2
3
  import { Maybe, Type } from 'ts-gems';
3
- import { classes } from '@sqb/builder';
4
4
  import { Repository } from '../orm/repository.class.js';
5
5
  import { SqbConnection } from './sqb-connection.js';
6
6
  import { ClientConfiguration, ClientDefaults, ConnectionOptions, QueryExecuteOptions, QueryRequest, QueryResult, TransactionFunction } from './types.js';
@@ -1,5 +1,5 @@
1
- import { Type } from 'ts-gems';
2
1
  import { classes } from '@sqb/builder';
2
+ import { Type } from 'ts-gems';
3
3
  import { Repository } from '../orm/repository.class.js';
4
4
  import { Adapter } from './adapter.js';
5
5
  import { SqbClient } from './sqb-client.js';
@@ -1,6 +1,6 @@
1
+ import { DataType, ParamOptions } from '@sqb/builder';
1
2
  import type { PoolConfiguration } from 'lightning-pool';
2
3
  import { Maybe } from 'ts-gems';
3
- import { DataType, ParamOptions } from '@sqb/builder';
4
4
  import type { Adapter } from './adapter';
5
5
  import type { Cursor } from './cursor';
6
6
  import type { FieldInfoMap } from './field-info-map';
package/types/index.d.ts CHANGED
@@ -1,23 +1,12 @@
1
1
  import 'reflect-metadata';
2
- export * from './client/types.js';
3
2
  export * from './client/adapter.js';
3
+ export * from './client/cursor.js';
4
+ export * from './client/extensions.js';
4
5
  export * from './client/sqb-client.js';
5
6
  export * from './client/sqb-connection.js';
6
- export * from './client/cursor.js';
7
- export { registerAdapter, unRegisterAdapter } from './client/extensions.js';
8
- export * from './orm/orm.type.js';
9
- export * from './orm/orm.const.js';
7
+ export * from './client/types.js';
8
+ export * from './orm/backward.js';
10
9
  export * from './orm/base-entity.js';
11
- export * from './orm/repository.class.js';
12
- export * from './orm/model/entity-metadata.js';
13
- export * from './orm/model/field-metadata.js';
14
- export * from './orm/model/column-field-metadata.js';
15
- export * from './orm/model/embedded-field-metadata.js';
16
- export * from './orm/model/association-field-metadata.js';
17
- export * from './orm/model/association.js';
18
- export * from './orm/model/association-node.js';
19
- export * from './orm/model/index-metadata.js';
20
- export * from './orm/model/link-chain.js';
21
10
  export * from './orm/decorators/column.decorator.js';
22
11
  export * from './orm/decorators/embedded.decorator.js';
23
12
  export * from './orm/decorators/entity.decorator.js';
@@ -27,5 +16,17 @@ export * from './orm/decorators/index.decorator.js';
27
16
  export * from './orm/decorators/link.decorator.js';
28
17
  export * from './orm/decorators/primarykey.decorator.js';
29
18
  export * from './orm/decorators/transform.decorator.js';
30
- export { isColumnField, isEmbeddedField, isAssociationField, isEntityClass } from './orm/util/orm.helper.js';
31
- export * from './orm/backward.js';
19
+ export * from './orm/model/association.js';
20
+ export * from './orm/model/association-field-metadata.js';
21
+ export * from './orm/model/association-node.js';
22
+ export * from './orm/model/column-field-metadata.js';
23
+ export * from './orm/model/embedded-field-metadata.js';
24
+ export * from './orm/model/entity-metadata.js';
25
+ export * from './orm/model/field-metadata.js';
26
+ export * from './orm/model/index-metadata.js';
27
+ export * from './orm/model/link-chain.js';
28
+ export * from './orm/orm.const.js';
29
+ export * from './orm/orm.type.js';
30
+ export * from './orm/repository.class.js';
31
+ export { isAssociationField, isColumnField, isEmbeddedField, isEntityClass } from './orm/util/orm.helper.js';
32
+ export * from './orm/util/parse-fields-projection.js';
@@ -2,6 +2,7 @@ import { SqbConnection } from '../../client/sqb-connection.js';
2
2
  import { AssociationNode } from '../model/association-node.js';
3
3
  import { EntityMetadata } from '../model/entity-metadata.js';
4
4
  import { Repository } from '../repository.class.js';
5
+ import { FieldsProjection } from '../util/parse-fields-projection.js';
5
6
  import { RowConverter } from './row-converter.js';
6
7
  export type FindCommandArgs = {
7
8
  entity: EntityMetadata;
@@ -29,9 +30,7 @@ export declare class FindCommand {
29
30
  tableAlias?: string;
30
31
  converter?: RowConverter;
31
32
  entity?: EntityMetadata;
32
- pick?: string[];
33
- omit?: string[];
34
- include?: string[];
33
+ projection?: FieldsProjection | string | string[];
35
34
  sort?: string[];
36
35
  prefix?: string;
37
36
  suffix?: string;
@@ -39,6 +38,6 @@ export declare class FindCommand {
39
38
  private _selectColumn;
40
39
  filter(filter: any): Promise<void>;
41
40
  sort(sortFields: string[]): Promise<void>;
42
- execute(args: Pick<FindCommandArgs, 'connection' | 'distinct' | 'offset' | 'limit' | 'params' | 'onTransformRow'>): Promise<any[]>;
41
+ execute(args: Pick<FindCommandArgs, 'connection' | 'distinct' | 'offset' | 'limit' | 'params' | 'onTransformRow' | 'prettyPrint'>): Promise<any[]>;
43
42
  private _getEntityFromAlias;
44
43
  }
@@ -1,5 +1,5 @@
1
- import { Type } from 'ts-gems';
2
1
  import { DataType } from '@sqb/builder';
2
+ import { Type } from 'ts-gems';
3
3
  import type { FieldInfoMap } from '../../client/field-info-map';
4
4
  import { SqbConnection } from '../../client/sqb-connection.js';
5
5
  import { ColumnTransformFunction } from '../orm.type.js';
@@ -2,3 +2,4 @@ import { DataType } from '@sqb/builder';
2
2
  import { ColumnFieldOptions } from '../model/column-field-metadata.js';
3
3
  export declare function Column(type?: DataType): PropertyDecorator;
4
4
  export declare function Column(options?: ColumnFieldOptions): PropertyDecorator;
5
+ export declare namespace Column { }
@@ -10,7 +10,7 @@ export interface FieldMetadata {
10
10
  hidden?: boolean;
11
11
  /**
12
12
  * Indicates whether or not to include this field by default when making queries.
13
- * If this set to "true" the field must be requested using "include" or "pick" option.
13
+ * If this set to "true" the field must be requested using "projection" option.
14
14
  */
15
15
  exclusive?: boolean;
16
16
  }
@@ -1,2 +1,3 @@
1
1
  export declare const ENTITY_METADATA_KEY: unique symbol;
2
2
  export declare const REPOSITORY_KEY: unique symbol;
3
+ export declare const DECORATOR_FACTORY: unique symbol;
@@ -1,14 +1,12 @@
1
- import { PartialDTO, PatchDTO, StrictOmit, Type } from 'ts-gems';
2
1
  import { LogicalOperator } from '@sqb/builder';
2
+ import { PartialDTO, PatchDTO, StrictOmit, Type } from 'ts-gems';
3
3
  import { FieldInfoMap } from '../client/field-info-map.js';
4
4
  import { SqbClient } from '../client/sqb-client.js';
5
5
  import { SqbConnection } from '../client/sqb-connection.js';
6
6
  import { QueryRequest, TransactionFunction } from '../client/types.js';
7
7
  import { EntityMetadata } from './model/entity-metadata.js';
8
8
  interface Projection {
9
- pick?: string[];
10
- omit?: string[];
11
- include?: string[];
9
+ projection?: string | string[];
12
10
  }
13
11
  interface Filtering {
14
12
  filter?: LogicalOperator | LogicalOperator[] | object | object[];
@@ -18,6 +16,7 @@ export declare namespace Repository {
18
16
  type TransformRowFunction = (fields: FieldInfoMap, row: object, obj: object) => void;
19
17
  interface CommandOptions {
20
18
  connection?: SqbConnection;
19
+ prettyPrint?: boolean;
21
20
  }
22
21
  interface CreateOptions extends CommandOptions, Projection {
23
22
  }
@@ -31,7 +30,7 @@ export declare namespace Repository {
31
30
  }
32
31
  interface FindOptions extends CommandOptions, Projection, Filtering {
33
32
  }
34
- interface FindOneOptions extends CommandOptions, Projection, Filtering {
33
+ interface FindOneOptions extends FindOptions {
35
34
  sort?: string[];
36
35
  offset?: number;
37
36
  }
@@ -44,6 +43,8 @@ export declare namespace Repository {
44
43
  }
45
44
  interface UpdateOptions extends CommandOptions, Projection, Filtering {
46
45
  }
46
+ interface UpdateOnlyOptions extends CommandOptions, Filtering {
47
+ }
47
48
  interface UpdateManyOptions extends CommandOptions, Filtering {
48
49
  }
49
50
  }
@@ -63,16 +64,15 @@ export declare class Repository<T> extends Repository_base {
63
64
  create(values: PartialDTO<T>, options?: Repository.CreateOptions): Promise<PartialDTO<T>>;
64
65
  createOnly(values: PartialDTO<T>, options?: StrictOmit<Repository.CreateOptions, keyof Projection>): Promise<void>;
65
66
  exists(keyValue: any | Record<string, any>, options?: Repository.ExistsOptions): Promise<boolean>;
67
+ existsOne(options?: Repository.ExistsOptions): Promise<boolean>;
66
68
  count(options?: Repository.CountOptions): Promise<number>;
67
- /** @deprecated - Use findById instead */
68
- find(keyValue: any | Record<string, any>, options?: Repository.FindOptions): Promise<PartialDTO<T> | undefined>;
69
69
  findById(keyValue: any | Record<string, any>, options?: Repository.FindOptions): Promise<PartialDTO<T> | undefined>;
70
70
  findOne(options?: Repository.FindOneOptions): Promise<PartialDTO<T> | undefined>;
71
71
  findMany(options?: Repository.FindManyOptions): Promise<PartialDTO<T>[]>;
72
72
  delete(keyValue: any | Record<string, any>, options?: Repository.DeleteOptions): Promise<boolean>;
73
73
  deleteMany(options?: Repository.DeleteManyOptions): Promise<number>;
74
74
  update(keyValue: any | Record<string, any>, values: PatchDTO<T>, options?: Repository.UpdateOptions): Promise<PartialDTO<T> | undefined>;
75
- updateOnly(keyValue: any | Record<string, any>, values: PatchDTO<T>, options?: StrictOmit<Repository.UpdateOptions, keyof Projection>): Promise<boolean>;
75
+ updateOnly(keyValue: any | Record<string, any>, values: PatchDTO<T>, options?: Repository.UpdateOnlyOptions): Promise<boolean>;
76
76
  updateMany(values: PartialDTO<T>, options?: Repository.UpdateManyOptions): Promise<number>;
77
77
  protected _execute(fn: TransactionFunction, opts?: Repository.CommandOptions): Promise<any>;
78
78
  protected _create(values: PartialDTO<T>, options: Repository.CreateOptions & {
@@ -82,6 +82,9 @@ export declare class Repository<T> extends Repository_base {
82
82
  protected _exists(keyValue: any | Record<string, any>, options: Repository.ExistsOptions & {
83
83
  connection: SqbConnection;
84
84
  }): Promise<boolean>;
85
+ protected _existsOne(options: Repository.ExistsOptions & {
86
+ connection: SqbConnection;
87
+ }): Promise<boolean>;
85
88
  protected _count(options: Repository.CountOptions & {
86
89
  connection: SqbConnection;
87
90
  }): Promise<number>;
@@ -0,0 +1,10 @@
1
+ export declare class FieldsProjection {
2
+ [key: string]: FieldsProjection.Item;
3
+ }
4
+ export declare namespace FieldsProjection {
5
+ class Item {
6
+ sign?: string;
7
+ projection?: FieldsProjection;
8
+ }
9
+ }
10
+ export declare function parseFieldsProjection(projection: string | string[], keepCase?: boolean): FieldsProjection | undefined;