mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Fixing passes parallel generation (#31) by Ianbale
This commit is contained in:
committed by
Alexander Cerutti
parent
f292031494
commit
a0a02bf083
@@ -1,21 +1,18 @@
|
||||
const schema = require("./schema");
|
||||
const debug = require("debug")("passkit:fields");
|
||||
|
||||
/**
|
||||
* Pass fields must be unique (for key) in its scope.
|
||||
* Therefore we use a Set to keep them tracked.
|
||||
*/
|
||||
|
||||
const fieldsKeys = new Set();
|
||||
|
||||
/**
|
||||
* Class to represent lower-level keys pass fields
|
||||
* @see https://apple.co/2wkUBdh
|
||||
*/
|
||||
|
||||
const poolSymbol = Symbol("pool");
|
||||
|
||||
class FieldsArray extends Array {
|
||||
constructor(...items) {
|
||||
super(...items);
|
||||
|
||||
constructor(pool,...args) {
|
||||
super(...args);
|
||||
this[poolSymbol] = pool;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,12 +26,12 @@ class FieldsArray extends Array {
|
||||
return acc;
|
||||
}
|
||||
|
||||
if (acc.some(e => e.key === current.key) || fieldsKeys.has(current.key)) {
|
||||
debug(`Field with key "${current.key}" discarded: fields must be unique in pass scope.`);
|
||||
} else {
|
||||
fieldsKeys.add(current.key);
|
||||
acc.push(current);
|
||||
}
|
||||
if (acc.some(e => e.key === current.key) || this[poolSymbol].has(current.key)) {
|
||||
debug(`Field with key "${key}" discarded: fields must be unique in pass scope.`);
|
||||
}
|
||||
|
||||
this[poolSymbol].add(current.key)
|
||||
acc.push(current)
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
@@ -48,8 +45,8 @@ class FieldsArray extends Array {
|
||||
*/
|
||||
|
||||
pop() {
|
||||
const element = Array.prototype.pop.call(this);
|
||||
fieldsKeys.delete(element.key);
|
||||
const element = Array.prototype.pop.call(this);
|
||||
this[poolSymbol].delete(element.key)
|
||||
return element;
|
||||
}
|
||||
|
||||
@@ -60,7 +57,7 @@ class FieldsArray extends Array {
|
||||
|
||||
splice(start, deleteCount, ...items) {
|
||||
const removeList = this.slice(start, deleteCount+start);
|
||||
removeList.forEach(item => fieldsKeys.delete(item.key));
|
||||
removeList.forEach(item => this[poolSymbol].delete(item.key));
|
||||
|
||||
return Array.prototype.splice.call(this, start, deleteCount, items);
|
||||
}
|
||||
@@ -68,10 +65,6 @@ class FieldsArray extends Array {
|
||||
get length() {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
static emptyUnique() {
|
||||
fieldsKeys.clear();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FieldsArray;
|
||||
|
||||
@@ -44,7 +44,12 @@ class Pass {
|
||||
|
||||
this._fields = ["primaryFields", "secondaryFields", "auxiliaryFields", "backFields", "headerFields"];
|
||||
|
||||
this._fields.forEach(a => this[a] = new FieldsArray());
|
||||
this.fieldsKeys = new Set();
|
||||
|
||||
this._fields.forEach(name => {
|
||||
this[name] = new FieldsArray(this.fieldsKeys);
|
||||
});
|
||||
|
||||
this[transitType] = "";
|
||||
|
||||
// Assigning model and _props to this
|
||||
@@ -213,8 +218,6 @@ class Pass {
|
||||
|
||||
archive.pipe(passStream);
|
||||
|
||||
FieldsArray.emptyUnique();
|
||||
|
||||
return archive.finalize().then(() => passStream);
|
||||
} catch (err) {
|
||||
if (err.code && err.code === "ENOENT") {
|
||||
|
||||
Reference in New Issue
Block a user