File
Blob: src/workerd/io/compatibility-date.h
| 1 | // Copyright (c) 2017-2022 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | #pragma once |
| 6 | |
| 7 | #include <workerd/io/compatibility-date.capnp.h> |
| 8 | #include <workerd/io/worker.h> |
| 9 | |
| 10 | namespace workerd { |
| 11 | |
| 12 | enum class CompatibilityDateValidation { |
| 13 | // Allow dates up through the date specified by `supportedCompatibilityDate` in |
| 14 | // `compatibility-date.capnp`. |
| 15 | CODE_VERSION, |
| 16 | |
| 17 | // Allow dates up to through the current date. |
| 18 | // |
| 19 | // This should ONLY be used by Cloudflare. If Cloudflare fails to deploy a compatibility flag |
| 20 | // before its default-on date passes, then the flag's default-on date needs to be pushed back. |
| 21 | CURRENT_DATE_FOR_CLOUDFLARE, |
| 22 | // TODO(someday): We may want to consider eliminating this and using CODE_VERSION even for |
| 23 | // Cloudflare. Once people are testing their code using the open source runtime in wrangler, |
| 24 | // they will be forced to set a date no later than `supportedCompatibilityDate` anyway. If |
| 25 | // we make sure Cloudflare is updated before the runtime used locally by Wrangler is updated, |
| 26 | // then there's no real need for Cloudflare to accept newer dates. This would then allow us |
| 27 | // to avoid the situation where a release misses the deadline implied by its compat flag |
| 28 | // default-on dates. |
| 29 | |
| 30 | // Allow any future date. This should only be used to test `compileCompatibilityFlags` itself. |
| 31 | FUTURE_FOR_TEST |
| 32 | }; |
| 33 | |
| 34 | void compileCompatibilityFlags(kj::StringPtr compatDate, |
| 35 | capnp::List<capnp::Text>::Reader compatFlags, |
| 36 | CompatibilityFlags::Builder output, |
| 37 | Worker::ValidationErrorReporter& errorReporter, |
| 38 | bool allowExperimentalFeatures, |
| 39 | CompatibilityDateValidation dateValidation); |
| 40 | void compileCompatibilityFlags(kj::StringPtr compatDate, |
| 41 | kj::ArrayPtr<const kj::String> compatFlags, |
| 42 | CompatibilityFlags::Builder output, |
| 43 | Worker::ValidationErrorReporter& errorReporter, |
| 44 | bool allowExperimentalFeatures, |
| 45 | CompatibilityDateValidation dateValidation); |
| 46 | |
| 47 | // Return an array of compatibility enable-flags which express the given FeatureFlags. The returned |
| 48 | // StringPtrs point to FeatureFlags annotation parameters, which live in static storage. |
| 49 | kj::Array<kj::StringPtr> decompileCompatibilityFlagsForFl(CompatibilityFlags::Reader input); |
| 50 | // TODO(soon): Introduce a codec which can minimize the number of flags generated by choosing a good |
| 51 | // compatibility date. |
| 52 | |
| 53 | // Exposed to unit test the parser. |
| 54 | kj::Maybe<kj::String> normalizeCompatDate(kj::StringPtr date); |
| 55 | |
| 56 | // Returns the current date as a string formatted by CompatDate. |
| 57 | kj::String currentDateStr(); |
| 58 | |
| 59 | // These values come from src/workerd/io/compatibility-date.capnp |
| 60 | static constexpr uint64_t COMPAT_ENABLE_FLAG_ANNOTATION_ID = 0xb6dabbc87cd1b03eull; |
| 61 | static constexpr uint64_t COMPAT_DISABLE_FLAG_ANNOTATION_ID = 0xd145cf1adc42577cull; |
| 62 | static constexpr uint64_t COMPAT_ENABLE_DATE_ANNOTATION_ID = 0x91a5d5d7244cf6d0ull; |
| 63 | static constexpr uint64_t COMPAT_ENABLE_ALL_DATES_ANNOTATION_ID = 0x9a1d37c8030d9418; |
| 64 | static constexpr uint64_t EXPERIMENTAl_ANNOTATION_ID = 0xe3e5a63e76284d88; |
| 65 | static constexpr uint64_t IMPLIED_BY_AFTER_DATE_ANNOTATION_ID = 0xe3e5a63e76284d89; |
| 66 | static constexpr uint64_t NEEDED_BY_FL = 0xbd23aff9deefc308ull; |
| 67 | static constexpr uint64_t PYTHON_SNAPSHOT_RELEASE_ANNOTATION_ID = 0xef74c0cc5d18cc0cull; |
| 68 | |
| 69 | } // namespace workerd |