@holo-js/queue 0.3.22 → 0.3.23
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/dist/index.mjs +19 -79
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -32,99 +32,36 @@ function getQueueJobDefinitionNames() {
|
|
|
32
32
|
runtime.__holoQueueJobDefinitionNames__ ??= /* @__PURE__ */ new WeakMap();
|
|
33
33
|
return runtime.__holoQueueJobDefinitionNames__;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function getQueueJobDefinitionsByName() {
|
|
36
36
|
const runtime = globalThis;
|
|
37
|
-
runtime.
|
|
38
|
-
return runtime.
|
|
39
|
-
}
|
|
40
|
-
function getQueueJobDefinitionOptionFingerprints() {
|
|
41
|
-
const runtime = globalThis;
|
|
42
|
-
runtime.__holoQueueJobDefinitionOptionFingerprints__ ??= /* @__PURE__ */ new Map();
|
|
43
|
-
return runtime.__holoQueueJobDefinitionOptionFingerprints__;
|
|
44
|
-
}
|
|
45
|
-
function createQueueJobDefinitionOptionsFingerprint(definition) {
|
|
46
|
-
return JSON.stringify({
|
|
47
|
-
connection: definition.connection,
|
|
48
|
-
queue: definition.queue,
|
|
49
|
-
tries: definition.tries,
|
|
50
|
-
backoff: definition.backoff,
|
|
51
|
-
timeout: definition.timeout
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function getQueueJobDefinitionFingerprint(definition) {
|
|
55
|
-
if (!isQueueJobDefinition(definition)) {
|
|
56
|
-
return void 0;
|
|
57
|
-
}
|
|
58
|
-
return JSON.stringify({
|
|
59
|
-
options: createQueueJobDefinitionOptionsFingerprint(definition),
|
|
60
|
-
handle: definition.handle.toString()
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
function addQueueJobDefinitionNameByFingerprint(fingerprints, fingerprint, name) {
|
|
64
|
-
const names = fingerprints.get(fingerprint) ?? /* @__PURE__ */ new Set();
|
|
65
|
-
names.add(name);
|
|
66
|
-
fingerprints.set(fingerprint, names);
|
|
37
|
+
runtime.__holoQueueJobDefinitionsByName__ ??= /* @__PURE__ */ new Map();
|
|
38
|
+
return runtime.__holoQueueJobDefinitionsByName__;
|
|
67
39
|
}
|
|
68
40
|
function setQueueJobDefinitionName(definition, name) {
|
|
69
41
|
getQueueJobDefinitionNames().set(definition, name);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
addQueueJobDefinitionNameByFingerprint(
|
|
74
|
-
getQueueJobDefinitionFingerprints(),
|
|
75
|
-
getQueueJobDefinitionFingerprint(definition),
|
|
76
|
-
name
|
|
77
|
-
);
|
|
78
|
-
addQueueJobDefinitionNameByFingerprint(
|
|
79
|
-
getQueueJobDefinitionOptionFingerprints(),
|
|
80
|
-
createQueueJobDefinitionOptionsFingerprint(definition),
|
|
81
|
-
name
|
|
82
|
-
);
|
|
42
|
+
const definitions = getQueueJobDefinitionsByName().get(name) ?? /* @__PURE__ */ new Set();
|
|
43
|
+
definitions.add(definition);
|
|
44
|
+
getQueueJobDefinitionsByName().set(name, definitions);
|
|
83
45
|
}
|
|
84
46
|
function deleteQueueJobDefinitionName(name) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
for (const [fingerprint, names] of fingerprints) {
|
|
90
|
-
names.delete(name);
|
|
91
|
-
if (names.size === 0) {
|
|
92
|
-
fingerprints.delete(fingerprint);
|
|
93
|
-
}
|
|
47
|
+
const definitions = getQueueJobDefinitionsByName().get(name);
|
|
48
|
+
for (const definition of definitions ?? []) {
|
|
49
|
+
if (getQueueJobDefinitionNames().get(definition) === name) {
|
|
50
|
+
getQueueJobDefinitionNames().delete(definition);
|
|
94
51
|
}
|
|
95
52
|
}
|
|
53
|
+
getQueueJobDefinitionsByName().delete(name);
|
|
96
54
|
}
|
|
97
55
|
function clearQueueJobDefinitionNames() {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
function resolveSingleQueueJobDefinitionFingerprintName(names) {
|
|
102
|
-
if (!names) {
|
|
103
|
-
return void 0;
|
|
104
|
-
}
|
|
105
|
-
if (names.size === 1) {
|
|
106
|
-
return [...names][0];
|
|
56
|
+
for (const name of getQueueJobDefinitionsByName().keys()) {
|
|
57
|
+
deleteQueueJobDefinitionName(name);
|
|
107
58
|
}
|
|
108
|
-
throw new Error("[Holo Queue] Job definition dispatch is ambiguous because multiple registered jobs match the same definition.");
|
|
109
59
|
}
|
|
110
60
|
function resolveQueueJobDefinitionName(definition) {
|
|
111
61
|
const name = getQueueJobDefinitionNames().get(definition);
|
|
112
62
|
if (name) {
|
|
113
63
|
return name;
|
|
114
64
|
}
|
|
115
|
-
const fingerprint = getQueueJobDefinitionFingerprint(definition);
|
|
116
|
-
const fingerprintName = fingerprint ? resolveSingleQueueJobDefinitionFingerprintName(getQueueJobDefinitionFingerprints().get(fingerprint)) : void 0;
|
|
117
|
-
if (fingerprintName) {
|
|
118
|
-
return fingerprintName;
|
|
119
|
-
}
|
|
120
|
-
if (isQueueJobDefinition(definition)) {
|
|
121
|
-
const optionFingerprintName = resolveSingleQueueJobDefinitionFingerprintName(
|
|
122
|
-
getQueueJobDefinitionOptionFingerprints().get(createQueueJobDefinitionOptionsFingerprint(definition))
|
|
123
|
-
);
|
|
124
|
-
if (optionFingerprintName) {
|
|
125
|
-
return optionFingerprintName;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
65
|
throw new Error("[Holo Queue] Job definitions cannot dispatch before the job is registered.");
|
|
129
66
|
}
|
|
130
67
|
function dispatchDefinedQueueJob(definition, payload) {
|
|
@@ -213,6 +150,10 @@ function normalizeQueueJobDefinition(job) {
|
|
|
213
150
|
}
|
|
214
151
|
function defineJob(job) {
|
|
215
152
|
const normalized = normalizeQueueJobDefinition(job);
|
|
153
|
+
const registeredName = getQueueJobDefinitionNames().get(job);
|
|
154
|
+
if (registeredName) {
|
|
155
|
+
setQueueJobDefinitionName(normalized, registeredName);
|
|
156
|
+
}
|
|
216
157
|
Object.defineProperty(normalized, "dispatch", {
|
|
217
158
|
value(payload) {
|
|
218
159
|
return dispatchDefinedQueueJob(normalized, payload);
|
|
@@ -284,10 +225,9 @@ function registerQueueJob(definition, options = {}) {
|
|
|
284
225
|
const entry = Object.freeze({
|
|
285
226
|
name,
|
|
286
227
|
...options.sourcePath ? { sourcePath: options.sourcePath } : {},
|
|
287
|
-
definition: Object.freeze(
|
|
288
|
-
...normalizedDefinition
|
|
289
|
-
})
|
|
228
|
+
definition: Object.freeze(normalizedDefinition)
|
|
290
229
|
});
|
|
230
|
+
queueJobInternals.deleteQueueJobDefinitionName(name);
|
|
291
231
|
queueJobInternals.setQueueJobDefinitionName(definition, name);
|
|
292
232
|
queueJobInternals.setQueueJobDefinitionName(normalizedDefinition, name);
|
|
293
233
|
registry.set(name, entry);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/queue",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.23",
|
|
4
4
|
"description": "Holo-JS Framework - queue contracts and config helpers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"test": "vitest --run"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@holo-js/config": "^0.3.
|
|
32
|
-
"@holo-js/kernel": "^0.3.
|
|
31
|
+
"@holo-js/config": "^0.3.23",
|
|
32
|
+
"@holo-js/kernel": "^0.3.23"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^22.10.2",
|