@ovok/core 0.4.49 → 0.4.50
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/client/observation/fhir-systems.d.ts +12 -0
- package/dist/client/observation/fhir-systems.js +13 -1
- package/dist/client/observation/observation-groups.d.ts +4 -3
- package/dist/client/observation/observation-groups.js +8 -4
- package/dist/client/observation/series.d.ts +21 -3
- package/dist/client/observation/series.js +14 -4
- package/dist/client/observation/services/ecg-observation-fragments.js +1 -0
- package/dist/client/offline/offline-measurement-queue.d.ts +3 -1
- package/dist/client/offline/offline-measurement-queue.js +2 -1
- package/dist/conformance/capability-requirements.js +1 -1
- package/dist/next/config/ovok-config.d.ts +18 -0
- package/dist/next/config/settings.js +10 -1
- package/dist/next/errors/ovok-errors.d.ts +7 -0
- package/dist/next/errors/ovok-errors.js +9 -1
- package/dist/next/http/transmit.js +4 -2
- package/dist/next/index.d.ts +15 -1
- package/dist/next/index.js +18 -1
- package/dist/next/logging/ovok-logger.d.ts +26 -0
- package/dist/next/logging/ovok-logger.js +10 -0
- package/dist/next/outbox/entry-observation.d.ts +3 -0
- package/dist/next/outbox/entry-observation.js +6 -0
- package/dist/next/outbox/failure-policy.d.ts +45 -0
- package/dist/next/outbox/failure-policy.js +92 -0
- package/dist/next/outbox/group-links.d.ts +19 -0
- package/dist/next/outbox/group-links.js +65 -0
- package/dist/next/outbox/indexed-db-outbox-store.d.ts +38 -0
- package/dist/next/outbox/indexed-db-outbox-store.js +90 -0
- package/dist/next/outbox/item-settler.d.ts +37 -0
- package/dist/next/outbox/item-settler.js +49 -0
- package/dist/next/outbox/legacy-queue-import.d.ts +7 -0
- package/dist/next/outbox/legacy-queue-import.js +50 -0
- package/dist/next/outbox/memory-outbox-store.d.ts +22 -0
- package/dist/next/outbox/memory-outbox-store.js +40 -0
- package/dist/next/outbox/outbox-items.d.ts +17 -0
- package/dist/next/outbox/outbox-items.js +89 -0
- package/dist/next/outbox/outbox-queries.d.ts +4 -0
- package/dist/next/outbox/outbox-queries.js +9 -0
- package/dist/next/outbox/outbox-resource.d.ts +73 -0
- package/dist/next/outbox/outbox-resource.js +170 -0
- package/dist/next/outbox/outbox-runner.d.ts +56 -0
- package/dist/next/outbox/outbox-runner.js +179 -0
- package/dist/next/outbox/outbox-snapshot.d.ts +3 -0
- package/dist/next/outbox/outbox-snapshot.js +40 -0
- package/dist/next/outbox/outbox-store.d.ts +21 -0
- package/dist/next/outbox/outbox-store.js +2 -0
- package/dist/next/outbox/outbox-triggers.d.ts +30 -0
- package/dist/next/outbox/outbox-triggers.js +38 -0
- package/dist/next/outbox/outbox-types.d.ts +138 -0
- package/dist/next/outbox/outbox-types.js +2 -0
- package/dist/next/outbox/outcome-handlers.d.ts +30 -0
- package/dist/next/outbox/outcome-handlers.js +50 -0
- package/dist/next/outbox/pending-saves.d.ts +6 -0
- package/dist/next/outbox/pending-saves.js +18 -0
- package/dist/next/outbox/request-budget.d.ts +10 -0
- package/dist/next/outbox/request-budget.js +22 -0
- package/dist/next/outbox/request-planner.d.ts +5 -0
- package/dist/next/outbox/request-planner.js +39 -0
- package/dist/next/outbox/runner-state.d.ts +34 -0
- package/dist/next/outbox/runner-state.js +61 -0
- package/dist/next/outbox/store-contract.d.ts +19 -0
- package/dist/next/outbox/store-contract.js +108 -0
- package/dist/next/outbox/wakeup.d.ts +11 -0
- package/dist/next/outbox/wakeup.js +34 -0
- package/dist/next/ovok.d.ts +3 -0
- package/dist/next/ovok.js +13 -2
- package/dist/next/react/index.d.ts +11 -1
- package/dist/next/react/index.js +15 -1
- package/dist/next/resources/measurements/measurement-sender.d.ts +27 -0
- package/dist/next/resources/measurements/measurement-sender.js +66 -0
- package/dist/next/resources/measurements/measurements-resource.d.ts +36 -25
- package/dist/next/resources/measurements/measurements-resource.js +62 -65
- package/dist/next/resources/measurements/offline-measurement-queue-types.d.ts +12 -14
- package/dist/next/resources/measurements/offline-measurement-queue.d.ts +4 -23
- package/dist/next/resources/measurements/offline-measurement-queue.js +18 -143
- package/package.json +1 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PauseLadder = exports.retryDelayMs = exports.classify = exports.summarizeFailure = void 0;
|
|
4
|
+
const ovok_errors_1 = require("../errors/ovok-errors");
|
|
5
|
+
const SECOND_MS = 1000;
|
|
6
|
+
const RATE_LIMIT_PAUSE_MS = 60 * SECOND_MS;
|
|
7
|
+
const SERVER_PAUSE_MS = 300 * SECOND_MS;
|
|
8
|
+
const SERVER_PAUSE_STEP_MS = 100 * SECOND_MS;
|
|
9
|
+
const SERVER_PAUSE_CAP_MS = 3600 * SECOND_MS;
|
|
10
|
+
const RETRY_BACKOFF_MS = 60 * SECOND_MS;
|
|
11
|
+
const RETRY_BACKOFF_CAP_MS = 900 * SECOND_MS;
|
|
12
|
+
const PRECONDITION_FAILED = 412;
|
|
13
|
+
const CONFLICT = 409;
|
|
14
|
+
const summarizeFailure = (error) => {
|
|
15
|
+
const failure = error;
|
|
16
|
+
return {
|
|
17
|
+
name: typeof (failure === null || failure === void 0 ? void 0 : failure.name) === "string" ? failure.name : "Error",
|
|
18
|
+
...(typeof (failure === null || failure === void 0 ? void 0 : failure.code) === "string" ? { code: failure.code } : {}),
|
|
19
|
+
...(typeof (failure === null || failure === void 0 ? void 0 : failure.status) === "number" ? { status: failure.status } : {}),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.summarizeFailure = summarizeFailure;
|
|
23
|
+
const statusOf = (error) => (error instanceof ovok_errors_1.OvokError ? error.status : null);
|
|
24
|
+
const isConditional = ({ request }) => (request === null || request === void 0 ? void 0 : request.ifNoneExist) !== undefined || ((request === null || request === void 0 ? void 0 : request.method) === "PUT" && request.url.includes("?"));
|
|
25
|
+
const onlyDeletes = (items) => items.every(({ kind }) => kind === "delete");
|
|
26
|
+
const onlyConditional = (items) => items.every(({ entries }) => entries.every(isConditional));
|
|
27
|
+
const interrupted = (_error, { signal }) => ((signal === null || signal === void 0 ? void 0 : signal.aborted) ? { type: "interrupted" } : null);
|
|
28
|
+
const accountChanged = (error) => error instanceof ovok_errors_1.OvokConflictError && error.status === null
|
|
29
|
+
? { type: "owner-unavailable", failure: (0, exports.summarizeFailure)(error) }
|
|
30
|
+
: null;
|
|
31
|
+
const rateLimited = (error) => error instanceof ovok_errors_1.OvokRateLimitError
|
|
32
|
+
? { type: "pause", reason: "rate-limited", retryAfterMs: error.retryAfterMs, failure: (0, exports.summarizeFailure)(error) }
|
|
33
|
+
: null;
|
|
34
|
+
const serverFailed = (error) => error instanceof ovok_errors_1.OvokServiceError
|
|
35
|
+
? { type: "pause", reason: "server-error", retryAfterMs: null, failure: (0, exports.summarizeFailure)(error) }
|
|
36
|
+
: null;
|
|
37
|
+
const signedOut = (error) => error instanceof ovok_errors_1.OvokAuthenticationError ? { type: "owner-unavailable", failure: (0, exports.summarizeFailure)(error) } : null;
|
|
38
|
+
const timedOut = (error) => error instanceof ovok_errors_1.OvokTimeoutError ? { type: "timeout", failure: (0, exports.summarizeFailure)(error), error } : null;
|
|
39
|
+
const unreachable = (error) => error instanceof ovok_errors_1.OvokConnectionError ? { type: "offline", failure: (0, exports.summarizeFailure)(error) } : null;
|
|
40
|
+
const isSingle = (items) => items.length === 1;
|
|
41
|
+
/** Only for one item: a conflict in a request of several does not say whose it is. */
|
|
42
|
+
const alreadySaved = (error, { items }) => {
|
|
43
|
+
const status = statusOf(error);
|
|
44
|
+
const duplicate = (status === CONFLICT || status === PRECONDITION_FAILED) && isSingle(items) && onlyConditional(items);
|
|
45
|
+
return duplicate ? { type: "already-applied" } : null;
|
|
46
|
+
};
|
|
47
|
+
const alreadyDeleted = (error, { items }) => error instanceof ovok_errors_1.OvokNotFoundError && isSingle(items) && onlyDeletes(items) ? { type: "already-applied" } : null;
|
|
48
|
+
const refused = (error) => error instanceof ovok_errors_1.OvokValidationError || error instanceof ovok_errors_1.OvokPermissionError || error instanceof ovok_errors_1.OvokNotFoundError
|
|
49
|
+
? { type: "reject", failure: (0, exports.summarizeFailure)(error), error }
|
|
50
|
+
: null;
|
|
51
|
+
const RULES = [
|
|
52
|
+
interrupted,
|
|
53
|
+
accountChanged,
|
|
54
|
+
rateLimited,
|
|
55
|
+
serverFailed,
|
|
56
|
+
signedOut,
|
|
57
|
+
timedOut,
|
|
58
|
+
unreachable,
|
|
59
|
+
alreadySaved,
|
|
60
|
+
alreadyDeleted,
|
|
61
|
+
refused,
|
|
62
|
+
];
|
|
63
|
+
/** Anything the rules do not name is tried again on the timeout schedule, then refused. */
|
|
64
|
+
const classify = (error, context) => {
|
|
65
|
+
var _a;
|
|
66
|
+
return (_a = RULES.map((rule) => rule(error, context)).find((outcome) => outcome !== null)) !== null && _a !== void 0 ? _a : {
|
|
67
|
+
type: "retry",
|
|
68
|
+
failure: (0, exports.summarizeFailure)(error),
|
|
69
|
+
error,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
exports.classify = classify;
|
|
73
|
+
const retryDelayMs = (attempts) => Math.min(RETRY_BACKOFF_CAP_MS, RETRY_BACKOFF_MS * 2 ** (attempts - 1));
|
|
74
|
+
exports.retryDelayMs = retryDelayMs;
|
|
75
|
+
/** How long the whole outbox waits after a 429 or a 5xx; repeated server errors wait longer each time. */
|
|
76
|
+
class PauseLadder {
|
|
77
|
+
constructor() {
|
|
78
|
+
this.serverErrors = 0;
|
|
79
|
+
}
|
|
80
|
+
durationMs(reason, retryAfterMs) {
|
|
81
|
+
if (reason === "rate-limited") {
|
|
82
|
+
this.reset();
|
|
83
|
+
return retryAfterMs !== null && retryAfterMs !== void 0 ? retryAfterMs : RATE_LIMIT_PAUSE_MS;
|
|
84
|
+
}
|
|
85
|
+
this.serverErrors += 1;
|
|
86
|
+
return Math.min(SERVER_PAUSE_CAP_MS, SERVER_PAUSE_MS + SERVER_PAUSE_STEP_MS * (this.serverErrors - 1));
|
|
87
|
+
}
|
|
88
|
+
reset() {
|
|
89
|
+
this.serverErrors = 0;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.PauseLadder = PauseLadder;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { OutboxStore } from "./outbox-store";
|
|
2
|
+
import type { OutboxItem } from "./outbox-types";
|
|
3
|
+
import type { Bundle, BundleEntry } from "@medplum/fhirtypes";
|
|
4
|
+
type Entries = BundleEntry[];
|
|
5
|
+
/**
|
|
6
|
+
* Keeps the links of a long recording true. Its segments go in separate requests, so each can only point at what
|
|
7
|
+
* the server already saved: the group item learns each saved segment's reference as it lands, and the items sent
|
|
8
|
+
* later read it from there.
|
|
9
|
+
*/
|
|
10
|
+
export declare class GroupLinks {
|
|
11
|
+
private readonly store;
|
|
12
|
+
constructor(store: OutboxStore);
|
|
13
|
+
/** The entries to send for an item of a recording, with links to unsaved observations removed. */
|
|
14
|
+
entriesToSend(item: OutboxItem): Promise<Entries>;
|
|
15
|
+
/** Tells the recording's group item where a segment was saved. */
|
|
16
|
+
landed(item: OutboxItem, response: Bundle): Promise<void>;
|
|
17
|
+
private groupItemOf;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GroupLinks = void 0;
|
|
4
|
+
const observation_bundle_utils_1 = require("../../client/observation/observation-bundle-utils");
|
|
5
|
+
const entry_observation_1 = require("./entry-observation");
|
|
6
|
+
const PLACEHOLDER_PREFIX = "urn:uuid:";
|
|
7
|
+
const isPlaceholder = (reference) => { var _a; return (_a = reference === null || reference === void 0 ? void 0 : reference.startsWith(PLACEHOLDER_PREFIX)) !== null && _a !== void 0 ? _a : false; };
|
|
8
|
+
const groupObservationOf = (item) => (0, entry_observation_1.observationOf)(item.entries[item.entries.length - 1]);
|
|
9
|
+
const withMembers = (entry, members) => {
|
|
10
|
+
const { hasMember: _members, ...rest } = (0, entry_observation_1.observationOf)(entry);
|
|
11
|
+
return { ...entry, resource: members.length > 0 ? { ...rest, hasMember: members } : rest };
|
|
12
|
+
};
|
|
13
|
+
/** Drops links to observations that are neither saved nor in this request, which the server could not resolve. */
|
|
14
|
+
const withoutDanglingMembers = (entries) => {
|
|
15
|
+
const inRequest = new Set(entries.map(({ fullUrl }) => fullUrl));
|
|
16
|
+
return entries.map((entry) => {
|
|
17
|
+
var _a;
|
|
18
|
+
const members = (_a = (0, entry_observation_1.observationOf)(entry)) === null || _a === void 0 ? void 0 : _a.hasMember;
|
|
19
|
+
const kept = members === null || members === void 0 ? void 0 : members.filter(({ reference }) => !isPlaceholder(reference) || inRequest.has(reference));
|
|
20
|
+
return members && kept && kept.length < members.length ? withMembers(entry, kept) : entry;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
/** A segment points at the recording's first segment; once that is saved, the group item knows where. */
|
|
24
|
+
const withSavedMain = (segment, group) => {
|
|
25
|
+
var _a, _b, _c, _d, _e, _f;
|
|
26
|
+
const placeholder = (_c = (_b = (_a = (0, entry_observation_1.observationOf)(segment.entries[0])) === null || _a === void 0 ? void 0 : _a.hasMember) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.reference;
|
|
27
|
+
const saved = group && ((_f = (_e = (_d = groupObservationOf(group)) === null || _d === void 0 ? void 0 : _d.hasMember) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.reference);
|
|
28
|
+
return isPlaceholder(placeholder) && saved && !isPlaceholder(saved)
|
|
29
|
+
? (0, observation_bundle_utils_1.rewriteObservationReferences)(segment.entries, placeholder, saved)
|
|
30
|
+
: segment.entries;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Keeps the links of a long recording true. Its segments go in separate requests, so each can only point at what
|
|
34
|
+
* the server already saved: the group item learns each saved segment's reference as it lands, and the items sent
|
|
35
|
+
* later read it from there.
|
|
36
|
+
*/
|
|
37
|
+
class GroupLinks {
|
|
38
|
+
constructor(store) {
|
|
39
|
+
this.store = store;
|
|
40
|
+
}
|
|
41
|
+
/** The entries to send for an item of a recording, with links to unsaved observations removed. */
|
|
42
|
+
async entriesToSend(item) {
|
|
43
|
+
const group = await this.groupItemOf(item);
|
|
44
|
+
return withoutDanglingMembers(group ? withSavedMain(item, group) : item.entries);
|
|
45
|
+
}
|
|
46
|
+
/** Tells the recording's group item where a segment was saved. */
|
|
47
|
+
async landed(item, response) {
|
|
48
|
+
var _a;
|
|
49
|
+
const group = await this.groupItemOf(item);
|
|
50
|
+
const placeholder = (_a = item.entries[0]) === null || _a === void 0 ? void 0 : _a.fullUrl;
|
|
51
|
+
const saved = (0, observation_bundle_utils_1.createdObservationReference)(response, 0);
|
|
52
|
+
if (group && placeholder && saved) {
|
|
53
|
+
await this.store.put({ ...group, entries: (0, observation_bundle_utils_1.rewriteObservationReferences)(group.entries, placeholder, saved) });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async groupItemOf(segment) {
|
|
57
|
+
if (segment.kind !== "segment") {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const stored = await this.store.summaries(segment.ownerKey);
|
|
61
|
+
const summary = stored.find(({ group, kind }) => group === segment.group && kind !== "segment");
|
|
62
|
+
return summary ? this.store.get(summary.id) : null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.GroupLinks = GroupLinks;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { OutboxStore } from "./outbox-store";
|
|
2
|
+
import type { OutboxItem, OutboxItemSummary, OutboxState } from "./outbox-types";
|
|
3
|
+
/**
|
|
4
|
+
* Where `IndexedDbOutboxStore` keeps its database.
|
|
5
|
+
*
|
|
6
|
+
* @category outbox
|
|
7
|
+
*/
|
|
8
|
+
export type IndexedDbOutboxOptions = {
|
|
9
|
+
/** Database name. Defaults to `ovok-outbox`. */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** The IndexedDB factory. Defaults to the global `indexedDB`. */
|
|
12
|
+
factory?: IDBFactory;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* An `OutboxStore` on the browser's IndexedDB, with no dependency. Items and their summaries live in two object
|
|
16
|
+
* stores, so listing and counting never read the entries.
|
|
17
|
+
*
|
|
18
|
+
* @category outbox
|
|
19
|
+
*/
|
|
20
|
+
export declare class IndexedDbOutboxStore implements OutboxStore {
|
|
21
|
+
private readonly options;
|
|
22
|
+
private database;
|
|
23
|
+
constructor(options?: IndexedDbOutboxOptions);
|
|
24
|
+
/** Stores an item, replacing the one with the same id. */
|
|
25
|
+
put(item: OutboxItem): Promise<void>;
|
|
26
|
+
/** Returns an item, or `null` when there is none. */
|
|
27
|
+
get(id: string): Promise<OutboxItem | null>;
|
|
28
|
+
/** Deletes an item. */
|
|
29
|
+
remove(id: string): Promise<void>;
|
|
30
|
+
/** The owner's pending items that are due, newest first. */
|
|
31
|
+
due(ownerKey: string, now: number, limit: number): Promise<OutboxItem[]>;
|
|
32
|
+
/** Every item of the owner, without its entries. */
|
|
33
|
+
summaries(ownerKey: string): Promise<OutboxItemSummary[]>;
|
|
34
|
+
/** How many of the owner's items are in `state`. */
|
|
35
|
+
count(ownerKey: string, state: OutboxState): Promise<number>;
|
|
36
|
+
private open;
|
|
37
|
+
private connect;
|
|
38
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IndexedDbOutboxStore = void 0;
|
|
4
|
+
const ovok_errors_1 = require("../errors/ovok-errors");
|
|
5
|
+
const outbox_queries_1 = require("./outbox-queries");
|
|
6
|
+
const DEFAULT_DATABASE_NAME = "ovok-outbox";
|
|
7
|
+
const SCHEMA_VERSION = 1;
|
|
8
|
+
const ITEMS = "items";
|
|
9
|
+
const SUMMARIES = "summaries";
|
|
10
|
+
const OWNER_INDEX = "owner";
|
|
11
|
+
const resultOf = (request) => new Promise((resolve, reject) => {
|
|
12
|
+
request.onsuccess = () => resolve(request.result);
|
|
13
|
+
request.onerror = () => reject(request.error);
|
|
14
|
+
});
|
|
15
|
+
const completionOf = (transaction) => new Promise((resolve, reject) => {
|
|
16
|
+
transaction.oncomplete = () => resolve();
|
|
17
|
+
transaction.onerror = () => reject(transaction.error);
|
|
18
|
+
transaction.onabort = () => reject(transaction.error);
|
|
19
|
+
});
|
|
20
|
+
const createSchema = (database) => {
|
|
21
|
+
database.createObjectStore(ITEMS, { keyPath: "id" });
|
|
22
|
+
database.createObjectStore(SUMMARIES, { keyPath: "id" }).createIndex(OWNER_INDEX, "ownerKey");
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* An `OutboxStore` on the browser's IndexedDB, with no dependency. Items and their summaries live in two object
|
|
26
|
+
* stores, so listing and counting never read the entries.
|
|
27
|
+
*
|
|
28
|
+
* @category outbox
|
|
29
|
+
*/
|
|
30
|
+
class IndexedDbOutboxStore {
|
|
31
|
+
constructor(options = {}) {
|
|
32
|
+
this.options = options;
|
|
33
|
+
this.database = null;
|
|
34
|
+
}
|
|
35
|
+
/** Stores an item, replacing the one with the same id. */
|
|
36
|
+
async put(item) {
|
|
37
|
+
const transaction = (await this.open()).transaction([ITEMS, SUMMARIES], "readwrite");
|
|
38
|
+
transaction.objectStore(ITEMS).put(item);
|
|
39
|
+
transaction.objectStore(SUMMARIES).put((0, outbox_queries_1.summaryOf)(item));
|
|
40
|
+
await completionOf(transaction);
|
|
41
|
+
}
|
|
42
|
+
/** Returns an item, or `null` when there is none. */
|
|
43
|
+
async get(id) {
|
|
44
|
+
var _a;
|
|
45
|
+
const database = await this.open();
|
|
46
|
+
return (_a = (await resultOf(database.transaction(ITEMS).objectStore(ITEMS).get(id)))) !== null && _a !== void 0 ? _a : null;
|
|
47
|
+
}
|
|
48
|
+
/** Deletes an item. */
|
|
49
|
+
async remove(id) {
|
|
50
|
+
const transaction = (await this.open()).transaction([ITEMS, SUMMARIES], "readwrite");
|
|
51
|
+
transaction.objectStore(ITEMS).delete(id);
|
|
52
|
+
transaction.objectStore(SUMMARIES).delete(id);
|
|
53
|
+
await completionOf(transaction);
|
|
54
|
+
}
|
|
55
|
+
/** The owner's pending items that are due, newest first. */
|
|
56
|
+
async due(ownerKey, now, limit) {
|
|
57
|
+
const due = (await this.summaries(ownerKey)).filter((0, outbox_queries_1.isDueFor)(ownerKey, now)).sort(outbox_queries_1.newestFirst).slice(0, limit);
|
|
58
|
+
const items = await Promise.all(due.map(({ id }) => this.get(id)));
|
|
59
|
+
return items.filter((item) => item !== null);
|
|
60
|
+
}
|
|
61
|
+
/** Every item of the owner, without its entries. */
|
|
62
|
+
async summaries(ownerKey) {
|
|
63
|
+
const database = await this.open();
|
|
64
|
+
const owner = database.transaction(SUMMARIES).objectStore(SUMMARIES).index(OWNER_INDEX);
|
|
65
|
+
return resultOf(owner.getAll(ownerKey));
|
|
66
|
+
}
|
|
67
|
+
/** How many of the owner's items are in `state`. */
|
|
68
|
+
async count(ownerKey, state) {
|
|
69
|
+
return (await this.summaries(ownerKey)).filter((item) => item.state === state).length;
|
|
70
|
+
}
|
|
71
|
+
open() {
|
|
72
|
+
var _a;
|
|
73
|
+
(_a = this.database) !== null && _a !== void 0 ? _a : (this.database = this.connect().catch((error) => {
|
|
74
|
+
this.database = null;
|
|
75
|
+
throw error;
|
|
76
|
+
}));
|
|
77
|
+
return this.database;
|
|
78
|
+
}
|
|
79
|
+
connect() {
|
|
80
|
+
var _a, _b;
|
|
81
|
+
const factory = (_a = this.options.factory) !== null && _a !== void 0 ? _a : globalThis.indexedDB;
|
|
82
|
+
if (!factory) {
|
|
83
|
+
throw new ovok_errors_1.OvokConfigError((0, ovok_errors_1.detailsFor)("IndexedDB is not available: pass options.factory."));
|
|
84
|
+
}
|
|
85
|
+
const request = factory.open((_b = this.options.name) !== null && _b !== void 0 ? _b : DEFAULT_DATABASE_NAME, SCHEMA_VERSION);
|
|
86
|
+
request.onupgradeneeded = () => createSchema(request.result);
|
|
87
|
+
return resultOf(request);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.IndexedDbOutboxStore = IndexedDbOutboxStore;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Outcome } from "./failure-policy";
|
|
2
|
+
import type { GroupLinks } from "./group-links";
|
|
3
|
+
import type { OutboxStore } from "./outbox-store";
|
|
4
|
+
import type { OutboxItem } from "./outbox-types";
|
|
5
|
+
import type { RunnerState } from "./runner-state";
|
|
6
|
+
import type { Bundle } from "@medplum/fhirtypes";
|
|
7
|
+
/**
|
|
8
|
+
* What one flush did, with the responses and errors of the items it settled.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export type FlushReport = {
|
|
13
|
+
/** Items a send was tried for. */
|
|
14
|
+
attempted: number;
|
|
15
|
+
/** Items the server accepted. */
|
|
16
|
+
sent: number;
|
|
17
|
+
/** Items the server refused. */
|
|
18
|
+
rejected: number;
|
|
19
|
+
/** The server's response for each item sent, by item id; items sent together share one response. */
|
|
20
|
+
responses: Map<string, Bundle>;
|
|
21
|
+
/** The error that refused each item, by item id. */
|
|
22
|
+
errors: Map<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
export type FailedOutcome = Extract<Outcome, {
|
|
25
|
+
type: "timeout" | "retry" | "reject";
|
|
26
|
+
}>;
|
|
27
|
+
export declare const emptyReport: () => FlushReport;
|
|
28
|
+
/** Writes the result of a send to the store: sent items go, failed ones are rescheduled or refused. */
|
|
29
|
+
export declare class ItemSettler {
|
|
30
|
+
private readonly store;
|
|
31
|
+
private readonly links;
|
|
32
|
+
private readonly state;
|
|
33
|
+
private readonly now;
|
|
34
|
+
constructor(store: OutboxStore, links: GroupLinks, state: RunnerState, now: () => number);
|
|
35
|
+
sent(items: OutboxItem[], response: Bundle, report: FlushReport): Promise<void>;
|
|
36
|
+
failed(item: OutboxItem, outcome: FailedOutcome, report: FlushReport): Promise<void>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ItemSettler = exports.emptyReport = void 0;
|
|
4
|
+
const failure_policy_1 = require("./failure-policy");
|
|
5
|
+
const MAX_ATTEMPTS = 5;
|
|
6
|
+
const emptyReport = () => ({
|
|
7
|
+
attempted: 0,
|
|
8
|
+
sent: 0,
|
|
9
|
+
rejected: 0,
|
|
10
|
+
responses: new Map(),
|
|
11
|
+
errors: new Map(),
|
|
12
|
+
});
|
|
13
|
+
exports.emptyReport = emptyReport;
|
|
14
|
+
/** Writes the result of a send to the store: sent items go, failed ones are rescheduled or refused. */
|
|
15
|
+
class ItemSettler {
|
|
16
|
+
constructor(store, links, state, now) {
|
|
17
|
+
this.store = store;
|
|
18
|
+
this.links = links;
|
|
19
|
+
this.state = state;
|
|
20
|
+
this.now = now;
|
|
21
|
+
}
|
|
22
|
+
async sent(items, response, report) {
|
|
23
|
+
for (const item of items) {
|
|
24
|
+
report.sent += 1;
|
|
25
|
+
report.responses.set(item.id, response);
|
|
26
|
+
if (!this.state.wasSuperseded(item.id)) {
|
|
27
|
+
await this.store.remove(item.id);
|
|
28
|
+
await this.links.landed(item, response);
|
|
29
|
+
}
|
|
30
|
+
this.state.remember(item);
|
|
31
|
+
}
|
|
32
|
+
this.state.succeeded();
|
|
33
|
+
}
|
|
34
|
+
async failed(item, outcome, report) {
|
|
35
|
+
this.state.lastError = outcome.failure;
|
|
36
|
+
if (this.state.wasSuperseded(item.id)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const attempts = item.attempts + 1;
|
|
40
|
+
const refused = outcome.type === "reject" || attempts >= MAX_ATTEMPTS;
|
|
41
|
+
const failed = { ...item, attempts, lastFailure: outcome.failure };
|
|
42
|
+
await this.store.put(refused ? { ...failed, state: "rejected" } : { ...failed, nextAttemptAt: this.now() + (0, failure_policy_1.retryDelayMs)(attempts) });
|
|
43
|
+
if (refused) {
|
|
44
|
+
report.rejected += 1;
|
|
45
|
+
report.errors.set(item.id, outcome.error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ItemSettler = ItemSettler;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OutboxStore } from "./outbox-store";
|
|
2
|
+
import type { OvokStorage } from "../storage/ovok-storage";
|
|
3
|
+
/**
|
|
4
|
+
* Moves the readings of the old single-key queue into the outbox, then deletes the key. Readings that ran out of
|
|
5
|
+
* retries come over as rejected, so the user can resend them. An unreadable queue is left where it is.
|
|
6
|
+
*/
|
|
7
|
+
export declare const importLegacyQueue: (storage: OvokStorage, key: string, store: OutboxStore, now: number) => Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.importLegacyQueue = void 0;
|
|
4
|
+
const entry_observation_1 = require("./entry-observation");
|
|
5
|
+
const outbox_items_1 = require("./outbox-items");
|
|
6
|
+
const isLegacyMeasurement = (value) => {
|
|
7
|
+
const item = value;
|
|
8
|
+
return typeof (item === null || item === void 0 ? void 0 : item.ownerKey) === "string" && Array.isArray(item.entries);
|
|
9
|
+
};
|
|
10
|
+
const parseQueue = (serialized) => {
|
|
11
|
+
try {
|
|
12
|
+
const queue = JSON.parse(serialized !== null && serialized !== void 0 ? serialized : "null");
|
|
13
|
+
return Array.isArray(queue) ? queue.filter(isLegacyMeasurement) : null;
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const outboxItemOf = (legacy, now) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const queuedAt = Date.parse((_a = legacy.queuedAt) !== null && _a !== void 0 ? _a : "");
|
|
22
|
+
const createdAt = Number.isNaN(queuedAt) ? now : queuedAt;
|
|
23
|
+
return {
|
|
24
|
+
id: (0, outbox_items_1.measurementItemId)(legacy.ownerKey, legacy.entries),
|
|
25
|
+
ownerKey: legacy.ownerKey,
|
|
26
|
+
kind: "measurement",
|
|
27
|
+
entries: legacy.entries,
|
|
28
|
+
state: legacy.exhausted ? "rejected" : "pending",
|
|
29
|
+
attempts: 0,
|
|
30
|
+
nextAttemptAt: 0,
|
|
31
|
+
createdAt,
|
|
32
|
+
recordedAt: (0, outbox_items_1.recordedAtOf)((0, entry_observation_1.observationOf)(legacy.entries[0]), createdAt),
|
|
33
|
+
...(legacy.lastFailure ? { lastFailure: legacy.lastFailure } : {}),
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Moves the readings of the old single-key queue into the outbox, then deletes the key. Readings that ran out of
|
|
38
|
+
* retries come over as rejected, so the user can resend them. An unreadable queue is left where it is.
|
|
39
|
+
*/
|
|
40
|
+
const importLegacyQueue = async (storage, key, store, now) => {
|
|
41
|
+
const queue = parseQueue(await storage.getItem(key));
|
|
42
|
+
if (queue === null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
for (const legacy of queue) {
|
|
46
|
+
await store.put(outboxItemOf(legacy, now));
|
|
47
|
+
}
|
|
48
|
+
await storage.removeItem(key);
|
|
49
|
+
};
|
|
50
|
+
exports.importLegacyQueue = importLegacyQueue;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OutboxStore } from "./outbox-store";
|
|
2
|
+
import type { OutboxItem, OutboxItemSummary, OutboxState } from "./outbox-types";
|
|
3
|
+
/**
|
|
4
|
+
* An `OutboxStore` that keeps items in memory and loses them when the process ends.
|
|
5
|
+
*
|
|
6
|
+
* @category outbox
|
|
7
|
+
*/
|
|
8
|
+
export declare class MemoryOutboxStore implements OutboxStore {
|
|
9
|
+
private readonly items;
|
|
10
|
+
/** Stores an item, replacing the one with the same id. */
|
|
11
|
+
put(item: OutboxItem): Promise<void>;
|
|
12
|
+
/** Returns an item, or `null` when there is none. */
|
|
13
|
+
get(id: string): Promise<OutboxItem | null>;
|
|
14
|
+
/** Deletes an item. */
|
|
15
|
+
remove(id: string): Promise<void>;
|
|
16
|
+
/** The owner's pending items that are due, newest first. */
|
|
17
|
+
due(ownerKey: string, now: number, limit: number): Promise<OutboxItem[]>;
|
|
18
|
+
/** Every item of the owner, without its entries. */
|
|
19
|
+
summaries(ownerKey: string): Promise<OutboxItemSummary[]>;
|
|
20
|
+
/** How many of the owner's items are in `state`. */
|
|
21
|
+
count(ownerKey: string, state: OutboxState): Promise<number>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryOutboxStore = void 0;
|
|
4
|
+
const outbox_queries_1 = require("./outbox-queries");
|
|
5
|
+
/**
|
|
6
|
+
* An `OutboxStore` that keeps items in memory and loses them when the process ends.
|
|
7
|
+
*
|
|
8
|
+
* @category outbox
|
|
9
|
+
*/
|
|
10
|
+
class MemoryOutboxStore {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.items = new Map();
|
|
13
|
+
}
|
|
14
|
+
/** Stores an item, replacing the one with the same id. */
|
|
15
|
+
async put(item) {
|
|
16
|
+
this.items.set(item.id, item);
|
|
17
|
+
}
|
|
18
|
+
/** Returns an item, or `null` when there is none. */
|
|
19
|
+
async get(id) {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = this.items.get(id)) !== null && _a !== void 0 ? _a : null;
|
|
22
|
+
}
|
|
23
|
+
/** Deletes an item. */
|
|
24
|
+
async remove(id) {
|
|
25
|
+
this.items.delete(id);
|
|
26
|
+
}
|
|
27
|
+
/** The owner's pending items that are due, newest first. */
|
|
28
|
+
async due(ownerKey, now, limit) {
|
|
29
|
+
return [...this.items.values()].filter((0, outbox_queries_1.isDueFor)(ownerKey, now)).sort(outbox_queries_1.newestFirst).slice(0, limit);
|
|
30
|
+
}
|
|
31
|
+
/** Every item of the owner, without its entries. */
|
|
32
|
+
async summaries(ownerKey) {
|
|
33
|
+
return [...this.items.values()].filter((item) => item.ownerKey === ownerKey).map(outbox_queries_1.summaryOf);
|
|
34
|
+
}
|
|
35
|
+
/** How many of the owner's items are in `state`. */
|
|
36
|
+
async count(ownerKey, state) {
|
|
37
|
+
return (await this.summaries(ownerKey)).filter((item) => item.state === state).length;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.MemoryOutboxStore = MemoryOutboxStore;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { OutboxDeleteTarget, OutboxItem } from "./outbox-types";
|
|
2
|
+
import type { BundleEntry, Observation } from "@medplum/fhirtypes";
|
|
3
|
+
import { ObservationEntryOptions } from "../../client/offline";
|
|
4
|
+
/**
|
|
5
|
+
* What the outbox needs to store an item; it adds the owner, state and timestamps.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export type OutboxDraft = Pick<OutboxItem, "id" | "kind" | "entries" | "recordedAt" | "group" | "seq">;
|
|
10
|
+
export declare const measurementItemId: (ownerKey: string, entries: BundleEntry[]) => string;
|
|
11
|
+
export declare const recordedAtOf: (observation: Observation | undefined, fallback: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* The items that save one reading: one item for a reading or a series, and for a recording of several segments one
|
|
14
|
+
* item per segment followed by an item for its group.
|
|
15
|
+
*/
|
|
16
|
+
export declare const draftsFor: (observations: Observation[], options: ObservationEntryOptions, ownerKey: string, now: number) => OutboxDraft[];
|
|
17
|
+
export declare const deleteDraft: (target: OutboxDeleteTarget, subject: string, ownerKey: string, now: number) => OutboxDraft;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteDraft = exports.draftsFor = exports.recordedAtOf = exports.measurementItemId = void 0;
|
|
4
|
+
const fhir_systems_1 = require("../../client/observation/fhir-systems");
|
|
5
|
+
const observation_bundle_utils_1 = require("../../client/observation/observation-bundle-utils");
|
|
6
|
+
const reading_group_1 = require("../../client/observation/reading-group");
|
|
7
|
+
const offline_1 = require("../../client/offline");
|
|
8
|
+
const identifierValue = (observation, system) => { var _a, _b; return (_b = (_a = observation.identifier) === null || _a === void 0 ? void 0 : _a.find((identifier) => identifier.system === system)) === null || _b === void 0 ? void 0 : _b.value; };
|
|
9
|
+
const idFor = (ownerKey, key) => (0, offline_1.stableValueId)({ ownerKey, key });
|
|
10
|
+
const measurementItemId = (ownerKey, entries) => idFor(ownerKey, entries.map(({ fullUrl }) => fullUrl !== null && fullUrl !== void 0 ? fullUrl : "").join("|"));
|
|
11
|
+
exports.measurementItemId = measurementItemId;
|
|
12
|
+
const recordedAtOf = (observation, fallback) => {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
const time = Date.parse((_c = (_a = observation === null || observation === void 0 ? void 0 : observation.effectiveDateTime) !== null && _a !== void 0 ? _a : (_b = observation === null || observation === void 0 ? void 0 : observation.effectivePeriod) === null || _b === void 0 ? void 0 : _b.start) !== null && _c !== void 0 ? _c : "");
|
|
15
|
+
return Number.isNaN(time) ? fallback : time;
|
|
16
|
+
};
|
|
17
|
+
exports.recordedAtOf = recordedAtOf;
|
|
18
|
+
const positionOf = (observation) => {
|
|
19
|
+
var _a;
|
|
20
|
+
const value = (_a = identifierValue(observation, fhir_systems_1.SEGMENT_IDENTIFIER_SYSTEM)) !== null && _a !== void 0 ? _a : "";
|
|
21
|
+
const divider = value.lastIndexOf("/");
|
|
22
|
+
const seq = Number(value.slice(divider + 1));
|
|
23
|
+
return divider > 0 && Number.isInteger(seq) ? { recording: value.slice(0, divider), seq } : null;
|
|
24
|
+
};
|
|
25
|
+
const entryFor = (observation, options) => {
|
|
26
|
+
var _a;
|
|
27
|
+
const isSeries = identifierValue(observation, fhir_systems_1.SERIES_IDENTIFIER_SYSTEM) !== undefined;
|
|
28
|
+
return (0, offline_1.entryForObservation)(observation, isSeries ? { identifierSystems: [...((_a = options.identifierSystems) !== null && _a !== void 0 ? _a : []), fhir_systems_1.SERIES_IDENTIFIER_SYSTEM], replace: true } : options);
|
|
29
|
+
};
|
|
30
|
+
const segmentDraft = (segment, ownerKey, now) => {
|
|
31
|
+
const { recording, seq } = positionOf(segment);
|
|
32
|
+
const identifier = identifierValue(segment, fhir_systems_1.SEGMENT_IDENTIFIER_SYSTEM);
|
|
33
|
+
return {
|
|
34
|
+
id: idFor(ownerKey, `segment|${identifier}`),
|
|
35
|
+
kind: "segment",
|
|
36
|
+
group: recording,
|
|
37
|
+
seq,
|
|
38
|
+
entries: [(0, offline_1.entryForObservation)(segment, { identifierSystems: [fhir_systems_1.SEGMENT_IDENTIFIER_SYSTEM], replace: true })],
|
|
39
|
+
recordedAt: (0, exports.recordedAtOf)(segment, now),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const recordingDrafts = (observations, segments, options, ownerKey, now) => {
|
|
43
|
+
var _a;
|
|
44
|
+
const drafts = segments.map((segment) => segmentDraft(segment, ownerKey, now));
|
|
45
|
+
const closing = observations.filter((observation) => !segments.includes(observation));
|
|
46
|
+
const recording = (_a = drafts[0]) === null || _a === void 0 ? void 0 : _a.group;
|
|
47
|
+
return [
|
|
48
|
+
...drafts,
|
|
49
|
+
{
|
|
50
|
+
id: idFor(ownerKey, `group|${recording}`),
|
|
51
|
+
kind: "measurement",
|
|
52
|
+
group: recording,
|
|
53
|
+
seq: Math.max(...drafts.map(({ seq }) => seq)) + 1,
|
|
54
|
+
entries: closing.map((observation) => entryFor(observation, options)),
|
|
55
|
+
recordedAt: (0, exports.recordedAtOf)(closing[closing.length - 1], now),
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
};
|
|
59
|
+
const wholeDraft = (observations, options, ownerKey, now) => {
|
|
60
|
+
const entries = observations.map((observation) => entryFor(observation, options));
|
|
61
|
+
const series = observations.map((observation) => identifierValue(observation, fhir_systems_1.SERIES_IDENTIFIER_SYSTEM)).find(Boolean);
|
|
62
|
+
const recordedAt = (0, exports.recordedAtOf)(observations[0], now);
|
|
63
|
+
return series
|
|
64
|
+
? { id: idFor(ownerKey, `series|${series}`), kind: "series", entries, recordedAt }
|
|
65
|
+
: { id: (0, exports.measurementItemId)(ownerKey, entries), kind: "measurement", entries, recordedAt };
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The items that save one reading: one item for a reading or a series, and for a recording of several segments one
|
|
69
|
+
* item per segment followed by an item for its group.
|
|
70
|
+
*/
|
|
71
|
+
const draftsFor = (observations, options, ownerKey, now) => {
|
|
72
|
+
const linked = (0, observation_bundle_utils_1.linkObservationMembers)(observations);
|
|
73
|
+
const segments = linked.filter((observation) => positionOf(observation) !== null);
|
|
74
|
+
const isLongRecording = segments.length > 1 && linked.some(reading_group_1.isReadingGroup);
|
|
75
|
+
return isLongRecording
|
|
76
|
+
? recordingDrafts(linked, segments, options, ownerKey, now)
|
|
77
|
+
: [wholeDraft(linked, options, ownerKey, now)];
|
|
78
|
+
};
|
|
79
|
+
exports.draftsFor = draftsFor;
|
|
80
|
+
const deleteDraft = (target, subject, ownerKey, now) => {
|
|
81
|
+
const identifier = encodeURIComponent(`${target.system}|${target.value}`);
|
|
82
|
+
return {
|
|
83
|
+
id: idFor(ownerKey, `delete|${target.system}|${target.value}|${subject}`),
|
|
84
|
+
kind: "delete",
|
|
85
|
+
recordedAt: now,
|
|
86
|
+
entries: [{ request: { method: "DELETE", url: `Observation?identifier=${identifier}&subject=${encodeURIComponent(subject)}` } }],
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.deleteDraft = deleteDraft;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { OutboxItem, OutboxItemSummary } from "./outbox-types";
|
|
2
|
+
export declare const summaryOf: ({ entries: _entries, ...summary }: OutboxItem) => OutboxItemSummary;
|
|
3
|
+
export declare const isDueFor: (ownerKey: string, now: number) => (item: OutboxItemSummary) => boolean;
|
|
4
|
+
export declare const newestFirst: (left: OutboxItemSummary, right: OutboxItemSummary) => number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newestFirst = exports.isDueFor = exports.summaryOf = void 0;
|
|
4
|
+
const summaryOf = ({ entries: _entries, ...summary }) => summary;
|
|
5
|
+
exports.summaryOf = summaryOf;
|
|
6
|
+
const isDueFor = (ownerKey, now) => (item) => item.ownerKey === ownerKey && item.state === "pending" && item.nextAttemptAt <= now;
|
|
7
|
+
exports.isDueFor = isDueFor;
|
|
8
|
+
const newestFirst = (left, right) => { var _a, _b; return right.recordedAt - left.recordedAt || ((_a = left.seq) !== null && _a !== void 0 ? _a : 0) - ((_b = right.seq) !== null && _b !== void 0 ? _b : 0) || left.id.localeCompare(right.id); };
|
|
9
|
+
exports.newestFirst = newestFirst;
|