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