@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,85 @@
|
|
|
1
|
+
import Emoji from 'enum/emoji';
|
|
2
|
+
import ToolType from 'enum/tool-type';
|
|
3
|
+
import PageType from 'client/enum/page-type';
|
|
4
|
+
import BaseResultSerializer from 'server/result-serializer/base';
|
|
5
|
+
import AccountSettings from 'type/account-settings';
|
|
6
|
+
import serializeTimePlaceOptions from 'server/result-serializer/common/time-place-options';
|
|
7
|
+
import getEmojiForToolType from 'server/utility/get-emoji-for-tool-type';
|
|
8
|
+
|
|
9
|
+
class SettingsResultSerializer extends BaseResultSerializer<AccountSettings> {
|
|
10
|
+
protected getTitle(): string {
|
|
11
|
+
return 'settings';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
protected serializeSections(): string {
|
|
15
|
+
const {tool_types, default_time_place_visibility} = this.getResult();
|
|
16
|
+
|
|
17
|
+
const tool_headers = Object.values(ToolType).map((tool_type) => {
|
|
18
|
+
const emoji = getEmojiForToolType(tool_type);
|
|
19
|
+
|
|
20
|
+
return `
|
|
21
|
+
<td>
|
|
22
|
+
<label for="tool-type-${tool_type}">
|
|
23
|
+
<span class="text-very-large">${emoji}</span>
|
|
24
|
+
</label>
|
|
25
|
+
</td>
|
|
26
|
+
`;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const tool_checkboxes = Object.values(ToolType).map((tool_type) => {
|
|
30
|
+
const checked = tool_types.includes(tool_type) ? 'checked' : '';
|
|
31
|
+
|
|
32
|
+
return `
|
|
33
|
+
<td>
|
|
34
|
+
<input name="tool_types" id="tool-type-${tool_type}" type="checkbox" value="${tool_type}" ${checked} />
|
|
35
|
+
</td>
|
|
36
|
+
`;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const time_place_options = serializeTimePlaceOptions(default_time_place_visibility);
|
|
40
|
+
|
|
41
|
+
return `
|
|
42
|
+
<section class="grey">
|
|
43
|
+
<form action="/settings" method="POST">
|
|
44
|
+
<fieldset>
|
|
45
|
+
<legend>username:</legend>
|
|
46
|
+
<input type="text" name="username" placeholder="username" autofocus />
|
|
47
|
+
</fieldset>
|
|
48
|
+
|
|
49
|
+
<fieldset>
|
|
50
|
+
<legend>toolbar:</legend>
|
|
51
|
+
|
|
52
|
+
<table class="fixed">
|
|
53
|
+
<thead>
|
|
54
|
+
<tr>
|
|
55
|
+
${tool_headers.join('\n')}
|
|
56
|
+
</tr>
|
|
57
|
+
</thead>
|
|
58
|
+
<tbody>
|
|
59
|
+
<tr>
|
|
60
|
+
${tool_checkboxes.join('\n')}
|
|
61
|
+
</tr>
|
|
62
|
+
</tbody>
|
|
63
|
+
</table>
|
|
64
|
+
</fieldset>
|
|
65
|
+
|
|
66
|
+
<fieldset>
|
|
67
|
+
<legend>default time/place visibility:</legend>
|
|
68
|
+
|
|
69
|
+
${time_place_options}
|
|
70
|
+
</fieldset>
|
|
71
|
+
|
|
72
|
+
<button class="mt-32 biglink green" type="submit">
|
|
73
|
+
submit ${Emoji.RIGHT_ARROW_UNICODE}
|
|
74
|
+
</button>
|
|
75
|
+
</form>
|
|
76
|
+
</section>
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
protected getPageType(): PageType {
|
|
81
|
+
return PageType.SETTINGS;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default SettingsResultSerializer;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {getMaxValue} from 'lib/array';
|
|
2
|
+
import {randomElement, randomNumber} from 'lib/random';
|
|
3
|
+
|
|
4
|
+
import Emoji from 'enum/emoji';
|
|
5
|
+
import Week from 'type/week';
|
|
6
|
+
import BaseResultSerializer from 'server/result-serializer/base';
|
|
7
|
+
import dateToPath from 'server/utility/date-to-path';
|
|
8
|
+
import dateLessThan from 'server/utility/date-less-than';
|
|
9
|
+
import PageType from 'client/enum/page-type';
|
|
10
|
+
import BlockType from 'enum/block-type';
|
|
11
|
+
import getMonthName from 'server/utility/get-month-name';
|
|
12
|
+
import weekToPath from 'server/utility/week-to-path';
|
|
13
|
+
import weekToDate from 'server/utility/week-to-date';
|
|
14
|
+
import getEndOfWeek from 'server/utility/get-end-of-week';
|
|
15
|
+
import addDays from 'server/utility/add-days';
|
|
16
|
+
import getEmojiForBlockType from 'server/utility/get-emoji-for-block-type';
|
|
17
|
+
import getWeekdayName from 'server/utility/get-weekday-name';
|
|
18
|
+
import datesAreEqual from 'server/utility/dates-are-equal';
|
|
19
|
+
import createDate from 'server/utility/create-date';
|
|
20
|
+
import getStartOfWeek from 'server/utility/get-start-of-week';
|
|
21
|
+
import getNextWeek from 'server/utility/get-next-week';
|
|
22
|
+
import monthToPath from 'server/utility/month-to-path';
|
|
23
|
+
import getPreviousWeek from 'server/utility/get-previous-week';
|
|
24
|
+
import createToastPath from 'server/utility/create-toast-path';
|
|
25
|
+
import Color from 'enum/color';
|
|
26
|
+
|
|
27
|
+
const MEDIA_BLOCK_TYPES = [
|
|
28
|
+
BlockType.IMAGE,
|
|
29
|
+
BlockType.AUDIO,
|
|
30
|
+
BlockType.NOTE
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
class WeekResultSerializer extends BaseResultSerializer<Week> {
|
|
34
|
+
protected serializeSections(): string {
|
|
35
|
+
const serialized_days: string[] = [];
|
|
36
|
+
const target_date = this.getTargetDate();
|
|
37
|
+
const block_types_by_date: Record<string, BlockType[]> = {};
|
|
38
|
+
|
|
39
|
+
let current_date = getStartOfWeek(target_date);
|
|
40
|
+
|
|
41
|
+
while (dateLessThan(current_date, getNextWeek(target_date))) {
|
|
42
|
+
const max_blocks = 60;
|
|
43
|
+
const block_count = randomNumber(0, max_blocks);
|
|
44
|
+
const blocks: BlockType[] = [];
|
|
45
|
+
|
|
46
|
+
while (blocks.length < block_count) {
|
|
47
|
+
const block_type = randomElement(MEDIA_BLOCK_TYPES) as BlockType;
|
|
48
|
+
blocks.push(block_type);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const date_path = dateToPath(current_date);
|
|
52
|
+
|
|
53
|
+
block_types_by_date[date_path] = blocks;
|
|
54
|
+
current_date = addDays(current_date, 1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const block_lengths = Object.values(block_types_by_date).map((blocks) => {
|
|
58
|
+
return blocks.length;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const max_block_count = getMaxValue(block_lengths);
|
|
62
|
+
// We want each row to be 4 cells wide.
|
|
63
|
+
const normalized_max = Math.ceil(max_block_count / 4) * 4;
|
|
64
|
+
const reticule = '<div class="focus-reticule scaling"></div>';
|
|
65
|
+
const today = createDate();
|
|
66
|
+
const today_toast_message = `${Emoji.SUNSHINE} today ${Emoji.SUNSHINE}`;
|
|
67
|
+
|
|
68
|
+
current_date = getStartOfWeek(target_date);
|
|
69
|
+
|
|
70
|
+
while (dateLessThan(current_date, getNextWeek(target_date))) {
|
|
71
|
+
const day_name = getWeekdayName(current_date);
|
|
72
|
+
const base_path = dateToPath(current_date);
|
|
73
|
+
const day_number = current_date.getUTCDate();
|
|
74
|
+
const truncated_day_name = day_name.slice(0, 3);
|
|
75
|
+
const date_is_today = datesAreEqual(current_date, today);
|
|
76
|
+
const today_prefix = date_is_today ? Emoji.SUNSHINE : '';
|
|
77
|
+
const reticule_markup = date_is_today ? reticule : '';
|
|
78
|
+
|
|
79
|
+
const date_path = (() => {
|
|
80
|
+
if (date_is_today) {
|
|
81
|
+
return createToastPath(base_path, {
|
|
82
|
+
message: today_toast_message,
|
|
83
|
+
color: Color.YELLOW
|
|
84
|
+
});
|
|
85
|
+
} else {
|
|
86
|
+
return base_path;
|
|
87
|
+
}
|
|
88
|
+
})();
|
|
89
|
+
|
|
90
|
+
const serialized_blocks: string[] = [];
|
|
91
|
+
const blocks = block_types_by_date[base_path];
|
|
92
|
+
|
|
93
|
+
let index = 0;
|
|
94
|
+
|
|
95
|
+
while (index < normalized_max) {
|
|
96
|
+
if (index < blocks.length) {
|
|
97
|
+
const block_type = blocks[index];
|
|
98
|
+
const block_emoji = getEmojiForBlockType(block_type);
|
|
99
|
+
|
|
100
|
+
serialized_blocks.push(`
|
|
101
|
+
<a href="${base_path}?block=${index}" class="weekday-post ${block_type}">
|
|
102
|
+
${block_emoji}
|
|
103
|
+
</a>
|
|
104
|
+
`);
|
|
105
|
+
} else {
|
|
106
|
+
serialized_blocks.push(`
|
|
107
|
+
<a href="${date_path}" class="weekday-post">
|
|
108
|
+
|
|
109
|
+
</a>
|
|
110
|
+
`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
index++;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
serialized_days.push(`
|
|
117
|
+
<td class="weekday">
|
|
118
|
+
<span class="biglink">
|
|
119
|
+
<div class="focus-reticule-container">
|
|
120
|
+
${reticule_markup}
|
|
121
|
+
<a href="${date_path}" class="weekday-name">${truncated_day_name}</a>
|
|
122
|
+
<a href="${date_path}" class="weekday-date">${today_prefix}${day_number}</a>
|
|
123
|
+
</div>
|
|
124
|
+
<span class="weekday-posts" aria-label="19 posts on sunday">
|
|
125
|
+
${serialized_blocks.join('\n')}
|
|
126
|
+
</span>
|
|
127
|
+
</span>
|
|
128
|
+
</td>
|
|
129
|
+
`);
|
|
130
|
+
|
|
131
|
+
current_date = addDays(current_date, 1);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const predominant_week = getEndOfWeek(target_date);
|
|
135
|
+
const predominant_month = getStartOfWeek(predominant_week);
|
|
136
|
+
const month_name = getMonthName(predominant_month);
|
|
137
|
+
const month_path = monthToPath(predominant_month);
|
|
138
|
+
const year = predominant_month.getUTCFullYear();
|
|
139
|
+
const previous_week_path = weekToPath(getPreviousWeek(predominant_week));
|
|
140
|
+
const next_week_path = weekToPath(getNextWeek(predominant_week));
|
|
141
|
+
|
|
142
|
+
return `
|
|
143
|
+
<table>
|
|
144
|
+
<thead>
|
|
145
|
+
<tr>
|
|
146
|
+
<th class="no-background">
|
|
147
|
+
</th>
|
|
148
|
+
<th>
|
|
149
|
+
<a class="biglink mb-8" href="${month_path}">
|
|
150
|
+
${Emoji.UP_ARROW_UNICODE} ${month_name} ${year} ${Emoji.UP_ARROW_UNICODE}
|
|
151
|
+
</a>
|
|
152
|
+
</th>
|
|
153
|
+
<th class="no-background">
|
|
154
|
+
</th>
|
|
155
|
+
</tr>
|
|
156
|
+
</thead>
|
|
157
|
+
<tbody>
|
|
158
|
+
<tr>
|
|
159
|
+
<td class="biglink-container">
|
|
160
|
+
<a class="biglink stretch" href="${previous_week_path}">${Emoji.LEFT_ARROW_UNICODE}</a>
|
|
161
|
+
</td>
|
|
162
|
+
<td>
|
|
163
|
+
<table class="fixed">
|
|
164
|
+
<tbody>
|
|
165
|
+
<tr>
|
|
166
|
+
${serialized_days.join('\n')}
|
|
167
|
+
</tr>
|
|
168
|
+
</tbody>
|
|
169
|
+
</table>
|
|
170
|
+
</td>
|
|
171
|
+
<td class="biglink-container">
|
|
172
|
+
<a class="biglink stretch" href="${next_week_path}">${Emoji.RIGHT_ARROW_UNICODE}</a>
|
|
173
|
+
</td>
|
|
174
|
+
</tr>
|
|
175
|
+
</tbody>
|
|
176
|
+
</table>
|
|
177
|
+
`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
protected getTitle(): string {
|
|
181
|
+
return 'xxx';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
protected getPageType(): PageType {
|
|
185
|
+
return PageType.WEEK;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private getTargetDate(): Date {
|
|
189
|
+
const week = this.getResult();
|
|
190
|
+
|
|
191
|
+
return weekToDate(week);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export default WeekResultSerializer;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {InvariantViolation} from 'lib/errors';
|
|
2
|
+
import {getLastValue} from 'lib/array';
|
|
3
|
+
|
|
4
|
+
import Emoji from 'enum/emoji';
|
|
5
|
+
import getNextDay from 'server/utility/get-next-day';
|
|
6
|
+
import getStartOfWeek from 'server/utility/get-start-of-week';
|
|
7
|
+
import weeksAreEqual from 'server/utility/weeks-are-equal';
|
|
8
|
+
import BaseResultSerializer from 'server/result-serializer/base';
|
|
9
|
+
import PageType from 'client/enum/page-type';
|
|
10
|
+
import getMonthName from 'server/utility/get-month-name';
|
|
11
|
+
import monthHasWeekContainingDate from 'server/utility/month-has-week-containing-date';
|
|
12
|
+
import datesAreEqual from 'server/utility/dates-are-equal';
|
|
13
|
+
import monthToPath from 'server/utility/month-to-path';
|
|
14
|
+
import monthsAreEqual from 'server/utility/months-are-equal';
|
|
15
|
+
import yearsAreEqual from 'server/utility/years-are-equal';
|
|
16
|
+
import yearToPath from 'server/utility/year-to-path';
|
|
17
|
+
import createDate from 'server/utility/create-date';
|
|
18
|
+
import yearToDate from 'server/utility/year-to-date';
|
|
19
|
+
import getStartOfYear from 'server/utility/get-start-of-year';
|
|
20
|
+
import getNextYear from 'server/utility/get-next-year';
|
|
21
|
+
import getStartOfMonth from 'server/utility/get-start-of-month';
|
|
22
|
+
import Year from 'type/year';
|
|
23
|
+
import getPreviousYear from 'server/utility/get-previous-year';
|
|
24
|
+
|
|
25
|
+
class YearResultSerializer extends BaseResultSerializer<Year> {
|
|
26
|
+
protected serializeSections(): string {
|
|
27
|
+
const target_date = this.getTargetDate();
|
|
28
|
+
const year_name = target_date.getUTCFullYear();
|
|
29
|
+
const reticule = '<div class="focus-reticule scaling"></div>';
|
|
30
|
+
const today = createDate();
|
|
31
|
+
const month_sets: string[][] = [[]];
|
|
32
|
+
|
|
33
|
+
let current_date = getStartOfYear(target_date);
|
|
34
|
+
|
|
35
|
+
while (yearsAreEqual(current_date, target_date)) {
|
|
36
|
+
const serialized_weeks: string[] = [];
|
|
37
|
+
const target_month = getStartOfMonth(current_date);
|
|
38
|
+
const month_name = getMonthName(target_month);
|
|
39
|
+
const month_path = monthToPath(target_month);
|
|
40
|
+
|
|
41
|
+
current_date = getStartOfWeek(target_month);
|
|
42
|
+
|
|
43
|
+
while (monthHasWeekContainingDate(target_month, current_date)) {
|
|
44
|
+
const serialized_days: string[] = [];
|
|
45
|
+
const target_week = current_date;
|
|
46
|
+
|
|
47
|
+
while (weeksAreEqual(current_date, target_week)) {
|
|
48
|
+
if (monthsAreEqual(current_date, target_month)) {
|
|
49
|
+
const date_is_today = datesAreEqual(current_date, today);
|
|
50
|
+
const reticule_markup = date_is_today ? reticule : '';
|
|
51
|
+
const utc_date = current_date.getUTCDate();
|
|
52
|
+
const value = date_is_today ? Emoji.SUNSHINE : utc_date;
|
|
53
|
+
|
|
54
|
+
serialized_days.push(`
|
|
55
|
+
<td class="focus-reticule-container">
|
|
56
|
+
${reticule_markup}
|
|
57
|
+
${value}
|
|
58
|
+
</td>
|
|
59
|
+
`);
|
|
60
|
+
} else {
|
|
61
|
+
serialized_days.push(`
|
|
62
|
+
<td></td>
|
|
63
|
+
`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
current_date = getNextDay(current_date);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
serialized_weeks.push(`
|
|
70
|
+
<tr>
|
|
71
|
+
${serialized_days.join('\n')}
|
|
72
|
+
</tr>
|
|
73
|
+
`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const serialized_month = `
|
|
77
|
+
<td class="month">
|
|
78
|
+
<a class="biglink" href="${month_path}">
|
|
79
|
+
<span>${month_name}</span>
|
|
80
|
+
<table class="fixed compact">
|
|
81
|
+
<tbody>
|
|
82
|
+
${serialized_weeks.join('\n')}
|
|
83
|
+
</tbody>
|
|
84
|
+
</table>
|
|
85
|
+
</a>
|
|
86
|
+
</td>
|
|
87
|
+
`;
|
|
88
|
+
|
|
89
|
+
const month_set = getLastValue(month_sets);
|
|
90
|
+
|
|
91
|
+
if (month_set === undefined) {
|
|
92
|
+
throw new InvariantViolation(`
|
|
93
|
+
Tried to read month set when current date was ${current_date},
|
|
94
|
+
but it was not set
|
|
95
|
+
`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
month_set.push(serialized_month);
|
|
99
|
+
|
|
100
|
+
if (month_set.length === 3) {
|
|
101
|
+
month_sets.push([]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const month_rows = month_sets.map((month_set) => {
|
|
106
|
+
return `
|
|
107
|
+
<tr class="month-set">
|
|
108
|
+
${month_set.join('\n')}
|
|
109
|
+
</tr>
|
|
110
|
+
`;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const previous_year = getPreviousYear(target_date);
|
|
114
|
+
const previous_year_path = yearToPath(previous_year);
|
|
115
|
+
const previous_year_name = previous_year.getUTCFullYear();
|
|
116
|
+
|
|
117
|
+
const next_year = getNextYear(target_date);
|
|
118
|
+
const next_year_path = yearToPath(next_year);
|
|
119
|
+
const next_year_name = next_year.getUTCFullYear();
|
|
120
|
+
|
|
121
|
+
return `
|
|
122
|
+
<table>
|
|
123
|
+
<tbody>
|
|
124
|
+
<tr>
|
|
125
|
+
<td>
|
|
126
|
+
<a class="biglink" href="${previous_year_path}">
|
|
127
|
+
${Emoji.LEFT_ARROW_UNICODE} ${previous_year_name}
|
|
128
|
+
</a>
|
|
129
|
+
</td>
|
|
130
|
+
<td>
|
|
131
|
+
<h2 class="centered">${year_name}</h2>
|
|
132
|
+
</td>
|
|
133
|
+
<td>
|
|
134
|
+
<a class="biglink" href="${next_year_path}">
|
|
135
|
+
${next_year_name} ${Emoji.RIGHT_ARROW_UNICODE}
|
|
136
|
+
</a>
|
|
137
|
+
</td>
|
|
138
|
+
</tr>
|
|
139
|
+
${month_rows.join('\n')}
|
|
140
|
+
</tbody>
|
|
141
|
+
</table>
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
protected getTitle(): string {
|
|
146
|
+
return 'xxx';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
protected getPageType(): PageType {
|
|
150
|
+
return PageType.YEAR;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private getTargetDate(): Date {
|
|
154
|
+
const year = this.getResult();
|
|
155
|
+
|
|
156
|
+
return yearToDate(year);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export default YearResultSerializer;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {IncomingRequest, HttpHeader, ContentType} from 'lib/http';
|
|
2
|
+
|
|
3
|
+
function acceptsContentType(request: IncomingRequest, content_type: ContentType): boolean {
|
|
4
|
+
const accepts = request.getHeaderValue(HttpHeader.ACCEPT);
|
|
5
|
+
|
|
6
|
+
if (accepts === undefined) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const accepts_json = accepts.includes(content_type);
|
|
11
|
+
const accepts_any = accepts.includes(ContentType.ANY);
|
|
12
|
+
|
|
13
|
+
return accepts_json || accepts_any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default acceptsContentType;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {IncomingRequest, ContentType} from 'lib/http';
|
|
2
|
+
|
|
3
|
+
import acceptsContentType from 'server/utility/accepts-content-type';
|
|
4
|
+
|
|
5
|
+
function acceptsHtml(request: IncomingRequest): boolean {
|
|
6
|
+
return acceptsContentType(request, ContentType.HTML);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default acceptsHtml;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {IncomingRequest, ContentType} from 'lib/http';
|
|
2
|
+
|
|
3
|
+
import acceptsContentType from 'server/utility/accepts-content-type';
|
|
4
|
+
|
|
5
|
+
function acceptsJson(request: IncomingRequest): boolean {
|
|
6
|
+
return acceptsContentType(request, ContentType.JSON);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default acceptsJson;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import createDate from 'server/utility/create-date';
|
|
2
|
+
|
|
3
|
+
function addDays(old_date: Date, days: number): Date {
|
|
4
|
+
const new_date = createDate(old_date);
|
|
5
|
+
|
|
6
|
+
new_date.setUTCDate(old_date.getUTCDate() + days);
|
|
7
|
+
|
|
8
|
+
return new_date;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default addDays;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {InvariantViolation} from 'lib/errors';
|
|
2
|
+
|
|
3
|
+
type NoArgs = [];
|
|
4
|
+
type SingleDateArg = [Date];
|
|
5
|
+
type YearMonthDayArgs = [number, number, number];
|
|
6
|
+
type DatetimeStringArg = [string | number];
|
|
7
|
+
type PermittedArgs = NoArgs | SingleDateArg | YearMonthDayArgs | DatetimeStringArg;
|
|
8
|
+
|
|
9
|
+
function createDate(...args: PermittedArgs): Date {
|
|
10
|
+
const result = new Date(...args as SingleDateArg);
|
|
11
|
+
const time = result.getTime();
|
|
12
|
+
|
|
13
|
+
if (isNaN(time)) {
|
|
14
|
+
console.trace();
|
|
15
|
+
throw new InvariantViolation(`
|
|
16
|
+
Specified date was invalid: ${args}
|
|
17
|
+
`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default createDate;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {URL} from 'url';
|
|
2
|
+
|
|
3
|
+
import Toast from 'type/toast';
|
|
4
|
+
|
|
5
|
+
function createToastPath(base_path: string, toast: Toast): string {
|
|
6
|
+
const url = new URL(base_path, 'http://0.0.0.0');
|
|
7
|
+
const escaped_message = encodeURIComponent(toast.message);
|
|
8
|
+
const escaped_color = toast.color.replace('#', '%23');
|
|
9
|
+
|
|
10
|
+
url.searchParams.set('toast_message', escaped_message);
|
|
11
|
+
url.searchParams.set('toast_color', escaped_color);
|
|
12
|
+
|
|
13
|
+
const pathname = url.pathname;
|
|
14
|
+
const search = url.search || '';
|
|
15
|
+
|
|
16
|
+
return `${pathname}${search}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default createToastPath;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function dateOccursBefore(a: Date, b: Date): boolean {
|
|
2
|
+
const a_year = a.getUTCFullYear();
|
|
3
|
+
const b_year = b.getUTCFullYear();
|
|
4
|
+
|
|
5
|
+
if (a_year !== b_year) {
|
|
6
|
+
return a_year < b_year;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const a_month = a.getMonth();
|
|
10
|
+
const b_month = b.getMonth();
|
|
11
|
+
|
|
12
|
+
if (a_month !== b_month) {
|
|
13
|
+
return a_month < b_month;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const a_day = a.getDate();
|
|
17
|
+
const b_day = b.getDate();
|
|
18
|
+
|
|
19
|
+
return a_day < b_day;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default dateOccursBefore;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function datesAreEqual(a: Date, b: Date): boolean {
|
|
2
|
+
const a_day = a.getDate();
|
|
3
|
+
const b_day = b.getDate();
|
|
4
|
+
|
|
5
|
+
if (a_day !== b_day) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const a_month = a.getMonth();
|
|
10
|
+
const b_month = b.getMonth();
|
|
11
|
+
|
|
12
|
+
if (a_month !== b_month) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const a_year = a.getUTCFullYear();
|
|
17
|
+
const b_year = b.getUTCFullYear();
|
|
18
|
+
|
|
19
|
+
return a_year === b_year;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default datesAreEqual;
|