@bonniernews/local-esi
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -32,2 +32,6 @@ /* eslint-disable no-use-before-define */ | ||
} | ||
open(data, next) { | ||
this.context.tries.push({ success: true, chunks: [] }); | ||
return next(); | ||
} | ||
close(next) { | ||
@@ -38,3 +42,10 @@ if (!this.children.includes("esi:attempt")) { | ||
this.children.length = 0; | ||
next(); | ||
const { chunks } = this.context.tries.pop(); | ||
if (this.context.tries.length) { | ||
this.context.tries.at(-1).chunks.push(...chunks); | ||
return next(); | ||
} | ||
this.context.writeToResult(chunks, next); | ||
} | ||
@@ -50,5 +61,12 @@ } | ||
open(data, next) { | ||
this.context.inAttempt = true; | ||
this.context.tries.at(-1).inAttempt = true; | ||
next(); | ||
} | ||
close(next) { | ||
this.context.tries.at(-1).inAttempt = false; | ||
if (!this.context.tries.at(-1).success) { | ||
this.context.tries.at(-1).chunks.length = 0; | ||
} | ||
next(); | ||
} | ||
} | ||
@@ -63,7 +81,7 @@ | ||
open(data, next) { | ||
this.context.inExcept = true; | ||
this.context.tries.at(-1).inExcept = true; | ||
next(); | ||
} | ||
close(next) { | ||
this.context.inExcept = false; | ||
this.context.tries.at(-1).inExcept = false; | ||
next(); | ||
@@ -322,2 +340,6 @@ } | ||
if (context.tries.length) { | ||
next = this.bufferEvaluated.bind(this, next); | ||
} | ||
context.writeToResult({ name, data: this.makeAttributes(data) }, next); | ||
@@ -341,2 +363,6 @@ } | ||
if (context.tries.length) { | ||
next = this.bufferEvaluated.bind(this, next); | ||
} | ||
context.writeToResult({ name }, next); | ||
@@ -361,2 +387,6 @@ } | ||
try { | ||
if (context.tries.length) { | ||
next = this.bufferEvaluated.bind(this, next); | ||
} | ||
return context.writeToResult((currentContext) => { | ||
@@ -390,2 +420,8 @@ const result = { text: replace(text, currentContext || context) }; | ||
} | ||
bufferEvaluated(next, error, chunk) { | ||
if (error || !chunk) return next(error, chunk); | ||
this.context.tries.at(-1).chunks.push(chunk); | ||
next(); | ||
} | ||
} |
@@ -13,3 +13,2 @@ import { EventEmitter } from "events"; | ||
this.inAttempt = false; | ||
this.lastAttemptWasError = false; | ||
this.inExcept = false; | ||
@@ -20,2 +19,3 @@ this.includeError = false; | ||
this.tags = []; | ||
this.tries = []; | ||
this.cookies = options.cookies; | ||
@@ -49,9 +49,5 @@ this.assigns = { | ||
shouldWrite() { | ||
if (this.inExcept && !this.lastAttemptWasError) return false; | ||
if (this.breakHit) return false; | ||
if (this.chooses.length) { | ||
return this.chooses.every((choose) => choose.chosen); | ||
} | ||
if (!this.tries.every((t) => t.success ? t.inAttempt : t.inExcept)) return false; | ||
if (!this.chooses.every((choose) => choose.chosen)) return false; | ||
return true; | ||
@@ -103,4 +99,4 @@ } | ||
if (resp.statusCode < 400) return; | ||
if (self.inAttempt) { | ||
self.lastAttemptWasError = true; | ||
if (self.tries.at(-1)?.inAttempt) { | ||
self.tries.at(-1).success = false; | ||
return this.push(null); | ||
@@ -111,4 +107,4 @@ } | ||
.on("error", (err) => { | ||
if (!self.inAttempt) return; | ||
self.lastAttemptWasError = true; | ||
if (!self.tries.at(-1)?.inAttempt) return; | ||
self.tries.at(-1).success = false; | ||
err.inAttempt = true; | ||
@@ -115,0 +111,0 @@ }); |
{ | ||
"name": "@bonniernews/local-esi", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Local Edge Side Includes parser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103366
3330