@fc3/mmcadi 0.1.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 +673 -0
- package/README.md +5 -0
- package/bin/compile +63 -0
- package/bin/copy-static-files +13 -0
- package/bin/install +5 -0
- package/bin/precompile +55 -0
- package/bin/prepublish +7 -0
- package/bin/remap-paths +113 -0
- package/bin/test +9 -0
- package/config/tsconfig.json +37 -0
- package/package.json +33 -0
- package/src/bootstrap/start.ts +12 -0
- package/src/client/bootstrap.ts +5 -0
- package/src/client/client.ts +54 -0
- package/src/client/enum/key-code.ts +34 -0
- package/src/client/enum/page-type.ts +19 -0
- package/src/client/factory/page.ts +61 -0
- package/src/client/page/confirm-delete-block.ts +30 -0
- package/src/client/page/create-block.ts +6 -0
- package/src/client/page/day.ts +8 -0
- package/src/client/page/edit-block.ts +43 -0
- package/src/client/page/edit-custom.ts +16 -0
- package/src/client/page/home.ts +8 -0
- package/src/client/page/login.ts +8 -0
- package/src/client/page/logout.ts +8 -0
- package/src/client/page/month.ts +8 -0
- package/src/client/page/move-block.ts +8 -0
- package/src/client/page/select-block-type.ts +56 -0
- package/src/client/page/settings.ts +8 -0
- package/src/client/page/view-custom.ts +665 -0
- package/src/client/page/week.ts +8 -0
- package/src/client/page/year.ts +8 -0
- package/src/client/page.ts +128 -0
- package/src/client/shim/execute.ts +5 -0
- package/src/client/shim/logger.ts +44 -0
- package/src/client/utility/get-meta-value.ts +23 -0
- package/src/common/builder/block/background.ts +25 -0
- package/src/common/builder/block/folder.ts +43 -0
- package/src/common/builder/block/header.ts +15 -0
- package/src/common/builder/block/link.ts +32 -0
- package/src/common/builder/block/multicolumn.ts +16 -0
- package/src/common/builder/block/note.ts +13 -0
- package/src/common/builder/block/whitespace.ts +13 -0
- package/src/common/utility/get-parent-path.ts +29 -0
- package/src/constant/month-names.ts +16 -0
- package/src/enum/action-type.ts +11 -0
- package/src/enum/block-type.ts +18 -0
- package/src/enum/calendar-view-mode.ts +9 -0
- package/src/enum/color.ts +15 -0
- package/src/enum/default-role.ts +6 -0
- package/src/enum/directory-item-type.ts +6 -0
- package/src/enum/emoji.ts +94 -0
- package/src/enum/field-type.ts +8 -0
- package/src/enum/header-size.ts +7 -0
- package/src/enum/permission-type.ts +8 -0
- package/src/enum/time-place-visibility.ts +8 -0
- package/src/enum/tool-type.ts +14 -0
- package/src/index.ts +8 -0
- package/src/interface/hydration-callback.ts +7 -0
- package/src/interface/provider.ts +8 -0
- package/src/interface/repository.ts +12 -0
- package/src/lib/array/add.ts +10 -0
- package/src/lib/array/assert-is-empty.ts +23 -0
- package/src/lib/array/clone.ts +5 -0
- package/src/lib/array/difference.ts +8 -0
- package/src/lib/array/empty.ts +6 -0
- package/src/lib/array/equal.ts +24 -0
- package/src/lib/array/get-first-value.ts +5 -0
- package/src/lib/array/get-last-value.ts +5 -0
- package/src/lib/array/get-max-value.ts +5 -0
- package/src/lib/array/get-value-after.ts +23 -0
- package/src/lib/array/get-value-before.ts +23 -0
- package/src/lib/array/get-values-between.ts +18 -0
- package/src/lib/array/index.ts +5 -0
- package/src/lib/array/is-empty.ts +6 -0
- package/src/lib/array/remove.ts +19 -0
- package/src/lib/array/sum.ts +11 -0
- package/src/lib/array/unique.ts +13 -0
- package/src/lib/environment/bootstrap.ts +1 -0
- package/src/lib/environment/enum/environment-type.ts +8 -0
- package/src/lib/environment/enum/service-type.ts +5 -0
- package/src/lib/environment/index.ts +7 -0
- package/src/lib/environment/utility/get-environment-type.ts +28 -0
- package/src/lib/environment/utility/is-browser.ts +5 -0
- package/src/lib/environment/utility/is-development.ts +10 -0
- package/src/lib/environment/utility/is-production-or-staging.ts +8 -0
- package/src/lib/environment/utility/is-production.ts +10 -0
- package/src/lib/environment/utility/is-staging.ts +10 -0
- package/src/lib/errors/enum/error-type.ts +13 -0
- package/src/lib/errors/error/base.ts +40 -0
- package/src/lib/errors/error/conflict.ts +16 -0
- package/src/lib/errors/error/generic.ts +23 -0
- package/src/lib/errors/error/invalid.ts +14 -0
- package/src/lib/errors/error/invariant-violation.ts +5 -0
- package/src/lib/errors/error/not-allowed.ts +14 -0
- package/src/lib/errors/error/not-found.ts +16 -0
- package/src/lib/errors/error/not-implemented.ts +20 -0
- package/src/lib/errors/error/omitted.ts +14 -0
- package/src/lib/errors/error/timeout.ts +14 -0
- package/src/lib/errors/error/unauthorized.ts +14 -0
- package/src/lib/errors/index.ts +18 -0
- package/src/lib/errors/sugar/invariant.ts +7 -0
- package/src/lib/errors/type/coded-error.ts +7 -0
- package/src/lib/errors/type/error-data.ts +11 -0
- package/src/lib/errors/utility/create-error-for-error-type.ts +60 -0
- package/src/lib/errors/utility/create-error-from-ambiguous-json-data.ts +26 -0
- package/src/lib/errors/utility/error-matches.ts +28 -0
- package/src/lib/errors/utility/get-error-type-for-posix-error-code.ts +37 -0
- package/src/lib/errors/utility/get-error-type-for-status-code.ts +38 -0
- package/src/lib/errors/utility/get-message-for-error-type.ts +29 -0
- package/src/lib/errors/utility/matches-posix-error-code.ts +11 -0
- package/src/lib/errors/utility/wrap-error.ts +39 -0
- package/src/lib/event-emitter/index.ts +63 -0
- package/src/lib/execution-context/execution-context.ts +90 -0
- package/src/lib/execution-context/index.ts +8 -0
- package/src/lib/execution-context/type/session.ts +7 -0
- package/src/lib/feature/feature.ts +108 -0
- package/src/lib/feature/index.ts +3 -0
- package/src/lib/filesystem/bootstrap.ts +1 -0
- package/src/lib/filesystem/enum/file-extension.ts +19 -0
- package/src/lib/filesystem/index.ts +4 -0
- package/src/lib/filesystem/utility/exists.ts +21 -0
- package/src/lib/filesystem/utility/get-extension-for-filepath.ts +20 -0
- package/src/lib/filesystem/utility/strip-extension.ts +26 -0
- package/src/lib/grammar/index.ts +3 -0
- package/src/lib/grammar/noun-inflector.ts +104 -0
- package/src/lib/grammar/utility/get-words-from-identifier.ts +9 -0
- package/src/lib/grammar/verb-inflector.ts +344 -0
- package/src/lib/http/buffer-stream.ts +76 -0
- package/src/lib/http/enum/content-type.ts +19 -0
- package/src/lib/http/enum/cookie-attribute.ts +11 -0
- package/src/lib/http/enum/header.ts +29 -0
- package/src/lib/http/enum/method.ts +11 -0
- package/src/lib/http/enum/same-site-policy.ts +7 -0
- package/src/lib/http/enum/status-code.ts +9 -0
- package/src/lib/http/factory/body-parser.ts +55 -0
- package/src/lib/http/index.ts +24 -0
- package/src/lib/http/interface/client-request.ts +15 -0
- package/src/lib/http/interface/incoming-message.ts +24 -0
- package/src/lib/http/interface/network-library.ts +9 -0
- package/src/lib/http/interface/request-callback.ts +7 -0
- package/src/lib/http/isomorphic/request.ts +77 -0
- package/src/lib/http/isomorphic/response.ts +77 -0
- package/src/lib/http/isomorphic.ts +20 -0
- package/src/lib/http/parser/accept-header.ts +35 -0
- package/src/lib/http/parser/basic-auth-header.ts +48 -0
- package/src/lib/http/parser/body/json.ts +14 -0
- package/src/lib/http/parser/body/multipart.ts +89 -0
- package/src/lib/http/parser/body/url-encoded.ts +16 -0
- package/src/lib/http/parser/body.ts +44 -0
- package/src/lib/http/parser/cookie.ts +114 -0
- package/src/lib/http/parser/querystring.ts +92 -0
- package/src/lib/http/parser/url.ts +76 -0
- package/src/lib/http/request/incoming.ts +299 -0
- package/src/lib/http/request/outgoing.ts +276 -0
- package/src/lib/http/request.ts +26 -0
- package/src/lib/http/response/incoming.ts +243 -0
- package/src/lib/http/response/outgoing.ts +160 -0
- package/src/lib/http/response.ts +74 -0
- package/src/lib/http/serializer/basic-auth-header.ts +27 -0
- package/src/lib/http/serializer/cookie.ts +90 -0
- package/src/lib/http/serializer/query-data.ts +54 -0
- package/src/lib/http/transaction.ts +320 -0
- package/src/lib/http/type/basic-auth-credentials.ts +6 -0
- package/src/lib/http/type/header-map.ts +5 -0
- package/src/lib/http/type/log-attributes.ts +12 -0
- package/src/lib/http/type/path-parameters.ts +5 -0
- package/src/lib/http/type/query-data.ts +7 -0
- package/src/lib/http/type/query-value.ts +11 -0
- package/src/lib/http/type/request-options.ts +16 -0
- package/src/lib/http/type/transaction-data.ts +4 -0
- package/src/lib/http/utility/get-content-type-for-extension.ts +47 -0
- package/src/lib/http/utility/get-library-for-protocol.ts +25 -0
- package/src/lib/http/utility/get-status-code-for-error-type.ts +37 -0
- package/src/lib/http/utility/get-status-code-for-error.ts +13 -0
- package/src/lib/http/utility/is-client-error-status.ts +15 -0
- package/src/lib/http/utility/is-error-status.ts +9 -0
- package/src/lib/http/utility/is-server-error-status.ts +7 -0
- package/src/lib/http/utility/is-success-status.ts +7 -0
- package/src/lib/http/utility/proxy-request.ts +58 -0
- package/src/lib/http/utility/serialize-request-options.ts +9 -0
- package/src/lib/http/utility/slug-generator.ts +20 -0
- package/src/lib/key-generator/index.ts +3 -0
- package/src/lib/key-generator/key-generator.ts +7 -0
- package/src/lib/logger/enum/ansi-escape-code.ts +14 -0
- package/src/lib/logger/enum/log-level.ts +8 -0
- package/src/lib/logger/formatter.ts +59 -0
- package/src/lib/logger/index.ts +7 -0
- package/src/lib/logger/interface/error-reporter.ts +7 -0
- package/src/lib/logger/interface/logger.ts +13 -0
- package/src/lib/logger/logger.ts +239 -0
- package/src/lib/logger/type/error-parameters.ts +9 -0
- package/src/lib/logger/type/loggable-data.ts +5 -0
- package/src/lib/logger/type/loggable-value.ts +1 -0
- package/src/lib/metrics/dispatcher.ts +264 -0
- package/src/lib/metrics/enum/dispatch-mode.ts +6 -0
- package/src/lib/metrics/index.ts +2 -0
- package/src/lib/metrics/settings-hydrator.ts +51 -0
- package/src/lib/metrics/type/dispatcher-settings.ts +12 -0
- package/src/lib/metrics/type/tag-map.ts +5 -0
- package/src/lib/network/bootstrap.ts +1 -0
- package/src/lib/network/enum/connection-status.ts +14 -0
- package/src/lib/network/enum/http-status-code.ts +75 -0
- package/src/lib/network/enum/network-protocol.ts +10 -0
- package/src/lib/network/event-emitter.ts +63 -0
- package/src/lib/network/index.ts +7 -0
- package/src/lib/network/interface/socket.ts +42 -0
- package/src/lib/network/type/socket-options.ts +6 -0
- package/src/lib/network/utility/get-protocol-from-url.ts +15 -0
- package/src/lib/operation/index.ts +6 -0
- package/src/lib/operation/operation/auto-logging.ts +94 -0
- package/src/lib/operation/operation/silent.ts +17 -0
- package/src/lib/operation/operation.ts +80 -0
- package/src/lib/process/bootstrap.ts +1 -0
- package/src/lib/process/enum/posix-error-code.ts +138 -0
- package/src/lib/process/enum/process-signal.ts +68 -0
- package/src/lib/process/error.ts +6 -0
- package/src/lib/process/execute.ts +77 -0
- package/src/lib/process/index.ts +4 -0
- package/src/lib/process/type/command-options.ts +9 -0
- package/src/lib/process/utility/bind-process-lifespan-to.ts +10 -0
- package/src/lib/promise-wrapper/index.ts +3 -0
- package/src/lib/promise-wrapper/promise-wrapper.ts +51 -0
- package/src/lib/random/chance.ts +5 -0
- package/src/lib/random/element.ts +7 -0
- package/src/lib/random/elements.ts +12 -0
- package/src/lib/random/enum.ts +34 -0
- package/src/lib/random/enums.ts +11 -0
- package/src/lib/random/index.ts +3 -0
- package/src/lib/random/number.ts +8 -0
- package/src/lib/server/base.ts +194 -0
- package/src/lib/server/enum/server-event.ts +5 -0
- package/src/lib/server/enum/server-status.ts +10 -0
- package/src/lib/server/http/endpoint/ping.ts +21 -0
- package/src/lib/server/http/endpoint.ts +345 -0
- package/src/lib/server/http/interface/endpoint-constructor.ts +12 -0
- package/src/lib/server/http/interface/result-serializer.ts +5 -0
- package/src/lib/server/http/middleware.ts +18 -0
- package/src/lib/server/http/result-serializer/html.ts +92 -0
- package/src/lib/server/http/result-serializer/json.ts +23 -0
- package/src/lib/server/http/route.ts +104 -0
- package/src/lib/server/http/router.ts +125 -0
- package/src/lib/server/http/type/session-resolver.ts +8 -0
- package/src/lib/server/http/utility/create-server.ts +34 -0
- package/src/lib/server/http/utility/path-parser.ts +49 -0
- package/src/lib/server/http/utility/standardize-html-indentation.ts +54 -0
- package/src/lib/server/http/websocket-wrapper.ts +83 -0
- package/src/lib/server/http.ts +301 -0
- package/src/lib/server/index.ts +5 -0
- package/src/lib/server/tcp.ts +53 -0
- package/src/lib/server/type/server-options.ts +10 -0
- package/src/lib/string/calculate-length.ts +17 -0
- package/src/lib/string/capitalize.ts +8 -0
- package/src/lib/string/create-slug.ts +14 -0
- package/src/lib/string/enum/ansi-escape-code.ts +14 -0
- package/src/lib/string/enum/string-encoding.ts +9 -0
- package/src/lib/string/hyphenate.ts +5 -0
- package/src/lib/string/index.ts +3 -0
- package/src/lib/string/pad.ts +14 -0
- package/src/lib/string/trim-multiline.ts +21 -0
- package/src/lib/string/trim.ts +8 -0
- package/src/lib/tcp/channel.ts +13 -0
- package/src/lib/tcp/connection/incoming.ts +72 -0
- package/src/lib/tcp/connection/outgoing.ts +219 -0
- package/src/lib/tcp/connection.ts +360 -0
- package/src/lib/tcp/enum/connection-event.ts +12 -0
- package/src/lib/tcp/enum/message-type.ts +9 -0
- package/src/lib/tcp/index.ts +1 -0
- package/src/lib/tcp/type/connection-parameters.ts +6 -0
- package/src/lib/tcp/type/message/channel-close.ts +9 -0
- package/src/lib/tcp/type/message/channel-open.ts +9 -0
- package/src/lib/tcp/type/message.ts +10 -0
- package/src/lib/test/index.ts +2 -0
- package/src/lib/test/utility/build-config.ts +17 -0
- package/src/lib/test/utility/build-execution-context.ts +11 -0
- package/src/lib/time/bootstrap.ts +1 -0
- package/src/lib/time/enum/time-interval.ts +12 -0
- package/src/lib/time/index.ts +4 -0
- package/src/lib/time/utility/format-duration.ts +139 -0
- package/src/lib/time/utility/format-relative-duration.ts +22 -0
- package/src/lib/time/utility/sleep.ts +9 -0
- package/src/operation.ts +18 -0
- package/src/server/endpoint/abstract-page.ts +126 -0
- package/src/server/endpoint/action/create.ts +545 -0
- package/src/server/endpoint/action/get.ts +231 -0
- package/src/server/endpoint/base.ts +51 -0
- package/src/server/endpoint/day.ts +13 -0
- package/src/server/endpoint/generic-page.ts +14 -0
- package/src/server/endpoint/index.ts +11 -0
- package/src/server/endpoint/login.ts +45 -0
- package/src/server/endpoint/logout.ts +38 -0
- package/src/server/endpoint/month.ts +35 -0
- package/src/server/endpoint/robots.ts +18 -0
- package/src/server/endpoint/session/create.ts +62 -0
- package/src/server/endpoint/settings/get.ts +40 -0
- package/src/server/endpoint/settings/update.ts +44 -0
- package/src/server/endpoint/today.ts +15 -0
- package/src/server/endpoint/week.ts +34 -0
- package/src/server/endpoint/year.ts +34 -0
- package/src/server/enum/custom-page-type.ts +10 -0
- package/src/server/factory/block-result-serializer.ts +115 -0
- package/src/server/middleware/base.ts +6 -0
- package/src/server/middleware/error-handler.ts +177 -0
- package/src/server/middleware/static-file.ts +83 -0
- package/src/server/operation/add-block.ts +110 -0
- package/src/server/operation/create-session.ts +43 -0
- package/src/server/operation/delete-block.ts +96 -0
- package/src/server/operation/demote-block.ts +108 -0
- package/src/server/operation/destroy-session.ts +26 -0
- package/src/server/operation/load-account.ts +30 -0
- package/src/server/operation/load-block.ts +48 -0
- package/src/server/operation/load-directory-items.ts +75 -0
- package/src/server/operation/load-page.ts +368 -0
- package/src/server/operation/promote-block.ts +104 -0
- package/src/server/operation/save-page.ts +60 -0
- package/src/server/operation/update-account-settings.ts +52 -0
- package/src/server/operation/update-block.ts +124 -0
- package/src/server/repository/memory.ts +112 -0
- package/src/server/result-serializer/action.ts +939 -0
- package/src/server/result-serializer/base.ts +1267 -0
- package/src/server/result-serializer/block/audio.ts +33 -0
- package/src/server/result-serializer/block/background.ts +20 -0
- package/src/server/result-serializer/block/calendar.ts +148 -0
- package/src/server/result-serializer/block/directory.ts +57 -0
- package/src/server/result-serializer/block/ephemeral.ts +14 -0
- package/src/server/result-serializer/block/folder.ts +106 -0
- package/src/server/result-serializer/block/header.ts +31 -0
- package/src/server/result-serializer/block/image.ts +46 -0
- package/src/server/result-serializer/block/link.ts +40 -0
- package/src/server/result-serializer/block/list.ts +140 -0
- package/src/server/result-serializer/block/multi-column.ts +97 -0
- package/src/server/result-serializer/block/note.ts +44 -0
- package/src/server/result-serializer/block/todo.ts +78 -0
- package/src/server/result-serializer/block/whitespace.ts +15 -0
- package/src/server/result-serializer/block.ts +248 -0
- package/src/server/result-serializer/common/time-place-options.ts +33 -0
- package/src/server/result-serializer/login.ts +58 -0
- package/src/server/result-serializer/month.ts +170 -0
- package/src/server/result-serializer/page.ts +548 -0
- package/src/server/result-serializer/settings.ts +85 -0
- package/src/server/result-serializer/week.ts +195 -0
- package/src/server/result-serializer/year.ts +160 -0
- package/src/server/utility/accepts-content-type.ts +16 -0
- package/src/server/utility/accepts-html.ts +9 -0
- package/src/server/utility/accepts-json.ts +9 -0
- package/src/server/utility/add-days.ts +11 -0
- package/src/server/utility/create-date.ts +23 -0
- package/src/server/utility/create-index-path.ts +5 -0
- package/src/server/utility/create-slug.ts +9 -0
- package/src/server/utility/create-toast-path.ts +19 -0
- package/src/server/utility/date-less-than.ts +5 -0
- package/src/server/utility/date-occurs-before.ts +22 -0
- package/src/server/utility/date-to-key.ts +7 -0
- package/src/server/utility/date-to-label.ts +5 -0
- package/src/server/utility/date-to-path.ts +9 -0
- package/src/server/utility/dates-are-equal.ts +22 -0
- package/src/server/utility/dates-are-in-order.ts +9 -0
- package/src/server/utility/dates-are-on-the-same-day.ts +9 -0
- package/src/server/utility/dates-in-same-month.ts +8 -0
- package/src/server/utility/day-to-date.ts +40 -0
- package/src/server/utility/decrement-date.ts +11 -0
- package/src/server/utility/get-block-at-index-path.ts +32 -0
- package/src/server/utility/get-block-permissions.ts +15 -0
- package/src/server/utility/get-compact-label-for-date.ts +8 -0
- package/src/server/utility/get-custom-page-type-for-path.ts +37 -0
- package/src/server/utility/get-element-id-for-block.ts +15 -0
- package/src/server/utility/get-emoji-for-block-type.ts +39 -0
- package/src/server/utility/get-emoji-for-tool-type.ts +20 -0
- package/src/server/utility/get-end-of-month.ts +13 -0
- package/src/server/utility/get-end-of-week.ts +13 -0
- package/src/server/utility/get-filepath-for-folder-block.ts +23 -0
- package/src/server/utility/get-hex-for-color.ts +31 -0
- package/src/server/utility/get-label-for-time-place-visibility.ts +23 -0
- package/src/server/utility/get-month-name.ts +18 -0
- package/src/server/utility/get-next-day.ts +7 -0
- package/src/server/utility/get-next-month.ts +12 -0
- package/src/server/utility/get-next-week.ts +12 -0
- package/src/server/utility/get-next-year.ts +13 -0
- package/src/server/utility/get-ordinal-label-for-week.ts +11 -0
- package/src/server/utility/get-ordinal-of-week-within-month.ts +15 -0
- package/src/server/utility/get-padded-date.ts +11 -0
- package/src/server/utility/get-parent-index-path.ts +18 -0
- package/src/server/utility/get-path-for-folder-block.ts +25 -0
- package/src/server/utility/get-path-from-url.ts +13 -0
- package/src/server/utility/get-previous-index-path.ts +27 -0
- package/src/server/utility/get-previous-month.ts +12 -0
- package/src/server/utility/get-previous-week.ts +11 -0
- package/src/server/utility/get-previous-year.ts +13 -0
- package/src/server/utility/get-random-emoji-for-date.ts +109 -0
- package/src/server/utility/get-short-label-for-date.ts +11 -0
- package/src/server/utility/get-short-month-name.ts +9 -0
- package/src/server/utility/get-short-ordinal.ts +26 -0
- package/src/server/utility/get-siblings-and-index-for-index-path.ts +67 -0
- package/src/server/utility/get-start-of-month.ts +11 -0
- package/src/server/utility/get-start-of-week.ts +12 -0
- package/src/server/utility/get-start-of-year.ts +12 -0
- package/src/server/utility/get-weekday-name.ts +24 -0
- package/src/server/utility/increment-date.ts +15 -0
- package/src/server/utility/is-index-path.ts +5 -0
- package/src/server/utility/key-to-date.ts +25 -0
- package/src/server/utility/month-has-week-containing-date.ts +13 -0
- package/src/server/utility/month-to-date.ts +28 -0
- package/src/server/utility/month-to-path.ts +10 -0
- package/src/server/utility/months-are-equal.ts +8 -0
- package/src/server/utility/parse-index-path.ts +23 -0
- package/src/server/utility/path-is-date.ts +13 -0
- package/src/server/utility/path-to-date.ts +24 -0
- package/src/server/utility/subtract-days.ts +7 -0
- package/src/server/utility/validate-month.ts +10 -0
- package/src/server/utility/validate-page.ts +46 -0
- package/src/server/utility/validate-path.ts +9 -0
- package/src/server/utility/validate-url.ts +12 -0
- package/src/server/utility/week-greater-than.ts +10 -0
- package/src/server/utility/week-to-date.ts +8 -0
- package/src/server/utility/week-to-path.ts +12 -0
- package/src/server/utility/weeks-are-equal.ts +8 -0
- package/src/server/utility/year-to-date.ts +26 -0
- package/src/server/utility/year-to-path.ts +7 -0
- package/src/server/utility/years-are-equal.ts +8 -0
- package/src/server.ts +140 -0
- package/src/test.ts +195 -0
- package/src/type/account-settings.ts +9 -0
- package/src/type/account.ts +11 -0
- package/src/type/action/add-block.ts +74 -0
- package/src/type/action/complete-block.ts +10 -0
- package/src/type/action/delete-block.ts +11 -0
- package/src/type/action/demote-block.ts +9 -0
- package/src/type/action/edit-block.ts +11 -0
- package/src/type/action/promote-block.ts +9 -0
- package/src/type/action.ts +9 -0
- package/src/type/block/audio.ts +8 -0
- package/src/type/block/background.ts +10 -0
- package/src/type/block/directory.ts +18 -0
- package/src/type/block/ephemeral.ts +9 -0
- package/src/type/block/folder.ts +14 -0
- package/src/type/block/header.ts +11 -0
- package/src/type/block/image.ts +8 -0
- package/src/type/block/link.ts +12 -0
- package/src/type/block/list.ts +24 -0
- package/src/type/block/multi-column.ts +10 -0
- package/src/type/block/note.ts +9 -0
- package/src/type/block/todo.ts +10 -0
- package/src/type/block/whitespace.ts +9 -0
- package/src/type/block-metadata.ts +14 -0
- package/src/type/block.ts +18 -0
- package/src/type/day.ts +5 -0
- package/src/type/field-definition.ts +8 -0
- package/src/type/field-value.ts +5 -0
- package/src/type/file.ts +6 -0
- package/src/type/month.ts +5 -0
- package/src/type/page.ts +8 -0
- package/src/type/price.ts +11 -0
- package/src/type/resource.ts +5 -0
- package/src/type/runtime-config.ts +13 -0
- package/src/type/server-settings.ts +17 -0
- package/src/type/toast.ts +8 -0
- package/src/type/week.ts +5 -0
- package/src/type/year.ts +5 -0
- package/test/unit/index.ts +11 -0
- package/test/unit/server/operation/promote-block.ts +84 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {PosixErrorCode} from 'lib/process';
|
|
2
|
+
|
|
3
|
+
import BaseError from 'lib/errors/error/base';
|
|
4
|
+
import ErrorType from 'lib/errors/enum/error-type';
|
|
5
|
+
import OmittedError from 'lib/errors/error/omitted';
|
|
6
|
+
import InvalidError from 'lib/errors/error/invalid';
|
|
7
|
+
import TimeoutError from 'lib/errors/error/timeout';
|
|
8
|
+
import GenericError from 'lib/errors/error/generic';
|
|
9
|
+
import ConflictError from 'lib/errors/error/conflict';
|
|
10
|
+
import NotFoundError from 'lib/errors/error/not-found';
|
|
11
|
+
import NotAllowedError from 'lib/errors/error/not-allowed';
|
|
12
|
+
import UnauthorizedError from 'lib/errors/error/unauthorized';
|
|
13
|
+
import NotImplementedError from 'lib/errors/error/not-implemented';
|
|
14
|
+
|
|
15
|
+
interface ErrorConstructor {
|
|
16
|
+
new (message: string | undefined, code: PosixErrorCode | null | undefined): BaseError;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function createErrorForErrorType(
|
|
20
|
+
error_type: ErrorType,
|
|
21
|
+
error_code?: PosixErrorCode | null,
|
|
22
|
+
message?: string
|
|
23
|
+
): BaseError {
|
|
24
|
+
const error_constructor = getConstructorForErrorType(error_type);
|
|
25
|
+
|
|
26
|
+
return new error_constructor(message, error_code);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getConstructorForErrorType(error_type: ErrorType): ErrorConstructor {
|
|
30
|
+
switch (error_type) {
|
|
31
|
+
case ErrorType.CONFLICT:
|
|
32
|
+
return ConflictError;
|
|
33
|
+
|
|
34
|
+
case ErrorType.INVALID:
|
|
35
|
+
return InvalidError;
|
|
36
|
+
|
|
37
|
+
case ErrorType.NOT_ALLOWED:
|
|
38
|
+
return NotAllowedError;
|
|
39
|
+
|
|
40
|
+
case ErrorType.NOT_FOUND:
|
|
41
|
+
return NotFoundError;
|
|
42
|
+
|
|
43
|
+
case ErrorType.NOT_IMPLEMENTED:
|
|
44
|
+
return NotImplementedError;
|
|
45
|
+
|
|
46
|
+
case ErrorType.OMITTED:
|
|
47
|
+
return OmittedError;
|
|
48
|
+
|
|
49
|
+
case ErrorType.TIMEOUT:
|
|
50
|
+
return TimeoutError;
|
|
51
|
+
|
|
52
|
+
case ErrorType.UNAUTHORIZED:
|
|
53
|
+
return UnauthorizedError;
|
|
54
|
+
|
|
55
|
+
default:
|
|
56
|
+
return GenericError;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default createErrorForErrorType;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {HttpStatusCode} from 'lib/network';
|
|
2
|
+
|
|
3
|
+
import BaseError from 'lib/errors/error/base';
|
|
4
|
+
import ErrorType from 'lib/errors/enum/error-type';
|
|
5
|
+
import ErrorData from 'lib/errors/type/error-data';
|
|
6
|
+
import createErrorForErrorType from 'lib/errors/utility/create-error-for-error-type';
|
|
7
|
+
import getErrorTypeForStatusCode from 'lib/errors/utility/get-error-type-for-status-code';
|
|
8
|
+
|
|
9
|
+
function createErrorFromAmbiguousJsonData(
|
|
10
|
+
data: object,
|
|
11
|
+
status_code: HttpStatusCode
|
|
12
|
+
): BaseError {
|
|
13
|
+
const error_data = data as ErrorData;
|
|
14
|
+
|
|
15
|
+
let error_type: ErrorType;
|
|
16
|
+
|
|
17
|
+
if (Object.values(ErrorType).includes(error_data.error_type)) {
|
|
18
|
+
error_type = error_data.error_type;
|
|
19
|
+
} else {
|
|
20
|
+
error_type = getErrorTypeForStatusCode(status_code);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return createErrorForErrorType(error_type, null, error_data.message);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default createErrorFromAmbiguousJsonData;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import wrapError from 'lib/errors/utility/wrap-error';
|
|
2
|
+
|
|
3
|
+
interface ErrorConstructor {
|
|
4
|
+
new (message: string): Error;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function errorMatches(
|
|
8
|
+
error: unknown,
|
|
9
|
+
error_constructor: ErrorConstructor
|
|
10
|
+
): boolean {
|
|
11
|
+
if (!(error instanceof Error)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (error.constructor.name === error_constructor.name) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (error instanceof error_constructor) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const wrapped_error = wrapError(error);
|
|
24
|
+
|
|
25
|
+
return wrapped_error.constructor.name === error_constructor.name;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default errorMatches;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {PosixErrorCode} from 'lib/process';
|
|
2
|
+
|
|
3
|
+
import ErrorType from 'lib/errors/enum/error-type';
|
|
4
|
+
|
|
5
|
+
function getErrorTypeForPosixErrorCode(error_code: PosixErrorCode): ErrorType {
|
|
6
|
+
switch (error_code) {
|
|
7
|
+
case PosixErrorCode.EPERM:
|
|
8
|
+
case PosixErrorCode.EACCES:
|
|
9
|
+
return ErrorType.UNAUTHORIZED;
|
|
10
|
+
|
|
11
|
+
case PosixErrorCode.ENOENT:
|
|
12
|
+
return ErrorType.NOT_FOUND;
|
|
13
|
+
|
|
14
|
+
case PosixErrorCode.EEXIST:
|
|
15
|
+
return ErrorType.CONFLICT;
|
|
16
|
+
|
|
17
|
+
case PosixErrorCode.ENOTDIR:
|
|
18
|
+
case PosixErrorCode.EISDIR:
|
|
19
|
+
case PosixErrorCode.EINVAL:
|
|
20
|
+
return ErrorType.INVALID;
|
|
21
|
+
|
|
22
|
+
case PosixErrorCode.EADDRINUSE:
|
|
23
|
+
return ErrorType.CONFLICT;
|
|
24
|
+
|
|
25
|
+
case PosixErrorCode.ETIMEDOUT:
|
|
26
|
+
return ErrorType.TIMEOUT;
|
|
27
|
+
|
|
28
|
+
case PosixErrorCode.ECONNREFUSED:
|
|
29
|
+
case PosixErrorCode.EHOSTDOWN:
|
|
30
|
+
case PosixErrorCode.EHOSTUNREACH:
|
|
31
|
+
// TODO: Add error type for these; they are common enough to warrant it.
|
|
32
|
+
default:
|
|
33
|
+
return ErrorType.GENERIC;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default getErrorTypeForPosixErrorCode;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {HttpStatusCode} from 'lib/network';
|
|
2
|
+
|
|
3
|
+
import ErrorType from 'lib/errors/enum/error-type';
|
|
4
|
+
|
|
5
|
+
function getErrorTypeForStatusCode(status_code: HttpStatusCode): ErrorType {
|
|
6
|
+
switch (status_code) {
|
|
7
|
+
case HttpStatusCode.CONFLICT:
|
|
8
|
+
return ErrorType.CONFLICT;
|
|
9
|
+
|
|
10
|
+
case HttpStatusCode.BAD_REQUEST:
|
|
11
|
+
return ErrorType.INVALID;
|
|
12
|
+
|
|
13
|
+
case HttpStatusCode.FORBIDDEN:
|
|
14
|
+
return ErrorType.NOT_ALLOWED;
|
|
15
|
+
|
|
16
|
+
case HttpStatusCode.FILE_NOT_FOUND:
|
|
17
|
+
return ErrorType.NOT_FOUND;
|
|
18
|
+
|
|
19
|
+
case HttpStatusCode.NOT_IMPLEMENTED:
|
|
20
|
+
return ErrorType.NOT_IMPLEMENTED;
|
|
21
|
+
|
|
22
|
+
case HttpStatusCode.REQUEST_TIMEOUT:
|
|
23
|
+
case HttpStatusCode.GATEWAY_TIMEOUT:
|
|
24
|
+
return ErrorType.TIMEOUT;
|
|
25
|
+
|
|
26
|
+
case HttpStatusCode.UNAUTHORIZED:
|
|
27
|
+
return ErrorType.UNAUTHORIZED;
|
|
28
|
+
|
|
29
|
+
default:
|
|
30
|
+
if (status_code >= HttpStatusCode.SERVER_ERROR) {
|
|
31
|
+
return ErrorType.GENERIC;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return ErrorType.INVALID;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default getErrorTypeForStatusCode;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import ErrorType from 'lib/errors/enum/error-type';
|
|
2
|
+
import InvalidError from 'lib/errors/error/invalid';
|
|
3
|
+
|
|
4
|
+
function getMessageForErrorType(error_type: ErrorType): string {
|
|
5
|
+
switch (error_type) {
|
|
6
|
+
case ErrorType.CONFLICT:
|
|
7
|
+
return 'The desired resource is already claimed.';
|
|
8
|
+
case ErrorType.GENERIC:
|
|
9
|
+
return 'Something went wrong.';
|
|
10
|
+
case ErrorType.INVALID:
|
|
11
|
+
return 'Invalid request.';
|
|
12
|
+
case ErrorType.NOT_ALLOWED:
|
|
13
|
+
return 'Not allowed.';
|
|
14
|
+
case ErrorType.NOT_FOUND:
|
|
15
|
+
return 'File not found.';
|
|
16
|
+
case ErrorType.NOT_IMPLEMENTED:
|
|
17
|
+
return 'Not yet implemented.';
|
|
18
|
+
case ErrorType.OMITTED:
|
|
19
|
+
return 'This value is required.';
|
|
20
|
+
case ErrorType.TIMEOUT:
|
|
21
|
+
return 'Request timed out.';
|
|
22
|
+
case ErrorType.UNAUTHORIZED:
|
|
23
|
+
return 'Not authorized.';
|
|
24
|
+
default:
|
|
25
|
+
throw new InvalidError(`Invalid error type: ${error_type}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default getMessageForErrorType;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {PosixErrorCode} from 'lib/process';
|
|
2
|
+
|
|
3
|
+
import wrapError from 'lib/errors/utility/wrap-error';
|
|
4
|
+
|
|
5
|
+
function matchesPosixErrorCode(error: unknown, posix_error_code: PosixErrorCode): boolean {
|
|
6
|
+
const wrapped_error = wrapError(error);
|
|
7
|
+
|
|
8
|
+
return wrapped_error.code === posix_error_code;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default matchesPosixErrorCode;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import BaseError from 'lib/errors/error/base';
|
|
2
|
+
import GenericError from 'lib/errors/error/generic';
|
|
3
|
+
import createErrorForErrorType from 'lib/errors/utility/create-error-for-error-type';
|
|
4
|
+
import CodedError from 'lib/errors/type/coded-error';
|
|
5
|
+
import getErrorTypeForPosixErrorCode from 'lib/errors/utility/get-error-type-for-posix-error-code';
|
|
6
|
+
|
|
7
|
+
function wrapError(error: unknown): BaseError {
|
|
8
|
+
if (error instanceof BaseError) {
|
|
9
|
+
return error;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (typeof error === 'string') {
|
|
13
|
+
return new GenericError(error);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Necessary in cases where we're passing around different BaseError
|
|
17
|
+
// base classes due to library imports.
|
|
18
|
+
const potential_base_error = error as BaseError;
|
|
19
|
+
|
|
20
|
+
if (potential_base_error.getType !== undefined) {
|
|
21
|
+
return potential_base_error;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const coded_error = error as CodedError;
|
|
25
|
+
|
|
26
|
+
if (coded_error.code) {
|
|
27
|
+
const error_type = getErrorTypeForPosixErrorCode(coded_error.code);
|
|
28
|
+
|
|
29
|
+
return createErrorForErrorType(
|
|
30
|
+
error_type,
|
|
31
|
+
coded_error.code,
|
|
32
|
+
coded_error.message
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return GenericError.fromNativeError(coded_error);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default wrapError;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
interface Listener {
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
|
+
(...args: any[]): void;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
interface ListenerMap {
|
|
7
|
+
[event: string]: Listener[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
abstract class EventEmitter {
|
|
11
|
+
private listener_map: ListenerMap;
|
|
12
|
+
|
|
13
|
+
public constructor() {
|
|
14
|
+
this.listener_map = {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public on(event: string, listener: Listener): void {
|
|
18
|
+
const listeners = this.getListenersForEvent(event);
|
|
19
|
+
|
|
20
|
+
listeners.push(listener);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public removeListener(event: string, listener: Listener): void {
|
|
24
|
+
const listeners = this.getListenersForEvent(event);
|
|
25
|
+
const index = listeners.indexOf(listener);
|
|
26
|
+
|
|
27
|
+
if (index === -1) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Could not find listener in list of listeners for event: ${event}`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
listeners.splice(index, 1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public removeAllListeners(event: string): void {
|
|
37
|
+
delete this.listener_map[event];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected emit(event: string, value?: unknown): void {
|
|
41
|
+
const listeners = this.getListenersForEvent(event);
|
|
42
|
+
|
|
43
|
+
listeners.forEach((listener) => {
|
|
44
|
+
listener(value);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private getListenersForEvent(event: string): Listener[] {
|
|
49
|
+
const listener_map = this.getListenerMap();
|
|
50
|
+
|
|
51
|
+
if (listener_map[event] === undefined) {
|
|
52
|
+
listener_map[event] = [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return listener_map[event];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private getListenerMap(): ListenerMap {
|
|
59
|
+
return this.listener_map;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default EventEmitter;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import Logger from 'lib/logger';
|
|
2
|
+
import KeyGenerator from 'lib/key-generator';
|
|
3
|
+
|
|
4
|
+
import Session from 'lib/execution-context/type/session';
|
|
5
|
+
|
|
6
|
+
import RuntimeConfig from 'type/runtime-config';
|
|
7
|
+
|
|
8
|
+
class ExecutionContext {
|
|
9
|
+
private config: RuntimeConfig;
|
|
10
|
+
private logger: Logger | undefined;
|
|
11
|
+
private session: Session | undefined;
|
|
12
|
+
private unique_id: string;
|
|
13
|
+
private remote_address: string;
|
|
14
|
+
|
|
15
|
+
public constructor(config: RuntimeConfig) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.unique_id = KeyGenerator.generateToken();
|
|
18
|
+
this.remote_address = '<not set>';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public getConfig(): RuntimeConfig {
|
|
22
|
+
return this.config;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public getLogger(): Logger {
|
|
26
|
+
if (this.logger === undefined) {
|
|
27
|
+
this.logger = this.createLogger();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return this.logger;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public getUniqueId(): string {
|
|
34
|
+
return this.unique_id;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public setUniqueId(unique_id: string): this {
|
|
38
|
+
this.unique_id = unique_id;
|
|
39
|
+
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public isLoggedIn(): boolean {
|
|
44
|
+
const session = this.getSession();
|
|
45
|
+
|
|
46
|
+
if (session === undefined) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return session.account_id !== null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public getSessionId(): number | string | undefined {
|
|
54
|
+
const session = this.getSession();
|
|
55
|
+
|
|
56
|
+
if (session === undefined) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return session.id;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public getSession(): Session | undefined {
|
|
64
|
+
return this.session;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public setSession(session: Session): this {
|
|
68
|
+
this.session = session;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public getRemoteAddress(): string {
|
|
73
|
+
return this.remote_address;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public setRemoteAddress(remote_address: string): void {
|
|
77
|
+
this.remote_address = remote_address;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private createLogger(): Logger {
|
|
81
|
+
const logger = new Logger();
|
|
82
|
+
const unique_id = this.getUniqueId();
|
|
83
|
+
|
|
84
|
+
logger.setUniqueId(unique_id);
|
|
85
|
+
|
|
86
|
+
return logger;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default ExecutionContext;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {InvalidError, NotFoundError} from 'lib/errors';
|
|
2
|
+
import {EnvironmentType, getEnvironmentType} from 'lib/environment';
|
|
3
|
+
|
|
4
|
+
interface FeatureNode {
|
|
5
|
+
[key: string]: boolean | FeatureNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// TODO: Find some way to have this live in a JSON file, while still allowing
|
|
9
|
+
// it to be loaded on the client. Possible solutions include:
|
|
10
|
+
//
|
|
11
|
+
// - finding some damned Webpack adapter or other that allows for importing
|
|
12
|
+
// JSON files the same way as Common.js modules.
|
|
13
|
+
//
|
|
14
|
+
// - Bypass webpack's punk ass altogether; have some pre-bundler script that
|
|
15
|
+
// builds the necessary "javascript" file as an artifact and inject it.
|
|
16
|
+
//
|
|
17
|
+
// ^
|
|
18
|
+
// |
|
|
19
|
+
// |
|
|
20
|
+
// probably the best approach
|
|
21
|
+
//
|
|
22
|
+
// - importing this data from a separate file on the client (similar to how
|
|
23
|
+
// Logger is monkey-patched; see web/client/logger). The problem with this
|
|
24
|
+
// approach is that there are likely still values in the base Feature set
|
|
25
|
+
// that are still needed (and which would not be specified in the client
|
|
26
|
+
// feature set). So the question then becomes: do we have some preprocessor
|
|
27
|
+
// step that finds all the instances of feature checks that are actually
|
|
28
|
+
// necessary on the client (essentially treating them as dependencies)?
|
|
29
|
+
// That way we could filter out any feature keys that clients don't need
|
|
30
|
+
// to know about, and hide details about the internal infrastructure...
|
|
31
|
+
const BASE_DATA: FeatureNode = {
|
|
32
|
+
metric_tags: false,
|
|
33
|
+
logger: {
|
|
34
|
+
json_logging: false
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
let EFFECTIVE_DATA = {
|
|
39
|
+
...BASE_DATA
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
class Feature {
|
|
43
|
+
public static setData(data: FeatureNode): void {
|
|
44
|
+
EFFECTIVE_DATA = {
|
|
45
|
+
...BASE_DATA,
|
|
46
|
+
...data
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public static resetData(): void {
|
|
51
|
+
EFFECTIVE_DATA = {
|
|
52
|
+
...BASE_DATA
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public static isEnabled(feature_key: string): boolean {
|
|
57
|
+
const segments = feature_key.split('.');
|
|
58
|
+
|
|
59
|
+
let current_node = EFFECTIVE_DATA;
|
|
60
|
+
|
|
61
|
+
while (segments.length > 0) {
|
|
62
|
+
const current_segment = segments.shift() as string;
|
|
63
|
+
const next_node = current_node[current_segment];
|
|
64
|
+
|
|
65
|
+
if (next_node === undefined) {
|
|
66
|
+
throw new NotFoundError(`
|
|
67
|
+
Segment "${current_segment}"
|
|
68
|
+
from feature key "${feature_key}"
|
|
69
|
+
did not exist
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (next_node === true || next_node === false) {
|
|
74
|
+
return next_node;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
current_node = next_node;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const environment_type = getEnvironmentType();
|
|
81
|
+
const env_value = current_node[environment_type];
|
|
82
|
+
|
|
83
|
+
if (typeof env_value === 'boolean') {
|
|
84
|
+
return env_value;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const all_keys = Object.keys(current_node);
|
|
88
|
+
const environment_types = Object.values(EnvironmentType) as string[];
|
|
89
|
+
|
|
90
|
+
const all_env_keys = all_keys.every((key) => {
|
|
91
|
+
return environment_types.includes(key);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (all_env_keys) {
|
|
95
|
+
// If our current environment isn't present in the stanza, but the
|
|
96
|
+
// stanza otherwise consists of environment type keys, just return
|
|
97
|
+
// false (ie, assume that whoever omitted this environment type
|
|
98
|
+
// doesn't want the feature enabled there).
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
throw new InvalidError(`
|
|
103
|
+
Feature key "${feature_key}" points to a stanza, not a scalar value
|
|
104
|
+
`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default Feature;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
throw new Error('Not implemented');
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
enum FileExtension {
|
|
2
|
+
CSS = 'css',
|
|
3
|
+
GIF = 'gif',
|
|
4
|
+
HTML = 'html',
|
|
5
|
+
ICO = 'ico',
|
|
6
|
+
JPEG = 'jpeg',
|
|
7
|
+
JPG = 'jpg',
|
|
8
|
+
JS = 'js',
|
|
9
|
+
JSON = 'json',
|
|
10
|
+
MD = 'md',
|
|
11
|
+
MP3 = 'mp3',
|
|
12
|
+
PNG = 'png',
|
|
13
|
+
SQL = 'sql',
|
|
14
|
+
SWP = 'swp',
|
|
15
|
+
TXT = 'txt',
|
|
16
|
+
WAV = 'wav'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default FileExtension;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export {default as FileExtension} from 'lib/filesystem/enum/file-extension';
|
|
2
|
+
export {default as getExtensionForFilepath} from 'lib/filesystem/utility/get-extension-for-filepath';
|
|
3
|
+
export {default as stripExtension} from 'lib/filesystem/utility/strip-extension';
|
|
4
|
+
export {default as exists} from 'lib/filesystem/utility/exists';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {access} from 'fs/promises';
|
|
2
|
+
|
|
3
|
+
import {matchesPosixErrorCode} from 'lib/errors';
|
|
4
|
+
|
|
5
|
+
import PosixErrorCode from 'lib/process/enum/posix-error-code';
|
|
6
|
+
|
|
7
|
+
async function exists(filepath: string): Promise<boolean> {
|
|
8
|
+
try {
|
|
9
|
+
await access(filepath);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
if (matchesPosixErrorCode(error, PosixErrorCode.ENOENT)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default exists;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import FileExtension from 'lib/filesystem/enum/file-extension';
|
|
2
|
+
|
|
3
|
+
function getExtensionForFilepath(filepath: string): FileExtension | undefined {
|
|
4
|
+
const parts = filepath.split('/');
|
|
5
|
+
const tail = parts.pop();
|
|
6
|
+
|
|
7
|
+
if (tail === undefined || tail.indexOf('.') === -1) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const extension = filepath.split('.').pop();
|
|
12
|
+
|
|
13
|
+
if (extension === undefined) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return extension.toLowerCase() as FileExtension;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default getExtensionForFilepath;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {InvalidError} from 'lib/errors';
|
|
2
|
+
|
|
3
|
+
// Basically the opposite of getExtensionForFilepath().
|
|
4
|
+
|
|
5
|
+
// TODO: Investigate whether it's possible for this to return the full
|
|
6
|
+
// filepath. As it is right now, there are some subtle bugs caused by
|
|
7
|
+
// the fact that it trims off the leading directory as well as the extension.
|
|
8
|
+
function stripExtension(filepath: string): string {
|
|
9
|
+
const segments = filepath.split('/');
|
|
10
|
+
const last_segment = segments.pop();
|
|
11
|
+
|
|
12
|
+
if (last_segment === undefined) {
|
|
13
|
+
throw new InvalidError(`Invalid filepath: ${filepath}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const parts = last_segment.split('.');
|
|
17
|
+
const prefix = parts[0];
|
|
18
|
+
|
|
19
|
+
if (prefix === undefined) {
|
|
20
|
+
throw new InvalidError(`Invalid filepath segment: ${last_segment}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return prefix;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default stripExtension;
|