@antelopejs/interface-data-api 0.4.0 → 0.6.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.
Files changed (165) hide show
  1. package/README.md +26 -22
  2. package/dist/antelope.test.js +1 -5
  3. package/dist/antelope.test.js.map +1 -1
  4. package/dist/components.d.ts +67 -39
  5. package/dist/components.js +106 -685
  6. package/dist/components.js.map +1 -1
  7. package/dist/index.d.ts +57 -68
  8. package/dist/index.js +114 -100
  9. package/dist/index.js.map +1 -1
  10. package/dist/internal/computed.d.ts +6 -0
  11. package/dist/internal/computed.js +51 -0
  12. package/dist/internal/computed.js.map +1 -0
  13. package/dist/internal/controller-types.d.ts +34 -0
  14. package/dist/internal/controller-types.js +4 -0
  15. package/dist/internal/controller-types.js.map +1 -0
  16. package/dist/internal/default-filter.d.ts +4 -0
  17. package/dist/internal/default-filter.js +29 -0
  18. package/dist/internal/default-filter.js.map +1 -0
  19. package/dist/internal/deferred-joined-stream.d.ts +11 -0
  20. package/dist/internal/deferred-joined-stream.js +125 -0
  21. package/dist/internal/deferred-joined-stream.js.map +1 -0
  22. package/dist/internal/extractors.d.ts +25 -0
  23. package/dist/internal/extractors.js +31 -0
  24. package/dist/internal/extractors.js.map +1 -0
  25. package/dist/internal/field-types.d.ts +199 -0
  26. package/dist/internal/field-types.js +4 -0
  27. package/dist/internal/field-types.js.map +1 -0
  28. package/dist/internal/filters.d.ts +6 -0
  29. package/dist/internal/filters.js +22 -0
  30. package/dist/internal/filters.js.map +1 -0
  31. package/dist/internal/foreign.d.ts +6 -0
  32. package/dist/internal/foreign.js +116 -0
  33. package/dist/internal/foreign.js.map +1 -0
  34. package/dist/internal/guards.d.ts +39 -0
  35. package/dist/internal/guards.js +116 -0
  36. package/dist/internal/guards.js.map +1 -0
  37. package/dist/internal/joined.d.ts +28 -0
  38. package/dist/internal/joined.js +127 -0
  39. package/dist/internal/joined.js.map +1 -0
  40. package/dist/internal/list.d.ts +16 -0
  41. package/dist/internal/list.js +182 -0
  42. package/dist/internal/list.js.map +1 -0
  43. package/dist/internal/meta-records.d.ts +19 -0
  44. package/dist/internal/meta-records.js +78 -0
  45. package/dist/internal/meta-records.js.map +1 -0
  46. package/dist/internal/properties.d.ts +4 -0
  47. package/dist/internal/properties.js +45 -0
  48. package/dist/internal/properties.js.map +1 -0
  49. package/dist/internal/prototypes.d.ts +14 -0
  50. package/dist/internal/prototypes.js +38 -0
  51. package/dist/internal/prototypes.js.map +1 -0
  52. package/dist/internal/read-properties.d.ts +3 -0
  53. package/dist/internal/read-properties.js +29 -0
  54. package/dist/internal/read-properties.js.map +1 -0
  55. package/dist/internal/table-reference.d.ts +11 -0
  56. package/dist/internal/table-reference.js +46 -0
  57. package/dist/internal/table-reference.js.map +1 -0
  58. package/dist/internal/tables.d.ts +28 -0
  59. package/dist/internal/tables.js +48 -0
  60. package/dist/internal/tables.js.map +1 -0
  61. package/dist/internal/validation.d.ts +12 -0
  62. package/dist/internal/validation.js +100 -0
  63. package/dist/internal/validation.js.map +1 -0
  64. package/dist/metadata.d.ts +27 -228
  65. package/dist/metadata.js +84 -213
  66. package/dist/metadata.js.map +1 -1
  67. package/dist/tests/components/access_control.test.js +28 -20
  68. package/dist/tests/components/access_control.test.js.map +1 -1
  69. package/dist/tests/components/computed.test.js +36 -27
  70. package/dist/tests/components/computed.test.js.map +1 -1
  71. package/dist/tests/components/cross_instance.test.js +8 -6
  72. package/dist/tests/components/cross_instance.test.js.map +1 -1
  73. package/dist/tests/components/deferred_joined.test.js +57 -54
  74. package/dist/tests/components/deferred_joined.test.js.map +1 -1
  75. package/dist/tests/components/extract_generic.test.d.ts +1 -0
  76. package/dist/tests/components/extract_generic.test.js +64 -0
  77. package/dist/tests/components/extract_generic.test.js.map +1 -0
  78. package/dist/tests/components/filter_comparisons.test.d.ts +1 -0
  79. package/dist/tests/components/filter_comparisons.test.js +34 -0
  80. package/dist/tests/components/filter_comparisons.test.js.map +1 -0
  81. package/dist/tests/components/filter_list_route.test.d.ts +1 -0
  82. package/dist/tests/components/filter_list_route.test.js +182 -0
  83. package/dist/tests/components/filter_list_route.test.js.map +1 -0
  84. package/dist/tests/components/filter_options.test.js +11 -10
  85. package/dist/tests/components/filter_options.test.js.map +1 -1
  86. package/dist/tests/components/foreign_computed.test.js +23 -14
  87. package/dist/tests/components/foreign_computed.test.js.map +1 -1
  88. package/dist/tests/components/foreign_joined.test.js +31 -27
  89. package/dist/tests/components/foreign_joined.test.js.map +1 -1
  90. package/dist/tests/components/joined.test.js +59 -45
  91. package/dist/tests/components/joined.test.js.map +1 -1
  92. package/dist/tests/components/listable.test.js +78 -58
  93. package/dist/tests/components/listable.test.js.map +1 -1
  94. package/dist/tests/components/localized_sort.test.js +14 -11
  95. package/dist/tests/components/localized_sort.test.js.map +1 -1
  96. package/dist/tests/components/mandatory.test.js +25 -25
  97. package/dist/tests/components/mandatory.test.js.map +1 -1
  98. package/dist/tests/components/modifier_key.test.js +27 -18
  99. package/dist/tests/components/modifier_key.test.js.map +1 -1
  100. package/dist/tests/components/parse_body.test.d.ts +1 -0
  101. package/dist/tests/components/parse_body.test.js +76 -0
  102. package/dist/tests/components/parse_body.test.js.map +1 -0
  103. package/dist/tests/components/parsed_value.test.js +23 -21
  104. package/dist/tests/components/parsed_value.test.js.map +1 -1
  105. package/dist/tests/components/partial_edit.test.js +38 -32
  106. package/dist/tests/components/partial_edit.test.js.map +1 -1
  107. package/dist/tests/components/per_action_access.test.js +20 -12
  108. package/dist/tests/components/per_action_access.test.js.map +1 -1
  109. package/dist/tests/components/prototype_named_filter.test.d.ts +1 -0
  110. package/dist/tests/components/prototype_named_filter.test.js +87 -0
  111. package/dist/tests/components/prototype_named_filter.test.js.map +1 -0
  112. package/dist/tests/components/validator.test.js +45 -37
  113. package/dist/tests/components/validator.test.js.map +1 -1
  114. package/dist/tests/components/written_row.test.d.ts +1 -0
  115. package/dist/tests/components/written_row.test.js +99 -0
  116. package/dist/tests/components/written_row.test.js.map +1 -0
  117. package/dist/tests/helpers/other-instance.d.ts +11 -1
  118. package/dist/tests/helpers/other-instance.js +35 -9
  119. package/dist/tests/helpers/other-instance.js.map +1 -1
  120. package/dist/tests/index/field_decorator_target.test.d.ts +1 -0
  121. package/dist/tests/index/field_decorator_target.test.js +20 -0
  122. package/dist/tests/index/field_decorator_target.test.js.map +1 -0
  123. package/dist/tests/index/get_guard.test.js +6 -6
  124. package/dist/tests/index/get_guard.test.js.map +1 -1
  125. package/dist/tests/index/inheritance.test.js +14 -9
  126. package/dist/tests/index/inheritance.test.js.map +1 -1
  127. package/dist/tests/index/metadata_names.test.d.ts +1 -0
  128. package/dist/tests/index/metadata_names.test.js +91 -0
  129. package/dist/tests/index/metadata_names.test.js.map +1 -0
  130. package/dist/tests/index/routes.test.js +49 -44
  131. package/dist/tests/index/routes.test.js.map +1 -1
  132. package/dist/tests/integration.test.d.ts +1 -1
  133. package/dist/tests/integration.test.js +66 -729
  134. package/dist/tests/integration.test.js.map +1 -1
  135. package/dist/tests/internal/controller-fields.test.d.ts +1 -0
  136. package/dist/tests/internal/controller-fields.test.js +25 -0
  137. package/dist/tests/internal/controller-fields.test.js.map +1 -0
  138. package/dist/tests/internal/http.d.ts +35 -0
  139. package/dist/tests/internal/http.js +56 -0
  140. package/dist/tests/internal/http.js.map +1 -0
  141. package/dist/tests/internal/shop-api.d.ts +1 -0
  142. package/dist/tests/internal/shop-api.js +331 -0
  143. package/dist/tests/internal/shop-api.js.map +1 -0
  144. package/dist/tests/internal/shop-schema.d.ts +162 -0
  145. package/dist/tests/internal/shop-schema.js +387 -0
  146. package/dist/tests/internal/shop-schema.js.map +1 -0
  147. package/dist/tests/utils.d.ts +8 -10
  148. package/dist/tests/utils.js +1 -3
  149. package/dist/tests/utils.js.map +1 -1
  150. package/dist/tests/utils.test.js +10 -11
  151. package/dist/tests/utils.test.js.map +1 -1
  152. package/docs/1.introduction.md +38 -35
  153. package/docs/10.joined.md +51 -40
  154. package/docs/11.computed.md +91 -47
  155. package/docs/2.data-controllers.md +50 -42
  156. package/docs/3.routes.md +156 -134
  157. package/docs/4.access-rights.md +48 -44
  158. package/docs/5.validators.md +65 -47
  159. package/docs/6.listable.md +53 -49
  160. package/docs/7.foreign-keys.md +55 -48
  161. package/docs/8.filters.md +65 -54
  162. package/docs/9.modifiers.md +29 -25
  163. package/package.json +34 -13
  164. package/skills/data-api-interface/SKILL.md +13 -3
  165. package/skills/data-api-interface/cases.json +99 -0
@@ -5,22 +5,21 @@ const chai_1 = require("chai");
5
5
  const utils_1 = require("./utils");
6
6
  const WRAPPER_DEPTHS = [1, 2, 5, 20];
7
7
  describe("Test utils", () => {
8
- it("returns the name of the calling function", () => returnsTheCallerName());
9
- it("skips frames added outside the tests folder", () => skipsFramesAddedOutsideTheTestsFolder());
8
+ it("returns the name of the calling function", () => expectReturnsTheCallerName());
9
+ it("skips frames added outside the tests folder", () => expectSkipsFramesAddedOutsideTheTestsFolder());
10
10
  });
11
- function returnsTheCallerName() {
12
- (0, chai_1.expect)((0, utils_1.getFunctionName)()).to.equal("returnsTheCallerName");
11
+ function expectReturnsTheCallerName() {
12
+ (0, chai_1.expect)((0, utils_1.getFunctionName)()).to.equal("expectReturnsTheCallerName");
13
13
  }
14
14
  function nameSeenThroughAsyncContexts(depth) {
15
15
  const storage = new node_async_hooks_1.AsyncLocalStorage();
16
- const run = storage.run.bind(storage);
17
- const nestedRuns = Array.from({ length: depth - 1 }, (_, store) => [
18
- run,
19
- store,
20
- ]).flat();
21
- return run(depth, ...nestedRuns, utils_1.getFunctionName);
16
+ let read = utils_1.getFunctionName;
17
+ for (let store = 0; store < depth; store++) {
18
+ read = storage.run.bind(storage, store, read);
19
+ }
20
+ return read();
22
21
  }
23
- function skipsFramesAddedOutsideTheTestsFolder() {
22
+ function expectSkipsFramesAddedOutsideTheTestsFolder() {
24
23
  for (const depth of WRAPPER_DEPTHS) {
25
24
  (0, chai_1.expect)(nameSeenThroughAsyncContexts(depth)).to.equal("nameSeenThroughAsyncContexts");
26
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../../src/tests/utils.test.ts"],"names":[],"mappings":";;AAAA,uDAAqD;AACrD,+BAA8B;AAE9B,mCAA0C;AAI1C,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAErC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAC7E,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE,CACrD,qCAAqC,EAAE,CAAC,CAAC;AAC7C,CAAC,CAAC,CAAC;AAEH,SAAS,oBAAoB;IAC3B,IAAA,aAAM,EAAC,IAAA,uBAAe,GAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,4BAA4B,CAAC,KAAa;IACjD,MAAM,OAAO,GAAG,IAAI,oCAAiB,EAAU,CAAC;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAa,CAAC;IAClD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACjE,GAAG;QACH,KAAK;KACN,CAAC,CAAC,IAAI,EAAE,CAAC;IACV,OAAO,GAAG,CAAC,KAAK,EAAE,GAAG,UAAU,EAAE,uBAAe,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,qCAAqC;IAC5C,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;QACnC,IAAA,aAAM,EAAC,4BAA4B,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAClD,8BAA8B,CAC/B,CAAC;IACJ,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../../src/tests/utils.test.ts"],"names":[],"mappings":";;AAAA,uDAAqD;AACrD,+BAA8B;AAE9B,mCAA0C;AAI1C,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAErC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE,CAClD,0BAA0B,EAAE,CAAC,CAAC;IAChC,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE,CACrD,2CAA2C,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC,CAAC;AAEH,SAAS,0BAA0B;IACjC,IAAA,aAAM,EAAC,IAAA,uBAAe,GAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,4BAA4B,CAAC,KAAa;IACjD,MAAM,OAAO,GAAG,IAAI,oCAAiB,EAAU,CAAC;IAChD,IAAI,IAAI,GAAe,uBAAe,CAAC;IACvC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;QAC3C,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAKrB,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,IAAI,EAAE,CAAC;AAChB,CAAC;AAED,SAAS,2CAA2C;IAClD,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;QACnC,IAAA,aAAM,EAAC,4BAA4B,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAClD,8BAA8B,CAC/B,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -1,21 +1,27 @@
1
- # Expose database records through an API
1
+ ---
2
+ title: Expose database records through an API
3
+ description: Build a first data controller that serves CRUD routes for a users table, then check which fields it reads and writes.
4
+ mode: tutorial
5
+ ---
2
6
 
3
7
  ## Overview
4
8
 
5
- Use `@antelopejs/interface-data-api` to expose a table through named CRUD routes and an explicit field policy. A data controller connects the table model to HTTP handlers; its metadata decides which fields clients may read, write, list, and filter.
9
+ In this tutorial, we expose a `users` table through five CRUD routes with `@antelopejs/interface-data-api`. A data controller connects the table model to HTTP handlers. Its metadata decides which fields clients can read, write, list and filter.
6
10
 
7
11
  ## Build one resource first
8
12
 
9
- 1. **Prepare the database.** Define a table and register its schema with database-decorators. Your AntelopeJS module needs a database provider and an API provider.
10
- 2. **Choose the routes.** Start with the [route set](./3.routes.md) your clients need, rather than exposing every write operation by default.
11
- 3. **Set the field policy.** Add [access rights](./4.access-rights.md), [validators](./5.validators.md), and [list fields](./6.listable.md). Field permissions are not user authentication or row-level authorization.
12
- 4. **Check one read and one rejected write.** Confirm the response excludes private fields and that invalid input cannot reach storage. Then add [relationships](./7.foreign-keys.md) and [filters](./8.filters.md).
13
+ We build one resource in four steps.
13
14
 
14
- ## Quick Start
15
+ 1. **Prepare the database.** Define a table and register its schema with database-decorators. The AntelopeJS project needs a database module and an API module.
16
+ 2. **Choose the routes.** Start with the [route set](./3.routes.md) your clients need, instead of exposing every write route by default.
17
+ 3. **Set the field policy.** Add [access rights](./4.access-rights.md), [validators](./5.validators.md) and [list fields](./6.listable.md). Field permissions do not authenticate users and do not authorize access to rows.
18
+ 4. **Check one read and one rejected write.** Confirm that the response leaves out private fields and that invalid input never reaches storage. Then add [relationships](./7.foreign-keys.md) and [filters](./8.filters.md).
15
19
 
16
- The following example declares all five CRUD routes for a `users` table. It assumes a configured provider and an existing `my-database` instance. Import the table declaration before calling `await RegisterSchema("myapp")` in the declaring module's initialization; await that setup before serving requests.
20
+ ## Quick start
17
21
 
18
- This is a field-policy example, not a production account system: write-only prevents a password from appearing in responses, but does not hash it or authenticate requests. Add an appropriate [database modifier](./9.modifiers.md) and your authentication policy before accepting real credentials.
22
+ The example declares all five CRUD routes for a `users` table. It assumes a configured database module and an existing `my-database` instance. Import the table declaration, then `await RegisterSchema("myapp")` when the declaring module initializes. Wait for that setup to finish before the module serves requests.
23
+
24
+ This example sets a field policy. It is not a production account system. `AccessMode.WriteOnly` keeps the password out of responses, but it does not hash the password or authenticate requests. Add a [database modifier](./9.modifiers.md) and your authentication policy before you accept real credentials.
19
25
 
20
26
  ```ts docs-check
21
27
  import { Controller } from "@antelopejs/interface-api";
@@ -40,7 +46,6 @@ import {
40
46
  Table,
41
47
  } from "@antelopejs/interface-database-decorators";
42
48
 
43
- // Define the database table
44
49
  @RegisterTable("users", "myapp")
45
50
  class User extends Table {
46
51
  @Field("string")
@@ -57,10 +62,8 @@ class User extends Table {
57
62
  declare password: string;
58
63
  }
59
64
 
60
- // Create the database model
61
65
  class UserModel extends BasicDataModel(User, "users") {}
62
66
 
63
- // Create the data controller
64
67
  @RegisterDataController()
65
68
  class UserAPI extends DataController(
66
69
  User,
@@ -91,38 +94,38 @@ class UserAPI extends DataController(
91
94
  }
92
95
  ```
93
96
 
94
- This generates the following REST endpoints:
97
+ The controller serves these REST endpoints.
95
98
 
96
- | Method | Endpoint | Description |
97
- | ------ | ----------------------- | -------------------------- |
98
- | GET | `/users/get?id=<id>` | Retrieve a single user |
99
- | GET | `/users/list?limit=10` | List users with pagination |
100
- | POST | `/users/new` | Create a new user |
101
- | PUT | `/users/edit?id=<id>` | Update an existing user |
102
- | DELETE | `/users/delete?id=<id>` | Delete a user |
99
+ | Method | Endpoint | Description |
100
+ | ------ | ----------------------- | -------------------- |
101
+ | GET | `/users/get?id=<id>` | Read one user |
102
+ | GET | `/users/list?limit=10` | List users, one page |
103
+ | POST | `/users/new` | Create a user |
104
+ | PUT | `/users/edit?id=<id>` | Update a user |
105
+ | DELETE | `/users/delete?id=<id>` | Delete a user |
103
106
 
104
107
  ### Check the field policy
105
108
 
106
- Use disposable data and your configured API base URL. Create a user with `name`, `email`, and a dummy `password`; the response is an array of inserted IDs. Use the first ID for the following checks:
109
+ Use disposable data and the base URL of your API module. First, create a user with `POST /users/new` and a body that holds `name`, `email` and a dummy `password`. The response is the created user, with its `_id` and without `password`. Use that `_id` in the next checks.
107
110
 
108
- 1. `GET /users/get?id=<id>` returns the readable fields, never `password`.
109
- 2. `GET /users/list?limit=10` includes `_id`, `name`, and `email` in `results`.
110
- 3. `PUT /users/edit?id=<id>` with `{ "name": "Updated" }` preserves the omitted email. With `{ "email": "" }`, it returns `400` because email is mandatory on edit.
111
+ 1. `GET /users/get?id=<id>` returns the readable fields. You see `_id`, `email` and `name`, and never `password`.
112
+ 2. `GET /users/list?limit=10` returns `_id`, `name` and `email` for each entry of `results`.
113
+ 3. `PUT /users/edit?id=<id>` with `{ "name": "Updated" }` keeps the email you did not send. With `{ "email": "" }`, the route answers `400`, because `email` is mandatory on `edit`.
111
114
 
112
- `@Mandatory` does not check email syntax or password strength. Add [validators](./5.validators.md) before accepting untrusted input.
115
+ `@Mandatory` does not check the email syntax or the password strength. Add [validators](./5.validators.md) before you accept untrusted input.
113
116
 
114
117
  ## Core guides
115
118
 
116
- - [Data Controllers](./2.data-controllers.md) - Create and configure data controllers
117
- - [Routes](./3.routes.md) - Default routes, custom routes, and route options
118
- - [Access Rights](./4.access-rights.md) - Control field read/write permissions
119
- - [Validators](./5.validators.md) - Field-level validation and mandatory fields
120
- - [Listable Fields](./6.listable.md) - Pagination, pluck modes, and sorting
119
+ - [Data controllers](./2.data-controllers.md). Create and configure data controllers.
120
+ - [Routes](./3.routes.md). Default routes, custom routes and route options.
121
+ - [Access rights](./4.access-rights.md). Which fields each action reads and writes.
122
+ - [Validators](./5.validators.md). Field validation and mandatory fields.
123
+ - [Listable fields](./6.listable.md). Pagination, pluck modes and sorting.
121
124
 
122
125
  ## Relationships and advanced queries
123
126
 
124
- - [Foreign Keys](./7.foreign-keys.md) - Establish relationships between tables
125
- - [Filters](./8.filters.md) - Add filtering capabilities to list endpoints
126
- - [Modifiers](./9.modifiers.md) - Automatic data transformation with database-decorators
127
- - [Joined Fields](./10.joined.md) - Flatten a remote field onto rows for native sort/filter
128
- - [Computed Fields](./11.computed.md) - In-database computed values, sortable and pageable natively
127
+ - [Foreign keys](./7.foreign-keys.md). Relations between tables.
128
+ - [Filters](./8.filters.md). Filters on list endpoints.
129
+ - [Modifiers](./9.modifiers.md). Data transformation with database-decorators modifiers.
130
+ - [Joined fields](./10.joined.md). A remote field flattened onto each row, sortable and filterable in the database.
131
+ - [Computed fields](./11.computed.md). Values computed in the database, sortable and pageable there.
package/docs/10.joined.md CHANGED
@@ -1,18 +1,22 @@
1
- # Joined Fields
1
+ ---
2
+ title: Joined fields
3
+ description: Flatten one field of another table onto each row with @Joined, so list requests sort and filter on it in the database.
4
+ mode: reference
5
+ ---
2
6
 
3
7
  ## Overview
4
8
 
5
- The `@Joined` decorator imports a single scalar field from another table and flattens it onto each row at query time. Unlike `@Foreign`, which embeds the full referenced record as a nested object in the response, `@Joined` copies one remote field to the top level of the row before sorting and filtering are applied. This makes the joined field natively sortable, filterable, and searchable in the database.
9
+ The `@Joined` decorator copies one scalar field from another table onto each row at query time. `@Foreign` nests the whole referenced record under the field. `@Joined` puts one remote field at the top level of the row, before the list query sorts and filters. The database can therefore sort, filter, and search on the joined field.
6
10
 
7
- Joined fields are read-only: the value is set by a lookup at query time and is never persisted on the controller's own table. Declaring a field as joined automatically sets its access mode to read-only and forces non-indexed sorting.
11
+ Joined fields are meant to be read-only. A lookup sets the value at query time, and the controller's own table never stores it. `@Joined` sets the field's access mode to read-only when it runs. An `@Access` written above it runs later and replaces that mode, so do not combine the two. `@Joined` also makes the field's sort non-indexed, whatever the decorator order.
8
12
 
9
- ## Basic Usage
13
+ ## Basic usage
10
14
 
11
- Apply `@Joined` to a field that should be populated from a remote table. The local row must carry a foreign key (`localKey`) that matches the remote table's `remoteIndex`.
15
+ Apply `@Joined` to a field that takes its value from a remote table. The local row must hold a key (`localKey`) that matches the remote table's `remoteIndex`.
12
16
 
13
- Use [foreign keys](./7.foreign-keys.md) when the response needs a nested record instead. The snippets below assume the controller imports and model from the [quick start](./1.introduction.md#quick-start), with `myapp` registered before requests are served.
17
+ Use [foreign keys](./7.foreign-keys.md) when the response needs a nested record instead. The snippets below assume the controller imports and the model from the [quick start](./1.introduction.md#quick-start), with `myapp` registered before the module serves requests.
14
18
 
15
- ```typescript
19
+ ```typescript fragment
16
20
  import { Joined } from "@antelopejs/interface-data-api/metadata";
17
21
  import {
18
22
  Field,
@@ -84,25 +88,27 @@ A GET request to `/orders/get?id=order-123` returns the joined value at the top
84
88
  }
85
89
  ```
86
90
 
87
- ## Decorator Parameters
91
+ ## Decorator parameters
88
92
 
89
- ```typescript
93
+ ```typescript fragment
90
94
  @Joined({ table, localKey, remoteField, remoteIndex?, schema? })
91
95
  ```
92
96
 
93
97
  | Option | Type | Required | Default | Description |
94
98
  | ------------- | -------------------------- | -------- | ----------------- | -------------------------------------------------------------------------------------------------- |
95
- | `table` | `Class<Table>` or `string` | Yes | - | The remote table class or registered table name string |
96
- | `localKey` | `string` | Yes | - | The field on the local row holding the value matched against the remote table |
97
- | `remoteField` | `string` | Yes | - | The remote field whose value is flattened onto the row |
99
+ | `table` | `Class<Table>` or `string` | Yes | None | The remote table class or registered table name string |
100
+ | `localKey` | `string` | Yes | None | The field on the local row holding the value matched against the remote table |
101
+ | `remoteField` | `string` | Yes | None | The remote field whose value is flattened onto the row |
98
102
  | `remoteIndex` | `string` | No | `"_id"` | The index on the remote table to match `localKey` against |
99
103
  | `schema` | `string` | No | Controller schema | Name of the schema the remote table is registered in, when it differs from the controller's schema |
100
104
 
101
- ## Sorting and Filtering
105
+ When a list mode includes a joined field, the mode also selects the field's `localKey`.
102
106
 
103
- Because the join is applied to the underlying query before sorting and filtering, joined fields behave like native columns. Combine `@Joined` with `@Sortable` or `@Filter` to order or filter by the imported value.
107
+ ## Sorting and filtering
104
108
 
105
- ```typescript
109
+ The list query applies the join before it sorts and filters, so a joined field behaves like a stored column. Combine `@Joined` with `@Sortable` or `@Filter` to sort or filter on the joined value.
110
+
111
+ ```typescript fragment
106
112
  @Sortable()
107
113
  @Filter()
108
114
  @Joined({
@@ -113,30 +119,35 @@ Because the join is applied to the underlying query before sorting and filtering
113
119
  declare userName: string;
114
120
  ```
115
121
 
116
- Joined fields are always sorted without a database index (`@Sortable` is forced to non-indexed for them), since the value comes from a runtime lookup rather than a stored column.
122
+ A joined field always sorts without a database index, because its value comes from a lookup at query time and not from a stored column. `@Sortable` on a joined field is always non-indexed.
117
123
 
118
- ## Deferred Resolution on Lists
124
+ ## Deferred resolution on lists
119
125
 
120
- The default list route handles this scheduling for you. Continue with [cross-schema joins](#cross-schema-joins) unless you are building a custom route with `Query.List`.
126
+ The default list route schedules the lookups itself. Skip to [cross-schema joins](#cross-schema-joins) unless you are building a custom route with `Query.List`.
121
127
 
122
- ![Joined fields used by filters are resolved before counting; sort fields before paging; display-only fields after paging in the default list route.](./assets/joined-list.svg){width="480"}
128
+ ![Joined fields used by filters are resolved before counting; sort fields before paging; display-only fields after paging in the default list route.](./assets/joined-list.svg "illustration"){width="480"}
123
129
 
124
130
  ### Advanced: composing `Query.List`
125
131
 
126
- `Query.List` only materializes the joined groups that the request's sort or filters reference before the count. The remaining display-only groups are deferred: the returned stream resolves them itself as soon as an operation can observe them, so destructuring `[query, total]` alone always yields rows with every `@Joined` field resolved.
132
+ `Query.List` resolves the joined fields that the request's filters read before it counts the rows. It resolves the joined fields that the sort reads after the count and before the sort. It defers the remaining display-only joined fields. The returned stream resolves them as soon as an operation can read rows, so destructuring `[query, total]` alone always gives rows with every `@Joined` field resolved.
127
133
 
128
- - Paging the stream (`slice`, `nth`) appends the lookups after the page boundary, so they only run on the returned rows.
129
- - A bare `count()` — and any field aggregate (`sum`, `min`, `distinct(field)`, ...) on a non-joined field — skips them entirely (left-join lookups never change the row count nor other fields).
130
- - `changes()` attaches to the raw stream, since change feeds cannot carry the join lookups.
131
- - Any other operation (`filter`, `orderBy`, `map`, ...) materializes them first, since it may read the joined values.
134
+ - Paging the stream (`slice`, `nth`) adds the lookups after the page boundary, so they run only on the returned rows.
135
+ - A bare `count()` skips the lookups, and so does a field aggregate such as `sum`, `min`, or `distinct(field)` on a field that is not joined. A left-join lookup never changes the row count or the other fields.
136
+ - `changes()` attaches to the raw stream, because change feeds cannot carry the join lookups.
137
+ - Any other operation, such as `filter`, `orderBy`, or `map`, resolves the lookups first, because it may read the joined values.
132
138
 
133
- The page-only benefit therefore holds as long as paging is the first thing the caller does. An operation applied to the whole stream before paging — a filter, a sort, or the `lookup` that `Query.Foreign` stages for a `@Foreign` field — materializes the joined groups over the whole matched set instead. The lookups still stay out of the count pipeline, but a caller that wants them strictly on the page must pass `{ exposeDeferredJoined: true }` to `Query.List` and resolve them itself after the slice: the raw stream is then returned unchanged and the third tuple element names the joined fields left to resolve with `Query.Joined`. This is what the default list route does, which also lets it limit the page lookups to the plucked fields.
139
+ The lookups therefore run on the page only when paging is the first operation the caller applies. An operation on the whole stream before paging resolves the joined fields over the whole matched set. Such operations include a filter, a sort, and the `lookup` that `Query.Foreign` adds for a `@Foreign` field. The lookups still stay out of the count. A caller that wants them on the page only must pass `{ exposeDeferredJoined: true }` to `Query.List` and resolve them after the slice. `Query.List` then returns the raw stream unchanged, and the third tuple element names the joined fields to resolve with `Query.Joined`. The default list route works this way, which also lets it limit the page lookups to the plucked fields.
134
140
 
135
141
  ### Reading a page: `Query.ListPage`
136
142
 
137
- A custom list route over `Query.List` reads its page with `Query.ListPage` rather than chaining the steps itself. It slices the stream, then resolves on the page only, in this order: the deferred joined groups, the `@Computed` fields the filters and the sort did not already merge, the `@Foreign` relations (last, since a computed expression may read a relation's key), and the pluck.
143
+ A custom list route over `Query.List` reads its page with `Query.ListPage` instead of chaining the steps itself. `Query.ListPage` slices the stream, then resolves these on the page only, in this order:
144
+
145
+ 1. The deferred joined fields.
146
+ 2. The `@Computed` fields that the filters and the sort did not already merge.
147
+ 3. The `@Foreign` relations. They come last because a computed expression may read a relation's key.
148
+ 4. The pluck.
138
149
 
139
- ```typescript
150
+ ```typescript fragment
140
151
  const [query, total, deferredJoined] = Query.List(
141
152
  this,
142
153
  meta,
@@ -158,11 +169,11 @@ const rows = await Query.ListPage(model.database, meta, query, {
158
169
  });
159
170
  ```
160
171
 
161
- ## Cross-Schema Joins
172
+ ## Cross-schema joins
162
173
 
163
- By default, the remote table is resolved in the same schema as the controller's table. Use the `schema` option to join against a table registered in a different schema; the join is resolved through the remote table's class, against the default instance of the schema `RegisterSchema` bound it to. The remote class must be registered with `@RegisterTable` before the field is declared; a string table name with no registered class in that schema throws at declaration.
174
+ By default, the Data API looks for the remote table in the schema of the controller's table. The `schema` option joins a table registered in a different schema. The join goes through the remote table's class, against the default instance of the schema that `RegisterSchema` bound it to. Register the remote class with `@RegisterTable` before you declare the field. A string table name with no registered class in that schema throws at declaration.
164
175
 
165
- ```typescript
176
+ ```typescript fragment
166
177
  @Joined({
167
178
  table: "users",
168
179
  localKey: "userId",
@@ -172,17 +183,17 @@ By default, the remote table is resolved in the same schema as the controller's
172
183
  declare userName: string;
173
184
  ```
174
185
 
175
- When a table class is passed, its schema is inferred from its `@RegisterTable` metadata. If both the class metadata and the explicit `schema` option specify a schema and they disagree, an error is thrown.
186
+ When you pass a table class, the Data API reads its schema from its `@RegisterTable` metadata. If the class metadata and the `schema` option name different schemas, the declaration throws.
176
187
 
177
- ## Joined vs. Foreign
188
+ ## `@Joined` compared with `@Foreign`
178
189
 
179
- | Aspect | `@Joined` | `@Foreign` |
180
- | ------------------- | -------------------------------------------- | --------------------------------------------------------------------- |
181
- | Result shape | A single scalar value flattened onto the row | The full referenced record (or plucked subset) nested under the field |
182
- | Access | Read-only (enforced) | Configurable via `@Access` |
183
- | Sort / filter | Native (join applied before sort/filter) | Not natively sortable/filterable on remote fields |
184
- | Multiple references | One remote field per decorator | Single or array (`multi`) references |
190
+ | Aspect | `@Joined` | `@Foreign` |
191
+ | ------------------- | ----------------------------------------------- | ------------------------------------------------------------------------- |
192
+ | Result shape | A single scalar value flattened onto the row | The full referenced record, or its plucked fields, nested under the field |
193
+ | Access | Read-only, unless a later `@Access` replaces it | Set with `@Access` |
194
+ | Sort and filter | In the database, join applied before both | No sort or filter on remote fields |
195
+ | Multiple references | One remote field per decorator | Single or array (`multi`) references |
185
196
 
186
- ## Next Steps
197
+ ## Next steps
187
198
 
188
- See the [computed fields documentation](./11.computed.md) to generalize this merge mechanism to arbitrary in-database expressions, or the [modifiers documentation](./9.modifiers.md) to learn how automatic data transformation integrates with the Data API.
199
+ To merge any in-database expression onto rows, see [Computed fields](./11.computed.md). To see how modifiers transform data in the Data API, see [Modifiers](./9.modifiers.md).
@@ -1,19 +1,45 @@
1
- # Computed Fields
1
+ ---
2
+ title: Computed fields
3
+ description: Compute a field in the database with @Computed, from the row or from a per-row subquery, and sort, filter, and page on it.
4
+ mode: reference
5
+ ---
2
6
 
3
7
  ## Overview
4
8
 
5
- The `@Computed` decorator declares a field whose value is computed in the database from an expression, then merged onto each row at query time. The expression can be a row-local computation (derived from other fields of the same row) or a per-row subquery, such as an aggregate over another table. Because the merge happens before sorting and filtering, computed fields are natively sortable, filterable, and pageable in DB — no fetch-all or in-memory sorting required.
9
+ The `@Computed` decorator declares a field whose value the database computes from an expression and merges onto each row at query time. The expression can compute from other fields of the same row, or run a per-row subquery such as an aggregate over another table. The merge happens before the list query sorts and filters, so the database sorts, filters, and pages computed fields. The API never fetches every row or sorts in memory.
6
10
 
7
- Computed fields are read-only: the value is produced by the query and is never persisted on the controller's table. Declaring a field as computed automatically sets its access mode to read-only and forces non-indexed sorting, regardless of decorator order.
11
+ Computed fields are meant to be read-only. The query produces the value, and the controller's table never stores it. `@Computed` sets the field's access mode to read-only when it runs. An `@Access` written above it runs later and replaces that mode, so do not combine the two. `@Computed` also makes the field's sort non-indexed, whatever the decorator order.
8
12
 
9
- ## Basic Usage
13
+ ## Basic usage
10
14
 
11
- The expression receives the row proxy and the schema instance of the controller's table. It must return a value built from the query builder (`ValueProxy` operations or a subquery), not plain JavaScript computed at request time.
15
+ The expression receives the row proxy and the schema instance of the controller's table. It must return a value built with the query builder (`ValueProxy` operations or a subquery), not plain JavaScript computed at request time.
12
16
 
13
- The snippets extend the [quick-start controller pattern](./1.introduction.md#quick-start); define `GroupModel` with `BasicDataModel(Group)` and register the `myapp` schema before serving requests. Check [driver support](#driver-support) before using aggregate subqueries.
17
+ The example follows the [quick-start controller pattern](./1.introduction.md#quick-start). Register the `myapp` schema before the module serves requests. Check [driver support](#driver-support) before you use aggregate subqueries.
14
18
 
15
19
  ```typescript
16
- import { Computed } from "@antelopejs/interface-data-api/metadata";
20
+ import { Controller } from "@antelopejs/interface-api";
21
+ import {
22
+ DataController,
23
+ DefaultRoutes,
24
+ RegisterDataController,
25
+ } from "@antelopejs/interface-data-api";
26
+ import {
27
+ Access,
28
+ AccessMode,
29
+ Computed,
30
+ Listable,
31
+ ModelReference,
32
+ Sortable,
33
+ } from "@antelopejs/interface-data-api/metadata";
34
+ import {
35
+ BasicDataModel,
36
+ Field,
37
+ Index,
38
+ Model,
39
+ RegisterTable,
40
+ Relation,
41
+ Table,
42
+ } from "@antelopejs/interface-database-decorators";
17
43
 
18
44
  @RegisterTable("groups", "myapp")
19
45
  class Group extends Table {
@@ -35,6 +61,8 @@ class Device extends Table {
35
61
  declare group_id: string;
36
62
  }
37
63
 
64
+ class GroupModel extends BasicDataModel(Group, "groups") {}
65
+
38
66
  @RegisterDataController()
39
67
  class GroupAPI extends DataController(
40
68
  Group,
@@ -56,7 +84,11 @@ class GroupAPI extends DataController(
56
84
  // Aggregate: number of devices referencing this group, computed in DB
57
85
  @Listable()
58
86
  @Computed(
59
- (row, db) => db.table("devices").getAll(row.key("_id"), "group_id").count(),
87
+ (row, db) =>
88
+ db
89
+ .table("devices")
90
+ .filter((device) => device.key("group_id").eq(row.key("_id")))
91
+ .count(),
60
92
  { default: 0 },
61
93
  )
62
94
  @Sortable()
@@ -64,11 +96,13 @@ class GroupAPI extends DataController(
64
96
 
65
97
  // Row-local expression
66
98
  @Listable()
67
- @Computed((row) => (row.key("name") as ValueProxy<string>).concat("!"))
99
+ @Computed((row) => row.key("name").concat("!"))
68
100
  declare display_name: string;
69
101
  }
70
102
  ```
71
103
 
104
+ The row proxy types every field as a `FieldValue`. The subquery compares each device's `group_id` with the row's `_id` through `eq`, which accepts that type. This filter checks every device for each row and does not use the `group_id` index. `getAll(row.key("_id"), "group_id")` would use the index, but `getAll` does not accept a row key typed as a `FieldValue`, so it compiles only with a cast.
105
+
72
106
  A GET request to `/groups/get?id=group-123` returns the computed values at the top level:
73
107
 
74
108
  ```json
@@ -80,69 +114,79 @@ A GET request to `/groups/get?id=group-123` returns the computed values at the t
80
114
  }
81
115
  ```
82
116
 
83
- ## Decorator Parameters
117
+ ## Decorator parameters
84
118
 
85
- ```typescript
119
+ ```typescript fragment
86
120
  @Computed(expr, options?)
87
121
  ```
88
122
 
89
- | Parameter | Type | Required | Description |
90
- | ----------------- | ------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
91
- | `expr` | `(row, db) => expression` | Yes | Expression receiving the row proxy and the schema instance; returns a `ValueProxy` expression or a subquery (`Datum`) |
92
- | `options.default` | `unknown` | No | Fallback merged over the computed value when the expression yields `null` |
123
+ | Parameter | Type | Required | Description |
124
+ | ----------------- | ------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------- |
125
+ | `expr` | `(row, db) => expression` | Yes | Expression receiving the row proxy and the schema instance. Returns a `ValueProxy` expression, a subquery (`Query`), or a constant |
126
+ | `options.default` | `FieldValue` | No | Fallback merged over the computed value when the expression yields `null` |
93
127
 
94
128
  ### The `default` option
95
129
 
96
- Aggregate subqueries yield `null` instead of their natural zero value when the underlying set is empty (a `count()` over a group with no devices returns `null`, not `0`). Calling `.default(0)` inside the subquery expression does not help: the aggregation produces no document at all, so there is nothing to apply the default to. The `options.default` value solves this by being applied at the row level, after the merge:
97
-
98
- ```typescript
99
- @Computed((row, db) => db.table("devices").getAll(row.key("_id"), "group_id").count(), {
100
- default: 0,
101
- })
130
+ An aggregate subquery over an empty set yields `null` instead of its zero value. A `count()` over a group with no devices returns `null`, not `0`. Calling `.default(0)` inside the subquery expression does not help, because the aggregation produces no document to apply the default to. The `options.default` value works because the Data API applies it to the row, after the merge:
131
+
132
+ ```typescript fragment
133
+ @Computed(
134
+ (row, db) =>
135
+ db
136
+ .table("devices")
137
+ .filter((device) => device.key("group_id").eq(row.key("_id")))
138
+ .count(),
139
+ { default: 0 },
140
+ )
102
141
  declare devices_count: number;
103
142
  ```
104
143
 
105
- Without it, rows with an empty aggregate carry `null`, which breaks equality filters (`filter_devices_count=eq:0`) and makes sort ordering depend on BSON type ordering.
144
+ Without it, a row with an empty aggregate holds `null`. An equality filter such as `filter_devices_count=eq:0` then misses the row, and the sort order depends on BSON type ordering.
106
145
 
107
- ## Sorting, Filtering, and Pagination
146
+ ## Sorting, filtering, and pagination
108
147
 
109
- Computed fields combine with `@Sortable` and `@Filter` like native columns. The framework injects the computation lazily, only when and where the value is needed:
148
+ Computed fields combine with `@Sortable` and `@Filter` like stored columns. The list query merges each computed field only where a step needs its value:
110
149
 
111
- - A computed field referenced by an active filter is merged before filters run.
112
- - A computed field used as the sort key is merged after the total count is captured and before the non-indexed `orderBy`, so the aggregate is not paid twice.
113
- - A computed field requested only for display (in the pluck, neither sorted nor filtered) is merged after pagination (`slice`), so it is computed only for the returned page, not the whole collection.
150
+ - A computed field that an active filter reads is merged before the filters run.
151
+ - A computed field used as the sort key is merged after the total count and before the non-indexed `orderBy`, so the count does not compute the aggregate.
152
+ - A computed field requested only for display, in the pluck and neither sorted nor filtered, is merged after pagination (`slice`). The database computes it for the returned page only.
114
153
 
115
- Sorting and pagination both stay in the database: sorting by a computed aggregate with `limit`/`offset` produces correct pages and a constant `total`.
154
+ Sorting and pagination both stay in the database. Sorting by a computed aggregate with `limit` and `offset` gives correct pages and the same `total` on every page.
116
155
 
117
- Computed fields are always sorted without a database index (`@Sortable` is forced to non-indexed), since the value does not exist as a stored column.
156
+ A computed field always sorts without a database index, because its value is not a stored column. `@Sortable` on a computed field is always non-indexed.
118
157
 
119
158
  ### Filtering on numeric computed fields
120
159
 
121
- Filter values arrive as strings from the query string. Use the validated `numberFilter` from [Numeric and Boolean Filters](./8.filters.md#numeric-and-boolean-filters), imported into the controller file. It rejects invalid numbers and honors the requested comparison operator; `parseFloat` alone accepts partial input such as `"3devices"`.
122
-
123
- ```typescript
124
- @Computed((row, db) => db.table("devices").getAll(row.key("_id"), "group_id").count(), {
125
- default: 0,
126
- })
160
+ Filter values arrive as strings from the query string. Import the validated `numberFilter` from [Numeric and boolean filters](./8.filters.md#numeric-and-boolean-filters) into the controller file. It rejects invalid numbers and applies the requested comparison operator. `parseFloat` alone accepts partial input such as `"3devices"`.
161
+
162
+ ```typescript fragment
163
+ @Computed(
164
+ (row, db) =>
165
+ db
166
+ .table("devices")
167
+ .filter((device) => device.key("group_id").eq(row.key("_id")))
168
+ .count(),
169
+ { default: 0 },
170
+ )
127
171
  @Filter(numberFilter, false)
128
172
  declare devices_count: number;
129
173
  ```
130
174
 
131
- ## Computed vs. Joined
175
+ ## `@Computed` compared with `@Joined`
132
176
 
133
- | Aspect | `@Computed` | `@Joined` |
134
- | ------------- | --------------------------------------------------------------- | ------------------------------------------------------------ |
135
- | Source | Arbitrary expression: row-local computation or per-row subquery | One scalar field from another table matched by a foreign key |
136
- | Typical use | Aggregates (`count`, `sum`), derived values | Flattening a referenced record's field |
137
- | Access | Read-only (enforced) | Read-only (enforced) |
138
- | Sort / filter | Native, lazily injected only where needed | Native, always applied before sort/filter |
177
+ | Aspect | `@Computed` | `@Joined` |
178
+ | --------------- | ---------------------------------------------------------------- | ------------------------------------------------------------ |
179
+ | Source | Any expression: a computation over the row or a per-row subquery | One scalar field from another table matched by a foreign key |
180
+ | Typical use | Aggregates (`count`, `sum`), derived values | Flattening a field of a referenced record |
181
+ | Access | Read-only, unless a later `@Access` replaces it | Read-only, unless a later `@Access` replaces it |
182
+ | Sort and filter | In the database, merged only where a step needs the value | In the database, join applied before sort and filter |
139
183
 
140
- `@Joined` remains the simpler choice for the 1:1 flattening case; `@Computed` generalizes the same merge mechanism to arbitrary expressions.
184
+ For one field copied from one referenced record, `@Joined` is simpler. `@Computed` applies the same merge to any expression.
141
185
 
142
- ## Driver Support
186
+ ## Driver support
143
187
 
144
- The aggregate form relies on the database driver translating a per-row subquery inside a merge into a correlated lookup (`$lookup` with `let`/`pipeline` on MongoDB). This is supported by `@antelopejs/mongodb` >= 1.2.1. Row-local expressions only use standard expression compilation and work on any driver.
188
+ The aggregate form needs a database driver that turns a per-row subquery inside a merge into a correlated lookup. On MongoDB, the lookup is a `$lookup` with `let` and `pipeline`. The `@antelopejs/mongodb` changelog names the release that added this translation. Row-local expressions use standard expression compilation and work on any driver.
145
189
 
146
- ## Next Steps
190
+ ## Next steps
147
191
 
148
- See the [joined fields documentation](./10.joined.md) for the dedicated 1:1 flattening decorator.
192
+ For the decorator that copies one field from a referenced record, see [Joined fields](./10.joined.md).