@yunsoft/yuncms-core 0.1.25 → 0.1.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yunsoft/yuncms-core",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "description": "Core services, schema, authentication, permissions and storage primitives for YunCMS.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -231,10 +231,10 @@ export class ItemsService extends BaseService {
231
231
  return combineCompiledFilters(permissionSql, userSql, searchSql);
232
232
  }
233
233
 
234
- async normalizeReadQuery(rawQuery) {
234
+ async normalizeReadQuery(rawQuery, context = {}) {
235
235
  const parsed = parseItemsQuery(rawQuery);
236
236
  const filtered = this.emitter
237
- ? await this.emitter.filter('items.query', parsed, this.hookContext({ operation: 'read' }))
237
+ ? await this.emitter.filter('items.query', parsed, this.hookContext({ ...context, operation: 'read' }))
238
238
  : parsed;
239
239
  const query = parseItemsQuery(filtered);
240
240
  assertQueryCost(query);
@@ -363,14 +363,18 @@ export class ItemsService extends BaseService {
363
363
 
364
364
  async readOne(id, { fields = null } = {}) {
365
365
  const schema = await this.getCollectionSchema();
366
+ const query = await this.normalizeReadQuery({ fields, limit: 1 }, { single: true, key: id });
367
+ if (query.aggregate) {
368
+ throw serviceError('INVALID_QUERY', 'Single-item reads do not support aggregate queries', 'aggregate');
369
+ }
366
370
  const permission = await this.resolvePermission('read');
367
371
  const accessSchema = schemaForFields(schema, permission.fields);
368
- const selected = compileSelectFields(normalizeFields(fields), accessSchema);
372
+ const selected = compileSelectFields(query.fields, accessSchema);
369
373
  const table = quoteIdentifier(this.collection, 'collection name');
370
374
  const primaryKey = schema.primary_key;
371
375
  const dynamicVariables = this.dynamicVariables();
372
376
  const filter = combineCompiledFilters(
373
- compileFilter(permission.filter, schema, { dynamicVariables }),
377
+ this.compileActionFilters(query.filter, permission.filter, accessSchema, schema, query.search, dynamicVariables),
374
378
  compileFilter({ [primaryKey]: { _eq: id } }, schema),
375
379
  );
376
380
  const [rows] = await this.database.query(
@@ -378,7 +382,7 @@ export class ItemsService extends BaseService {
378
382
  filter.params,
379
383
  );
380
384
  const record = rows[0] ?? null;
381
- if (record) await this.emitReadAction({ fields: normalizeFields(fields) }, [record], schema, { single: true });
385
+ if (record) await this.emitReadAction(query, [record], schema, { single: true });
382
386
  return record;
383
387
  }
384
388