@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,33 @@
|
|
|
1
|
+
import BlockResultSerializer from 'server/result-serializer/block';
|
|
2
|
+
import AudioBlock from 'type/block/audio';
|
|
3
|
+
|
|
4
|
+
class AudioBlockResultSerializer extends BlockResultSerializer<AudioBlock> {
|
|
5
|
+
public serializeContent(): string {
|
|
6
|
+
if (!this.canRead()) {
|
|
7
|
+
return this.serializePermissionDenied();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const {files} = this.getResult();
|
|
11
|
+
|
|
12
|
+
if (files === undefined) {
|
|
13
|
+
return this.wrapSection(`
|
|
14
|
+
<em>(no audio files specified)</em>
|
|
15
|
+
`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const serialized_files = files.map((file) => {
|
|
19
|
+
const {filename} = file;
|
|
20
|
+
const url = `/public/${filename}`;
|
|
21
|
+
|
|
22
|
+
return `
|
|
23
|
+
<audio controls src="${url}">
|
|
24
|
+
`;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return this.wrapSection(`
|
|
28
|
+
${serialized_files.join('\n')}
|
|
29
|
+
`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default AudioBlockResultSerializer;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import BlockResultSerializer from 'server/result-serializer/block';
|
|
2
|
+
import BackgroundBlock from 'type/block/background';
|
|
3
|
+
import getHexForColor from 'server/utility/get-hex-for-color';
|
|
4
|
+
|
|
5
|
+
class BackgroundBlockResultSerializer extends BlockResultSerializer<BackgroundBlock> {
|
|
6
|
+
public serializeContent(): string {
|
|
7
|
+
const {color} = this.getResult();
|
|
8
|
+
const hex = getHexForColor(color);
|
|
9
|
+
|
|
10
|
+
return this.wrapSection(`
|
|
11
|
+
<style>
|
|
12
|
+
main {
|
|
13
|
+
background: ${hex} !important;
|
|
14
|
+
}
|
|
15
|
+
</style>
|
|
16
|
+
`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default BackgroundBlockResultSerializer;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import dateToKey from 'server/utility/date-to-key';
|
|
2
|
+
import Emoji from 'enum/emoji';
|
|
3
|
+
import BlockResultSerializer from 'server/result-serializer/block';
|
|
4
|
+
import getEndOfWeek from 'server/utility/get-end-of-week';
|
|
5
|
+
import dateOccursBefore from 'server/utility/date-occurs-before';
|
|
6
|
+
import getShortOrdinal from 'server/utility/get-short-ordinal';
|
|
7
|
+
import dateToPath from 'server/utility/date-to-path';
|
|
8
|
+
import getOrdinalLabelForWeek from 'server/utility/get-ordinal-label-for-week';
|
|
9
|
+
import weekToPath from 'server/utility/week-to-path';
|
|
10
|
+
import createToastPath from 'server/utility/create-toast-path';
|
|
11
|
+
import Color from 'enum/color';
|
|
12
|
+
import datesAreEqual from 'server/utility/dates-are-equal';
|
|
13
|
+
import getWeekdayName from 'server/utility/get-weekday-name';
|
|
14
|
+
import addDays from 'server/utility/add-days';
|
|
15
|
+
import Block from 'type/block';
|
|
16
|
+
import getMonthName from 'server/utility/get-month-name';
|
|
17
|
+
import createDate from 'server/utility/create-date';
|
|
18
|
+
import dateToLabel from 'server/utility/date-to-label';
|
|
19
|
+
import subtractDays from 'server/utility/subtract-days';
|
|
20
|
+
|
|
21
|
+
class CalendarBlockResultSerializer extends BlockResultSerializer<Block> {
|
|
22
|
+
public serializeContent(): string {
|
|
23
|
+
const target_date = this.getTargetDate();
|
|
24
|
+
const month_name = getMonthName(target_date);
|
|
25
|
+
const day_index = target_date.getUTCDate();
|
|
26
|
+
const year = target_date.getUTCFullYear();
|
|
27
|
+
const day_ordinal = getShortOrdinal(day_index);
|
|
28
|
+
|
|
29
|
+
const weekday_name = getWeekdayName(target_date);
|
|
30
|
+
const previous_date = subtractDays(target_date, 1);
|
|
31
|
+
const previous_path = dateToPath(previous_date);
|
|
32
|
+
const previous_label = dateToLabel(previous_date);
|
|
33
|
+
const next_date = addDays(target_date, 1);
|
|
34
|
+
const next_path = dateToPath(next_date);
|
|
35
|
+
const next_label = dateToLabel(next_date);
|
|
36
|
+
const predominant_week = getEndOfWeek(target_date);
|
|
37
|
+
const week_label = getOrdinalLabelForWeek(predominant_week);
|
|
38
|
+
const week_path = weekToPath(predominant_week);
|
|
39
|
+
const today = createDate();
|
|
40
|
+
const today_key = dateToKey(today);
|
|
41
|
+
const base_path = dateToPath(today);
|
|
42
|
+
const day_is_today = datesAreEqual(target_date, today);
|
|
43
|
+
const today_emoji = Emoji.SUNSHINE;
|
|
44
|
+
|
|
45
|
+
const multiline_date = `
|
|
46
|
+
${weekday_name}
|
|
47
|
+
<br />
|
|
48
|
+
${month_name} ${day_ordinal}
|
|
49
|
+
<br />
|
|
50
|
+
${year}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
const current_day_markup = !day_is_today ? `<h2>${multiline_date}</h2>` : `
|
|
54
|
+
<h2 class="nowrap">
|
|
55
|
+
${today_emoji} today ${today_emoji}
|
|
56
|
+
</h2>
|
|
57
|
+
|
|
58
|
+
<em>${multiline_date}</em>
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
const toast_message = `${Emoji.SUNSHINE} today ${Emoji.SUNSHINE}`;
|
|
62
|
+
|
|
63
|
+
const today_path = createToastPath(`${base_path}?highlight_date=${today_key}`, {
|
|
64
|
+
message: toast_message,
|
|
65
|
+
color: Color.YELLOW
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const today_before_day = dateOccursBefore(today, target_date);
|
|
69
|
+
const toast_prefix = today_before_day ? Emoji.LEFT_ARROW_UNICODE : '';
|
|
70
|
+
const toast_suffix = today_before_day ? '' : Emoji.RIGHT_ARROW_UNICODE;
|
|
71
|
+
|
|
72
|
+
const other_day_markup = day_is_today ? '' : `
|
|
73
|
+
<table class="fixed mt-8">
|
|
74
|
+
<tbody>
|
|
75
|
+
<tr>
|
|
76
|
+
<td>
|
|
77
|
+
<a class="biglink" href="${today_path}">
|
|
78
|
+
${toast_prefix}
|
|
79
|
+
go to ${toast_message}
|
|
80
|
+
${toast_suffix}
|
|
81
|
+
</a>
|
|
82
|
+
</td>
|
|
83
|
+
</tr>
|
|
84
|
+
</tbody>
|
|
85
|
+
</table>
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
const full_previous_path = (() => {
|
|
89
|
+
if (datesAreEqual(today, previous_date)) {
|
|
90
|
+
return createToastPath(previous_path, {
|
|
91
|
+
message: toast_message,
|
|
92
|
+
color: Color.YELLOW
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
return previous_path;
|
|
96
|
+
}
|
|
97
|
+
})();
|
|
98
|
+
|
|
99
|
+
const full_next_path = (() => {
|
|
100
|
+
if (datesAreEqual(today, next_date)) {
|
|
101
|
+
return createToastPath(next_path, {
|
|
102
|
+
message: toast_message,
|
|
103
|
+
color: Color.YELLOW
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
return next_path;
|
|
107
|
+
}
|
|
108
|
+
})();
|
|
109
|
+
|
|
110
|
+
const primary_section_markup = this.wrapSection(`
|
|
111
|
+
<a class="biglink mb-8" href="${week_path}">
|
|
112
|
+
${Emoji.UP_ARROW_UNICODE} ${week_label} ${Emoji.UP_ARROW_UNICODE}
|
|
113
|
+
</a>
|
|
114
|
+
|
|
115
|
+
<table class="fixed">
|
|
116
|
+
<tr>
|
|
117
|
+
<td class="biglink-container">
|
|
118
|
+
<a class="biglink stretch" href="${full_previous_path}">
|
|
119
|
+
${Emoji.LEFT_ARROW_UNICODE} ${previous_label}
|
|
120
|
+
</a>
|
|
121
|
+
</td>
|
|
122
|
+
<td>
|
|
123
|
+
${current_day_markup}
|
|
124
|
+
</td>
|
|
125
|
+
<td class="biglink-container">
|
|
126
|
+
<a class="biglink stretch" href="${full_next_path}">
|
|
127
|
+
${next_label} ${Emoji.RIGHT_ARROW_UNICODE}
|
|
128
|
+
</a>
|
|
129
|
+
</td>
|
|
130
|
+
</tr>
|
|
131
|
+
</table>
|
|
132
|
+
|
|
133
|
+
${other_day_markup}
|
|
134
|
+
`);
|
|
135
|
+
|
|
136
|
+
return `
|
|
137
|
+
${primary_section_markup}
|
|
138
|
+
`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private getTargetDate(): Date {
|
|
142
|
+
const date = createDate();
|
|
143
|
+
|
|
144
|
+
return date;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default CalendarBlockResultSerializer;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Path from 'path';
|
|
2
|
+
|
|
3
|
+
import BlockResultSerializer from 'server/result-serializer/block';
|
|
4
|
+
import Emoji from 'enum/emoji';
|
|
5
|
+
import DirectoryItemType from 'enum/directory-item-type';
|
|
6
|
+
import DirectoryBlock, {DirectoryItem} from 'type/block/directory';
|
|
7
|
+
|
|
8
|
+
class DirectoryBlockResultSerializer extends BlockResultSerializer<DirectoryBlock> {
|
|
9
|
+
public serializeContent(): string {
|
|
10
|
+
const block = this.getResult();
|
|
11
|
+
const {items, path} = block;
|
|
12
|
+
|
|
13
|
+
if (items === undefined || !Array.isArray(items)) {
|
|
14
|
+
return this.printWarning(`
|
|
15
|
+
Got invalid config for directory block (no items specified):
|
|
16
|
+
${JSON.stringify(block)}
|
|
17
|
+
`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const serialized_items = items.map((directory_item) => {
|
|
21
|
+
return this.serializeDirectoryItem(directory_item);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return this.wrapSection(`
|
|
25
|
+
<h4>contents of <em>${path}</em>:</h4>
|
|
26
|
+
<ul>
|
|
27
|
+
${serialized_items.join('\n')}
|
|
28
|
+
</ul>
|
|
29
|
+
`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private serializeDirectoryItem(directory_item: DirectoryItem): string {
|
|
33
|
+
const {filename, item_type} = directory_item;
|
|
34
|
+
const {page_path} = this.getMetadata();
|
|
35
|
+
const path = Path.resolve(page_path, filename);
|
|
36
|
+
|
|
37
|
+
const emoji = (() => {
|
|
38
|
+
switch (item_type) {
|
|
39
|
+
case DirectoryItemType.DIRECTORY:
|
|
40
|
+
return Emoji.FOLDER;
|
|
41
|
+
case DirectoryItemType.GENERIC_FILE:
|
|
42
|
+
default:
|
|
43
|
+
return Emoji.FILE;
|
|
44
|
+
}
|
|
45
|
+
})();
|
|
46
|
+
|
|
47
|
+
return `
|
|
48
|
+
<li class="mt-8">
|
|
49
|
+
<a class="biglink yellow align-left" href="${path}">
|
|
50
|
+
${emoji} ${filename}
|
|
51
|
+
</a>
|
|
52
|
+
</li>
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default DirectoryBlockResultSerializer;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import BlockResultSerializer from 'server/result-serializer/block';
|
|
2
|
+
import EphemeralBlock from 'type/block/ephemeral';
|
|
3
|
+
|
|
4
|
+
class EphemeralBlockResultSerializer extends BlockResultSerializer<EphemeralBlock> {
|
|
5
|
+
public serializeContent(): string {
|
|
6
|
+
const {label} = this.getResult();
|
|
7
|
+
|
|
8
|
+
return this.wrapSection(`
|
|
9
|
+
<span class="ephemeral">${label}</span>
|
|
10
|
+
`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default EphemeralBlockResultSerializer;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import getElementIdForBlock from 'server/utility/get-element-id-for-block';
|
|
2
|
+
import BlockResultSerializer from 'server/result-serializer/block';
|
|
3
|
+
import Color from 'enum/color';
|
|
4
|
+
import FolderBlock from 'type/block/folder';
|
|
5
|
+
import Emoji from 'enum/emoji';
|
|
6
|
+
import getPathForFolderBlock from 'server/utility/get-path-for-folder-block';
|
|
7
|
+
|
|
8
|
+
class FolderBlockResultSerializer extends BlockResultSerializer<FolderBlock> {
|
|
9
|
+
public serializeContent(): string {
|
|
10
|
+
const block_id = this.getBlockId();
|
|
11
|
+
const title = this.getBlockTitle();
|
|
12
|
+
const color = this.getColor();
|
|
13
|
+
const subtitle = this.serializeSubtitle();
|
|
14
|
+
const emoji = this.getEmoji();
|
|
15
|
+
const path = this.getBlockPath();
|
|
16
|
+
|
|
17
|
+
return this.wrapSection(`
|
|
18
|
+
<a data-role="block_activation" class="biglink ${color} wrap" href="${path}">
|
|
19
|
+
<table>
|
|
20
|
+
<tr>
|
|
21
|
+
<td class="p-8" style="width:15%">
|
|
22
|
+
<h1 class="m-0">${emoji}</h1>
|
|
23
|
+
</td>
|
|
24
|
+
<td class="p-8 align-left">
|
|
25
|
+
<h4 id="${block_id}-title-target">${title}</h4>
|
|
26
|
+
${subtitle}
|
|
27
|
+
</td>
|
|
28
|
+
<td class="p-8" style="width:15%">
|
|
29
|
+
${Emoji.RIGHT_ARROW_UNICODE}
|
|
30
|
+
</td>
|
|
31
|
+
</tr>
|
|
32
|
+
</table>
|
|
33
|
+
</a>
|
|
34
|
+
`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private getBlockId(): string {
|
|
38
|
+
const block = this.getResult();
|
|
39
|
+
const metadata = this.getMetadata();
|
|
40
|
+
|
|
41
|
+
return getElementIdForBlock(block, metadata);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private getBlockTitle(): string {
|
|
45
|
+
const {title} = this.getResult();
|
|
46
|
+
|
|
47
|
+
return title || '<em>no text supplied</em>';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private getColor(): Color {
|
|
51
|
+
const {color} = this.getResult();
|
|
52
|
+
|
|
53
|
+
return color;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private getEmoji(): Emoji {
|
|
57
|
+
if (!this.canRead()) {
|
|
58
|
+
return Emoji.LOCKED;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const {emoji} = this.getResult();
|
|
62
|
+
|
|
63
|
+
return emoji;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private serializeSubtitle(): string {
|
|
67
|
+
const block = this.getResult();
|
|
68
|
+
const subtitle = this.getSubtitle();
|
|
69
|
+
const metadata = this.getMetadata();
|
|
70
|
+
const path = this.getBlockPath();
|
|
71
|
+
const block_id = getElementIdForBlock(block, metadata);
|
|
72
|
+
const has_subtitle = subtitle !== '';
|
|
73
|
+
|
|
74
|
+
const path_visibility_class = has_subtitle ? 'hidden': '';
|
|
75
|
+
const subtitle_visibility_class = has_subtitle ? '' : 'hidden';
|
|
76
|
+
|
|
77
|
+
return `
|
|
78
|
+
<code id="${block_id}-path-target" class="${path_visibility_class} text-smaller three-quarter-opacity">${path}</code>
|
|
79
|
+
<h5 class="${subtitle_visibility_class} three-quarter-opacity m-0 mt-4" id="${block_id}-subtitle-target">
|
|
80
|
+
${subtitle}
|
|
81
|
+
</h5>
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private getSubtitle(): string {
|
|
86
|
+
if (!this.canRead()) {
|
|
87
|
+
return this.getPermissionDeniedMessage();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const {subtitle} = this.getResult();
|
|
91
|
+
|
|
92
|
+
return subtitle;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private getBlockPath(): string {
|
|
96
|
+
const block = this.getResult();
|
|
97
|
+
const {page_path} = this.getMetadata();
|
|
98
|
+
|
|
99
|
+
return getPathForFolderBlock({
|
|
100
|
+
block,
|
|
101
|
+
base_path: page_path
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default FolderBlockResultSerializer;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import BlockResultSerializer from 'server/result-serializer/block';
|
|
2
|
+
import HeaderBlock from 'type/block/header';
|
|
3
|
+
import HeaderSize from 'enum/header-size';
|
|
4
|
+
|
|
5
|
+
class HeaderBlockResultSerializer extends BlockResultSerializer<HeaderBlock> {
|
|
6
|
+
public serializeContent(): string {
|
|
7
|
+
if (!this.canRead()) {
|
|
8
|
+
return this.serializePermissionDenied();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const {title, size} = this.getResult();
|
|
12
|
+
|
|
13
|
+
const tag = (() => {
|
|
14
|
+
switch (size) {
|
|
15
|
+
case HeaderSize.SMALL:
|
|
16
|
+
return 'h3';
|
|
17
|
+
case HeaderSize.MEDIUM:
|
|
18
|
+
return 'h2';
|
|
19
|
+
case HeaderSize.LARGE:
|
|
20
|
+
default:
|
|
21
|
+
return 'h1';
|
|
22
|
+
}
|
|
23
|
+
})();
|
|
24
|
+
|
|
25
|
+
return this.wrapSection(`
|
|
26
|
+
<${tag}>${title}</${tag}>
|
|
27
|
+
`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default HeaderBlockResultSerializer;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Path from 'path';
|
|
2
|
+
|
|
3
|
+
import BlockResultSerializer from 'server/result-serializer/block';
|
|
4
|
+
import ImageBlock from 'type/block/image';
|
|
5
|
+
import getElementIdForBlock from 'server/utility/get-element-id-for-block';
|
|
6
|
+
|
|
7
|
+
class ImageBlockResultSerializer extends BlockResultSerializer<ImageBlock> {
|
|
8
|
+
public serializeContent(): string {
|
|
9
|
+
if (!this.canRead()) {
|
|
10
|
+
return this.serializePermissionDenied();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const page_path = this.getPagePath();
|
|
14
|
+
const block = this.getResult();
|
|
15
|
+
const {files} = block;
|
|
16
|
+
const metadata = this.getMetadata();
|
|
17
|
+
const block_id = getElementIdForBlock(block, metadata);
|
|
18
|
+
|
|
19
|
+
if (files === undefined || files.length === 0) {
|
|
20
|
+
return this.wrapSection(`
|
|
21
|
+
<div id="${block_id}-image-container">
|
|
22
|
+
<em>(no image specified)</em>
|
|
23
|
+
</div>
|
|
24
|
+
`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const serialized_files = files.map((file) => {
|
|
28
|
+
const {filename} = file;
|
|
29
|
+
const file_path = Path.resolve(page_path, `./${filename}`);
|
|
30
|
+
|
|
31
|
+
return `
|
|
32
|
+
<a data-role="block_activation" href="${file_path}">
|
|
33
|
+
<img class="thumbnail" src="${file_path}" />
|
|
34
|
+
</a>
|
|
35
|
+
`;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return this.wrapSection(`
|
|
39
|
+
<div id="${block_id}-image-container">
|
|
40
|
+
${serialized_files.join('\n')}
|
|
41
|
+
</div>
|
|
42
|
+
`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default ImageBlockResultSerializer;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import BlockResultSerializer from 'server/result-serializer/block';
|
|
2
|
+
import Color from 'enum/color';
|
|
3
|
+
import LinkBlock from 'type/block/link';
|
|
4
|
+
|
|
5
|
+
class LinkBlockResultSerializer extends BlockResultSerializer<LinkBlock> {
|
|
6
|
+
public serializeContent(): string {
|
|
7
|
+
const block = this.getResult();
|
|
8
|
+
const {label, href, color} = block;
|
|
9
|
+
const all_colors = Object.values(Color);
|
|
10
|
+
|
|
11
|
+
if (typeof label !== 'string') {
|
|
12
|
+
return this.printWarning(`
|
|
13
|
+
Got invalid config for link block (no label content):
|
|
14
|
+
${JSON.stringify(block)}
|
|
15
|
+
`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (typeof href !== 'string') {
|
|
19
|
+
return this.printWarning(`
|
|
20
|
+
Got invalid config for link block (no href content):
|
|
21
|
+
${JSON.stringify(block)}
|
|
22
|
+
`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!all_colors.includes(color)) {
|
|
26
|
+
return this.printWarning(`
|
|
27
|
+
Got invalid config for link block (unsupported color):
|
|
28
|
+
${JSON.stringify(block)}
|
|
29
|
+
`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return this.wrapSection(`
|
|
33
|
+
<a class="biglink ${color} p-16" href="${href}">
|
|
34
|
+
${label}
|
|
35
|
+
</a>
|
|
36
|
+
`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default LinkBlockResultSerializer;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {InvariantViolation} from 'lib/errors';
|
|
2
|
+
|
|
3
|
+
import BlockResultSerializer from 'server/result-serializer/block';
|
|
4
|
+
import ListBlock from 'type/block/list';
|
|
5
|
+
import FieldDefinition from 'type/field-definition';
|
|
6
|
+
import FieldType from 'enum/field-type';
|
|
7
|
+
import Resource from 'type/resource';
|
|
8
|
+
import Price from 'type/price';
|
|
9
|
+
import FieldValue from 'type/field-value';
|
|
10
|
+
import dateToLabel from 'server/utility/date-to-label';
|
|
11
|
+
|
|
12
|
+
class ListBlockResultSerializer extends BlockResultSerializer<ListBlock> {
|
|
13
|
+
public serializeContent(): string {
|
|
14
|
+
const block = this.getResult();
|
|
15
|
+
const {fields, items} = block;
|
|
16
|
+
|
|
17
|
+
if (!Array.isArray(fields)) {
|
|
18
|
+
return this.printWarning(`
|
|
19
|
+
Got invalid config for list block (no fields defined):
|
|
20
|
+
${JSON.stringify(block)}
|
|
21
|
+
`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!Array.isArray(items)) {
|
|
25
|
+
return this.printWarning(`
|
|
26
|
+
Got invalid config for list block (no items defined):
|
|
27
|
+
${JSON.stringify(block)}
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const serialized_headers = this.serializeHeaders(fields);
|
|
32
|
+
const serialized_items = this.serializeItems(fields, items);
|
|
33
|
+
|
|
34
|
+
return this.wrapSection(`
|
|
35
|
+
<table class="resource-list align-left">
|
|
36
|
+
<thead>
|
|
37
|
+
<tr>
|
|
38
|
+
${serialized_headers}
|
|
39
|
+
</tr>
|
|
40
|
+
</thead>
|
|
41
|
+
<tbody>
|
|
42
|
+
${serialized_items}
|
|
43
|
+
</tbody>
|
|
44
|
+
</table>
|
|
45
|
+
`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private serializeHeaders(fields: FieldDefinition[]): string {
|
|
49
|
+
const keys = fields.map((field) => {
|
|
50
|
+
return field.key;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const serialized_cells = keys.map((key) => {
|
|
54
|
+
return `
|
|
55
|
+
<th>
|
|
56
|
+
<a class="biglink blue align-left" href="?sort_by=${key}">${key}</a>
|
|
57
|
+
</th>
|
|
58
|
+
`;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return serialized_cells.join('\n');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private serializeItems(fields: FieldDefinition[], items: Resource[]): string {
|
|
65
|
+
const serialized_items = items.map((item) => {
|
|
66
|
+
const serialized_cells = fields.map((field) => {
|
|
67
|
+
const {key} = field;
|
|
68
|
+
const value = item[key];
|
|
69
|
+
|
|
70
|
+
if (value === undefined) {
|
|
71
|
+
throw new InvariantViolation(`
|
|
72
|
+
Tried to read value for key "${key}", but it was not set
|
|
73
|
+
`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const serialized_value = this.serializeValue(field, value);
|
|
77
|
+
|
|
78
|
+
return `
|
|
79
|
+
<td>${serialized_value}</td>
|
|
80
|
+
`;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return `
|
|
84
|
+
<tr>
|
|
85
|
+
${serialized_cells.join('\n')}
|
|
86
|
+
</tr>
|
|
87
|
+
`;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return serialized_items.join('\n');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private serializeValue(field: FieldDefinition, value: FieldValue): string {
|
|
94
|
+
const {field_type} = field;
|
|
95
|
+
|
|
96
|
+
switch (field_type) {
|
|
97
|
+
case FieldType.TEXT:
|
|
98
|
+
return this.serializeTextValue(field, value as string);
|
|
99
|
+
|
|
100
|
+
case FieldType.PRICE:
|
|
101
|
+
return this.serializePriceValue(field, value as Price);
|
|
102
|
+
|
|
103
|
+
case FieldType.DATE:
|
|
104
|
+
return this.serializeDateValue(field, value as number);
|
|
105
|
+
|
|
106
|
+
case FieldType.ENUM:
|
|
107
|
+
return this.serializeEnumValue(field, value as string);
|
|
108
|
+
|
|
109
|
+
default:
|
|
110
|
+
throw new InvariantViolation(`Unsupported field type: ${field_type}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private serializeTextValue(field: FieldDefinition, value: string): string {
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private serializePriceValue(field: FieldDefinition, price: Price): string {
|
|
119
|
+
const {amount, currency_code} = price;
|
|
120
|
+
|
|
121
|
+
return `
|
|
122
|
+
$${amount} ${currency_code}
|
|
123
|
+
`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private serializeDateValue(field: FieldDefinition, timestamp: number): string {
|
|
127
|
+
const date = new Date(timestamp);
|
|
128
|
+
const label = dateToLabel(date);
|
|
129
|
+
|
|
130
|
+
return `
|
|
131
|
+
${label}
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private serializeEnumValue(field: FieldDefinition, value: string): string {
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export default ListBlockResultSerializer;
|