lumen-framework 3.1.1 → 4.0.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 (258) hide show
  1. package/README.md +75 -109
  2. package/bin/lumen +23 -41
  3. package/dist/cli.cjs +856 -479
  4. package/dist/cli.cjs.map +4 -4
  5. package/dist/index.js +3273 -1719
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.mjs +3251 -1697
  8. package/dist/index.mjs.map +4 -4
  9. package/dist/testing.js +280 -0
  10. package/dist/testing.js.map +7 -0
  11. package/dist/testing.mjs +252 -0
  12. package/dist/testing.mjs.map +7 -0
  13. package/dist/types/errors/links-only-error.d.ts +13 -0
  14. package/dist/types/errors/reserved-field-name-error.d.ts +13 -0
  15. package/dist/types/errors/unknown-attribute-error.d.ts +13 -0
  16. package/dist/types/index.d.ts +14 -0
  17. package/dist/types/interfaces.d.ts +1 -1
  18. package/dist/types/packages/application/index.d.ts +38 -45
  19. package/dist/types/packages/application/initialize.d.ts +3 -5
  20. package/dist/types/packages/application/interfaces.d.ts +13 -5
  21. package/dist/types/packages/application/utils/create-controller.d.ts +14 -4
  22. package/dist/types/packages/application/utils/create-serializer.d.ts +2 -2
  23. package/dist/types/packages/application/utils/normalize-port.d.ts +1 -3
  24. package/dist/types/packages/application/utils/resolve-visibility.d.ts +15 -0
  25. package/dist/types/packages/application/utils/restrict-open-namespaces.d.ts +19 -0
  26. package/dist/types/packages/application/utils/validate-attributes.d.ts +17 -0
  27. package/dist/types/packages/application/utils/validate-links-only.d.ts +19 -0
  28. package/dist/types/packages/application/utils/validate-namespaced-serializers.d.ts +3 -3
  29. package/dist/types/packages/application/utils/validate-reserved-names.d.ts +12 -0
  30. package/dist/types/packages/application/utils/warn-query-param-names.d.ts +10 -0
  31. package/dist/types/packages/cli/commands/dbcreate.d.ts +1 -1
  32. package/dist/types/packages/cli/commands/dbdrop.d.ts +1 -1
  33. package/dist/types/packages/cli/commands/destroy.d.ts +3 -2
  34. package/dist/types/packages/cli/commands/generate.d.ts +5 -5
  35. package/dist/types/packages/cli/commands/index.d.ts +0 -1
  36. package/dist/types/packages/cli/generator/index.d.ts +6 -6
  37. package/dist/types/packages/cli/generator/interfaces.d.ts +3 -3
  38. package/dist/types/packages/cli/generator/utils/create-generator.d.ts +2 -2
  39. package/dist/types/packages/cli/generator/utils/generate-type.d.ts +9 -9
  40. package/dist/types/packages/cli/generator/utils/migration-conflict.d.ts +4 -4
  41. package/dist/types/packages/cli/templates/pnpm-workspace.d.ts +15 -0
  42. package/dist/types/packages/cli/utils/create-spinner.d.ts +14 -0
  43. package/dist/types/packages/cli/utils/print-statements.d.ts +12 -0
  44. package/dist/types/packages/cli/utils/server-database.d.ts +27 -0
  45. package/dist/types/packages/compiler/interfaces.d.ts +1 -1
  46. package/dist/types/packages/config/interfaces.d.ts +10 -4
  47. package/dist/types/packages/controller/constants.d.ts +7 -2
  48. package/dist/types/packages/controller/errors/related-record-not-found-error.d.ts +4 -4
  49. package/dist/types/packages/controller/index.d.ts +364 -473
  50. package/dist/types/packages/controller/interfaces.d.ts +21 -6
  51. package/dist/types/packages/controller/utils/find-many.d.ts +2 -5
  52. package/dist/types/packages/controller/utils/find-one.d.ts +2 -5
  53. package/dist/types/packages/controller/utils/params-to-query.d.ts +8 -10
  54. package/dist/types/packages/controller/utils/resolve-relationships.d.ts +1 -3
  55. package/dist/types/packages/controller/utils/validate-relationships.d.ts +5 -3
  56. package/dist/types/packages/controller/visibility/errors.d.ts +21 -0
  57. package/dist/types/packages/controller/visibility/index.d.ts +51 -0
  58. package/dist/types/packages/database/attribute/index.d.ts +4 -6
  59. package/dist/types/packages/database/attribute/interfaces.d.ts +1 -1
  60. package/dist/types/packages/database/attribute/utils/create-attribute.d.ts +3 -5
  61. package/dist/types/packages/database/attribute/utils/create-getter.d.ts +2 -2
  62. package/dist/types/packages/database/attribute/utils/create-setter.d.ts +3 -5
  63. package/dist/types/packages/database/constants.d.ts +1 -0
  64. package/dist/types/packages/database/errors/index.d.ts +1 -0
  65. package/dist/types/packages/database/errors/invalid-driver-error.d.ts +1 -3
  66. package/dist/types/packages/database/errors/migrations-pending-error.d.ts +1 -3
  67. package/dist/types/packages/database/errors/model-missing-error.d.ts +1 -3
  68. package/dist/types/packages/database/errors/relationship-config-error.d.ts +10 -0
  69. package/dist/types/packages/database/errors/unique-constraint-error.d.ts +1 -1
  70. package/dist/types/packages/database/index.d.ts +9 -6
  71. package/dist/types/packages/database/initialize.d.ts +3 -5
  72. package/dist/types/packages/database/interfaces.d.ts +115 -25
  73. package/dist/types/packages/database/migration/index.d.ts +5 -7
  74. package/dist/types/packages/database/migration/interfaces.d.ts +2 -4
  75. package/dist/types/packages/database/migration/utils/generate-timestamp.d.ts +9 -1
  76. package/dist/types/packages/database/model/index.d.ts +348 -759
  77. package/dist/types/packages/database/model/initialize-class.d.ts +7 -1
  78. package/dist/types/packages/database/model/interfaces.d.ts +30 -12
  79. package/dist/types/packages/database/model/utils/attribute.d.ts +14 -0
  80. package/dist/types/packages/database/model/utils/get-columns.d.ts +1 -3
  81. package/dist/types/packages/database/model/utils/persistence.d.ts +5 -14
  82. package/dist/types/packages/database/model/utils/process-write-error.d.ts +2 -2
  83. package/dist/types/packages/database/model/utils/run-hooks.d.ts +7 -3
  84. package/dist/types/packages/database/model/utils/validate.d.ts +4 -1
  85. package/dist/types/packages/database/query/errors/record-not-found-error.d.ts +1 -1
  86. package/dist/types/packages/database/query/index.d.ts +179 -3
  87. package/dist/types/packages/database/query/runner/index.d.ts +1 -3
  88. package/dist/types/packages/database/query/runner/utils/build-results.d.ts +3 -4
  89. package/dist/types/packages/database/query/utils/format-select.d.ts +1 -3
  90. package/dist/types/packages/database/relationship/index.d.ts +7 -6
  91. package/dist/types/packages/database/relationship/interfaces.d.ts +16 -3
  92. package/dist/types/packages/database/relationship/utils/getters.d.ts +7 -13
  93. package/dist/types/packages/database/relationship/utils/inverse-setters.d.ts +5 -9
  94. package/dist/types/packages/database/relationship/utils/setters.d.ts +7 -13
  95. package/dist/types/packages/database/relationship/utils/unassociate.d.ts +1 -3
  96. package/dist/types/packages/database/relationship/utils/update-relationship.d.ts +6 -2
  97. package/dist/types/packages/database/transaction/index.d.ts +9 -10
  98. package/dist/types/packages/database/transaction/interfaces.d.ts +7 -1
  99. package/dist/types/packages/database/utils/connect.d.ts +16 -3
  100. package/dist/types/packages/database/utils/create-migrations.d.ts +1 -3
  101. package/dist/types/packages/database/utils/normalize-model-name.d.ts +1 -3
  102. package/dist/types/packages/database/utils/pending-migrations.d.ts +1 -3
  103. package/dist/types/packages/database/utils/primary-key-type.d.ts +10 -0
  104. package/dist/types/packages/database/utils/type-for-column.d.ts +3 -5
  105. package/dist/types/packages/database/utils/validate-relationships.d.ts +13 -0
  106. package/dist/types/packages/database/validation/errors/validation-error.d.ts +4 -4
  107. package/dist/types/packages/database/validation/index.d.ts +3 -5
  108. package/dist/types/packages/database/validation/interfaces.d.ts +1 -1
  109. package/dist/types/packages/freezeable/map/index.d.ts +1 -3
  110. package/dist/types/packages/freezeable/set/index.d.ts +1 -3
  111. package/dist/types/packages/freezeable/utils/freeze.d.ts +5 -15
  112. package/dist/types/packages/freezeable/utils/is-frozen.d.ts +1 -3
  113. package/dist/types/packages/fs/index.d.ts +7 -7
  114. package/dist/types/packages/fs/interfaces.d.ts +4 -4
  115. package/dist/types/packages/fs/utils/parse-path.d.ts +2 -2
  116. package/dist/types/packages/fs/watcher/interfaces.d.ts +1 -1
  117. package/dist/types/packages/jsonapi/errors/invalid-content-type-error.d.ts +3 -5
  118. package/dist/types/packages/jsonapi/errors/not-acceptable-error.d.ts +2 -4
  119. package/dist/types/packages/jsonapi/errors/unsupported-media-type-error.d.ts +2 -4
  120. package/dist/types/packages/jsonapi/index.d.ts +1 -1
  121. package/dist/types/packages/jsonapi/interfaces.d.ts +47 -36
  122. package/dist/types/packages/jsonapi/utils/has-media-type-params.d.ts +1 -1
  123. package/dist/types/packages/jsonapi/utils/is-jsonapi.d.ts +1 -1
  124. package/dist/types/packages/jsonapi/utils/media-type.d.ts +2 -2
  125. package/dist/types/packages/loader/builder/index.d.ts +3 -3
  126. package/dist/types/packages/loader/builder/interfaces.d.ts +7 -7
  127. package/dist/types/packages/loader/builder/utils/create-children-builder.d.ts +2 -2
  128. package/dist/types/packages/loader/builder/utils/create-parent-builder.d.ts +9 -2
  129. package/dist/types/packages/loader/builder/utils/sort-by-namespace.d.ts +2 -2
  130. package/dist/types/packages/loader/index.d.ts +1 -1
  131. package/dist/types/packages/loader/interfaces.d.ts +2 -2
  132. package/dist/types/packages/loader/resolver/index.d.ts +2 -2
  133. package/dist/types/packages/loader/resolver/utils/closest-ancestor.d.ts +2 -2
  134. package/dist/types/packages/loader/resolver/utils/closest-child.d.ts +2 -2
  135. package/dist/types/packages/logger/constants.d.ts +3 -3
  136. package/dist/types/packages/logger/errors/invalid-config-error.d.ts +5 -0
  137. package/dist/types/packages/logger/index.d.ts +65 -142
  138. package/dist/types/packages/logger/interfaces.d.ts +52 -10
  139. package/dist/types/packages/logger/request-logger/index.d.ts +3 -5
  140. package/dist/types/packages/logger/request-logger/interfaces.d.ts +5 -5
  141. package/dist/types/packages/logger/request-logger/templates.d.ts +5 -9
  142. package/dist/types/packages/logger/request-logger/utils/filter-params.d.ts +6 -1
  143. package/dist/types/packages/logger/request-logger/utils/log-json.d.ts +2 -4
  144. package/dist/types/packages/logger/request-logger/utils/log-text.d.ts +1 -3
  145. package/dist/types/packages/logger/request-logger/utils/params-for.d.ts +9 -0
  146. package/dist/types/packages/logger/utils/error-name.d.ts +7 -0
  147. package/dist/types/packages/logger/utils/line.d.ts +1 -3
  148. package/dist/types/packages/logger/writer/constants.d.ts +0 -1
  149. package/dist/types/packages/logger/writer/index.d.ts +6 -6
  150. package/dist/types/packages/logger/writer/interfaces.d.ts +2 -2
  151. package/dist/types/packages/logger/writer/utils/format-message.d.ts +2 -2
  152. package/dist/types/packages/lumenify/index.d.ts +20 -5
  153. package/dist/types/packages/lumenify/utils/create-response-proxy.d.ts +1 -1
  154. package/dist/types/packages/pm/cluster/index.d.ts +56 -7
  155. package/dist/types/packages/pm/cluster/interfaces.d.ts +2 -1
  156. package/dist/types/packages/pm/index.d.ts +2 -2
  157. package/dist/types/packages/router/definitions/context/index.d.ts +5 -7
  158. package/dist/types/packages/router/definitions/context/utils/create-definition-group.d.ts +3 -5
  159. package/dist/types/packages/router/definitions/context/utils/create-definition.d.ts +11 -6
  160. package/dist/types/packages/router/definitions/context/utils/normalize-resource-args.d.ts +4 -5
  161. package/dist/types/packages/router/definitions/index.d.ts +5 -9
  162. package/dist/types/packages/router/definitions/interfaces.d.ts +4 -4
  163. package/dist/types/packages/router/index.d.ts +23 -11
  164. package/dist/types/packages/router/interfaces.d.ts +4 -4
  165. package/dist/types/packages/router/namespace/index.d.ts +7 -9
  166. package/dist/types/packages/router/namespace/interfaces.d.ts +3 -3
  167. package/dist/types/packages/router/namespace/utils/normalize-name.d.ts +1 -3
  168. package/dist/types/packages/router/namespace/utils/normalize-path.d.ts +1 -3
  169. package/dist/types/packages/router/resource/index.d.ts +7 -8
  170. package/dist/types/packages/router/resource/interfaces.d.ts +12 -4
  171. package/dist/types/packages/router/resource/utils/normalize-only.d.ts +3 -5
  172. package/dist/types/packages/router/route/action/enhancers/resource.d.ts +1 -3
  173. package/dist/types/packages/router/route/action/enhancers/track-perf.d.ts +1 -3
  174. package/dist/types/packages/router/route/action/index.d.ts +7 -2
  175. package/dist/types/packages/router/route/action/interfaces.d.ts +4 -0
  176. package/dist/types/packages/router/route/action/utils/create-page-links.d.ts +21 -5
  177. package/dist/types/packages/router/route/action/utils/get-action-name.d.ts +1 -3
  178. package/dist/types/packages/router/route/action/utils/get-controller-name.d.ts +1 -3
  179. package/dist/types/packages/router/route/index.d.ts +13 -9
  180. package/dist/types/packages/router/route/interfaces.d.ts +7 -5
  181. package/dist/types/packages/router/route/params/errors/client-generated-id-error.d.ts +4 -4
  182. package/dist/types/packages/router/route/params/errors/forbidden-parameter-error.d.ts +4 -4
  183. package/dist/types/packages/router/route/params/errors/index.d.ts +1 -0
  184. package/dist/types/packages/router/route/params/errors/invalid-parameter-error.d.ts +4 -6
  185. package/dist/types/packages/router/route/params/errors/parameter-not-nullable-error.d.ts +4 -6
  186. package/dist/types/packages/router/route/params/errors/parameter-range-error.d.ts +9 -0
  187. package/dist/types/packages/router/route/params/errors/parameter-required-error.d.ts +4 -6
  188. package/dist/types/packages/router/route/params/errors/parameter-type-error.d.ts +4 -6
  189. package/dist/types/packages/router/route/params/errors/parameter-value-error.d.ts +4 -6
  190. package/dist/types/packages/router/route/params/errors/resource-mismatch-error.d.ts +4 -6
  191. package/dist/types/packages/router/route/params/index.d.ts +5 -9
  192. package/dist/types/packages/router/route/params/interfaces.d.ts +12 -8
  193. package/dist/types/packages/router/route/params/parameter/forbidden-parameter.d.ts +1 -1
  194. package/dist/types/packages/router/route/params/parameter/ignored-parameter.d.ts +14 -0
  195. package/dist/types/packages/router/route/params/parameter/index.d.ts +21 -5
  196. package/dist/types/packages/router/route/params/parameter/interfaces.d.ts +2 -2
  197. package/dist/types/packages/router/route/params/parameter/utils/validate-range.d.ts +3 -0
  198. package/dist/types/packages/router/route/params/parameter/utils/validate-value.d.ts +1 -3
  199. package/dist/types/packages/router/route/params/parameter-group/index.d.ts +3 -5
  200. package/dist/types/packages/router/route/params/parameter-group/utils/missing-params.d.ts +8 -0
  201. package/dist/types/packages/router/route/params/utils/get-data-params.d.ts +5 -1
  202. package/dist/types/packages/router/route/params/utils/get-default-collection-params.d.ts +1 -3
  203. package/dist/types/packages/router/route/params/utils/get-default-member-params.d.ts +5 -2
  204. package/dist/types/packages/router/route/params/utils/get-query-params.d.ts +3 -9
  205. package/dist/types/packages/router/route/params/utils/get-url-params.d.ts +1 -3
  206. package/dist/types/packages/router/route/params/utils/parse-column-value.d.ts +16 -0
  207. package/dist/types/packages/router/route/params/utils/validate-client-id.d.ts +1 -1
  208. package/dist/types/packages/router/route/params/utils/validate-resource-id.d.ts +1 -3
  209. package/dist/types/packages/router/route/params/utils/validate-type.d.ts +3 -5
  210. package/dist/types/packages/router/route/utils/get-dynamic-segments.d.ts +1 -3
  211. package/dist/types/packages/router/route/utils/get-static-path.d.ts +6 -2
  212. package/dist/types/packages/router/utils/create-replacer.d.ts +10 -2
  213. package/dist/types/packages/serializer/index.d.ts +243 -434
  214. package/dist/types/packages/serializer/interfaces.d.ts +19 -1
  215. package/dist/types/packages/serializer/utils/include-tree.d.ts +12 -3
  216. package/dist/types/packages/serializer/utils/load-linkage.d.ts +9 -3
  217. package/dist/types/packages/server/errors/error-list.d.ts +25 -0
  218. package/dist/types/packages/server/errors/method-not-allowed-error.d.ts +11 -0
  219. package/dist/types/packages/server/index.d.ts +9 -9
  220. package/dist/types/packages/server/interfaces.d.ts +59 -7
  221. package/dist/types/packages/server/request/constants.d.ts +2 -2
  222. package/dist/types/packages/server/request/index.d.ts +3 -5
  223. package/dist/types/packages/server/request/interfaces.d.ts +72 -8
  224. package/dist/types/packages/server/request/parser/errors/malformed-request-error.d.ts +3 -5
  225. package/dist/types/packages/server/request/parser/index.d.ts +6 -1
  226. package/dist/types/packages/server/request/parser/utils/format.d.ts +13 -11
  227. package/dist/types/packages/server/request/parser/utils/normalize-document.d.ts +13 -0
  228. package/dist/types/packages/server/request/parser/utils/parse-nested-object.d.ts +1 -3
  229. package/dist/types/packages/server/request/parser/utils/parse-read.d.ts +2 -4
  230. package/dist/types/packages/server/request/parser/utils/parse-write.d.ts +17 -1
  231. package/dist/types/packages/server/request/utils/get-domain.d.ts +1 -3
  232. package/dist/types/packages/server/responder/index.d.ts +1 -3
  233. package/dist/types/packages/server/responder/utils/content-type-for.d.ts +8 -0
  234. package/dist/types/packages/server/responder/utils/data-for.d.ts +3 -5
  235. package/dist/types/packages/server/responder/utils/normalize.d.ts +2 -3
  236. package/dist/types/packages/server/response/index.d.ts +3 -5
  237. package/dist/types/packages/server/response/interfaces.d.ts +14 -3
  238. package/dist/types/packages/server/utils/client-ip-for.d.ts +10 -0
  239. package/dist/types/packages/server/utils/create-server-error.d.ts +11 -3
  240. package/dist/types/packages/server/utils/request-id-for.d.ts +9 -0
  241. package/dist/types/packages/server/utils/set-cors-headers.d.ts +2 -2
  242. package/dist/types/packages/server/utils/source-for.d.ts +19 -3
  243. package/dist/types/packages/server/utils/status-for-error.d.ts +6 -0
  244. package/dist/types/packages/server/utils/validate-accept.d.ts +1 -1
  245. package/dist/types/packages/server/utils/validate-content-type.d.ts +8 -3
  246. package/dist/types/packages/testing/audit-visibility.d.ts +189 -0
  247. package/dist/types/packages/testing/index.d.ts +4 -0
  248. package/dist/types/packages/testing/start-app.d.ts +52 -0
  249. package/dist/types/packages/testing/utils/identifiers-in.d.ts +14 -0
  250. package/dist/types/testing.d.ts +9 -0
  251. package/dist/types/utils/chalk.d.ts +16 -0
  252. package/dist/types/utils/pick.d.ts +2 -2
  253. package/package.json +54 -26
  254. package/dist/types/packages/cli/commands/test.d.ts +0 -4
  255. package/dist/types/packages/logger/utils/sql.d.ts +0 -4
  256. package/dist/types/packages/router/route/params/parameter-group/utils/has-required-params.d.ts +0 -5
  257. package/dist/types/utils/create-query-string.d.ts +0 -6
  258. package/dist/types/utils/has-own-property.d.ts +0 -1
@@ -1,418 +1,147 @@
1
- import type { Bundle$Namespace } from '../loader';
1
+ import type { BundleNamespace } from '../loader';
2
2
  import type { Model, ModelClass } from '../database';
3
- import type { JSONAPI$Document, JSONAPI$DocumentLinks, JSONAPI$ResourceObject, JSONAPI$RelationshipObject } from '../jsonapi';
4
- import type { Serializer$opts } from './interfaces';
3
+ import type { JsonApiDocument, JsonApiDocumentLinks, JsonApiResourceObject, JsonApiRelationshipObject, JsonApiRelationshipDocument } from '../jsonapi';
4
+ import type { SerializerFields, SerializerOptions, SerializerRouted } from './interfaces';
5
+ import { Scope } from '../controller/visibility';
5
6
  import type { Linkage } from './utils/load-linkage';
6
7
  import type { IncludeTree } from './utils/include-tree';
7
8
  /**
8
- * ## Overview
9
- *
10
- * The Serializer class is used to describe which attributes and relationships
11
- * to include for a particular resource.
12
- *
13
- * The attributes and relationships you declare in a Serializer will determine
14
- * the attributes and relationships that will be included in the response from
15
- * the resource that the Serializer represents.
16
- *
17
- * #### Attributes
18
- *
19
- * You can add attributes to your serializer using an array assigned to the
20
- * class property `attributes` like the example below.
21
- *
22
- * ```javascript
23
- * class UsersSerializer extends Serializer {
24
- * attributes = [
25
- * 'name',
26
- * 'email',
27
- * 'username',
28
- * 'createdAt',
29
- * 'updatedAt'
30
- * ];
31
- * }
32
- * ```
33
- *
34
- * Since the attributes required for a resource are declared ahead of time in a
35
- * Serializer, Lumen will optimize SQL queries for the resource to only include
36
- * what the Serializer needs to build the response.
37
- *
38
- * ```javascript
39
- * import { Serializer } from 'lumen-framework';
40
- *
41
- * class PostsSerializer extends Serializer {
42
- * attributes = [
43
- * 'body',
44
- * 'title',
45
- * 'createdAt'
46
- * ];
47
- * }
48
- *
49
- * export default PostsSerializer;
50
- * ```
51
- *
52
- * The Serializer above would result in resources returned from the `/posts`
53
- * endpoint to only include the `body`, `title`, and `createdAt` attributes. If
54
- * we wanted include an additional attribute such as `isPublic`, we would have
55
- * to add `'isPublic'` to the `attributes` property.
56
- *
57
- * ```javascript
58
- * import { Serializer } from 'lumen-framework';
59
- *
60
- * class PostsSerializer extends Serializer {
61
- * attributes = [
62
- * 'body',
63
- * 'title',
64
- * 'isPublic',
65
- * 'createdAt'
66
- * ];
67
- * }
68
- *
69
- * export default PostsSerializer;
70
- * ```
71
- *
72
- * #### Associations
73
- *
74
- * Similar to `attributes` you can declare associations by adding relationship
75
- * names to either the `hasOne` or `hasMany` property arrays on a Serializer.
76
- *
77
- * Serializers are not concerned with ownership when it comes to associations,
78
- * so both `hasOne` and `belongsTo` associations can be specified in the
79
- * `hasOne` array property.
80
- *
81
- * ```javascript
82
- * import { Model } from 'lumen-framework';
83
- *
84
- * class Post extends Model {
85
- * static hasOne = {
86
- * image: {
87
- * inverse: 'post'
88
- * }
89
- * };
90
- *
91
- * static hasMany = {
92
- * tags: {
93
- * inverse: 'posts',
94
- * through: 'categorization'
95
- * },
96
- *
97
- * comments: {
98
- * inverse: 'post'
99
- * }
100
- * };
101
- *
102
- * static belongsTo = {
103
- * user: {
104
- * inverse: 'posts'
105
- * }
106
- * };
107
- * }
108
- *
109
- * export default Post;
110
- * ```
111
- *
112
- * To include the `user` and `image` associations in the response returned from
113
- * the `/posts` endpoint, we must specify both associations in the `hasOne`
114
- * property array of the Serializer.
115
- *
116
- * ```javascript
117
- * import { Serializer } from 'lumen-framework';
118
- *
119
- * class PostsSerializer extends Serializer {
120
- * hasOne = [
121
- * 'user',
122
- * 'image'
123
- * ];
124
- * }
125
- *
126
- * export default PostsSerializer;
127
- * ```
128
- *
129
- * If we wanted to also include the `tags` and `comments` in the response, we
130
- * have to add a `hasMany` array property containing `'tags'` and `'comments'`.
131
- *
132
- * ```javascript
133
- * import { Serializer } from 'lumen-framework';
134
- *
135
- * class PostsSerializer extends Serializer {
136
- * hasOne = [
137
- * 'user',
138
- * 'image'
139
- * ];
140
- *
141
- * hasMany = [
142
- * 'tags',
143
- * 'comments'
144
- * ];
145
- * }
146
- *
147
- * export default PostsSerializer;
148
- * ```
149
- *
150
- * You no longer need to specify that `tags` is a many to many relationship
151
- * using the `Categorization` model as a join table.
152
- *
153
- * #### Including Related Resources
154
- *
155
- * When requesting related resources for an endpoint, the included resource will
156
- * follow the serialization rules defined by the included resources Serializer.
157
- *
158
- * If we request that the `posts` association is included from the `/users`
159
- * endpoint, we will only get the `attributes` that the `PostsSerializer` has
160
- * defined even though the response is processed by the `UsersSerializer`.
161
- * The same goes for relationships: each included resource carries the
162
- * `relationships` its own Serializer declares in `hasOne` and `hasMany`.
163
- *
164
- * Included resources follow the request's namespace: from `/admin/posts`,
165
- * included comments are serialized by `AdminCommentsSerializer` when it
166
- * exists and by `CommentsSerializer` otherwise (the same fallback a
167
- * namespaced Controller uses), and their links point into `/admin`.
168
- *
169
- * Relationship paths may be nested, e.g. `/posts?include=comments.user`, up
170
- * to the controller's `maxIncludeDepth` (3 by default). The intermediate
171
- * resources (the comments) are included along with the leaves (their users).
172
- *
173
- * #### Sparse Fieldsets
174
- *
175
- * When a request specifies the fields that it would like included in the
176
- * response, the fields **MUST** be declared in the `attributes` property array
177
- * of the resources Serializer, or they will be ignored.
178
- *
179
- * #### Namespaces
180
- *
181
- * When using namespaces, you are not required to have a Serializer for each
182
- * resource as long as a Serializer for the given resource can be resolved
183
- * upstream.
184
- *
185
- * For example, if you have a `posts` resource and you decide to implement an
186
- * admin namespace, you only need to export an `AdminPostsSerializer` from
187
- * `app/serializers/admin/posts.js` if you want to specify different attributes
188
- * or relationships than the `PostsSerializer` exported from
189
- * `app/serializers/posts.js`.
190
- *
191
- * In the event that you do want to specify different attributes or
192
- * relationships that the `PostsSerializer` exported from
193
- * `app/serializers/posts.js`, you are not required to extend `PostsSerializer`.
194
- *
195
- * ```javascript
196
- * import { Serializer } from 'lumen-framework';
197
- *
198
- * class PostsSerializer extends Serializer {
199
- * attributes = [
200
- * 'body',
201
- * 'title',
202
- * 'createdAt'
203
- * ];
204
- *
205
- * hasOne = [
206
- * 'user',
207
- * 'image'
208
- * ];
209
- *
210
- * hasMany = [
211
- * 'tags',
212
- * 'comments'
213
- * ];
214
- * }
215
- *
216
- * export default PostsSerializer;
217
- * ```
218
- *
219
- * To add the `isPublic` attribute to the response payload of requests to a
220
- * `/admin/posts` endpoint we can do either of the following examples:
221
- *
222
- * ```javascript
223
- * // app/serializers/admin/posts.js
224
- * import PostsSerializer from 'app/serializers/posts';
225
- *
226
- * class AdminPostsSerializer extends PostsSerializer {
227
- * attributes = [
228
- * 'body',
229
- * 'title',
230
- * 'isPublic',
231
- * 'createdAt'
232
- * ];
233
- * }
234
- *
235
- * export default AdminPostsSerializer;
236
- * ```
237
- *
238
- * OR
239
- *
240
- * ```javascript
241
- * // app/serializers/admin/posts.js
242
- * import { Serializer } from 'lumen-framework';
243
- *
244
- * class AdminPostsSerializer extends Serializer {
245
- * attributes = [
246
- * 'body',
247
- * 'title',
248
- * 'isPublic',
249
- * 'createdAt'
250
- * ];
251
- *
252
- * hasOne = [
253
- * 'user',
254
- * 'image'
255
- * ];
256
- *
257
- * hasMany = [
258
- * 'tags',
259
- * 'comments'
260
- * ];
261
- * }
262
- *
263
- * export default AdminPostsSerializer;
264
- * ```
265
- *
266
- * Even with inheritance, the examples above are a tad repetitive. We can
267
- * improve this code by exporting constants from `app/serializers/posts.js`.
9
+ * The base class of an app's serializers. A serializer lists what a
10
+ * resource looks like in a JSON:API document: its `attributes`, and its
11
+ * relationships in `hasOne` (to-one, whether the model's relationship is
12
+ * `hasOne` or `belongsTo`) and `hasMany`.
268
13
  *
269
14
  * ```javascript
15
+ * // app/serializers/posts.js
270
16
  * import { Serializer } from 'lumen-framework';
271
17
  *
272
- * export const HAS_ONE = [
273
- * 'user',
274
- * 'image'
275
- * ];
276
- *
277
- * export const HAS_MANY = [
278
- * 'tags',
279
- * 'comments'
280
- * ];
281
- *
282
- * export const ATTRIBUTES = [
283
- * 'body',
284
- * 'title',
285
- * 'createdAt'
286
- * ];
287
- *
288
18
  * class PostsSerializer extends Serializer {
289
- * hasOne = HAS_ONE;
290
- * hasMany = HAS_MANY;
291
- * attributes = ATTRIBUTES;
19
+ * attributes = ['title', 'body', 'createdAt'];
20
+ * hasOne = ['user'];
21
+ * hasMany = ['comments', 'tags'];
292
22
  * }
293
23
  *
294
24
  * export default PostsSerializer;
295
25
  * ```
296
26
  *
297
- * If we choose to use inheritance, our code can look like this:
298
- *
299
- * ```javascript
300
- * // app/serializers/admin/posts.js
301
- * import PostsSerializer, { ATTRIBUTES } from 'app/serializers/posts';
302
- *
303
- * class AdminPostsSerializer extends PostsSerializer {
304
- * attributes = [
305
- * ...ATTRIBUTES,
306
- * 'isPublic'
307
- * ];
308
- * }
309
- *
310
- * export default AdminPostsSerializer;
311
- * ```
312
- *
313
- * If we choose not use inheritance, our code can look like this:
314
- *
315
- * ```javascript
316
- * // app/serializers/admin/posts.js
317
- * import { Serializer } from 'lumen-framework';
318
- * import { HAS_ONE, HAS_MANY, ATTRIBUTES } from 'app/serializers/posts';
319
- *
320
- * class AdminPostsSerializer extends PostsSerializer {
321
- * hasOne = HAS_ONE;
322
- * hasMany = HAS_MANY;
323
- *
324
- * attributes = [
325
- * ...ATTRIBUTES,
326
- * 'isPublic'
327
- * ];
328
- * }
329
- *
330
- * export default AdminPostsSerializer;
331
- * ```
332
- *
333
- * @class Serializer
334
- * @public
27
+ * Lumen loads only the columns a serializer needs. The lists are also what
28
+ * clients may ask for: `sort` and `filter` default to the attributes,
29
+ * `include` accepts the relationships (nested up to the controller's
30
+ * `maxIncludeDepth`), and `fields[posts]` may name any of them. Each included
31
+ * resource is formatted by its own type's serializer.
32
+ *
33
+ * A namespace may have its own serializer for a type
34
+ * (`app/serializers/admin/posts.js`), used for that type everywhere in the
35
+ * namespace, included resources too; without one, the root serializer is used,
36
+ * unless the namespace's `ApplicationController` sets `serializerFallback =
37
+ * false`. See the
38
+ * [serializers guide](https://github.com/nickschot/lux/blob/main/docs/guides/serializers.md).
335
39
  */
336
40
  declare class Serializer<T extends Model> {
337
41
  /**
338
- * An Array of the `hasOne` or `belongsTo` relationships on a Serializer
339
- * instance's Model to include in the
340
- * `relationships` resource object of a serialized payload.
42
+ * The to-one relationships to serialize — the model's `hasOne` and
43
+ * `belongsTo` relationships alike.
341
44
  *
342
45
  * ```javascript
343
46
  * class PostsSerializer extends Serializer {
344
- * hasOne = [
345
- * 'user'
346
- * ];
47
+ * hasOne = ['user', 'image'];
347
48
  * }
348
49
  * ```
349
- *
350
- * @property hasOne
351
- * @type {Array}
352
- * @default []
353
- * @public
354
50
  */
355
51
  hasOne: Array<string>;
356
52
  /**
357
- * An Array of the `hasMany` relationships on a Serializer instance's Model to
358
- * include in the `relationships` resource object of a serialized payload.
53
+ * The to-many relationships to serialize.
359
54
  *
360
- * ```javscript
55
+ * ```javascript
361
56
  * class PostsSerializer extends Serializer {
362
- * hasMany = [
363
- * 'comments'
364
- * ];
57
+ * hasMany = ['comments', 'tags'];
365
58
  * }
366
59
  * ```
367
- *
368
- * @property hasMany
369
- * @type {Array}
370
- * @default []
371
- * @public
372
60
  */
373
61
  hasMany: Array<string>;
374
62
  /**
375
- * An array of the `attributes` on a Serializer instance's Model to include in
376
- * the `attributes` resource object of a serialized payload.
63
+ * The model attributes to serialize, camelCase as on the model; documents
64
+ * dasherize them (`createdAt` → `created-at`). Each must be a column of the
65
+ * model's table: the app refuses to boot when one isn't (a getter, say).
377
66
  *
378
- * ```javscript
67
+ * ```javascript
379
68
  * class PostsSerializer extends Serializer {
380
- * attributes = [
381
- * 'body',
382
- * 'title'
383
- * ];
69
+ * attributes = ['title', 'body', 'createdAt'];
384
70
  * }
385
71
  * ```
386
- *
387
- * @property attributes
388
- * @type {Array}
389
- * @default []
390
- * @public
391
72
  */
392
73
  attributes: Array<string>;
74
+ /**
75
+ * The `hasMany` relationships to serialize as links only: without resource
76
+ * linkage (`data`), so a resource with many related records stays small and
77
+ * their ids are not loaded. Clients load them from the relationship's
78
+ * `related` link when needed (ember-data does so for an async `hasMany`).
79
+ *
80
+ * ```javascript
81
+ * class PostsSerializer extends Serializer {
82
+ * hasMany = ['comments', 'tags'];
83
+ *
84
+ * linksOnly = ['comments'];
85
+ * }
86
+ * ```
87
+ *
88
+ * ```json
89
+ * "comments": {
90
+ * "links": {
91
+ * "self": "https://api.example.com/posts/1/relationships/comments",
92
+ * "related": "https://api.example.com/posts/1/comments"
93
+ * }
94
+ * }
95
+ * ```
96
+ *
97
+ * A relationship a request includes (`?include=comments`) keeps its `data`,
98
+ * since JSON:API requires every included resource to be linked from the
99
+ * document. So does one without a related endpoint where it is serialized
100
+ * (a namespace without a resource for the type), which would otherwise be
101
+ * left with nothing to load it from.
102
+ *
103
+ * Each name must be in `hasMany`, and have a related endpoint in at least
104
+ * one namespace that formats this type with this Serializer (the related
105
+ * type's resource routing `index`, this type's routing `show`), or the
106
+ * application refuses to boot.
107
+ */
108
+ linksOnly: Array<string>;
109
+ /**
110
+ * Allow `attributes`, `hasOne` or `hasMany` to name `type` or `id`.
111
+ *
112
+ * JSON:API forbids a field with either name: they share a namespace with
113
+ * the resource's own `type` and `id`. By default the application refuses
114
+ * to boot when a serializer lists one. Set this for a serializer whose
115
+ * clients already rely on such a field; the application then boots with a
116
+ * warning, and the field is sent as before:
117
+ *
118
+ * ```javascript
119
+ * class ReactionsSerializer extends Serializer {
120
+ * attributes = ['type', 'createdAt'];
121
+ *
122
+ * // `type` breaks JSON:API, but our clients read it.
123
+ * allowReservedNames = true;
124
+ * }
125
+ * ```
126
+ */
127
+ allowReservedNames: boolean;
393
128
  /**
394
129
  * The resolved Model that a Serializer instance represents.
395
130
  *
396
- * @property model
397
- * @type {Model}
398
- * @private
131
+ * @internal
399
132
  */
400
133
  model: ModelClass<T>;
401
134
  /**
402
135
  * A reference to the root Serializer for the namespace that a Serializer
403
136
  * instance is a member of.
404
137
  *
405
- * @property parent
406
- * @type {?Serializer}
407
- * @private
138
+ * @internal
408
139
  */
409
140
  parent: Serializer<Model> | null;
410
141
  /**
411
142
  * The namespace that a Serializer instance is a member of.
412
143
  *
413
- * @property namespace
414
- * @type {String}
415
- * @private
144
+ * @internal
416
145
  */
417
146
  namespace: string;
418
147
  /**
@@ -421,138 +150,182 @@ declare class Serializer<T extends Model> {
421
150
  * `serializerFor()` to serialize related resources in this Serializer's
422
151
  * namespace.
423
152
  *
424
- * @property serializers
425
- * @type {Map}
426
- * @private
153
+ * @internal
427
154
  */
428
- serializers?: Bundle$Namespace<Serializer<Model>>;
429
- constructor({ model, parent, namespace }: Serializer$opts<T>);
155
+ serializers?: BundleNamespace<Serializer<Model>>;
156
+ constructor({ model, parent, namespace }: SerializerOptions<T>);
430
157
  /**
431
158
  * Transform an array of Model instances or a single Model instance into a
432
159
  * [JSON API](http://jsonapi.org) document object.
433
160
  *
434
- * @method format
435
161
  *
436
- * @param {Object} options - An options object used for building the
162
+ * @param options - An options object used for building the
437
163
  * returned [JSON API](http://jsonapi.org) document object.
438
164
  *
439
- * @param {Model|Array} options.data - The Model instance or array of
165
+ * @param options.data - The Model instance or array of
440
166
  * Model instances to transform into the returned [JSON API](
441
167
  * http://jsonapi.org) document object.
442
168
  *
443
- * @param {Object} options.links - An object containing links to include in
169
+ * @param options.links - An object containing links to include in
444
170
  * the top level links object of the returned [JSON API](http://jsonapi.org)
445
171
  * document object.
446
172
  *
447
- * @param {String} options.domain - A string used to build links included in
173
+ * @param options.domain - A string used to build links included in
448
174
  * the resource and relationship objects in the returned [JSON API](
449
175
  * http://jsonapi.org) document object.
450
176
  *
451
- * @param {Array} options.include - An array of relationship paths (e.g.
177
+ * @param options.include - An array of relationship paths (e.g.
452
178
  * `'comments'` or `'comments.user'`) whose resources should be added to the
453
179
  * top level included object of the returned [JSON API](http://jsonapi.org)
454
180
  * document object. Intermediate resources of a nested path are included too.
455
181
  *
456
- * @param {String} options.namespace - The namespace of the request, i.e. of
182
+ * @param options.fields - The request's sparse fieldsets, keyed by
183
+ * type. Each narrows the attributes and relationships of every resource of
184
+ * its type in the document; primary data was already loaded with its own.
185
+ *
186
+ * @param options.scope - The visibility rules of the request. Every
187
+ * related record loaded for the document — its linkage and `included` — is
188
+ * narrowed by them; primary data was already loaded through them.
189
+ *
190
+ * @param options.meta - Top level meta information of the returned
191
+ * document (`{ total }` for a page of a collection), if any.
192
+ *
193
+ * @param options.namespace - The namespace of the request, i.e. of
457
194
  * the Controller handling it. Every link in the document is built in it, and
458
195
  * included resources are serialized by their Serializer in it (falling back
459
196
  * to the root). Defaults to this Serializer's namespace — which is the root
460
197
  * one when a namespaced Controller has no Serializer of its own, so the
461
198
  * Controller passes its namespace explicitly.
462
199
  *
463
- * @return {Promise} Resolves with a [JSON API](http://jsonapi.org) document
200
+ * @param options.routed - Whether the application serves a path
201
+ * (`/posts/:dynamic/relationships/user`). A relationship is only given the
202
+ * links of the endpoints it is served by, since JSON:API requires every
203
+ * relationship `self` link to be served. Without it, none are.
204
+ *
205
+ * @returns Resolves with a [JSON API](http://jsonapi.org) document
464
206
  * object.
465
207
  *
466
- * @private
208
+ * @internal
467
209
  */
468
- format({ data, links, domain, include, namespace }: {
210
+ format({ data, meta, links, domain, include, fields, scope, namespace, routed }: {
469
211
  data: T | Array<T>;
470
- links: JSONAPI$DocumentLinks;
212
+ meta?: JsonApiDocument['meta'];
213
+ links: JsonApiDocumentLinks;
471
214
  domain: string;
472
215
  include: Array<string>;
216
+ fields?: SerializerFields;
217
+ scope?: Scope;
473
218
  namespace?: string;
474
- }): Promise<JSONAPI$Document>;
219
+ routed?: SerializerRouted;
220
+ }): Promise<JsonApiDocument>;
475
221
  /**
476
222
  * Transform a single Model instance into a [JSON API](http://jsonapi.org)
477
- * resource object.
223
+ * resource object. Its attributes are the ones loaded on `item`, declared by
224
+ * this Serializer and kept by the request's fieldset for its type; its
225
+ * relationships, those declared and kept, are built from `linkage`,
226
+ * batch-loaded by `loadLinkage()`, without touching the database.
478
227
  *
479
- * Relationships are serialized in one of two ways. By default each one is
480
- * read from the Model instance (for primary data the query has already
481
- * loaded them). When `linkage` is given — as it is for included resources,
482
- * whose relationships are batch-loaded by `addIncluded()` — the resource
483
- * linkage is built from it instead, without touching the database.
484
228
  *
485
- * @method formatOne
486
- *
487
- * @param {Object} options - An options object used for building the returned
229
+ * @param options - An options object used for building the returned
488
230
  * [JSON API](http://jsonapi.org) resource object.
489
231
  *
490
- * @param {Model} options.item - The Model instance to transform into the
232
+ * @param options.item - The Model instance to transform into the
491
233
  * returned [JSON API](http://jsonapi.org) resource object.
492
234
  *
493
- * @param {Object} options.links - An object containing links to include in
235
+ * @param options.links - An object containing links to include in
494
236
  * the top level links object of the returned [JSON API](http://jsonapi.org)
495
237
  * resource object.
496
238
  *
497
- * @param {String} options.domain - A string used to build links included in
239
+ * @param options.domain - A string used to build links included in
498
240
  * the top level links object or relationship links objects in the returned
499
241
  * [JSON API](http://jsonapi.org) resource object.
500
242
  *
501
- * @param {Array} options.include - An array of the relationship keys whose
502
- * related records should be collected into `options.related`.
503
- *
504
- * @param {Map} options.related - Collects, per relationship key in
505
- * `options.include`, the related Model instances that belong in the top
506
- * level included object of a [JSON API](http://jsonapi.org) document object.
243
+ * @param options.linkage - The resource linkage (related primary
244
+ * keys per relationship key) to serialize relationships from.
507
245
  *
508
- * @param {Object} options.linkage - Pre-loaded resource linkage (related
509
- * primary keys per relationship key) to serialize relationships from.
246
+ * @param options.fields - The request's sparse fieldsets, keyed by
247
+ * type. Only the one for this resource's type applies.
510
248
  *
511
- * @param {String} options.namespace - The namespace to build links in.
249
+ * @param options.namespace - The namespace to build links in.
512
250
  * Defaults to this Serializer's; included resources pass the namespace of
513
251
  * the request, so every link in a document points into the same namespace.
514
252
  *
515
- * @return {Promise} Resolves with a [JSON API](http://jsonapi.org) resource
253
+ * @param options.routed - Whether the application serves a path;
254
+ * see `format()`.
255
+ *
256
+ * @param options.linksOnly - The relationships to serialize without
257
+ * resource linkage; see `linksOnlyFor()`.
258
+ *
259
+ * @returns Resolves with a [JSON API](http://jsonapi.org) resource
516
260
  * object.
517
261
  *
518
- * @private
262
+ * @internal
519
263
  */
520
- formatOne({ item, links, domain, include, related, linkage, namespace }: {
264
+ formatOne({ item, links, domain, linkage, fields, namespace, routed, linksOnly }: {
521
265
  item: T;
522
266
  links?: boolean;
523
267
  domain: string;
524
- include?: Array<string>;
525
- related?: Map<string, Array<Model>>;
526
268
  linkage?: Linkage;
269
+ fields?: SerializerFields;
527
270
  namespace?: string;
528
- }): Promise<JSONAPI$ResourceObject>;
271
+ routed?: SerializerRouted;
272
+ linksOnly?: Set<string>;
273
+ }): Promise<JsonApiResourceObject>;
529
274
  /**
530
- * Transform a single Model instance into a [JSON API](http://jsonapi.org)
531
- * relationship object.
532
- *
533
- * @method formatRelationship
534
- *
535
- * @param {Model} item - The Model instance to transform into the returned
536
- * [JSON API](http://jsonapi.org) relationship object.
537
- *
538
- * @param {String} domain - A string used to build links included in the
539
- * returned [JSON API](http://jsonapi.org) relationship object.
275
+ * The document a relationship endpoint (`/posts/1/relationships/user`)
276
+ * responds with: the relationship of `item` named `name` as resource
277
+ * linkage, narrowed by `scope` like any other linkage, and its links.
540
278
  *
541
- * @return {Object} A [JSON API](http://jsonapi.org) relationship object.
279
+ * @internal
280
+ */
281
+ formatRelationship({ item, name, domain, scope, namespace, routed }: {
282
+ item: T;
283
+ name: string;
284
+ domain: string;
285
+ scope?: Scope;
286
+ namespace?: string;
287
+ routed?: SerializerRouted;
288
+ }): Promise<JsonApiRelationshipDocument>;
289
+ /**
290
+ * The relationships of `linksOnly` to serialize without resource linkage at
291
+ * one level of a document, whose include tree is `tree`: those not included
292
+ * there (an included resource must be linked from the document) and with a
293
+ * related endpoint in `namespace` to load them from.
542
294
  *
543
- * @private
295
+ * @internal
544
296
  */
545
- formatRelationship(item: Model, domain: string, namespace?: string): JSONAPI$RelationshipObject;
297
+ linksOnlyFor(tree: IncludeTree, namespace: string, routed: SerializerRouted): Set<string>;
298
+ /**
299
+ * The `links` of the relationship `name` of the resource `type`/`id`: a
300
+ * `self` link to its relationship endpoint (`/posts/1/relationships/user`)
301
+ * and a `related` link to its related endpoint (`/posts/1/user`), each when
302
+ * the application serves it in `namespace` (JSON:API requires every
303
+ * relationship `self` link to be served). Without either the relationship
304
+ * has no links.
305
+ *
306
+ * A related resource's own URL (`/users/2`) is never a relationship's
307
+ * `related` link: that link must not change when the relationship's content
308
+ * does.
309
+ *
310
+ * @internal
311
+ */
312
+ relationshipLinksFor({ id, type, name, domain, routed, namespace }: {
313
+ id: string;
314
+ type: string;
315
+ name: string;
316
+ domain: string;
317
+ routed: SerializerRouted;
318
+ namespace: string;
319
+ }): Pick<JsonApiRelationshipObject, 'links'>;
546
320
  /**
547
321
  * Build a [JSON API](http://jsonapi.org) relationship object from resource
548
- * linkage, in the same shape `formatRelationship()` produces from Model
549
- * instances: to-one relationships carry a `links` object, to-many ones only
550
- * `data`, and a missing to-one relationship is `{ data: null }`.
322
+ * linkage: `{ data }`, where `data` is an identifier (or `null`) for a
323
+ * to-one relationship and an array of them for a to-many one. Its links
324
+ * come from `relationshipLinksFor()`.
551
325
  *
552
- * @method formatLinkage
553
- * @private
326
+ * @internal
554
327
  */
555
- formatLinkage(domain: string, type: string | undefined, linkage: Array<string> | string | null | undefined, namespace?: string): JSONAPI$RelationshipObject;
328
+ formatLinkage(type: string | undefined, linkage: Array<string> | string | null | undefined): JsonApiRelationshipObject;
556
329
  /**
557
330
  * Add `records` (instances of `model`) to `included` as resource objects,
558
331
  * then recurse into the relationships named in `tree`. Each is serialized by
@@ -561,17 +334,49 @@ declare class Serializer<T extends Model> {
561
334
  * is one and `CommentsSerializer` otherwise. The relationships of every level
562
335
  * are batch-loaded with one query per relationship, not one per record.
563
336
  *
564
- * @method addIncluded
565
- * @private
337
+ * @internal
566
338
  */
567
- addIncluded({ model, records, tree, domain, included, namespace }: {
339
+ addIncluded({ model, records, tree, scope, domain, fields, routed, included, namespace }: {
568
340
  model: ModelClass;
569
341
  records: Array<Model>;
570
342
  tree: IncludeTree;
343
+ scope: Scope;
344
+ domain: string;
345
+ fields: SerializerFields;
346
+ routed: SerializerRouted;
347
+ included: Map<string, JsonApiResourceObject>;
348
+ namespace: string;
349
+ }): Promise<void>;
350
+ /**
351
+ * Load the records `linkage` points to through each relationship named in
352
+ * `tree` — one query per relationship, selecting the attributes their
353
+ * Serializer (narrowed by the request's `fields[type]`) will serialize —
354
+ * and add them to `included` with `addIncluded()`. Only the relationships in
355
+ * `names`, those the parent's Serializer exposes, are followed. The tree is
356
+ * walked in request order, so `included` is deterministic.
357
+ *
358
+ * @internal
359
+ */
360
+ includeRelated({ model, names, linkage, tree, scope, domain, fields, routed, included, namespace }: {
361
+ model: ModelClass;
362
+ names: Array<string>;
363
+ linkage: Map<string, Linkage>;
364
+ tree: IncludeTree;
365
+ scope: Scope;
571
366
  domain: string;
572
- included: Map<string, JSONAPI$ResourceObject>;
367
+ fields: SerializerFields;
368
+ routed: SerializerRouted;
369
+ included: Map<string, JsonApiResourceObject>;
573
370
  namespace: string;
574
371
  }): Promise<void>;
372
+ /**
373
+ * The attributes to load for included resources of `model`: those its
374
+ * Serializer in `namespace` declares, narrowed to the request's
375
+ * `fields[type]` when there is one — possibly to none.
376
+ *
377
+ * @internal
378
+ */
379
+ attributesFor(model: ModelClass, namespace: string, fields: SerializerFields): Array<string>;
575
380
  /**
576
381
  * Resolve the Serializer for `model` in `namespace` (this Serializer's by
577
382
  * default), the way a namespaced Controller resolves its own:
@@ -584,13 +389,17 @@ declare class Serializer<T extends Model> {
584
389
  * namespace is the root one whenever it is a namespaced Controller's
585
390
  * fallback.
586
391
  *
587
- * @method serializerFor
588
- * @private
392
+ * @internal
589
393
  */
590
394
  serializerFor(model: ModelClass, namespace?: string): Serializer<Model>;
395
+ /** @internal */
396
+ linkFor(domain: string, type: string, id: string, namespace?: string): string;
591
397
  /**
592
- * @private
398
+ * The path of the resource `type`/`id` in `namespace`.
399
+ *
400
+ * @internal
593
401
  */
594
- linkFor(domain: string, type: string, id: string, namespace?: string): string;
402
+ pathFor(type: string, id: string, namespace?: string): string;
595
403
  }
596
404
  export default Serializer;
405
+ export type { SerializerOptions } from './interfaces';