lumen-framework 3.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 (302) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +164 -0
  3. package/bin/lumen +275 -0
  4. package/dist/cli.cjs +3002 -0
  5. package/dist/cli.cjs.map +7 -0
  6. package/dist/index.js +6515 -0
  7. package/dist/index.js.map +7 -0
  8. package/dist/index.mjs +6480 -0
  9. package/dist/index.mjs.map +7 -0
  10. package/dist/types/constants.d.ts +7 -0
  11. package/dist/types/errors/controller-missing-error.d.ts +7 -0
  12. package/dist/types/errors/serializer-missing-error.d.ts +7 -0
  13. package/dist/types/index.d.ts +6 -0
  14. package/dist/types/interfaces.d.ts +12 -0
  15. package/dist/types/packages/application/index.d.ts +97 -0
  16. package/dist/types/packages/application/initialize.d.ts +6 -0
  17. package/dist/types/packages/application/interfaces.d.ts +16 -0
  18. package/dist/types/packages/application/utils/create-controller.d.ts +12 -0
  19. package/dist/types/packages/application/utils/create-serializer.d.ts +4 -0
  20. package/dist/types/packages/application/utils/normalize-port.d.ts +4 -0
  21. package/dist/types/packages/cli/commands/build.d.ts +1 -0
  22. package/dist/types/packages/cli/commands/create.d.ts +4 -0
  23. package/dist/types/packages/cli/commands/dbcreate.d.ts +4 -0
  24. package/dist/types/packages/cli/commands/dbdrop.d.ts +4 -0
  25. package/dist/types/packages/cli/commands/dbmigrate.d.ts +4 -0
  26. package/dist/types/packages/cli/commands/dbrollback.d.ts +4 -0
  27. package/dist/types/packages/cli/commands/dbseed.d.ts +4 -0
  28. package/dist/types/packages/cli/commands/destroy.d.ts +11 -0
  29. package/dist/types/packages/cli/commands/generate.d.ts +10 -0
  30. package/dist/types/packages/cli/commands/index.d.ts +12 -0
  31. package/dist/types/packages/cli/commands/repl.d.ts +1 -0
  32. package/dist/types/packages/cli/commands/serve.d.ts +8 -0
  33. package/dist/types/packages/cli/commands/test.d.ts +4 -0
  34. package/dist/types/packages/cli/constants.d.ts +2 -0
  35. package/dist/types/packages/cli/errors/database-config-missing.d.ts +4 -0
  36. package/dist/types/packages/cli/generator/constants.d.ts +5 -0
  37. package/dist/types/packages/cli/generator/index.d.ts +11 -0
  38. package/dist/types/packages/cli/generator/interfaces.d.ts +9 -0
  39. package/dist/types/packages/cli/generator/utils/create-generator.d.ts +9 -0
  40. package/dist/types/packages/cli/generator/utils/generate-type.d.ts +33 -0
  41. package/dist/types/packages/cli/generator/utils/generator-for.d.ts +2 -0
  42. package/dist/types/packages/cli/generator/utils/log.d.ts +4 -0
  43. package/dist/types/packages/cli/generator/utils/migration-conflict.d.ts +6 -0
  44. package/dist/types/packages/cli/templates/application.d.ts +5 -0
  45. package/dist/types/packages/cli/templates/config.d.ts +5 -0
  46. package/dist/types/packages/cli/templates/controller.d.ts +5 -0
  47. package/dist/types/packages/cli/templates/database.d.ts +5 -0
  48. package/dist/types/packages/cli/templates/empty-migration.d.ts +5 -0
  49. package/dist/types/packages/cli/templates/eslint-config.d.ts +5 -0
  50. package/dist/types/packages/cli/templates/gitignore.d.ts +5 -0
  51. package/dist/types/packages/cli/templates/license.d.ts +5 -0
  52. package/dist/types/packages/cli/templates/middleware.d.ts +5 -0
  53. package/dist/types/packages/cli/templates/model-migration.d.ts +5 -0
  54. package/dist/types/packages/cli/templates/model.d.ts +5 -0
  55. package/dist/types/packages/cli/templates/package-json.d.ts +5 -0
  56. package/dist/types/packages/cli/templates/readme.d.ts +5 -0
  57. package/dist/types/packages/cli/templates/routes.d.ts +5 -0
  58. package/dist/types/packages/cli/templates/seed.d.ts +5 -0
  59. package/dist/types/packages/cli/templates/serializer.d.ts +5 -0
  60. package/dist/types/packages/cli/templates/util.d.ts +5 -0
  61. package/dist/types/packages/cli/utils/create-prompt.d.ts +4 -0
  62. package/dist/types/packages/cli/utils/driver-for.d.ts +1 -0
  63. package/dist/types/packages/cli/utils/indent.d.ts +1 -0
  64. package/dist/types/packages/compiler/index.d.ts +11 -0
  65. package/dist/types/packages/compiler/interfaces.d.ts +1 -0
  66. package/dist/types/packages/compiler/utils/create-boot-script.d.ts +6 -0
  67. package/dist/types/packages/compiler/utils/create-manifest.d.ts +6 -0
  68. package/dist/types/packages/compiler/utils/format-name.d.ts +5 -0
  69. package/dist/types/packages/config/index.d.ts +3 -0
  70. package/dist/types/packages/config/interfaces.d.ts +6 -0
  71. package/dist/types/packages/controller/constants.d.ts +2 -0
  72. package/dist/types/packages/controller/index.d.ts +591 -0
  73. package/dist/types/packages/controller/interfaces.d.ts +13 -0
  74. package/dist/types/packages/controller/utils/find-many.d.ts +6 -0
  75. package/dist/types/packages/controller/utils/find-one.d.ts +6 -0
  76. package/dist/types/packages/controller/utils/params-to-query.d.ts +16 -0
  77. package/dist/types/packages/controller/utils/resolve-relationships.d.ts +5 -0
  78. package/dist/types/packages/database/attribute/index.d.ts +6 -0
  79. package/dist/types/packages/database/attribute/interfaces.d.ts +6 -0
  80. package/dist/types/packages/database/attribute/utils/create-attribute.d.ts +5 -0
  81. package/dist/types/packages/database/attribute/utils/create-getter.d.ts +3 -0
  82. package/dist/types/packages/database/attribute/utils/create-normalizer.d.ts +1 -0
  83. package/dist/types/packages/database/attribute/utils/create-setter.d.ts +8 -0
  84. package/dist/types/packages/database/change-set/index.d.ts +10 -0
  85. package/dist/types/packages/database/constants.d.ts +3 -0
  86. package/dist/types/packages/database/errors/config-missing-error.d.ts +4 -0
  87. package/dist/types/packages/database/errors/index.d.ts +5 -0
  88. package/dist/types/packages/database/errors/invalid-driver-error.d.ts +7 -0
  89. package/dist/types/packages/database/errors/migrations-pending-error.d.ts +7 -0
  90. package/dist/types/packages/database/errors/model-missing-error.d.ts +7 -0
  91. package/dist/types/packages/database/errors/unique-constraint-error.d.ts +4 -0
  92. package/dist/types/packages/database/index.d.ts +26 -0
  93. package/dist/types/packages/database/initialize.d.ts +6 -0
  94. package/dist/types/packages/database/interfaces.d.ts +85 -0
  95. package/dist/types/packages/database/migration/index.d.ts +12 -0
  96. package/dist/types/packages/database/migration/interfaces.d.ts +4 -0
  97. package/dist/types/packages/database/migration/utils/generate-timestamp.d.ts +2 -0
  98. package/dist/types/packages/database/model/index.d.ts +1046 -0
  99. package/dist/types/packages/database/model/initialize-class.d.ts +10 -0
  100. package/dist/types/packages/database/model/interfaces.d.ts +14 -0
  101. package/dist/types/packages/database/model/utils/get-columns.d.ts +5 -0
  102. package/dist/types/packages/database/model/utils/persistence.d.ts +18 -0
  103. package/dist/types/packages/database/model/utils/process-write-error.d.ts +4 -0
  104. package/dist/types/packages/database/model/utils/run-hooks.d.ts +6 -0
  105. package/dist/types/packages/database/model/utils/validate.d.ts +5 -0
  106. package/dist/types/packages/database/query/errors/index.d.ts +1 -0
  107. package/dist/types/packages/database/query/errors/record-not-found-error.d.ts +6 -0
  108. package/dist/types/packages/database/query/index.d.ts +38 -0
  109. package/dist/types/packages/database/query/runner/constants.d.ts +2 -0
  110. package/dist/types/packages/database/query/runner/index.d.ts +9 -0
  111. package/dist/types/packages/database/query/runner/utils/build-results.d.ts +10 -0
  112. package/dist/types/packages/database/query/runner/utils/get-find-param.d.ts +2 -0
  113. package/dist/types/packages/database/query/utils/format-select.d.ts +5 -0
  114. package/dist/types/packages/database/query/utils/scopes-for.d.ts +2 -0
  115. package/dist/types/packages/database/relationship/index.d.ts +11 -0
  116. package/dist/types/packages/database/relationship/interfaces.d.ts +12 -0
  117. package/dist/types/packages/database/relationship/utils/getters.d.ts +14 -0
  118. package/dist/types/packages/database/relationship/utils/inverse-setters.d.ts +15 -0
  119. package/dist/types/packages/database/relationship/utils/setters.d.ts +14 -0
  120. package/dist/types/packages/database/relationship/utils/unassociate.d.ts +5 -0
  121. package/dist/types/packages/database/relationship/utils/update-relationship.d.ts +5 -0
  122. package/dist/types/packages/database/relationship/utils/validate-type.d.ts +2 -0
  123. package/dist/types/packages/database/transaction/index.d.ts +16 -0
  124. package/dist/types/packages/database/transaction/interfaces.d.ts +5 -0
  125. package/dist/types/packages/database/utils/connect.d.ts +6 -0
  126. package/dist/types/packages/database/utils/create-migrations.d.ts +5 -0
  127. package/dist/types/packages/database/utils/normalize-model-name.d.ts +5 -0
  128. package/dist/types/packages/database/utils/pending-migrations.d.ts +4 -0
  129. package/dist/types/packages/database/utils/type-for-column.d.ts +5 -0
  130. package/dist/types/packages/database/validation/errors/index.d.ts +1 -0
  131. package/dist/types/packages/database/validation/errors/validation-error.d.ts +7 -0
  132. package/dist/types/packages/database/validation/index.d.ts +13 -0
  133. package/dist/types/packages/database/validation/interfaces.d.ts +5 -0
  134. package/dist/types/packages/freezeable/constants.d.ts +1 -0
  135. package/dist/types/packages/freezeable/index.d.ts +3 -0
  136. package/dist/types/packages/freezeable/map/index.d.ts +11 -0
  137. package/dist/types/packages/freezeable/set/index.d.ts +11 -0
  138. package/dist/types/packages/freezeable/utils/freeze.d.ts +20 -0
  139. package/dist/types/packages/freezeable/utils/is-frozen.d.ts +4 -0
  140. package/dist/types/packages/fs/index.d.ts +52 -0
  141. package/dist/types/packages/fs/interfaces.d.ts +19 -0
  142. package/dist/types/packages/fs/utils/create-path-remover.d.ts +5 -0
  143. package/dist/types/packages/fs/utils/create-resolver.d.ts +4 -0
  144. package/dist/types/packages/fs/utils/exists.d.ts +4 -0
  145. package/dist/types/packages/fs/utils/is-js-file.d.ts +4 -0
  146. package/dist/types/packages/fs/utils/parse-path.d.ts +5 -0
  147. package/dist/types/packages/fs/utils/rmrf.d.ts +5 -0
  148. package/dist/types/packages/fs/watcher/index.d.ts +13 -0
  149. package/dist/types/packages/fs/watcher/initialize.d.ts +5 -0
  150. package/dist/types/packages/fs/watcher/interfaces.d.ts +3 -0
  151. package/dist/types/packages/jsonapi/constants.d.ts +2 -0
  152. package/dist/types/packages/jsonapi/errors/index.d.ts +3 -0
  153. package/dist/types/packages/jsonapi/errors/invalid-content-type-error.d.ts +8 -0
  154. package/dist/types/packages/jsonapi/errors/not-acceptable-error.d.ts +8 -0
  155. package/dist/types/packages/jsonapi/errors/unsupported-media-type-error.d.ts +8 -0
  156. package/dist/types/packages/jsonapi/index.d.ts +5 -0
  157. package/dist/types/packages/jsonapi/interfaces.d.ts +66 -0
  158. package/dist/types/packages/jsonapi/utils/has-media-type.d.ts +4 -0
  159. package/dist/types/packages/jsonapi/utils/is-jsonapi.d.ts +4 -0
  160. package/dist/types/packages/loader/builder/index.d.ts +6 -0
  161. package/dist/types/packages/loader/builder/interfaces.d.ts +10 -0
  162. package/dist/types/packages/loader/builder/utils/create-children-builder.d.ts +2 -0
  163. package/dist/types/packages/loader/builder/utils/create-parent-builder.d.ts +2 -0
  164. package/dist/types/packages/loader/builder/utils/sort-by-namespace.d.ts +5 -0
  165. package/dist/types/packages/loader/index.d.ts +8 -0
  166. package/dist/types/packages/loader/interfaces.d.ts +4 -0
  167. package/dist/types/packages/loader/resolver/index.d.ts +7 -0
  168. package/dist/types/packages/loader/resolver/utils/closest-ancestor.d.ts +2 -0
  169. package/dist/types/packages/loader/resolver/utils/closest-child.d.ts +2 -0
  170. package/dist/types/packages/loader/utils/bundle-for.d.ts +5 -0
  171. package/dist/types/packages/loader/utils/format-key.d.ts +4 -0
  172. package/dist/types/packages/logger/constants.d.ts +8 -0
  173. package/dist/types/packages/logger/index.d.ts +182 -0
  174. package/dist/types/packages/logger/interfaces.d.ts +17 -0
  175. package/dist/types/packages/logger/request-logger/index.d.ts +6 -0
  176. package/dist/types/packages/logger/request-logger/interfaces.d.ts +25 -0
  177. package/dist/types/packages/logger/request-logger/templates.d.ts +9 -0
  178. package/dist/types/packages/logger/request-logger/utils/filter-params.d.ts +4 -0
  179. package/dist/types/packages/logger/request-logger/utils/log-json.d.ts +10 -0
  180. package/dist/types/packages/logger/request-logger/utils/log-text.d.ts +10 -0
  181. package/dist/types/packages/logger/utils/line.d.ts +4 -0
  182. package/dist/types/packages/logger/utils/sql.d.ts +4 -0
  183. package/dist/types/packages/logger/writer/constants.d.ts +3 -0
  184. package/dist/types/packages/logger/writer/index.d.ts +6 -0
  185. package/dist/types/packages/logger/writer/interfaces.d.ts +2 -0
  186. package/dist/types/packages/logger/writer/utils/format-message.d.ts +9 -0
  187. package/dist/types/packages/lumenify/index.d.ts +11 -0
  188. package/dist/types/packages/lumenify/utils/create-response-proxy.d.ts +8 -0
  189. package/dist/types/packages/pm/cluster/index.d.ts +21 -0
  190. package/dist/types/packages/pm/cluster/interfaces.d.ts +7 -0
  191. package/dist/types/packages/pm/index.d.ts +6 -0
  192. package/dist/types/packages/router/definitions/context/index.d.ts +11 -0
  193. package/dist/types/packages/router/definitions/context/utils/create-definition-group.d.ts +7 -0
  194. package/dist/types/packages/router/definitions/context/utils/create-definition.d.ts +10 -0
  195. package/dist/types/packages/router/definitions/context/utils/normalize-resource-args.d.ts +12 -0
  196. package/dist/types/packages/router/definitions/index.d.ts +10 -0
  197. package/dist/types/packages/router/definitions/interfaces.d.ts +7 -0
  198. package/dist/types/packages/router/index.d.ts +18 -0
  199. package/dist/types/packages/router/interfaces.d.ts +18 -0
  200. package/dist/types/packages/router/namespace/index.d.ts +20 -0
  201. package/dist/types/packages/router/namespace/interfaces.d.ts +9 -0
  202. package/dist/types/packages/router/namespace/utils/normalize-name.d.ts +4 -0
  203. package/dist/types/packages/router/namespace/utils/normalize-path.d.ts +4 -0
  204. package/dist/types/packages/router/resource/index.d.ts +13 -0
  205. package/dist/types/packages/router/resource/interfaces.d.ts +5 -0
  206. package/dist/types/packages/router/resource/utils/normalize-only.d.ts +5 -0
  207. package/dist/types/packages/router/route/action/constants.d.ts +1 -0
  208. package/dist/types/packages/router/route/action/enhancers/resource.d.ts +5 -0
  209. package/dist/types/packages/router/route/action/enhancers/track-perf.d.ts +5 -0
  210. package/dist/types/packages/router/route/action/index.d.ts +9 -0
  211. package/dist/types/packages/router/route/action/interfaces.d.ts +2 -0
  212. package/dist/types/packages/router/route/action/utils/create-page-links.d.ts +12 -0
  213. package/dist/types/packages/router/route/action/utils/get-action-name.d.ts +5 -0
  214. package/dist/types/packages/router/route/action/utils/get-controller-name.d.ts +5 -0
  215. package/dist/types/packages/router/route/constants.d.ts +1 -0
  216. package/dist/types/packages/router/route/index.d.ts +28 -0
  217. package/dist/types/packages/router/route/interfaces.d.ts +10 -0
  218. package/dist/types/packages/router/route/params/errors/index.d.ts +5 -0
  219. package/dist/types/packages/router/route/params/errors/invalid-parameter-error.d.ts +8 -0
  220. package/dist/types/packages/router/route/params/errors/parameter-not-nullable-error.d.ts +9 -0
  221. package/dist/types/packages/router/route/params/errors/parameter-required-error.d.ts +8 -0
  222. package/dist/types/packages/router/route/params/errors/parameter-type-error.d.ts +9 -0
  223. package/dist/types/packages/router/route/params/errors/parameter-value-error.d.ts +9 -0
  224. package/dist/types/packages/router/route/params/errors/resource-mismatch-error.d.ts +8 -0
  225. package/dist/types/packages/router/route/params/index.d.ts +18 -0
  226. package/dist/types/packages/router/route/params/interfaces.d.ts +25 -0
  227. package/dist/types/packages/router/route/params/parameter/index.d.ts +14 -0
  228. package/dist/types/packages/router/route/params/parameter/interfaces.d.ts +4 -0
  229. package/dist/types/packages/router/route/params/parameter/utils/validate-value.d.ts +5 -0
  230. package/dist/types/packages/router/route/params/parameter-group/index.d.ts +14 -0
  231. package/dist/types/packages/router/route/params/parameter-group/utils/has-required-params.d.ts +5 -0
  232. package/dist/types/packages/router/route/params/utils/get-data-params.d.ts +6 -0
  233. package/dist/types/packages/router/route/params/utils/get-default-collection-params.d.ts +6 -0
  234. package/dist/types/packages/router/route/params/utils/get-default-member-params.d.ts +5 -0
  235. package/dist/types/packages/router/route/params/utils/get-query-params.d.ts +14 -0
  236. package/dist/types/packages/router/route/params/utils/get-url-params.d.ts +5 -0
  237. package/dist/types/packages/router/route/params/utils/validate-resource-id.d.ts +5 -0
  238. package/dist/types/packages/router/route/params/utils/validate-type.d.ts +5 -0
  239. package/dist/types/packages/router/route/utils/get-dynamic-segments.d.ts +4 -0
  240. package/dist/types/packages/router/route/utils/get-static-path.d.ts +4 -0
  241. package/dist/types/packages/router/utils/create-replacer.d.ts +5 -0
  242. package/dist/types/packages/serializer/index.d.ts +521 -0
  243. package/dist/types/packages/serializer/interfaces.d.ts +7 -0
  244. package/dist/types/packages/server/constants.d.ts +2 -0
  245. package/dist/types/packages/server/index.d.ts +27 -0
  246. package/dist/types/packages/server/interfaces.d.ts +18 -0
  247. package/dist/types/packages/server/request/constants.d.ts +2 -0
  248. package/dist/types/packages/server/request/index.d.ts +8 -0
  249. package/dist/types/packages/server/request/interfaces.d.ts +63 -0
  250. package/dist/types/packages/server/request/parser/constants.d.ts +6 -0
  251. package/dist/types/packages/server/request/parser/errors/index.d.ts +1 -0
  252. package/dist/types/packages/server/request/parser/errors/malformed-request-error.d.ts +8 -0
  253. package/dist/types/packages/server/request/parser/index.d.ts +5 -0
  254. package/dist/types/packages/server/request/parser/utils/format.d.ts +17 -0
  255. package/dist/types/packages/server/request/parser/utils/parse-nested-object.d.ts +4 -0
  256. package/dist/types/packages/server/request/parser/utils/parse-read.d.ts +5 -0
  257. package/dist/types/packages/server/request/parser/utils/parse-write.d.ts +5 -0
  258. package/dist/types/packages/server/request/utils/get-domain.d.ts +5 -0
  259. package/dist/types/packages/server/responder/index.d.ts +5 -0
  260. package/dist/types/packages/server/responder/utils/data-for.d.ts +5 -0
  261. package/dist/types/packages/server/responder/utils/has-content-type.d.ts +2 -0
  262. package/dist/types/packages/server/responder/utils/normalize.d.ts +7 -0
  263. package/dist/types/packages/server/response/index.d.ts +5 -0
  264. package/dist/types/packages/server/response/interfaces.d.ts +22 -0
  265. package/dist/types/packages/server/utils/create-server-error.d.ts +7 -0
  266. package/dist/types/packages/server/utils/set-cors-headers.d.ts +3 -0
  267. package/dist/types/packages/server/utils/validate-accept.d.ts +4 -0
  268. package/dist/types/packages/server/utils/validate-content-type.d.ts +4 -0
  269. package/dist/types/packages/template/index.d.ts +8 -0
  270. package/dist/types/packages/template/utils/insert-values.d.ts +4 -0
  271. package/dist/types/utils/chain.d.ts +5 -0
  272. package/dist/types/utils/compact.d.ts +11 -0
  273. package/dist/types/utils/compose.d.ts +19 -0
  274. package/dist/types/utils/create-query-string.d.ts +6 -0
  275. package/dist/types/utils/diff.d.ts +4 -0
  276. package/dist/types/utils/entries.d.ts +4 -0
  277. package/dist/types/utils/env.d.ts +3 -0
  278. package/dist/types/utils/exec.d.ts +5 -0
  279. package/dist/types/utils/github.d.ts +9 -0
  280. package/dist/types/utils/has-own-property.d.ts +1 -0
  281. package/dist/types/utils/insert.d.ts +4 -0
  282. package/dist/types/utils/is-buffer.d.ts +4 -0
  283. package/dist/types/utils/is-null.d.ts +4 -0
  284. package/dist/types/utils/is-object.d.ts +17 -0
  285. package/dist/types/utils/is-undefined.d.ts +4 -0
  286. package/dist/types/utils/k.d.ts +10 -0
  287. package/dist/types/utils/map-to-object.d.ts +1 -0
  288. package/dist/types/utils/merge.d.ts +4 -0
  289. package/dist/types/utils/omit.d.ts +9 -0
  290. package/dist/types/utils/pick.d.ts +11 -0
  291. package/dist/types/utils/present.d.ts +4 -0
  292. package/dist/types/utils/promise-hash.d.ts +9 -0
  293. package/dist/types/utils/proxy.d.ts +6 -0
  294. package/dist/types/utils/range.d.ts +4 -0
  295. package/dist/types/utils/set-type.d.ts +11 -0
  296. package/dist/types/utils/sleep.d.ts +4 -0
  297. package/dist/types/utils/stringify.d.ts +4 -0
  298. package/dist/types/utils/transform-keys.d.ts +29 -0
  299. package/dist/types/utils/try-catch.d.ts +55 -0
  300. package/dist/types/utils/underscore.d.ts +4 -0
  301. package/dist/types/utils/uniq.d.ts +4 -0
  302. package/package.json +87 -0
@@ -0,0 +1,521 @@
1
+ import type { Model, ModelClass } from '../database';
2
+ import type { JSONAPI$Document, JSONAPI$DocumentLinks, JSONAPI$ResourceObject, JSONAPI$RelationshipObject } from '../jsonapi';
3
+ import type { Serializer$opts } from './interfaces';
4
+ /**
5
+ * ## Overview
6
+ *
7
+ * The Serializer class is used to describe which attributes and relationships
8
+ * to include for a particular resource.
9
+ *
10
+ * The attributes and relationships you declare in a Serializer will determine
11
+ * the attributes and relationships that will be included in the response from
12
+ * the resource that the Serializer represents.
13
+ *
14
+ * #### Attributes
15
+ *
16
+ * You can add attributes to your serializer using an array assigned to the
17
+ * class property `attributes` like the example below.
18
+ *
19
+ * ```javascript
20
+ * class UsersSerializer extends Serializer {
21
+ * attributes = [
22
+ * 'name',
23
+ * 'email',
24
+ * 'username',
25
+ * 'createdAt',
26
+ * 'updatedAt'
27
+ * ];
28
+ * }
29
+ * ```
30
+ *
31
+ * Since the attributes required for a resource are declared ahead of time in a
32
+ * Serializer, Lumen will optimize SQL queries for the resource to only include
33
+ * what the Serializer needs to build the response.
34
+ *
35
+ * ```javascript
36
+ * import { Serializer } from 'lumen-framework';
37
+ *
38
+ * class PostsSerializer extends Serializer {
39
+ * attributes = [
40
+ * 'body',
41
+ * 'title',
42
+ * 'createdAt'
43
+ * ];
44
+ * }
45
+ *
46
+ * export default PostsSerializer;
47
+ * ```
48
+ *
49
+ * The Serializer above would result in resources returned from the `/posts`
50
+ * endpoint to only include the `body`, `title`, and `createdAt` attributes. If
51
+ * we wanted include an additional attribute such as `isPublic`, we would have
52
+ * to add `'isPublic'` to the `attributes` property.
53
+ *
54
+ * ```javascript
55
+ * import { Serializer } from 'lumen-framework';
56
+ *
57
+ * class PostsSerializer extends Serializer {
58
+ * attributes = [
59
+ * 'body',
60
+ * 'title',
61
+ * 'isPublic',
62
+ * 'createdAt'
63
+ * ];
64
+ * }
65
+ *
66
+ * export default PostsSerializer;
67
+ * ```
68
+ *
69
+ * #### Associations
70
+ *
71
+ * Similar to `attributes` you can declare associations by adding relationship
72
+ * names to either the `hasOne` or `hasMany` property arrays on a Serializer.
73
+ *
74
+ * Serializers are not concerned with ownership when it comes to associations,
75
+ * so both `hasOne` and `belongsTo` associations can be specified in the
76
+ * `hasOne` array property.
77
+ *
78
+ * ```javascript
79
+ * import { Model } from 'lumen-framework';
80
+ *
81
+ * class Post extends Model {
82
+ * static hasOne = {
83
+ * image: {
84
+ * inverse: 'post'
85
+ * }
86
+ * };
87
+ *
88
+ * static hasMany = {
89
+ * tags: {
90
+ * inverse: 'posts',
91
+ * through: 'categorization'
92
+ * },
93
+ *
94
+ * comments: {
95
+ * inverse: 'post'
96
+ * }
97
+ * };
98
+ *
99
+ * static belongsTo = {
100
+ * user: {
101
+ * inverse: 'posts'
102
+ * }
103
+ * };
104
+ * }
105
+ *
106
+ * export default Post;
107
+ * ```
108
+ *
109
+ * To include the `user` and `image` associations in the response returned from
110
+ * the `/posts` endpoint, we must specify both associations in the `hasOne`
111
+ * property array of the Serializer.
112
+ *
113
+ * ```javascript
114
+ * import { Serializer } from 'lumen-framework';
115
+ *
116
+ * class PostsSerializer extends Serializer {
117
+ * hasOne = [
118
+ * 'user',
119
+ * 'image'
120
+ * ];
121
+ * }
122
+ *
123
+ * export default PostsSerializer;
124
+ * ```
125
+ *
126
+ * If we wanted to also include the `tags` and `comments` in the response, we
127
+ * have to add a `hasMany` array property containing `'tags'` and `'comments'`.
128
+ *
129
+ * ```javascript
130
+ * import { Serializer } from 'lumen-framework';
131
+ *
132
+ * class PostsSerializer extends Serializer {
133
+ * hasOne = [
134
+ * 'user',
135
+ * 'image'
136
+ * ];
137
+ *
138
+ * hasMany = [
139
+ * 'tags',
140
+ * 'comments'
141
+ * ];
142
+ * }
143
+ *
144
+ * export default PostsSerializer;
145
+ * ```
146
+ *
147
+ * You no longer need to specify that `tags` is a many to many relationship
148
+ * using the `Categorization` model as a join table.
149
+ *
150
+ * #### Including Related Resources
151
+ *
152
+ * When requesting related resources for an endpoint, the included resource will
153
+ * follow the serialization rules defined by the included resources Serializer.
154
+ *
155
+ * If we request that the `posts` association is included from the `/users`
156
+ * endpoint, we will only get the `attributes` that the `PostsSerializer` has
157
+ * defined even though the response is processed by the `UsersSerializer`.
158
+ *
159
+ * #### Sparse Fieldsets
160
+ *
161
+ * When a request specifies the fields that it would like included in the
162
+ * response, the fields **MUST** be declared in the `attributes` property array
163
+ * of the resources Serializer, or they will be ignored.
164
+ *
165
+ * #### Namespaces
166
+ *
167
+ * When using namespaces, you are not required to have a Serializer for each
168
+ * resource as long as a Serializer for the given resource can be resolved
169
+ * upstream.
170
+ *
171
+ * For example, if you have a `posts` resource and you decide to implement an
172
+ * admin namespace, you only need to export an `AdminPostsSerializer` from
173
+ * `app/serializers/admin/posts.js` if you want to specify different attributes
174
+ * or relationships than the `PostsSerializer` exported from
175
+ * `app/serializers/posts.js`.
176
+ *
177
+ * In the event that you do want to specify different attributes or
178
+ * relationships that the `PostsSerializer` exported from
179
+ * `app/serializers/posts.js`, you are not required to extend `PostsSerializer`.
180
+ *
181
+ * ```javascript
182
+ * import { Serializer } from 'lumen-framework';
183
+ *
184
+ * class PostsSerializer extends Serializer {
185
+ * attributes = [
186
+ * 'body',
187
+ * 'title',
188
+ * 'createdAt'
189
+ * ];
190
+ *
191
+ * hasOne = [
192
+ * 'user',
193
+ * 'image'
194
+ * ];
195
+ *
196
+ * hasMany = [
197
+ * 'tags',
198
+ * 'comments'
199
+ * ];
200
+ * }
201
+ *
202
+ * export default PostsSerializer;
203
+ * ```
204
+ *
205
+ * To add the `isPublic` attribute to the response payload of requests to a
206
+ * `/admin/posts` endpoint we can do either of the following examples:
207
+ *
208
+ * ```javascript
209
+ * // app/serializers/admin/posts.js
210
+ * import PostsSerializer from 'app/serializers/posts';
211
+ *
212
+ * class AdminPostsSerializer extends PostsSerializer {
213
+ * attributes = [
214
+ * 'body',
215
+ * 'title',
216
+ * 'isPublic',
217
+ * 'createdAt'
218
+ * ];
219
+ * }
220
+ *
221
+ * export default AdminPostsSerializer;
222
+ * ```
223
+ *
224
+ * OR
225
+ *
226
+ * ```javascript
227
+ * // app/serializers/admin/posts.js
228
+ * import { Serializer } from 'lumen-framework';
229
+ *
230
+ * class AdminPostsSerializer extends Serializer {
231
+ * attributes = [
232
+ * 'body',
233
+ * 'title',
234
+ * 'isPublic',
235
+ * 'createdAt'
236
+ * ];
237
+ *
238
+ * hasOne = [
239
+ * 'user',
240
+ * 'image'
241
+ * ];
242
+ *
243
+ * hasMany = [
244
+ * 'tags',
245
+ * 'comments'
246
+ * ];
247
+ * }
248
+ *
249
+ * export default AdminPostsSerializer;
250
+ * ```
251
+ *
252
+ * Even with inheritance, the examples above are a tad repetitive. We can
253
+ * improve this code by exporting constants from `app/serializers/posts.js`.
254
+ *
255
+ * ```javascript
256
+ * import { Serializer } from 'lumen-framework';
257
+ *
258
+ * export const HAS_ONE = [
259
+ * 'user',
260
+ * 'image'
261
+ * ];
262
+ *
263
+ * export const HAS_MANY = [
264
+ * 'tags',
265
+ * 'comments'
266
+ * ];
267
+ *
268
+ * export const ATTRIBUTES = [
269
+ * 'body',
270
+ * 'title',
271
+ * 'createdAt'
272
+ * ];
273
+ *
274
+ * class PostsSerializer extends Serializer {
275
+ * hasOne = HAS_ONE;
276
+ * hasMany = HAS_MANY;
277
+ * attributes = ATTRIBUTES;
278
+ * }
279
+ *
280
+ * export default PostsSerializer;
281
+ * ```
282
+ *
283
+ * If we choose to use inheritance, our code can look like this:
284
+ *
285
+ * ```javascript
286
+ * // app/serializers/admin/posts.js
287
+ * import PostsSerializer, { ATTRIBUTES } from 'app/serializers/posts';
288
+ *
289
+ * class AdminPostsSerializer extends PostsSerializer {
290
+ * attributes = [
291
+ * ...ATTRIBUTES,
292
+ * 'isPublic'
293
+ * ];
294
+ * }
295
+ *
296
+ * export default AdminPostsSerializer;
297
+ * ```
298
+ *
299
+ * If we choose not use inheritance, our code can look like this:
300
+ *
301
+ * ```javascript
302
+ * // app/serializers/admin/posts.js
303
+ * import { Serializer } from 'lumen-framework';
304
+ * import { HAS_ONE, HAS_MANY, ATTRIBUTES } from 'app/serializers/posts';
305
+ *
306
+ * class AdminPostsSerializer extends PostsSerializer {
307
+ * hasOne = HAS_ONE;
308
+ * hasMany = HAS_MANY;
309
+ *
310
+ * attributes = [
311
+ * ...ATTRIBUTES,
312
+ * 'isPublic'
313
+ * ];
314
+ * }
315
+ *
316
+ * export default AdminPostsSerializer;
317
+ * ```
318
+ *
319
+ * @class Serializer
320
+ * @public
321
+ */
322
+ declare class Serializer<T extends Model> {
323
+ /**
324
+ * An Array of the `hasOne` or `belongsTo` relationships on a Serializer
325
+ * instance's Model to include in the
326
+ * `relationships` resource object of a serialized payload.
327
+ *
328
+ * ```javascript
329
+ * class PostsSerializer extends Serializer {
330
+ * hasOne = [
331
+ * 'user'
332
+ * ];
333
+ * }
334
+ * ```
335
+ *
336
+ * @property hasOne
337
+ * @type {Array}
338
+ * @default []
339
+ * @public
340
+ */
341
+ hasOne: Array<string>;
342
+ /**
343
+ * An Array of the `hasMany` relationships on a Serializer instance's Model to
344
+ * include in the `relationships` resource object of a serialized payload.
345
+ *
346
+ * ```javscript
347
+ * class PostsSerializer extends Serializer {
348
+ * hasMany = [
349
+ * 'comments'
350
+ * ];
351
+ * }
352
+ * ```
353
+ *
354
+ * @property hasMany
355
+ * @type {Array}
356
+ * @default []
357
+ * @public
358
+ */
359
+ hasMany: Array<string>;
360
+ /**
361
+ * An array of the `attributes` on a Serializer instance's Model to include in
362
+ * the `attributes` resource object of a serialized payload.
363
+ *
364
+ * ```javscript
365
+ * class PostsSerializer extends Serializer {
366
+ * attributes = [
367
+ * 'body',
368
+ * 'title'
369
+ * ];
370
+ * }
371
+ * ```
372
+ *
373
+ * @property attributes
374
+ * @type {Array}
375
+ * @default []
376
+ * @public
377
+ */
378
+ attributes: Array<string>;
379
+ /**
380
+ * The resolved Model that a Serializer instance represents.
381
+ *
382
+ * @property model
383
+ * @type {Model}
384
+ * @private
385
+ */
386
+ model: ModelClass<T>;
387
+ /**
388
+ * A reference to the root Serializer for the namespace that a Serializer
389
+ * instance is a member of.
390
+ *
391
+ * @property parent
392
+ * @type {?Serializer}
393
+ * @private
394
+ */
395
+ parent: Serializer<Model> | null;
396
+ /**
397
+ * The namespace that a Serializer instance is a member of.
398
+ *
399
+ * @property namespace
400
+ * @type {String}
401
+ * @private
402
+ */
403
+ namespace: string;
404
+ constructor({ model, parent, namespace }: Serializer$opts<T>);
405
+ /**
406
+ * Transform an array of Model instances or a single Model instance into a
407
+ * [JSON API](http://jsonapi.org) document object.
408
+ *
409
+ * @method format
410
+ *
411
+ * @param {Object} options - An options object used for building the
412
+ * returned [JSON API](http://jsonapi.org) document object.
413
+ *
414
+ * @param {Model|Array} options.data - The Model instance or array of
415
+ * Model instances to transform into the returned [JSON API](
416
+ * http://jsonapi.org) document object.
417
+ *
418
+ * @param {Object} options.links - An object containing links to include in
419
+ * the top level links object of the returned [JSON API](http://jsonapi.org)
420
+ * document object.
421
+ *
422
+ * @param {String} options.domain - A string used to build links included in
423
+ * the resource and relationship objects in the returned [JSON API](
424
+ * http://jsonapi.org) document object.
425
+ *
426
+ * @param {Array} options.include - An array of strings containing the
427
+ * relationship keys that should be added to the top level included object of
428
+ * the returned [JSON API](http://jsonapi.org) document object.
429
+ *
430
+ * @return {Promise} Resolves with a [JSON API](http://jsonapi.org) document
431
+ * object.
432
+ *
433
+ * @private
434
+ */
435
+ format({ data, links, domain, include }: {
436
+ data: T | Array<T>;
437
+ links: JSONAPI$DocumentLinks;
438
+ domain: string;
439
+ include: Array<string>;
440
+ }): Promise<JSONAPI$Document>;
441
+ /**
442
+ * Transform a single Model instance into a [JSON API](http://jsonapi.org)
443
+ * resource object.
444
+ *
445
+ * @method formatOne
446
+ *
447
+ * @param {Object} options - An options object used for building the returned
448
+ * [JSON API](http://jsonapi.org) resource object.
449
+ *
450
+ * @param {Model} options.item - The Model instance to transform into the
451
+ * returned [JSON API](http://jsonapi.org) resource object.
452
+ *
453
+ * @param {Object} options.links - An object containing links to include in
454
+ * the top level links object of the returned [JSON API](http://jsonapi.org)
455
+ * resource object.
456
+ *
457
+ * @param {String} options.domain - A string used to build links included in
458
+ * the top level links object or relationship links objects in the returned
459
+ * [JSON API](http://jsonapi.org) resource object.
460
+ *
461
+ * @param {Array} options.include - An array of strings containing the
462
+ * relationship keys that should be added to the top level included object of
463
+ * a [JSON API](http://jsonapi.org) document object.
464
+ *
465
+ * @param {Array} options.included - An array of [JSON API](
466
+ * http://jsonapi.org) resource objects that will be added to the top level
467
+ * included array of a [JSON API](http://jsonapi.org) document object.
468
+ *
469
+ * @param {Boolean} options.formatRelationships - Wether or not
470
+ * relationships should be formatted and included in the returned
471
+ * [JSON API](http://jsonapi.org) resource object.
472
+ *
473
+ * @return {Promise} Resolves with a [JSON API](http://jsonapi.org) resource
474
+ * object.
475
+ *
476
+ * @private
477
+ */
478
+ formatOne({ item, links, domain, include, included, formatRelationships }: {
479
+ item: T;
480
+ links?: boolean;
481
+ domain: string;
482
+ include: Array<string>;
483
+ included: Array<JSONAPI$ResourceObject>;
484
+ formatRelationships?: boolean;
485
+ }): Promise<JSONAPI$ResourceObject>;
486
+ /**
487
+ * Transform a single Model instance into a [JSON API](http://jsonapi.org)
488
+ * relationship object.
489
+ *
490
+ * @method formatRelationship
491
+ *
492
+ * @param {Object} options - An options object used for building the returned
493
+ * [JSON API](http://jsonapi.org) relationship object.
494
+ *
495
+ * @param {Model} options.item - The Model instance to transform into the
496
+ * returned [JSON API](http://jsonapi.org) relationship object.
497
+ *
498
+ * @param {String} options.domain - A string used to build links included in
499
+ * the returned [JSON API](http://jsonapi.org) relationship object.
500
+ *
501
+ * @param {Array} options.include - An array of strings containing the
502
+ * relationship keys that should be added to the top level included object of
503
+ * a [JSON API](http://jsonapi.org) document object.
504
+ *
505
+ * @param {Array} options.included - An array of [JSON API](
506
+ * http://jsonapi.org) resource objects that will be added to the top level
507
+ * included array of a [JSON API](http://jsonapi.org) document object.
508
+ *
509
+ * @return {Promise} Resolves with a [JSON API](http://jsonapi.org)
510
+ * relationship object.
511
+ *
512
+ * @private
513
+ */
514
+ formatRelationship({ item, domain, include, included }: {
515
+ item: Model;
516
+ domain: string;
517
+ include: boolean;
518
+ included: Array<JSONAPI$ResourceObject>;
519
+ }): Promise<JSONAPI$RelationshipObject>;
520
+ }
521
+ export default Serializer;
@@ -0,0 +1,7 @@
1
+ import type Serializer from './index';
2
+ import type { Model, ModelClass } from '../database';
3
+ export type Serializer$opts<T extends Model> = {
4
+ model: ModelClass<T>;
5
+ parent: Serializer<Model> | null;
6
+ namespace: string;
7
+ };
@@ -0,0 +1,2 @@
1
+ export declare const HAS_BODY: RegExp;
2
+ export declare const STATUS_CODES: Map<number, string>;
@@ -0,0 +1,27 @@
1
+ import type { Writable } from 'stream';
2
+ import type { IncomingMessage, Server as HTTPServer } from 'http';
3
+ import type Logger from '../logger';
4
+ import type Router from '../router';
5
+ import type { Request } from './request/interfaces';
6
+ import type { Response } from './response/interfaces';
7
+ import type { Server$opts, Server$cors } from './interfaces';
8
+ /**
9
+ * @private
10
+ */
11
+ declare class Server {
12
+ logger: Logger;
13
+ router: Router;
14
+ cors: Server$cors;
15
+ instance: HTTPServer;
16
+ constructor({ logger, router, cors }: Server$opts);
17
+ listen(port: number): void;
18
+ initializeRequest(req: IncomingMessage, res: Writable): [Request, Response];
19
+ validateRequest({ method, headers }: Request): true;
20
+ receiveRequest: (req: IncomingMessage, res: Writable) => void;
21
+ }
22
+ export default Server;
23
+ export { REQUEST_METHODS, getDomain } from './request';
24
+ export { default as createServerError } from './utils/create-server-error';
25
+ export type { Server$config } from './interfaces';
26
+ export type { Request, Request$params, Request$method } from './request/interfaces';
27
+ export type { Response } from './response/interfaces';
@@ -0,0 +1,18 @@
1
+ import type Logger from '../logger';
2
+ import type Router from '../router';
3
+ export type Server$cors = {
4
+ enabled: boolean;
5
+ origin?: string;
6
+ headers?: Array<string>;
7
+ methods?: Array<string>;
8
+ };
9
+ export type Server$config = {
10
+ cors: Server$cors;
11
+ };
12
+ export type Server$opts = Server$config & {
13
+ logger: Logger;
14
+ router: Router;
15
+ };
16
+ export interface Server$Error extends Error {
17
+ statusCode: number;
18
+ }
@@ -0,0 +1,2 @@
1
+ import type { Request$method } from './interfaces';
2
+ export declare const REQUEST_METHODS: Array<Request$method>;
@@ -0,0 +1,8 @@
1
+ import type { Request, Request$opts } from './interfaces';
2
+ /**
3
+ * @private
4
+ */
5
+ export declare function createRequest(req: any, { logger, router }: Request$opts): Request;
6
+ export { REQUEST_METHODS } from './constants';
7
+ export { parseRequest } from './parser';
8
+ export { default as getDomain } from './utils/get-domain';
@@ -0,0 +1,63 @@
1
+ import type { Readable } from 'stream';
2
+ import type { Socket } from 'net';
3
+ import type Logger from '../../logger';
4
+ import type Router from '../../router';
5
+ import type { Route } from '../../router';
6
+ import type Controller from '../../controller';
7
+ export type Request$opts = {
8
+ logger: Logger;
9
+ router: Router;
10
+ };
11
+ type Request$url = {
12
+ protocol?: string;
13
+ slashes?: boolean;
14
+ auth?: string;
15
+ host?: string;
16
+ port?: string;
17
+ hostname?: string;
18
+ hash?: string;
19
+ search?: string;
20
+ params: Array<string>;
21
+ query: Record<string, unknown>;
22
+ pathname: string;
23
+ path: string;
24
+ href: string;
25
+ };
26
+ export type Request$method = 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'DELETE';
27
+ export type Request$params = {
28
+ id: number | string | Buffer;
29
+ sort: string;
30
+ filter: Record<string, unknown>;
31
+ fields: Record<string, unknown>;
32
+ include: Array<string>;
33
+ page: {
34
+ size?: number;
35
+ number?: number;
36
+ };
37
+ data: {
38
+ id: number | string | Buffer;
39
+ type: string;
40
+ attributes?: Record<string, unknown>;
41
+ relationships?: Record<string, unknown>;
42
+ };
43
+ };
44
+ export interface Request extends Readable {
45
+ headers: Map<string, string>;
46
+ httpVersion: string;
47
+ method: Request$method;
48
+ trailers: Record<string, unknown>;
49
+ socket: Socket;
50
+ logger: Logger;
51
+ params: Request$params;
52
+ defaultParams: Request$params;
53
+ route: Route;
54
+ action: string;
55
+ controller: Controller;
56
+ url: Request$url;
57
+ connection: {
58
+ encrypted: boolean;
59
+ remoteAddress: string;
60
+ };
61
+ setTimeout(msecs: number, callback: () => void): void;
62
+ }
63
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const INT: RegExp;
2
+ export declare const NULL: RegExp;
3
+ export declare const BOOL: RegExp;
4
+ export declare const DATE: RegExp;
5
+ export declare const TRUE: RegExp;
6
+ export declare const BRACKETS: RegExp;
@@ -0,0 +1 @@
1
+ export { default as MalformedRequestError } from './malformed-request-error';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @private
3
+ */
4
+ declare class MalformedRequestError extends SyntaxError {
5
+ constructor();
6
+ }
7
+ declare const _default: new (...args: Array<any>) => MalformedRequestError & import("../../../interfaces").Server$Error;
8
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import type { Request } from '../interfaces';
2
+ /**
3
+ * @private
4
+ */
5
+ export declare function parseRequest(req: Request): Promise<Record<string, unknown>>;
@@ -0,0 +1,17 @@
1
+ import type { Request$method } from '../../interfaces';
2
+ /**
3
+ * @private
4
+ */
5
+ export declare function formatSort(sort: string): string;
6
+ /**
7
+ * @private
8
+ */
9
+ export declare function formatFields(fields: Record<string, unknown>): Record<string, unknown>;
10
+ /**
11
+ * @private
12
+ */
13
+ export declare function formatInclude(include: string | Array<string>): Array<string>;
14
+ /**
15
+ * @private
16
+ */
17
+ export default function format(params: Record<string, unknown>, method: Request$method): Record<string, unknown>;