@expo/entity-database-adapter-knex 0.61.0 → 0.63.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.
- package/build/src/AuthorizationResultBasedKnexEntityLoader.d.ts +0 -8
- package/build/src/AuthorizationResultBasedKnexEntityLoader.js +0 -11
- package/build/src/BasePostgresEntityDatabaseAdapter.d.ts +0 -11
- package/build/src/BasePostgresEntityDatabaseAdapter.js +0 -13
- package/build/src/EnforcingKnexEntityLoader.d.ts +0 -32
- package/build/src/EnforcingKnexEntityLoader.js +0 -35
- package/build/src/PostgresEntityDatabaseAdapter.d.ts +3 -2
- package/build/src/PostgresEntityDatabaseAdapter.js +2 -6
- package/build/src/SQLOperator.d.ts +379 -31
- package/build/src/internal/EntityKnexDataManager.d.ts +0 -10
- package/build/src/internal/EntityKnexDataManager.js +3 -16
- package/package.json +5 -5
- package/src/AuthorizationResultBasedKnexEntityLoader.ts +0 -21
- package/src/BasePostgresEntityDatabaseAdapter.ts +0 -36
- package/src/EnforcingKnexEntityLoader.ts +0 -44
- package/src/PostgresEntityDatabaseAdapter.ts +4 -15
- package/src/SQLOperator.ts +449 -101
- package/src/__integration-tests__/PostgresEntityIntegration-test.ts +69 -116
- package/src/__tests__/AuthorizationResultBasedKnexEntityLoader-test.ts +0 -75
- package/src/__tests__/BasePostgresEntityDatabaseAdapter-test.ts +4 -28
- package/src/__tests__/EnforcingKnexEntityLoader-test.ts +0 -52
- package/src/__tests__/fixtures/StubPostgresDatabaseAdapter.ts +3 -13
- package/src/internal/EntityKnexDataManager.ts +6 -37
- package/src/internal/__tests__/EntityKnexDataManager-test.ts +1 -57
|
@@ -88,16 +88,6 @@ export declare class EntityKnexDataManager<TFields extends Record<string, any>,
|
|
|
88
88
|
* @returns array of objects matching the query
|
|
89
89
|
*/
|
|
90
90
|
loadManyByFieldEqualityConjunctionAsync<N extends keyof TFields>(queryContext: EntityQueryContext, fieldEqualityOperands: readonly FieldEqualityCondition<TFields, N>[], querySelectionModifiers: PostgresQuerySelectionModifiers<TFields>): Promise<readonly Readonly<TFields>[]>;
|
|
91
|
-
/**
|
|
92
|
-
* Loads many objects matching the raw WHERE clause.
|
|
93
|
-
*
|
|
94
|
-
* @param queryContext - query context in which to perform the load
|
|
95
|
-
* @param rawWhereClause - parameterized SQL WHERE clause with positional binding placeholders or named binding placeholders
|
|
96
|
-
* @param bindings - array of positional bindings or object of named bindings
|
|
97
|
-
* @param querySelectionModifiers - limit, offset, orderBy, and orderByRaw for the query
|
|
98
|
-
* @returns array of objects matching the query
|
|
99
|
-
*/
|
|
100
|
-
loadManyByRawWhereClauseAsync(queryContext: EntityQueryContext, rawWhereClause: string, bindings: readonly any[] | object, querySelectionModifiers: PostgresQuerySelectionModifiers<TFields>): Promise<readonly Readonly<TFields>[]>;
|
|
101
91
|
loadManyBySQLFragmentAsync(queryContext: EntityQueryContext, sqlFragment: SQLFragment<TFields>, querySelectionModifiers: PostgresQuerySelectionModifiers<TFields>): Promise<readonly Readonly<TFields>[]>;
|
|
102
92
|
/**
|
|
103
93
|
* Load a page of objects using cursor-based pagination with unified pagination specification.
|
|
@@ -42,19 +42,6 @@ export class EntityKnexDataManager {
|
|
|
42
42
|
EntityKnexDataManager.validateOrderByClauses(querySelectionModifiers.orderBy);
|
|
43
43
|
return await timeAndLogLoadEventAsync(this.metricsAdapter, EntityMetricsLoadType.LOAD_MANY_EQUALITY_CONJUNCTION, this.entityClassName, queryContext)(this.databaseAdapter.fetchManyByFieldEqualityConjunctionAsync(queryContext, fieldEqualityOperands, querySelectionModifiers));
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Loads many objects matching the raw WHERE clause.
|
|
47
|
-
*
|
|
48
|
-
* @param queryContext - query context in which to perform the load
|
|
49
|
-
* @param rawWhereClause - parameterized SQL WHERE clause with positional binding placeholders or named binding placeholders
|
|
50
|
-
* @param bindings - array of positional bindings or object of named bindings
|
|
51
|
-
* @param querySelectionModifiers - limit, offset, orderBy, and orderByRaw for the query
|
|
52
|
-
* @returns array of objects matching the query
|
|
53
|
-
*/
|
|
54
|
-
async loadManyByRawWhereClauseAsync(queryContext, rawWhereClause, bindings, querySelectionModifiers) {
|
|
55
|
-
EntityKnexDataManager.validateOrderByClauses(querySelectionModifiers.orderBy);
|
|
56
|
-
return await timeAndLogLoadEventAsync(this.metricsAdapter, EntityMetricsLoadType.LOAD_MANY_RAW, this.entityClassName, queryContext)(this.databaseAdapter.fetchManyByRawWhereClauseAsync(queryContext, rawWhereClause, bindings, querySelectionModifiers));
|
|
57
|
-
}
|
|
58
45
|
async loadManyBySQLFragmentAsync(queryContext, sqlFragment, querySelectionModifiers) {
|
|
59
46
|
EntityKnexDataManager.validateOrderByClauses(querySelectionModifiers.orderBy);
|
|
60
47
|
return await timeAndLogLoadEventAsync(this.metricsAdapter, EntityMetricsLoadType.LOAD_MANY_SQL, this.entityClassName, queryContext)(this.databaseAdapter.fetchManyBySQLFragmentAsync(queryContext, sqlFragment, querySelectionModifiers));
|
|
@@ -284,10 +271,10 @@ export class EntityKnexDataManager {
|
|
|
284
271
|
catch (e) {
|
|
285
272
|
throw new EntityDatabaseAdapterPaginationCursorInvalidError(`Failed to decode cursor`, e instanceof Error ? e : undefined);
|
|
286
273
|
}
|
|
287
|
-
if (
|
|
288
|
-
|
|
274
|
+
if (typeof parsedCursor === 'object' && 'id' in parsedCursor) {
|
|
275
|
+
return parsedCursor.id;
|
|
289
276
|
}
|
|
290
|
-
|
|
277
|
+
throw new EntityDatabaseAdapterPaginationCursorInvalidError(`Cursor is missing required 'id' field. Parsed cursor: ${JSON.stringify(parsedCursor)}`);
|
|
291
278
|
}
|
|
292
279
|
resolveSearchFieldToSQLFragment(field, tableAlias) {
|
|
293
280
|
if (field instanceof SQLFragment) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/entity-database-adapter-knex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "Knex database adapter for @expo/entity",
|
|
5
5
|
"files": [
|
|
6
6
|
"build",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"type": "module",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@expo/entity": "^0.
|
|
32
|
+
"@expo/entity": "^0.63.0",
|
|
33
33
|
"knex": "^3.1.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@expo/entity-testing-utils": "^0.
|
|
37
|
-
"@jest/globals": "30.
|
|
36
|
+
"@expo/entity-testing-utils": "^0.63.0",
|
|
37
|
+
"@jest/globals": "30.3.0",
|
|
38
38
|
"pg": "8.20.0",
|
|
39
39
|
"ts-mockito": "2.6.1",
|
|
40
40
|
"typescript": "5.9.3"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "dbd1cc847952754acc0eb407165cbb7b8350d2df"
|
|
43
43
|
}
|
|
@@ -400,27 +400,6 @@ export class AuthorizationResultBasedKnexEntityLoader<
|
|
|
400
400
|
return await this.constructionUtils.constructAndAuthorizeEntitiesArrayAsync(fieldObjects);
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
/**
|
|
404
|
-
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
|
405
|
-
* @returns array of entity results that match the query, where result error can be UnauthorizedError
|
|
406
|
-
* @throws Error when rawWhereClause or bindings are invalid
|
|
407
|
-
*
|
|
408
|
-
* @deprecated Use loadManyBySQL instead for safer value bindings and more flexible query building.
|
|
409
|
-
*/
|
|
410
|
-
async loadManyByRawWhereClauseAsync(
|
|
411
|
-
rawWhereClause: string,
|
|
412
|
-
bindings: any[] | object,
|
|
413
|
-
querySelectionModifiers: EntityLoaderQuerySelectionModifiers<TFields, TSelectedFields> = {},
|
|
414
|
-
): Promise<readonly Result<TEntity>[]> {
|
|
415
|
-
const fieldObjects = await this.knexDataManager.loadManyByRawWhereClauseAsync(
|
|
416
|
-
this.queryContext,
|
|
417
|
-
rawWhereClause,
|
|
418
|
-
bindings,
|
|
419
|
-
querySelectionModifiers,
|
|
420
|
-
);
|
|
421
|
-
return await this.constructionUtils.constructAndAuthorizeEntitiesArrayAsync(fieldObjects);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
403
|
/**
|
|
425
404
|
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
|
426
405
|
* @returns SQL query builder for building and executing SQL queries that when executed returns entity results where result error can be UnauthorizedError.
|
|
@@ -216,42 +216,6 @@ export abstract class BasePostgresEntityDatabaseAdapter<
|
|
|
216
216
|
querySelectionModifiers: TableQuerySelectionModifiers<TFields>,
|
|
217
217
|
): Promise<object[]>;
|
|
218
218
|
|
|
219
|
-
/**
|
|
220
|
-
* Fetch many objects matching the raw WHERE clause.
|
|
221
|
-
*
|
|
222
|
-
* @param queryContext - query context with which to perform the fetch
|
|
223
|
-
* @param rawWhereClause - parameterized SQL WHERE clause with positional binding placeholders or named binding placeholders
|
|
224
|
-
* @param bindings - array of positional bindings or object of named bindings
|
|
225
|
-
* @param querySelectionModifiers - limit, offset, and orderBy for the query
|
|
226
|
-
* @returns array of objects matching the query
|
|
227
|
-
*/
|
|
228
|
-
async fetchManyByRawWhereClauseAsync(
|
|
229
|
-
queryContext: EntityQueryContext,
|
|
230
|
-
rawWhereClause: string,
|
|
231
|
-
bindings: any[] | object,
|
|
232
|
-
querySelectionModifiers: PostgresQuerySelectionModifiers<TFields>,
|
|
233
|
-
): Promise<readonly Readonly<TFields>[]> {
|
|
234
|
-
const results = await this.fetchManyByRawWhereClauseInternalAsync(
|
|
235
|
-
queryContext.getQueryInterface(),
|
|
236
|
-
this.entityConfiguration.tableName,
|
|
237
|
-
rawWhereClause,
|
|
238
|
-
bindings,
|
|
239
|
-
this.convertToTableQueryModifiers(querySelectionModifiers),
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
return results.map((result) =>
|
|
243
|
-
transformDatabaseObjectToFields(this.entityConfiguration, this.fieldTransformerMap, result),
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
protected abstract fetchManyByRawWhereClauseInternalAsync(
|
|
248
|
-
queryInterface: Knex,
|
|
249
|
-
tableName: string,
|
|
250
|
-
rawWhereClause: string,
|
|
251
|
-
bindings: object | any[],
|
|
252
|
-
querySelectionModifiers: TableQuerySelectionModifiers<TFields>,
|
|
253
|
-
): Promise<object[]>;
|
|
254
|
-
|
|
255
219
|
/**
|
|
256
220
|
* Fetch many objects matching the SQL fragment.
|
|
257
221
|
*
|
|
@@ -104,50 +104,6 @@ export class EnforcingKnexEntityLoader<
|
|
|
104
104
|
return entityResults.map((result) => result.enforceValue());
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
/**
|
|
108
|
-
* Load entities with a raw SQL WHERE clause.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* Load entities with SQL function
|
|
112
|
-
* ```typescript
|
|
113
|
-
* const entitiesWithJsonKey = await ExampleEntity.loader(vc)
|
|
114
|
-
* .loadManyByRawWhereClauseAsync(
|
|
115
|
-
* "json_column->>'key_name' = ?",
|
|
116
|
-
* ['value'],
|
|
117
|
-
* );
|
|
118
|
-
* ```
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* Load entities with tuple matching
|
|
122
|
-
* ```typescript
|
|
123
|
-
* const entities = await ExampleEntity.loader(vc)
|
|
124
|
-
* .loadManyByRawWhereClauseAsync(
|
|
125
|
-
* '(column_1, column_2) IN ((?, ?), (?, ?))',
|
|
126
|
-
* [value1, value2, value3, value4],
|
|
127
|
-
* );
|
|
128
|
-
* ```
|
|
129
|
-
* @param rawWhereClause - SQL WHERE clause. Interpolated values should be specified as ?-placeholders or :key_name
|
|
130
|
-
* @param bindings - values to bind to the placeholders in the WHERE clause
|
|
131
|
-
* @param querySelectionModifiers - limit, offset, and orderBy for the query.
|
|
132
|
-
* @returns entities matching the WHERE clause
|
|
133
|
-
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
|
134
|
-
* @throws Error when rawWhereClause or bindings are invalid
|
|
135
|
-
*
|
|
136
|
-
* @deprecated Use loadManyBySQL instead for safer value bindings and more flexible query building.
|
|
137
|
-
*/
|
|
138
|
-
async loadManyByRawWhereClauseAsync(
|
|
139
|
-
rawWhereClause: string,
|
|
140
|
-
bindings: any[] | object,
|
|
141
|
-
querySelectionModifiers: EntityLoaderQuerySelectionModifiers<TFields, TSelectedFields> = {},
|
|
142
|
-
): Promise<readonly TEntity[]> {
|
|
143
|
-
const entityResults = await this.knexEntityLoader.loadManyByRawWhereClauseAsync(
|
|
144
|
-
rawWhereClause,
|
|
145
|
-
bindings,
|
|
146
|
-
querySelectionModifiers,
|
|
147
|
-
);
|
|
148
|
-
return entityResults.map((result) => result.enforceValue());
|
|
149
|
-
}
|
|
150
|
-
|
|
151
107
|
/**
|
|
152
108
|
* Load entities using a SQL query builder. When executed, all queries will enforce authorization and throw if not authorized.
|
|
153
109
|
*
|
|
@@ -210,18 +210,6 @@ export class PostgresEntityDatabaseAdapter<
|
|
|
210
210
|
return await wrapNativePostgresCallAsync(() => query);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
protected async fetchManyByRawWhereClauseInternalAsync(
|
|
214
|
-
queryInterface: Knex,
|
|
215
|
-
tableName: string,
|
|
216
|
-
rawWhereClause: string,
|
|
217
|
-
bindings: object | any[],
|
|
218
|
-
querySelectionModifiers: TableQuerySelectionModifiers<TFields>,
|
|
219
|
-
): Promise<object[]> {
|
|
220
|
-
let query = queryInterface.select().from(tableName).whereRaw(rawWhereClause, bindings);
|
|
221
|
-
query = this.applyQueryModifiersToQuery(query, querySelectionModifiers);
|
|
222
|
-
return await wrapNativePostgresCallAsync(() => query);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
213
|
protected async fetchManyBySQLFragmentInternalAsync(
|
|
226
214
|
queryInterface: Knex,
|
|
227
215
|
tableName: string,
|
|
@@ -257,10 +245,11 @@ export class PostgresEntityDatabaseAdapter<
|
|
|
257
245
|
tableIdField: string,
|
|
258
246
|
id: any,
|
|
259
247
|
object: object,
|
|
260
|
-
): Promise<
|
|
261
|
-
|
|
262
|
-
queryInterface.update(object).into(tableName).where(tableIdField, id)
|
|
248
|
+
): Promise<{ updatedRowCount: number }> {
|
|
249
|
+
const updatedRowCount = await wrapNativePostgresCallAsync(() =>
|
|
250
|
+
queryInterface.update(object).into(tableName).where(tableIdField, id),
|
|
263
251
|
);
|
|
252
|
+
return { updatedRowCount };
|
|
264
253
|
}
|
|
265
254
|
|
|
266
255
|
protected async deleteInternalAsync(
|