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
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import type { Model, ModelClass, Query } from '../database';
|
|
2
2
|
import type { Request, Response } from '../server';
|
|
3
3
|
import type Serializer from '../serializer';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* What Lumen constructs a controller with when the app boots. Apps don't
|
|
6
|
+
* construct controllers themselves.
|
|
7
|
+
*/
|
|
8
|
+
export type ControllerOptions = {
|
|
9
|
+
/** The model of the controller's resource, if it has one. */
|
|
5
10
|
model?: ModelClass<Model>;
|
|
11
|
+
/** The controller's namespace (`admin`), or `''` for the root. */
|
|
6
12
|
namespace?: string;
|
|
13
|
+
/** The serializer of the controller's resource, if it has one. */
|
|
7
14
|
serializer?: Serializer<Model>;
|
|
8
15
|
};
|
|
9
|
-
export type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
export type BuiltInAction = 'show' | 'index' | 'create' | 'update' | 'destroy';
|
|
17
|
+
/**
|
|
18
|
+
* A {@link Controller.beforeAction} hook. Resolving with anything but
|
|
19
|
+
* `undefined` ends the request, with that value as the response.
|
|
20
|
+
*/
|
|
21
|
+
export type BeforeAction = (request: Request, response: Response) => Promise<unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* A {@link Controller.afterAction} hook. `responseData` is the action's result
|
|
24
|
+
* (or the previous hook's); what the hook resolves with is sent instead.
|
|
25
|
+
*/
|
|
26
|
+
export type AfterAction = (request: Request, response: Response, responseData?: unknown) => Promise<unknown>;
|
|
27
|
+
export type FindOne<T extends Model> = (request: Request) => Query<T>;
|
|
28
|
+
export type FindMany<T extends Model> = (request: Request) => Query<Array<T>>;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { Model, ModelClass, Query } from '../../database';
|
|
2
|
-
import type Serializer from '../../serializer';
|
|
3
2
|
import type { Request } from '../../server';
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export default function findMany<T extends Model>(model: ModelClass<T>, req: Request, serializerFor?: (model: ModelClass) => Serializer<Model>): Query<Array<Model>>;
|
|
3
|
+
/** @internal */
|
|
4
|
+
export default function findMany<T extends Model>(model: ModelClass<T>, req: Request): Query<Array<Model>>;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { Model, ModelClass, Query } from '../../database';
|
|
2
|
-
import type Serializer from '../../serializer';
|
|
3
2
|
import type { Request } from '../../server';
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export default function findOne<T extends Model>(model: ModelClass<T>, req: Request, serializerFor?: (model: ModelClass) => Serializer<Model>): Query<T>;
|
|
3
|
+
/** @internal */
|
|
4
|
+
export default function findOne<T extends Model>(model: ModelClass<T>, req: Request): Query<T>;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
type Controller$query = {
|
|
1
|
+
import type { ModelClass } from '../../database';
|
|
2
|
+
import type { RequestParams } from '../../server';
|
|
3
|
+
type ControllerQuery = {
|
|
5
4
|
id?: number | string | Buffer;
|
|
6
5
|
filter?: Record<string, unknown>;
|
|
7
6
|
select: Array<string>;
|
|
8
7
|
page?: number;
|
|
9
8
|
limit?: number;
|
|
10
9
|
sort?: [string, string];
|
|
11
|
-
include: Record<string, Array<string>>;
|
|
12
10
|
};
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* Translate request params into the primary query. Only primary data is
|
|
13
|
+
* loaded by it: resource linkage and included resources are batch-loaded by
|
|
14
|
+
* the Serializer.
|
|
17
15
|
*
|
|
18
|
-
* @
|
|
16
|
+
* @internal
|
|
19
17
|
*/
|
|
20
|
-
export default function paramsToQuery(model: ModelClass, { id, page, sort, filter, fields
|
|
18
|
+
export default function paramsToQuery(model: ModelClass, { id, page, sort, filter, fields }: RequestParams): ControllerQuery;
|
|
21
19
|
export {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { Scope } from '../visibility';
|
|
1
2
|
import type { Model, ModelClass } from '../../database';
|
|
2
3
|
/**
|
|
3
4
|
* Check that every resource referenced from `data.relationships` exists, so a
|
|
4
|
-
* write cannot leave dangling linkage
|
|
5
|
+
* write cannot leave dangling linkage, or link a record `scope` hides. One
|
|
6
|
+
* query per relationship.
|
|
5
7
|
*
|
|
6
|
-
* @
|
|
8
|
+
* @internal
|
|
7
9
|
*/
|
|
8
|
-
export default function validateRelationships<T extends Model>(model: ModelClass<T>, relationships?: Record<string, unknown
|
|
10
|
+
export default function validateRelationships<T extends Model>(model: ModelClass<T>, relationships?: Record<string, unknown>, scope?: Scope): Promise<void>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ModelClass } from '../../database';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown at boot for visibility rules that cannot be applied: rules declared
|
|
4
|
+
* on a controller other than a namespace's `ApplicationController`, rules for
|
|
5
|
+
* an unknown type, or a rule that is not a function.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare class VisibilityConfigError extends TypeError {
|
|
10
|
+
constructor(problems: Array<string>);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Thrown while serving a request when a visibility rule does something other
|
|
14
|
+
* than narrow its query with conditions. A programming error, so it surfaces
|
|
15
|
+
* as a `500`.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare class VisibilityRuleError extends TypeError {
|
|
20
|
+
constructor({ resourceName }: ModelClass, problem: string);
|
|
21
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Query } from '../../database';
|
|
2
|
+
import type { Model, ModelClass } from '../../database';
|
|
3
|
+
import type { Request } from '../../server';
|
|
4
|
+
/**
|
|
5
|
+
* A namespace's visibility rules: per resource type, a function that narrows
|
|
6
|
+
* a `Query` of that type to the rows the request may see.
|
|
7
|
+
*/
|
|
8
|
+
export type Visibility = Record<string, (query: Query<Array<Model>>, request: Request) => Query<Array<Model>>>;
|
|
9
|
+
/**
|
|
10
|
+
* Applies a namespace's visibility rules for one request. Every query Lumen
|
|
11
|
+
* issues for the request — primary data, linkage, `included`, relationship
|
|
12
|
+
* checks on writes — goes through `apply()`.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare class Scope {
|
|
17
|
+
/**
|
|
18
|
+
* Applies no rules. The default wherever no request is involved.
|
|
19
|
+
*/
|
|
20
|
+
static readonly none: Scope;
|
|
21
|
+
private readonly rules;
|
|
22
|
+
private readonly request;
|
|
23
|
+
private readonly compiled;
|
|
24
|
+
constructor(rules: Visibility, request: Request | null);
|
|
25
|
+
/**
|
|
26
|
+
* Whether a rule narrows `model`.
|
|
27
|
+
*/
|
|
28
|
+
covers(model: ModelClass): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Add the conditions of `query.model`'s rule, if it has one, to `query`.
|
|
31
|
+
*
|
|
32
|
+
* The conditions are added untagged, so `query.unscope()` cannot remove
|
|
33
|
+
* them.
|
|
34
|
+
*/
|
|
35
|
+
apply<Q extends Query<unknown>>(query: Q): Q;
|
|
36
|
+
/**
|
|
37
|
+
* Run `model`'s rule once per request against an empty probe query and keep
|
|
38
|
+
* the conditions it adds. Only conditions are allowed: the same rule has to
|
|
39
|
+
* hold for `count()`, for the narrow selects linkage is loaded with and for
|
|
40
|
+
* existence checks, which a `select`, `order`, `limit`, `include` or join
|
|
41
|
+
* would break.
|
|
42
|
+
*/
|
|
43
|
+
private conditionsFor;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The `Scope` of `request` under `rules`, created once per request so each
|
|
47
|
+
* rule runs at most once however many queries it narrows.
|
|
48
|
+
*
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export declare function scopeFor(rules: Visibility, request: Request): Scope;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare function createAttribute(opts: Attribute$meta): PropertyDescriptor;
|
|
6
|
-
export type { Attribute$meta } from './interfaces';
|
|
1
|
+
import type { AttributeMeta } from './interfaces';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export declare function createAttribute(opts: AttributeMeta): PropertyDescriptor;
|
|
4
|
+
export type { AttributeMeta } from './interfaces';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
export default function createAttribute(opts: Attribute$meta): PropertyDescriptor;
|
|
1
|
+
import type { AttributeMeta } from '../index';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export default function createAttribute(opts: AttributeMeta): PropertyDescriptor;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type Model from '../../model';
|
|
2
|
-
import type {
|
|
3
|
-
export default function createGetter({ key, defaultValue }:
|
|
2
|
+
import type { AttributeMeta } from '../index';
|
|
3
|
+
export default function createGetter({ key, defaultValue }: AttributeMeta): (this: Model) => unknown;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type Model from '../../model';
|
|
2
|
-
import type {
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
export default function createSetter({ key, nullable, normalize, defaultValue }: Attribute$meta & {
|
|
2
|
+
import type { AttributeMeta } from '../index';
|
|
3
|
+
/** @internal */
|
|
4
|
+
export default function createSetter({ key, nullable, normalize, defaultValue }: AttributeMeta & {
|
|
7
5
|
normalize: (value: unknown) => unknown;
|
|
8
6
|
}): (this: Model, value?: unknown) => void;
|
|
@@ -3,3 +3,4 @@ export { default as ModelMissingError } from './model-missing-error';
|
|
|
3
3
|
export { default as MigrationsPendingError } from './migrations-pending-error';
|
|
4
4
|
export { default as UniqueConstraintError } from './unique-constraint-error';
|
|
5
5
|
export { default as ConfigMissingError } from './config-missing-error';
|
|
6
|
+
export { default as RelationshipConfigError } from './relationship-config-error';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown at boot when relationships are declared in a way that cannot work,
|
|
3
|
+
* listing every problem.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
declare class RelationshipConfigError extends TypeError {
|
|
8
|
+
constructor(problems: Array<string>);
|
|
9
|
+
}
|
|
10
|
+
export default RelationshipConfigError;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare class UniqueConstraintError extends Error {
|
|
2
2
|
}
|
|
3
|
-
declare const _default: new (...args: Array<any>) => UniqueConstraintError & import("../../server
|
|
3
|
+
declare const _default: new (...args: Array<any>) => UniqueConstraintError & import("../../server").ServerError;
|
|
4
4
|
export default _default;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
2
|
import type Logger from '../logger';
|
|
3
|
-
import type {
|
|
4
|
-
/**
|
|
5
|
-
* @private
|
|
6
|
-
*/
|
|
3
|
+
import type { DatabaseOptions, ModelClass } from './interfaces';
|
|
4
|
+
/** @internal */
|
|
7
5
|
declare class Database {
|
|
8
6
|
path: string;
|
|
9
7
|
debug: boolean;
|
|
@@ -12,15 +10,20 @@ declare class Database {
|
|
|
12
10
|
schema: () => Knex.SchemaBuilder;
|
|
13
11
|
connection: Knex;
|
|
14
12
|
models: Map<string, ModelClass>;
|
|
15
|
-
constructor(opts:
|
|
13
|
+
constructor(opts: DatabaseOptions);
|
|
16
14
|
modelFor(type: string): ModelClass;
|
|
17
15
|
}
|
|
18
16
|
export default Database;
|
|
19
17
|
export { default as Model } from './model';
|
|
20
18
|
export { default as Query } from './query';
|
|
19
|
+
export { readAttribute, writeAttribute } from './model/utils/attribute';
|
|
21
20
|
export { default as Migration, generateTimestamp } from './migration';
|
|
22
21
|
export { default as connect } from './utils/connect';
|
|
23
22
|
export { default as typeForColumn } from './utils/type-for-column';
|
|
23
|
+
export { default as primaryKeyType } from './utils/primary-key-type';
|
|
24
24
|
export { default as createMigrations } from './utils/create-migrations';
|
|
25
25
|
export { default as pendingMigrations } from './utils/pending-migrations';
|
|
26
|
-
export type {
|
|
26
|
+
export type { DatabaseOptions, DatabaseConfig, DatabaseEnvironmentConfig, DatabasePoolConfig, ModelClass } from './interfaces';
|
|
27
|
+
export type { ModelHook, ModelHooks } from './model/interfaces';
|
|
28
|
+
export type { RelationshipOptions } from './relationship/interfaces';
|
|
29
|
+
export type { TransactionResult } from './transaction/interfaces';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type Database from './index';
|
|
2
|
-
import type {
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
export default function initialize<T extends Database>(instance: T, opts: Database$opts): Promise<T>;
|
|
2
|
+
import type { DatabaseOptions } from './index';
|
|
3
|
+
/** @internal */
|
|
4
|
+
export default function initialize<T extends Database>(instance: T, opts: DatabaseOptions): Promise<T>;
|
|
@@ -2,84 +2,174 @@ import type Logger from '../logger';
|
|
|
2
2
|
import type Serializer from '../serializer';
|
|
3
3
|
import type Database from './index';
|
|
4
4
|
import type { Model, Query } from './index';
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
|
|
5
|
+
import type { ModelHooks } from './model/interfaces';
|
|
6
|
+
import type { RelationshipOptions } from './relationship/interfaces';
|
|
7
|
+
import type { TransactionResult } from './transaction/interfaces';
|
|
8
|
+
/**
|
|
9
|
+
* The size of the connection pool, per process: a maximum (the minimum is
|
|
10
|
+
* then 2, or 1 for a pool of 1), or both bounds.
|
|
11
|
+
*/
|
|
12
|
+
export type DatabasePoolConfig = number | {
|
|
13
|
+
/** The fewest connections kept open. */
|
|
9
14
|
min: number;
|
|
15
|
+
/** The most connections open at once. */
|
|
10
16
|
max: number;
|
|
11
17
|
};
|
|
12
|
-
type
|
|
13
|
-
|
|
18
|
+
type DatabaseColumnType = 'floating' | 'enu' | 'bool' | 'varchar' | 'bigInteger';
|
|
19
|
+
/**
|
|
20
|
+
* The database connection of one environment, in `config/database.js`.
|
|
21
|
+
*
|
|
22
|
+
* ```javascript
|
|
23
|
+
* production: {
|
|
24
|
+
* driver: 'pg',
|
|
25
|
+
* host: 'db.internal',
|
|
26
|
+
* database: 'blog_prod',
|
|
27
|
+
* username: 'blog',
|
|
28
|
+
* password: process.env.DATABASE_PASSWORD,
|
|
29
|
+
* pool: 10
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* A `url`, or the `DATABASE_URL` environment variable, replaces the host,
|
|
34
|
+
* credentials and database settings; `driver`, `pool`, `debug` and `ssl`
|
|
35
|
+
* still apply.
|
|
36
|
+
*/
|
|
37
|
+
export type DatabaseEnvironmentConfig = {
|
|
38
|
+
/** The database server's host name. */
|
|
14
39
|
host?: string;
|
|
15
|
-
pool
|
|
40
|
+
/** The connection pool size, per process. */
|
|
41
|
+
pool?: DatabasePoolConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Log every SQL statement, with its values, at `DEBUG`. Defaults to `true`
|
|
44
|
+
* in development only.
|
|
45
|
+
*/
|
|
16
46
|
debug?: boolean;
|
|
47
|
+
/** The client: `'pg'`, `'mysql2'` or `'better-sqlite3'`. */
|
|
17
48
|
driver: string;
|
|
49
|
+
/** A Unix socket to connect through instead of `host` and `port`. */
|
|
18
50
|
socket?: string;
|
|
51
|
+
/**
|
|
52
|
+
* The database name. With SQLite, the file is
|
|
53
|
+
* `db/<database>_<NODE_ENV>.sqlite` in the app.
|
|
54
|
+
*/
|
|
19
55
|
database?: string;
|
|
56
|
+
/** The user to connect as. */
|
|
20
57
|
username?: string;
|
|
58
|
+
/** The user's password. */
|
|
21
59
|
password?: string;
|
|
60
|
+
/** The database server's port. */
|
|
22
61
|
port?: number;
|
|
23
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Connect over TLS: `true`, or the driver's TLS options
|
|
64
|
+
* (`{ rejectUnauthorized: false }` for a certificate Node doesn't trust,
|
|
65
|
+
* as on Heroku Postgres). Applies with a `url` or `DATABASE_URL` too,
|
|
66
|
+
* unless the URL sets TLS itself (`?sslmode=…`).
|
|
67
|
+
*/
|
|
68
|
+
ssl?: boolean | Record<string, unknown>;
|
|
69
|
+
/**
|
|
70
|
+
* A connection string (`postgres://user:pass@host:5432/db`) that replaces
|
|
71
|
+
* the host, credentials and database settings. `DATABASE_URL` takes
|
|
72
|
+
* precedence over it.
|
|
73
|
+
*/
|
|
24
74
|
url?: string;
|
|
25
75
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
76
|
+
/**
|
|
77
|
+
* The contents of `config/database.js`: a connection per environment,
|
|
78
|
+
* chosen by `NODE_ENV` or the CLI's `--environment`.
|
|
79
|
+
*/
|
|
80
|
+
export type DatabaseConfig = {
|
|
81
|
+
/** The connection used by `lumen serve` and the `db:` commands by default. */
|
|
82
|
+
development: DatabaseEnvironmentConfig;
|
|
83
|
+
/** The connection used when `NODE_ENV` is `test`. */
|
|
84
|
+
test: DatabaseEnvironmentConfig;
|
|
85
|
+
/** The connection used when `NODE_ENV` is `production`. */
|
|
86
|
+
production: DatabaseEnvironmentConfig;
|
|
87
|
+
[environment: string]: DatabaseEnvironmentConfig | undefined;
|
|
30
88
|
};
|
|
31
|
-
export type
|
|
89
|
+
export type DatabaseOptions = {
|
|
32
90
|
path: string;
|
|
33
91
|
models: Map<string, ModelClass>;
|
|
34
|
-
config:
|
|
92
|
+
config: DatabaseConfig;
|
|
35
93
|
logger: Logger;
|
|
36
94
|
checkMigrations?: boolean;
|
|
95
|
+
checkRelationships?: boolean;
|
|
37
96
|
};
|
|
38
|
-
export type
|
|
39
|
-
type:
|
|
97
|
+
export type DatabaseColumn = {
|
|
98
|
+
type: DatabaseColumnType;
|
|
40
99
|
nullable: boolean;
|
|
41
100
|
maxLength: string;
|
|
42
101
|
columnName: string;
|
|
43
102
|
defaultValue: unknown;
|
|
44
103
|
};
|
|
45
104
|
/**
|
|
46
|
-
*
|
|
47
|
-
* `
|
|
48
|
-
*
|
|
49
|
-
* holds "a model class".
|
|
105
|
+
* A model class — {@link Model} or a subclass — as a value: what
|
|
106
|
+
* `Post` is, where a `Post` record is a {@link Model}. Framework APIs that
|
|
107
|
+
* take or return a model use it.
|
|
50
108
|
*/
|
|
51
109
|
export interface ModelClass<T extends Model = Model> {
|
|
110
|
+
/** @internal */
|
|
52
111
|
new (attrs?: Record<string, unknown>, initialize?: boolean): T;
|
|
112
|
+
/** @internal */
|
|
53
113
|
prototype: T;
|
|
114
|
+
/** The class name (`BlogPost`). */
|
|
54
115
|
name: string;
|
|
116
|
+
/** See {@link Model.primaryKey}. */
|
|
55
117
|
primaryKey: string;
|
|
118
|
+
/** See {@link Model.tableName}. */
|
|
56
119
|
tableName: string;
|
|
120
|
+
/** See {@link Model.modelName}. */
|
|
57
121
|
modelName: string;
|
|
122
|
+
/** See {@link Model.resourceName}. */
|
|
58
123
|
resourceName: string;
|
|
124
|
+
/** @internal */
|
|
59
125
|
serializer: Serializer<T>;
|
|
126
|
+
/** @internal */
|
|
60
127
|
attributes: Record<string, unknown>;
|
|
128
|
+
/** @internal */
|
|
61
129
|
attributeNames: Array<string>;
|
|
62
|
-
|
|
130
|
+
/** @internal */
|
|
131
|
+
relationships: Record<string, RelationshipOptions>;
|
|
132
|
+
/** @internal */
|
|
63
133
|
relationshipNames: Array<string>;
|
|
134
|
+
/** See {@link Model.hasOne}. */
|
|
64
135
|
hasOne: Record<string, unknown>;
|
|
136
|
+
/** See {@link Model.hasMany}. */
|
|
65
137
|
hasMany: Record<string, unknown>;
|
|
138
|
+
/** See {@link Model.belongsTo}. */
|
|
66
139
|
belongsTo: Record<string, unknown>;
|
|
140
|
+
/** See {@link Model.scopes}. */
|
|
67
141
|
scopes: Record<string, unknown>;
|
|
142
|
+
/** See {@link Model.validates}. */
|
|
68
143
|
validates: Record<string, unknown>;
|
|
69
|
-
hooks
|
|
144
|
+
/** See {@link Model.hooks}. */
|
|
145
|
+
hooks: ModelHooks;
|
|
146
|
+
/** @internal */
|
|
70
147
|
store: Database;
|
|
148
|
+
/** See {@link Model.logger}. */
|
|
71
149
|
logger: Logger;
|
|
150
|
+
/** @internal */
|
|
72
151
|
table(): any;
|
|
152
|
+
/** See {@link Model.isInstance}. */
|
|
73
153
|
isInstance(value: unknown): boolean;
|
|
154
|
+
/** @internal */
|
|
74
155
|
initialize(store: Database, table: () => unknown): Promise<ModelClass>;
|
|
156
|
+
/** See {@link Model.transaction}. */
|
|
75
157
|
transaction<R>(fn: (...args: Array<unknown>) => Promise<R>): Promise<R>;
|
|
76
|
-
|
|
158
|
+
/** @internal */
|
|
159
|
+
columnFor(key: string): DatabaseColumn | undefined;
|
|
160
|
+
/** @internal */
|
|
77
161
|
columnNameFor(key: string): string | undefined;
|
|
78
|
-
|
|
162
|
+
/** @internal */
|
|
163
|
+
relationshipFor(key: string): RelationshipOptions | undefined;
|
|
164
|
+
/** See {@link Model.find}. */
|
|
79
165
|
find(primaryKey: unknown): Query<T>;
|
|
166
|
+
/** See {@link Model.first}. */
|
|
80
167
|
first(): Query<T>;
|
|
168
|
+
/** See {@link Model.where}. */
|
|
81
169
|
where(conditions: Record<string, unknown>): Query<Array<T>>;
|
|
170
|
+
/** See {@link Model.select}. */
|
|
82
171
|
select(...columns: Array<string>): Query<Array<T>>;
|
|
83
|
-
|
|
172
|
+
/** See {@link Model.create}. */
|
|
173
|
+
create(attributes?: Record<string, unknown>, trx?: unknown): Promise<TransactionResult<T, boolean>>;
|
|
84
174
|
}
|
|
85
175
|
export {};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
* @private
|
|
4
|
-
*/
|
|
1
|
+
import type { MigrationFn } from './interfaces';
|
|
2
|
+
/** @internal */
|
|
5
3
|
declare class Migration<T extends object> {
|
|
6
|
-
fn:
|
|
7
|
-
constructor(fn:
|
|
4
|
+
fn: MigrationFn<T>;
|
|
5
|
+
constructor(fn: MigrationFn<T>);
|
|
8
6
|
run(schema: T): T;
|
|
9
7
|
}
|
|
10
8
|
export default Migration;
|
|
11
9
|
export { default as generateTimestamp } from './utils/generate-timestamp';
|
|
12
|
-
export type {
|
|
10
|
+
export type { MigrationFn } from './interfaces';
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export declare function padding(char: string, amount: number): Generator<string, void, void>;
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A migration's version: `YYYYMMDDHHmmssCC` in UTC (`CC` are hundredths of a
|
|
4
|
+
* second), 16 digits. Fixed-width and zero-padded, so versions sort in the
|
|
5
|
+
* order they were generated — `lumen db:migrate` runs migrations in that
|
|
6
|
+
* order.
|
|
7
|
+
*
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
export default function generateTimestamp(now?: Date): string;
|