@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,108 @@
|
|
|
1
|
+
import {InvariantViolation} from 'lib/errors';
|
|
2
|
+
|
|
3
|
+
import ExecutionContext from 'lib/execution-context';
|
|
4
|
+
import getSiblingsAndIndexForIndexPath from 'server/utility/get-siblings-and-index-for-index-path';
|
|
5
|
+
import parseIndexPath from 'server/utility/parse-index-path';
|
|
6
|
+
import createIndexPath from 'server/utility/create-index-path';
|
|
7
|
+
import BlockType from 'enum/block-type';
|
|
8
|
+
import BaseOperation from 'operation';
|
|
9
|
+
import LoadPageOperation from 'server/operation/load-page';
|
|
10
|
+
import SavePageOperation from 'server/operation/save-page';
|
|
11
|
+
import getParentIndexPath from 'server/utility/get-parent-index-path';
|
|
12
|
+
|
|
13
|
+
class DemoteBlockOperation extends BaseOperation<string> {
|
|
14
|
+
private key: string;
|
|
15
|
+
private index_path: string;
|
|
16
|
+
|
|
17
|
+
public constructor(key: string, index_path: string, execution_context: ExecutionContext) {
|
|
18
|
+
super(execution_context);
|
|
19
|
+
|
|
20
|
+
this.key = key;
|
|
21
|
+
this.index_path = index_path;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected async performInternal(): Promise<string> {
|
|
25
|
+
const key = this.getKey();
|
|
26
|
+
const execution_context = this.getExecutionContext();
|
|
27
|
+
const load_operation = new LoadPageOperation(key, execution_context);
|
|
28
|
+
const page = await load_operation.perform();
|
|
29
|
+
const index_path = this.getIndexPath();
|
|
30
|
+
const final_path = createIndexPath([page.blocks.length - 1]);
|
|
31
|
+
|
|
32
|
+
if (index_path === final_path) {
|
|
33
|
+
return index_path;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
siblings,
|
|
38
|
+
index
|
|
39
|
+
} = getSiblingsAndIndexForIndexPath(page, index_path);
|
|
40
|
+
|
|
41
|
+
const index_parts = parseIndexPath(index_path);
|
|
42
|
+
const parent_parts = index_parts.slice(0, -1);
|
|
43
|
+
|
|
44
|
+
let new_path: string;
|
|
45
|
+
|
|
46
|
+
if (index === siblings.length - 1) {
|
|
47
|
+
const [removed_block] = siblings.splice(index, 1);
|
|
48
|
+
const parent_index_path = getParentIndexPath(index_path);
|
|
49
|
+
const {
|
|
50
|
+
siblings: parent_siblings,
|
|
51
|
+
index: parent_index
|
|
52
|
+
} = getSiblingsAndIndexForIndexPath(page, parent_index_path);
|
|
53
|
+
|
|
54
|
+
parent_siblings.splice(parent_index + 1, 0, removed_block);
|
|
55
|
+
new_path = createIndexPath([
|
|
56
|
+
...parent_parts.slice(0, -1),
|
|
57
|
+
parent_index + 1
|
|
58
|
+
]);
|
|
59
|
+
} else {
|
|
60
|
+
const new_index = index + 1;
|
|
61
|
+
const sibling = siblings[new_index];
|
|
62
|
+
|
|
63
|
+
if (sibling && sibling.block_type === BlockType.MULTI_COLUMN) {
|
|
64
|
+
const [removed_block] = siblings.splice(index, 1);
|
|
65
|
+
const children = sibling.children;
|
|
66
|
+
|
|
67
|
+
if (children === undefined) {
|
|
68
|
+
throw new InvariantViolation(`
|
|
69
|
+
Tried to read children for multi-column block,
|
|
70
|
+
but they were not set
|
|
71
|
+
`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
children.unshift(removed_block);
|
|
75
|
+
new_path = createIndexPath([
|
|
76
|
+
...parent_parts,
|
|
77
|
+
new_index,
|
|
78
|
+
0
|
|
79
|
+
]);
|
|
80
|
+
} else {
|
|
81
|
+
const [removed_block] = siblings.splice(index, 1);
|
|
82
|
+
|
|
83
|
+
new_path = createIndexPath([
|
|
84
|
+
...parent_parts,
|
|
85
|
+
new_index
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
siblings.splice(new_index, 0, removed_block);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const save_operation = new SavePageOperation(page, execution_context);
|
|
93
|
+
|
|
94
|
+
await save_operation.perform();
|
|
95
|
+
|
|
96
|
+
return new_path;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private getKey(): string {
|
|
100
|
+
return this.key;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private getIndexPath(): string {
|
|
104
|
+
return this.index_path;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default DemoteBlockOperation;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import ExecutionContext from 'lib/execution-context';
|
|
2
|
+
|
|
3
|
+
import BaseOperation from 'operation';
|
|
4
|
+
|
|
5
|
+
class DestroySessionOperation extends BaseOperation<void> {
|
|
6
|
+
private session_id: string;
|
|
7
|
+
|
|
8
|
+
public constructor(session_id: string, execution_context: ExecutionContext) {
|
|
9
|
+
super(execution_context);
|
|
10
|
+
|
|
11
|
+
this.session_id = session_id;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
protected async performInternal(): Promise<void> {
|
|
15
|
+
const {repository} = this.getConfig();
|
|
16
|
+
const session_id = this.getSessionId();
|
|
17
|
+
|
|
18
|
+
await repository.destroySession(session_id);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private getSessionId(): string {
|
|
22
|
+
return this.session_id;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default DestroySessionOperation;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Account from 'type/account';
|
|
2
|
+
import BaseOperation from 'operation';
|
|
3
|
+
|
|
4
|
+
class LoadAccountOperation extends BaseOperation<Account | null> {
|
|
5
|
+
protected async performInternal(): Promise<Account | null> {
|
|
6
|
+
const execution_context = this.getExecutionContext();
|
|
7
|
+
const session = execution_context.getSession();
|
|
8
|
+
|
|
9
|
+
if (session === undefined) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const {username} = session;
|
|
14
|
+
|
|
15
|
+
if (username === null) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const {repository} = this.getConfig();
|
|
20
|
+
const account = await repository.getAccountForUsername(username);
|
|
21
|
+
|
|
22
|
+
if (account === undefined) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return account;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default LoadAccountOperation;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import ExecutionContext from 'lib/execution-context';
|
|
2
|
+
import {NotFoundError} from 'lib/errors';
|
|
3
|
+
|
|
4
|
+
import LoadPageOperation from 'server/operation/load-page';
|
|
5
|
+
import getBlockAtIndexPath from 'server/utility/get-block-at-index-path';
|
|
6
|
+
import Block from 'type/block';
|
|
7
|
+
import BaseOperation from 'operation';
|
|
8
|
+
|
|
9
|
+
class LoadBlockOperation extends BaseOperation<Block> {
|
|
10
|
+
private key: string;
|
|
11
|
+
private index_path: string;
|
|
12
|
+
|
|
13
|
+
public constructor(key: string, index_path: string, execution_context: ExecutionContext) {
|
|
14
|
+
super(execution_context);
|
|
15
|
+
|
|
16
|
+
this.key = key;
|
|
17
|
+
this.index_path = index_path;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected async performInternal(): Promise<Block> {
|
|
21
|
+
const key = this.getKey();
|
|
22
|
+
const execution_context = this.getExecutionContext();
|
|
23
|
+
|
|
24
|
+
const operation = new LoadPageOperation(key, execution_context);
|
|
25
|
+
const page = await operation.perform();
|
|
26
|
+
|
|
27
|
+
const index_path = this.getIndexPath();
|
|
28
|
+
const block = getBlockAtIndexPath(page, index_path);
|
|
29
|
+
|
|
30
|
+
if (block === undefined) {
|
|
31
|
+
throw new NotFoundError(`
|
|
32
|
+
Unable to find block in page ${key} at index path ${index_path}
|
|
33
|
+
`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return block;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private getKey(): string {
|
|
40
|
+
return this.key;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private getIndexPath(): string {
|
|
44
|
+
return this.index_path;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default LoadBlockOperation;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import Path from 'path';
|
|
2
|
+
import {readdir, stat} from 'fs/promises';
|
|
3
|
+
|
|
4
|
+
import ExecutionContext from 'lib/execution-context';
|
|
5
|
+
import {getExtensionForFilepath} from 'lib/filesystem';
|
|
6
|
+
|
|
7
|
+
import DirectoryItemType from 'enum/directory-item-type';
|
|
8
|
+
import BaseOperation from 'operation';
|
|
9
|
+
import {DirectoryItem} from 'type/block/directory';
|
|
10
|
+
|
|
11
|
+
class LoadDirectoryItemsOperation extends BaseOperation<DirectoryItem[]> {
|
|
12
|
+
private path: string;
|
|
13
|
+
|
|
14
|
+
public constructor(path: string, execution_context: ExecutionContext) {
|
|
15
|
+
super(execution_context);
|
|
16
|
+
|
|
17
|
+
this.path = path;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected formatResult(results: DirectoryItem[]): string {
|
|
21
|
+
const filenames = results.map((directory_item) => {
|
|
22
|
+
return directory_item.filename;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return filenames.join(', ');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected async performInternal(): Promise<DirectoryItem[]> {
|
|
29
|
+
const path = this.getPath();
|
|
30
|
+
const {public_directory} = this.getConfig();
|
|
31
|
+
const resolved_path = Path.resolve(public_directory, `.${path}`);
|
|
32
|
+
const filenames = await readdir(resolved_path);
|
|
33
|
+
|
|
34
|
+
const promises = filenames.map((filename) => {
|
|
35
|
+
const filepath = Path.resolve(resolved_path, filename);
|
|
36
|
+
|
|
37
|
+
return stat(filepath);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const combined_stats = await Promise.all(promises);
|
|
41
|
+
|
|
42
|
+
return combined_stats.map((stats, index) => {
|
|
43
|
+
const filename = filenames[index];
|
|
44
|
+
|
|
45
|
+
const item_type = (() => {
|
|
46
|
+
if (stats.isDirectory()) {
|
|
47
|
+
return DirectoryItemType.DIRECTORY;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const extension = getExtensionForFilepath(filename);
|
|
51
|
+
|
|
52
|
+
switch (extension) {
|
|
53
|
+
default:
|
|
54
|
+
return DirectoryItemType.GENERIC_FILE;
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
|
|
58
|
+
const filesize = stats.size;
|
|
59
|
+
const created_at = Math.floor(stats.birthtimeMs);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
filename,
|
|
63
|
+
item_type,
|
|
64
|
+
filesize,
|
|
65
|
+
created_at
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private getPath(): string {
|
|
71
|
+
return this.path;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default LoadDirectoryItemsOperation;
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import Path from 'path';
|
|
2
|
+
import {readFile} from 'fs/promises';
|
|
3
|
+
|
|
4
|
+
import {StringEncoding} from 'lib/string';
|
|
5
|
+
import ExecutionContext from 'lib/execution-context';
|
|
6
|
+
import {exists} from 'lib/filesystem';
|
|
7
|
+
import {StatusCode} from 'lib/http';
|
|
8
|
+
import {
|
|
9
|
+
InvalidError,
|
|
10
|
+
NotFoundError,
|
|
11
|
+
InvariantViolation,
|
|
12
|
+
getErrorTypeForStatusCode,
|
|
13
|
+
createErrorForErrorType
|
|
14
|
+
} from 'lib/errors';
|
|
15
|
+
|
|
16
|
+
import BaseOperation from 'operation';
|
|
17
|
+
import pathToDate from 'server/utility/path-to-date';
|
|
18
|
+
import BlockType from 'enum/block-type';
|
|
19
|
+
import validatePath from 'server/utility/validate-path';
|
|
20
|
+
import CustomPageType from 'server/enum/custom-page-type';
|
|
21
|
+
import Color from 'enum/color';
|
|
22
|
+
import getWeekdayName from 'server/utility/get-weekday-name';
|
|
23
|
+
import Page from 'type/page';
|
|
24
|
+
import EphemeralBlock from 'type/block/ephemeral';
|
|
25
|
+
import getShortOrdinal from 'server/utility/get-short-ordinal';
|
|
26
|
+
import getMonthName from 'server/utility/get-month-name';
|
|
27
|
+
import MultiColumnBlock from 'type/block/multi-column';
|
|
28
|
+
import LinkBlock from 'type/block/link';
|
|
29
|
+
import getCustomPageTypeForPath from 'server/utility/get-custom-page-type-for-path';
|
|
30
|
+
import getOrdinalLabelForWeek from 'server/utility/get-ordinal-label-for-week';
|
|
31
|
+
import dateToPath from 'server/utility/date-to-path';
|
|
32
|
+
import getStartOfWeek from 'server/utility/get-start-of-week';
|
|
33
|
+
import weekToPath from 'server/utility/week-to-path';
|
|
34
|
+
import incrementDate from 'server/utility/increment-date';
|
|
35
|
+
import decrementDate from 'server/utility/decrement-date';
|
|
36
|
+
import dateLessThan from 'server/utility/date-less-than';
|
|
37
|
+
import createDate from 'server/utility/create-date';
|
|
38
|
+
import datesAreEqual from 'server/utility/dates-are-equal';
|
|
39
|
+
import header from 'common/builder/block/header';
|
|
40
|
+
import getCompactLabelForDate from 'server/utility/get-compact-label-for-date';
|
|
41
|
+
import Emoji from 'enum/emoji';
|
|
42
|
+
import validatePage from 'server/utility/validate-page';
|
|
43
|
+
import Block from 'type/block';
|
|
44
|
+
import ListBlock from 'type/block/list';
|
|
45
|
+
|
|
46
|
+
type RawPage = Omit<Page, 'path'>;
|
|
47
|
+
|
|
48
|
+
class LoadPageOperation extends BaseOperation<Page> {
|
|
49
|
+
private path: string;
|
|
50
|
+
|
|
51
|
+
public constructor(path: string, execution_context: ExecutionContext) {
|
|
52
|
+
validatePath(path);
|
|
53
|
+
|
|
54
|
+
super(execution_context);
|
|
55
|
+
|
|
56
|
+
this.path = path;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected async performInternal(): Promise<Page> {
|
|
60
|
+
const raw_page = await this.loadRawPage();
|
|
61
|
+
const {path} = raw_page as Page;
|
|
62
|
+
|
|
63
|
+
if (path !== undefined) {
|
|
64
|
+
throw new InvariantViolation(`
|
|
65
|
+
Raw page specified an illegal path: ${path}
|
|
66
|
+
`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const hydrated_blocks = await this.hydrateBlocks(raw_page.blocks);
|
|
70
|
+
|
|
71
|
+
const page = {
|
|
72
|
+
...raw_page,
|
|
73
|
+
blocks: hydrated_blocks,
|
|
74
|
+
path: this.getPath()
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
validatePage(page);
|
|
78
|
+
|
|
79
|
+
return page;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected formatResult(result: Page): string {
|
|
83
|
+
return result.path;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private async hydrateBlocks(blocks: Block[]): Promise<Block[]> {
|
|
87
|
+
const hydrated_blocks: Block[] = [];
|
|
88
|
+
|
|
89
|
+
for (const block of blocks) {
|
|
90
|
+
const hydrated_block = await this.hydrateBlock(block);
|
|
91
|
+
hydrated_blocks.push(hydrated_block);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return hydrated_blocks;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private async hydrateBlock(block: Block): Promise<Block> {
|
|
98
|
+
if (block.block_type === BlockType.LIST) {
|
|
99
|
+
const {data_source} = block as ListBlock;
|
|
100
|
+
|
|
101
|
+
if (data_source !== undefined) {
|
|
102
|
+
const {hydrate} = this.getConfig();
|
|
103
|
+
|
|
104
|
+
if (hydrate === undefined) {
|
|
105
|
+
throw new InvalidError(`
|
|
106
|
+
Tried to hydrate a list block for data source ${data_source}
|
|
107
|
+
`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const items = await hydrate(data_source);
|
|
111
|
+
|
|
112
|
+
block = {
|
|
113
|
+
...block,
|
|
114
|
+
items
|
|
115
|
+
} as ListBlock;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (block.children) {
|
|
120
|
+
const hydrated_children = await this.hydrateBlocks(block.children);
|
|
121
|
+
|
|
122
|
+
block = {
|
|
123
|
+
...block,
|
|
124
|
+
children: hydrated_children
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return block;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private async loadRawPage(): Promise<RawPage> {
|
|
132
|
+
const {public_directory, providers} = this.getConfig();
|
|
133
|
+
const page_path = this.getPath();
|
|
134
|
+
|
|
135
|
+
let index = 0;
|
|
136
|
+
|
|
137
|
+
const blocks: Block[] = [];
|
|
138
|
+
|
|
139
|
+
while (index < providers.length) {
|
|
140
|
+
const provider = providers[index++];
|
|
141
|
+
const {path, handler} = provider;
|
|
142
|
+
|
|
143
|
+
if (page_path === path) {
|
|
144
|
+
const subset = await handler(path);
|
|
145
|
+
|
|
146
|
+
blocks.push(...subset);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const filename = `.${page_path}/index.json`;
|
|
151
|
+
const absolute_path = Path.resolve(public_directory, filename);
|
|
152
|
+
const file_exists = await exists(absolute_path);
|
|
153
|
+
|
|
154
|
+
if (!file_exists) {
|
|
155
|
+
if (blocks.length) {
|
|
156
|
+
return {
|
|
157
|
+
blocks
|
|
158
|
+
};
|
|
159
|
+
} else if (this.shouldAutogenerate()) {
|
|
160
|
+
return this.autogenerate();
|
|
161
|
+
} else {
|
|
162
|
+
throw new NotFoundError(`Unable to find page: ${page_path}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const contents = await readFile(absolute_path, StringEncoding.UTF8);
|
|
167
|
+
const raw_page = JSON.parse(contents) as RawPage;
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
...raw_page,
|
|
171
|
+
blocks: [
|
|
172
|
+
...raw_page.blocks,
|
|
173
|
+
...blocks
|
|
174
|
+
]
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private shouldAutogenerate(): boolean {
|
|
179
|
+
const page_type = this.getCustomPageType();
|
|
180
|
+
|
|
181
|
+
switch (page_type) {
|
|
182
|
+
case CustomPageType.DATE:
|
|
183
|
+
case CustomPageType.ERROR:
|
|
184
|
+
case CustomPageType.INDEX:
|
|
185
|
+
return true;
|
|
186
|
+
|
|
187
|
+
default:
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private autogenerate(): Promise<RawPage> {
|
|
193
|
+
const path = this.getPath();
|
|
194
|
+
const page_type = this.getCustomPageType();
|
|
195
|
+
const logger = this.getLogger();
|
|
196
|
+
|
|
197
|
+
logger.warn(`
|
|
198
|
+
Page not found for path ${path};
|
|
199
|
+
autogenerating as [${page_type}]...
|
|
200
|
+
`);
|
|
201
|
+
|
|
202
|
+
switch (page_type) {
|
|
203
|
+
case CustomPageType.DATE:
|
|
204
|
+
return this.autogenerateDate();
|
|
205
|
+
case CustomPageType.ERROR:
|
|
206
|
+
return this.autogenerateError();
|
|
207
|
+
case CustomPageType.INDEX:
|
|
208
|
+
return this.autogenerateIndex();
|
|
209
|
+
|
|
210
|
+
default:
|
|
211
|
+
throw new InvalidError(`Unable to autogenerate page for path: ${path}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private async autogenerateDate(): Promise<RawPage> {
|
|
216
|
+
const path = this.getPath();
|
|
217
|
+
const date = pathToDate(path);
|
|
218
|
+
const created_at = date.getTime();
|
|
219
|
+
const month = getMonthName(date);
|
|
220
|
+
const day = date.getUTCDate();
|
|
221
|
+
const year = date.getUTCFullYear();
|
|
222
|
+
const ordinal = getShortOrdinal(day);
|
|
223
|
+
const weekday_name = getWeekdayName(date);
|
|
224
|
+
const title = `${weekday_name}, ${month} ${ordinal}, ${year}`;
|
|
225
|
+
const execution_context = this.getExecutionContext();
|
|
226
|
+
|
|
227
|
+
const ephemeral_label = (() => {
|
|
228
|
+
const logged_in = execution_context.isLoggedIn();
|
|
229
|
+
const today = createDate();
|
|
230
|
+
const date_is_today = datesAreEqual(date, today);
|
|
231
|
+
|
|
232
|
+
if (date_is_today) {
|
|
233
|
+
if (logged_in) {
|
|
234
|
+
return `nothing here yet. post using ${Emoji.NOTEPAD} ${Emoji.MICROPHONE} ${Emoji.CAMERA}`;
|
|
235
|
+
} else {
|
|
236
|
+
return 'nothing here yet.';
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const date_is_past = dateLessThan(date, today);
|
|
241
|
+
|
|
242
|
+
if (date_is_past) {
|
|
243
|
+
return 'there were no posts on this date.';
|
|
244
|
+
} else {
|
|
245
|
+
return 'this date is in the future.';
|
|
246
|
+
}
|
|
247
|
+
})();
|
|
248
|
+
|
|
249
|
+
const previous_date = decrementDate(date);
|
|
250
|
+
const previous_date_label = getCompactLabelForDate(previous_date);
|
|
251
|
+
const previous_date_path = dateToPath(previous_date);
|
|
252
|
+
const next_date = incrementDate(date);
|
|
253
|
+
const next_date_label = getCompactLabelForDate(next_date);
|
|
254
|
+
const next_date_path = dateToPath(next_date);
|
|
255
|
+
const current_week = getStartOfWeek(date);
|
|
256
|
+
const current_week_path = weekToPath(current_week);
|
|
257
|
+
const current_week_label = getOrdinalLabelForWeek(current_week);
|
|
258
|
+
|
|
259
|
+
return {
|
|
260
|
+
blocks: [
|
|
261
|
+
{
|
|
262
|
+
block_type: BlockType.LINK,
|
|
263
|
+
label: `${Emoji.UP_ARROW_UNICODE} ${current_week_label} ${Emoji.UP_ARROW_UNICODE}`,
|
|
264
|
+
href: current_week_path,
|
|
265
|
+
color: Color.BLUE,
|
|
266
|
+
created_at,
|
|
267
|
+
show_time: false
|
|
268
|
+
} as LinkBlock,
|
|
269
|
+
{
|
|
270
|
+
block_type: BlockType.MULTI_COLUMN,
|
|
271
|
+
title,
|
|
272
|
+
created_at,
|
|
273
|
+
show_time: false,
|
|
274
|
+
max_columns: 3,
|
|
275
|
+
children: [
|
|
276
|
+
{
|
|
277
|
+
block_type: BlockType.LINK,
|
|
278
|
+
label: `${Emoji.LEFT_ARROW_UNICODE} ${previous_date_label}`,
|
|
279
|
+
href: previous_date_path,
|
|
280
|
+
color: Color.BLUE,
|
|
281
|
+
created_at,
|
|
282
|
+
show_time: false
|
|
283
|
+
} as LinkBlock,
|
|
284
|
+
header(title),
|
|
285
|
+
{
|
|
286
|
+
block_type: BlockType.LINK,
|
|
287
|
+
label: `${next_date_label} ${Emoji.RIGHT_ARROW_UNICODE}`,
|
|
288
|
+
href: next_date_path,
|
|
289
|
+
color: Color.BLUE,
|
|
290
|
+
created_at,
|
|
291
|
+
show_time: false
|
|
292
|
+
} as LinkBlock
|
|
293
|
+
]
|
|
294
|
+
} as MultiColumnBlock,
|
|
295
|
+
|
|
296
|
+
{
|
|
297
|
+
block_type: BlockType.EPHEMERAL,
|
|
298
|
+
label: ephemeral_label,
|
|
299
|
+
created_at
|
|
300
|
+
} as EphemeralBlock
|
|
301
|
+
]
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private async autogenerateError(): Promise<RawPage> {
|
|
306
|
+
const path = this.getPath();
|
|
307
|
+
const parsed_key = parseInt(path.slice(1));
|
|
308
|
+
const status_code = parsed_key as StatusCode;
|
|
309
|
+
const now = Date.now();
|
|
310
|
+
const error_type = getErrorTypeForStatusCode(status_code);
|
|
311
|
+
const error = createErrorForErrorType(error_type);
|
|
312
|
+
|
|
313
|
+
const title = (() => {
|
|
314
|
+
switch (status_code) {
|
|
315
|
+
case StatusCode.BAD_REQUEST:
|
|
316
|
+
return 'invalid request';
|
|
317
|
+
case StatusCode.FILE_NOT_FOUND:
|
|
318
|
+
return '404: file not found';
|
|
319
|
+
case StatusCode.UNAUTHORIZED:
|
|
320
|
+
return 'not authorized';
|
|
321
|
+
case StatusCode.SERVER_ERROR:
|
|
322
|
+
return 'something went wrong';
|
|
323
|
+
|
|
324
|
+
default:
|
|
325
|
+
return `${status_code}: ${error.message}`;
|
|
326
|
+
}
|
|
327
|
+
})();
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
blocks: [
|
|
331
|
+
header(title),
|
|
332
|
+
{
|
|
333
|
+
block_type: BlockType.EPHEMERAL,
|
|
334
|
+
label: error.message,
|
|
335
|
+
created_at: now
|
|
336
|
+
} as EphemeralBlock
|
|
337
|
+
]
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
private async autogenerateIndex(): Promise<RawPage> {
|
|
342
|
+
const now = Date.now();
|
|
343
|
+
const {username} = this.getSession();
|
|
344
|
+
|
|
345
|
+
return {
|
|
346
|
+
blocks: [
|
|
347
|
+
header(`${username}'s home page`),
|
|
348
|
+
{
|
|
349
|
+
block_type: BlockType.EPHEMERAL,
|
|
350
|
+
label: '(nothing here yet)',
|
|
351
|
+
created_at: now
|
|
352
|
+
} as EphemeralBlock
|
|
353
|
+
]
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
private getCustomPageType(): CustomPageType {
|
|
358
|
+
const path = this.getPath();
|
|
359
|
+
|
|
360
|
+
return getCustomPageTypeForPath(path);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
private getPath(): string {
|
|
364
|
+
return this.path;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export default LoadPageOperation;
|