@tricoteuses/assemblee 3.6.0 → 3.6.1
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.
- package/lib/eliasse-sync.d.ts +3 -1
- package/lib/eliasse-sync.js +37 -32
- package/package.json +1 -1
package/lib/eliasse-sync.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface EliasseSyncState {
|
|
|
28
28
|
amendements: EliasseStoredAmendement[];
|
|
29
29
|
}
|
|
30
30
|
export interface EliasseSyncCounts {
|
|
31
|
+
source: "http" | "patch";
|
|
32
|
+
version: number;
|
|
31
33
|
stored: number;
|
|
32
34
|
/** Actual open data changes, not attempted writes. */
|
|
33
35
|
patched: number;
|
|
@@ -36,7 +38,7 @@ export interface EliasseSyncCounts {
|
|
|
36
38
|
export interface EliasseSyncRepository {
|
|
37
39
|
load(uidExamen: string): Promise<EliasseSyncState>;
|
|
38
40
|
/** Must be atomic; a rejection must leave the previous checkpoint intact. */
|
|
39
|
-
commit(target: EliasseSyncTarget, state: EliasseSyncState, statistiques?: EliasseStatistiques): Promise<
|
|
41
|
+
commit(target: EliasseSyncTarget, state: EliasseSyncState, statistiques?: EliasseStatistiques): Promise<Pick<EliasseSyncCounts, "stored" | "patched">>;
|
|
40
42
|
saveStatistics(uidExamen: string, statistiques: EliasseStatistiques): Promise<void>;
|
|
41
43
|
}
|
|
42
44
|
export interface EliasseSynchronizerOptions {
|
package/lib/eliasse-sync.js
CHANGED
|
@@ -3,7 +3,10 @@ import { applyEliasseDerouleurUpdate as e, compareEliasseOrdre as t } from "./el
|
|
|
3
3
|
function n(e) {
|
|
4
4
|
return e != null && e !== "" && e !== "Aucun";
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
function r(e) {
|
|
7
|
+
return JSON.stringify(e, (e, t) => typeof t != "object" || !t || Array.isArray(t) ? t : Object.fromEntries(Object.entries(t).sort(([e], [t]) => e < t ? -1 : +(e > t))));
|
|
8
|
+
}
|
|
9
|
+
var i = class {
|
|
7
10
|
constructor(e) {
|
|
8
11
|
this.options = e, this.tails = /* @__PURE__ */ new Map();
|
|
9
12
|
}
|
|
@@ -24,7 +27,7 @@ var r = class {
|
|
|
24
27
|
libelle: e.libelle ?? r.derouleur.places.find((t) => t.id === e.id)?.libelle
|
|
25
28
|
}
|
|
26
29
|
})));
|
|
27
|
-
return this.process(t, r, e(r.derouleur, n), i);
|
|
30
|
+
return this.process(t, r, e(r.derouleur, n), i, void 0, "patch");
|
|
28
31
|
});
|
|
29
32
|
}
|
|
30
33
|
saveStatistics(e, t) {
|
|
@@ -42,59 +45,61 @@ var r = class {
|
|
|
42
45
|
})]);
|
|
43
46
|
return this.process(e, t, n, [], r);
|
|
44
47
|
}
|
|
45
|
-
async process(e,
|
|
46
|
-
let
|
|
48
|
+
async process(e, i, a, o, s, c = "http") {
|
|
49
|
+
let l = this.options.now?.() ?? Date.now(), u = new Map(i.amendements.map((e) => [e.uid, { ...e }])), d = a.places.flatMap((e) => e.amendements.map((t) => ({
|
|
47
50
|
amendement: t,
|
|
48
51
|
place: {
|
|
49
52
|
id: e.id,
|
|
50
53
|
libelle: e.libelle
|
|
51
54
|
}
|
|
52
55
|
})));
|
|
53
|
-
|
|
54
|
-
let
|
|
55
|
-
for (let e of [...
|
|
56
|
-
let t = e.amendement.uid,
|
|
57
|
-
|
|
58
|
-
...
|
|
56
|
+
d.sort((e, n) => t(e.amendement.ordre, n.amendement.ordre));
|
|
57
|
+
let f = new Set(d.filter((e) => e.amendement.estVisible !== !1).map((e) => e.amendement.uid)), p = new Set(d.filter((e) => e.amendement.estVisible !== !1 && !n(e.amendement.sort)).slice(0, this.options.limit ?? 25).map((e) => e.amendement.uid)), m = e.uidAmendement ?? void 0;
|
|
58
|
+
for (let e of [...d, ...o]) {
|
|
59
|
+
let t = e.amendement.uid, i = u.get(t), a = r(i?.row) !== r(e), o = n(e.amendement.sort) || t === m || p.has(t) || i?.present === !0 && !f.has(t);
|
|
60
|
+
u.set(t, {
|
|
61
|
+
...i,
|
|
59
62
|
uid: t,
|
|
60
63
|
row: e,
|
|
61
|
-
present:
|
|
62
|
-
detailPending:
|
|
63
|
-
detailRetryAt:
|
|
64
|
+
present: f.has(t),
|
|
65
|
+
detailPending: i?.detailPending === !0 || o && (i?.detail === void 0 || a || (t === m || p.has(t)) && l - (i?.detailFetchedAt ?? 0) >= (this.options.detailRefreshMs ?? 6e4)),
|
|
66
|
+
detailRetryAt: a ? void 0 : i?.detailRetryAt
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
|
-
for (let e of
|
|
67
|
-
|
|
68
|
-
uid:
|
|
69
|
+
for (let e of u.values()) f.has(e.uid) || (e.present && (e.detailPending = !0, e.detailRetryAt = void 0), e.present = !1);
|
|
70
|
+
m !== void 0 && !u.has(m) && u.set(m, {
|
|
71
|
+
uid: m,
|
|
69
72
|
present: !1,
|
|
70
73
|
detailPending: !0
|
|
71
74
|
});
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
let
|
|
75
|
-
if (
|
|
76
|
-
|
|
75
|
+
let h = m === void 0 ? void 0 : u.get(m);
|
|
76
|
+
h !== void 0 && l - (h.detailFetchedAt ?? 0) >= (this.options.detailRefreshMs ?? 6e4) && (h.detailPending = !0), h?.detailRetryAt !== void 0 && (h.detailRetryAt = Math.min(h.detailRetryAt, l + Math.min(this.options.retryMs ?? 6e4, 15e3)));
|
|
77
|
+
let g = (e) => e.uid === m ? 0 : n(e.row?.amendement.sort) ? 1 : e.present ? 3 : 2, _ = [...u.values()].filter((e) => e.detailPending && (e.detailRetryAt ?? 0) <= l).sort((e, n) => g(e) - g(n) || (e.detailFetchedAt ?? 0) - (n.detailFetchedAt ?? 0) || t(e.row?.amendement.ordre ?? "", n.row?.amendement.ordre ?? "")).slice(0, Math.max(0, this.options.limit ?? 25)), v = /* @__PURE__ */ new Map();
|
|
78
|
+
if (_.length > 0) try {
|
|
79
|
+
v = await this.options.fetchDetails(e, _.map((e) => e.uid));
|
|
77
80
|
} catch (e) {
|
|
78
81
|
this.options.onError?.(e);
|
|
79
82
|
}
|
|
80
|
-
for (let e of
|
|
81
|
-
let t =
|
|
82
|
-
if (t !== void 0) e.detail = t, e.detailFetchedAt =
|
|
83
|
+
for (let e of _) {
|
|
84
|
+
let t = v.get(e.uid);
|
|
85
|
+
if (t !== void 0) e.detail = t, e.detailFetchedAt = l, e.detailPending = !1, e.detailRetryAt = void 0;
|
|
83
86
|
else {
|
|
84
87
|
let t = this.options.retryMs ?? 6e4;
|
|
85
|
-
e.detailRetryAt =
|
|
88
|
+
e.detailRetryAt = l + (e.uid === m ? Math.min(t, 15e3) : t);
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
|
-
let
|
|
89
|
-
revision:
|
|
90
|
-
derouleur:
|
|
91
|
-
amendements: [...
|
|
91
|
+
let y = {
|
|
92
|
+
revision: i.revision,
|
|
93
|
+
derouleur: a,
|
|
94
|
+
amendements: [...u.values()]
|
|
92
95
|
};
|
|
93
96
|
return {
|
|
94
|
-
...await this.options.repository.commit(e,
|
|
95
|
-
|
|
97
|
+
...await this.options.repository.commit(e, y, s),
|
|
98
|
+
source: c,
|
|
99
|
+
version: a.version,
|
|
100
|
+
pendingDetails: y.amendements.filter((e) => e.detailPending).length
|
|
96
101
|
};
|
|
97
102
|
}
|
|
98
103
|
};
|
|
99
104
|
//#endregion
|
|
100
|
-
export {
|
|
105
|
+
export { i as EliasseSynchronizer, n as isEliasseKnownSort };
|