velocious 1.0.344 → 1.0.346
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/README.md +2 -0
- package/build/src/database/query/model-class-query.d.ts +30 -1
- package/build/src/database/query/model-class-query.d.ts.map +1 -1
- package/build/src/database/query/model-class-query.js +47 -3
- package/build/src/database/query/query-data.d.ts +108 -0
- package/build/src/database/query/query-data.d.ts.map +1 -0
- package/build/src/database/query/query-data.js +242 -0
- package/build/src/database/record/index.d.ts +87 -0
- package/build/src/database/record/index.d.ts.map +1 -1
- package/build/src/database/record/index.js +156 -1
- package/build/src/frontend-model-controller.d.ts +62 -0
- package/build/src/frontend-model-controller.d.ts.map +1 -1
- package/build/src/frontend-model-controller.js +219 -2
- package/build/src/frontend-models/base.d.ts +50 -1
- package/build/src/frontend-models/base.d.ts.map +1 -1
- package/build/src/frontend-models/base.js +88 -3
- package/build/src/frontend-models/query.d.ts +77 -0
- package/build/src/frontend-models/query.d.ts.map +1 -1
- package/build/src/frontend-models/query.js +165 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* Controllers and views for HTTP endpoints
|
|
10
10
|
* Rails-style nested-attribute writes on frontend-model `save()` (see [docs/nested-attributes.md](docs/nested-attributes.md))
|
|
11
11
|
* Per-row association counts via `.withCount(...)` on frontend and backend queries (see [docs/with-count.md](docs/with-count.md))
|
|
12
|
+
* Consumer-defined per-row SQL aggregates/computations via `.queryData(...)` on frontend and backend queries (see [docs/query-data.md](docs/query-data.md))
|
|
13
|
+
* Per-record ability checks via `.abilities(...)` on frontend queries + `record.can(action)` (see [docs/abilities.md](docs/abilities.md))
|
|
12
14
|
|
|
13
15
|
# Setup
|
|
14
16
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
5
|
* @template {typeof import("../record/index.js").default} [MC=typeof import("../record/index.js").default]
|
|
6
|
-
* @typedef {import("./index.js").QueryArgsType & {modelClass: MC, joinBasePath?: string[], joinTracker?: import("./join-tracker.js").default, forceQualifyBaseTable?: boolean, withCount?: import("./with-count.js").WithCountEntry[]}} ModelClassQueryArgsType
|
|
6
|
+
* @typedef {import("./index.js").QueryArgsType & {modelClass: MC, joinBasePath?: string[], joinTracker?: import("./join-tracker.js").default, forceQualifyBaseTable?: boolean, withCount?: import("./with-count.js").WithCountEntry[], queryData?: import("./query-data.js").QueryDataEntry[]}} ModelClassQueryArgsType
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* A generic query over some model type.
|
|
@@ -20,6 +20,8 @@ export default class VelociousDatabaseQueryModelClassQuery<MC extends typeof imp
|
|
|
20
20
|
_forceQualifyBaseTable: boolean;
|
|
21
21
|
/** @type {import("./with-count.js").WithCountEntry[]} */
|
|
22
22
|
_withCount: import("./with-count.js").WithCountEntry[];
|
|
23
|
+
/** @type {import("./query-data.js").QueryDataEntry[]} */
|
|
24
|
+
_queryData: import("./query-data.js").QueryDataEntry[];
|
|
23
25
|
/** @returns {this} - The clone. */
|
|
24
26
|
clone(): this;
|
|
25
27
|
/**
|
|
@@ -31,6 +33,32 @@ export default class VelociousDatabaseQueryModelClassQuery<MC extends typeof imp
|
|
|
31
33
|
* @returns {this} - This query, for chaining.
|
|
32
34
|
*/
|
|
33
35
|
withCount(spec: import("./with-count.js").WithCountSpec): this;
|
|
36
|
+
/**
|
|
37
|
+
* Attach one or more consumer-defined, per-row computed values onto
|
|
38
|
+
* every loaded root record. Leaf strings in the spec are names of
|
|
39
|
+
* functions previously registered via `Model.queryData(name, fn)`.
|
|
40
|
+
* Nested object keys are relationship names traced from the root to
|
|
41
|
+
* the model that declares the fn. Every resulting SELECT alias is
|
|
42
|
+
* attached to the **root** record (not to the intermediate joined
|
|
43
|
+
* rows); read values with `record.queryData(aliasName)`.
|
|
44
|
+
*
|
|
45
|
+
* See also `src/database/query/query-data.js`.
|
|
46
|
+
*
|
|
47
|
+
* @param {import("./query-data.js").QueryDataSpec} spec - Spec in shorthand or nested form.
|
|
48
|
+
* @returns {this} - This query, for chaining.
|
|
49
|
+
*/
|
|
50
|
+
queryData(spec: import("./query-data.js").QueryDataSpec): this;
|
|
51
|
+
/**
|
|
52
|
+
* Return the table reference (alias or table name) registered for the
|
|
53
|
+
* given relationship chain, relative to the query's current join base
|
|
54
|
+
* path. Convenience wrapper around `getTableReferenceForJoin` for use
|
|
55
|
+
* inside `queryData` callbacks where the writer's intent reads more
|
|
56
|
+
* naturally as "give me the table name for 'tasks'".
|
|
57
|
+
*
|
|
58
|
+
* @param {...string} path - Relationship path segments.
|
|
59
|
+
* @returns {string} - Unquoted table reference.
|
|
60
|
+
*/
|
|
61
|
+
tableNameFor(...path: string[]): string;
|
|
34
62
|
/** @returns {Promise<number>} - Resolves with the count. */
|
|
35
63
|
count(): Promise<number>;
|
|
36
64
|
/**
|
|
@@ -210,6 +238,7 @@ export type ModelClassQueryArgsType<MC extends typeof import("../record/index.js
|
|
|
210
238
|
joinTracker?: import("./join-tracker.js").default;
|
|
211
239
|
forceQualifyBaseTable?: boolean;
|
|
212
240
|
withCount?: import("./with-count.js").WithCountEntry[];
|
|
241
|
+
queryData?: import("./query-data.js").QueryDataEntry[];
|
|
213
242
|
};
|
|
214
243
|
import DatabaseQuery from "./index.js";
|
|
215
244
|
import JoinTracker from "./join-tracker.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-class-query.d.ts","sourceRoot":"","sources":["../../../../src/database/query/model-class-query.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"model-class-query.d.ts","sourceRoot":"","sources":["../../../../src/database/query/model-class-query.js"],"names":[],"mappings":"AAuIA;;GAEG;AACH;;;GAGG;AAEH;;;GAGG;AACH,2DAX4D,EAAE,SAAjD,cAAe,oBAAoB,EAAE,OAAQ;IAYxD,+EAA+E;IAC/E,kBADY,uBAAuB,CAAC,EAAE,CAAC,EA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