@sqb/connect 4.14.0 → 4.15.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 (50) hide show
  1. package/cjs/client/sqb-connection.js +1 -1
  2. package/cjs/orm/repository.class.js +77 -19
  3. package/esm/client/adapter.js +2 -1
  4. package/esm/client/cursor-stream.js +9 -4
  5. package/esm/client/cursor.js +22 -17
  6. package/esm/client/extensions.js +5 -1
  7. package/esm/client/field-info-map.js +5 -1
  8. package/esm/client/helpers.js +19 -12
  9. package/esm/client/sqb-client.js +32 -27
  10. package/esm/client/sqb-connection.js +42 -37
  11. package/esm/client/types.js +5 -1
  12. package/esm/index.js +40 -32
  13. package/esm/orm/backward.js +19 -12
  14. package/esm/orm/base-entity.js +10 -6
  15. package/esm/orm/commands/command.helper.js +34 -28
  16. package/esm/orm/commands/count.command.js +10 -6
  17. package/esm/orm/commands/create.command.js +18 -14
  18. package/esm/orm/commands/delete.command.js +10 -6
  19. package/esm/orm/commands/find.command.js +34 -30
  20. package/esm/orm/commands/row-converter.js +7 -3
  21. package/esm/orm/commands/update.command.js +18 -14
  22. package/esm/orm/decorators/column.decorator.js +10 -7
  23. package/esm/orm/decorators/embedded.decorator.js +7 -4
  24. package/esm/orm/decorators/entity.decorator.js +56 -53
  25. package/esm/orm/decorators/events.decorator.js +27 -19
  26. package/esm/orm/decorators/foreignkey.decorator.js +7 -4
  27. package/esm/orm/decorators/index.decorator.js +9 -6
  28. package/esm/orm/decorators/link.decorator.js +11 -8
  29. package/esm/orm/decorators/primarykey.decorator.js +11 -8
  30. package/esm/orm/decorators/transform.decorator.js +11 -7
  31. package/esm/orm/model/association-field-metadata.js +8 -4
  32. package/esm/orm/model/association-node.js +6 -2
  33. package/esm/orm/model/association.js +20 -16
  34. package/esm/orm/model/column-field-metadata.js +8 -4
  35. package/esm/orm/model/embedded-field-metadata.js +7 -4
  36. package/esm/orm/model/entity-metadata.js +50 -47
  37. package/esm/orm/model/field-metadata.js +2 -1
  38. package/esm/orm/model/index-metadata.js +2 -1
  39. package/esm/orm/model/link-chain.js +8 -4
  40. package/esm/orm/orm.const.js +6 -3
  41. package/esm/orm/orm.type.js +2 -1
  42. package/esm/orm/repository.class.js +103 -41
  43. package/esm/orm/util/apply-mixins.js +4 -1
  44. package/esm/orm/util/extract-keyvalues.js +9 -6
  45. package/esm/orm/util/orm.helper.js +20 -10
  46. package/esm/orm/util/parse-fields-projection.js +11 -6
  47. package/esm/orm/util/serialize-field.js +13 -10
  48. package/package.json +30 -24
  49. package/types/orm/repository.class.d.ts +110 -11
  50. package/cjs/package.json +0 -3
@@ -1,5 +1,5 @@
1
1
  import { LogicalOperator } from '@sqb/builder';
2
- import { PartialDTO, PatchDTO, StrictOmit, Type } from 'ts-gems';
2
+ import { PartialDTO, PatchDTO, RequiredSome, 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';
@@ -54,6 +54,10 @@ interface RepositoryEvents {
54
54
  acquire: (connection: SqbConnection) => Promise<void>;
55
55
  }
56
56
  declare const Repository_base: Type<import("strict-typed-events").TypedEventEmitter<any, RepositoryEvents, RepositoryEvents>>;
57
+ /**
58
+ * @class Repository
59
+ * @template T - The data type class type of the record
60
+ */
57
61
  export declare class Repository<T> extends Repository_base {
58
62
  private readonly _executor;
59
63
  private readonly _entity;
@@ -61,19 +65,114 @@ export declare class Repository<T> extends Repository_base {
61
65
  constructor(entityDef: EntityMetadata, executor: SqbClient | SqbConnection, schema?: string);
62
66
  get entity(): EntityMetadata;
63
67
  get type(): Type<T>;
64
- create(values: PartialDTO<T>, options?: Repository.CreateOptions): Promise<PartialDTO<T>>;
65
- createOnly(values: PartialDTO<T>, options?: StrictOmit<Repository.CreateOptions, keyof Projection>): Promise<void>;
66
- exists(keyValue: any | Record<string, any>, options?: Repository.ExistsOptions): Promise<boolean>;
67
- existsOne(options?: Repository.ExistsOptions): Promise<boolean>;
68
+ /**
69
+ * Creates a new resource
70
+ *
71
+ * @param {PartialDTO<T>} input - The input data
72
+ * @param {Repository.CreateOptions} [options] - The options object
73
+ * @returns {Promise<PartialDTO<T>>} A promise that resolves to the created resource
74
+ * @throws {Error} if an unknown error occurs while creating the resource
75
+ */
76
+ create(input: PartialDTO<T>, options: RequiredSome<Repository.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
77
+ create(input: PartialDTO<T>, options?: Repository.CreateOptions): Promise<T>;
78
+ /**
79
+ * Creates a new resource but returns nothing
80
+ *
81
+ * @param {PartialDTO<T>} input - The input data
82
+ * @param {Repository.CreateOptions} [options] - The options object
83
+ * @throws {Error} if an unknown error occurs while creating the resource
84
+ */
85
+ createOnly(input: PartialDTO<T>, options?: StrictOmit<Repository.CreateOptions, keyof Projection>): Promise<void>;
86
+ /**
87
+ * Returns the count of records based on the provided options
88
+ *
89
+ * @param {Repository.CountOptions} options - The options for the count operation.
90
+ * @return {Promise<number>} - A promise that resolves to the count of records
91
+ */
68
92
  count(options?: Repository.CountOptions): Promise<number>;
69
- findById(keyValue: any | Record<string, any>, options?: Repository.FindOptions): Promise<PartialDTO<T> | undefined>;
70
- findOne(options?: Repository.FindOneOptions): Promise<PartialDTO<T> | undefined>;
71
- findMany(options?: Repository.FindManyOptions): Promise<PartialDTO<T>[]>;
93
+ /**
94
+ * Deletes a record from the collection.
95
+ *
96
+ * @param {any} keyValue - The ID of the resource to delete.
97
+ * @param {Repository.DeleteOptions} [options] - Optional delete options.
98
+ * @return {Promise<boolean>} - A Promise that resolves true or false. True when resource deleted.
99
+ */
72
100
  delete(keyValue: any | Record<string, any>, options?: Repository.DeleteOptions): Promise<boolean>;
101
+ /**
102
+ * Deletes multiple documents from the collection that meet the specified filter criteria.
103
+ *
104
+ * @param {Repository.DeleteManyOptions} options - The options for the delete operation.
105
+ * @return {Promise<number>} - A promise that resolves to the number of resources deleted.
106
+ */
73
107
  deleteMany(options?: Repository.DeleteManyOptions): Promise<number>;
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?: Repository.UpdateOnlyOptions): Promise<boolean>;
76
- updateMany(values: PartialDTO<T>, options?: Repository.UpdateManyOptions): Promise<number>;
108
+ /**
109
+ * Checks if a record with the given id exists.
110
+ *
111
+ * @param {any} keyValue - The id of the object to check.
112
+ * @param {Repository.ExistsOptions} [options] - The options for the query (optional).
113
+ * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
114
+ */
115
+ exists(keyValue: any | Record<string, any>, options?: Repository.ExistsOptions): Promise<boolean>;
116
+ /**
117
+ * Checks if a record with the given arguments exists.
118
+ *
119
+ * @param {Repository.ExistsOptions} [options] - The options for the query (optional).
120
+ * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
121
+ */
122
+ existsOne(options?: Repository.ExistsOptions): Promise<boolean>;
123
+ /**
124
+ * Finds a record by ID.
125
+ *
126
+ * @param {any} keyValue - The ID of the record.
127
+ * @param {Repository.FindOneOptions} [options] - The options for the find query.
128
+ * @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
129
+ */
130
+ findById(keyValue: any | Record<string, any>, options: RequiredSome<Repository.FindOptions, 'projection'>): Promise<PartialDTO<T> | undefined>;
131
+ findById(keyValue: any | Record<string, any>, options?: Repository.FindOptions): Promise<T | undefined>;
132
+ /**
133
+ * Finds a record in the collection that matches the specified options.
134
+ *
135
+ * @param {Repository.FindOneOptions} options - The options for the query.
136
+ * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
137
+ */
138
+ findOne(options: RequiredSome<Repository.FindOneOptions, 'projection'>): Promise<PartialDTO<T> | undefined>;
139
+ findOne(options?: Repository.FindOneOptions): Promise<T | undefined>;
140
+ /**
141
+ * Finds multiple records in collection.
142
+ *
143
+ * @param {Repository.FindManyOptions} options - The options for the find operation.
144
+ * @return A Promise that resolves to an array of partial outputs of type T.
145
+ */
146
+ findMany(options: RequiredSome<Repository.FindManyOptions, 'projection'>): Promise<PartialDTO<T>[]>;
147
+ findMany(options?: Repository.FindManyOptions): Promise<T[]>;
148
+ /**
149
+ * Updates a record with the given id in the collection.
150
+ *
151
+ * @param {any} keyValue - The id of the document to update.
152
+ * @param {PatchDTO<T>} input - The partial input object containing the fields to update.
153
+ * @param {Repository.UpdateOptions} [options] - The options for the update operation.
154
+ * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
155
+ * undefined if the document was not found.
156
+ */
157
+ update(keyValue: any | Record<string, any>, input: PatchDTO<T>, options: RequiredSome<Repository.UpdateOptions, 'projection'>): Promise<PartialDTO<T> | undefined>;
158
+ update(keyValue: any | Record<string, any>, input: PatchDTO<T>, options?: Repository.UpdateOptions): Promise<T | undefined>;
159
+ /**
160
+ * Updates a record in the collection with the specified ID and returns updated record count
161
+ *
162
+ * @param {any} keyValue - The ID of the document to update.
163
+ * @param {PatchDTO<T>} input - The partial input data to update the document with.
164
+ * @param {Repository.UpdateOptions} options - The options for updating the document.
165
+ * @returns {Promise<number>} - A Promise that resolves true or false. True when resource updated.
166
+ */
167
+ updateOnly(keyValue: any | Record<string, any>, input: PatchDTO<T>, options?: Repository.UpdateOnlyOptions): Promise<boolean>;
168
+ /**
169
+ * Updates multiple records in the collection based on the specified input and options.
170
+ *
171
+ * @param {PatchDTO<T>} input - The partial input to update the documents with.
172
+ * @param {Repository.UpdateManyOptions} options - The options for updating the documents.
173
+ * @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
174
+ */
175
+ updateMany(input: PartialDTO<T>, options?: Repository.UpdateManyOptions): Promise<number>;
77
176
  protected _execute(fn: TransactionFunction, opts?: Repository.CommandOptions): Promise<any>;
78
177
  protected _create(values: PartialDTO<T>, options: Repository.CreateOptions & {
79
178
  connection: SqbConnection;
package/cjs/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }