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.
- package/README.md +75 -109
- package/bin/lumen +23 -41
- package/dist/cli.cjs +856 -479
- package/dist/cli.cjs.map +4 -4
- package/dist/index.js +3273 -1719
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +3251 -1697
- package/dist/index.mjs.map +4 -4
- package/dist/testing.js +280 -0
- package/dist/testing.js.map +7 -0
- package/dist/testing.mjs +252 -0
- package/dist/testing.mjs.map +7 -0
- package/dist/types/errors/links-only-error.d.ts +13 -0
- package/dist/types/errors/reserved-field-name-error.d.ts +13 -0
- package/dist/types/errors/unknown-attribute-error.d.ts +13 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/interfaces.d.ts +1 -1
- package/dist/types/packages/application/index.d.ts +38 -45
- package/dist/types/packages/application/initialize.d.ts +3 -5
- package/dist/types/packages/application/interfaces.d.ts +13 -5
- package/dist/types/packages/application/utils/create-controller.d.ts +14 -4
- package/dist/types/packages/application/utils/create-serializer.d.ts +2 -2
- package/dist/types/packages/application/utils/normalize-port.d.ts +1 -3
- package/dist/types/packages/application/utils/resolve-visibility.d.ts +15 -0
- package/dist/types/packages/application/utils/restrict-open-namespaces.d.ts +19 -0
- package/dist/types/packages/application/utils/validate-attributes.d.ts +17 -0
- package/dist/types/packages/application/utils/validate-links-only.d.ts +19 -0
- package/dist/types/packages/application/utils/validate-namespaced-serializers.d.ts +3 -3
- package/dist/types/packages/application/utils/validate-reserved-names.d.ts +12 -0
- package/dist/types/packages/application/utils/warn-query-param-names.d.ts +10 -0
- package/dist/types/packages/cli/commands/dbcreate.d.ts +1 -1
- package/dist/types/packages/cli/commands/dbdrop.d.ts +1 -1
- package/dist/types/packages/cli/commands/destroy.d.ts +3 -2
- package/dist/types/packages/cli/commands/generate.d.ts +5 -5
- package/dist/types/packages/cli/commands/index.d.ts +0 -1
- package/dist/types/packages/cli/generator/index.d.ts +6 -6
- package/dist/types/packages/cli/generator/interfaces.d.ts +3 -3
- package/dist/types/packages/cli/generator/utils/create-generator.d.ts +2 -2
- package/dist/types/packages/cli/generator/utils/generate-type.d.ts +9 -9
- package/dist/types/packages/cli/generator/utils/migration-conflict.d.ts +4 -4
- package/dist/types/packages/cli/templates/pnpm-workspace.d.ts +15 -0
- package/dist/types/packages/cli/utils/create-spinner.d.ts +14 -0
- package/dist/types/packages/cli/utils/print-statements.d.ts +12 -0
- package/dist/types/packages/cli/utils/server-database.d.ts +27 -0
- package/dist/types/packages/compiler/interfaces.d.ts +1 -1
- package/dist/types/packages/config/interfaces.d.ts +10 -4
- package/dist/types/packages/controller/constants.d.ts +7 -2
- package/dist/types/packages/controller/errors/related-record-not-found-error.d.ts +4 -4
- package/dist/types/packages/controller/index.d.ts +364 -473
- package/dist/types/packages/controller/interfaces.d.ts +21 -6
- package/dist/types/packages/controller/utils/find-many.d.ts +2 -5
- package/dist/types/packages/controller/utils/find-one.d.ts +2 -5
- package/dist/types/packages/controller/utils/params-to-query.d.ts +8 -10
- package/dist/types/packages/controller/utils/resolve-relationships.d.ts +1 -3
- package/dist/types/packages/controller/utils/validate-relationships.d.ts +5 -3
- package/dist/types/packages/controller/visibility/errors.d.ts +21 -0
- package/dist/types/packages/controller/visibility/index.d.ts +51 -0
- package/dist/types/packages/database/attribute/index.d.ts +4 -6
- package/dist/types/packages/database/attribute/interfaces.d.ts +1 -1
- package/dist/types/packages/database/attribute/utils/create-attribute.d.ts +3 -5
- package/dist/types/packages/database/attribute/utils/create-getter.d.ts +2 -2
- package/dist/types/packages/database/attribute/utils/create-setter.d.ts +3 -5
- package/dist/types/packages/database/constants.d.ts +1 -0
- package/dist/types/packages/database/errors/index.d.ts +1 -0
- package/dist/types/packages/database/errors/invalid-driver-error.d.ts +1 -3
- package/dist/types/packages/database/errors/migrations-pending-error.d.ts +1 -3
- package/dist/types/packages/database/errors/model-missing-error.d.ts +1 -3
- package/dist/types/packages/database/errors/relationship-config-error.d.ts +10 -0
- package/dist/types/packages/database/errors/unique-constraint-error.d.ts +1 -1
- package/dist/types/packages/database/index.d.ts +9 -6
- package/dist/types/packages/database/initialize.d.ts +3 -5
- package/dist/types/packages/database/interfaces.d.ts +115 -25
- package/dist/types/packages/database/migration/index.d.ts +5 -7
- package/dist/types/packages/database/migration/interfaces.d.ts +2 -4
- package/dist/types/packages/database/migration/utils/generate-timestamp.d.ts +9 -1
- package/dist/types/packages/database/model/index.d.ts +348 -759
- package/dist/types/packages/database/model/initialize-class.d.ts +7 -1
- package/dist/types/packages/database/model/interfaces.d.ts +30 -12
- package/dist/types/packages/database/model/utils/attribute.d.ts +14 -0
- package/dist/types/packages/database/model/utils/get-columns.d.ts +1 -3
- package/dist/types/packages/database/model/utils/persistence.d.ts +5 -14
- package/dist/types/packages/database/model/utils/process-write-error.d.ts +2 -2
- package/dist/types/packages/database/model/utils/run-hooks.d.ts +7 -3
- package/dist/types/packages/database/model/utils/validate.d.ts +4 -1
- package/dist/types/packages/database/query/errors/record-not-found-error.d.ts +1 -1
- package/dist/types/packages/database/query/index.d.ts +179 -3
- package/dist/types/packages/database/query/runner/index.d.ts +1 -3
- package/dist/types/packages/database/query/runner/utils/build-results.d.ts +3 -4
- package/dist/types/packages/database/query/utils/format-select.d.ts +1 -3
- package/dist/types/packages/database/relationship/index.d.ts +7 -6
- package/dist/types/packages/database/relationship/interfaces.d.ts +16 -3
- package/dist/types/packages/database/relationship/utils/getters.d.ts +7 -13
- package/dist/types/packages/database/relationship/utils/inverse-setters.d.ts +5 -9
- package/dist/types/packages/database/relationship/utils/setters.d.ts +7 -13
- package/dist/types/packages/database/relationship/utils/unassociate.d.ts +1 -3
- package/dist/types/packages/database/relationship/utils/update-relationship.d.ts +6 -2
- package/dist/types/packages/database/transaction/index.d.ts +9 -10
- package/dist/types/packages/database/transaction/interfaces.d.ts +7 -1
- package/dist/types/packages/database/utils/connect.d.ts +16 -3
- package/dist/types/packages/database/utils/create-migrations.d.ts +1 -3
- package/dist/types/packages/database/utils/normalize-model-name.d.ts +1 -3
- package/dist/types/packages/database/utils/pending-migrations.d.ts +1 -3
- package/dist/types/packages/database/utils/primary-key-type.d.ts +10 -0
- package/dist/types/packages/database/utils/type-for-column.d.ts +3 -5
- package/dist/types/packages/database/utils/validate-relationships.d.ts +13 -0
- package/dist/types/packages/database/validation/errors/validation-error.d.ts +4 -4
- package/dist/types/packages/database/validation/index.d.ts +3 -5
- package/dist/types/packages/database/validation/interfaces.d.ts +1 -1
- package/dist/types/packages/freezeable/map/index.d.ts +1 -3
- package/dist/types/packages/freezeable/set/index.d.ts +1 -3
- package/dist/types/packages/freezeable/utils/freeze.d.ts +5 -15
- package/dist/types/packages/freezeable/utils/is-frozen.d.ts +1 -3
- package/dist/types/packages/fs/index.d.ts +7 -7
- package/dist/types/packages/fs/interfaces.d.ts +4 -4
- package/dist/types/packages/fs/utils/parse-path.d.ts +2 -2
- package/dist/types/packages/fs/watcher/interfaces.d.ts +1 -1
- package/dist/types/packages/jsonapi/errors/invalid-content-type-error.d.ts +3 -5
- package/dist/types/packages/jsonapi/errors/not-acceptable-error.d.ts +2 -4
- package/dist/types/packages/jsonapi/errors/unsupported-media-type-error.d.ts +2 -4
- package/dist/types/packages/jsonapi/index.d.ts +1 -1
- package/dist/types/packages/jsonapi/interfaces.d.ts +47 -36
- package/dist/types/packages/jsonapi/utils/has-media-type-params.d.ts +1 -1
- package/dist/types/packages/jsonapi/utils/is-jsonapi.d.ts +1 -1
- package/dist/types/packages/jsonapi/utils/media-type.d.ts +2 -2
- package/dist/types/packages/loader/builder/index.d.ts +3 -3
- package/dist/types/packages/loader/builder/interfaces.d.ts +7 -7
- package/dist/types/packages/loader/builder/utils/create-children-builder.d.ts +2 -2
- package/dist/types/packages/loader/builder/utils/create-parent-builder.d.ts +9 -2
- package/dist/types/packages/loader/builder/utils/sort-by-namespace.d.ts +2 -2
- package/dist/types/packages/loader/index.d.ts +1 -1
- package/dist/types/packages/loader/interfaces.d.ts +2 -2
- package/dist/types/packages/loader/resolver/index.d.ts +2 -2
- package/dist/types/packages/loader/resolver/utils/closest-ancestor.d.ts +2 -2
- package/dist/types/packages/loader/resolver/utils/closest-child.d.ts +2 -2
- package/dist/types/packages/logger/constants.d.ts +3 -3
- package/dist/types/packages/logger/errors/invalid-config-error.d.ts +5 -0
- package/dist/types/packages/logger/index.d.ts +65 -142
- package/dist/types/packages/logger/interfaces.d.ts +52 -10
- package/dist/types/packages/logger/request-logger/index.d.ts +3 -5
- package/dist/types/packages/logger/request-logger/interfaces.d.ts +5 -5
- package/dist/types/packages/logger/request-logger/templates.d.ts +5 -9
- package/dist/types/packages/logger/request-logger/utils/filter-params.d.ts +6 -1
- package/dist/types/packages/logger/request-logger/utils/log-json.d.ts +2 -4
- package/dist/types/packages/logger/request-logger/utils/log-text.d.ts +1 -3
- package/dist/types/packages/logger/request-logger/utils/params-for.d.ts +9 -0
- package/dist/types/packages/logger/utils/error-name.d.ts +7 -0
- package/dist/types/packages/logger/utils/line.d.ts +1 -3
- package/dist/types/packages/logger/writer/constants.d.ts +0 -1
- package/dist/types/packages/logger/writer/index.d.ts +6 -6
- package/dist/types/packages/logger/writer/interfaces.d.ts +2 -2
- package/dist/types/packages/logger/writer/utils/format-message.d.ts +2 -2
- package/dist/types/packages/lumenify/index.d.ts +20 -5
- package/dist/types/packages/lumenify/utils/create-response-proxy.d.ts +1 -1
- package/dist/types/packages/pm/cluster/index.d.ts +56 -7
- package/dist/types/packages/pm/cluster/interfaces.d.ts +2 -1
- package/dist/types/packages/pm/index.d.ts +2 -2
- package/dist/types/packages/router/definitions/context/index.d.ts +5 -7
- package/dist/types/packages/router/definitions/context/utils/create-definition-group.d.ts +3 -5
- package/dist/types/packages/router/definitions/context/utils/create-definition.d.ts +11 -6
- package/dist/types/packages/router/definitions/context/utils/normalize-resource-args.d.ts +4 -5
- package/dist/types/packages/router/definitions/index.d.ts +5 -9
- package/dist/types/packages/router/definitions/interfaces.d.ts +4 -4
- package/dist/types/packages/router/index.d.ts +23 -11
- package/dist/types/packages/router/interfaces.d.ts +4 -4
- package/dist/types/packages/router/namespace/index.d.ts +7 -9
- package/dist/types/packages/router/namespace/interfaces.d.ts +3 -3
- package/dist/types/packages/router/namespace/utils/normalize-name.d.ts +1 -3
- package/dist/types/packages/router/namespace/utils/normalize-path.d.ts +1 -3
- package/dist/types/packages/router/resource/index.d.ts +7 -8
- package/dist/types/packages/router/resource/interfaces.d.ts +12 -4
- package/dist/types/packages/router/resource/utils/normalize-only.d.ts +3 -5
- package/dist/types/packages/router/route/action/enhancers/resource.d.ts +1 -3
- package/dist/types/packages/router/route/action/enhancers/track-perf.d.ts +1 -3
- package/dist/types/packages/router/route/action/index.d.ts +7 -2
- package/dist/types/packages/router/route/action/interfaces.d.ts +4 -0
- package/dist/types/packages/router/route/action/utils/create-page-links.d.ts +21 -5
- package/dist/types/packages/router/route/action/utils/get-action-name.d.ts +1 -3
- package/dist/types/packages/router/route/action/utils/get-controller-name.d.ts +1 -3
- package/dist/types/packages/router/route/index.d.ts +13 -9
- package/dist/types/packages/router/route/interfaces.d.ts +7 -5
- package/dist/types/packages/router/route/params/errors/client-generated-id-error.d.ts +4 -4
- package/dist/types/packages/router/route/params/errors/forbidden-parameter-error.d.ts +4 -4
- package/dist/types/packages/router/route/params/errors/index.d.ts +1 -0
- package/dist/types/packages/router/route/params/errors/invalid-parameter-error.d.ts +4 -6
- package/dist/types/packages/router/route/params/errors/parameter-not-nullable-error.d.ts +4 -6
- package/dist/types/packages/router/route/params/errors/parameter-range-error.d.ts +9 -0
- package/dist/types/packages/router/route/params/errors/parameter-required-error.d.ts +4 -6
- package/dist/types/packages/router/route/params/errors/parameter-type-error.d.ts +4 -6
- package/dist/types/packages/router/route/params/errors/parameter-value-error.d.ts +4 -6
- package/dist/types/packages/router/route/params/errors/resource-mismatch-error.d.ts +4 -6
- package/dist/types/packages/router/route/params/index.d.ts +5 -9
- package/dist/types/packages/router/route/params/interfaces.d.ts +12 -8
- package/dist/types/packages/router/route/params/parameter/forbidden-parameter.d.ts +1 -1
- package/dist/types/packages/router/route/params/parameter/ignored-parameter.d.ts +14 -0
- package/dist/types/packages/router/route/params/parameter/index.d.ts +21 -5
- package/dist/types/packages/router/route/params/parameter/interfaces.d.ts +2 -2
- package/dist/types/packages/router/route/params/parameter/utils/validate-range.d.ts +3 -0
- package/dist/types/packages/router/route/params/parameter/utils/validate-value.d.ts +1 -3
- package/dist/types/packages/router/route/params/parameter-group/index.d.ts +3 -5
- package/dist/types/packages/router/route/params/parameter-group/utils/missing-params.d.ts +8 -0
- package/dist/types/packages/router/route/params/utils/get-data-params.d.ts +5 -1
- package/dist/types/packages/router/route/params/utils/get-default-collection-params.d.ts +1 -3
- package/dist/types/packages/router/route/params/utils/get-default-member-params.d.ts +5 -2
- package/dist/types/packages/router/route/params/utils/get-query-params.d.ts +3 -9
- package/dist/types/packages/router/route/params/utils/get-url-params.d.ts +1 -3
- package/dist/types/packages/router/route/params/utils/parse-column-value.d.ts +16 -0
- package/dist/types/packages/router/route/params/utils/validate-client-id.d.ts +1 -1
- package/dist/types/packages/router/route/params/utils/validate-resource-id.d.ts +1 -3
- package/dist/types/packages/router/route/params/utils/validate-type.d.ts +3 -5
- package/dist/types/packages/router/route/utils/get-dynamic-segments.d.ts +1 -3
- package/dist/types/packages/router/route/utils/get-static-path.d.ts +6 -2
- package/dist/types/packages/router/utils/create-replacer.d.ts +10 -2
- package/dist/types/packages/serializer/index.d.ts +243 -434
- package/dist/types/packages/serializer/interfaces.d.ts +19 -1
- package/dist/types/packages/serializer/utils/include-tree.d.ts +12 -3
- package/dist/types/packages/serializer/utils/load-linkage.d.ts +9 -3
- package/dist/types/packages/server/errors/error-list.d.ts +25 -0
- package/dist/types/packages/server/errors/method-not-allowed-error.d.ts +11 -0
- package/dist/types/packages/server/index.d.ts +9 -9
- package/dist/types/packages/server/interfaces.d.ts +59 -7
- package/dist/types/packages/server/request/constants.d.ts +2 -2
- package/dist/types/packages/server/request/index.d.ts +3 -5
- package/dist/types/packages/server/request/interfaces.d.ts +72 -8
- package/dist/types/packages/server/request/parser/errors/malformed-request-error.d.ts +3 -5
- package/dist/types/packages/server/request/parser/index.d.ts +6 -1
- package/dist/types/packages/server/request/parser/utils/format.d.ts +13 -11
- package/dist/types/packages/server/request/parser/utils/normalize-document.d.ts +13 -0
- package/dist/types/packages/server/request/parser/utils/parse-nested-object.d.ts +1 -3
- package/dist/types/packages/server/request/parser/utils/parse-read.d.ts +2 -4
- package/dist/types/packages/server/request/parser/utils/parse-write.d.ts +17 -1
- package/dist/types/packages/server/request/utils/get-domain.d.ts +1 -3
- package/dist/types/packages/server/responder/index.d.ts +1 -3
- package/dist/types/packages/server/responder/utils/content-type-for.d.ts +8 -0
- package/dist/types/packages/server/responder/utils/data-for.d.ts +3 -5
- package/dist/types/packages/server/responder/utils/normalize.d.ts +2 -3
- package/dist/types/packages/server/response/index.d.ts +3 -5
- package/dist/types/packages/server/response/interfaces.d.ts +14 -3
- package/dist/types/packages/server/utils/client-ip-for.d.ts +10 -0
- package/dist/types/packages/server/utils/create-server-error.d.ts +11 -3
- package/dist/types/packages/server/utils/request-id-for.d.ts +9 -0
- package/dist/types/packages/server/utils/set-cors-headers.d.ts +2 -2
- package/dist/types/packages/server/utils/source-for.d.ts +19 -3
- package/dist/types/packages/server/utils/status-for-error.d.ts +6 -0
- package/dist/types/packages/server/utils/validate-accept.d.ts +1 -1
- package/dist/types/packages/server/utils/validate-content-type.d.ts +8 -3
- package/dist/types/packages/testing/audit-visibility.d.ts +189 -0
- package/dist/types/packages/testing/index.d.ts +4 -0
- package/dist/types/packages/testing/start-app.d.ts +52 -0
- package/dist/types/packages/testing/utils/identifiers-in.d.ts +14 -0
- package/dist/types/testing.d.ts +9 -0
- package/dist/types/utils/chalk.d.ts +16 -0
- package/dist/types/utils/pick.d.ts +2 -2
- package/package.json +54 -26
- package/dist/types/packages/cli/commands/test.d.ts +0 -4
- package/dist/types/packages/logger/utils/sql.d.ts +0 -4
- package/dist/types/packages/router/route/params/parameter-group/utils/has-required-params.d.ts +0 -5
- package/dist/types/utils/create-query-string.d.ts +0 -6
- package/dist/types/utils/has-own-property.d.ts +0 -1
package/README.md
CHANGED
|
@@ -2,145 +2,111 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/nickschot/lux/actions/workflows/ci.yml) [](https://www.npmjs.com/package/lumen-framework)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
An MVC-style Node.js framework for building [JSON:API 1.0](https://jsonapi.org/)
|
|
6
|
+
compliant REST APIs with very little code. Controllers get create, read, update
|
|
7
|
+
and delete for free — including pagination, sorting, filtering, sparse
|
|
8
|
+
fieldsets and compound documents — and the ORM sits on top of
|
|
9
|
+
[Knex](https://knexjs.org/).
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
**Disclaimer:**
|
|
10
|
-
|
|
11
|
-
This isn't another wrapper around [Express](http://expressjs.com/) or a framework for building frameworks. This also isn't a replacement for server-side frameworks that render DHTML.
|
|
12
|
-
|
|
13
|
-
[Check out the Medium Article!](https://trackchanges.postlight.com/not-another-node-js-framework-33103ebeedf8)
|
|
14
|
-
|
|
15
|
-
## What?
|
|
16
|
-
|
|
17
|
-
### Features
|
|
18
|
-
|
|
19
|
-
* Automatic CRUD actions in controllers
|
|
20
|
-
* Automatic pagination, sorting, filtering via query params in controllers
|
|
21
|
-
* CLI for eliminating boiler plate
|
|
22
|
-
* [JSON API](http://jsonapi.org/) 1.0 compliant out of the box
|
|
23
|
-
* Optimized database queries based on serialized attributes and associations
|
|
24
|
-
* Highly extensible - just write reusable JavaScript functions
|
|
25
|
-
* Pairs nicely with client-side JavaScript applications 🍷
|
|
26
|
-
* Easy to contribute
|
|
27
|
-
* Routes are stored and accessed via a `Map` not an `Array`
|
|
28
|
-
* Embraces ES2015 and beyond
|
|
29
|
-
* Classes
|
|
30
|
-
* Modules
|
|
31
|
-
* Promises & async/await
|
|
32
|
-
* Arrow Functions
|
|
33
|
-
* etc.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Philosophies
|
|
37
|
-
|
|
38
|
-
##### Minimal API surface area
|
|
39
|
-
|
|
40
|
-
Lumen uses JavaScript's standard library rather than creating a ton of functions you'll have to learn and remember.
|
|
41
|
-
|
|
42
|
-
After your learn how to use it, you'll rarely need to look at the docs.
|
|
43
|
-
|
|
44
|
-
##### Pure functions are awesome
|
|
45
|
-
|
|
46
|
-
Or more appropriately somewhat pure functions are awesome.
|
|
47
|
-
|
|
48
|
-
Serving content is done by returning objects, arrays, or other primitives rather than calling `res.end(/* content */);` and returning nothing.
|
|
49
|
-
|
|
50
|
-
##### Convention over configuration
|
|
51
|
-
|
|
52
|
-
[Rails](http://rubyonrails.org/) and [Ember](http://emberjs.com/) are great because they make hard decisions for you and make it possible to submit a PR on your first day at a new company. This is rare with Node server frameworks.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
## Why?
|
|
56
|
-
|
|
57
|
-
Frameworks like Rails are pretty great. You can build amazing applications in a reasonable amount of time without a ton of developers working on a project. They have their limitations though. They can be slow and sometimes hard to scale. Not to mention WebSocket support being so-so.
|
|
58
|
-
|
|
59
|
-
##### Node to the rescue.
|
|
60
|
-
|
|
61
|
-
It's fast, it allows the developer to get low level with a relatively simple API, WebSockets are stable and supported out of the box, and last but not least it's just JavaScript.
|
|
62
|
-
|
|
63
|
-
##### Not so fast (metaphorically speaking).
|
|
64
|
-
|
|
65
|
-
The last bit there "It's just JavaScript" has actually been somewhat of a double-edged sword. This has positioned Node as a "great prototyping tool" or "only used for micro services."
|
|
11
|
+
```javascript
|
|
12
|
+
import { Controller } from 'lumen-framework';
|
|
66
13
|
|
|
67
|
-
|
|
14
|
+
class PostsController extends Controller {
|
|
15
|
+
params = ['title', 'body'];
|
|
16
|
+
}
|
|
68
17
|
|
|
69
|
-
|
|
70
|
-
app.get('/posts', (req, res) => {
|
|
71
|
-
Post.findAll()
|
|
72
|
-
.then(posts => {
|
|
73
|
-
res.status(200).json(posts);
|
|
74
|
-
}, err => {
|
|
75
|
-
console.error(err);
|
|
76
|
-
res.status(500).send(err.message);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
18
|
+
export default PostsController;
|
|
79
19
|
```
|
|
80
20
|
|
|
81
|
-
|
|
21
|
+
That controller, a model and a serializer are a complete `/posts` resource:
|
|
22
|
+
`GET /posts?sort=-title&page[size]=10&fields[posts]=title`, `GET /posts/1`,
|
|
23
|
+
`POST`, `PATCH` and `DELETE` all work.
|
|
82
24
|
|
|
83
|
-
|
|
25
|
+
## Features
|
|
84
26
|
|
|
85
|
-
|
|
27
|
+
- Automatic CRUD actions in controllers, overridable one at a time
|
|
28
|
+
- Pagination, sorting and filtering from query params, limited to the fields
|
|
29
|
+
you allow
|
|
30
|
+
- JSON:API compound documents (`?include=`), sparse fieldsets, relationship
|
|
31
|
+
and related endpoints
|
|
32
|
+
- Visibility rules declared once per namespace and applied to every query a
|
|
33
|
+
request makes — listings, lookups, relationships and includes
|
|
34
|
+
- Database queries shaped by what the serializer actually outputs
|
|
35
|
+
- Structured request logging (JSON or plain text) with credential filtering
|
|
36
|
+
- A CLI that generates models, controllers, serializers, migrations and whole
|
|
37
|
+
resources
|
|
38
|
+
- Written in TypeScript; type declarations ship with the package
|
|
39
|
+
- SQLite, PostgreSQL and MySQL via Knex
|
|
86
40
|
|
|
87
|
-
|
|
41
|
+
## Requirements
|
|
88
42
|
|
|
89
|
-
|
|
43
|
+
- Node.js **22.14** or later
|
|
44
|
+
- One of `better-sqlite3`, `pg` or `mysql2` (`lumen new` adds the one you pick)
|
|
90
45
|
|
|
91
|
-
|
|
46
|
+
## Getting started
|
|
92
47
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
```javascript
|
|
96
|
-
class PostsController extends Controller {
|
|
97
|
-
index(req, res) {
|
|
98
|
-
return Post.all();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
48
|
+
```bash
|
|
49
|
+
npm install -g lumen-framework
|
|
101
50
|
```
|
|
102
51
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
```javascript
|
|
106
|
-
class PostsController extends Controller {
|
|
107
|
-
|
|
108
|
-
}
|
|
52
|
+
```bash
|
|
53
|
+
lumen new blog
|
|
109
54
|
```
|
|
110
55
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
## How?
|
|
56
|
+
```bash
|
|
57
|
+
cd blog
|
|
58
|
+
```
|
|
115
59
|
|
|
116
|
-
|
|
60
|
+
```bash
|
|
61
|
+
lumen generate resource post title:string body:text
|
|
62
|
+
```
|
|
117
63
|
|
|
118
64
|
```bash
|
|
119
|
-
|
|
65
|
+
lumen db:migrate
|
|
120
66
|
```
|
|
121
67
|
|
|
122
|
-
|
|
68
|
+
```bash
|
|
69
|
+
lumen serve
|
|
70
|
+
```
|
|
123
71
|
|
|
124
|
-
|
|
72
|
+
The API is now on `http://localhost:4000`:
|
|
125
73
|
|
|
126
74
|
```bash
|
|
127
|
-
|
|
75
|
+
curl -X POST localhost:4000/posts -H 'Content-Type: application/vnd.api+json' -d '{"data":{"type":"posts","attributes":{"title":"Hello","body":"First post"}}}'
|
|
128
76
|
```
|
|
129
77
|
|
|
130
|
-
|
|
78
|
+
`lumen new --database postgres` (or `mysql`) starts a project on another
|
|
79
|
+
database; `lumen --help` and `lumen <command> --help` list every command and
|
|
80
|
+
option. The [getting-started guide](docs/guides/getting-started.md) walks
|
|
81
|
+
through this step by step, with related resources and the requests the API
|
|
82
|
+
answers.
|
|
83
|
+
|
|
84
|
+
## Documentation
|
|
85
|
+
|
|
86
|
+
- [Guides](docs/guides/) — start with
|
|
87
|
+
[Getting started](docs/guides/getting-started.md).
|
|
88
|
+
- [UPGRADING.md](UPGRADING.md) — what an app has to change, or check, to
|
|
89
|
+
move to Lumen 4.0.
|
|
90
|
+
- [CHANGELOG.md](CHANGELOG.md) — release notes.
|
|
91
|
+
- [examples/social-network](examples/social-network/) — an example app that
|
|
92
|
+
uses most of the framework, with a map of where each feature lives.
|
|
93
|
+
- API reference — every exported class and type, generated from the source:
|
|
94
|
+
`pnpm docs:api` in a checkout of this repository, then open
|
|
95
|
+
`docs/api/index.html`.
|
|
131
96
|
|
|
132
|
-
|
|
97
|
+
## Contributing
|
|
133
98
|
|
|
134
99
|
```bash
|
|
135
|
-
|
|
136
|
-
lumen serve
|
|
100
|
+
pnpm install
|
|
137
101
|
```
|
|
138
102
|
|
|
139
|
-
|
|
103
|
+
```bash
|
|
104
|
+
pnpm build && pnpm test
|
|
105
|
+
```
|
|
140
106
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
107
|
+
The test suite needs the fixture app's dependencies
|
|
108
|
+
(`pnpm --dir test/test-app install`) and builds a SQLite database on first
|
|
109
|
+
run. [RELEASE.md](RELEASE.md) describes how releases are cut.
|
|
144
110
|
|
|
145
111
|
## Attribution
|
|
146
112
|
|
|
@@ -153,7 +119,7 @@ serialization, the ORM built on Knex — is their work.
|
|
|
153
119
|
Upstream development stopped after `v1.2.3` (2018). This fork picks it up from there: it
|
|
154
120
|
was renamed to Lumen to avoid confusion with the original, since it is no longer a
|
|
155
121
|
drop-in continuation of it — the toolchain has been modernized (TypeScript, esbuild,
|
|
156
|
-
Vitest, Node
|
|
122
|
+
Vitest, Node 22+) and the public API has been allowed to change. Lumen is **not** an
|
|
157
123
|
official Postlight project, and the Postlight team provides no support for it.
|
|
158
124
|
|
|
159
125
|
The original is MIT licensed, and Lumen remains MIT licensed under the same terms. The
|
package/bin/lumen
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
// the required app bundle and the cluster workers (which inherit execArgv) both
|
|
8
8
|
// map stack traces back to source.
|
|
9
9
|
|
|
10
|
-
const { EOL } = require('os');
|
|
11
10
|
const path = require('path');
|
|
12
11
|
const { existsSync } = require('fs');
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
// commander is ESM-only from v15 on; `require()` of it needs Node >= 22.12
|
|
14
|
+
// (unflagged require(esm)), within the engines floor.
|
|
15
|
+
const { program: cli, Option } = require('commander');
|
|
16
16
|
|
|
17
17
|
const { version: VERSION } = require('../package.json');
|
|
18
18
|
|
|
@@ -25,7 +25,7 @@ function inLumenProject() {
|
|
|
25
25
|
if (dependencies && dependencies['lumen-framework']) {
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
|
-
} catch
|
|
28
|
+
} catch {
|
|
29
29
|
// No readable package.json here — fall through to the layout check below.
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -43,13 +43,6 @@ function inLumenProject() {
|
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function commandNotFound(cmd) {
|
|
47
|
-
console.log(
|
|
48
|
-
`${EOL} ${red(cmd)} is not a valid command.${EOL.repeat(2)}`,
|
|
49
|
-
` Use ${green('lumen --help')} for a full list of commands.${EOL}`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
46
|
function setEnvVar(key, val, def) {
|
|
54
47
|
if (val) {
|
|
55
48
|
Reflect.set(process.env, key, val);
|
|
@@ -61,7 +54,7 @@ function setEnvVar(key, val, def) {
|
|
|
61
54
|
function exec(cmd, ...args) {
|
|
62
55
|
const handler = require('../dist/cli.cjs')[cmd];
|
|
63
56
|
const needsProject = new RegExp(
|
|
64
|
-
'^(?:db:.+|
|
|
57
|
+
'^(?:db:.+|build|serve|console|generate|destroy)$'
|
|
65
58
|
);
|
|
66
59
|
|
|
67
60
|
if (needsProject.test(cmd) && !inLumenProject()) {
|
|
@@ -88,24 +81,15 @@ cli
|
|
|
88
81
|
.command('n <name>')
|
|
89
82
|
.alias('new')
|
|
90
83
|
.description('Create a new application')
|
|
91
|
-
.
|
|
92
|
-
'--database
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
'sqlite'
|
|
84
|
+
.addOption(
|
|
85
|
+
new Option('--database <database>', 'Database driver')
|
|
86
|
+
.choices(['postgres', 'sqlite', 'mysql'])
|
|
87
|
+
.default('sqlite')
|
|
96
88
|
)
|
|
97
89
|
.action((name, { database }) => {
|
|
98
90
|
exec('create', name, database).then(exit).catch(rescue);
|
|
99
91
|
});
|
|
100
92
|
|
|
101
|
-
cli
|
|
102
|
-
.command('t')
|
|
103
|
-
.alias('test')
|
|
104
|
-
.description("Run your application's test suite")
|
|
105
|
-
.action(() => {
|
|
106
|
-
exec('test').then(exit).catch(rescue);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
93
|
cli
|
|
110
94
|
.command('b')
|
|
111
95
|
.alias('build')
|
|
@@ -119,7 +103,7 @@ cli
|
|
|
119
103
|
.command('c')
|
|
120
104
|
.alias('console')
|
|
121
105
|
.description('Load your application into a repl')
|
|
122
|
-
.option('-e, --environment
|
|
106
|
+
.option('-e, --environment <env>', '(Default: development)')
|
|
123
107
|
.option('-w, --use-weak', 'Use weak mode')
|
|
124
108
|
.action(({ environment, useWeak }) => {
|
|
125
109
|
setEnvVar('NODE_ENV', environment, 'development');
|
|
@@ -136,8 +120,8 @@ cli
|
|
|
136
120
|
.alias('serve')
|
|
137
121
|
.description('Serve your application')
|
|
138
122
|
.option('-c, --cluster', 'Run in cluster mode')
|
|
139
|
-
.option('-e, --environment
|
|
140
|
-
.option('-p, --port
|
|
123
|
+
.option('-e, --environment <env>', '(Default: development)')
|
|
124
|
+
.option('-p, --port <port>', '(Default: 4000)', port =>
|
|
141
125
|
Number.parseInt(port, 10)
|
|
142
126
|
)
|
|
143
127
|
.option('-H, --hot', 'Reload when a file change is detected')
|
|
@@ -164,8 +148,8 @@ cli
|
|
|
164
148
|
});
|
|
165
149
|
|
|
166
150
|
cli
|
|
167
|
-
.command('d')
|
|
168
|
-
.alias('destroy
|
|
151
|
+
.command('d <type> <name>')
|
|
152
|
+
.alias('destroy')
|
|
169
153
|
.description('Example: lumen destroy model user')
|
|
170
154
|
.action((type, name) => {
|
|
171
155
|
exec('destroy', { type, name }).then(exit).catch(rescue);
|
|
@@ -174,7 +158,7 @@ cli
|
|
|
174
158
|
cli
|
|
175
159
|
.command('db:create')
|
|
176
160
|
.description('Create your database schema')
|
|
177
|
-
.option('-e, --environment
|
|
161
|
+
.option('-e, --environment <env>', '(Default: development)')
|
|
178
162
|
.option('-w, --use-weak', 'Use weak mode')
|
|
179
163
|
.action(({ environment, useWeak }) => {
|
|
180
164
|
const useStrict = !useWeak;
|
|
@@ -190,7 +174,7 @@ cli
|
|
|
190
174
|
cli
|
|
191
175
|
.command('db:drop')
|
|
192
176
|
.description('Drop your database schema')
|
|
193
|
-
.option('-e, --environment
|
|
177
|
+
.option('-e, --environment <env>', '(Default: development)')
|
|
194
178
|
.option('-w, --use-weak', 'Use weak mode')
|
|
195
179
|
.action(({ environment, useWeak }) => {
|
|
196
180
|
const useStrict = !useWeak;
|
|
@@ -206,7 +190,7 @@ cli
|
|
|
206
190
|
cli
|
|
207
191
|
.command('db:reset')
|
|
208
192
|
.description('Drop your database schema and create a new schema')
|
|
209
|
-
.option('-e, --environment
|
|
193
|
+
.option('-e, --environment <env>', '(Default: development)')
|
|
210
194
|
.option('-w, --use-weak', 'Use weak mode')
|
|
211
195
|
.action(({ environment, useWeak }) => {
|
|
212
196
|
const useStrict = !useWeak;
|
|
@@ -223,7 +207,7 @@ cli
|
|
|
223
207
|
cli
|
|
224
208
|
.command('db:migrate')
|
|
225
209
|
.description('Run database migrations')
|
|
226
|
-
.option('-e, --environment
|
|
210
|
+
.option('-e, --environment <env>', '(Default: development)')
|
|
227
211
|
.option('-w, --use-weak', 'Use weak mode')
|
|
228
212
|
.action(({ environment, useWeak }) => {
|
|
229
213
|
const useStrict = !useWeak;
|
|
@@ -239,7 +223,7 @@ cli
|
|
|
239
223
|
cli
|
|
240
224
|
.command('db:rollback')
|
|
241
225
|
.description('Rollback the last database migration')
|
|
242
|
-
.option('-e, --environment
|
|
226
|
+
.option('-e, --environment <env>', '(Default: development)')
|
|
243
227
|
.option('-w, --use-weak', 'Use weak mode')
|
|
244
228
|
.action(({ environment, useWeak }) => {
|
|
245
229
|
const useStrict = !useWeak;
|
|
@@ -255,7 +239,7 @@ cli
|
|
|
255
239
|
cli
|
|
256
240
|
.command('db:seed')
|
|
257
241
|
.description('Add fixtures to your db from the seed function')
|
|
258
|
-
.option('-e, --environment
|
|
242
|
+
.option('-e, --environment <env>', '(Default: development)')
|
|
259
243
|
.option('-w, --use-weak', 'Use weak mode')
|
|
260
244
|
.action(({ environment, useWeak }) => {
|
|
261
245
|
const useStrict = !useWeak;
|
|
@@ -268,8 +252,6 @@ cli
|
|
|
268
252
|
.catch(rescue);
|
|
269
253
|
});
|
|
270
254
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
cli.help();
|
|
275
|
-
}
|
|
255
|
+
// An unknown command errors (with a "did you mean" suggestion) and no command
|
|
256
|
+
// prints the help — both built into commander, exiting 1.
|
|
257
|
+
cli.parse(process.argv);
|