miniflare 0.0.0-e55f489db → 0.0.0-e5ae13ade

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.
@@ -7720,6 +7720,181 @@ var require_index_cjs = __commonJS({
7720
7720
  }
7721
7721
  });
7722
7722
 
7723
+ // ../workers-shared/utils/responses.ts
7724
+ var OkResponse = class _OkResponse extends Response {
7725
+ static {
7726
+ this.status = 200;
7727
+ }
7728
+ constructor(body, init) {
7729
+ super(body, {
7730
+ ...init,
7731
+ status: _OkResponse.status
7732
+ });
7733
+ }
7734
+ }, NotFoundResponse = class _NotFoundResponse extends Response {
7735
+ static {
7736
+ this.status = 404;
7737
+ }
7738
+ constructor(...[body, init]) {
7739
+ super(body, {
7740
+ ...init,
7741
+ status: _NotFoundResponse.status,
7742
+ statusText: "Not Found"
7743
+ });
7744
+ }
7745
+ };
7746
+ var MethodNotAllowedResponse = class _MethodNotAllowedResponse extends Response {
7747
+ static {
7748
+ this.status = 405;
7749
+ }
7750
+ constructor(...[body, init]) {
7751
+ super(body, {
7752
+ ...init,
7753
+ status: _MethodNotAllowedResponse.status,
7754
+ statusText: "Method Not Allowed"
7755
+ });
7756
+ }
7757
+ }, InternalServerErrorResponse = class _InternalServerErrorResponse extends Response {
7758
+ static {
7759
+ this.status = 500;
7760
+ }
7761
+ constructor(err, init) {
7762
+ super(null, {
7763
+ ...init,
7764
+ status: _InternalServerErrorResponse.status
7765
+ });
7766
+ }
7767
+ }, NotModifiedResponse = class _NotModifiedResponse extends Response {
7768
+ static {
7769
+ this.status = 304;
7770
+ }
7771
+ constructor(...[_body, init]) {
7772
+ super(null, {
7773
+ ...init,
7774
+ status: _NotModifiedResponse.status,
7775
+ statusText: "Not Modified"
7776
+ });
7777
+ }
7778
+ }, MovedPermanentlyResponse = class _MovedPermanentlyResponse extends Response {
7779
+ static {
7780
+ this.status = 301;
7781
+ }
7782
+ constructor(location, init) {
7783
+ super(null, {
7784
+ ...init,
7785
+ status: _MovedPermanentlyResponse.status,
7786
+ statusText: "Moved Permanently",
7787
+ headers: {
7788
+ ...init?.headers,
7789
+ Location: location
7790
+ }
7791
+ });
7792
+ }
7793
+ }, FoundResponse = class _FoundResponse extends Response {
7794
+ static {
7795
+ this.status = 302;
7796
+ }
7797
+ constructor(location, init) {
7798
+ super(null, {
7799
+ ...init,
7800
+ status: _FoundResponse.status,
7801
+ statusText: "Found",
7802
+ headers: {
7803
+ ...init?.headers,
7804
+ Location: location
7805
+ }
7806
+ });
7807
+ }
7808
+ }, SeeOtherResponse = class _SeeOtherResponse extends Response {
7809
+ static {
7810
+ this.status = 303;
7811
+ }
7812
+ constructor(location, init) {
7813
+ super(null, {
7814
+ ...init,
7815
+ status: _SeeOtherResponse.status,
7816
+ statusText: "See Other",
7817
+ headers: {
7818
+ ...init?.headers,
7819
+ Location: location
7820
+ }
7821
+ });
7822
+ }
7823
+ }, TemporaryRedirectResponse = class _TemporaryRedirectResponse extends Response {
7824
+ static {
7825
+ this.status = 307;
7826
+ }
7827
+ constructor(location, init) {
7828
+ super(null, {
7829
+ ...init,
7830
+ status: _TemporaryRedirectResponse.status,
7831
+ statusText: "Temporary Redirect",
7832
+ headers: {
7833
+ ...init?.headers,
7834
+ Location: location
7835
+ }
7836
+ });
7837
+ }
7838
+ }, PermanentRedirectResponse = class _PermanentRedirectResponse extends Response {
7839
+ static {
7840
+ this.status = 308;
7841
+ }
7842
+ constructor(location, init) {
7843
+ super(null, {
7844
+ ...init,
7845
+ status: _PermanentRedirectResponse.status,
7846
+ statusText: "Permanent Redirect",
7847
+ headers: {
7848
+ ...init?.headers,
7849
+ Location: location
7850
+ }
7851
+ });
7852
+ }
7853
+ };
7854
+
7855
+ // ../workers-shared/utils/tracing.ts
7856
+ function mockJaegerBindingSpan() {
7857
+ return {
7858
+ addLogs: () => {
7859
+ },
7860
+ setTags: () => {
7861
+ },
7862
+ end: () => {
7863
+ },
7864
+ isRecording: !0
7865
+ };
7866
+ }
7867
+ function mockJaegerBinding() {
7868
+ return {
7869
+ enterSpan: (_, span, ...args) => span(mockJaegerBindingSpan(), ...args),
7870
+ getSpanContext: () => ({
7871
+ traceId: "test-trace",
7872
+ spanId: "test-span",
7873
+ parentSpanId: "test-parent-span",
7874
+ traceFlags: 0
7875
+ }),
7876
+ runWithSpanContext: (_, callback, ...args) => callback(...args),
7877
+ traceId: "test-trace",
7878
+ spanId: "test-span",
7879
+ parentSpanId: "test-parent-span",
7880
+ cfTraceIdHeader: "test-trace:test-span:0"
7881
+ };
7882
+ }
7883
+
7884
+ // ../workers-shared/asset-worker/src/utils/rules-engine.ts
7885
+ var ESCAPE_REGEX_CHARACTERS = /[-/\\^$*+?.()|[\]{}]/g, escapeRegex = (str) => str.replace(ESCAPE_REGEX_CHARACTERS, "\\$&");
7886
+ var generateGlobOnlyRuleRegExp = (rule) => (rule = rule.split("*").map(escapeRegex).join(".*"), rule = "^" + rule + "$", RegExp(rule));
7887
+ var generateStaticRoutingRuleMatcher = (rules) => ({ request }) => {
7888
+ let { pathname } = new URL(request.url);
7889
+ for (let rule of rules)
7890
+ try {
7891
+ if (generateGlobOnlyRuleRegExp(rule).test(pathname))
7892
+ return !0;
7893
+ } catch {
7894
+ }
7895
+ return !1;
7896
+ };
7897
+
7723
7898
  // ../workers-shared/utils/performance.ts
7724
7899
  var PerformanceTimer = class {
7725
7900
  constructor(performanceTimer) {
@@ -7771,35 +7946,6 @@ function setupSentry(request, context, dsn, clientId, clientSecret, coloMetadata
7771
7946
  return coloMetadata && (sentry.setTag("colo", coloMetadata.coloId), sentry.setTag("metal", coloMetadata.metalId)), accountId && scriptId && (sentry.setTag("accountId", accountId), sentry.setTag("scriptId", scriptId)), sentry.setUser({ id: accountId?.toString() }), sentry;
7772
7947
  }
7773
7948
 
7774
- // ../workers-shared/utils/tracing.ts
7775
- function mockJaegerBindingSpan() {
7776
- return {
7777
- addLogs: () => {
7778
- },
7779
- setTags: () => {
7780
- },
7781
- end: () => {
7782
- },
7783
- isRecording: !0
7784
- };
7785
- }
7786
- function mockJaegerBinding() {
7787
- return {
7788
- enterSpan: (_, span, ...args) => span(mockJaegerBindingSpan(), ...args),
7789
- getSpanContext: () => ({
7790
- traceId: "test-trace",
7791
- spanId: "test-span",
7792
- parentSpanId: "test-parent-span",
7793
- traceFlags: 0
7794
- }),
7795
- runWithSpanContext: (_, callback, ...args) => callback(...args),
7796
- traceId: "test-trace",
7797
- spanId: "test-span",
7798
- parentSpanId: "test-parent-span",
7799
- cfTraceIdHeader: "test-trace:test-span:0"
7800
- };
7801
- }
7802
-
7803
7949
  // ../workers-shared/router-worker/src/analytics.ts
7804
7950
  var Analytics = class {
7805
7951
  constructor(readyAnalytics) {
@@ -7827,7 +7973,9 @@ var Analytics = class {
7827
7973
  // double3
7828
7974
  this.data.coloTier ?? -1,
7829
7975
  // double4
7830
- this.data.userWorkerAhead === void 0 ? -1 : Number(this.data.userWorkerAhead)
7976
+ this.data.userWorkerAhead === void 0 ? -1 : Number(this.data.userWorkerAhead),
7977
+ this.data.staticRoutingDecision ?? 0 /* NOT_PROVIDED */
7978
+ // double6
7831
7979
  ],
7832
7980
  blobs: [
7833
7981
  this.data.hostname?.substring(0, 256),
@@ -7851,7 +7999,11 @@ var applyConfigurationDefaults = (configuration) => ({
7851
7999
  has_user_worker: configuration?.has_user_worker ?? !1,
7852
8000
  account_id: configuration?.account_id ?? -1,
7853
8001
  script_id: configuration?.script_id ?? -1,
7854
- debug: configuration?.debug ?? !1
8002
+ debug: configuration?.debug ?? !1,
8003
+ static_routing: configuration?.static_routing ?? {
8004
+ version: 1,
8005
+ include: []
8006
+ }
7855
8007
  });
7856
8008
 
7857
8009
  // ../workers-shared/router-worker/src/index.ts
@@ -7870,7 +8022,7 @@ var src_default = {
7870
8022
  env.CONFIG?.account_id,
7871
8023
  env.CONFIG?.script_id
7872
8024
  );
7873
- let config = applyConfigurationDefaults(env.CONFIG), url = new URL(request.url);
8025
+ let hasStaticRouting = env.CONFIG.static_routing !== void 0, config = applyConfigurationDefaults(env.CONFIG), url = new URL(request.url);
7874
8026
  env.COLO_METADATA && env.VERSION_METADATA && env.CONFIG && analytics.setData({
7875
8027
  accountId: env.CONFIG.account_id,
7876
8028
  scriptId: env.CONFIG.script_id,
@@ -7883,6 +8035,42 @@ var src_default = {
7883
8035
  userWorkerAhead: config.invoke_user_worker_ahead_of_assets
7884
8036
  });
7885
8037
  let maybeSecondRequest = request.clone();
8038
+ if (config.static_routing) {
8039
+ if (generateStaticRoutingRuleMatcher(
8040
+ config.static_routing.exclude ?? []
8041
+ )({
8042
+ request
8043
+ }))
8044
+ return analytics.setData({
8045
+ dispatchtype: "asset" /* ASSETS */,
8046
+ staticRoutingDecision: 2 /* EXCLUDE */
8047
+ }), await env.JAEGER.enterSpan("dispatch_assets", async (span) => (span.setTags({
8048
+ hasUserWorker: config.has_user_worker,
8049
+ asset: "static_routing",
8050
+ dispatchType: "asset" /* ASSETS */
8051
+ }), env.ASSET_WORKER.fetch(maybeSecondRequest)));
8052
+ if (generateStaticRoutingRuleMatcher(
8053
+ config.static_routing.include
8054
+ )({
8055
+ request
8056
+ })) {
8057
+ if (!config.has_user_worker)
8058
+ throw new Error(
8059
+ "Fetch for user worker without having a user worker binding"
8060
+ );
8061
+ return analytics.setData({
8062
+ dispatchtype: "worker" /* WORKER */,
8063
+ staticRoutingDecision: 3 /* INCLUDE */
8064
+ }), await env.JAEGER.enterSpan("dispatch_worker", async (span) => (span.setTags({
8065
+ hasUserWorker: !0,
8066
+ asset: "static_routing",
8067
+ dispatchType: "worker" /* WORKER */
8068
+ }), userWorkerInvocation = !0, env.USER_WORKER.fetch(maybeSecondRequest)));
8069
+ }
8070
+ analytics.setData({
8071
+ staticRoutingDecision: hasStaticRouting ? 1 /* NOT_ROUTED */ : 0 /* NOT_PROVIDED */
8072
+ });
8073
+ }
7886
8074
  if (config.invoke_user_worker_ahead_of_assets) {
7887
8075
  if (!config.has_user_worker)
7888
8076
  throw new Error(