@venizia/ignis 0.0.5-2 → 0.0.5-20
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/dist/base/applications/abstract.d.ts.map +1 -1
- package/dist/base/applications/abstract.js +1 -0
- package/dist/base/applications/abstract.js.map +1 -1
- package/dist/base/applications/base.d.ts.map +1 -1
- package/dist/base/applications/base.js +8 -1
- package/dist/base/applications/base.js.map +1 -1
- package/dist/base/applications/types.d.ts +10 -1
- package/dist/base/applications/types.d.ts.map +1 -1
- package/dist/base/controllers/abstract.d.ts +1 -0
- package/dist/base/controllers/abstract.d.ts.map +1 -1
- package/dist/base/controllers/abstract.js +12 -1
- package/dist/base/controllers/abstract.js.map +1 -1
- package/dist/base/controllers/common/types.d.ts +5 -1
- package/dist/base/controllers/common/types.d.ts.map +1 -1
- package/dist/base/controllers/factory/controller.d.ts +15 -6
- package/dist/base/controllers/factory/controller.d.ts.map +1 -1
- package/dist/base/controllers/factory/controller.js +46 -21
- package/dist/base/controllers/factory/controller.js.map +1 -1
- package/dist/base/datasources/base.d.ts.map +1 -1
- package/dist/base/datasources/base.js +10 -1
- package/dist/base/datasources/base.js.map +1 -1
- package/dist/base/metadata/index.d.ts +1 -0
- package/dist/base/metadata/index.d.ts.map +1 -1
- package/dist/base/metadata/index.js +1 -0
- package/dist/base/metadata/index.js.map +1 -1
- package/dist/base/metadata/request-context.d.ts +3 -0
- package/dist/base/metadata/request-context.d.ts.map +1 -0
- package/dist/base/metadata/request-context.js +9 -0
- package/dist/base/metadata/request-context.js.map +1 -0
- package/dist/base/metadata/routes.d.ts +30 -40
- package/dist/base/metadata/routes.d.ts.map +1 -1
- package/dist/base/metadata/routes.js +15 -5
- package/dist/base/metadata/routes.js.map +1 -1
- package/dist/base/middlewares/app-error.middleware.d.ts +1 -0
- package/dist/base/middlewares/app-error.middleware.d.ts.map +1 -1
- package/dist/base/middlewares/app-error.middleware.js +10 -8
- package/dist/base/middlewares/app-error.middleware.js.map +1 -1
- package/dist/base/middlewares/request-spy.middleware.d.ts.map +1 -1
- package/dist/base/middlewares/request-spy.middleware.js +12 -0
- package/dist/base/middlewares/request-spy.middleware.js.map +1 -1
- package/dist/base/mixins/component.mixin.d.ts.map +1 -1
- package/dist/base/mixins/controller.mixin.d.ts.map +1 -1
- package/dist/base/mixins/repository.mixin.d.ts.map +1 -1
- package/dist/base/mixins/service.mixin.d.ts.map +1 -1
- package/dist/base/models/enrichers/id.enricher.d.ts +15 -10
- package/dist/base/models/enrichers/id.enricher.d.ts.map +1 -1
- package/dist/base/models/enrichers/id.enricher.js +3 -3
- package/dist/base/models/enrichers/id.enricher.js.map +1 -1
- package/dist/base/models/enrichers/principal.enricher.d.ts +7 -9
- package/dist/base/models/enrichers/principal.enricher.d.ts.map +1 -1
- package/dist/base/models/enrichers/principal.enricher.js.map +1 -1
- package/dist/base/models/enrichers/user-audit.enricher.d.ts +3 -2
- package/dist/base/models/enrichers/user-audit.enricher.d.ts.map +1 -1
- package/dist/base/models/enrichers/user-audit.enricher.js +47 -11
- package/dist/base/models/enrichers/user-audit.enricher.js.map +1 -1
- package/dist/base/repositories/common/constants.d.ts +59 -0
- package/dist/base/repositories/common/constants.d.ts.map +1 -1
- package/dist/base/repositories/common/constants.js +51 -2
- package/dist/base/repositories/common/constants.js.map +1 -1
- package/dist/base/repositories/common/types.d.ts +482 -44
- package/dist/base/repositories/common/types.d.ts.map +1 -1
- package/dist/base/repositories/common/types.js +164 -17
- package/dist/base/repositories/common/types.js.map +1 -1
- package/dist/base/repositories/core/abstract.d.ts +450 -0
- package/dist/base/repositories/core/abstract.d.ts.map +1 -0
- package/dist/base/repositories/core/abstract.js +287 -0
- package/dist/base/repositories/core/abstract.js.map +1 -0
- package/dist/base/repositories/core/default-crud.d.ts +2 -2
- package/dist/base/repositories/core/default-crud.d.ts.map +1 -1
- package/dist/base/repositories/core/index.d.ts +1 -1
- package/dist/base/repositories/core/index.d.ts.map +1 -1
- package/dist/base/repositories/core/index.js +1 -1
- package/dist/base/repositories/core/index.js.map +1 -1
- package/dist/base/repositories/core/persistable.d.ts +91 -36
- package/dist/base/repositories/core/persistable.d.ts.map +1 -1
- package/dist/base/repositories/core/persistable.js +139 -37
- package/dist/base/repositories/core/persistable.js.map +1 -1
- package/dist/base/repositories/core/readable.d.ts +166 -62
- package/dist/base/repositories/core/readable.d.ts.map +1 -1
- package/dist/base/repositories/core/readable.js +185 -56
- package/dist/base/repositories/core/readable.js.map +1 -1
- package/dist/base/repositories/mixins/default-filter.d.ts +65 -0
- package/dist/base/repositories/mixins/default-filter.d.ts.map +1 -0
- package/dist/base/repositories/mixins/default-filter.js +97 -0
- package/dist/base/repositories/mixins/default-filter.js.map +1 -0
- package/dist/base/repositories/mixins/fields-visibility.d.ts +74 -0
- package/dist/base/repositories/mixins/fields-visibility.d.ts.map +1 -0
- package/dist/base/repositories/mixins/fields-visibility.js +129 -0
- package/dist/base/repositories/mixins/fields-visibility.js.map +1 -0
- package/dist/base/repositories/mixins/index.d.ts +3 -0
- package/dist/base/repositories/mixins/index.d.ts.map +1 -0
- package/dist/base/repositories/mixins/index.js +19 -0
- package/dist/base/repositories/mixins/index.js.map +1 -0
- package/dist/base/repositories/operators/filter.d.ts +146 -12
- package/dist/base/repositories/operators/filter.d.ts.map +1 -1
- package/dist/base/repositories/operators/filter.js +432 -112
- package/dist/base/repositories/operators/filter.js.map +1 -1
- package/dist/base/repositories/operators/query.d.ts +69 -0
- package/dist/base/repositories/operators/query.d.ts.map +1 -1
- package/dist/base/repositories/operators/query.js +190 -2
- package/dist/base/repositories/operators/query.js.map +1 -1
- package/dist/base/repositories/operators/relation.d.ts +33 -0
- package/dist/base/repositories/operators/relation.d.ts.map +1 -1
- package/dist/base/repositories/operators/relation.js +36 -0
- package/dist/base/repositories/operators/relation.js.map +1 -1
- package/dist/common/statuses.d.ts +26 -7
- package/dist/common/statuses.d.ts.map +1 -1
- package/dist/common/statuses.js +96 -9
- package/dist/common/statuses.js.map +1 -1
- package/dist/components/auth/authenticate/common/constants.d.ts +1 -0
- package/dist/components/auth/authenticate/common/constants.d.ts.map +1 -1
- package/dist/components/auth/authenticate/common/constants.js +1 -0
- package/dist/components/auth/authenticate/common/constants.js.map +1 -1
- package/dist/components/auth/authenticate/common/types.d.ts +7 -0
- package/dist/components/auth/authenticate/common/types.d.ts.map +1 -1
- package/dist/components/auth/authenticate/controllers/factory.d.ts +1 -0
- package/dist/components/auth/authenticate/controllers/factory.d.ts.map +1 -1
- package/dist/components/auth/authenticate/strategies/strategy-registry.d.ts.map +1 -1
- package/dist/components/auth/authenticate/strategies/strategy-registry.js +3 -0
- package/dist/components/auth/authenticate/strategies/strategy-registry.js.map +1 -1
- package/dist/components/auth/models/entities/user-role.model.d.ts +1 -1
- package/dist/components/auth/models/entities/user-role.model.d.ts.map +1 -1
- package/dist/components/auth/models/entities/user-role.model.js +1 -1
- package/dist/components/auth/models/entities/user-role.model.js.map +1 -1
- package/dist/components/health-check/controller.d.ts +4 -5
- package/dist/components/health-check/controller.d.ts.map +1 -1
- package/dist/components/health-check/controller.js +12 -12
- package/dist/components/health-check/controller.js.map +1 -1
- package/dist/components/static-asset/component.d.ts +0 -1
- package/dist/components/static-asset/component.d.ts.map +1 -1
- package/dist/components/static-asset/component.js +0 -2
- package/dist/components/static-asset/component.js.map +1 -1
- package/dist/components/static-asset/controller/factory.d.ts +1 -0
- package/dist/components/static-asset/controller/factory.d.ts.map +1 -1
- package/dist/components/static-asset/controller/factory.js +1 -1
- package/dist/components/static-asset/controller/factory.js.map +1 -1
- package/dist/components/static-asset/models/base.model.d.ts +10 -10
- package/dist/components/static-asset/models/base.model.js +1 -1
- package/dist/components/static-asset/models/base.model.js.map +1 -1
- package/dist/helpers/inversion/common/types.d.ts +35 -1
- package/dist/helpers/inversion/common/types.d.ts.map +1 -1
- package/package.json +4 -5
- package/dist/base/repositories/core/base.d.ts +0 -264
- package/dist/base/repositories/core/base.d.ts.map +0 -1
- package/dist/base/repositories/core/base.js +0 -197
- package/dist/base/repositories/core/base.js.map +0 -1
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractRepository = void 0;
|
|
4
|
+
const inversion_1 = require("../../../helpers/inversion");
|
|
5
|
+
const ignis_helpers_1 = require("@venizia/ignis-helpers");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
const mixins_1 = require("../mixins");
|
|
8
|
+
const operators_1 = require("../operators");
|
|
9
|
+
// -----------------------------------------------------------------------------
|
|
10
|
+
// Abstract Repository
|
|
11
|
+
// -----------------------------------------------------------------------------
|
|
12
|
+
/**
|
|
13
|
+
* Abstract base repository class with dependency injection support.
|
|
14
|
+
*
|
|
15
|
+
* This class provides the foundation for all repository implementations,
|
|
16
|
+
* combining {@link FieldsVisibilityMixin} and {@link DefaultFilterMixin}
|
|
17
|
+
* for automatic hidden field exclusion and default filter application.
|
|
18
|
+
*
|
|
19
|
+
* @template EntitySchema - The Drizzle table schema type with an 'id' column
|
|
20
|
+
* @template DataObject - The type of objects returned from queries
|
|
21
|
+
* @template PersistObject - The type for insert/update operations
|
|
22
|
+
* @template ExtraOptions - Additional options type extending IExtraOptions
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* **1. Zero boilerplate - dataSource auto-injected from @repository metadata:**
|
|
26
|
+
* ```typescript
|
|
27
|
+
* @repository({ model: User, dataSource: PostgresDataSource })
|
|
28
|
+
* export class UserRepository extends DefaultCRUDRepository<typeof User.schema> {
|
|
29
|
+
* // No constructor needed - datasource auto-injected!
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* **2. Explicit @inject:**
|
|
35
|
+
* ```typescript
|
|
36
|
+
* @repository({ model: User })
|
|
37
|
+
* export class UserRepository extends DefaultCRUDRepository<typeof User.schema> {
|
|
38
|
+
* constructor(
|
|
39
|
+
* @inject({ key: 'datasources.PostgresDataSource' })
|
|
40
|
+
* dataSource: PostgresDataSource,
|
|
41
|
+
* ) {
|
|
42
|
+
* super(dataSource);
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
class AbstractRepository extends (0, mixins_1.DefaultFilterMixin)((0, mixins_1.FieldsVisibilityMixin)(ignis_helpers_1.BaseHelper)) {
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Constructor
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new repository instance.
|
|
53
|
+
*
|
|
54
|
+
* @param ds - DataSource (auto-injected from @repository decorator or passed explicitly)
|
|
55
|
+
* @param opts - Optional configuration
|
|
56
|
+
* @param opts.scope - Custom scope name for logging
|
|
57
|
+
* @param opts.entityClass - Entity class if not using @repository decorator
|
|
58
|
+
* @param opts.operationScope - Operation scope (defaults to READ_ONLY)
|
|
59
|
+
*/
|
|
60
|
+
constructor(ds, opts) {
|
|
61
|
+
const scopeName = (opts?.scope ?? opts?.entityClass?.name)
|
|
62
|
+
? [opts?.entityClass?.name, 'Repository'].join('')
|
|
63
|
+
: new.target.name;
|
|
64
|
+
super({ scope: scopeName });
|
|
65
|
+
this._operationScope = opts?.operationScope ?? common_1.RepositoryOperationScopes.READ_ONLY;
|
|
66
|
+
this._filterBuilder = new operators_1.FilterBuilder();
|
|
67
|
+
if (ds) {
|
|
68
|
+
this._dataSource = ds;
|
|
69
|
+
}
|
|
70
|
+
if (opts?.entityClass) {
|
|
71
|
+
this._entity = new opts.entityClass();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Public Accessors
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
/**
|
|
78
|
+
* Gets the data source for database operations.
|
|
79
|
+
* @throws Error if dataSource is not available
|
|
80
|
+
*/
|
|
81
|
+
get dataSource() {
|
|
82
|
+
if (!this._dataSource) {
|
|
83
|
+
throw (0, ignis_helpers_1.getError)({
|
|
84
|
+
message: `[${this.constructor.name}] DataSource not available. Use @repository({ model: YourModel, dataSource: YourDataSource }) or pass dataSource in constructor.`,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return this._dataSource;
|
|
88
|
+
}
|
|
89
|
+
/** Sets the data source for database operations. */
|
|
90
|
+
set dataSource(value) {
|
|
91
|
+
this._dataSource = value;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Gets the entity instance.
|
|
95
|
+
* Auto-resolves from @repository metadata if not explicitly set.
|
|
96
|
+
*/
|
|
97
|
+
get entity() {
|
|
98
|
+
if (!this._entity) {
|
|
99
|
+
this._entity = this.resolveEntity();
|
|
100
|
+
}
|
|
101
|
+
return this._entity;
|
|
102
|
+
}
|
|
103
|
+
/** Sets the entity instance. */
|
|
104
|
+
set entity(value) {
|
|
105
|
+
this._entity = value;
|
|
106
|
+
}
|
|
107
|
+
/** Gets the current operation scope (READ_ONLY, WRITE_ONLY, or READ_WRITE). */
|
|
108
|
+
get operationScope() {
|
|
109
|
+
return this._operationScope;
|
|
110
|
+
}
|
|
111
|
+
/** Gets the filter builder instance. */
|
|
112
|
+
get filterBuilder() {
|
|
113
|
+
return this._filterBuilder;
|
|
114
|
+
}
|
|
115
|
+
/** Gets the database connector from the data source. */
|
|
116
|
+
get connector() {
|
|
117
|
+
return this.dataSource.connector;
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// Public Instance Methods
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
/**
|
|
123
|
+
* Sets the data source for this repository.
|
|
124
|
+
* @param opts - Options containing the data source
|
|
125
|
+
*/
|
|
126
|
+
setDataSource(opts) {
|
|
127
|
+
this._dataSource = opts.dataSource;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns the entity instance associated with this repository.
|
|
131
|
+
* @returns The entity instance
|
|
132
|
+
*/
|
|
133
|
+
getEntity() {
|
|
134
|
+
return this.entity;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns the Drizzle table schema for this entity.
|
|
138
|
+
* @returns The table schema
|
|
139
|
+
*/
|
|
140
|
+
getEntitySchema() {
|
|
141
|
+
return this.entity.schema;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns the database connector from the data source.
|
|
145
|
+
* @returns The database connector
|
|
146
|
+
*/
|
|
147
|
+
getConnector() {
|
|
148
|
+
return this.connector;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Begins a new database transaction.
|
|
152
|
+
* @param opts - Optional transaction configuration
|
|
153
|
+
* @returns Promise resolving to the transaction instance
|
|
154
|
+
*/
|
|
155
|
+
async beginTransaction(opts) {
|
|
156
|
+
return this.dataSource.beginTransaction(opts);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Builds Drizzle query options from a filter object.
|
|
160
|
+
* Handles field visibility by excluding hidden properties.
|
|
161
|
+
*
|
|
162
|
+
* @param opts - Options containing the filter to convert
|
|
163
|
+
* @returns Drizzle-compatible query options
|
|
164
|
+
*/
|
|
165
|
+
buildQuery(opts) {
|
|
166
|
+
const result = this.filterBuilder.build({
|
|
167
|
+
tableName: this.entity.name,
|
|
168
|
+
schema: this.entity.schema,
|
|
169
|
+
filter: opts.filter,
|
|
170
|
+
});
|
|
171
|
+
if (!this.hasHiddenProperties()) {
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
const hiddenProps = this.getHiddenProperties();
|
|
175
|
+
if (result.columns) {
|
|
176
|
+
// User specified fields - filter out hidden (single loop)
|
|
177
|
+
const filteredColumns = {};
|
|
178
|
+
for (const key in result.columns) {
|
|
179
|
+
if (!hiddenProps.has(key)) {
|
|
180
|
+
filteredColumns[key] = result.columns[key];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
result.columns = filteredColumns;
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
// No fields specified - use cached visible properties keys
|
|
187
|
+
const visibleProps = this.getVisibleProperties();
|
|
188
|
+
if (visibleProps) {
|
|
189
|
+
const filteredColumns = {};
|
|
190
|
+
for (const key in visibleProps) {
|
|
191
|
+
filteredColumns[key] = true;
|
|
192
|
+
}
|
|
193
|
+
result.columns = filteredColumns;
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
// Entity Resolution (protected)
|
|
199
|
+
// ---------------------------------------------------------------------------
|
|
200
|
+
/**
|
|
201
|
+
* Resolves the entity instance from @repository metadata.
|
|
202
|
+
* Called lazily when entity is first accessed.
|
|
203
|
+
*
|
|
204
|
+
* @returns The resolved entity instance
|
|
205
|
+
* @throws Error if entity cannot be resolved from metadata
|
|
206
|
+
*/
|
|
207
|
+
resolveEntity() {
|
|
208
|
+
const registry = inversion_1.MetadataRegistry.getInstance();
|
|
209
|
+
const binding = registry.getRepositoryBinding({
|
|
210
|
+
name: this.constructor.name,
|
|
211
|
+
});
|
|
212
|
+
if (!binding?.model) {
|
|
213
|
+
throw (0, ignis_helpers_1.getError)({
|
|
214
|
+
message: `[${this.constructor.name}] Cannot resolve entity. Either pass entityClass in constructor or use @repository decorator with model option.`,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
// Cast to TClass - at runtime this is always a class constructor
|
|
218
|
+
const ctor = (0, ignis_helpers_1.resolveValue)(binding.model);
|
|
219
|
+
return new ctor();
|
|
220
|
+
}
|
|
221
|
+
// ---------------------------------------------------------------------------
|
|
222
|
+
// Transaction Support (protected)
|
|
223
|
+
// ---------------------------------------------------------------------------
|
|
224
|
+
/**
|
|
225
|
+
* Resolves the database connector, using transaction connector if provided.
|
|
226
|
+
*
|
|
227
|
+
* @param opts - Options containing optional transaction
|
|
228
|
+
* @returns The database connector (from transaction or default data source)
|
|
229
|
+
* @throws Error if transaction is no longer active
|
|
230
|
+
*/
|
|
231
|
+
resolveConnector(opts) {
|
|
232
|
+
const transaction = opts?.transaction;
|
|
233
|
+
if (!transaction) {
|
|
234
|
+
return this.dataSource.connector;
|
|
235
|
+
}
|
|
236
|
+
if (!transaction.isActive) {
|
|
237
|
+
throw (0, ignis_helpers_1.getError)({
|
|
238
|
+
message: `[${this.constructor.name}][resolveConnector] Transaction is no longer active`,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return transaction.connector;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Gets the Drizzle query interface for this entity.
|
|
245
|
+
* Validates that the schema is properly registered in the connector.
|
|
246
|
+
*
|
|
247
|
+
* @param opts - Options containing extra options with optional transaction
|
|
248
|
+
* @returns The Drizzle query interface for this entity
|
|
249
|
+
* @throws Error if connector.query is not available
|
|
250
|
+
* @throws Error if entity schema is not registered in connector
|
|
251
|
+
*/
|
|
252
|
+
getQueryInterface(opts) {
|
|
253
|
+
const connector = this.resolveConnector({ transaction: opts?.options?.transaction });
|
|
254
|
+
// Validate connector.query exists
|
|
255
|
+
if (!connector.query) {
|
|
256
|
+
throw (0, ignis_helpers_1.getError)({
|
|
257
|
+
message: `[${this.constructor.name}] Connector query interface not available | Ensure datasource is properly configured with schema`,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
const queryInterface = connector.query[this.entity.name];
|
|
261
|
+
if (!queryInterface) {
|
|
262
|
+
const availableKeys = Object.keys(connector.query);
|
|
263
|
+
throw (0, ignis_helpers_1.getError)({
|
|
264
|
+
message: `[${this.constructor.name}] Schema key mismatch | Entity name '${this.entity.name}' not found in connector.query | Available keys: [${availableKeys.join(', ')}] | Ensure the model's TABLE_NAME matches the schema registration key`,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return queryInterface;
|
|
268
|
+
}
|
|
269
|
+
updateBy(opts) {
|
|
270
|
+
if (opts.options?.shouldReturn === false) {
|
|
271
|
+
const strictOpts = opts;
|
|
272
|
+
return this.updateAll(strictOpts);
|
|
273
|
+
}
|
|
274
|
+
const strictOpts = opts;
|
|
275
|
+
return this.updateAll(strictOpts);
|
|
276
|
+
}
|
|
277
|
+
deleteBy(opts) {
|
|
278
|
+
if (opts.options?.shouldReturn === false) {
|
|
279
|
+
const strictOpts = opts;
|
|
280
|
+
return this.deleteAll(strictOpts);
|
|
281
|
+
}
|
|
282
|
+
const strictOpts = opts;
|
|
283
|
+
return this.deleteAll(strictOpts);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
exports.AbstractRepository = AbstractRepository;
|
|
287
|
+
//# sourceMappingURL=abstract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../src/base/repositories/core/abstract.ts"],"names":[],"mappings":";;;AAEA,mDAAuD;AACvD,0DAA+F;AAC/F,sCAWmB;AACnB,sCAAsE;AACtE,4CAA6C;AAE7C,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAsB,kBAMpB,SAAQ,IAAA,2BAAkB,EAAC,IAAA,8BAAqB,EAAC,0BAAU,CAAC,CAAC;IA+B7D,8EAA8E;IAC9E,cAAc;IACd,8EAA8E;IAE9E;;;;;;;;OAQG;IACH,YACE,EAAgB,EAChB,IAIC;QAED,MAAM,SAAS,GACb,CAAC,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC;YACtC,CAAC,CAAC,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;YAClD,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAEtB,KAAK,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAE5B,IAAI,CAAC,eAAe,GAAG,IAAI,EAAE,cAAc,IAAI,kCAAyB,CAAC,SAAS,CAAC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AAO,IAAI,CAAC,SAAS,CAAI,UAAU,CAAC,CAAC;IACvC,CAAC;IAsDD,QAAQ,CAAiB,IAGxB;QACC,IAAI,IAAI,CAAC,OAAO,EAAE,YAAY,KAAK,KAAK,EAAE,CAAC;YACzC,MAAM,UAAU,GAAG,IAGlB,CAAC;YACF,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC;QAED,MAAM,UAAU,GAAG,IAGlB,CAAC;QACF,OAAO,IAAI,CAAC,SAAS,CAAI,UAAU,CAAC,CAAC;IACvC,CAAC;CACF;AA/iBD,gDA+iBC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TTableInsert, TTableObject, TTableSchemaWithId } from '../../../base/models';
|
|
2
|
-
import {
|
|
2
|
+
import { IExtraOptions } from '../common';
|
|
3
3
|
import { PersistableRepository } from './persistable';
|
|
4
4
|
/**
|
|
5
5
|
* Default CRUD repository with dependency injection support.
|
|
@@ -37,6 +37,6 @@ import { PersistableRepository } from './persistable';
|
|
|
37
37
|
* ```
|
|
38
38
|
* Note: When @inject is at param index 0, auto-injection is skipped (your @inject takes precedence).
|
|
39
39
|
*/
|
|
40
|
-
export declare class DefaultCRUDRepository<EntitySchema extends TTableSchemaWithId = TTableSchemaWithId, DataObject extends TTableObject<EntitySchema> = TTableObject<EntitySchema>, PersistObject extends TTableInsert<EntitySchema> = TTableInsert<EntitySchema>, ExtraOptions extends
|
|
40
|
+
export declare class DefaultCRUDRepository<EntitySchema extends TTableSchemaWithId = TTableSchemaWithId, DataObject extends TTableObject<EntitySchema> = TTableObject<EntitySchema>, PersistObject extends TTableInsert<EntitySchema> = TTableInsert<EntitySchema>, ExtraOptions extends IExtraOptions = IExtraOptions> extends PersistableRepository<EntitySchema, DataObject, PersistObject, ExtraOptions> {
|
|
41
41
|
}
|
|
42
42
|
//# sourceMappingURL=default-crud.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-crud.d.ts","sourceRoot":"","sources":["../../../../src/base/repositories/core/default-crud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"default-crud.d.ts","sourceRoot":"","sources":["../../../../src/base/repositories/core/default-crud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,qBAAqB,CAChC,YAAY,SAAS,kBAAkB,GAAG,kBAAkB,EAC5D,UAAU,SAAS,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,EAC1E,aAAa,SAAS,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,EAC7E,YAAY,SAAS,aAAa,GAAG,aAAa,CAClD,SAAQ,qBAAqB,CAAC,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,CAAC;CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/base/repositories/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/base/repositories/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./abstract"), exports);
|
|
18
18
|
__exportStar(require("./default-crud"), exports);
|
|
19
19
|
__exportStar(require("./persistable"), exports);
|
|
20
20
|
__exportStar(require("./readable"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/base/repositories/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/base/repositories/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,iDAA+B;AAC/B,gDAA8B;AAC9B,6CAA2B"}
|
|
@@ -1,16 +1,68 @@
|
|
|
1
1
|
import { IDataSource } from '../../../base/datasources';
|
|
2
2
|
import { BaseEntity, IdType, TTableInsert, TTableObject, TTableSchemaWithId } from '../../../base/models';
|
|
3
3
|
import { TClass, TNullable } from '@venizia/ignis-helpers';
|
|
4
|
-
import { TCount, TRepositoryLogOptions,
|
|
4
|
+
import { IExtraOptions, TCount, TRepositoryLogOptions, TWhere } from '../common';
|
|
5
5
|
import { ReadableRepository } from './readable';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Full CRUD repository implementation.
|
|
8
|
+
*
|
|
9
|
+
* Extends {@link ReadableRepository} with create, update, and delete operations.
|
|
10
|
+
* This class provides the complete set of database operations for entities.
|
|
11
|
+
*
|
|
12
|
+
* @template EntitySchema - The Drizzle table schema type with an 'id' column
|
|
13
|
+
* @template DataObject - The type of objects returned from queries
|
|
14
|
+
* @template PersistObject - The type for insert/update operations
|
|
15
|
+
* @template ExtraOptions - Additional options type extending IExtraOptions
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* @repository({ model: User, dataSource: PostgresDataSource })
|
|
20
|
+
* export class UserRepository extends PersistableRepository<typeof User.schema> {
|
|
21
|
+
* async createWithDefaults(email: string) {
|
|
22
|
+
* return this.create({
|
|
23
|
+
* data: { email, role: 'user', isActive: true }
|
|
24
|
+
* });
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
8
28
|
*/
|
|
9
|
-
export declare class PersistableRepository<EntitySchema extends TTableSchemaWithId = TTableSchemaWithId, DataObject extends TTableObject<EntitySchema> = TTableObject<EntitySchema>, PersistObject extends TTableInsert<EntitySchema> = TTableInsert<EntitySchema>, ExtraOptions extends
|
|
29
|
+
export declare class PersistableRepository<EntitySchema extends TTableSchemaWithId = TTableSchemaWithId, DataObject extends TTableObject<EntitySchema> = TTableObject<EntitySchema>, PersistObject extends TTableInsert<EntitySchema> = TTableInsert<EntitySchema>, ExtraOptions extends IExtraOptions = IExtraOptions> extends ReadableRepository<EntitySchema, DataObject, PersistObject, ExtraOptions> {
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new persistable (read-write) repository instance.
|
|
32
|
+
*
|
|
33
|
+
* @param ds - Optional data source (auto-injected from @repository decorator)
|
|
34
|
+
* @param opts - Optional configuration
|
|
35
|
+
* @param opts.entityClass - Entity class if not using @repository decorator
|
|
36
|
+
*/
|
|
10
37
|
constructor(ds?: IDataSource, opts?: {
|
|
11
38
|
entityClass?: TClass<BaseEntity<EntitySchema>>;
|
|
12
39
|
});
|
|
13
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Validates where condition for bulk operations (update/delete).
|
|
42
|
+
* Prevents accidental mass updates/deletes by requiring explicit force flag.
|
|
43
|
+
*
|
|
44
|
+
* @param opts - Validation options
|
|
45
|
+
* @param opts.where - The where condition to validate
|
|
46
|
+
* @param opts.force - If true, allows empty where condition
|
|
47
|
+
* @param opts.operationName - Operation name for error message
|
|
48
|
+
* @returns True if where is empty (used for logging warnings)
|
|
49
|
+
* @throws Error if where is empty and force is not true
|
|
50
|
+
*/
|
|
51
|
+
protected validateWhereCondition(opts: {
|
|
52
|
+
where: TWhere<DataObject>;
|
|
53
|
+
force?: boolean;
|
|
54
|
+
operationName: string;
|
|
55
|
+
}): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Internal create implementation for single or bulk inserts.
|
|
58
|
+
*
|
|
59
|
+
* @template R - Return type (defaults to DataObject)
|
|
60
|
+
* @param opts - Create options
|
|
61
|
+
* @param opts.data - Array of records to insert
|
|
62
|
+
* @param opts.options - Extra options (transaction, logging, shouldReturn)
|
|
63
|
+
* @returns Promise with count and optionally the created records
|
|
64
|
+
*/
|
|
65
|
+
protected _create<R = DataObject>(opts: {
|
|
14
66
|
data: Array<PersistObject>;
|
|
15
67
|
options: ExtraOptions & {
|
|
16
68
|
shouldReturn?: boolean;
|
|
@@ -23,16 +75,14 @@ export declare class PersistableRepository<EntitySchema extends TTableSchemaWith
|
|
|
23
75
|
data: PersistObject;
|
|
24
76
|
options: ExtraOptions & {
|
|
25
77
|
shouldReturn: false;
|
|
26
|
-
log?: TRepositoryLogOptions;
|
|
27
78
|
};
|
|
28
79
|
}): Promise<TCount & {
|
|
29
|
-
data: null;
|
|
80
|
+
data: undefined | null;
|
|
30
81
|
}>;
|
|
31
|
-
create<R =
|
|
82
|
+
create<R = DataObject>(opts: {
|
|
32
83
|
data: PersistObject;
|
|
33
84
|
options?: ExtraOptions & {
|
|
34
85
|
shouldReturn?: true;
|
|
35
|
-
log?: TRepositoryLogOptions;
|
|
36
86
|
};
|
|
37
87
|
}): Promise<TCount & {
|
|
38
88
|
data: R;
|
|
@@ -41,27 +91,34 @@ export declare class PersistableRepository<EntitySchema extends TTableSchemaWith
|
|
|
41
91
|
data: Array<PersistObject>;
|
|
42
92
|
options: ExtraOptions & {
|
|
43
93
|
shouldReturn: false;
|
|
44
|
-
log?: TRepositoryLogOptions;
|
|
45
94
|
};
|
|
46
95
|
}): Promise<TCount & {
|
|
47
|
-
data: null;
|
|
96
|
+
data: undefined | null;
|
|
48
97
|
}>;
|
|
49
|
-
createAll<R =
|
|
98
|
+
createAll<R = DataObject>(opts: {
|
|
50
99
|
data: Array<PersistObject>;
|
|
51
100
|
options?: ExtraOptions & {
|
|
52
101
|
shouldReturn?: true;
|
|
53
|
-
log?: TRepositoryLogOptions;
|
|
54
102
|
};
|
|
55
103
|
}): Promise<TCount & {
|
|
56
104
|
data: Array<R>;
|
|
57
105
|
}>;
|
|
58
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Internal update implementation for single or bulk updates.
|
|
108
|
+
*
|
|
109
|
+
* @template R - Return type (defaults to DataObject)
|
|
110
|
+
* @param opts - Update options
|
|
111
|
+
* @param opts.data - Partial data to update
|
|
112
|
+
* @param opts.where - Where condition for selecting records to update
|
|
113
|
+
* @param opts.options - Extra options (transaction, logging, shouldReturn, force)
|
|
114
|
+
* @returns Promise with count and optionally the updated records
|
|
115
|
+
*/
|
|
116
|
+
protected _update<R = DataObject>(opts: {
|
|
59
117
|
data: Partial<PersistObject>;
|
|
60
118
|
where: TWhere<DataObject>;
|
|
61
119
|
options?: ExtraOptions & {
|
|
62
120
|
shouldReturn?: boolean;
|
|
63
121
|
force?: boolean;
|
|
64
|
-
log?: TRepositoryLogOptions;
|
|
65
122
|
};
|
|
66
123
|
}): Promise<TCount & {
|
|
67
124
|
data: TNullable<Array<R>>;
|
|
@@ -71,17 +128,15 @@ export declare class PersistableRepository<EntitySchema extends TTableSchemaWith
|
|
|
71
128
|
data: Partial<PersistObject>;
|
|
72
129
|
options: ExtraOptions & {
|
|
73
130
|
shouldReturn: false;
|
|
74
|
-
log?: TRepositoryLogOptions;
|
|
75
131
|
};
|
|
76
132
|
}): Promise<TCount & {
|
|
77
|
-
data: null;
|
|
133
|
+
data: undefined | null;
|
|
78
134
|
}>;
|
|
79
|
-
updateById<R =
|
|
135
|
+
updateById<R = DataObject>(opts: {
|
|
80
136
|
id: IdType;
|
|
81
137
|
data: Partial<PersistObject>;
|
|
82
138
|
options?: ExtraOptions & {
|
|
83
139
|
shouldReturn?: true;
|
|
84
|
-
log?: TRepositoryLogOptions;
|
|
85
140
|
};
|
|
86
141
|
}): Promise<TCount & {
|
|
87
142
|
data: R;
|
|
@@ -92,28 +147,34 @@ export declare class PersistableRepository<EntitySchema extends TTableSchemaWith
|
|
|
92
147
|
options: ExtraOptions & {
|
|
93
148
|
shouldReturn: false;
|
|
94
149
|
force?: boolean;
|
|
95
|
-
log?: TRepositoryLogOptions;
|
|
96
150
|
};
|
|
97
151
|
}): Promise<TCount & {
|
|
98
|
-
data: null;
|
|
152
|
+
data: undefined | null;
|
|
99
153
|
}>;
|
|
100
|
-
updateAll<R =
|
|
154
|
+
updateAll<R = DataObject>(opts: {
|
|
101
155
|
data: Partial<PersistObject>;
|
|
102
156
|
where: TWhere<DataObject>;
|
|
103
157
|
options?: ExtraOptions & {
|
|
104
158
|
shouldReturn?: true;
|
|
105
159
|
force?: boolean;
|
|
106
|
-
log?: TRepositoryLogOptions;
|
|
107
160
|
};
|
|
108
161
|
}): Promise<TCount & {
|
|
109
162
|
data: Array<R>;
|
|
110
163
|
}>;
|
|
111
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Internal delete implementation for single or bulk deletes.
|
|
166
|
+
*
|
|
167
|
+
* @template R - Return type (defaults to DataObject)
|
|
168
|
+
* @param opts - Delete options
|
|
169
|
+
* @param opts.where - Where condition for selecting records to delete
|
|
170
|
+
* @param opts.options - Extra options (transaction, logging, shouldReturn, force)
|
|
171
|
+
* @returns Promise with count and optionally the deleted records
|
|
172
|
+
*/
|
|
173
|
+
protected _delete<R = DataObject>(opts: {
|
|
112
174
|
where: TWhere<DataObject>;
|
|
113
175
|
options?: ExtraOptions & {
|
|
114
176
|
shouldReturn?: boolean;
|
|
115
177
|
force?: boolean;
|
|
116
|
-
log?: TRepositoryLogOptions;
|
|
117
178
|
};
|
|
118
179
|
}): Promise<TCount & {
|
|
119
180
|
data: TNullable<Array<R>>;
|
|
@@ -122,16 +183,14 @@ export declare class PersistableRepository<EntitySchema extends TTableSchemaWith
|
|
|
122
183
|
id: IdType;
|
|
123
184
|
options: ExtraOptions & {
|
|
124
185
|
shouldReturn: false;
|
|
125
|
-
log?: TRepositoryLogOptions;
|
|
126
186
|
};
|
|
127
187
|
}): Promise<TCount & {
|
|
128
|
-
data: null;
|
|
188
|
+
data: undefined | null;
|
|
129
189
|
}>;
|
|
130
|
-
deleteById<R =
|
|
190
|
+
deleteById<R = DataObject>(opts: {
|
|
131
191
|
id: IdType;
|
|
132
192
|
options?: ExtraOptions & {
|
|
133
193
|
shouldReturn?: true;
|
|
134
|
-
log?: TRepositoryLogOptions;
|
|
135
194
|
};
|
|
136
195
|
}): Promise<TCount & {
|
|
137
196
|
data: R;
|
|
@@ -141,17 +200,15 @@ export declare class PersistableRepository<EntitySchema extends TTableSchemaWith
|
|
|
141
200
|
options: ExtraOptions & {
|
|
142
201
|
shouldReturn: false;
|
|
143
202
|
force?: boolean;
|
|
144
|
-
log?: TRepositoryLogOptions;
|
|
145
203
|
};
|
|
146
204
|
}): Promise<TCount & {
|
|
147
|
-
data: null;
|
|
205
|
+
data: undefined | null;
|
|
148
206
|
}>;
|
|
149
|
-
deleteAll<R =
|
|
207
|
+
deleteAll<R = DataObject>(opts: {
|
|
150
208
|
where?: TWhere<DataObject>;
|
|
151
209
|
options?: ExtraOptions & {
|
|
152
210
|
shouldReturn?: true;
|
|
153
211
|
force?: boolean;
|
|
154
|
-
log?: TRepositoryLogOptions;
|
|
155
212
|
};
|
|
156
213
|
}): Promise<TCount & {
|
|
157
214
|
data: Array<R>;
|
|
@@ -161,17 +218,15 @@ export declare class PersistableRepository<EntitySchema extends TTableSchemaWith
|
|
|
161
218
|
options: ExtraOptions & {
|
|
162
219
|
shouldReturn: false;
|
|
163
220
|
force?: boolean;
|
|
164
|
-
log?: TRepositoryLogOptions;
|
|
165
221
|
};
|
|
166
222
|
}): Promise<TCount & {
|
|
167
|
-
data: null;
|
|
223
|
+
data: undefined | null;
|
|
168
224
|
}>;
|
|
169
|
-
deleteBy<R =
|
|
225
|
+
deleteBy<R = DataObject>(opts: {
|
|
170
226
|
where: TWhere<DataObject>;
|
|
171
227
|
options?: ExtraOptions & {
|
|
172
228
|
shouldReturn?: true;
|
|
173
229
|
force?: boolean;
|
|
174
|
-
log?: TRepositoryLogOptions;
|
|
175
230
|
};
|
|
176
231
|
}): Promise<TCount & {
|
|
177
232
|
data: Array<R>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistable.d.ts","sourceRoot":"","sources":["../../../../src/base/repositories/core/persistable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnG,OAAO,EAAY,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,
|
|
1
|
+
{"version":3,"file":"persistable.d.ts","sourceRoot":"","sources":["../../../../src/base/repositories/core/persistable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnG,OAAO,EAAY,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,EACL,aAAa,EAEb,MAAM,EACN,qBAAqB,EACrB,MAAM,EACP,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAMhD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,qBAAqB,CAChC,YAAY,SAAS,kBAAkB,GAAG,kBAAkB,EAC5D,UAAU,SAAS,YAAY,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,EAC1E,aAAa,SAAS,YAAY,CAAC,YAAY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