@sqb/connect 4.20.6 → 4.21.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 (144) hide show
  1. package/{types/client → client}/cursor-stream.d.ts +1 -1
  2. package/{types/client → client}/cursor.d.ts +4 -4
  3. package/{types/client → client}/sqb-connection.d.ts +4 -4
  4. package/{esm/orm → orm}/commands/command.helper.js +2 -3
  5. package/{types/orm → orm}/commands/count.command.d.ts +2 -2
  6. package/{types/orm → orm}/commands/create.command.d.ts +1 -1
  7. package/{esm/orm → orm}/commands/create.command.js +3 -5
  8. package/{types/orm → orm}/commands/delete.command.d.ts +2 -2
  9. package/{types/orm → orm}/commands/find.command.d.ts +2 -2
  10. package/{esm/orm → orm}/commands/find.command.js +3 -4
  11. package/{types/orm → orm}/commands/row-converter.d.ts +1 -1
  12. package/{types/orm → orm}/commands/update.command.d.ts +2 -2
  13. package/{esm/orm → orm}/commands/update.command.js +3 -5
  14. package/{types/orm → orm}/model/association-field-metadata.d.ts +0 -5
  15. package/{types/orm → orm}/model/association.d.ts +3 -3
  16. package/{esm/orm → orm}/model/association.js +1 -1
  17. package/{types/orm → orm}/model/column-field-metadata.d.ts +2 -8
  18. package/{types/orm → orm}/model/embedded-field-metadata.d.ts +0 -1
  19. package/{esm/orm → orm}/model/embedded-field-metadata.js +0 -14
  20. package/{types/orm → orm}/model/entity-metadata.d.ts +3 -3
  21. package/{esm/orm → orm}/model/entity-metadata.js +21 -6
  22. package/orm/model/index-metadata.js +1 -0
  23. package/orm/orm.type.js +1 -0
  24. package/{types/orm → orm}/repository.class.d.ts +2 -2
  25. package/{esm/orm → orm}/repository.class.js +1 -1
  26. package/{types/orm → orm}/util/orm.helper.d.ts +5 -3
  27. package/{esm/orm → orm}/util/orm.helper.js +14 -0
  28. package/package.json +10 -26
  29. package/cjs/client/adapter.js +0 -2
  30. package/cjs/client/cursor-stream.js +0 -104
  31. package/cjs/client/cursor.js +0 -261
  32. package/cjs/client/extensions.js +0 -41
  33. package/cjs/client/field-info-map.js +0 -54
  34. package/cjs/client/helpers.js +0 -140
  35. package/cjs/client/sqb-client.js +0 -175
  36. package/cjs/client/sqb-connection.js +0 -293
  37. package/cjs/client/sqb-error.js +0 -15
  38. package/cjs/client/types.js +0 -5
  39. package/cjs/index.js +0 -41
  40. package/cjs/orm/backward.js +0 -24
  41. package/cjs/orm/base-entity.js +0 -29
  42. package/cjs/orm/commands/command.helper.js +0 -170
  43. package/cjs/orm/commands/count.command.js +0 -30
  44. package/cjs/orm/commands/create.command.js +0 -92
  45. package/cjs/orm/commands/delete.command.js +0 -30
  46. package/cjs/orm/commands/find.command.js +0 -301
  47. package/cjs/orm/commands/row-converter.js +0 -190
  48. package/cjs/orm/commands/update.command.js +0 -83
  49. package/cjs/orm/decorators/column.decorator.js +0 -32
  50. package/cjs/orm/decorators/embedded.decorator.js +0 -15
  51. package/cjs/orm/decorators/entity.decorator.js +0 -180
  52. package/cjs/orm/decorators/events.decorator.js +0 -63
  53. package/cjs/orm/decorators/foreignkey.decorator.js +0 -12
  54. package/cjs/orm/decorators/index.decorator.js +0 -20
  55. package/cjs/orm/decorators/link.decorator.js +0 -72
  56. package/cjs/orm/decorators/primarykey.decorator.js +0 -24
  57. package/cjs/orm/decorators/transform.decorator.js +0 -21
  58. package/cjs/orm/model/association-field-metadata.js +0 -24
  59. package/cjs/orm/model/association-node.js +0 -28
  60. package/cjs/orm/model/association.js +0 -141
  61. package/cjs/orm/model/column-field-metadata.js +0 -32
  62. package/cjs/orm/model/embedded-field-metadata.js +0 -28
  63. package/cjs/orm/model/entity-metadata.js +0 -327
  64. package/cjs/orm/model/field-metadata.js +0 -2
  65. package/cjs/orm/model/index-metadata.js +0 -2
  66. package/cjs/orm/model/link-chain.js +0 -47
  67. package/cjs/orm/orm.const.js +0 -6
  68. package/cjs/orm/orm.type.js +0 -2
  69. package/cjs/orm/repository.class.js +0 -293
  70. package/cjs/orm/util/apply-mixins.js +0 -16
  71. package/cjs/orm/util/extract-keyvalues.js +0 -63
  72. package/cjs/orm/util/orm.helper.js +0 -34
  73. package/cjs/orm/util/parse-fields-projection.js +0 -68
  74. package/cjs/orm/util/serialize-field.js +0 -49
  75. package/cjs/package.json +0 -3
  76. package/esm/orm/model/association-field-metadata.js +0 -20
  77. package/esm/orm/model/column-field-metadata.js +0 -28
  78. package/esm/package.json +0 -3
  79. package/types/index.d.cts +0 -33
  80. /package/{types/client → client}/adapter.d.ts +0 -0
  81. /package/{esm/client → client}/adapter.js +0 -0
  82. /package/{esm/client → client}/cursor-stream.js +0 -0
  83. /package/{esm/client → client}/cursor.js +0 -0
  84. /package/{types/client → client}/extensions.d.ts +0 -0
  85. /package/{esm/client → client}/extensions.js +0 -0
  86. /package/{types/client → client}/field-info-map.d.ts +0 -0
  87. /package/{esm/client → client}/field-info-map.js +0 -0
  88. /package/{types/client → client}/helpers.d.ts +0 -0
  89. /package/{esm/client → client}/helpers.js +0 -0
  90. /package/{types/client → client}/sqb-client.d.ts +0 -0
  91. /package/{esm/client → client}/sqb-client.js +0 -0
  92. /package/{esm/client → client}/sqb-connection.js +0 -0
  93. /package/{types/client → client}/sqb-error.d.ts +0 -0
  94. /package/{esm/client → client}/sqb-error.js +0 -0
  95. /package/{types/client → client}/types.d.ts +0 -0
  96. /package/{esm/client → client}/types.js +0 -0
  97. /package/{types/index.d.ts → index.d.ts} +0 -0
  98. /package/{esm/index.js → index.js} +0 -0
  99. /package/{types/orm → orm}/backward.d.ts +0 -0
  100. /package/{esm/orm → orm}/backward.js +0 -0
  101. /package/{types/orm → orm}/base-entity.d.ts +0 -0
  102. /package/{esm/orm → orm}/base-entity.js +0 -0
  103. /package/{types/orm → orm}/commands/command.helper.d.ts +0 -0
  104. /package/{esm/orm → orm}/commands/count.command.js +0 -0
  105. /package/{esm/orm → orm}/commands/delete.command.js +0 -0
  106. /package/{esm/orm → orm}/commands/row-converter.js +0 -0
  107. /package/{types/orm → orm}/decorators/column.decorator.d.ts +0 -0
  108. /package/{esm/orm → orm}/decorators/column.decorator.js +0 -0
  109. /package/{types/orm → orm}/decorators/embedded.decorator.d.ts +0 -0
  110. /package/{esm/orm → orm}/decorators/embedded.decorator.js +0 -0
  111. /package/{types/orm → orm}/decorators/entity.decorator.d.ts +0 -0
  112. /package/{esm/orm → orm}/decorators/entity.decorator.js +0 -0
  113. /package/{types/orm → orm}/decorators/events.decorator.d.ts +0 -0
  114. /package/{esm/orm → orm}/decorators/events.decorator.js +0 -0
  115. /package/{types/orm → orm}/decorators/foreignkey.decorator.d.ts +0 -0
  116. /package/{esm/orm → orm}/decorators/foreignkey.decorator.js +0 -0
  117. /package/{types/orm → orm}/decorators/index.decorator.d.ts +0 -0
  118. /package/{esm/orm → orm}/decorators/index.decorator.js +0 -0
  119. /package/{types/orm → orm}/decorators/link.decorator.d.ts +0 -0
  120. /package/{esm/orm → orm}/decorators/link.decorator.js +0 -0
  121. /package/{types/orm → orm}/decorators/primarykey.decorator.d.ts +0 -0
  122. /package/{esm/orm → orm}/decorators/primarykey.decorator.js +0 -0
  123. /package/{types/orm → orm}/decorators/transform.decorator.d.ts +0 -0
  124. /package/{esm/orm → orm}/decorators/transform.decorator.js +0 -0
  125. /package/{esm/orm/model/field-metadata.js → orm/model/association-field-metadata.js} +0 -0
  126. /package/{types/orm → orm}/model/association-node.d.ts +0 -0
  127. /package/{esm/orm → orm}/model/association-node.js +0 -0
  128. /package/{esm/orm/model/index-metadata.js → orm/model/column-field-metadata.js} +0 -0
  129. /package/{types/orm → orm}/model/field-metadata.d.ts +0 -0
  130. /package/{esm/orm/orm.type.js → orm/model/field-metadata.js} +0 -0
  131. /package/{types/orm → orm}/model/index-metadata.d.ts +0 -0
  132. /package/{types/orm → orm}/model/link-chain.d.ts +0 -0
  133. /package/{esm/orm → orm}/model/link-chain.js +0 -0
  134. /package/{types/orm → orm}/orm.const.d.ts +0 -0
  135. /package/{esm/orm → orm}/orm.const.js +0 -0
  136. /package/{types/orm → orm}/orm.type.d.ts +0 -0
  137. /package/{types/orm → orm}/util/apply-mixins.d.ts +0 -0
  138. /package/{esm/orm → orm}/util/apply-mixins.js +0 -0
  139. /package/{types/orm → orm}/util/extract-keyvalues.d.ts +0 -0
  140. /package/{esm/orm → orm}/util/extract-keyvalues.js +0 -0
  141. /package/{types/orm → orm}/util/parse-fields-projection.d.ts +0 -0
  142. /package/{esm/orm → orm}/util/parse-fields-projection.js +0 -0
  143. /package/{types/orm → orm}/util/serialize-field.d.ts +0 -0
  144. /package/{esm/orm → orm}/util/serialize-field.js +0 -0
@@ -1,5 +1,5 @@
1
1
  import { Readable } from 'stream';
2
- import { Cursor } from './cursor.js';
2
+ import type { Cursor } from './cursor.js';
3
3
  export interface CursorStreamOptions {
4
4
  objectMode?: boolean;
5
5
  limit?: number;
@@ -1,8 +1,8 @@
1
- import { Adapter } from './adapter.js';
1
+ import type { Adapter } from './adapter.js';
2
2
  import { CursorStream, CursorStreamOptions } from './cursor-stream.js';
3
- import { FieldInfoMap } from './field-info-map.js';
4
- import { SqbConnection } from './sqb-connection.js';
5
- import { ObjectRow, QueryRequest } from './types.js';
3
+ import type { FieldInfoMap } from './field-info-map.js';
4
+ import type { SqbConnection } from './sqb-connection.js';
5
+ import type { ObjectRow, QueryRequest } from './types.js';
6
6
  interface CursorEvents {
7
7
  close: () => void;
8
8
  error: (error: unknown) => void;
@@ -1,9 +1,9 @@
1
1
  import { classes } from '@sqb/builder';
2
- import { Type } from 'ts-gems';
2
+ import type { Type } from 'ts-gems';
3
3
  import { Repository } from '../orm/repository.class.js';
4
- import { Adapter } from './adapter.js';
5
- import { SqbClient } from './sqb-client.js';
6
- import { ConnectionOptions, QueryExecuteOptions, QueryRequest } from './types.js';
4
+ import type { Adapter } from './adapter.js';
5
+ import type { SqbClient } from './sqb-client.js';
6
+ import type { ConnectionOptions, QueryExecuteOptions, QueryRequest } from './types.js';
7
7
  interface SqbConnectionEvents {
8
8
  close: () => void;
9
9
  execute: (request: QueryRequest) => void;
@@ -1,7 +1,6 @@
1
1
  import { And, Eq, Exists, Field, InnerJoin, isCompOperator, isLogicalOperator, LeftOuterJoin, op, OperatorType, Raw, Select, } from '@sqb/builder';
2
- import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
3
2
  import { EntityMetadata } from '../model/entity-metadata.js';
4
- import { isAssociationField, isColumnField, isEmbeddedField, } from '../util/orm.helper.js';
3
+ import { isAssociationField, isColumnField, isEmbeddedField, resolveEntityForEmbeddedField, } from '../util/orm.helper.js';
5
4
  export async function joinAssociationGetFirst(joinInfos, association, parentAlias, innerJoin) {
6
5
  const joins = await joinAssociation(joinInfos, association, parentAlias, innerJoin);
7
6
  return joins[0];
@@ -107,7 +106,7 @@ export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T')
107
106
  if (isColumnField(col))
108
107
  throw new Error(`Invalid column (${item._left}) defined in filter`);
109
108
  if (isEmbeddedField(col)) {
110
- _curEntity = await EmbeddedFieldMetadata.resolveType(col);
109
+ _curEntity = await resolveEntityForEmbeddedField(col);
111
110
  _curPrefix = _curPrefix + (col.fieldNamePrefix || '');
112
111
  _curSuffix = (col.fieldNameSuffix || '') + _curSuffix;
113
112
  continue;
@@ -1,6 +1,6 @@
1
- import { SqbConnection } from '../../client/sqb-connection.js';
1
+ import type { SqbConnection } from '../../client/sqb-connection.js';
2
2
  import { EntityMetadata } from '../model/entity-metadata.js';
3
- import { Repository } from '../repository.class.js';
3
+ import type { Repository } from '../repository.class.js';
4
4
  export type CountCommandArgs = {
5
5
  entity: EntityMetadata;
6
6
  connection: SqbConnection;
@@ -1,4 +1,4 @@
1
- import { SqbConnection } from '../../client/sqb-connection.js';
1
+ import type { SqbConnection } from '../../client/sqb-connection.js';
2
2
  import { EntityMetadata } from '../model/entity-metadata.js';
3
3
  export type CreateCommandArgs = {
4
4
  entity: EntityMetadata;
@@ -1,8 +1,6 @@
1
1
  import { Insert, Param } from '@sqb/builder';
2
- import { ColumnFieldMetadata } from '../model/column-field-metadata.js';
3
- import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
4
2
  import { EntityMetadata } from '../model/entity-metadata.js';
5
- import { isColumnField, isEmbeddedField } from '../util/orm.helper.js';
3
+ import { checkEnumValue, isColumnField, isEmbeddedField, resolveEntityForEmbeddedField, } from '../util/orm.helper.js';
6
4
  export class CreateCommand {
7
5
  // istanbul ignore next
8
6
  constructor() {
@@ -68,7 +66,7 @@ export class CreateCommand {
68
66
  }
69
67
  continue;
70
68
  }
71
- ColumnFieldMetadata.checkEnumValue(col, v);
69
+ checkEnumValue(col, v);
72
70
  const fieldName = prefix + col.fieldName + suffix;
73
71
  const k = ('I$_' + fieldName).substring(0, 30);
74
72
  ctx.queryValues[fieldName] = Param({
@@ -80,7 +78,7 @@ export class CreateCommand {
80
78
  ctx.colCount++;
81
79
  }
82
80
  else if (v != null && isEmbeddedField(col)) {
83
- const type = await EmbeddedFieldMetadata.resolveType(col);
81
+ const type = await resolveEntityForEmbeddedField(col);
84
82
  await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
85
83
  }
86
84
  }
@@ -1,6 +1,6 @@
1
- import { SqbConnection } from '../../client/sqb-connection.js';
1
+ import type { SqbConnection } from '../../client/sqb-connection.js';
2
2
  import { EntityMetadata } from '../model/entity-metadata.js';
3
- import { Repository } from '../repository.class.js';
3
+ import type { Repository } from '../repository.class.js';
4
4
  export type DestroyCommandArgs = {
5
5
  entity: EntityMetadata;
6
6
  connection: SqbConnection;
@@ -1,7 +1,7 @@
1
- import { SqbConnection } from '../../client/sqb-connection.js';
1
+ import type { 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
- import { Repository } from '../repository.class.js';
4
+ import type { Repository } from '../repository.class.js';
5
5
  import { FieldsProjection } from '../util/parse-fields-projection.js';
6
6
  import { RowConverter } from './row-converter.js';
7
7
  export type FindCommandArgs = {
@@ -1,8 +1,7 @@
1
1
  import { And, In, Param, Select } from '@sqb/builder';
2
2
  import { AssociationNode } from '../model/association-node.js';
3
- import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
4
3
  import { EntityMetadata } from '../model/entity-metadata.js';
5
- import { isAssociationField, isColumnField, isEmbeddedField, } from '../util/orm.helper.js';
4
+ import { isAssociationField, isColumnField, isEmbeddedField, resolveEntityForEmbeddedField, } from '../util/orm.helper.js';
6
5
  import { parseFieldsProjection, } from '../util/parse-fields-projection.js';
7
6
  import { joinAssociationGetLast, prepareFilter, } from './command.helper.js';
8
7
  import { RowConverter } from './row-converter.js';
@@ -107,7 +106,7 @@ export class FindCommand {
107
106
  continue;
108
107
  }
109
108
  if (isEmbeddedField(col)) {
110
- const typ = await EmbeddedFieldMetadata.resolveType(col);
109
+ const typ = await resolveEntityForEmbeddedField(col);
111
110
  const subConverter = converter.addObjectProperty({
112
111
  name: col.name,
113
112
  type: typ.ctor,
@@ -205,7 +204,7 @@ export class FindCommand {
205
204
  while (a.length > 1) {
206
205
  const col = EntityMetadata.getField(_entityDef, a.shift() || '');
207
206
  if (isEmbeddedField(col)) {
208
- _entityDef = await EmbeddedFieldMetadata.resolveType(col);
207
+ _entityDef = await resolveEntityForEmbeddedField(col);
209
208
  if (col.fieldNamePrefix)
210
209
  prefix += col.fieldNamePrefix;
211
210
  if (col.fieldNameSuffix)
@@ -1,7 +1,7 @@
1
1
  import { DataType } from '@sqb/builder';
2
2
  import { Type } from 'ts-gems';
3
3
  import type { FieldInfoMap } from '../../client/field-info-map.js';
4
- import { SqbConnection } from '../../client/sqb-connection.js';
4
+ import type { SqbConnection } from '../../client/sqb-connection.js';
5
5
  import { ColumnTransformFunction } from '../orm.type.js';
6
6
  import type { Repository } from '../repository.class.js';
7
7
  import type { FindCommand } from './find.command.js';
@@ -1,6 +1,6 @@
1
- import { SqbConnection } from '../../client/sqb-connection.js';
1
+ import type { SqbConnection } from '../../client/sqb-connection.js';
2
2
  import { EntityMetadata } from '../model/entity-metadata.js';
3
- import { Repository } from '../repository.class.js';
3
+ import type { Repository } from '../repository.class.js';
4
4
  export type UpdateCommandArgs = {
5
5
  entity: EntityMetadata;
6
6
  connection: SqbConnection;
@@ -1,7 +1,5 @@
1
1
  import { And, Param, Update } from '@sqb/builder';
2
- import { ColumnFieldMetadata } from '../model/column-field-metadata.js';
3
- import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
4
- import { isColumnField, isEmbeddedField } from '../util/orm.helper.js';
2
+ import { checkEnumValue, isColumnField, isEmbeddedField, resolveEntityForEmbeddedField, } from '../util/orm.helper.js';
5
3
  import { prepareFilter } from './command.helper.js';
6
4
  export class UpdateCommand {
7
5
  // istanbul ignore next
@@ -59,7 +57,7 @@ export class UpdateCommand {
59
57
  throw new Error(`${entity.name}.${col.name} is required and can't be null`);
60
58
  if (v === undefined)
61
59
  continue;
62
- ColumnFieldMetadata.checkEnumValue(col, v);
60
+ checkEnumValue(col, v);
63
61
  const fieldName = prefix + col.fieldName + suffix;
64
62
  const k = ('I$_' + fieldName).substring(0, 30);
65
63
  ctx.queryValues[fieldName] = Param({
@@ -71,7 +69,7 @@ export class UpdateCommand {
71
69
  ctx.colCount++;
72
70
  }
73
71
  else if (v != null && isEmbeddedField(col)) {
74
- const type = await EmbeddedFieldMetadata.resolveType(col);
72
+ const type = await resolveEntityForEmbeddedField(col);
75
73
  await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
76
74
  }
77
75
  }
@@ -1,12 +1,7 @@
1
1
  import { AssociationNode } from './association-node.js';
2
- import { EntityMetadata } from './entity-metadata.js';
3
2
  import { FieldMetadata } from './field-metadata.js';
4
3
  export type AssociationFieldOptions = Partial<Omit<AssociationFieldMetadata, 'entity' | 'name' | 'kind' | 'association'>>;
5
4
  export interface AssociationFieldMetadata extends FieldMetadata {
6
5
  readonly kind: 'association';
7
6
  readonly association: AssociationNode;
8
7
  }
9
- export declare namespace AssociationFieldMetadata {
10
- function create(entity: EntityMetadata, name: string, association: AssociationNode, options?: AssociationFieldOptions): AssociationFieldMetadata;
11
- function assign(target: AssociationFieldMetadata, options: AssociationFieldOptions): void;
12
- }
@@ -1,6 +1,6 @@
1
- import { AssociationSettings, TypeThunk } from '../orm.type.js';
2
- import { ColumnFieldMetadata } from './column-field-metadata.js';
3
- import { EntityMetadata } from './entity-metadata.js';
1
+ import type { AssociationSettings, TypeThunk } from '../orm.type.js';
2
+ import type { ColumnFieldMetadata } from './column-field-metadata.js';
3
+ import type { EntityMetadata } from './entity-metadata.js';
4
4
  export declare class Association {
5
5
  private _resolved?;
6
6
  private _source?;
@@ -1,6 +1,5 @@
1
1
  import { camelCase } from 'putil-varhelpers';
2
2
  import { resolveEntityMeta } from '../util/orm.helper.js';
3
- import { EntityMetadata } from './entity-metadata.js';
4
3
  export class Association {
5
4
  _resolved;
6
5
  _source; // cached value
@@ -59,6 +58,7 @@ export class Association {
59
58
  return this.many;
60
59
  }
61
60
  async _resolveKeys() {
61
+ const { EntityMetadata } = await import('../model/entity-metadata.js');
62
62
  if (this._resolved)
63
63
  return;
64
64
  const source = await this.resolveSource();
@@ -1,6 +1,5 @@
1
1
  import { DataType } from '@sqb/builder';
2
2
  import type { ColumnAutoGenerationStrategy, ColumnTransformFunction, DefaultValueGetter, EnumValue, FieldValue } from '../orm.type.js';
3
- import type { EntityMetadata } from './entity-metadata.js';
4
3
  import { FieldMetadata } from './field-metadata.js';
5
4
  export type ColumnFieldOptions = Partial<Omit<ColumnFieldMetadata, 'entity' | 'name' | 'kind'>>;
6
5
  export interface ColumnFieldMetadata extends FieldMetadata {
@@ -58,18 +57,13 @@ export interface ColumnFieldMetadata extends FieldMetadata {
58
57
  */
59
58
  notNull?: boolean;
60
59
  /**
61
- * Indicates if column value is used in update queries
60
+ * Indicates if the column value is used in update queries
62
61
  */
63
62
  noUpdate?: boolean;
64
63
  /**
65
- * Indicates if column value is used in insert queries
64
+ * Indicates if the column value is used in insert queries
66
65
  */
67
66
  noInsert?: boolean;
68
67
  parse?: ColumnTransformFunction;
69
68
  serialize?: ColumnTransformFunction;
70
69
  }
71
- export declare namespace ColumnFieldMetadata {
72
- function create(entity: EntityMetadata, name: string, options?: ColumnFieldOptions): ColumnFieldMetadata;
73
- function assign(target: ColumnFieldMetadata, options: ColumnFieldOptions): void;
74
- function checkEnumValue(col: ColumnFieldMetadata, v: FieldValue): void;
75
- }
@@ -9,6 +9,5 @@ export interface EmbeddedFieldMetadata extends FieldMetadata {
9
9
  fieldNameSuffix?: string;
10
10
  }
11
11
  export declare namespace EmbeddedFieldMetadata {
12
- function create(entity: EntityMetadata, name: string, type: TypeThunk, options?: EmbeddedFieldOptions): EmbeddedFieldMetadata;
13
12
  function resolveType(meta: EmbeddedFieldMetadata): Promise<EntityMetadata>;
14
13
  }
@@ -1,20 +1,6 @@
1
1
  import { resolveEntityMeta } from '../util/orm.helper.js';
2
2
  export var EmbeddedFieldMetadata;
3
3
  (function (EmbeddedFieldMetadata) {
4
- function create(entity, name, type, options) {
5
- const result = {
6
- kind: 'object',
7
- entity,
8
- name,
9
- type,
10
- };
11
- if (options?.fieldNamePrefix)
12
- result.fieldNamePrefix = options.fieldNamePrefix;
13
- if (options?.fieldNameSuffix)
14
- result.fieldNameSuffix = options.fieldNameSuffix;
15
- return result;
16
- }
17
- EmbeddedFieldMetadata.create = create;
18
4
  async function resolveType(meta) {
19
5
  const typ = await resolveEntityMeta(meta.type);
20
6
  if (typ)
@@ -1,10 +1,10 @@
1
1
  import { Maybe, Type } from 'ts-gems';
2
2
  import { Ctor, TypeThunk } from '../orm.type.js';
3
3
  import { Association } from './association.js';
4
- import { AssociationFieldMetadata, AssociationFieldOptions } from './association-field-metadata.js';
4
+ import type { AssociationFieldMetadata, AssociationFieldOptions } from './association-field-metadata.js';
5
5
  import { AssociationNode } from './association-node.js';
6
- import { ColumnFieldMetadata, ColumnFieldOptions } from './column-field-metadata.js';
7
- import { EmbeddedFieldMetadata, EmbeddedFieldOptions } from './embedded-field-metadata.js';
6
+ import type { ColumnFieldMetadata, ColumnFieldOptions } from './column-field-metadata.js';
7
+ import type { EmbeddedFieldMetadata, EmbeddedFieldOptions } from './embedded-field-metadata.js';
8
8
  import { IndexMetadata } from './index-metadata.js';
9
9
  export type AnyFieldMetadata = ColumnFieldMetadata | EmbeddedFieldMetadata | AssociationFieldMetadata;
10
10
  export type EntityOptions = Partial<Pick<EntityMetadata, 'name' | 'schema' | 'comment' | 'tableName'>>;
@@ -2,9 +2,6 @@ import { DataType } from '@sqb/builder';
2
2
  import { ENTITY_METADATA_KEY } from '../orm.const.js';
3
3
  import { isAssociationField, isColumnField, isEmbeddedField, } from '../util/orm.helper.js';
4
4
  import { Association } from './association.js';
5
- import { AssociationFieldMetadata, } from './association-field-metadata.js';
6
- import { ColumnFieldMetadata, } from './column-field-metadata.js';
7
- import { EmbeddedFieldMetadata, } from './embedded-field-metadata.js';
8
5
  export var EntityMetadata;
9
6
  (function (EntityMetadata) {
10
7
  function define(ctor) {
@@ -233,7 +230,13 @@ export var EntityMetadata;
233
230
  options.dataType = DataType.VARCHAR;
234
231
  }
235
232
  }
236
- prop = ColumnFieldMetadata.create(entity, name, options);
233
+ prop = {
234
+ fieldName: name,
235
+ ...options,
236
+ kind: 'column',
237
+ entity,
238
+ name,
239
+ };
237
240
  entity.fields[name.toLowerCase()] = prop;
238
241
  return prop;
239
242
  }
@@ -243,14 +246,26 @@ export var EntityMetadata;
243
246
  let prop = EntityMetadata.getField(entity, name);
244
247
  if (isEmbeddedField(prop))
245
248
  options = { ...prop, ...options };
246
- prop = EmbeddedFieldMetadata.create(entity, name, type, options);
249
+ prop = {
250
+ ...options,
251
+ kind: 'object',
252
+ entity,
253
+ name,
254
+ type,
255
+ };
247
256
  entity.fields[name.toLowerCase()] = prop;
248
257
  return prop;
249
258
  }
250
259
  EntityMetadata.defineEmbeddedField = defineEmbeddedField;
251
260
  function defineAssociationField(entity, propertyKey, association, options) {
252
261
  delete entity._fieldNames;
253
- const prop = AssociationFieldMetadata.create(entity, propertyKey, association, options);
262
+ const prop = {
263
+ ...options,
264
+ kind: 'association',
265
+ entity,
266
+ name: propertyKey,
267
+ association,
268
+ };
254
269
  let l = association;
255
270
  let i = 1;
256
271
  while (l) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,8 @@
1
1
  import { LogicalOperator } from '@sqb/builder';
2
2
  import { PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
3
3
  import { FieldInfoMap } from '../client/field-info-map.js';
4
- import { SqbClient } from '../client/sqb-client.js';
5
- import { SqbConnection } from '../client/sqb-connection.js';
4
+ import type { SqbClient } from '../client/sqb-client.js';
5
+ import type { 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 {
@@ -1,5 +1,4 @@
1
1
  import { AsyncEventEmitter, TypedEventEmitterClass } from 'strict-typed-events';
2
- import { SqbConnection } from '../client/sqb-connection.js';
3
2
  import { CountCommand } from './commands/count.command.js';
4
3
  import { CreateCommand } from './commands/create.command.js';
5
4
  import { DeleteCommand } from './commands/delete.command.js';
@@ -151,6 +150,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
151
150
  }
152
151
  async _execute(fn, opts) {
153
152
  let connection = opts?.connection;
153
+ const { SqbConnection } = await import('../client/sqb-connection.js');
154
154
  if (!connection && this._executor instanceof SqbConnection)
155
155
  connection = this._executor;
156
156
  if (connection) {
@@ -1,9 +1,9 @@
1
1
  import { Type } from 'ts-gems';
2
- import { AssociationFieldMetadata } from '../model/association-field-metadata.js';
2
+ import type { AssociationFieldMetadata } from '../model/association-field-metadata.js';
3
3
  import type { ColumnFieldMetadata } from '../model/column-field-metadata.js';
4
- import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
4
+ import type { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
5
5
  import type { EntityMetadata } from '../model/entity-metadata.js';
6
- import type { TypeThunk } from '../orm.type.js';
6
+ import type { FieldValue, TypeThunk } from '../orm.type.js';
7
7
  export declare function isClass(fn: any): fn is Type;
8
8
  export declare function isEntityClass(fn: any): fn is Type;
9
9
  export declare function isColumnField(f: any): f is ColumnFieldMetadata;
@@ -11,3 +11,5 @@ export declare const isEmbeddedField: (f: any) => f is EmbeddedFieldMetadata;
11
11
  export declare const isAssociationField: (f: any) => f is AssociationFieldMetadata;
12
12
  export declare function resolveEntity(ctorThunk: TypeThunk): Promise<Type | undefined>;
13
13
  export declare function resolveEntityMeta(ctorThunk: TypeThunk): Promise<EntityMetadata | undefined>;
14
+ export declare function resolveEntityForEmbeddedField(meta: EmbeddedFieldMetadata): Promise<EntityMetadata>;
15
+ export declare function checkEnumValue(col: ColumnFieldMetadata, v: FieldValue): void;
@@ -22,3 +22,17 @@ export async function resolveEntityMeta(ctorThunk) {
22
22
  const ctor = await resolveEntity(ctorThunk);
23
23
  return ctor && Reflect.getMetadata(ENTITY_METADATA_KEY, ctor);
24
24
  }
25
+ export async function resolveEntityForEmbeddedField(meta) {
26
+ const typ = await resolveEntityMeta(meta.type);
27
+ if (typ) {
28
+ return typ;
29
+ }
30
+ throw new Error(`Can't resolve type of ${meta.entity.name}.${meta.name}`);
31
+ }
32
+ export function checkEnumValue(col, v) {
33
+ if (v === undefined || !col.enum || (v == null && !col.notNull))
34
+ return;
35
+ const enumKeys = Array.isArray(col.enum) ? col.enum : Object.keys(col.enum);
36
+ if (!enumKeys.includes(v))
37
+ throw new Error(`${col.entity.name}.${col.name} value must be one of (${enumKeys})`);
38
+ }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@sqb/connect",
3
3
  "description": "Multi-dialect database connection framework written with TypeScript",
4
- "version": "4.20.6",
4
+ "version": "4.21.0",
5
5
  "author": "Panates",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
8
8
  "@jsopen/objects": "^2.0.2",
9
9
  "debug": "^4.4.3",
10
10
  "doublylinked": "^2.5.6",
11
- "fast-tokenizer": "^1.7.0",
11
+ "fast-tokenizer": "^1.8.0",
12
12
  "lightning-pool": "^4.12.0",
13
13
  "lodash": "^4.17.21",
14
14
  "power-tasks": "^1.11.1",
@@ -21,27 +21,22 @@
21
21
  "tslib": "^2.8.1"
22
22
  },
23
23
  "peerDependencies": {
24
- "@sqb/builder": "^4.20.6",
24
+ "@sqb/builder": "^4.21.0",
25
25
  "reflect-metadata": "^0.2.2"
26
26
  },
27
27
  "type": "module",
28
+ "module": "./index.js",
29
+ "types": "./index.d.ts",
28
30
  "exports": {
29
31
  ".": {
30
- "import": {
31
- "types": "./types/index.d.ts",
32
- "default": "./esm/index.js"
33
- },
34
- "require": {
35
- "types": "./types/index.d.cts",
36
- "default": "./cjs/index.js"
37
- },
38
- "default": "./esm/index.js"
32
+ "types": "./index.d.ts",
33
+ "default": "./index.js"
39
34
  },
40
35
  "./package.json": "./package.json"
41
36
  },
42
- "main": "./cjs/index.js",
43
- "module": "./esm/index.js",
44
- "types": "./types/index.d.ts",
37
+ "engines": {
38
+ "node": ">=20.0"
39
+ },
45
40
  "contributors": [
46
41
  "Eray Hanoglu <e.hanoglu@panates.com>",
47
42
  "Ilker Gurelli <i.gurelli@panates.com>"
@@ -51,17 +46,6 @@
51
46
  "url": "https://github.com/panates/sqb.git",
52
47
  "directory": "packages/connect"
53
48
  },
54
- "engines": {
55
- "node": ">=18.0"
56
- },
57
- "files": [
58
- "bin/",
59
- "cjs/",
60
- "esm/",
61
- "types/",
62
- "LICENSE",
63
- "README.md"
64
- ],
65
49
  "keywords": [
66
50
  "sqb",
67
51
  "rdbms",
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,104 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CursorStream = void 0;
4
- const tslib_1 = require("tslib");
5
- const debug_1 = tslib_1.__importDefault(require("debug"));
6
- const stream_1 = require("stream");
7
- const inspect = Symbol.for('nodejs.util.inspect.custom');
8
- const debug = (0, debug_1.default)('sqb:cursorstream');
9
- class CursorStream extends stream_1.Readable {
10
- _cursor;
11
- _objectMode;
12
- _limit;
13
- _rowNum = -1;
14
- _eof = false;
15
- constructor(cursor, options) {
16
- super(options);
17
- this._cursor = cursor;
18
- this._objectMode = options?.objectMode;
19
- this._limit = options?.limit || Number.MAX_SAFE_INTEGER;
20
- this.on('end', () => {
21
- this.close().catch(() => false);
22
- });
23
- cursor.once('close', () => this.emit('close'));
24
- cursor.on('error', err => this.emit('error', err));
25
- }
26
- /**
27
- * Returns if stream is closed.
28
- */
29
- get isClosed() {
30
- return this._cursor.isClosed;
31
- }
32
- /**
33
- * Closes stream and releases the cursor
34
- */
35
- close() {
36
- this.pause();
37
- this.unpipe();
38
- return this._cursor.close();
39
- }
40
- toString() {
41
- return '[object ' + Object.getPrototypeOf(this).constructor.name + ']';
42
- }
43
- [inspect]() {
44
- return this.toString();
45
- }
46
- _read() {
47
- if (this._rowNum >= this._limit) {
48
- this.pause();
49
- this.unpipe();
50
- this.emit('end');
51
- return;
52
- }
53
- this._cursor
54
- .next()
55
- .then(row => {
56
- if (this._eof)
57
- return this.push(null);
58
- let buf = '';
59
- if (this._rowNum < 0) {
60
- this._rowNum = 0;
61
- if (!this._objectMode)
62
- buf += '[';
63
- }
64
- if (!row) {
65
- this._eof = true;
66
- if (!this._objectMode) {
67
- buf += ']';
68
- this.push(buf);
69
- }
70
- else
71
- this.push(null);
72
- return;
73
- }
74
- this._rowNum++;
75
- if (this._objectMode)
76
- this.push(row);
77
- else {
78
- if (this._rowNum > 1)
79
- buf += ',';
80
- this.push(buf + JSON.stringify(row));
81
- }
82
- })
83
- .catch(err => {
84
- /* istanbul ignore next */
85
- if (typeof this.destroy == 'function')
86
- this.destroy(err);
87
- else
88
- this.emit('error', err);
89
- this.close().catch(() => 0);
90
- });
91
- }
92
- emit(event, ...args) {
93
- try {
94
- if (event === 'error' && !this.listenerCount('error'))
95
- return false;
96
- return super.emit(event, ...args);
97
- }
98
- catch (ignored) {
99
- debug('emit-error', ignored);
100
- return false;
101
- }
102
- }
103
- }
104
- exports.CursorStream = CursorStream;