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.
- package/LICENSE +26 -0
- package/README.md +164 -0
- package/bin/lumen +275 -0
- package/dist/cli.cjs +3002 -0
- package/dist/cli.cjs.map +7 -0
- package/dist/index.js +6515 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +6480 -0
- package/dist/index.mjs.map +7 -0
- package/dist/types/constants.d.ts +7 -0
- package/dist/types/errors/controller-missing-error.d.ts +7 -0
- package/dist/types/errors/serializer-missing-error.d.ts +7 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/interfaces.d.ts +12 -0
- package/dist/types/packages/application/index.d.ts +97 -0
- package/dist/types/packages/application/initialize.d.ts +6 -0
- package/dist/types/packages/application/interfaces.d.ts +16 -0
- package/dist/types/packages/application/utils/create-controller.d.ts +12 -0
- package/dist/types/packages/application/utils/create-serializer.d.ts +4 -0
- package/dist/types/packages/application/utils/normalize-port.d.ts +4 -0
- package/dist/types/packages/cli/commands/build.d.ts +1 -0
- package/dist/types/packages/cli/commands/create.d.ts +4 -0
- package/dist/types/packages/cli/commands/dbcreate.d.ts +4 -0
- package/dist/types/packages/cli/commands/dbdrop.d.ts +4 -0
- package/dist/types/packages/cli/commands/dbmigrate.d.ts +4 -0
- package/dist/types/packages/cli/commands/dbrollback.d.ts +4 -0
- package/dist/types/packages/cli/commands/dbseed.d.ts +4 -0
- package/dist/types/packages/cli/commands/destroy.d.ts +11 -0
- package/dist/types/packages/cli/commands/generate.d.ts +10 -0
- package/dist/types/packages/cli/commands/index.d.ts +12 -0
- package/dist/types/packages/cli/commands/repl.d.ts +1 -0
- package/dist/types/packages/cli/commands/serve.d.ts +8 -0
- package/dist/types/packages/cli/commands/test.d.ts +4 -0
- package/dist/types/packages/cli/constants.d.ts +2 -0
- package/dist/types/packages/cli/errors/database-config-missing.d.ts +4 -0
- package/dist/types/packages/cli/generator/constants.d.ts +5 -0
- package/dist/types/packages/cli/generator/index.d.ts +11 -0
- package/dist/types/packages/cli/generator/interfaces.d.ts +9 -0
- package/dist/types/packages/cli/generator/utils/create-generator.d.ts +9 -0
- package/dist/types/packages/cli/generator/utils/generate-type.d.ts +33 -0
- package/dist/types/packages/cli/generator/utils/generator-for.d.ts +2 -0
- package/dist/types/packages/cli/generator/utils/log.d.ts +4 -0
- package/dist/types/packages/cli/generator/utils/migration-conflict.d.ts +6 -0
- package/dist/types/packages/cli/templates/application.d.ts +5 -0
- package/dist/types/packages/cli/templates/config.d.ts +5 -0
- package/dist/types/packages/cli/templates/controller.d.ts +5 -0
- package/dist/types/packages/cli/templates/database.d.ts +5 -0
- package/dist/types/packages/cli/templates/empty-migration.d.ts +5 -0
- package/dist/types/packages/cli/templates/eslint-config.d.ts +5 -0
- package/dist/types/packages/cli/templates/gitignore.d.ts +5 -0
- package/dist/types/packages/cli/templates/license.d.ts +5 -0
- package/dist/types/packages/cli/templates/middleware.d.ts +5 -0
- package/dist/types/packages/cli/templates/model-migration.d.ts +5 -0
- package/dist/types/packages/cli/templates/model.d.ts +5 -0
- package/dist/types/packages/cli/templates/package-json.d.ts +5 -0
- package/dist/types/packages/cli/templates/readme.d.ts +5 -0
- package/dist/types/packages/cli/templates/routes.d.ts +5 -0
- package/dist/types/packages/cli/templates/seed.d.ts +5 -0
- package/dist/types/packages/cli/templates/serializer.d.ts +5 -0
- package/dist/types/packages/cli/templates/util.d.ts +5 -0
- package/dist/types/packages/cli/utils/create-prompt.d.ts +4 -0
- package/dist/types/packages/cli/utils/driver-for.d.ts +1 -0
- package/dist/types/packages/cli/utils/indent.d.ts +1 -0
- package/dist/types/packages/compiler/index.d.ts +11 -0
- package/dist/types/packages/compiler/interfaces.d.ts +1 -0
- package/dist/types/packages/compiler/utils/create-boot-script.d.ts +6 -0
- package/dist/types/packages/compiler/utils/create-manifest.d.ts +6 -0
- package/dist/types/packages/compiler/utils/format-name.d.ts +5 -0
- package/dist/types/packages/config/index.d.ts +3 -0
- package/dist/types/packages/config/interfaces.d.ts +6 -0
- package/dist/types/packages/controller/constants.d.ts +2 -0
- package/dist/types/packages/controller/index.d.ts +591 -0
- package/dist/types/packages/controller/interfaces.d.ts +13 -0
- package/dist/types/packages/controller/utils/find-many.d.ts +6 -0
- package/dist/types/packages/controller/utils/find-one.d.ts +6 -0
- package/dist/types/packages/controller/utils/params-to-query.d.ts +16 -0
- package/dist/types/packages/controller/utils/resolve-relationships.d.ts +5 -0
- package/dist/types/packages/database/attribute/index.d.ts +6 -0
- package/dist/types/packages/database/attribute/interfaces.d.ts +6 -0
- package/dist/types/packages/database/attribute/utils/create-attribute.d.ts +5 -0
- package/dist/types/packages/database/attribute/utils/create-getter.d.ts +3 -0
- package/dist/types/packages/database/attribute/utils/create-normalizer.d.ts +1 -0
- package/dist/types/packages/database/attribute/utils/create-setter.d.ts +8 -0
- package/dist/types/packages/database/change-set/index.d.ts +10 -0
- package/dist/types/packages/database/constants.d.ts +3 -0
- package/dist/types/packages/database/errors/config-missing-error.d.ts +4 -0
- package/dist/types/packages/database/errors/index.d.ts +5 -0
- package/dist/types/packages/database/errors/invalid-driver-error.d.ts +7 -0
- package/dist/types/packages/database/errors/migrations-pending-error.d.ts +7 -0
- package/dist/types/packages/database/errors/model-missing-error.d.ts +7 -0
- package/dist/types/packages/database/errors/unique-constraint-error.d.ts +4 -0
- package/dist/types/packages/database/index.d.ts +26 -0
- package/dist/types/packages/database/initialize.d.ts +6 -0
- package/dist/types/packages/database/interfaces.d.ts +85 -0
- package/dist/types/packages/database/migration/index.d.ts +12 -0
- package/dist/types/packages/database/migration/interfaces.d.ts +4 -0
- package/dist/types/packages/database/migration/utils/generate-timestamp.d.ts +2 -0
- package/dist/types/packages/database/model/index.d.ts +1046 -0
- package/dist/types/packages/database/model/initialize-class.d.ts +10 -0
- package/dist/types/packages/database/model/interfaces.d.ts +14 -0
- package/dist/types/packages/database/model/utils/get-columns.d.ts +5 -0
- package/dist/types/packages/database/model/utils/persistence.d.ts +18 -0
- package/dist/types/packages/database/model/utils/process-write-error.d.ts +4 -0
- package/dist/types/packages/database/model/utils/run-hooks.d.ts +6 -0
- package/dist/types/packages/database/model/utils/validate.d.ts +5 -0
- package/dist/types/packages/database/query/errors/index.d.ts +1 -0
- package/dist/types/packages/database/query/errors/record-not-found-error.d.ts +6 -0
- package/dist/types/packages/database/query/index.d.ts +38 -0
- package/dist/types/packages/database/query/runner/constants.d.ts +2 -0
- package/dist/types/packages/database/query/runner/index.d.ts +9 -0
- package/dist/types/packages/database/query/runner/utils/build-results.d.ts +10 -0
- package/dist/types/packages/database/query/runner/utils/get-find-param.d.ts +2 -0
- package/dist/types/packages/database/query/utils/format-select.d.ts +5 -0
- package/dist/types/packages/database/query/utils/scopes-for.d.ts +2 -0
- package/dist/types/packages/database/relationship/index.d.ts +11 -0
- package/dist/types/packages/database/relationship/interfaces.d.ts +12 -0
- package/dist/types/packages/database/relationship/utils/getters.d.ts +14 -0
- package/dist/types/packages/database/relationship/utils/inverse-setters.d.ts +15 -0
- package/dist/types/packages/database/relationship/utils/setters.d.ts +14 -0
- package/dist/types/packages/database/relationship/utils/unassociate.d.ts +5 -0
- package/dist/types/packages/database/relationship/utils/update-relationship.d.ts +5 -0
- package/dist/types/packages/database/relationship/utils/validate-type.d.ts +2 -0
- package/dist/types/packages/database/transaction/index.d.ts +16 -0
- package/dist/types/packages/database/transaction/interfaces.d.ts +5 -0
- package/dist/types/packages/database/utils/connect.d.ts +6 -0
- package/dist/types/packages/database/utils/create-migrations.d.ts +5 -0
- package/dist/types/packages/database/utils/normalize-model-name.d.ts +5 -0
- package/dist/types/packages/database/utils/pending-migrations.d.ts +4 -0
- package/dist/types/packages/database/utils/type-for-column.d.ts +5 -0
- package/dist/types/packages/database/validation/errors/index.d.ts +1 -0
- package/dist/types/packages/database/validation/errors/validation-error.d.ts +7 -0
- package/dist/types/packages/database/validation/index.d.ts +13 -0
- package/dist/types/packages/database/validation/interfaces.d.ts +5 -0
- package/dist/types/packages/freezeable/constants.d.ts +1 -0
- package/dist/types/packages/freezeable/index.d.ts +3 -0
- package/dist/types/packages/freezeable/map/index.d.ts +11 -0
- package/dist/types/packages/freezeable/set/index.d.ts +11 -0
- package/dist/types/packages/freezeable/utils/freeze.d.ts +20 -0
- package/dist/types/packages/freezeable/utils/is-frozen.d.ts +4 -0
- package/dist/types/packages/fs/index.d.ts +52 -0
- package/dist/types/packages/fs/interfaces.d.ts +19 -0
- package/dist/types/packages/fs/utils/create-path-remover.d.ts +5 -0
- package/dist/types/packages/fs/utils/create-resolver.d.ts +4 -0
- package/dist/types/packages/fs/utils/exists.d.ts +4 -0
- package/dist/types/packages/fs/utils/is-js-file.d.ts +4 -0
- package/dist/types/packages/fs/utils/parse-path.d.ts +5 -0
- package/dist/types/packages/fs/utils/rmrf.d.ts +5 -0
- package/dist/types/packages/fs/watcher/index.d.ts +13 -0
- package/dist/types/packages/fs/watcher/initialize.d.ts +5 -0
- package/dist/types/packages/fs/watcher/interfaces.d.ts +3 -0
- package/dist/types/packages/jsonapi/constants.d.ts +2 -0
- package/dist/types/packages/jsonapi/errors/index.d.ts +3 -0
- package/dist/types/packages/jsonapi/errors/invalid-content-type-error.d.ts +8 -0
- package/dist/types/packages/jsonapi/errors/not-acceptable-error.d.ts +8 -0
- package/dist/types/packages/jsonapi/errors/unsupported-media-type-error.d.ts +8 -0
- package/dist/types/packages/jsonapi/index.d.ts +5 -0
- package/dist/types/packages/jsonapi/interfaces.d.ts +66 -0
- package/dist/types/packages/jsonapi/utils/has-media-type.d.ts +4 -0
- package/dist/types/packages/jsonapi/utils/is-jsonapi.d.ts +4 -0
- package/dist/types/packages/loader/builder/index.d.ts +6 -0
- package/dist/types/packages/loader/builder/interfaces.d.ts +10 -0
- package/dist/types/packages/loader/builder/utils/create-children-builder.d.ts +2 -0
- package/dist/types/packages/loader/builder/utils/create-parent-builder.d.ts +2 -0
- package/dist/types/packages/loader/builder/utils/sort-by-namespace.d.ts +5 -0
- package/dist/types/packages/loader/index.d.ts +8 -0
- package/dist/types/packages/loader/interfaces.d.ts +4 -0
- package/dist/types/packages/loader/resolver/index.d.ts +7 -0
- package/dist/types/packages/loader/resolver/utils/closest-ancestor.d.ts +2 -0
- package/dist/types/packages/loader/resolver/utils/closest-child.d.ts +2 -0
- package/dist/types/packages/loader/utils/bundle-for.d.ts +5 -0
- package/dist/types/packages/loader/utils/format-key.d.ts +4 -0
- package/dist/types/packages/logger/constants.d.ts +8 -0
- package/dist/types/packages/logger/index.d.ts +182 -0
- package/dist/types/packages/logger/interfaces.d.ts +17 -0
- package/dist/types/packages/logger/request-logger/index.d.ts +6 -0
- package/dist/types/packages/logger/request-logger/interfaces.d.ts +25 -0
- package/dist/types/packages/logger/request-logger/templates.d.ts +9 -0
- package/dist/types/packages/logger/request-logger/utils/filter-params.d.ts +4 -0
- package/dist/types/packages/logger/request-logger/utils/log-json.d.ts +10 -0
- package/dist/types/packages/logger/request-logger/utils/log-text.d.ts +10 -0
- package/dist/types/packages/logger/utils/line.d.ts +4 -0
- package/dist/types/packages/logger/utils/sql.d.ts +4 -0
- package/dist/types/packages/logger/writer/constants.d.ts +3 -0
- package/dist/types/packages/logger/writer/index.d.ts +6 -0
- package/dist/types/packages/logger/writer/interfaces.d.ts +2 -0
- package/dist/types/packages/logger/writer/utils/format-message.d.ts +9 -0
- package/dist/types/packages/lumenify/index.d.ts +11 -0
- package/dist/types/packages/lumenify/utils/create-response-proxy.d.ts +8 -0
- package/dist/types/packages/pm/cluster/index.d.ts +21 -0
- package/dist/types/packages/pm/cluster/interfaces.d.ts +7 -0
- package/dist/types/packages/pm/index.d.ts +6 -0
- package/dist/types/packages/router/definitions/context/index.d.ts +11 -0
- package/dist/types/packages/router/definitions/context/utils/create-definition-group.d.ts +7 -0
- package/dist/types/packages/router/definitions/context/utils/create-definition.d.ts +10 -0
- package/dist/types/packages/router/definitions/context/utils/normalize-resource-args.d.ts +12 -0
- package/dist/types/packages/router/definitions/index.d.ts +10 -0
- package/dist/types/packages/router/definitions/interfaces.d.ts +7 -0
- package/dist/types/packages/router/index.d.ts +18 -0
- package/dist/types/packages/router/interfaces.d.ts +18 -0
- package/dist/types/packages/router/namespace/index.d.ts +20 -0
- package/dist/types/packages/router/namespace/interfaces.d.ts +9 -0
- package/dist/types/packages/router/namespace/utils/normalize-name.d.ts +4 -0
- package/dist/types/packages/router/namespace/utils/normalize-path.d.ts +4 -0
- package/dist/types/packages/router/resource/index.d.ts +13 -0
- package/dist/types/packages/router/resource/interfaces.d.ts +5 -0
- package/dist/types/packages/router/resource/utils/normalize-only.d.ts +5 -0
- package/dist/types/packages/router/route/action/constants.d.ts +1 -0
- package/dist/types/packages/router/route/action/enhancers/resource.d.ts +5 -0
- package/dist/types/packages/router/route/action/enhancers/track-perf.d.ts +5 -0
- package/dist/types/packages/router/route/action/index.d.ts +9 -0
- package/dist/types/packages/router/route/action/interfaces.d.ts +2 -0
- package/dist/types/packages/router/route/action/utils/create-page-links.d.ts +12 -0
- package/dist/types/packages/router/route/action/utils/get-action-name.d.ts +5 -0
- package/dist/types/packages/router/route/action/utils/get-controller-name.d.ts +5 -0
- package/dist/types/packages/router/route/constants.d.ts +1 -0
- package/dist/types/packages/router/route/index.d.ts +28 -0
- package/dist/types/packages/router/route/interfaces.d.ts +10 -0
- package/dist/types/packages/router/route/params/errors/index.d.ts +5 -0
- package/dist/types/packages/router/route/params/errors/invalid-parameter-error.d.ts +8 -0
- package/dist/types/packages/router/route/params/errors/parameter-not-nullable-error.d.ts +9 -0
- package/dist/types/packages/router/route/params/errors/parameter-required-error.d.ts +8 -0
- package/dist/types/packages/router/route/params/errors/parameter-type-error.d.ts +9 -0
- package/dist/types/packages/router/route/params/errors/parameter-value-error.d.ts +9 -0
- package/dist/types/packages/router/route/params/errors/resource-mismatch-error.d.ts +8 -0
- package/dist/types/packages/router/route/params/index.d.ts +18 -0
- package/dist/types/packages/router/route/params/interfaces.d.ts +25 -0
- package/dist/types/packages/router/route/params/parameter/index.d.ts +14 -0
- package/dist/types/packages/router/route/params/parameter/interfaces.d.ts +4 -0
- package/dist/types/packages/router/route/params/parameter/utils/validate-value.d.ts +5 -0
- package/dist/types/packages/router/route/params/parameter-group/index.d.ts +14 -0
- package/dist/types/packages/router/route/params/parameter-group/utils/has-required-params.d.ts +5 -0
- package/dist/types/packages/router/route/params/utils/get-data-params.d.ts +6 -0
- package/dist/types/packages/router/route/params/utils/get-default-collection-params.d.ts +6 -0
- package/dist/types/packages/router/route/params/utils/get-default-member-params.d.ts +5 -0
- package/dist/types/packages/router/route/params/utils/get-query-params.d.ts +14 -0
- package/dist/types/packages/router/route/params/utils/get-url-params.d.ts +5 -0
- package/dist/types/packages/router/route/params/utils/validate-resource-id.d.ts +5 -0
- package/dist/types/packages/router/route/params/utils/validate-type.d.ts +5 -0
- package/dist/types/packages/router/route/utils/get-dynamic-segments.d.ts +4 -0
- package/dist/types/packages/router/route/utils/get-static-path.d.ts +4 -0
- package/dist/types/packages/router/utils/create-replacer.d.ts +5 -0
- package/dist/types/packages/serializer/index.d.ts +521 -0
- package/dist/types/packages/serializer/interfaces.d.ts +7 -0
- package/dist/types/packages/server/constants.d.ts +2 -0
- package/dist/types/packages/server/index.d.ts +27 -0
- package/dist/types/packages/server/interfaces.d.ts +18 -0
- package/dist/types/packages/server/request/constants.d.ts +2 -0
- package/dist/types/packages/server/request/index.d.ts +8 -0
- package/dist/types/packages/server/request/interfaces.d.ts +63 -0
- package/dist/types/packages/server/request/parser/constants.d.ts +6 -0
- package/dist/types/packages/server/request/parser/errors/index.d.ts +1 -0
- package/dist/types/packages/server/request/parser/errors/malformed-request-error.d.ts +8 -0
- package/dist/types/packages/server/request/parser/index.d.ts +5 -0
- package/dist/types/packages/server/request/parser/utils/format.d.ts +17 -0
- package/dist/types/packages/server/request/parser/utils/parse-nested-object.d.ts +4 -0
- package/dist/types/packages/server/request/parser/utils/parse-read.d.ts +5 -0
- package/dist/types/packages/server/request/parser/utils/parse-write.d.ts +5 -0
- package/dist/types/packages/server/request/utils/get-domain.d.ts +5 -0
- package/dist/types/packages/server/responder/index.d.ts +5 -0
- package/dist/types/packages/server/responder/utils/data-for.d.ts +5 -0
- package/dist/types/packages/server/responder/utils/has-content-type.d.ts +2 -0
- package/dist/types/packages/server/responder/utils/normalize.d.ts +7 -0
- package/dist/types/packages/server/response/index.d.ts +5 -0
- package/dist/types/packages/server/response/interfaces.d.ts +22 -0
- package/dist/types/packages/server/utils/create-server-error.d.ts +7 -0
- package/dist/types/packages/server/utils/set-cors-headers.d.ts +3 -0
- package/dist/types/packages/server/utils/validate-accept.d.ts +4 -0
- package/dist/types/packages/server/utils/validate-content-type.d.ts +4 -0
- package/dist/types/packages/template/index.d.ts +8 -0
- package/dist/types/packages/template/utils/insert-values.d.ts +4 -0
- package/dist/types/utils/chain.d.ts +5 -0
- package/dist/types/utils/compact.d.ts +11 -0
- package/dist/types/utils/compose.d.ts +19 -0
- package/dist/types/utils/create-query-string.d.ts +6 -0
- package/dist/types/utils/diff.d.ts +4 -0
- package/dist/types/utils/entries.d.ts +4 -0
- package/dist/types/utils/env.d.ts +3 -0
- package/dist/types/utils/exec.d.ts +5 -0
- package/dist/types/utils/github.d.ts +9 -0
- package/dist/types/utils/has-own-property.d.ts +1 -0
- package/dist/types/utils/insert.d.ts +4 -0
- package/dist/types/utils/is-buffer.d.ts +4 -0
- package/dist/types/utils/is-null.d.ts +4 -0
- package/dist/types/utils/is-object.d.ts +17 -0
- package/dist/types/utils/is-undefined.d.ts +4 -0
- package/dist/types/utils/k.d.ts +10 -0
- package/dist/types/utils/map-to-object.d.ts +1 -0
- package/dist/types/utils/merge.d.ts +4 -0
- package/dist/types/utils/omit.d.ts +9 -0
- package/dist/types/utils/pick.d.ts +11 -0
- package/dist/types/utils/present.d.ts +4 -0
- package/dist/types/utils/promise-hash.d.ts +9 -0
- package/dist/types/utils/proxy.d.ts +6 -0
- package/dist/types/utils/range.d.ts +4 -0
- package/dist/types/utils/set-type.d.ts +11 -0
- package/dist/types/utils/sleep.d.ts +4 -0
- package/dist/types/utils/stringify.d.ts +4 -0
- package/dist/types/utils/transform-keys.d.ts +29 -0
- package/dist/types/utils/try-catch.d.ts +55 -0
- package/dist/types/utils/underscore.d.ts +4 -0
- package/dist/types/utils/uniq.d.ts +4 -0
- package/package.json +87 -0
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,3002 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/packages/cli/commands/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
build: () => build2,
|
|
34
|
+
create: () => create2,
|
|
35
|
+
dbcreate: () => dbcreate,
|
|
36
|
+
dbdrop: () => dbdrop,
|
|
37
|
+
dbmigrate: () => dbmigrate,
|
|
38
|
+
dbrollback: () => dbrollback,
|
|
39
|
+
dbseed: () => dbseed,
|
|
40
|
+
destroy: () => destroy2,
|
|
41
|
+
generate: () => generate,
|
|
42
|
+
repl: () => repl,
|
|
43
|
+
serve: () => serve,
|
|
44
|
+
test: () => test
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(index_exports);
|
|
47
|
+
|
|
48
|
+
// src/packages/cli/commands/build.ts
|
|
49
|
+
var import_ora = __toESM(require("ora"));
|
|
50
|
+
|
|
51
|
+
// src/constants.ts
|
|
52
|
+
var import_os = require("os");
|
|
53
|
+
var { env: ENV } = process;
|
|
54
|
+
var CWD = process.cwd();
|
|
55
|
+
var PID = process.pid;
|
|
56
|
+
var PORT = parseInt(ENV.PORT, 10) || 4e3;
|
|
57
|
+
var NODE_ENV = ENV.NODE_ENV || "development";
|
|
58
|
+
var DATABASE_URL = ENV.DATABASE_URL;
|
|
59
|
+
var LUMEN_CONSOLE = ENV.LUMEN_CONSOLE || false;
|
|
60
|
+
var PLATFORM = (0, import_os.platform)();
|
|
61
|
+
|
|
62
|
+
// src/packages/compiler/index.ts
|
|
63
|
+
var import_path9 = __toESM(require("path"));
|
|
64
|
+
var esbuild = __toESM(require("esbuild"));
|
|
65
|
+
|
|
66
|
+
// src/packages/fs/index.ts
|
|
67
|
+
var import_fs2 = __toESM(require("fs"));
|
|
68
|
+
var import_path5 = require("path");
|
|
69
|
+
|
|
70
|
+
// src/packages/fs/watcher/index.ts
|
|
71
|
+
var import_events = __toESM(require("events"));
|
|
72
|
+
var import_fb_watchman2 = require("fb-watchman");
|
|
73
|
+
|
|
74
|
+
// src/packages/fs/watcher/initialize.ts
|
|
75
|
+
var import_path2 = require("path");
|
|
76
|
+
var import_fs = require("fs");
|
|
77
|
+
var import_fb_watchman = require("fb-watchman");
|
|
78
|
+
|
|
79
|
+
// src/utils/exec.ts
|
|
80
|
+
var import_child_process = require("child_process");
|
|
81
|
+
function exec(cmd, opts) {
|
|
82
|
+
return new Promise((resolve2, reject) => {
|
|
83
|
+
(0, import_child_process.exec)(cmd, { ...opts, encoding: "utf8" }, (err, stdout, stderr) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
reject(err);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
resolve2([stdout, stderr]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/utils/k.ts
|
|
94
|
+
function K() {
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/utils/try-catch.ts
|
|
99
|
+
async function tryCatch(fn, rescue = K) {
|
|
100
|
+
let result;
|
|
101
|
+
try {
|
|
102
|
+
result = await fn();
|
|
103
|
+
} catch (err) {
|
|
104
|
+
result = await rescue(err);
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/packages/fs/utils/is-js-file.ts
|
|
110
|
+
var import_path = require("path");
|
|
111
|
+
function isJSFile(target) {
|
|
112
|
+
return (0, import_path.extname)(target) === ".js";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/packages/freezeable/constants.ts
|
|
116
|
+
var FREEZER = /* @__PURE__ */ new WeakSet();
|
|
117
|
+
|
|
118
|
+
// src/utils/is-object.ts
|
|
119
|
+
function isObject(value) {
|
|
120
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/packages/freezeable/utils/freeze.ts
|
|
124
|
+
function freeze(value) {
|
|
125
|
+
FREEZER.add(value);
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
function freezeProps(target, makePublic, ...props) {
|
|
129
|
+
Object.defineProperties(
|
|
130
|
+
target,
|
|
131
|
+
props.reduce(
|
|
132
|
+
(obj, key) => ({
|
|
133
|
+
...obj,
|
|
134
|
+
[key]: {
|
|
135
|
+
value: Reflect.get(target, key),
|
|
136
|
+
writable: false,
|
|
137
|
+
enumerable: makePublic,
|
|
138
|
+
configurable: false
|
|
139
|
+
}
|
|
140
|
+
}),
|
|
141
|
+
{}
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
return target;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/packages/freezeable/utils/is-frozen.ts
|
|
148
|
+
function isFrozen(value) {
|
|
149
|
+
return FREEZER.has(value);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/packages/freezeable/map/index.ts
|
|
153
|
+
var FreezeableMap = class extends Map {
|
|
154
|
+
set(key, value) {
|
|
155
|
+
if (!this.isFrozen()) {
|
|
156
|
+
super.set(key, value);
|
|
157
|
+
}
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
clear() {
|
|
161
|
+
if (!this.isFrozen()) {
|
|
162
|
+
super.clear();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
delete(key) {
|
|
166
|
+
return this.isFrozen() ? false : super.delete(key);
|
|
167
|
+
}
|
|
168
|
+
freeze(deep) {
|
|
169
|
+
if (deep) {
|
|
170
|
+
this.forEach(Object.freeze);
|
|
171
|
+
}
|
|
172
|
+
return freeze(this);
|
|
173
|
+
}
|
|
174
|
+
isFrozen() {
|
|
175
|
+
return isFrozen(this);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var map_default = FreezeableMap;
|
|
179
|
+
|
|
180
|
+
// src/packages/freezeable/set/index.ts
|
|
181
|
+
var FreezeableSet = class extends Set {
|
|
182
|
+
add(value) {
|
|
183
|
+
if (!this.isFrozen()) {
|
|
184
|
+
super.add(value);
|
|
185
|
+
}
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
clear() {
|
|
189
|
+
if (!this.isFrozen()) {
|
|
190
|
+
super.clear();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
delete(value) {
|
|
194
|
+
return this.isFrozen() ? false : super.delete(value);
|
|
195
|
+
}
|
|
196
|
+
freeze(deep) {
|
|
197
|
+
if (deep) {
|
|
198
|
+
this.forEach(Object.freeze);
|
|
199
|
+
}
|
|
200
|
+
return freeze(this);
|
|
201
|
+
}
|
|
202
|
+
isFrozen() {
|
|
203
|
+
return isFrozen(this);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var set_default = FreezeableSet;
|
|
207
|
+
|
|
208
|
+
// src/packages/fs/watcher/initialize.ts
|
|
209
|
+
var SUBSCRIPTION_NAME = "lumen-watcher";
|
|
210
|
+
function fallback(instance, path6) {
|
|
211
|
+
return (0, import_fs.watch)(
|
|
212
|
+
path6,
|
|
213
|
+
{
|
|
214
|
+
recursive: true
|
|
215
|
+
},
|
|
216
|
+
(type, name) => {
|
|
217
|
+
if (typeof name === "string" && isJSFile(name)) {
|
|
218
|
+
instance.emit("change", [{ name, type }]);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
function setupWatchmen(instance, path6) {
|
|
224
|
+
return new Promise((resolve2, reject) => {
|
|
225
|
+
const client = new import_fb_watchman.Client();
|
|
226
|
+
client.capabilityCheck({}, (capabilityErr) => {
|
|
227
|
+
if (capabilityErr) {
|
|
228
|
+
reject(capabilityErr);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
client.command(
|
|
232
|
+
["watch-project", path6],
|
|
233
|
+
(watchErr, { watch: watch2, relative_path: relativePath } = {}) => {
|
|
234
|
+
if (watchErr) {
|
|
235
|
+
reject(watchErr);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
client.command(["clock", watch2], (clockErr, { clock: since }) => {
|
|
239
|
+
if (clockErr) {
|
|
240
|
+
reject(clockErr);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
client.command(
|
|
244
|
+
[
|
|
245
|
+
"subscribe",
|
|
246
|
+
watch2,
|
|
247
|
+
SUBSCRIPTION_NAME,
|
|
248
|
+
{
|
|
249
|
+
since,
|
|
250
|
+
relative_root: relativePath,
|
|
251
|
+
fields: ["name", "size", "exists", "type"],
|
|
252
|
+
expression: ["allof", ["match", "*.js"]]
|
|
253
|
+
}
|
|
254
|
+
],
|
|
255
|
+
(subscribeErr) => {
|
|
256
|
+
if (subscribeErr) {
|
|
257
|
+
reject(subscribeErr);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
client.on("subscription", ({ files, subscription }) => {
|
|
261
|
+
if (subscription === SUBSCRIPTION_NAME) {
|
|
262
|
+
instance.emit("change", files);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
resolve2(client);
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
async function initialize(instance, path6, useWatchman) {
|
|
275
|
+
const appPath = (0, import_path2.join)(path6, "app");
|
|
276
|
+
let client;
|
|
277
|
+
if (useWatchman) {
|
|
278
|
+
await tryCatch(async () => {
|
|
279
|
+
await exec("which watchman");
|
|
280
|
+
client = await setupWatchmen(instance, appPath);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
Object.assign(instance, {
|
|
284
|
+
path: appPath,
|
|
285
|
+
client: client || fallback(instance, appPath)
|
|
286
|
+
});
|
|
287
|
+
freezeProps(instance, true, "path", "client");
|
|
288
|
+
return instance;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// src/packages/fs/watcher/index.ts
|
|
292
|
+
var Watcher = class extends import_events.default {
|
|
293
|
+
constructor(path6, useWatchman = true) {
|
|
294
|
+
super();
|
|
295
|
+
return initialize(this, path6, useWatchman);
|
|
296
|
+
}
|
|
297
|
+
destroy() {
|
|
298
|
+
const { client } = this;
|
|
299
|
+
if (client instanceof import_fb_watchman2.Client) {
|
|
300
|
+
client.end();
|
|
301
|
+
} else {
|
|
302
|
+
client.close();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
var watcher_default = Watcher;
|
|
307
|
+
|
|
308
|
+
// src/packages/fs/utils/create-resolver.ts
|
|
309
|
+
function createResolver(resolve2, reject) {
|
|
310
|
+
return function fsResolver(err, ...args) {
|
|
311
|
+
const [data] = args;
|
|
312
|
+
if (err) {
|
|
313
|
+
reject(err);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
resolve2(args.length > 1 ? args : data);
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/packages/fs/utils/create-path-remover.ts
|
|
321
|
+
function createPathRemover(path6) {
|
|
322
|
+
let pattern = new RegExp(`${path6}(/)?(.+)`);
|
|
323
|
+
if (PLATFORM.startsWith("win")) {
|
|
324
|
+
const sep2 = "\\\\";
|
|
325
|
+
pattern = new RegExp(`${path6.replace(/\\/g, sep2)}(${sep2})?(.+)`);
|
|
326
|
+
}
|
|
327
|
+
return (source) => source.replace(pattern, "$2");
|
|
328
|
+
}
|
|
329
|
+
var create_path_remover_default = createPathRemover;
|
|
330
|
+
|
|
331
|
+
// src/packages/fs/utils/rmrf.ts
|
|
332
|
+
var import_path3 = __toESM(require("path"));
|
|
333
|
+
function rmrf(target) {
|
|
334
|
+
return stat(target).then((stats) => {
|
|
335
|
+
if (stats && stats.isDirectory()) {
|
|
336
|
+
return readdir(target);
|
|
337
|
+
} else if (stats && stats.isFile()) {
|
|
338
|
+
return unlink(target).then(() => []);
|
|
339
|
+
}
|
|
340
|
+
return [];
|
|
341
|
+
}).then(
|
|
342
|
+
(files) => Promise.all(files.map((file) => rmrf(import_path3.default.join(target, file))))
|
|
343
|
+
).then(() => rmdir(target)).catch((err) => {
|
|
344
|
+
if (err.code === "ENOENT") {
|
|
345
|
+
return Promise.resolve();
|
|
346
|
+
}
|
|
347
|
+
return Promise.reject(err);
|
|
348
|
+
}).then(() => true);
|
|
349
|
+
}
|
|
350
|
+
var rmrf_default = rmrf;
|
|
351
|
+
|
|
352
|
+
// src/packages/fs/utils/exists.ts
|
|
353
|
+
async function exists(path6, dir) {
|
|
354
|
+
if (path6 instanceof RegExp) {
|
|
355
|
+
const pattern = path6;
|
|
356
|
+
let files = [];
|
|
357
|
+
if (dir) {
|
|
358
|
+
files = await readdir(dir);
|
|
359
|
+
}
|
|
360
|
+
return files.some((file) => pattern.test(file));
|
|
361
|
+
}
|
|
362
|
+
return stat(path6).then(
|
|
363
|
+
() => true,
|
|
364
|
+
() => false
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/packages/fs/utils/parse-path.ts
|
|
369
|
+
var import_path4 = __toESM(require("path"));
|
|
370
|
+
|
|
371
|
+
// src/utils/chain.ts
|
|
372
|
+
function chain(source) {
|
|
373
|
+
return {
|
|
374
|
+
pipe(handler) {
|
|
375
|
+
return chain(handler(source));
|
|
376
|
+
},
|
|
377
|
+
value() {
|
|
378
|
+
return source;
|
|
379
|
+
},
|
|
380
|
+
construct(constructor) {
|
|
381
|
+
return chain(Reflect.construct(constructor, [source]));
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/packages/fs/utils/parse-path.ts
|
|
387
|
+
function resolvePath(cwd = CWD, dir = "", name = "") {
|
|
388
|
+
return chain(name.split("/")).pipe((parts) => import_path4.default.join(cwd, dir, ...parts)).pipe(import_path4.default.parse).pipe(({ base, ...etc }) => ({
|
|
389
|
+
base,
|
|
390
|
+
...etc,
|
|
391
|
+
relative: import_path4.default.join(etc.dir.substr(etc.dir.indexOf(dir)), base),
|
|
392
|
+
absolute: import_path4.default.join(etc.dir, base)
|
|
393
|
+
})).value();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/packages/fs/index.ts
|
|
397
|
+
function watch(path6) {
|
|
398
|
+
return new watcher_default(path6);
|
|
399
|
+
}
|
|
400
|
+
function stat(path6) {
|
|
401
|
+
return new Promise((resolve2, reject) => {
|
|
402
|
+
import_fs2.default.stat(path6, createResolver(resolve2, reject));
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function mkdir(path6, mode = 511) {
|
|
406
|
+
return new Promise((resolve2, reject) => {
|
|
407
|
+
import_fs2.default.mkdir(path6, mode, createResolver(resolve2, reject));
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
function mkdirRec(path6, mode = 511) {
|
|
411
|
+
const parent = (0, import_path5.resolve)(path6, "..");
|
|
412
|
+
return stat(parent).catch((err) => {
|
|
413
|
+
if (err.code === "ENOENT") {
|
|
414
|
+
return mkdirRec(parent, mode);
|
|
415
|
+
}
|
|
416
|
+
return Promise.reject(err);
|
|
417
|
+
}).then(() => mkdir(path6, mode)).catch((err) => {
|
|
418
|
+
if (err.code !== "EEXIST") {
|
|
419
|
+
return Promise.reject(err);
|
|
420
|
+
}
|
|
421
|
+
return Promise.resolve();
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
function rmdir(path6) {
|
|
425
|
+
return new Promise((resolve2, reject) => {
|
|
426
|
+
import_fs2.default.rmdir(path6, createResolver(resolve2, reject));
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
function readdir(path6, opts) {
|
|
430
|
+
return new Promise((resolve2, reject) => {
|
|
431
|
+
import_fs2.default.readdir(path6, createResolver(resolve2, reject));
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
function readdirRec(path6, opts) {
|
|
435
|
+
const stripPath = create_path_remover_default(path6);
|
|
436
|
+
return readdir(path6, opts).then(
|
|
437
|
+
(files) => Promise.all(
|
|
438
|
+
files.map((file) => {
|
|
439
|
+
const filePath = (0, import_path5.join)(path6, file);
|
|
440
|
+
return Promise.all([filePath, stat(filePath)]);
|
|
441
|
+
})
|
|
442
|
+
)
|
|
443
|
+
).then(
|
|
444
|
+
(files) => Promise.all(
|
|
445
|
+
files.map(
|
|
446
|
+
([file, stats]) => Promise.all([file, stats.isDirectory() ? readdirRec(file) : []])
|
|
447
|
+
)
|
|
448
|
+
)
|
|
449
|
+
).then(
|
|
450
|
+
(files) => files.reduce((arr, [file, children]) => {
|
|
451
|
+
const basename3 = stripPath(file);
|
|
452
|
+
return [
|
|
453
|
+
...arr,
|
|
454
|
+
basename3,
|
|
455
|
+
...children.map((child) => (0, import_path5.join)(basename3, stripPath(child)))
|
|
456
|
+
];
|
|
457
|
+
}, [])
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
function readFile(path6, opts) {
|
|
461
|
+
return new Promise((resolve2, reject) => {
|
|
462
|
+
import_fs2.default.readFile(
|
|
463
|
+
path6,
|
|
464
|
+
typeof opts === "object" ? opts : {},
|
|
465
|
+
createResolver(resolve2, reject)
|
|
466
|
+
);
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
function writeFile(path6, data, opts) {
|
|
470
|
+
return new Promise((resolve2, reject) => {
|
|
471
|
+
import_fs2.default.writeFile(
|
|
472
|
+
path6,
|
|
473
|
+
data,
|
|
474
|
+
opts || {},
|
|
475
|
+
createResolver(resolve2, reject)
|
|
476
|
+
);
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
function appendFile(path6, data, opts) {
|
|
480
|
+
return new Promise((resolve2, reject) => {
|
|
481
|
+
import_fs2.default.appendFile(
|
|
482
|
+
path6,
|
|
483
|
+
data,
|
|
484
|
+
typeof opts === "object" ? opts : {},
|
|
485
|
+
createResolver(resolve2, reject)
|
|
486
|
+
);
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
function unlink(path6) {
|
|
490
|
+
return new Promise((resolve2, reject) => {
|
|
491
|
+
import_fs2.default.unlink(path6, createResolver(resolve2, reject));
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// src/packages/compiler/utils/create-manifest.ts
|
|
496
|
+
var import_path7 = require("path");
|
|
497
|
+
var import_inflection3 = require("inflection");
|
|
498
|
+
|
|
499
|
+
// src/utils/underscore.ts
|
|
500
|
+
var import_inflection = require("inflection");
|
|
501
|
+
function underscore(source = "", upper = false) {
|
|
502
|
+
return (0, import_inflection.underscore)(source, upper).replace(/-/g, "_");
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/utils/compose.ts
|
|
506
|
+
function compose(main, ...etc) {
|
|
507
|
+
return (input) => main(etc.reduceRight((value, fn) => fn(value), input));
|
|
508
|
+
}
|
|
509
|
+
function composeAsync(main, ...etc) {
|
|
510
|
+
return (input) => etc.reduceRight(
|
|
511
|
+
(value, fn) => Promise.resolve(value).then(fn),
|
|
512
|
+
Promise.resolve(input)
|
|
513
|
+
).then(main);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// src/packages/compiler/utils/format-name.ts
|
|
517
|
+
var import_path6 = require("path");
|
|
518
|
+
var import_inflection2 = require("inflection");
|
|
519
|
+
var DOUBLE_COLON = /::/g;
|
|
520
|
+
var formatName = compose(
|
|
521
|
+
(name) => name.replace(DOUBLE_COLON, "$"),
|
|
522
|
+
import_inflection2.camelize,
|
|
523
|
+
underscore,
|
|
524
|
+
(name) => import_path6.posix.join((0, import_path6.dirname)(name), (0, import_path6.basename)(name, ".js"))
|
|
525
|
+
);
|
|
526
|
+
var format_name_default = formatName;
|
|
527
|
+
|
|
528
|
+
// src/packages/compiler/utils/create-manifest.ts
|
|
529
|
+
function createExportStatement(name, path6, isDefault = true) {
|
|
530
|
+
const normalized = import_path7.posix.join(...path6.split(import_path7.sep));
|
|
531
|
+
if (isDefault) {
|
|
532
|
+
return `export {
|
|
533
|
+
default as ${name}
|
|
534
|
+
} from '../${normalized}';
|
|
535
|
+
|
|
536
|
+
`;
|
|
537
|
+
}
|
|
538
|
+
return `export {
|
|
539
|
+
${name}
|
|
540
|
+
} from '../${normalized}';
|
|
541
|
+
|
|
542
|
+
`;
|
|
543
|
+
}
|
|
544
|
+
function createWriter(file) {
|
|
545
|
+
const writerFor = (type, handleWrite) => (value) => {
|
|
546
|
+
const formatSymbol = compose(
|
|
547
|
+
(str) => str + (0, import_inflection3.capitalize)(type),
|
|
548
|
+
format_name_default
|
|
549
|
+
);
|
|
550
|
+
return Promise.all(
|
|
551
|
+
value.map((item) => {
|
|
552
|
+
if (handleWrite) {
|
|
553
|
+
return handleWrite(item);
|
|
554
|
+
}
|
|
555
|
+
const path6 = (0, import_path7.join)("app", (0, import_inflection3.pluralize)(type), item);
|
|
556
|
+
const symbol = formatSymbol(item);
|
|
557
|
+
return appendFile(file, createExportStatement(symbol, path6));
|
|
558
|
+
})
|
|
559
|
+
);
|
|
560
|
+
};
|
|
561
|
+
return {
|
|
562
|
+
controllers: writerFor("controller"),
|
|
563
|
+
serializers: writerFor("serializer"),
|
|
564
|
+
models: writerFor("model", async (item) => {
|
|
565
|
+
const path6 = (0, import_path7.join)("app", "models", item);
|
|
566
|
+
const name = format_name_default(item);
|
|
567
|
+
return appendFile(file, createExportStatement(name, path6));
|
|
568
|
+
}),
|
|
569
|
+
migrations: writerFor("migration", async (item) => {
|
|
570
|
+
const path6 = (0, import_path7.join)("db", "migrate", item);
|
|
571
|
+
const name = chain(item).pipe((str) => (0, import_path7.basename)(str, ".js")).pipe(underscore).pipe((str) => str.substr(17)).pipe((str) => (0, import_inflection3.camelize)(str, true)).value();
|
|
572
|
+
await appendFile(
|
|
573
|
+
file,
|
|
574
|
+
createExportStatement(`up as ${name}Up`, path6, false)
|
|
575
|
+
);
|
|
576
|
+
await appendFile(
|
|
577
|
+
file,
|
|
578
|
+
createExportStatement(`down as ${name}Down`, path6, false)
|
|
579
|
+
);
|
|
580
|
+
})
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
async function createManifest(dir, assets, { useStrict }) {
|
|
584
|
+
const dist = (0, import_path7.join)(dir, "dist");
|
|
585
|
+
const file = (0, import_path7.join)(dist, "index.js");
|
|
586
|
+
const writer = createWriter(file);
|
|
587
|
+
await tryCatch(() => mkdir(dist));
|
|
588
|
+
await writeFile(file, useStrict ? "'use strict';\n\n" : "");
|
|
589
|
+
await Promise.all(
|
|
590
|
+
Array.from(assets).map(([key, value]) => {
|
|
591
|
+
const write = Reflect.get(writer, key);
|
|
592
|
+
if (write) {
|
|
593
|
+
return write(value);
|
|
594
|
+
} else if (!write && typeof value === "string") {
|
|
595
|
+
return appendFile(file, createExportStatement(key, value));
|
|
596
|
+
}
|
|
597
|
+
return Promise.resolve();
|
|
598
|
+
})
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// src/packages/compiler/utils/create-boot-script.ts
|
|
603
|
+
var import_path8 = __toESM(require("path"));
|
|
604
|
+
|
|
605
|
+
// src/packages/template/utils/insert-values.ts
|
|
606
|
+
function insertValues(strings, ...values) {
|
|
607
|
+
if (values.length) {
|
|
608
|
+
return strings.reduce((result, part, idx) => {
|
|
609
|
+
const raw = values[idx];
|
|
610
|
+
let value = "";
|
|
611
|
+
if (raw && typeof raw.toString === "function") {
|
|
612
|
+
value = raw.toString();
|
|
613
|
+
}
|
|
614
|
+
return result + part + value;
|
|
615
|
+
}, "");
|
|
616
|
+
}
|
|
617
|
+
return strings.join("");
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// src/packages/template/index.ts
|
|
621
|
+
var bodyPattern = /^\n([\s\S]+)\s{2}$/gm;
|
|
622
|
+
var trailingWhitespace = /\s+$/;
|
|
623
|
+
function template(strings, ...values) {
|
|
624
|
+
const compiled = insertValues(strings, ...values);
|
|
625
|
+
let [body] = compiled.match(bodyPattern) || [];
|
|
626
|
+
let indentLevel = /^\s{0,4}(.+)$/g;
|
|
627
|
+
if (!body) {
|
|
628
|
+
body = compiled;
|
|
629
|
+
indentLevel = /^\s{0,2}(.+)$/g;
|
|
630
|
+
}
|
|
631
|
+
return body.split("\n").slice(1).map((line2) => {
|
|
632
|
+
let str = line2.replace(indentLevel, "$1");
|
|
633
|
+
if (trailingWhitespace.test(str)) {
|
|
634
|
+
str = str.replace(trailingWhitespace, "");
|
|
635
|
+
}
|
|
636
|
+
return str;
|
|
637
|
+
}).join("\n");
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// src/packages/compiler/utils/create-boot-script.ts
|
|
641
|
+
async function createBootScript(dir, {
|
|
642
|
+
useStrict
|
|
643
|
+
}) {
|
|
644
|
+
let data = template`
|
|
645
|
+
const CWD = process.cwd();
|
|
646
|
+
const { env: { PORT } } = process;
|
|
647
|
+
const { Application, config, database } = require('./bundle');
|
|
648
|
+
|
|
649
|
+
module.exports = new Application(
|
|
650
|
+
Object.assign(config, {
|
|
651
|
+
database,
|
|
652
|
+
path: CWD,
|
|
653
|
+
port: PORT
|
|
654
|
+
})
|
|
655
|
+
).catch(err => {
|
|
656
|
+
process.send({
|
|
657
|
+
error: err ? err.stack : void 0,
|
|
658
|
+
message: 'error'
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
`;
|
|
662
|
+
if (useStrict) {
|
|
663
|
+
data = `'use strict';
|
|
664
|
+
|
|
665
|
+
${data}`;
|
|
666
|
+
}
|
|
667
|
+
await writeFile(import_path8.default.join(dir, "dist", "boot.js"), data);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// src/packages/compiler/index.ts
|
|
671
|
+
async function compile(dir, env, opts = {}) {
|
|
672
|
+
const { useStrict = false } = opts;
|
|
673
|
+
const local = import_path9.default.join(__dirname, "index.mjs");
|
|
674
|
+
const entry = import_path9.default.join(dir, "dist", "index.js");
|
|
675
|
+
const assets = await Promise.all([
|
|
676
|
+
readdir(import_path9.default.join(dir, "app", "models")),
|
|
677
|
+
readdir(import_path9.default.join(dir, "db", "migrate")),
|
|
678
|
+
readdirRec(import_path9.default.join(dir, "app", "controllers")),
|
|
679
|
+
readdirRec(import_path9.default.join(dir, "app", "serializers"))
|
|
680
|
+
]).then((types) => {
|
|
681
|
+
let [models, migrations, controllers, serializers] = types;
|
|
682
|
+
models = models.filter(isJSFile);
|
|
683
|
+
migrations = migrations.filter(isJSFile);
|
|
684
|
+
controllers = controllers.filter(isJSFile);
|
|
685
|
+
serializers = serializers.filter(isJSFile);
|
|
686
|
+
return /* @__PURE__ */ new Map([
|
|
687
|
+
["Application", import_path9.default.join("app", "index.js")],
|
|
688
|
+
["config", import_path9.default.join("config", "environments", `${env}.js`)],
|
|
689
|
+
["controllers", controllers],
|
|
690
|
+
["database", import_path9.default.join("config", "database.js")],
|
|
691
|
+
["migrations", migrations],
|
|
692
|
+
["models", models],
|
|
693
|
+
["routes", import_path9.default.join("app", "routes.js")],
|
|
694
|
+
["seed", import_path9.default.join("db", "seed.js")],
|
|
695
|
+
["serializers", serializers]
|
|
696
|
+
]);
|
|
697
|
+
});
|
|
698
|
+
await Promise.all([
|
|
699
|
+
createManifest(dir, assets, { useStrict }),
|
|
700
|
+
createBootScript(dir, { useStrict })
|
|
701
|
+
]);
|
|
702
|
+
await esbuild.build({
|
|
703
|
+
entryPoints: [entry],
|
|
704
|
+
outfile: import_path9.default.join(dir, "dist", "bundle.js"),
|
|
705
|
+
bundle: true,
|
|
706
|
+
platform: "node",
|
|
707
|
+
format: "cjs",
|
|
708
|
+
target: "node20",
|
|
709
|
+
sourcemap: true,
|
|
710
|
+
// Reproduces `rollup-plugin-lumen`: preserves each class's `.name` (Lumen keys
|
|
711
|
+
// models/controllers/serializers off it) against esbuild's own renaming.
|
|
712
|
+
keepNames: true,
|
|
713
|
+
// Bare specifiers stay external (knex, inflection, the app's own deps);
|
|
714
|
+
// relative paths and the two aliases below are bundled in. This matches the
|
|
715
|
+
// old `is-external` split, with the framework itself pulled in via LUMEN_LOCAL.
|
|
716
|
+
packages: "external",
|
|
717
|
+
alias: {
|
|
718
|
+
// Apps import the framework as `import { Model } from 'LUMEN_LOCAL'`.
|
|
719
|
+
LUMEN_LOCAL: local,
|
|
720
|
+
// ...and their own tree as `app/...`.
|
|
721
|
+
app: import_path9.default.join(dir, "app")
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
await rmrf_default(entry);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// src/packages/cli/commands/build.ts
|
|
728
|
+
async function build2(useStrict = false) {
|
|
729
|
+
const spinner = new import_ora.default({
|
|
730
|
+
text: "Building your application...",
|
|
731
|
+
spinner: "dots"
|
|
732
|
+
});
|
|
733
|
+
spinner.start();
|
|
734
|
+
await compile(CWD, NODE_ENV, {
|
|
735
|
+
useStrict
|
|
736
|
+
});
|
|
737
|
+
spinner.stop();
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// src/packages/cli/commands/create.ts
|
|
741
|
+
var import_os3 = require("os");
|
|
742
|
+
var import_ora2 = __toESM(require("ora"));
|
|
743
|
+
var import_chalk10 = require("chalk");
|
|
744
|
+
|
|
745
|
+
// src/packages/cli/utils/driver-for.ts
|
|
746
|
+
var drivers = /* @__PURE__ */ new Map([
|
|
747
|
+
["postgres", "pg"],
|
|
748
|
+
["sqlite", "sqlite3"],
|
|
749
|
+
["mysql", "mysql2"]
|
|
750
|
+
]);
|
|
751
|
+
function driverFor(database = "sqlite") {
|
|
752
|
+
return drivers.get(database) || "sqlite3";
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// src/packages/cli/templates/application.ts
|
|
756
|
+
var import_inflection4 = require("inflection");
|
|
757
|
+
var application_default = (name) => {
|
|
758
|
+
const normalized = chain(name).pipe(underscore).pipe(import_inflection4.classify).value();
|
|
759
|
+
return template`
|
|
760
|
+
import { Application } from 'lumen-framework';
|
|
761
|
+
|
|
762
|
+
class ${normalized} extends Application {
|
|
763
|
+
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
export default ${normalized};
|
|
767
|
+
`;
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
// src/packages/cli/templates/config.ts
|
|
771
|
+
var config_default = (name, env) => {
|
|
772
|
+
const isTestENV = env === "test";
|
|
773
|
+
const isProdENV = env === "production";
|
|
774
|
+
return template`
|
|
775
|
+
export default {
|
|
776
|
+
logging: {
|
|
777
|
+
level: ${isProdENV ? "'INFO'" : "'DEBUG'"},
|
|
778
|
+
format: ${isProdENV ? "'json'" : "'text'"},
|
|
779
|
+
enabled: ${(!isTestENV).toString()},
|
|
780
|
+
|
|
781
|
+
filter: {
|
|
782
|
+
params: []
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
`;
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
// src/packages/cli/templates/routes.ts
|
|
790
|
+
var routes_default = () => template`
|
|
791
|
+
export default function routes() {
|
|
792
|
+
|
|
793
|
+
}
|
|
794
|
+
`;
|
|
795
|
+
|
|
796
|
+
// src/packages/cli/utils/indent.ts
|
|
797
|
+
function indent(amount = 1) {
|
|
798
|
+
return " ".repeat(amount);
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// src/packages/cli/templates/database.ts
|
|
802
|
+
var database_default = (name, driver) => {
|
|
803
|
+
const schemaName = underscore(name);
|
|
804
|
+
let driverName = driver;
|
|
805
|
+
let template2 = "export default {\n";
|
|
806
|
+
let username;
|
|
807
|
+
if (!driverName) {
|
|
808
|
+
driverName = "sqlite3";
|
|
809
|
+
}
|
|
810
|
+
if (driverName === "pg") {
|
|
811
|
+
username = "postgres";
|
|
812
|
+
} else if (driverName !== "pg" && driverName !== "sqlite3") {
|
|
813
|
+
username = "root";
|
|
814
|
+
}
|
|
815
|
+
["development", "test", "production"].forEach((environment) => {
|
|
816
|
+
template2 += `${indent(2)}${environment}: {
|
|
817
|
+
`;
|
|
818
|
+
if (driverName !== "sqlite3") {
|
|
819
|
+
template2 += `${indent(4)}pool: 5,
|
|
820
|
+
`;
|
|
821
|
+
}
|
|
822
|
+
template2 += `${indent(4)}driver: '${driverName}',
|
|
823
|
+
`;
|
|
824
|
+
if (username) {
|
|
825
|
+
template2 += `${indent(4)}username: '${username}',
|
|
826
|
+
`;
|
|
827
|
+
}
|
|
828
|
+
switch (environment) {
|
|
829
|
+
case "development":
|
|
830
|
+
template2 += `${indent(4)}database: '${schemaName}_dev'
|
|
831
|
+
`;
|
|
832
|
+
break;
|
|
833
|
+
case "test":
|
|
834
|
+
template2 += `${indent(4)}database: '${schemaName}_test'
|
|
835
|
+
`;
|
|
836
|
+
break;
|
|
837
|
+
case "production":
|
|
838
|
+
template2 += `${indent(4)}database: '${schemaName}_prod'
|
|
839
|
+
`;
|
|
840
|
+
break;
|
|
841
|
+
default:
|
|
842
|
+
template2 += `${indent(4)}database: '${schemaName}_${environment}'
|
|
843
|
+
`;
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
template2 += `${indent(2)}}`;
|
|
847
|
+
if (environment !== "production") {
|
|
848
|
+
template2 += ",\n\n";
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
template2 += "\n};\n";
|
|
852
|
+
return template2;
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
// src/packages/cli/templates/seed.ts
|
|
856
|
+
var seed_default = () => template`
|
|
857
|
+
export default async function seed() {
|
|
858
|
+
|
|
859
|
+
}
|
|
860
|
+
`;
|
|
861
|
+
|
|
862
|
+
// package.json
|
|
863
|
+
var version = "3.0.0";
|
|
864
|
+
|
|
865
|
+
// src/packages/cli/templates/package-json.ts
|
|
866
|
+
var LUMEN_VERSION = version;
|
|
867
|
+
var DRIVER_DEPS = {
|
|
868
|
+
sqlite3: { name: "sqlite3", version: "^5.1.7" },
|
|
869
|
+
pg: { name: "pg", version: "^8.16.3" },
|
|
870
|
+
mysql2: { name: "mysql2", version: "^3.15.3" }
|
|
871
|
+
};
|
|
872
|
+
var package_json_default = (name, driver) => {
|
|
873
|
+
const dbDriver = DRIVER_DEPS[driver] || DRIVER_DEPS.sqlite3;
|
|
874
|
+
const pkg = {
|
|
875
|
+
name,
|
|
876
|
+
version: "0.0.1",
|
|
877
|
+
description: "",
|
|
878
|
+
scripts: {
|
|
879
|
+
start: "lumen serve",
|
|
880
|
+
test: "lumen test",
|
|
881
|
+
lint: "eslint ."
|
|
882
|
+
},
|
|
883
|
+
author: "",
|
|
884
|
+
license: "MIT",
|
|
885
|
+
dependencies: {
|
|
886
|
+
knex: "^3.3.0",
|
|
887
|
+
"lumen-framework": LUMEN_VERSION,
|
|
888
|
+
[dbDriver.name]: dbDriver.version
|
|
889
|
+
},
|
|
890
|
+
devDependencies: {
|
|
891
|
+
"@eslint/js": "^9.39.5",
|
|
892
|
+
eslint: "^9.39.5",
|
|
893
|
+
globals: "^17.7.0"
|
|
894
|
+
},
|
|
895
|
+
engines: {
|
|
896
|
+
node: ">= 20"
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
if (dbDriver.name === "sqlite3") {
|
|
900
|
+
pkg.pnpm = { onlyBuiltDependencies: ["sqlite3"] };
|
|
901
|
+
}
|
|
902
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
903
|
+
`;
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
// src/packages/cli/templates/eslint-config.ts
|
|
907
|
+
var eslint_config_default = () => `import js from '@eslint/js';
|
|
908
|
+
import globals from 'globals';
|
|
909
|
+
|
|
910
|
+
export default [
|
|
911
|
+
js.configs.recommended,
|
|
912
|
+
{
|
|
913
|
+
languageOptions: {
|
|
914
|
+
ecmaVersion: 2023,
|
|
915
|
+
sourceType: 'module',
|
|
916
|
+
globals: {
|
|
917
|
+
...globals.node
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
];
|
|
922
|
+
`;
|
|
923
|
+
|
|
924
|
+
// src/packages/cli/templates/readme.ts
|
|
925
|
+
var readme_default = (name) => template`
|
|
926
|
+
# ${name}
|
|
927
|
+
|
|
928
|
+
## Installation
|
|
929
|
+
|
|
930
|
+
* \`git clone https://github.com/<this-repository>\`
|
|
931
|
+
* \`cd ${name}\`
|
|
932
|
+
* \`npm install\`
|
|
933
|
+
|
|
934
|
+
## Running / Development
|
|
935
|
+
|
|
936
|
+
* \`lumen serve\`
|
|
937
|
+
|
|
938
|
+
## Testing
|
|
939
|
+
|
|
940
|
+
* \`lumen test\`
|
|
941
|
+
|
|
942
|
+
## Further Reading / Useful Links
|
|
943
|
+
* [Lumen](https://github.com/nickschot/lux/)
|
|
944
|
+
* [Chai](http://chaijs.com/) / [Mocha](http://mochajs.org/)
|
|
945
|
+
`;
|
|
946
|
+
|
|
947
|
+
// src/packages/cli/templates/license.ts
|
|
948
|
+
var license_default = () => template`
|
|
949
|
+
The MIT License (MIT)
|
|
950
|
+
|
|
951
|
+
Copyright (c) 2016
|
|
952
|
+
|
|
953
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
954
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
955
|
+
in the Software without restriction, including without limitation the rights
|
|
956
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
957
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
958
|
+
furnished to do so, subject to the following conditions:
|
|
959
|
+
|
|
960
|
+
The above copyright notice and this permission notice shall be included in all
|
|
961
|
+
copies or substantial portions of the Software.
|
|
962
|
+
|
|
963
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
964
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
965
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
966
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
967
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
968
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
969
|
+
SOFTWARE.
|
|
970
|
+
`;
|
|
971
|
+
|
|
972
|
+
// src/packages/cli/templates/gitignore.ts
|
|
973
|
+
var gitignore_default = () => template`
|
|
974
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
|
975
|
+
|
|
976
|
+
# dependencies
|
|
977
|
+
/node_modules
|
|
978
|
+
|
|
979
|
+
# build
|
|
980
|
+
/dist
|
|
981
|
+
|
|
982
|
+
# logs
|
|
983
|
+
/log
|
|
984
|
+
npm-debug.log
|
|
985
|
+
|
|
986
|
+
# database
|
|
987
|
+
*.sqlite
|
|
988
|
+
*.sqlite-journal
|
|
989
|
+
*.sqlite-wal
|
|
990
|
+
*.sqlite-shm
|
|
991
|
+
|
|
992
|
+
# misc
|
|
993
|
+
*.DS_Store
|
|
994
|
+
`;
|
|
995
|
+
|
|
996
|
+
// src/packages/cli/generator/index.ts
|
|
997
|
+
var import_chalk9 = require("chalk");
|
|
998
|
+
|
|
999
|
+
// src/packages/cli/utils/create-prompt.ts
|
|
1000
|
+
var import_readline = require("readline");
|
|
1001
|
+
var YES = /^y(es)?$/i;
|
|
1002
|
+
function createPrompt() {
|
|
1003
|
+
const prompt = (0, import_readline.createInterface)({
|
|
1004
|
+
input: process.stdin,
|
|
1005
|
+
output: process.stdout
|
|
1006
|
+
});
|
|
1007
|
+
prompt.setPrompt("");
|
|
1008
|
+
return {
|
|
1009
|
+
question(text) {
|
|
1010
|
+
return new Promise((resolve2) => {
|
|
1011
|
+
prompt.question(text, (answer) => {
|
|
1012
|
+
resolve2(YES.test(answer));
|
|
1013
|
+
});
|
|
1014
|
+
});
|
|
1015
|
+
},
|
|
1016
|
+
close() {
|
|
1017
|
+
prompt.close();
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
// src/packages/cli/generator/utils/generate-type.ts
|
|
1023
|
+
var generate_type_exports = {};
|
|
1024
|
+
__export(generate_type_exports, {
|
|
1025
|
+
controller: () => controller,
|
|
1026
|
+
middleware: () => middleware,
|
|
1027
|
+
migration: () => migration,
|
|
1028
|
+
model: () => model,
|
|
1029
|
+
modelMigration: () => modelMigration,
|
|
1030
|
+
resource: () => resource,
|
|
1031
|
+
serializer: () => serializer,
|
|
1032
|
+
util: () => util
|
|
1033
|
+
});
|
|
1034
|
+
var import_path12 = require("path");
|
|
1035
|
+
var import_chalk8 = require("chalk");
|
|
1036
|
+
var import_inflection19 = require("inflection");
|
|
1037
|
+
|
|
1038
|
+
// src/packages/cli/generator/constants.ts
|
|
1039
|
+
var import_chalk = require("chalk");
|
|
1040
|
+
var NAMESPACED_RESOURCE_MESSAGE = template`
|
|
1041
|
+
|
|
1042
|
+
🎉 It looks like the resource you generated is within a namespace!
|
|
1043
|
+
|
|
1044
|
+
Lumen will only update your 'routes.js' file if you generate a resource at the\
|
|
1045
|
+
root namespace (i.e 'lumen generate resource users').
|
|
1046
|
+
|
|
1047
|
+
In order to access the resource you have created, remember to manually update\
|
|
1048
|
+
your 'routes.js' file.
|
|
1049
|
+
|
|
1050
|
+
Example:
|
|
1051
|
+
|
|
1052
|
+
export default function routes() {
|
|
1053
|
+
${(0, import_chalk.dim)("// this resource will be accessible at /users")}
|
|
1054
|
+
this.resource('users');
|
|
1055
|
+
|
|
1056
|
+
this.namespace('admin', function () {
|
|
1057
|
+
${(0, import_chalk.dim)("// this resource will be accessible at /admin/users")}
|
|
1058
|
+
this.resource('users');
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
`;
|
|
1063
|
+
|
|
1064
|
+
// src/packages/database/errors/invalid-driver-error.ts
|
|
1065
|
+
var import_chalk5 = require("chalk");
|
|
1066
|
+
|
|
1067
|
+
// src/packages/database/constants.ts
|
|
1068
|
+
var VALID_DRIVERS = [
|
|
1069
|
+
"pg",
|
|
1070
|
+
"sqlite3",
|
|
1071
|
+
"mssql",
|
|
1072
|
+
"mysql",
|
|
1073
|
+
"mysql2",
|
|
1074
|
+
"mariasql",
|
|
1075
|
+
"strong-oracle",
|
|
1076
|
+
"oracle"
|
|
1077
|
+
];
|
|
1078
|
+
|
|
1079
|
+
// src/packages/logger/constants.ts
|
|
1080
|
+
var DEBUG = "DEBUG";
|
|
1081
|
+
var INFO = "INFO";
|
|
1082
|
+
var WARN = "WARN";
|
|
1083
|
+
var ERROR = "ERROR";
|
|
1084
|
+
var FORMATS = new set_default(["text", "json"]);
|
|
1085
|
+
FORMATS.freeze();
|
|
1086
|
+
var LEVELS = new map_default([
|
|
1087
|
+
[DEBUG, 0],
|
|
1088
|
+
[INFO, 1],
|
|
1089
|
+
[WARN, 2],
|
|
1090
|
+
[ERROR, 3]
|
|
1091
|
+
]);
|
|
1092
|
+
LEVELS.freeze();
|
|
1093
|
+
|
|
1094
|
+
// src/packages/logger/writer/index.ts
|
|
1095
|
+
var import_tty = require("tty");
|
|
1096
|
+
var import_chalk2 = require("chalk");
|
|
1097
|
+
|
|
1098
|
+
// src/utils/entries.ts
|
|
1099
|
+
function entries(source) {
|
|
1100
|
+
return Object.entries(source);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// src/utils/omit.ts
|
|
1104
|
+
function omit(src, ...omitted) {
|
|
1105
|
+
return entries(src).filter(([key]) => omitted.indexOf(key) < 0).reduce(
|
|
1106
|
+
(result, [key, value]) => ({
|
|
1107
|
+
...result,
|
|
1108
|
+
[key]: value
|
|
1109
|
+
}),
|
|
1110
|
+
{}
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
// src/packages/logger/writer/constants.ts
|
|
1115
|
+
var import_ansi_regex = __toESM(require("ansi-regex"));
|
|
1116
|
+
var ANSI = (0, import_ansi_regex.default)();
|
|
1117
|
+
var STDOUT = /^(DEBUG|INFO)$/;
|
|
1118
|
+
var STDERR = /^(WARN|ERROR)$/;
|
|
1119
|
+
|
|
1120
|
+
// src/utils/stringify.ts
|
|
1121
|
+
function stringify(value, spaces) {
|
|
1122
|
+
if (isObject(value) || Array.isArray(value)) {
|
|
1123
|
+
return JSON.stringify(value, null, spaces);
|
|
1124
|
+
}
|
|
1125
|
+
return String(value);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// src/packages/logger/writer/utils/format-message.ts
|
|
1129
|
+
function formatMessage(data, format) {
|
|
1130
|
+
if (data instanceof Error) {
|
|
1131
|
+
return data.stack;
|
|
1132
|
+
} else if (format === "json") {
|
|
1133
|
+
return stringify(data).replace(ANSI, "");
|
|
1134
|
+
}
|
|
1135
|
+
return stringify(data, 2);
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// src/packages/logger/writer/index.ts
|
|
1139
|
+
function isMessageObject(value) {
|
|
1140
|
+
return Boolean(value) && typeof value === "object";
|
|
1141
|
+
}
|
|
1142
|
+
function createWriter2(format) {
|
|
1143
|
+
return function write(data) {
|
|
1144
|
+
const { level, ...etc } = data;
|
|
1145
|
+
let { message, timestamp } = etc;
|
|
1146
|
+
let output;
|
|
1147
|
+
if (format === "json") {
|
|
1148
|
+
output = {};
|
|
1149
|
+
if (isMessageObject(message) && message.message) {
|
|
1150
|
+
output = {
|
|
1151
|
+
timestamp,
|
|
1152
|
+
level,
|
|
1153
|
+
message: message.message,
|
|
1154
|
+
...omit(message, "message")
|
|
1155
|
+
};
|
|
1156
|
+
} else {
|
|
1157
|
+
output = {
|
|
1158
|
+
timestamp,
|
|
1159
|
+
level,
|
|
1160
|
+
message
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
output = formatMessage(output, "json");
|
|
1164
|
+
} else {
|
|
1165
|
+
let columns = 0;
|
|
1166
|
+
if (process.stdout instanceof import_tty.WriteStream) {
|
|
1167
|
+
columns = process.stdout.columns;
|
|
1168
|
+
}
|
|
1169
|
+
message = formatMessage(message, "text");
|
|
1170
|
+
switch (level) {
|
|
1171
|
+
case WARN:
|
|
1172
|
+
timestamp = (0, import_chalk2.yellow)(`[${timestamp}]`);
|
|
1173
|
+
break;
|
|
1174
|
+
case ERROR:
|
|
1175
|
+
timestamp = (0, import_chalk2.red)(`[${timestamp}]`);
|
|
1176
|
+
break;
|
|
1177
|
+
default:
|
|
1178
|
+
timestamp = (0, import_chalk2.dim)(`[${timestamp}]`);
|
|
1179
|
+
break;
|
|
1180
|
+
}
|
|
1181
|
+
output = `${timestamp} ${message}
|
|
1182
|
+
|
|
1183
|
+
${(0, import_chalk2.dim)("-").repeat(columns)}
|
|
1184
|
+
`;
|
|
1185
|
+
}
|
|
1186
|
+
if (STDOUT.test(level)) {
|
|
1187
|
+
process.stdout.write(`${output}
|
|
1188
|
+
`);
|
|
1189
|
+
} else if (STDERR.test(level)) {
|
|
1190
|
+
process.stderr.write(`${output}
|
|
1191
|
+
`);
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// src/packages/logger/request-logger/utils/log-text.ts
|
|
1197
|
+
var import_chalk4 = __toESM(require("chalk"));
|
|
1198
|
+
|
|
1199
|
+
// src/packages/logger/request-logger/templates.ts
|
|
1200
|
+
var import_chalk3 = require("chalk");
|
|
1201
|
+
|
|
1202
|
+
// src/packages/logger/utils/line.ts
|
|
1203
|
+
function line(strings, ...values) {
|
|
1204
|
+
return insertValues(strings, ...values).replace(/(\r\n|\n|\r|)/gm, "").replace(/\s+/g, " ").trim();
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
// src/packages/logger/request-logger/templates.ts
|
|
1208
|
+
function countDigits(num) {
|
|
1209
|
+
const digits = Math.floor(Math.log10(num) + 1);
|
|
1210
|
+
return digits > 0 && Number.isFinite(digits) ? digits : 1;
|
|
1211
|
+
}
|
|
1212
|
+
function pad(startTime, endTime, duration) {
|
|
1213
|
+
const maxLength = countDigits(endTime - startTime);
|
|
1214
|
+
return " ".repeat(maxLength - countDigits(duration)) + duration;
|
|
1215
|
+
}
|
|
1216
|
+
var debugTemplate = ({
|
|
1217
|
+
path: path6,
|
|
1218
|
+
stats,
|
|
1219
|
+
route,
|
|
1220
|
+
method,
|
|
1221
|
+
params,
|
|
1222
|
+
colorStr,
|
|
1223
|
+
startTime,
|
|
1224
|
+
endTime,
|
|
1225
|
+
statusCode,
|
|
1226
|
+
statusMessage,
|
|
1227
|
+
remoteAddress
|
|
1228
|
+
}) => `${line`
|
|
1229
|
+
Processed ${(0, import_chalk3.cyan)(`${method}`)} "${path6}" from ${remoteAddress}
|
|
1230
|
+
with ${Reflect.apply(colorStr, null, [`${statusCode}`])}
|
|
1231
|
+
${Reflect.apply(colorStr, null, [`${statusMessage}`])} by ${route ? `${(0, import_chalk3.yellow)(route.controller.constructor.name)}#${(0, import_chalk3.blue)(route.action)}` : null}
|
|
1232
|
+
`}
|
|
1233
|
+
|
|
1234
|
+
${(0, import_chalk3.magenta)("Params")}
|
|
1235
|
+
|
|
1236
|
+
${JSON.stringify(params, null, 2)}
|
|
1237
|
+
|
|
1238
|
+
${(0, import_chalk3.magenta)("Stats")}
|
|
1239
|
+
|
|
1240
|
+
${stats.map((stat2) => {
|
|
1241
|
+
const { type, duration, controller: controller2 } = stat2;
|
|
1242
|
+
let { name } = stat2;
|
|
1243
|
+
name = (0, import_chalk3.blue)(name);
|
|
1244
|
+
if (type === "action") {
|
|
1245
|
+
name = `${(0, import_chalk3.yellow)(controller2)}#${name}`;
|
|
1246
|
+
}
|
|
1247
|
+
return `${pad(startTime, endTime, duration)} ms ${name}`;
|
|
1248
|
+
}).join("\n")}
|
|
1249
|
+
${pad(
|
|
1250
|
+
startTime,
|
|
1251
|
+
endTime,
|
|
1252
|
+
stats.reduce((total, { duration }) => total + duration, 0)
|
|
1253
|
+
)} ms Total
|
|
1254
|
+
${(endTime - startTime).toString()} ms Actual`;
|
|
1255
|
+
var infoTemplate = ({
|
|
1256
|
+
path: path6,
|
|
1257
|
+
route,
|
|
1258
|
+
method,
|
|
1259
|
+
params,
|
|
1260
|
+
colorStr,
|
|
1261
|
+
startTime,
|
|
1262
|
+
endTime,
|
|
1263
|
+
statusCode,
|
|
1264
|
+
statusMessage,
|
|
1265
|
+
remoteAddress
|
|
1266
|
+
}) => line`
|
|
1267
|
+
Processed ${(0, import_chalk3.cyan)(`${method}`)} "${path6}" ${(0, import_chalk3.magenta)("Params")} ${JSON.stringify(
|
|
1268
|
+
params
|
|
1269
|
+
)} from ${remoteAddress} in ${(endTime - startTime).toString()} ms with ${Reflect.apply(
|
|
1270
|
+
colorStr,
|
|
1271
|
+
null,
|
|
1272
|
+
[`${statusCode}`]
|
|
1273
|
+
)} ${Reflect.apply(colorStr, null, [`${statusMessage}`])} by ${route ? `${(0, import_chalk3.yellow)(route.controller.constructor.name)}#${(0, import_chalk3.blue)(route.action)}` : null}
|
|
1274
|
+
`;
|
|
1275
|
+
|
|
1276
|
+
// src/packages/logger/request-logger/utils/filter-params.ts
|
|
1277
|
+
function filterParams(params, ...filtered) {
|
|
1278
|
+
return entries(params).map(([key, value]) => [
|
|
1279
|
+
key,
|
|
1280
|
+
filtered.indexOf(key) >= 0 ? "[FILTERED]" : value
|
|
1281
|
+
]).reduce(
|
|
1282
|
+
(result, [key, value]) => ({
|
|
1283
|
+
...result,
|
|
1284
|
+
[key]: value && typeof value === "object" && !Array.isArray(value) ? filterParams(value, ...filtered) : value
|
|
1285
|
+
}),
|
|
1286
|
+
{}
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
// src/packages/logger/request-logger/utils/log-text.ts
|
|
1291
|
+
function logText(logger, {
|
|
1292
|
+
startTime,
|
|
1293
|
+
request: req,
|
|
1294
|
+
response: res
|
|
1295
|
+
}) {
|
|
1296
|
+
res.once("finish", () => {
|
|
1297
|
+
const endTime = Date.now();
|
|
1298
|
+
const {
|
|
1299
|
+
route,
|
|
1300
|
+
method,
|
|
1301
|
+
url: { path: path6 },
|
|
1302
|
+
connection: { remoteAddress }
|
|
1303
|
+
} = req;
|
|
1304
|
+
const { stats, statusCode, statusMessage } = res;
|
|
1305
|
+
const params = filterParams(req.params, ...logger.filter.params);
|
|
1306
|
+
const statusColor = statusCode >= 200 && statusCode < 400 ? "green" : "red";
|
|
1307
|
+
let colorStr = Reflect.get(import_chalk4.default, statusColor);
|
|
1308
|
+
if (typeof colorStr === "undefined") {
|
|
1309
|
+
colorStr = (str) => str;
|
|
1310
|
+
}
|
|
1311
|
+
const templateData = {
|
|
1312
|
+
path: path6,
|
|
1313
|
+
stats,
|
|
1314
|
+
route,
|
|
1315
|
+
method,
|
|
1316
|
+
params,
|
|
1317
|
+
colorStr,
|
|
1318
|
+
startTime,
|
|
1319
|
+
endTime,
|
|
1320
|
+
statusCode: statusCode.toString(),
|
|
1321
|
+
statusMessage,
|
|
1322
|
+
remoteAddress
|
|
1323
|
+
};
|
|
1324
|
+
if (logger.level === DEBUG) {
|
|
1325
|
+
logger.debug(debugTemplate(templateData));
|
|
1326
|
+
} else {
|
|
1327
|
+
logger.info(infoTemplate(templateData));
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
// src/packages/logger/request-logger/utils/log-json.ts
|
|
1333
|
+
var MESSAGE = "Processed Request";
|
|
1334
|
+
function logJSON(logger, {
|
|
1335
|
+
request: req,
|
|
1336
|
+
response: res
|
|
1337
|
+
}) {
|
|
1338
|
+
res.once("finish", () => {
|
|
1339
|
+
const {
|
|
1340
|
+
method,
|
|
1341
|
+
headers,
|
|
1342
|
+
httpVersion,
|
|
1343
|
+
url: { path: path6 },
|
|
1344
|
+
connection: { remoteAddress }
|
|
1345
|
+
} = req;
|
|
1346
|
+
const { statusCode: status } = res;
|
|
1347
|
+
const userAgent = headers.get("user-agent");
|
|
1348
|
+
const protocol = `HTTP/${httpVersion}`;
|
|
1349
|
+
const params = filterParams(req.params, ...logger.filter.params);
|
|
1350
|
+
logger.info({
|
|
1351
|
+
message: MESSAGE,
|
|
1352
|
+
method,
|
|
1353
|
+
path: path6,
|
|
1354
|
+
params,
|
|
1355
|
+
status,
|
|
1356
|
+
protocol,
|
|
1357
|
+
userAgent,
|
|
1358
|
+
remoteAddress
|
|
1359
|
+
});
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
// src/packages/logger/request-logger/index.ts
|
|
1364
|
+
function createRequestLogger(logger) {
|
|
1365
|
+
return function request(req, res, { startTime }) {
|
|
1366
|
+
if (logger.format === "json") {
|
|
1367
|
+
logJSON(logger, {
|
|
1368
|
+
startTime,
|
|
1369
|
+
request: req,
|
|
1370
|
+
response: res
|
|
1371
|
+
});
|
|
1372
|
+
} else {
|
|
1373
|
+
logText(logger, {
|
|
1374
|
+
startTime,
|
|
1375
|
+
request: req,
|
|
1376
|
+
response: res
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
// src/packages/logger/utils/sql.ts
|
|
1383
|
+
var PATTERN = /(?:,?`|'|").+(?:`|'|"),?/;
|
|
1384
|
+
function sql(strings, ...values) {
|
|
1385
|
+
return insertValues(strings, ...values).split(" ").map((part) => {
|
|
1386
|
+
if (PATTERN.test(part)) {
|
|
1387
|
+
return part;
|
|
1388
|
+
}
|
|
1389
|
+
return part.toUpperCase();
|
|
1390
|
+
}).join(" ");
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
// src/packages/logger/index.ts
|
|
1394
|
+
var Logger = class {
|
|
1395
|
+
constructor({ level, format, filter, enabled }) {
|
|
1396
|
+
let write = K;
|
|
1397
|
+
let request = K;
|
|
1398
|
+
if (!LUMEN_CONSOLE && enabled) {
|
|
1399
|
+
write = createWriter2(format);
|
|
1400
|
+
request = createRequestLogger(this);
|
|
1401
|
+
}
|
|
1402
|
+
Object.defineProperties(this, {
|
|
1403
|
+
level: {
|
|
1404
|
+
value: level,
|
|
1405
|
+
writable: false,
|
|
1406
|
+
enumerable: true,
|
|
1407
|
+
configurable: false
|
|
1408
|
+
},
|
|
1409
|
+
format: {
|
|
1410
|
+
value: format,
|
|
1411
|
+
writable: false,
|
|
1412
|
+
enumerable: true,
|
|
1413
|
+
configurable: false
|
|
1414
|
+
},
|
|
1415
|
+
filter: {
|
|
1416
|
+
value: filter,
|
|
1417
|
+
writable: false,
|
|
1418
|
+
enumerable: true,
|
|
1419
|
+
configurable: false
|
|
1420
|
+
},
|
|
1421
|
+
enabled: {
|
|
1422
|
+
value: Boolean(enabled),
|
|
1423
|
+
writable: false,
|
|
1424
|
+
enumerable: true,
|
|
1425
|
+
configurable: false
|
|
1426
|
+
},
|
|
1427
|
+
request: {
|
|
1428
|
+
value: request,
|
|
1429
|
+
writable: false,
|
|
1430
|
+
enumerable: false,
|
|
1431
|
+
configurable: false
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
const levelNum = LEVELS.get(level) || 0;
|
|
1435
|
+
LEVELS.forEach((val, key) => {
|
|
1436
|
+
Reflect.defineProperty(this, key.toLowerCase(), {
|
|
1437
|
+
writable: false,
|
|
1438
|
+
enumerable: false,
|
|
1439
|
+
configurable: false,
|
|
1440
|
+
value: val >= levelNum ? (message) => {
|
|
1441
|
+
write({
|
|
1442
|
+
message,
|
|
1443
|
+
level: key,
|
|
1444
|
+
timestamp: this.getTimestamp()
|
|
1445
|
+
});
|
|
1446
|
+
} : K
|
|
1447
|
+
});
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
/**
|
|
1451
|
+
* @method getTimestamp
|
|
1452
|
+
* @return {String} The current time as an ISO8601 string.
|
|
1453
|
+
* @private
|
|
1454
|
+
*/
|
|
1455
|
+
getTimestamp() {
|
|
1456
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
var logger_default = Logger;
|
|
1460
|
+
|
|
1461
|
+
// src/packages/database/errors/invalid-driver-error.ts
|
|
1462
|
+
var InvalidDriverError = class extends Error {
|
|
1463
|
+
constructor(driver) {
|
|
1464
|
+
super(line`
|
|
1465
|
+
Invalid database driver ${(0, import_chalk5.yellow)(driver)} in ./config/database.js.
|
|
1466
|
+
Please use one of the following database drivers:
|
|
1467
|
+
${VALID_DRIVERS.map((str) => (0, import_chalk5.green)(str)).join(", ")}.
|
|
1468
|
+
`);
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
var invalid_driver_error_default = InvalidDriverError;
|
|
1472
|
+
|
|
1473
|
+
// src/packages/database/errors/model-missing-error.ts
|
|
1474
|
+
var ModelMissingError = class extends Error {
|
|
1475
|
+
constructor(name) {
|
|
1476
|
+
super(`Could not resolve model by name '${name}'`);
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
var model_missing_error_default = ModelMissingError;
|
|
1480
|
+
|
|
1481
|
+
// src/packages/database/errors/migrations-pending-error.ts
|
|
1482
|
+
var import_chalk6 = require("chalk");
|
|
1483
|
+
var MigrationsPendingError = class extends Error {
|
|
1484
|
+
constructor(migrations = []) {
|
|
1485
|
+
const pending = migrations.map((str) => (0, import_chalk6.yellow)(str.substr(0, str.length - 3))).join(", ");
|
|
1486
|
+
super(line`
|
|
1487
|
+
The following migrations are pending ${pending}.
|
|
1488
|
+
Please run ${(0, import_chalk6.green)("lumen db:migrate")} before starting your application.
|
|
1489
|
+
`);
|
|
1490
|
+
}
|
|
1491
|
+
};
|
|
1492
|
+
var migrations_pending_error_default = MigrationsPendingError;
|
|
1493
|
+
|
|
1494
|
+
// src/packages/server/utils/create-server-error.ts
|
|
1495
|
+
function createServerError(Target, statusCode) {
|
|
1496
|
+
const ServerError = class extends Target {
|
|
1497
|
+
constructor(...args) {
|
|
1498
|
+
super(...args);
|
|
1499
|
+
this.statusCode = statusCode;
|
|
1500
|
+
}
|
|
1501
|
+
};
|
|
1502
|
+
Reflect.defineProperty(ServerError, "name", {
|
|
1503
|
+
value: Target.name
|
|
1504
|
+
});
|
|
1505
|
+
return ServerError;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
// src/packages/database/errors/unique-constraint-error.ts
|
|
1509
|
+
var UniqueConstraintError = class extends Error {
|
|
1510
|
+
};
|
|
1511
|
+
var unique_constraint_error_default = createServerError(UniqueConstraintError, 409);
|
|
1512
|
+
|
|
1513
|
+
// src/packages/database/errors/config-missing-error.ts
|
|
1514
|
+
var ConfigMissingError = class extends Error {
|
|
1515
|
+
constructor(environment) {
|
|
1516
|
+
super(`Database config not found for environment ${environment}.`);
|
|
1517
|
+
}
|
|
1518
|
+
};
|
|
1519
|
+
var config_missing_error_default = ConfigMissingError;
|
|
1520
|
+
|
|
1521
|
+
// src/packages/database/initialize.ts
|
|
1522
|
+
var import_cluster = __toESM(require("cluster"));
|
|
1523
|
+
|
|
1524
|
+
// src/packages/database/utils/connect.ts
|
|
1525
|
+
var import_path10 = require("path");
|
|
1526
|
+
function connect(path6, config) {
|
|
1527
|
+
let { pool } = config;
|
|
1528
|
+
const { host, socket, driver, database, username, password, port, ssl, url } = config;
|
|
1529
|
+
if (VALID_DRIVERS.indexOf(driver) < 0) {
|
|
1530
|
+
throw new invalid_driver_error_default(driver);
|
|
1531
|
+
}
|
|
1532
|
+
if (pool && typeof pool === "number") {
|
|
1533
|
+
pool = {
|
|
1534
|
+
min: pool > 1 ? 2 : 1,
|
|
1535
|
+
max: pool
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
const knex = require((0, import_path10.join)(path6, "node_modules", "knex"));
|
|
1539
|
+
const usingSQLite = driver === "sqlite3";
|
|
1540
|
+
const connection = DATABASE_URL || url || {
|
|
1541
|
+
host,
|
|
1542
|
+
database,
|
|
1543
|
+
password,
|
|
1544
|
+
port,
|
|
1545
|
+
ssl,
|
|
1546
|
+
user: username,
|
|
1547
|
+
socketPath: socket,
|
|
1548
|
+
filename: usingSQLite ? (0, import_path10.join)(path6, "db", `${database || "default"}_${NODE_ENV}.sqlite`) : void 0
|
|
1549
|
+
};
|
|
1550
|
+
return knex({
|
|
1551
|
+
pool,
|
|
1552
|
+
connection,
|
|
1553
|
+
debug: false,
|
|
1554
|
+
client: driver,
|
|
1555
|
+
useNullAsDefault: usingSQLite
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
// src/packages/database/utils/create-migrations.ts
|
|
1560
|
+
async function createMigrations(schema) {
|
|
1561
|
+
const hasTable = await schema().hasTable("migrations");
|
|
1562
|
+
if (!hasTable) {
|
|
1563
|
+
await schema().createTable("migrations", (table) => {
|
|
1564
|
+
table.string("version", 16).primary();
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
return true;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
// src/packages/database/utils/pending-migrations.ts
|
|
1571
|
+
async function pendingMigrations(appPath, table) {
|
|
1572
|
+
const migrations = await readdir(`${appPath}/db/migrate`);
|
|
1573
|
+
const versions = await table().select().then(
|
|
1574
|
+
(data) => data.map(({ version: version2 }) => version2)
|
|
1575
|
+
);
|
|
1576
|
+
return migrations.filter(
|
|
1577
|
+
(migration2) => versions.indexOf(migration2.replace(/^(\d{16})-.+$/g, "$1")) < 0
|
|
1578
|
+
);
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
// src/packages/database/initialize.ts
|
|
1582
|
+
async function initialize2(instance, opts) {
|
|
1583
|
+
const { path: path6, models, logger, checkMigrations } = opts;
|
|
1584
|
+
const config = Reflect.get(opts.config, NODE_ENV);
|
|
1585
|
+
if (!config) {
|
|
1586
|
+
throw new config_missing_error_default(NODE_ENV);
|
|
1587
|
+
}
|
|
1588
|
+
const { debug = NODE_ENV === "development" } = config;
|
|
1589
|
+
Object.defineProperties(instance, {
|
|
1590
|
+
path: {
|
|
1591
|
+
value: path6,
|
|
1592
|
+
writable: false,
|
|
1593
|
+
enumerable: false,
|
|
1594
|
+
configurable: false
|
|
1595
|
+
},
|
|
1596
|
+
debug: {
|
|
1597
|
+
value: debug,
|
|
1598
|
+
writable: false,
|
|
1599
|
+
enumerable: false,
|
|
1600
|
+
configurable: false
|
|
1601
|
+
},
|
|
1602
|
+
models: {
|
|
1603
|
+
value: models,
|
|
1604
|
+
writable: false,
|
|
1605
|
+
enumerable: false,
|
|
1606
|
+
configurable: false
|
|
1607
|
+
},
|
|
1608
|
+
logger: {
|
|
1609
|
+
value: logger,
|
|
1610
|
+
writable: false,
|
|
1611
|
+
enumerable: false,
|
|
1612
|
+
configurable: false
|
|
1613
|
+
},
|
|
1614
|
+
config: {
|
|
1615
|
+
value: config,
|
|
1616
|
+
writable: false,
|
|
1617
|
+
enumerable: true,
|
|
1618
|
+
configurable: false
|
|
1619
|
+
},
|
|
1620
|
+
schema: {
|
|
1621
|
+
value: () => instance.connection.schema,
|
|
1622
|
+
writable: false,
|
|
1623
|
+
enumerable: false,
|
|
1624
|
+
configurable: false
|
|
1625
|
+
},
|
|
1626
|
+
connection: {
|
|
1627
|
+
value: connect(path6, config),
|
|
1628
|
+
writable: false,
|
|
1629
|
+
enumerable: false,
|
|
1630
|
+
configurable: false
|
|
1631
|
+
}
|
|
1632
|
+
});
|
|
1633
|
+
if (import_cluster.default.isMaster || import_cluster.default.worker && import_cluster.default.worker.id === 1) {
|
|
1634
|
+
await createMigrations(instance.schema);
|
|
1635
|
+
if (checkMigrations) {
|
|
1636
|
+
const pending = await pendingMigrations(
|
|
1637
|
+
path6,
|
|
1638
|
+
() => instance.connection("migrations")
|
|
1639
|
+
);
|
|
1640
|
+
if (pending.length) {
|
|
1641
|
+
throw new migrations_pending_error_default(pending);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
await Promise.all(
|
|
1646
|
+
Array.from(models.values()).map(
|
|
1647
|
+
(model2) => model2.initialize(instance, () => instance.connection(model2.tableName))
|
|
1648
|
+
)
|
|
1649
|
+
);
|
|
1650
|
+
return instance;
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
// src/packages/database/utils/normalize-model-name.ts
|
|
1654
|
+
var import_inflection5 = require("inflection");
|
|
1655
|
+
var normalize_model_name_default = compose(import_inflection5.singularize, import_inflection5.dasherize, underscore);
|
|
1656
|
+
|
|
1657
|
+
// src/packages/database/model/index.ts
|
|
1658
|
+
var import_inflection12 = require("inflection");
|
|
1659
|
+
|
|
1660
|
+
// src/packages/database/query/index.ts
|
|
1661
|
+
var import_inflection8 = require("inflection");
|
|
1662
|
+
|
|
1663
|
+
// src/packages/database/query/utils/format-select.ts
|
|
1664
|
+
var import_inflection6 = require("inflection");
|
|
1665
|
+
|
|
1666
|
+
// src/packages/database/query/errors/record-not-found-error.ts
|
|
1667
|
+
var RecordNotFoundError = class extends Error {
|
|
1668
|
+
constructor({ name, primaryKey }, primaryKeyValue) {
|
|
1669
|
+
super(
|
|
1670
|
+
`Could not find ${name} with ${primaryKey} ${stringify(primaryKeyValue)}.`
|
|
1671
|
+
);
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
1674
|
+
var record_not_found_error_default = createServerError(RecordNotFoundError, 404);
|
|
1675
|
+
|
|
1676
|
+
// src/packages/database/query/runner/utils/build-results.ts
|
|
1677
|
+
var import_inflection7 = require("inflection");
|
|
1678
|
+
|
|
1679
|
+
// src/packages/database/relationship/index.ts
|
|
1680
|
+
var import_inflection10 = require("inflection");
|
|
1681
|
+
|
|
1682
|
+
// src/packages/database/relationship/utils/getters.ts
|
|
1683
|
+
var import_inflection9 = require("inflection");
|
|
1684
|
+
|
|
1685
|
+
// src/packages/database/model/initialize-class.ts
|
|
1686
|
+
var import_inflection11 = require("inflection");
|
|
1687
|
+
|
|
1688
|
+
// src/packages/database/migration/utils/generate-timestamp.ts
|
|
1689
|
+
function formatInt(int) {
|
|
1690
|
+
return (int / 10).toString().replace(".", "").substr(0, 2);
|
|
1691
|
+
}
|
|
1692
|
+
function* padding(char, amount) {
|
|
1693
|
+
for (let i = 0; i < amount; i += 1) {
|
|
1694
|
+
yield char;
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
function generateTimestamp() {
|
|
1698
|
+
const now = /* @__PURE__ */ new Date();
|
|
1699
|
+
const timestamp = now.toISOString().substr(0, 10).split("-").join("") + formatInt(now.getHours()) + formatInt(now.getMinutes()) + formatInt(now.getSeconds()) + formatInt(now.getMilliseconds());
|
|
1700
|
+
return timestamp + Array.from(padding("0", 16 - timestamp.length)).join("");
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
// src/packages/database/migration/index.ts
|
|
1704
|
+
var Migration = class {
|
|
1705
|
+
constructor(fn) {
|
|
1706
|
+
this.fn = fn;
|
|
1707
|
+
}
|
|
1708
|
+
run(schema) {
|
|
1709
|
+
return this.fn(schema);
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
var migration_default = Migration;
|
|
1713
|
+
|
|
1714
|
+
// src/packages/database/index.ts
|
|
1715
|
+
var Database = class {
|
|
1716
|
+
constructor(opts) {
|
|
1717
|
+
return initialize2(this, opts);
|
|
1718
|
+
}
|
|
1719
|
+
modelFor(type) {
|
|
1720
|
+
const model2 = this.models.get(normalize_model_name_default(type));
|
|
1721
|
+
if (!model2) {
|
|
1722
|
+
throw new model_missing_error_default(type);
|
|
1723
|
+
}
|
|
1724
|
+
return model2;
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
var database_default2 = Database;
|
|
1728
|
+
|
|
1729
|
+
// src/packages/cli/templates/model.ts
|
|
1730
|
+
var import_os2 = require("os");
|
|
1731
|
+
var import_inflection13 = require("inflection");
|
|
1732
|
+
var VALID_ATTR = /^(\w|-)+:(\w|-)+$/;
|
|
1733
|
+
var RELATIONSHIP = /^belongs-to|has-(one|many)$/;
|
|
1734
|
+
var model_default2 = (name, attrs) => {
|
|
1735
|
+
const normalized = chain(name).pipe(underscore).pipe(import_inflection13.classify).value();
|
|
1736
|
+
return template`
|
|
1737
|
+
import { Model } from 'lumen-framework';
|
|
1738
|
+
|
|
1739
|
+
class ${normalized} extends Model {
|
|
1740
|
+
${entries(
|
|
1741
|
+
(attrs || []).filter((attr) => VALID_ATTR.test(attr)).map((attr) => attr.split(":")).filter(([, type]) => RELATIONSHIP.test(type)).reduce(
|
|
1742
|
+
(types, [related, type]) => {
|
|
1743
|
+
const key = chain(type).pipe(underscore).pipe((str) => (0, import_inflection13.camelize)(str, true)).value();
|
|
1744
|
+
const value = Reflect.get(types, key);
|
|
1745
|
+
if (value) {
|
|
1746
|
+
const inverse = (0, import_inflection13.camelize)(normalized, true);
|
|
1747
|
+
const relatedKey = chain(related).pipe(underscore).pipe((str) => (0, import_inflection13.camelize)(str, true)).value();
|
|
1748
|
+
return {
|
|
1749
|
+
...types,
|
|
1750
|
+
[key]: [
|
|
1751
|
+
...value,
|
|
1752
|
+
`${indent(8)}${relatedKey}: {${import_os2.EOL}${indent(10)}inverse: '${inverse}'${import_os2.EOL}${indent(8)}}`
|
|
1753
|
+
]
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
return types;
|
|
1757
|
+
},
|
|
1758
|
+
{
|
|
1759
|
+
hasOne: [],
|
|
1760
|
+
hasMany: [],
|
|
1761
|
+
belongsTo: []
|
|
1762
|
+
}
|
|
1763
|
+
)
|
|
1764
|
+
).filter(([, value]) => value.length).reduce(
|
|
1765
|
+
(result, [key, value], index) => chain(result).pipe((str) => {
|
|
1766
|
+
if (index && str.length) {
|
|
1767
|
+
return `${str}${import_os2.EOL.repeat(2)}`;
|
|
1768
|
+
}
|
|
1769
|
+
return str;
|
|
1770
|
+
}).pipe(
|
|
1771
|
+
(str) => str + `${indent(index === 0 ? 2 : 6)}static ${key} = {${import_os2.EOL}${value.join(`,${import_os2.EOL.repeat(2)}`)}${import_os2.EOL}${indent(6)}};`
|
|
1772
|
+
).value(),
|
|
1773
|
+
""
|
|
1774
|
+
)}
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
export default ${normalized};
|
|
1778
|
+
`;
|
|
1779
|
+
};
|
|
1780
|
+
|
|
1781
|
+
// src/packages/cli/templates/serializer.ts
|
|
1782
|
+
var import_inflection14 = require("inflection");
|
|
1783
|
+
var serializer_default = (name, attrs) => {
|
|
1784
|
+
let normalized = chain(name).pipe(underscore).pipe(import_inflection14.classify).value();
|
|
1785
|
+
if (!normalized.endsWith("Application")) {
|
|
1786
|
+
normalized = (0, import_inflection14.pluralize)(normalized);
|
|
1787
|
+
}
|
|
1788
|
+
const body = entries(
|
|
1789
|
+
attrs.filter((attr) => /^(\w|-)+:(\w|-)+$/g.test(attr)).map((attr) => attr.split(":")).reduce(
|
|
1790
|
+
(obj, parts) => {
|
|
1791
|
+
const [, type] = parts;
|
|
1792
|
+
let [attr] = parts;
|
|
1793
|
+
let { hasOne, hasMany, attributes } = obj;
|
|
1794
|
+
attr = `${indent(8)}'${(0, import_inflection14.camelize)(underscore(attr), true)}'`;
|
|
1795
|
+
switch (type) {
|
|
1796
|
+
case "belongs-to":
|
|
1797
|
+
case "has-one":
|
|
1798
|
+
hasOne = [...hasOne, attr];
|
|
1799
|
+
break;
|
|
1800
|
+
case "has-many":
|
|
1801
|
+
hasMany = [...hasMany, attr];
|
|
1802
|
+
break;
|
|
1803
|
+
default:
|
|
1804
|
+
attributes = [...attributes, attr];
|
|
1805
|
+
}
|
|
1806
|
+
return {
|
|
1807
|
+
attributes,
|
|
1808
|
+
hasOne,
|
|
1809
|
+
hasMany
|
|
1810
|
+
};
|
|
1811
|
+
},
|
|
1812
|
+
{
|
|
1813
|
+
// `belongsTo` was a dead accumulator key — never destructured and, for
|
|
1814
|
+
// non-empty attrs, never present in the returned object — so it emitted
|
|
1815
|
+
// nothing. Dropped so the accumulator types cleanly.
|
|
1816
|
+
attributes: [],
|
|
1817
|
+
hasOne: [],
|
|
1818
|
+
hasMany: []
|
|
1819
|
+
}
|
|
1820
|
+
)
|
|
1821
|
+
).reduce((result, group, index) => {
|
|
1822
|
+
const [key, items] = group;
|
|
1823
|
+
let str = result;
|
|
1824
|
+
if (items.length) {
|
|
1825
|
+
const value = items.join(",\n");
|
|
1826
|
+
if (index && str.length) {
|
|
1827
|
+
str += "\n\n";
|
|
1828
|
+
}
|
|
1829
|
+
str += `${indent(index === 0 ? 2 : 6)}${key} = [
|
|
1830
|
+
${value}
|
|
1831
|
+
${indent(6)}];`;
|
|
1832
|
+
}
|
|
1833
|
+
return str;
|
|
1834
|
+
}, "");
|
|
1835
|
+
return template`
|
|
1836
|
+
import { Serializer } from 'lumen-framework';
|
|
1837
|
+
|
|
1838
|
+
class ${normalized}Serializer extends Serializer {
|
|
1839
|
+
${body}
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
export default ${normalized}Serializer;
|
|
1843
|
+
`;
|
|
1844
|
+
};
|
|
1845
|
+
|
|
1846
|
+
// src/packages/cli/templates/controller.ts
|
|
1847
|
+
var import_inflection15 = require("inflection");
|
|
1848
|
+
var controller_default = (name, attrs) => {
|
|
1849
|
+
let normalized = chain(name).pipe(underscore).pipe(import_inflection15.classify).value();
|
|
1850
|
+
if (!normalized.endsWith("Application")) {
|
|
1851
|
+
normalized = (0, import_inflection15.pluralize)(normalized);
|
|
1852
|
+
}
|
|
1853
|
+
const body = entries(
|
|
1854
|
+
attrs.filter((attr) => /^(\w|-)+:(\w|-)+$/g.test(attr)).map((attr) => attr.split(":")[0]).reduce(
|
|
1855
|
+
(obj, attr) => ({
|
|
1856
|
+
...obj,
|
|
1857
|
+
params: [
|
|
1858
|
+
...obj.params,
|
|
1859
|
+
`${indent(8)}'${(0, import_inflection15.camelize)(underscore(attr), true)}'`
|
|
1860
|
+
]
|
|
1861
|
+
}),
|
|
1862
|
+
{ params: [] }
|
|
1863
|
+
)
|
|
1864
|
+
).reduce((result, group, index) => {
|
|
1865
|
+
const [key, items] = group;
|
|
1866
|
+
let str = result;
|
|
1867
|
+
if (items.length) {
|
|
1868
|
+
const value = items.join(",\n");
|
|
1869
|
+
if (index && str.length) {
|
|
1870
|
+
str += "\n\n";
|
|
1871
|
+
}
|
|
1872
|
+
str += `${indent(index === 0 ? 2 : 6)}${key} = [
|
|
1873
|
+
${value}
|
|
1874
|
+
${indent(6)}];`;
|
|
1875
|
+
}
|
|
1876
|
+
return str;
|
|
1877
|
+
}, "");
|
|
1878
|
+
return template`
|
|
1879
|
+
import { Controller } from 'lumen-framework';
|
|
1880
|
+
|
|
1881
|
+
class ${normalized}Controller extends Controller {
|
|
1882
|
+
${body}
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
export default ${normalized}Controller;
|
|
1886
|
+
`;
|
|
1887
|
+
};
|
|
1888
|
+
|
|
1889
|
+
// src/packages/cli/templates/empty-migration.ts
|
|
1890
|
+
var empty_migration_default = () => template`
|
|
1891
|
+
export function up(schema) {
|
|
1892
|
+
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
export function down(schema) {
|
|
1896
|
+
|
|
1897
|
+
}
|
|
1898
|
+
`;
|
|
1899
|
+
|
|
1900
|
+
// src/packages/cli/templates/model-migration.ts
|
|
1901
|
+
var import_inflection16 = require("inflection");
|
|
1902
|
+
var model_migration_default = (name, attrs) => {
|
|
1903
|
+
const indices = ["id"];
|
|
1904
|
+
const table = chain(name).pipe((str) => str.substr(24)).pipe(underscore).pipe(import_inflection16.pluralize).value();
|
|
1905
|
+
let body = "";
|
|
1906
|
+
if (Array.isArray(attrs)) {
|
|
1907
|
+
body = attrs.filter((attr) => /^(\w|-)+:(\w|-)+$/g.test(attr)).map((attr) => attr.split(":")).filter(([, type]) => !/^has-(one|many)$/g.test(type)).map((attr) => {
|
|
1908
|
+
let [column, type] = attr;
|
|
1909
|
+
column = underscore(column);
|
|
1910
|
+
if (type === "belongs-to") {
|
|
1911
|
+
type = "integer";
|
|
1912
|
+
column = `${column}_id`;
|
|
1913
|
+
if (Array.isArray(indices)) {
|
|
1914
|
+
indices.push(column);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
return [column, type];
|
|
1918
|
+
}).map((attr, index) => {
|
|
1919
|
+
let [column] = attr;
|
|
1920
|
+
const [, type] = attr;
|
|
1921
|
+
const shouldIndex = indices.indexOf(column) >= 0;
|
|
1922
|
+
column = `${indent(index > 0 ? 8 : 0)}table.${type}('${column}')`;
|
|
1923
|
+
return shouldIndex ? `${column}.index();` : `${column};`;
|
|
1924
|
+
}).join("\n");
|
|
1925
|
+
}
|
|
1926
|
+
return template`
|
|
1927
|
+
export function up(schema) {
|
|
1928
|
+
return schema.createTable('${table}', table => {
|
|
1929
|
+
table.increments('id');
|
|
1930
|
+
${body}
|
|
1931
|
+
table.timestamps();
|
|
1932
|
+
|
|
1933
|
+
table.index('created_at');
|
|
1934
|
+
table.index('updated_at');
|
|
1935
|
+
});
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
export function down(schema) {
|
|
1939
|
+
return schema.dropTable('${table}');
|
|
1940
|
+
}
|
|
1941
|
+
`;
|
|
1942
|
+
};
|
|
1943
|
+
|
|
1944
|
+
// src/packages/cli/templates/middleware.ts
|
|
1945
|
+
var import_inflection17 = require("inflection");
|
|
1946
|
+
var middleware_default = (name) => {
|
|
1947
|
+
const normalized = chain(name).pipe(underscore).pipe((str) => (0, import_inflection17.camelize)(str, true)).value();
|
|
1948
|
+
return template`
|
|
1949
|
+
export default function ${normalized}(/*request, response*/) {
|
|
1950
|
+
|
|
1951
|
+
}
|
|
1952
|
+
`;
|
|
1953
|
+
};
|
|
1954
|
+
|
|
1955
|
+
// src/packages/cli/templates/util.ts
|
|
1956
|
+
var import_inflection18 = require("inflection");
|
|
1957
|
+
var util_default = (name) => {
|
|
1958
|
+
const normalized = chain(name).pipe(underscore).pipe((str) => (0, import_inflection18.camelize)(str, true)).value();
|
|
1959
|
+
return template`
|
|
1960
|
+
export default function ${normalized}() {
|
|
1961
|
+
|
|
1962
|
+
}
|
|
1963
|
+
`;
|
|
1964
|
+
};
|
|
1965
|
+
|
|
1966
|
+
// src/packages/cli/generator/utils/log.ts
|
|
1967
|
+
function log(data) {
|
|
1968
|
+
if (data instanceof Error) {
|
|
1969
|
+
process.stdout.write(`${data.stack || data.message}
|
|
1970
|
+
`);
|
|
1971
|
+
} else {
|
|
1972
|
+
process.stderr.write(`${data}
|
|
1973
|
+
`);
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
// src/packages/cli/generator/utils/create-generator.ts
|
|
1978
|
+
var import_path11 = require("path");
|
|
1979
|
+
var import_chalk7 = require("chalk");
|
|
1980
|
+
var FORWARD_SLASH = /\//g;
|
|
1981
|
+
function createGenerator({
|
|
1982
|
+
dir,
|
|
1983
|
+
template: template2,
|
|
1984
|
+
hasConflict = exists
|
|
1985
|
+
}) {
|
|
1986
|
+
return async ({ cwd, attrs, onConflict, ...opts }) => {
|
|
1987
|
+
const path6 = resolvePath(cwd, dir, `${opts.name}.js`);
|
|
1988
|
+
const name = opts.name.replace(FORWARD_SLASH, "-");
|
|
1989
|
+
let action = (0, import_chalk7.green)("create");
|
|
1990
|
+
await mkdirRec(path6.dir);
|
|
1991
|
+
if (await hasConflict(path6.absolute)) {
|
|
1992
|
+
const shouldContinue = await onConflict(path6.relative);
|
|
1993
|
+
if (shouldContinue && typeof shouldContinue === "string") {
|
|
1994
|
+
await rmrf_default((0, import_path11.join)(path6.dir, shouldContinue));
|
|
1995
|
+
log(`${(0, import_chalk7.red)("remove")} ${(0, import_path11.join)(dir, shouldContinue)}`);
|
|
1996
|
+
} else if (shouldContinue && typeof shouldContinue === "boolean") {
|
|
1997
|
+
action = (0, import_chalk7.yellow)("overwrite");
|
|
1998
|
+
await rmrf_default(path6.absolute);
|
|
1999
|
+
} else {
|
|
2000
|
+
log(`${(0, import_chalk7.yellow)("skip")} ${path6.relative}`);
|
|
2001
|
+
return;
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
await writeFile(path6.absolute, template2(name, attrs));
|
|
2005
|
+
log(`${action} ${path6.relative}`);
|
|
2006
|
+
};
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
// src/packages/cli/generator/utils/migration-conflict.ts
|
|
2010
|
+
function detectConflict(path6) {
|
|
2011
|
+
const { dir, base } = resolvePath(path6);
|
|
2012
|
+
const pattern = new RegExp(`^\\d+-${base.substr(17)}$`);
|
|
2013
|
+
return exists(pattern, dir);
|
|
2014
|
+
}
|
|
2015
|
+
function createConflictResolver({
|
|
2016
|
+
cwd,
|
|
2017
|
+
onConflict
|
|
2018
|
+
}) {
|
|
2019
|
+
return async (path6) => {
|
|
2020
|
+
if (await onConflict(path6)) {
|
|
2021
|
+
const parsed = resolvePath(cwd, path6);
|
|
2022
|
+
const migrations = await readdir(parsed.dir);
|
|
2023
|
+
return migrations.find((file) => file.substr(17) === parsed.base.substr(17)) || false;
|
|
2024
|
+
}
|
|
2025
|
+
return false;
|
|
2026
|
+
};
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
// src/packages/cli/generator/utils/generate-type.ts
|
|
2030
|
+
async function controller(opts) {
|
|
2031
|
+
const { cwd } = opts;
|
|
2032
|
+
let { name } = opts;
|
|
2033
|
+
const dir = (0, import_path12.join)("app", "controllers");
|
|
2034
|
+
const generate2 = createGenerator({
|
|
2035
|
+
dir,
|
|
2036
|
+
template: controller_default
|
|
2037
|
+
});
|
|
2038
|
+
if (!name.endsWith("application")) {
|
|
2039
|
+
name = (0, import_inflection19.pluralize)(name);
|
|
2040
|
+
}
|
|
2041
|
+
await generate2({
|
|
2042
|
+
...opts,
|
|
2043
|
+
cwd,
|
|
2044
|
+
name
|
|
2045
|
+
});
|
|
2046
|
+
const namespace = import_path12.posix.dirname(name);
|
|
2047
|
+
if (namespace !== ".") {
|
|
2048
|
+
const hasParent = await exists(
|
|
2049
|
+
(0, import_path12.join)(cwd, dir, ...[...namespace.split("/"), "application.js"])
|
|
2050
|
+
);
|
|
2051
|
+
if (!hasParent) {
|
|
2052
|
+
await controller({
|
|
2053
|
+
...opts,
|
|
2054
|
+
cwd,
|
|
2055
|
+
name: `${namespace}/application`,
|
|
2056
|
+
attrs: []
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
async function serializer(opts) {
|
|
2062
|
+
const { cwd } = opts;
|
|
2063
|
+
let { name } = opts;
|
|
2064
|
+
const dir = (0, import_path12.join)("app", "serializers");
|
|
2065
|
+
const generate2 = createGenerator({
|
|
2066
|
+
dir,
|
|
2067
|
+
template: serializer_default
|
|
2068
|
+
});
|
|
2069
|
+
if (!name.endsWith("application")) {
|
|
2070
|
+
name = (0, import_inflection19.pluralize)(name);
|
|
2071
|
+
}
|
|
2072
|
+
await generate2({
|
|
2073
|
+
...opts,
|
|
2074
|
+
cwd,
|
|
2075
|
+
name
|
|
2076
|
+
});
|
|
2077
|
+
const namespace = import_path12.posix.dirname(name);
|
|
2078
|
+
if (namespace !== ".") {
|
|
2079
|
+
const hasParent = await exists(
|
|
2080
|
+
(0, import_path12.join)(cwd, dir, ...[...namespace.split("/"), "application.js"])
|
|
2081
|
+
);
|
|
2082
|
+
if (!hasParent) {
|
|
2083
|
+
await serializer({
|
|
2084
|
+
...opts,
|
|
2085
|
+
cwd,
|
|
2086
|
+
name: `${namespace}/application`,
|
|
2087
|
+
attrs: []
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
function migration(opts) {
|
|
2093
|
+
const { cwd, onConflict } = opts;
|
|
2094
|
+
let { name } = opts;
|
|
2095
|
+
const dir = (0, import_path12.join)("db", "migrate");
|
|
2096
|
+
const generate2 = createGenerator({
|
|
2097
|
+
dir,
|
|
2098
|
+
template: empty_migration_default,
|
|
2099
|
+
hasConflict: detectConflict
|
|
2100
|
+
});
|
|
2101
|
+
name = chain(name).pipe(import_path12.posix.basename).pipe((str) => `${generateTimestamp()}-${str}`).value();
|
|
2102
|
+
return generate2({
|
|
2103
|
+
...opts,
|
|
2104
|
+
cwd,
|
|
2105
|
+
name,
|
|
2106
|
+
onConflict: createConflictResolver({
|
|
2107
|
+
cwd,
|
|
2108
|
+
onConflict
|
|
2109
|
+
})
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
function modelMigration(opts) {
|
|
2113
|
+
const { cwd, onConflict } = opts;
|
|
2114
|
+
let { name } = opts;
|
|
2115
|
+
const dir = (0, import_path12.join)("db", "migrate");
|
|
2116
|
+
const generate2 = createGenerator({
|
|
2117
|
+
dir,
|
|
2118
|
+
template: model_migration_default,
|
|
2119
|
+
hasConflict: detectConflict
|
|
2120
|
+
});
|
|
2121
|
+
name = chain(name).pipe(import_path12.posix.basename).pipe(import_inflection19.pluralize).pipe((str) => `${generateTimestamp()}-create-${str}`).value();
|
|
2122
|
+
return generate2({
|
|
2123
|
+
...opts,
|
|
2124
|
+
cwd,
|
|
2125
|
+
name,
|
|
2126
|
+
onConflict: createConflictResolver({
|
|
2127
|
+
cwd,
|
|
2128
|
+
onConflict
|
|
2129
|
+
})
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
async function model(opts) {
|
|
2133
|
+
let { name } = opts;
|
|
2134
|
+
const generate2 = createGenerator({
|
|
2135
|
+
dir: (0, import_path12.join)("app", "models"),
|
|
2136
|
+
template: model_default2
|
|
2137
|
+
});
|
|
2138
|
+
await modelMigration({ ...opts, name });
|
|
2139
|
+
name = chain(name).pipe(import_path12.posix.basename).pipe(import_inflection19.singularize).value();
|
|
2140
|
+
return generate2({
|
|
2141
|
+
...opts,
|
|
2142
|
+
name
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
function middleware(opts) {
|
|
2146
|
+
let { name } = opts;
|
|
2147
|
+
const parts = name.split("/");
|
|
2148
|
+
name = parts.pop() || name;
|
|
2149
|
+
const generate2 = createGenerator({
|
|
2150
|
+
dir: (0, import_path12.join)("app", "middleware", ...parts),
|
|
2151
|
+
template: middleware_default
|
|
2152
|
+
});
|
|
2153
|
+
return generate2({
|
|
2154
|
+
...opts,
|
|
2155
|
+
name
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
function util(opts) {
|
|
2159
|
+
let { name } = opts;
|
|
2160
|
+
const parts = name.split("/");
|
|
2161
|
+
name = parts.pop() || name;
|
|
2162
|
+
const generate2 = createGenerator({
|
|
2163
|
+
dir: (0, import_path12.join)("app", "utils", ...parts),
|
|
2164
|
+
template: util_default
|
|
2165
|
+
});
|
|
2166
|
+
return generate2({
|
|
2167
|
+
...opts,
|
|
2168
|
+
name
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
async function resource(opts) {
|
|
2172
|
+
await model(opts);
|
|
2173
|
+
await controller(opts);
|
|
2174
|
+
await serializer(opts);
|
|
2175
|
+
if (import_path12.posix.dirname(opts.name) !== ".") {
|
|
2176
|
+
log(NAMESPACED_RESOURCE_MESSAGE);
|
|
2177
|
+
return;
|
|
2178
|
+
}
|
|
2179
|
+
const path6 = (0, import_path12.join)(opts.cwd, "app", "routes.js");
|
|
2180
|
+
const routes = chain(await readFile(path6)).pipe((buf) => buf.toString("utf8")).pipe((str) => str.split("\n")).pipe(
|
|
2181
|
+
(lines) => lines.reduce((result, line2, index, arr) => {
|
|
2182
|
+
const closeIndex = arr.lastIndexOf("}");
|
|
2183
|
+
let str = result;
|
|
2184
|
+
if (line2 && index <= closeIndex) {
|
|
2185
|
+
str += `${line2}
|
|
2186
|
+
`;
|
|
2187
|
+
}
|
|
2188
|
+
if (index + 1 === closeIndex) {
|
|
2189
|
+
str += ` this.resource('${(0, import_inflection19.pluralize)(opts.name)}');
|
|
2190
|
+
`;
|
|
2191
|
+
}
|
|
2192
|
+
return str;
|
|
2193
|
+
}, "")
|
|
2194
|
+
).value();
|
|
2195
|
+
await writeFile(path6, routes);
|
|
2196
|
+
log(`${(0, import_chalk8.green)("update")} app/routes.js`);
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
// src/packages/cli/generator/utils/generator-for.ts
|
|
2200
|
+
function generatorFor(type) {
|
|
2201
|
+
const normalized = type.toLowerCase();
|
|
2202
|
+
const generator = Reflect.get(generate_type_exports, normalized);
|
|
2203
|
+
if (!generator) {
|
|
2204
|
+
throw new Error(`Could not find a generator for '${type}'.`);
|
|
2205
|
+
}
|
|
2206
|
+
return generator;
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
// src/packages/cli/generator/index.ts
|
|
2210
|
+
async function runGenerator({
|
|
2211
|
+
cwd,
|
|
2212
|
+
type,
|
|
2213
|
+
name,
|
|
2214
|
+
attrs
|
|
2215
|
+
}) {
|
|
2216
|
+
const generator = generatorFor(type);
|
|
2217
|
+
const prompt = createPrompt();
|
|
2218
|
+
await generator({
|
|
2219
|
+
cwd,
|
|
2220
|
+
type,
|
|
2221
|
+
name,
|
|
2222
|
+
attrs,
|
|
2223
|
+
onConflict: (path6) => prompt.question(`${(0, import_chalk9.green)("?")} ${(0, import_chalk9.red)("Overwrite")} ${path6}? (Y/n)\r`)
|
|
2224
|
+
});
|
|
2225
|
+
prompt.close();
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
// src/packages/cli/commands/generate.ts
|
|
2229
|
+
function generate({
|
|
2230
|
+
cwd = CWD,
|
|
2231
|
+
name,
|
|
2232
|
+
type,
|
|
2233
|
+
attrs = []
|
|
2234
|
+
}) {
|
|
2235
|
+
return runGenerator({
|
|
2236
|
+
cwd,
|
|
2237
|
+
name,
|
|
2238
|
+
type,
|
|
2239
|
+
attrs
|
|
2240
|
+
});
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
// src/packages/cli/commands/create.ts
|
|
2244
|
+
async function create2(name, database) {
|
|
2245
|
+
const driver = driverFor(database);
|
|
2246
|
+
const project = `${CWD}/${name}`;
|
|
2247
|
+
await mkdir(project);
|
|
2248
|
+
await Promise.all([
|
|
2249
|
+
mkdir(`${project}/app`),
|
|
2250
|
+
mkdir(`${project}/config`),
|
|
2251
|
+
mkdir(`${project}/db`)
|
|
2252
|
+
]);
|
|
2253
|
+
await Promise.all([
|
|
2254
|
+
mkdir(`${project}/app/models`),
|
|
2255
|
+
mkdir(`${project}/app/serializers`),
|
|
2256
|
+
mkdir(`${project}/app/controllers`),
|
|
2257
|
+
mkdir(`${project}/app/middleware`),
|
|
2258
|
+
mkdir(`${project}/app/utils`),
|
|
2259
|
+
mkdir(`${project}/config/environments`),
|
|
2260
|
+
mkdir(`${project}/db/migrate`)
|
|
2261
|
+
]);
|
|
2262
|
+
await Promise.all([
|
|
2263
|
+
writeFile(`${project}/app/index.js`, application_default(name)),
|
|
2264
|
+
writeFile(`${project}/app/routes.js`, routes_default()),
|
|
2265
|
+
writeFile(
|
|
2266
|
+
`${project}/config/environments/development.js`,
|
|
2267
|
+
config_default(name, "development")
|
|
2268
|
+
),
|
|
2269
|
+
writeFile(
|
|
2270
|
+
`${project}/config/environments/test.js`,
|
|
2271
|
+
config_default(name, "test")
|
|
2272
|
+
),
|
|
2273
|
+
writeFile(
|
|
2274
|
+
`${project}/config/environments/production.js`,
|
|
2275
|
+
config_default(name, "production")
|
|
2276
|
+
),
|
|
2277
|
+
writeFile(`${project}/config/database.js`, database_default(name, driver)),
|
|
2278
|
+
writeFile(`${project}/db/seed.js`, seed_default()),
|
|
2279
|
+
writeFile(`${project}/README.md`, readme_default(name)),
|
|
2280
|
+
writeFile(`${project}/LICENSE`, license_default()),
|
|
2281
|
+
writeFile(`${project}/package.json`, package_json_default(name, driver)),
|
|
2282
|
+
writeFile(`${project}/eslint.config.mjs`, eslint_config_default()),
|
|
2283
|
+
writeFile(`${project}/.gitignore`, gitignore_default())
|
|
2284
|
+
]);
|
|
2285
|
+
const logOutput = template`
|
|
2286
|
+
${(0, import_chalk10.green)("create")} app/index.js
|
|
2287
|
+
${(0, import_chalk10.green)("create")} app/routes.js
|
|
2288
|
+
${(0, import_chalk10.green)("create")} bin/app.js
|
|
2289
|
+
${(0, import_chalk10.green)("create")} config/environments/development.js
|
|
2290
|
+
${(0, import_chalk10.green)("create")} config/environments/test.js
|
|
2291
|
+
${(0, import_chalk10.green)("create")} config/environments/production.js
|
|
2292
|
+
${(0, import_chalk10.green)("create")} config/database.js
|
|
2293
|
+
${(0, import_chalk10.green)("create")} db/migrate
|
|
2294
|
+
${(0, import_chalk10.green)("create")} db/seed.js
|
|
2295
|
+
${(0, import_chalk10.green)("create")} README.md
|
|
2296
|
+
${(0, import_chalk10.green)("create")} LICENSE
|
|
2297
|
+
${(0, import_chalk10.green)("create")} package.json
|
|
2298
|
+
${(0, import_chalk10.green)("create")} eslint.config.mjs
|
|
2299
|
+
${(0, import_chalk10.green)("create")} .gitignore
|
|
2300
|
+
`;
|
|
2301
|
+
process.stdout.write(logOutput.substr(0, logOutput.length - 1));
|
|
2302
|
+
process.stdout.write(import_os3.EOL);
|
|
2303
|
+
await Promise.all([
|
|
2304
|
+
generate({
|
|
2305
|
+
cwd: project,
|
|
2306
|
+
type: "serializer",
|
|
2307
|
+
name: "application"
|
|
2308
|
+
}),
|
|
2309
|
+
generate({
|
|
2310
|
+
cwd: project,
|
|
2311
|
+
type: "controller",
|
|
2312
|
+
name: "application"
|
|
2313
|
+
})
|
|
2314
|
+
]);
|
|
2315
|
+
await exec("git init && git add .", {
|
|
2316
|
+
cwd: project
|
|
2317
|
+
});
|
|
2318
|
+
process.stdout.write(`${(0, import_chalk10.green)("initialize")} git`);
|
|
2319
|
+
process.stdout.write(import_os3.EOL);
|
|
2320
|
+
const spinner = new import_ora2.default({
|
|
2321
|
+
text: "Installing dependencies from npm...",
|
|
2322
|
+
spinner: "dots"
|
|
2323
|
+
});
|
|
2324
|
+
spinner.start();
|
|
2325
|
+
await exec("npm install", {
|
|
2326
|
+
cwd: project
|
|
2327
|
+
});
|
|
2328
|
+
spinner.stop();
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
// src/packages/cli/commands/dbcreate.ts
|
|
2332
|
+
var import_os4 = require("os");
|
|
2333
|
+
|
|
2334
|
+
// src/utils/github.ts
|
|
2335
|
+
var GITHUB_URL = "https://github.com/nickschot/lux";
|
|
2336
|
+
function fileLink(path6, opts = {}) {
|
|
2337
|
+
const { line: line2, branch = "master" } = opts;
|
|
2338
|
+
let link = `${GITHUB_URL}/blob/${branch}/${path6}`;
|
|
2339
|
+
if (line2 && line2 >= 0) {
|
|
2340
|
+
link += `#${line2}`;
|
|
2341
|
+
}
|
|
2342
|
+
return link;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
// src/packages/cli/constants.ts
|
|
2346
|
+
var DB_INTERFACE_URL = fileLink("src/packages/database/interfaces.js", {
|
|
2347
|
+
line: 17
|
|
2348
|
+
});
|
|
2349
|
+
var CONNECTION_STRING_MESSAGE = template`
|
|
2350
|
+
|
|
2351
|
+
You're using a URL in your database config (config/database.js).
|
|
2352
|
+
|
|
2353
|
+
In that case, Lumen assumes you don't need to create or drop your database.
|
|
2354
|
+
If you'd like to create or drop a database, set up your database config
|
|
2355
|
+
without the url.
|
|
2356
|
+
|
|
2357
|
+
For guidance, see:
|
|
2358
|
+
${DB_INTERFACE_URL}
|
|
2359
|
+
`;
|
|
2360
|
+
|
|
2361
|
+
// src/packages/cli/errors/database-config-missing.ts
|
|
2362
|
+
var DatabaseConfigMissingError = class extends ReferenceError {
|
|
2363
|
+
constructor(environment) {
|
|
2364
|
+
super(`Could not find database config for environment "${environment}".`);
|
|
2365
|
+
}
|
|
2366
|
+
};
|
|
2367
|
+
var database_config_missing_default = DatabaseConfigMissingError;
|
|
2368
|
+
|
|
2369
|
+
// src/packages/loader/utils/bundle-for.ts
|
|
2370
|
+
var import_path13 = require("path");
|
|
2371
|
+
|
|
2372
|
+
// src/packages/config/index.ts
|
|
2373
|
+
function createDefaultConfig() {
|
|
2374
|
+
const isTestENV = NODE_ENV === "test";
|
|
2375
|
+
const isProdENV = NODE_ENV === "production";
|
|
2376
|
+
return {
|
|
2377
|
+
server: {
|
|
2378
|
+
cors: {
|
|
2379
|
+
enabled: false
|
|
2380
|
+
}
|
|
2381
|
+
},
|
|
2382
|
+
logging: {
|
|
2383
|
+
level: isProdENV ? "INFO" : "DEBUG",
|
|
2384
|
+
format: isProdENV ? "json" : "text",
|
|
2385
|
+
enabled: !isTestENV,
|
|
2386
|
+
filter: {
|
|
2387
|
+
params: []
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2393
|
+
// src/utils/merge.ts
|
|
2394
|
+
function hasOwnProperty2(target, key) {
|
|
2395
|
+
return Reflect.apply(Object.prototype.hasOwnProperty, target, [key]);
|
|
2396
|
+
}
|
|
2397
|
+
function merge(dest, source) {
|
|
2398
|
+
return entries(source).reduce(
|
|
2399
|
+
(result, [key, value]) => {
|
|
2400
|
+
if (hasOwnProperty2(result, key) && isObject(value)) {
|
|
2401
|
+
const currentValue = Reflect.get(result, key);
|
|
2402
|
+
if (isObject(currentValue)) {
|
|
2403
|
+
return {
|
|
2404
|
+
...result,
|
|
2405
|
+
[key]: merge(currentValue, value)
|
|
2406
|
+
};
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
return {
|
|
2410
|
+
...result,
|
|
2411
|
+
[key]: value
|
|
2412
|
+
};
|
|
2413
|
+
},
|
|
2414
|
+
{ ...dest }
|
|
2415
|
+
);
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
// src/packages/loader/utils/format-key.ts
|
|
2419
|
+
var import_inflection20 = require("inflection");
|
|
2420
|
+
var NAMESPACE_DELIMITER = /\$-/g;
|
|
2421
|
+
function formatKey(key, formatter) {
|
|
2422
|
+
return chain(key).pipe((str) => {
|
|
2423
|
+
if (formatter) {
|
|
2424
|
+
return formatter(str);
|
|
2425
|
+
}
|
|
2426
|
+
return str;
|
|
2427
|
+
}).pipe(underscore).pipe(import_inflection20.dasherize).pipe((str) => str.replace(NAMESPACE_DELIMITER, "/")).value();
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
// src/packages/loader/utils/bundle-for.ts
|
|
2431
|
+
var SUFFIX_PATTERN = /^.+(Controller|Down|Serializer|Up)/;
|
|
2432
|
+
function normalize(manifest) {
|
|
2433
|
+
return entries(manifest).reduce(
|
|
2434
|
+
(obj, [key, value]) => {
|
|
2435
|
+
if (SUFFIX_PATTERN.test(key)) {
|
|
2436
|
+
const suffix = key.replace(SUFFIX_PATTERN, "$1");
|
|
2437
|
+
const stripSuffix = (source) => source.replace(suffix, "");
|
|
2438
|
+
switch (suffix) {
|
|
2439
|
+
case "Controller":
|
|
2440
|
+
obj.controllers.set(formatKey(key, stripSuffix), value);
|
|
2441
|
+
break;
|
|
2442
|
+
case "Serializer":
|
|
2443
|
+
obj.serializers.set(formatKey(key, stripSuffix), value);
|
|
2444
|
+
break;
|
|
2445
|
+
case "Up":
|
|
2446
|
+
case "Down":
|
|
2447
|
+
obj.migrations.set(
|
|
2448
|
+
formatKey(key),
|
|
2449
|
+
Reflect.construct(migration_default, [value])
|
|
2450
|
+
);
|
|
2451
|
+
break;
|
|
2452
|
+
default:
|
|
2453
|
+
break;
|
|
2454
|
+
}
|
|
2455
|
+
} else {
|
|
2456
|
+
switch (key) {
|
|
2457
|
+
case "Application":
|
|
2458
|
+
case "routes":
|
|
2459
|
+
case "seed":
|
|
2460
|
+
Reflect.set(obj, formatKey(key), value);
|
|
2461
|
+
break;
|
|
2462
|
+
case "config":
|
|
2463
|
+
Reflect.set(obj, "config", {
|
|
2464
|
+
...merge(createDefaultConfig(), {
|
|
2465
|
+
...obj.config,
|
|
2466
|
+
...value
|
|
2467
|
+
})
|
|
2468
|
+
});
|
|
2469
|
+
break;
|
|
2470
|
+
case "database":
|
|
2471
|
+
Reflect.set(obj, "config", {
|
|
2472
|
+
...obj.config,
|
|
2473
|
+
database: value
|
|
2474
|
+
});
|
|
2475
|
+
break;
|
|
2476
|
+
default:
|
|
2477
|
+
obj.models.set(formatKey(key), value);
|
|
2478
|
+
break;
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
return obj;
|
|
2482
|
+
},
|
|
2483
|
+
{
|
|
2484
|
+
config: {},
|
|
2485
|
+
controllers: new map_default(),
|
|
2486
|
+
migrations: new map_default(),
|
|
2487
|
+
models: new map_default(),
|
|
2488
|
+
serializers: new map_default()
|
|
2489
|
+
}
|
|
2490
|
+
);
|
|
2491
|
+
}
|
|
2492
|
+
function bundleFor(path6) {
|
|
2493
|
+
const manifest = Reflect.apply(require, null, [
|
|
2494
|
+
(0, import_path13.join)(path6, "dist", "bundle")
|
|
2495
|
+
]);
|
|
2496
|
+
return chain(manifest).pipe(normalize).pipe(entries).pipe((pairs) => new map_default(pairs)).value().freeze();
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
// src/packages/loader/index.ts
|
|
2500
|
+
function createLoader(path6) {
|
|
2501
|
+
let bundle;
|
|
2502
|
+
return function load(type) {
|
|
2503
|
+
if (!bundle) {
|
|
2504
|
+
bundle = bundleFor(path6);
|
|
2505
|
+
}
|
|
2506
|
+
return bundle.get(type);
|
|
2507
|
+
};
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
// src/packages/cli/commands/dbcreate.ts
|
|
2511
|
+
function dbcreate() {
|
|
2512
|
+
const load = createLoader(CWD);
|
|
2513
|
+
const config = Reflect.get(load("config").database, NODE_ENV);
|
|
2514
|
+
if (!config) {
|
|
2515
|
+
throw new database_config_missing_default(NODE_ENV);
|
|
2516
|
+
}
|
|
2517
|
+
if (config.driver === "sqlite3") {
|
|
2518
|
+
return writeFile(`${CWD}/db/${config.database}_${NODE_ENV}.sqlite`, "");
|
|
2519
|
+
}
|
|
2520
|
+
if (DATABASE_URL || config.url) {
|
|
2521
|
+
process.stderr.write(CONNECTION_STRING_MESSAGE);
|
|
2522
|
+
process.stderr.write(import_os4.EOL);
|
|
2523
|
+
return Promise.resolve();
|
|
2524
|
+
}
|
|
2525
|
+
const { schema } = connect(CWD, config);
|
|
2526
|
+
const query = `CREATE DATABASE ${config.database}`;
|
|
2527
|
+
const raw = schema.raw(query);
|
|
2528
|
+
return raw.once("query", () => {
|
|
2529
|
+
process.stdout.write(query);
|
|
2530
|
+
process.stdout.write(import_os4.EOL);
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
// src/packages/cli/commands/dbdrop.ts
|
|
2535
|
+
var import_os5 = require("os");
|
|
2536
|
+
function dbdrop() {
|
|
2537
|
+
const load = createLoader(CWD);
|
|
2538
|
+
const config = Reflect.get(load("config").database, NODE_ENV);
|
|
2539
|
+
if (!config) {
|
|
2540
|
+
throw new database_config_missing_default(NODE_ENV);
|
|
2541
|
+
}
|
|
2542
|
+
if (config.driver === "sqlite3") {
|
|
2543
|
+
return rmrf_default(`${CWD}/db/${config.database}_${NODE_ENV}.sqlite`);
|
|
2544
|
+
}
|
|
2545
|
+
if (DATABASE_URL || config.url) {
|
|
2546
|
+
process.stderr.write(CONNECTION_STRING_MESSAGE);
|
|
2547
|
+
process.stderr.write(import_os5.EOL);
|
|
2548
|
+
return Promise.resolve();
|
|
2549
|
+
}
|
|
2550
|
+
const { schema } = connect(CWD, config);
|
|
2551
|
+
const query = `DROP DATABASE IF EXISTS ${config.database}`;
|
|
2552
|
+
const raw = schema.raw(query);
|
|
2553
|
+
return raw.once("query", () => {
|
|
2554
|
+
process.stdout.write(query);
|
|
2555
|
+
process.stdout.write(import_os5.EOL);
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
// src/packages/cli/commands/dbmigrate.ts
|
|
2560
|
+
var import_os6 = require("os");
|
|
2561
|
+
async function dbmigrate() {
|
|
2562
|
+
const load = createLoader(CWD);
|
|
2563
|
+
const { database: config } = load("config");
|
|
2564
|
+
const models = load("models");
|
|
2565
|
+
const migrations = load("migrations");
|
|
2566
|
+
const { connection, schema } = await new database_default2({
|
|
2567
|
+
config,
|
|
2568
|
+
models,
|
|
2569
|
+
path: CWD,
|
|
2570
|
+
checkMigrations: false,
|
|
2571
|
+
logger: new logger_default({ enabled: false })
|
|
2572
|
+
});
|
|
2573
|
+
const pending = await pendingMigrations(CWD, () => connection("migrations"));
|
|
2574
|
+
if (pending.length) {
|
|
2575
|
+
const runners = pending.map((name) => {
|
|
2576
|
+
const version2 = name.replace(/^(\d{16})-.+$/g, "$1");
|
|
2577
|
+
const key = name.replace(new RegExp(`${version2}-(.+)\\.js`), "$1");
|
|
2578
|
+
return [version2, migrations.get(`${key}-up`)];
|
|
2579
|
+
}).filter(([, migration2]) => Boolean(migration2)).reverse().map(([version2, migration2]) => () => {
|
|
2580
|
+
const query = migration2.run(schema());
|
|
2581
|
+
return query.on("query", () => {
|
|
2582
|
+
process.stdout.write(sql`${query.toString()}`);
|
|
2583
|
+
process.stdout.write(import_os6.EOL);
|
|
2584
|
+
}).then(
|
|
2585
|
+
() => connection("migrations").insert({
|
|
2586
|
+
version: version2
|
|
2587
|
+
})
|
|
2588
|
+
);
|
|
2589
|
+
});
|
|
2590
|
+
await composeAsync(...runners)();
|
|
2591
|
+
}
|
|
2592
|
+
return true;
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
// src/packages/cli/commands/dbrollback.ts
|
|
2596
|
+
var import_os7 = require("os");
|
|
2597
|
+
async function dbrollback() {
|
|
2598
|
+
const load = createLoader(CWD);
|
|
2599
|
+
const { database: config } = load("config");
|
|
2600
|
+
const models = load("models");
|
|
2601
|
+
const migrations = load("migrations");
|
|
2602
|
+
const { connection, schema } = await new database_default2({
|
|
2603
|
+
config,
|
|
2604
|
+
models,
|
|
2605
|
+
path: CWD,
|
|
2606
|
+
checkMigrations: false,
|
|
2607
|
+
logger: new logger_default({ enabled: false })
|
|
2608
|
+
});
|
|
2609
|
+
const migrationFiles = await readdir(`${CWD}/db/migrate`);
|
|
2610
|
+
if (migrationFiles.length) {
|
|
2611
|
+
let migration2;
|
|
2612
|
+
let version2 = await connection("migrations").orderBy("version", "desc").first();
|
|
2613
|
+
if (version2 && version2.version) {
|
|
2614
|
+
version2 = version2.version;
|
|
2615
|
+
}
|
|
2616
|
+
const target = migrationFiles.find((m) => m.indexOf(version2) === 0);
|
|
2617
|
+
if (target) {
|
|
2618
|
+
migration2 = target.replace(new RegExp(`${version2}-(.+)\\.js`), "$1");
|
|
2619
|
+
migration2 = migrations.get(`${migration2}-down`);
|
|
2620
|
+
if (migration2) {
|
|
2621
|
+
const query = migration2.run(schema());
|
|
2622
|
+
await query.on("query", () => {
|
|
2623
|
+
process.stdout.write(sql`${query.toString()}`);
|
|
2624
|
+
process.stdout.write(import_os7.EOL);
|
|
2625
|
+
});
|
|
2626
|
+
await connection("migrations").where({
|
|
2627
|
+
version: version2
|
|
2628
|
+
}).del();
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
// src/packages/cli/commands/dbseed.ts
|
|
2635
|
+
function dbseed() {
|
|
2636
|
+
const load = createLoader(CWD);
|
|
2637
|
+
const { database: config } = load("config");
|
|
2638
|
+
const seed = load("seed");
|
|
2639
|
+
const models = load("models");
|
|
2640
|
+
return new database_default2({
|
|
2641
|
+
config,
|
|
2642
|
+
models,
|
|
2643
|
+
path: CWD,
|
|
2644
|
+
logger: new logger_default({
|
|
2645
|
+
enabled: false
|
|
2646
|
+
})
|
|
2647
|
+
}).then((store) => store.connection.transaction(seed));
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
// src/packages/cli/commands/destroy.ts
|
|
2651
|
+
var import_os8 = require("os");
|
|
2652
|
+
var import_chalk11 = require("chalk");
|
|
2653
|
+
var import_inflection21 = require("inflection");
|
|
2654
|
+
async function destroyType(type, name) {
|
|
2655
|
+
const normalizedType = type.toLowerCase();
|
|
2656
|
+
let normalizedName = name;
|
|
2657
|
+
let path6;
|
|
2658
|
+
let migrations;
|
|
2659
|
+
switch (normalizedType) {
|
|
2660
|
+
case "model":
|
|
2661
|
+
normalizedName = (0, import_inflection21.singularize)(normalizedName);
|
|
2662
|
+
path6 = `app/${(0, import_inflection21.pluralize)(normalizedType)}/${normalizedName}.js`;
|
|
2663
|
+
break;
|
|
2664
|
+
case "migration":
|
|
2665
|
+
migrations = await readdir(`${CWD}/db/migrate`);
|
|
2666
|
+
normalizedName = migrations.find(
|
|
2667
|
+
(file) => `${normalizedName}.js` === file.substr(17)
|
|
2668
|
+
);
|
|
2669
|
+
path6 = `db/migrate/${normalizedName}`;
|
|
2670
|
+
break;
|
|
2671
|
+
case "controller":
|
|
2672
|
+
case "serializer":
|
|
2673
|
+
normalizedName = (0, import_inflection21.pluralize)(normalizedName);
|
|
2674
|
+
path6 = `app/${(0, import_inflection21.pluralize)(normalizedType)}/${normalizedName}.js`;
|
|
2675
|
+
break;
|
|
2676
|
+
case "middleware":
|
|
2677
|
+
path6 = `app/${normalizedType}/${normalizedName}.js`;
|
|
2678
|
+
break;
|
|
2679
|
+
case "util":
|
|
2680
|
+
path6 = `app/${(0, import_inflection21.pluralize)(normalizedType)}/${normalizedName}.js`;
|
|
2681
|
+
break;
|
|
2682
|
+
default:
|
|
2683
|
+
return;
|
|
2684
|
+
}
|
|
2685
|
+
if (await exists(`${CWD}/${path6}`)) {
|
|
2686
|
+
await rmrf_default(`${CWD}/${path6}`);
|
|
2687
|
+
process.stdout.write(`${(0, import_chalk11.red)("remove")} ${path6}`);
|
|
2688
|
+
process.stdout.write(import_os8.EOL);
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
async function destroy2({ type, name }) {
|
|
2692
|
+
if (type === "resource") {
|
|
2693
|
+
const routes = (await readFile(`${CWD}/app/routes.js`)).toString("utf8").split("\n").reduce((lines, line2) => {
|
|
2694
|
+
const pattern = new RegExp(
|
|
2695
|
+
`\\s*this.resource\\(('|"|\`)${(0, import_inflection21.pluralize)(name)}('|"|\`)\\);?`
|
|
2696
|
+
);
|
|
2697
|
+
return pattern.test(line2) ? lines : [...lines, line2];
|
|
2698
|
+
}, []).join("\n");
|
|
2699
|
+
await Promise.all([
|
|
2700
|
+
destroyType("model", name),
|
|
2701
|
+
destroyType("migration", `create-${(0, import_inflection21.pluralize)(name)}`),
|
|
2702
|
+
destroyType("serializer", name),
|
|
2703
|
+
destroyType("controller", name)
|
|
2704
|
+
]);
|
|
2705
|
+
await writeFile(`${CWD}/app/routes.js`, routes);
|
|
2706
|
+
process.stdout.write(`${(0, import_chalk11.green)("update")} app/routes.js`);
|
|
2707
|
+
process.stdout.write(import_os8.EOL);
|
|
2708
|
+
} else if (type === "model") {
|
|
2709
|
+
await Promise.all([
|
|
2710
|
+
destroyType(type, name),
|
|
2711
|
+
destroyType("migration", `create-${(0, import_inflection21.pluralize)(name)}`)
|
|
2712
|
+
]);
|
|
2713
|
+
} else {
|
|
2714
|
+
await destroyType(type, name);
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2718
|
+
// src/packages/cli/commands/repl.ts
|
|
2719
|
+
var import_path14 = __toESM(require("path"));
|
|
2720
|
+
var import_repl = require("repl");
|
|
2721
|
+
function repl() {
|
|
2722
|
+
return new Promise(async (resolve2) => {
|
|
2723
|
+
const app = await Reflect.apply(require, null, [
|
|
2724
|
+
import_path14.default.join(CWD, "dist", "boot")
|
|
2725
|
+
]);
|
|
2726
|
+
const instance = (0, import_repl.start)({
|
|
2727
|
+
prompt: "> "
|
|
2728
|
+
});
|
|
2729
|
+
instance.once("exit", resolve2);
|
|
2730
|
+
Object.assign(instance.context, {
|
|
2731
|
+
app,
|
|
2732
|
+
logger: app.logger,
|
|
2733
|
+
routes: app.router,
|
|
2734
|
+
[app.constructor.name]: app,
|
|
2735
|
+
...Array.from(app.models).reduce(
|
|
2736
|
+
(context, [, model2]) => ({
|
|
2737
|
+
...context,
|
|
2738
|
+
[model2.name]: model2
|
|
2739
|
+
}),
|
|
2740
|
+
{}
|
|
2741
|
+
),
|
|
2742
|
+
...Array.from(app.controllers).reduce(
|
|
2743
|
+
(context, [, controller2]) => ({
|
|
2744
|
+
...context,
|
|
2745
|
+
[controller2.constructor.name]: controller2
|
|
2746
|
+
}),
|
|
2747
|
+
{}
|
|
2748
|
+
),
|
|
2749
|
+
...Array.from(app.serializers).reduce(
|
|
2750
|
+
(context, [, serializer2]) => ({
|
|
2751
|
+
...context,
|
|
2752
|
+
[serializer2.constructor.name]: serializer2
|
|
2753
|
+
}),
|
|
2754
|
+
{}
|
|
2755
|
+
)
|
|
2756
|
+
});
|
|
2757
|
+
});
|
|
2758
|
+
}
|
|
2759
|
+
|
|
2760
|
+
// src/packages/cli/commands/serve.ts
|
|
2761
|
+
var import_chalk13 = require("chalk");
|
|
2762
|
+
|
|
2763
|
+
// src/packages/pm/cluster/index.ts
|
|
2764
|
+
var import_events2 = __toESM(require("events"));
|
|
2765
|
+
var import_os9 = __toESM(require("os"));
|
|
2766
|
+
var import_cluster2 = __toESM(require("cluster"));
|
|
2767
|
+
var import_path15 = require("path");
|
|
2768
|
+
var import_chalk12 = require("chalk");
|
|
2769
|
+
|
|
2770
|
+
// src/utils/range.ts
|
|
2771
|
+
function* range(start, end) {
|
|
2772
|
+
for (let i = start; i <= end; i += 1) {
|
|
2773
|
+
yield i;
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
// src/packages/pm/cluster/index.ts
|
|
2778
|
+
var Cluster = class extends import_events2.default {
|
|
2779
|
+
constructor({ path: path6, port, logger, maxWorkers }) {
|
|
2780
|
+
super();
|
|
2781
|
+
Object.defineProperties(this, {
|
|
2782
|
+
path: {
|
|
2783
|
+
value: path6,
|
|
2784
|
+
writable: false,
|
|
2785
|
+
enumerable: true,
|
|
2786
|
+
configurable: false
|
|
2787
|
+
},
|
|
2788
|
+
port: {
|
|
2789
|
+
value: port,
|
|
2790
|
+
writable: false,
|
|
2791
|
+
enumerable: true,
|
|
2792
|
+
configurable: false
|
|
2793
|
+
},
|
|
2794
|
+
logger: {
|
|
2795
|
+
value: logger,
|
|
2796
|
+
writable: false,
|
|
2797
|
+
enumerable: true,
|
|
2798
|
+
configurable: false
|
|
2799
|
+
},
|
|
2800
|
+
workers: {
|
|
2801
|
+
value: /* @__PURE__ */ new Set(),
|
|
2802
|
+
writable: false,
|
|
2803
|
+
enumerable: true,
|
|
2804
|
+
configurable: false
|
|
2805
|
+
},
|
|
2806
|
+
maxWorkers: {
|
|
2807
|
+
value: maxWorkers || import_os9.default.cpus().length,
|
|
2808
|
+
writable: false,
|
|
2809
|
+
enumerable: true,
|
|
2810
|
+
configurable: false
|
|
2811
|
+
}
|
|
2812
|
+
});
|
|
2813
|
+
import_cluster2.default.setupMaster({
|
|
2814
|
+
exec: (0, import_path15.join)(path6, "dist", "boot.js")
|
|
2815
|
+
});
|
|
2816
|
+
process.on("update", (changed) => {
|
|
2817
|
+
changed.forEach(({ name: filename }) => {
|
|
2818
|
+
logger.info(`${(0, import_chalk12.green)("update")} ${filename}`);
|
|
2819
|
+
});
|
|
2820
|
+
this.reload();
|
|
2821
|
+
});
|
|
2822
|
+
this.forkAll().then(() => this.emit("ready"));
|
|
2823
|
+
}
|
|
2824
|
+
fork(retry = true) {
|
|
2825
|
+
return new Promise((resolve2) => {
|
|
2826
|
+
if (this.workers.size < this.maxWorkers) {
|
|
2827
|
+
const worker = import_cluster2.default.fork({
|
|
2828
|
+
NODE_ENV,
|
|
2829
|
+
PORT: this.port
|
|
2830
|
+
});
|
|
2831
|
+
const timeout = setTimeout(() => {
|
|
2832
|
+
this.logger.info(line`
|
|
2833
|
+
Removing worker process: ${(0, import_chalk12.red)(`${worker.process.pid}`)}
|
|
2834
|
+
`);
|
|
2835
|
+
clearTimeout(timeout);
|
|
2836
|
+
worker.removeAllListeners();
|
|
2837
|
+
worker.kill();
|
|
2838
|
+
this.workers.delete(worker);
|
|
2839
|
+
resolve2(worker);
|
|
2840
|
+
if (retry) {
|
|
2841
|
+
this.fork(false);
|
|
2842
|
+
}
|
|
2843
|
+
}, 3e4);
|
|
2844
|
+
const handleError = (err) => {
|
|
2845
|
+
if (err) {
|
|
2846
|
+
this.logger.error(err);
|
|
2847
|
+
}
|
|
2848
|
+
this.logger.info(line`
|
|
2849
|
+
Removing worker process: ${(0, import_chalk12.red)(`${worker.process.pid}`)}
|
|
2850
|
+
`);
|
|
2851
|
+
clearTimeout(timeout);
|
|
2852
|
+
worker.removeAllListeners();
|
|
2853
|
+
worker.kill();
|
|
2854
|
+
this.workers.delete(worker);
|
|
2855
|
+
resolve2(worker);
|
|
2856
|
+
};
|
|
2857
|
+
worker.on("message", (msg) => {
|
|
2858
|
+
let data = {};
|
|
2859
|
+
let message = msg;
|
|
2860
|
+
if (typeof message === "object") {
|
|
2861
|
+
data = omit(message, "message");
|
|
2862
|
+
message = message.message;
|
|
2863
|
+
}
|
|
2864
|
+
switch (message) {
|
|
2865
|
+
case "ready":
|
|
2866
|
+
this.logger.info(line`
|
|
2867
|
+
Adding worker process: ${(0, import_chalk12.green)(`${worker.process.pid}`)}
|
|
2868
|
+
`);
|
|
2869
|
+
this.workers.add(worker);
|
|
2870
|
+
clearTimeout(timeout);
|
|
2871
|
+
worker.removeListener("error", handleError);
|
|
2872
|
+
resolve2(worker);
|
|
2873
|
+
break;
|
|
2874
|
+
case "error":
|
|
2875
|
+
handleError(data.error);
|
|
2876
|
+
break;
|
|
2877
|
+
default:
|
|
2878
|
+
break;
|
|
2879
|
+
}
|
|
2880
|
+
});
|
|
2881
|
+
worker.once("error", handleError);
|
|
2882
|
+
worker.once("exit", (code) => {
|
|
2883
|
+
const {
|
|
2884
|
+
process: { pid }
|
|
2885
|
+
} = worker;
|
|
2886
|
+
if (typeof code === "number") {
|
|
2887
|
+
this.logger.info(line`
|
|
2888
|
+
Worker process: ${(0, import_chalk12.red)(`${pid}`)} exited with code ${code}
|
|
2889
|
+
`);
|
|
2890
|
+
}
|
|
2891
|
+
this.logger.info(`Removing worker process: ${(0, import_chalk12.red)(`${pid}`)}`);
|
|
2892
|
+
clearTimeout(timeout);
|
|
2893
|
+
worker.removeAllListeners();
|
|
2894
|
+
this.workers.delete(worker);
|
|
2895
|
+
this.fork();
|
|
2896
|
+
});
|
|
2897
|
+
}
|
|
2898
|
+
});
|
|
2899
|
+
}
|
|
2900
|
+
shutdown(worker) {
|
|
2901
|
+
return new Promise((resolve2) => {
|
|
2902
|
+
this.workers.delete(worker);
|
|
2903
|
+
const timeout = setTimeout(() => worker.kill(), 5e3);
|
|
2904
|
+
worker.once("disconnect", () => {
|
|
2905
|
+
worker.kill();
|
|
2906
|
+
});
|
|
2907
|
+
worker.once("exit", () => {
|
|
2908
|
+
resolve2(worker);
|
|
2909
|
+
clearTimeout(timeout);
|
|
2910
|
+
});
|
|
2911
|
+
worker.send("shutdown");
|
|
2912
|
+
worker.disconnect();
|
|
2913
|
+
});
|
|
2914
|
+
}
|
|
2915
|
+
reload() {
|
|
2916
|
+
if (this.workers.size) {
|
|
2917
|
+
const groups = Array.from(this.workers).reduce((arr, item, idx, src) => {
|
|
2918
|
+
if ((idx + 1) % 2) {
|
|
2919
|
+
const group = src.slice(idx, idx + 2);
|
|
2920
|
+
return [
|
|
2921
|
+
...arr,
|
|
2922
|
+
() => Promise.all(group.map((worker) => this.shutdown(worker)))
|
|
2923
|
+
];
|
|
2924
|
+
}
|
|
2925
|
+
return arr;
|
|
2926
|
+
}, []);
|
|
2927
|
+
return composeAsync(...groups)();
|
|
2928
|
+
}
|
|
2929
|
+
return this.fork();
|
|
2930
|
+
}
|
|
2931
|
+
forkAll() {
|
|
2932
|
+
return Promise.race(
|
|
2933
|
+
Array.from(range(1, this.maxWorkers)).map(() => this.fork())
|
|
2934
|
+
);
|
|
2935
|
+
}
|
|
2936
|
+
};
|
|
2937
|
+
var cluster_default = Cluster;
|
|
2938
|
+
|
|
2939
|
+
// src/packages/pm/index.ts
|
|
2940
|
+
function createCluster({
|
|
2941
|
+
path: path6,
|
|
2942
|
+
port,
|
|
2943
|
+
logger,
|
|
2944
|
+
maxWorkers
|
|
2945
|
+
}) {
|
|
2946
|
+
return new cluster_default({
|
|
2947
|
+
path: path6,
|
|
2948
|
+
port,
|
|
2949
|
+
logger,
|
|
2950
|
+
maxWorkers
|
|
2951
|
+
});
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
// src/packages/cli/commands/serve.ts
|
|
2955
|
+
async function serve({
|
|
2956
|
+
hot = NODE_ENV === "development",
|
|
2957
|
+
cluster: cluster3 = false,
|
|
2958
|
+
useStrict = false
|
|
2959
|
+
}) {
|
|
2960
|
+
const load = createLoader(CWD);
|
|
2961
|
+
const { logging } = load("config");
|
|
2962
|
+
const logger = new logger_default(logging);
|
|
2963
|
+
if (hot) {
|
|
2964
|
+
const watcher = await watch(CWD);
|
|
2965
|
+
watcher.on("change", async (changed) => {
|
|
2966
|
+
await build2(useStrict);
|
|
2967
|
+
process.emit("update", changed);
|
|
2968
|
+
});
|
|
2969
|
+
}
|
|
2970
|
+
createCluster({
|
|
2971
|
+
logger,
|
|
2972
|
+
path: CWD,
|
|
2973
|
+
port: PORT,
|
|
2974
|
+
maxWorkers: cluster3 ? void 0 : 1
|
|
2975
|
+
}).once("ready", () => {
|
|
2976
|
+
logger.info(`Lumen Server listening on port: ${(0, import_chalk13.cyan)(`${PORT}`)}`);
|
|
2977
|
+
});
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
// src/packages/cli/commands/test.ts
|
|
2981
|
+
var import_os10 = require("os");
|
|
2982
|
+
function test() {
|
|
2983
|
+
process.stdout.write("Coming Soon!");
|
|
2984
|
+
process.stdout.write(import_os10.EOL);
|
|
2985
|
+
return Promise.resolve();
|
|
2986
|
+
}
|
|
2987
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2988
|
+
0 && (module.exports = {
|
|
2989
|
+
build,
|
|
2990
|
+
create,
|
|
2991
|
+
dbcreate,
|
|
2992
|
+
dbdrop,
|
|
2993
|
+
dbmigrate,
|
|
2994
|
+
dbrollback,
|
|
2995
|
+
dbseed,
|
|
2996
|
+
destroy,
|
|
2997
|
+
generate,
|
|
2998
|
+
repl,
|
|
2999
|
+
serve,
|
|
3000
|
+
test
|
|
3001
|
+
});
|
|
3002
|
+
//# sourceMappingURL=cli.cjs.map
|