tods-competition-factory 1.8.2 → 1.8.4
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/forge/generate.d.ts +11 -3
- package/dist/forge/generate.mjs +337 -65
- package/dist/forge/generate.mjs.map +1 -1
- package/dist/forge/query.mjs +24 -12
- package/dist/forge/query.mjs.map +1 -1
- package/dist/forge/transform.mjs +250 -4
- package/dist/forge/transform.mjs.map +1 -1
- package/dist/forge/utilities.mjs +175 -0
- package/dist/forge/utilities.mjs.map +1 -1
- package/dist/index.mjs +347 -173
- package/dist/index.mjs.map +1 -1
- package/dist/tods-competition-factory.development.cjs.js +422 -225
- package/dist/tods-competition-factory.development.cjs.js.map +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js.map +1 -1
- package/package.json +1 -1
package/dist/forge/utilities.mjs
CHANGED
|
@@ -127,10 +127,174 @@ function chunkByNth(arr, chunksCount, shuttle) {
|
|
|
127
127
|
}, []);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
const SUCCESS = { success: true };
|
|
131
|
+
|
|
132
|
+
const MISSING_TOURNAMENT_RECORD = {
|
|
133
|
+
message: "Missing tournamentRecord",
|
|
134
|
+
code: "ERR_MISSING_TOURNAMENT"
|
|
135
|
+
};
|
|
136
|
+
const INVALID_TOURNAMENT_RECORD = {
|
|
137
|
+
message: "Invalid tournamentRecord",
|
|
138
|
+
code: "ERR_INVALID_TOURNAMENT"
|
|
139
|
+
};
|
|
130
140
|
const INVALID_VALUES = {
|
|
131
141
|
message: "Invalid values",
|
|
132
142
|
code: "ERR_INVALID_VALUES"
|
|
133
143
|
};
|
|
144
|
+
const NOT_FOUND = { message: "Not found", code: "ERR_NOT_FOUND" };
|
|
145
|
+
|
|
146
|
+
const syncGlobalState = {
|
|
147
|
+
disableNotifications: false,
|
|
148
|
+
tournamentId: void 0,
|
|
149
|
+
tournamentRecords: {},
|
|
150
|
+
subscriptions: {},
|
|
151
|
+
modified: false,
|
|
152
|
+
notices: []
|
|
153
|
+
};
|
|
154
|
+
var syncGlobalState$1 = {
|
|
155
|
+
addNotice,
|
|
156
|
+
callListener,
|
|
157
|
+
cycleMutationStatus,
|
|
158
|
+
deleteNotice,
|
|
159
|
+
deleteNotices,
|
|
160
|
+
disableNotifications,
|
|
161
|
+
enableNotifications,
|
|
162
|
+
getNotices,
|
|
163
|
+
getTopics,
|
|
164
|
+
getTournamentId,
|
|
165
|
+
getTournamentRecord,
|
|
166
|
+
getTournamentRecords,
|
|
167
|
+
removeTournamentRecord,
|
|
168
|
+
setSubscriptions,
|
|
169
|
+
setTournamentId,
|
|
170
|
+
setTournamentRecord,
|
|
171
|
+
setTournamentRecords,
|
|
172
|
+
handleCaughtError
|
|
173
|
+
};
|
|
174
|
+
function disableNotifications() {
|
|
175
|
+
syncGlobalState.disableNotifications = true;
|
|
176
|
+
}
|
|
177
|
+
function enableNotifications() {
|
|
178
|
+
syncGlobalState.disableNotifications = false;
|
|
179
|
+
}
|
|
180
|
+
function getTournamentId() {
|
|
181
|
+
return syncGlobalState.tournamentId;
|
|
182
|
+
}
|
|
183
|
+
function getTournamentRecord(tournamentId) {
|
|
184
|
+
return syncGlobalState.tournamentRecords[tournamentId];
|
|
185
|
+
}
|
|
186
|
+
function getTournamentRecords() {
|
|
187
|
+
return syncGlobalState.tournamentRecords;
|
|
188
|
+
}
|
|
189
|
+
function setTournamentRecord(tournamentRecord) {
|
|
190
|
+
const tournamentId = tournamentRecord?.tournamentId;
|
|
191
|
+
if (tournamentId) {
|
|
192
|
+
syncGlobalState.tournamentRecords[tournamentId] = tournamentRecord;
|
|
193
|
+
return { success: true };
|
|
194
|
+
} else {
|
|
195
|
+
return { error: INVALID_TOURNAMENT_RECORD };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function setTournamentId(tournamentId) {
|
|
199
|
+
if (syncGlobalState.tournamentRecords[tournamentId]) {
|
|
200
|
+
syncGlobalState.tournamentId = tournamentId;
|
|
201
|
+
return { success: true };
|
|
202
|
+
} else {
|
|
203
|
+
return { error: MISSING_TOURNAMENT_RECORD };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function setTournamentRecords(tournamentRecords) {
|
|
207
|
+
syncGlobalState.tournamentRecords = tournamentRecords;
|
|
208
|
+
const tournamentIds = Object.keys(tournamentRecords);
|
|
209
|
+
if (tournamentIds.length === 1) {
|
|
210
|
+
syncGlobalState.tournamentId = tournamentIds[0];
|
|
211
|
+
} else if (!tournamentIds.length) {
|
|
212
|
+
syncGlobalState.tournamentId = void 0;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function removeTournamentRecord(tournamentId) {
|
|
216
|
+
if (typeof tournamentId !== "string")
|
|
217
|
+
return { error: INVALID_VALUES };
|
|
218
|
+
if (!syncGlobalState.tournamentRecords[tournamentId])
|
|
219
|
+
return { error: NOT_FOUND };
|
|
220
|
+
delete syncGlobalState.tournamentRecords[tournamentId];
|
|
221
|
+
const tournamentIds = Object.keys(syncGlobalState.tournamentRecords);
|
|
222
|
+
if (tournamentIds.length === 1) {
|
|
223
|
+
syncGlobalState.tournamentId = tournamentIds[0];
|
|
224
|
+
} else if (!tournamentIds.length) {
|
|
225
|
+
syncGlobalState.tournamentId = void 0;
|
|
226
|
+
}
|
|
227
|
+
return { success: true };
|
|
228
|
+
}
|
|
229
|
+
function setSubscriptions(params) {
|
|
230
|
+
if (typeof params.subscriptions !== "object")
|
|
231
|
+
return { error: INVALID_VALUES };
|
|
232
|
+
Object.keys(params.subscriptions).forEach((subscription) => {
|
|
233
|
+
syncGlobalState.subscriptions[subscription] = params.subscriptions[subscription];
|
|
234
|
+
});
|
|
235
|
+
return { ...SUCCESS };
|
|
236
|
+
}
|
|
237
|
+
function cycleMutationStatus() {
|
|
238
|
+
const status = syncGlobalState.modified;
|
|
239
|
+
syncGlobalState.modified = false;
|
|
240
|
+
return status;
|
|
241
|
+
}
|
|
242
|
+
function addNotice({ topic, payload, key }) {
|
|
243
|
+
syncGlobalState.modified = true;
|
|
244
|
+
if (typeof topic !== "string" || typeof payload !== "object") {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (syncGlobalState.disableNotifications || !syncGlobalState.subscriptions[topic])
|
|
248
|
+
return;
|
|
249
|
+
if (key) {
|
|
250
|
+
syncGlobalState.notices = syncGlobalState.notices.filter(
|
|
251
|
+
(notice) => !(notice.topic === topic && notice.key === key)
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
syncGlobalState.notices.push({ topic, payload, key });
|
|
255
|
+
}
|
|
256
|
+
function getNotices({ topic }) {
|
|
257
|
+
const notices = syncGlobalState.notices.filter((notice) => notice.topic === topic).map((notice) => notice.payload);
|
|
258
|
+
return notices.length && notices;
|
|
259
|
+
}
|
|
260
|
+
function deleteNotices() {
|
|
261
|
+
syncGlobalState.notices = [];
|
|
262
|
+
}
|
|
263
|
+
function deleteNotice({ topic, key }) {
|
|
264
|
+
syncGlobalState.notices = syncGlobalState.notices.filter(
|
|
265
|
+
(notice) => (!topic || notice.topic === topic) && notice.key !== key
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
function getTopics() {
|
|
269
|
+
const topics = Object.keys(syncGlobalState.subscriptions);
|
|
270
|
+
return { topics };
|
|
271
|
+
}
|
|
272
|
+
function callListener({ topic, notices }) {
|
|
273
|
+
const method = syncGlobalState.subscriptions[topic];
|
|
274
|
+
if (method && typeof method === "function") {
|
|
275
|
+
method(notices);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function handleCaughtError({
|
|
279
|
+
engineName,
|
|
280
|
+
methodName,
|
|
281
|
+
params,
|
|
282
|
+
err
|
|
283
|
+
}) {
|
|
284
|
+
let error;
|
|
285
|
+
if (typeof err === "string") {
|
|
286
|
+
error = err.toUpperCase();
|
|
287
|
+
} else if (err instanceof Error) {
|
|
288
|
+
error = err.message;
|
|
289
|
+
}
|
|
290
|
+
console.log("ERROR", {
|
|
291
|
+
tournamentId: getTournamentId(),
|
|
292
|
+
params: JSON.stringify(params),
|
|
293
|
+
engine: engineName,
|
|
294
|
+
methodName,
|
|
295
|
+
error
|
|
296
|
+
});
|
|
297
|
+
}
|
|
134
298
|
|
|
135
299
|
const globalState = {
|
|
136
300
|
tournamentFactoryVersion: "0.0.0",
|
|
@@ -143,6 +307,7 @@ const globalState = {
|
|
|
143
307
|
},
|
|
144
308
|
deepCopy: true
|
|
145
309
|
};
|
|
310
|
+
let _globalStateProvider = syncGlobalState$1;
|
|
146
311
|
function getDevContext(contextCriteria) {
|
|
147
312
|
if (!contextCriteria || typeof contextCriteria !== "object") {
|
|
148
313
|
return globalState.devContext ?? false;
|
|
@@ -163,6 +328,9 @@ function deepCopyEnabled() {
|
|
|
163
328
|
...globalState.deepCopyAttributes
|
|
164
329
|
};
|
|
165
330
|
}
|
|
331
|
+
function getProvider() {
|
|
332
|
+
return _globalStateProvider;
|
|
333
|
+
}
|
|
166
334
|
|
|
167
335
|
function isDateObject(value) {
|
|
168
336
|
if (typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -174,6 +342,13 @@ function isDateObject(value) {
|
|
|
174
342
|
}
|
|
175
343
|
|
|
176
344
|
function makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions, iteration = 0) {
|
|
345
|
+
if (getProvider().makeDeepCopy)
|
|
346
|
+
return getProvider().makeDeepCopy(
|
|
347
|
+
sourceObject,
|
|
348
|
+
convertExtensions,
|
|
349
|
+
internalUse,
|
|
350
|
+
removeExtensions
|
|
351
|
+
);
|
|
177
352
|
const deepCopy = deepCopyEnabled();
|
|
178
353
|
const { stringify, toJSON, ignore, modulate } = deepCopy || {};
|
|
179
354
|
if (!deepCopy?.enabled && !internalUse || typeof sourceObject !== "object" || typeof sourceObject === "function" || sourceObject === null || typeof deepCopy?.threshold === "number" && iteration >= deepCopy.threshold) {
|