@atscript/moost-db 0.1.76 → 0.1.78

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/index.cjs CHANGED
@@ -652,6 +652,7 @@ let AsReadableController = class AsReadableController {
652
652
  return this._getOneControlsValidator;
653
653
  }
654
654
  validateControls(controls, type) {
655
+ if (type === "query" && controls.$groupBy !== void 0) return;
655
656
  const v = type === "query" ? this.queryControlsValidator : type === "pages" ? this.pagesControlsValidator : this.getOneControlsValidator;
656
657
  if (!v.validate(controls, true)) return v.errors[0]?.message || "Invalid controls";
657
658
  }
@@ -1327,12 +1328,13 @@ let AsDbReadableController = class AsDbReadableController extends AsReadableCont
1327
1328
  const parsed = this.parseQueryString(url);
1328
1329
  const controls = parsed.controls;
1329
1330
  this._coerceActionsControl(controls);
1330
- if (controls.$groupBy?.length) {
1331
- if (controls.$with?.length) return new _moostjs_event_http.HttpError(400, "Cannot combine $with and $groupBy in the same query");
1332
- if (parsed.insights) {
1333
- const insightsError = this.validateInsights(parsed.insights);
1334
- if (insightsError) return new _moostjs_event_http.HttpError(400, insightsError);
1335
- }
1331
+ const groupBy = controls.$groupBy;
1332
+ if (groupBy?.length && controls.$with?.length) return new _moostjs_event_http.HttpError(400, "Cannot combine $with and $groupBy in the same query");
1333
+ const error = this.validateParsed(parsed, "query");
1334
+ if (error) return error;
1335
+ const gateError = this.checkGates(parsed.filter, controls, this._gates);
1336
+ if (gateError) return gateError;
1337
+ if (groupBy?.length) {
1336
1338
  const filter = await this.transformFilter(parsed.filter);
1337
1339
  return this.readable.aggregate({
1338
1340
  filter,
@@ -1340,10 +1342,6 @@ let AsDbReadableController = class AsDbReadableController extends AsReadableCont
1340
1342
  insights: parsed.insights
1341
1343
  });
1342
1344
  }
1343
- const error = this.validateParsed(parsed, "query");
1344
- if (error) return error;
1345
- const gateError = this.checkGates(parsed.filter, controls, this._gates);
1346
- if (gateError) return gateError;
1347
1345
  const [filter, rawSelect] = await Promise.all([this.transformFilter(parsed.filter), this.transformProjection(controls.$select)]);
1348
1346
  if (controls.$count) return this.readable.count({
1349
1347
  filter,
package/dist/index.d.cts CHANGED
@@ -506,7 +506,7 @@ declare const TABLE_DEF = "__atscript_db_readable_def";
506
506
  * export class UsersController extends AsDbController<typeof UserModel> {}
507
507
  * ```
508
508
  */
509
- declare const TableController: (table: AtscriptDbTable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
509
+ declare const TableController: <Table extends AtscriptDbTable<any, any, any, any, any, any, any>>(table: Table, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
510
510
  /**
511
511
  * Combines the boilerplate needed to turn an {@link AsDbReadableController}
512
512
  * subclass into a fully wired HTTP controller for a given `@db.view` or `@db.table` model.
@@ -520,7 +520,7 @@ declare const TableController: (table: AtscriptDbTable, prefix?: string) => Meth
520
520
  * export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
521
521
  * ```
522
522
  */
523
- declare const ReadableController: (readable: AtscriptDbReadable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
523
+ declare const ReadableController: <Readable extends AtscriptDbReadable<any, any, any, any, any, any, any>>(readable: Readable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
524
524
  /**
525
525
  * Alias for {@link ReadableController} — use with view-backed controllers.
526
526
  *
@@ -530,7 +530,7 @@ declare const ReadableController: (readable: AtscriptDbReadable, prefix?: string
530
530
  * export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
531
531
  * ```
532
532
  */
533
- declare const ViewController: (readable: AtscriptDbReadable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
533
+ declare const ViewController: <Readable extends AtscriptDbReadable<any, any, any, any, any, any, any>>(readable: Readable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
534
534
  //#endregion
535
535
  //#region src/validation-interceptor.d.ts
536
536
  declare const validationErrorTransform: () => _$moost.TInterceptorDef;
package/dist/index.d.mts CHANGED
@@ -506,7 +506,7 @@ declare const TABLE_DEF = "__atscript_db_readable_def";
506
506
  * export class UsersController extends AsDbController<typeof UserModel> {}
507
507
  * ```
508
508
  */
509
- declare const TableController: (table: AtscriptDbTable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
509
+ declare const TableController: <Table extends AtscriptDbTable<any, any, any, any, any, any, any>>(table: Table, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
510
510
  /**
511
511
  * Combines the boilerplate needed to turn an {@link AsDbReadableController}
512
512
  * subclass into a fully wired HTTP controller for a given `@db.view` or `@db.table` model.
@@ -520,7 +520,7 @@ declare const TableController: (table: AtscriptDbTable, prefix?: string) => Meth
520
520
  * export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
521
521
  * ```
522
522
  */
523
- declare const ReadableController: (readable: AtscriptDbReadable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
523
+ declare const ReadableController: <Readable extends AtscriptDbReadable<any, any, any, any, any, any, any>>(readable: Readable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
524
524
  /**
525
525
  * Alias for {@link ReadableController} — use with view-backed controllers.
526
526
  *
@@ -530,7 +530,7 @@ declare const ReadableController: (readable: AtscriptDbReadable, prefix?: string
530
530
  * export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
531
531
  * ```
532
532
  */
533
- declare const ViewController: (readable: AtscriptDbReadable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
533
+ declare const ViewController: <Readable extends AtscriptDbReadable<any, any, any, any, any, any, any>>(readable: Readable, prefix?: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
534
534
  //#endregion
535
535
  //#region src/validation-interceptor.d.ts
536
536
  declare const validationErrorTransform: () => _$moost.TInterceptorDef;
package/dist/index.mjs CHANGED
@@ -651,6 +651,7 @@ let AsReadableController = class AsReadableController {
651
651
  return this._getOneControlsValidator;
652
652
  }
653
653
  validateControls(controls, type) {
654
+ if (type === "query" && controls.$groupBy !== void 0) return;
654
655
  const v = type === "query" ? this.queryControlsValidator : type === "pages" ? this.pagesControlsValidator : this.getOneControlsValidator;
655
656
  if (!v.validate(controls, true)) return v.errors[0]?.message || "Invalid controls";
656
657
  }
@@ -1326,12 +1327,13 @@ let AsDbReadableController = class AsDbReadableController extends AsReadableCont
1326
1327
  const parsed = this.parseQueryString(url);
1327
1328
  const controls = parsed.controls;
1328
1329
  this._coerceActionsControl(controls);
1329
- if (controls.$groupBy?.length) {
1330
- if (controls.$with?.length) return new HttpError(400, "Cannot combine $with and $groupBy in the same query");
1331
- if (parsed.insights) {
1332
- const insightsError = this.validateInsights(parsed.insights);
1333
- if (insightsError) return new HttpError(400, insightsError);
1334
- }
1330
+ const groupBy = controls.$groupBy;
1331
+ if (groupBy?.length && controls.$with?.length) return new HttpError(400, "Cannot combine $with and $groupBy in the same query");
1332
+ const error = this.validateParsed(parsed, "query");
1333
+ if (error) return error;
1334
+ const gateError = this.checkGates(parsed.filter, controls, this._gates);
1335
+ if (gateError) return gateError;
1336
+ if (groupBy?.length) {
1335
1337
  const filter = await this.transformFilter(parsed.filter);
1336
1338
  return this.readable.aggregate({
1337
1339
  filter,
@@ -1339,10 +1341,6 @@ let AsDbReadableController = class AsDbReadableController extends AsReadableCont
1339
1341
  insights: parsed.insights
1340
1342
  });
1341
1343
  }
1342
- const error = this.validateParsed(parsed, "query");
1343
- if (error) return error;
1344
- const gateError = this.checkGates(parsed.filter, controls, this._gates);
1345
- if (gateError) return gateError;
1346
1344
  const [filter, rawSelect] = await Promise.all([this.transformFilter(parsed.filter), this.transformProjection(controls.$select)]);
1347
1345
  if (controls.$count) return this.readable.count({
1348
1346
  filter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/moost-db",
3
- "version": "0.1.76",
3
+ "version": "0.1.78",
4
4
  "description": "Generic database controller for Moost with Atscript.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -58,7 +58,7 @@
58
58
  "@wooksjs/event-core": "^0.7.11",
59
59
  "@wooksjs/http-body": "^0.7.11",
60
60
  "moost": "^0.6.9",
61
- "@atscript/db": "^0.1.76"
61
+ "@atscript/db": "^0.1.78"
62
62
  },
63
63
  "scripts": {
64
64
  "postinstall": "asc -f dts",