@interncom/diplomatic 0.4.5 → 0.5.0
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/web/client.d.ts +6 -4
- package/dist/web/index.d.ts +4 -4
- package/dist/web/index.mjs +1 -1
- package/dist/web/stores/idb/msgs.d.ts +6 -3
- package/dist/web/stores/idb/store.d.ts +3 -2
- package/dist/web/stores/memory/msgs.d.ts +6 -3
- package/dist/web/types.d.ts +53 -19
- package/dist/web/worker.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Status } from "../../shared/consts";
|
|
2
2
|
import { ICrypto } from "../../shared/types";
|
|
3
3
|
import { EntityID, Hash } from "../../shared/types";
|
|
4
|
-
import { IMessageStore, IStorableMessage, IStoredMessage } from "../../types";
|
|
4
|
+
import { ApldState, IMessageStore, IStorableMessage, IStoredMessage } from "../../types";
|
|
5
5
|
export declare class IDBMessageStore implements IMessageStore {
|
|
6
6
|
private crypto;
|
|
7
7
|
db: IDBDatabase;
|
|
@@ -10,9 +10,12 @@ export declare class IDBMessageStore implements IMessageStore {
|
|
|
10
10
|
del(keys: Iterable<Hash>): Promise<void>;
|
|
11
11
|
get(key: Hash): Promise<IStoredMessage | undefined>;
|
|
12
12
|
has(key: Hash): Promise<boolean>;
|
|
13
|
-
list(): Promise<
|
|
13
|
+
list(apld?: ApldState): Promise<IStoredMessage[]>;
|
|
14
14
|
last(eid: EntityID): Promise<IStoredMessage | undefined>;
|
|
15
|
-
listUnapplied(): Promise<IStoredMessage[]>;
|
|
16
15
|
markApplied(keys: Iterable<Hash>): Promise<void>;
|
|
16
|
+
markFailed(entries: Iterable<{
|
|
17
|
+
key: Hash;
|
|
18
|
+
err: Status;
|
|
19
|
+
}>): Promise<void>;
|
|
17
20
|
wipe(): Promise<void>;
|
|
18
21
|
}
|
|
@@ -11,8 +11,9 @@ export declare const UPLOAD_QUEUE_TABLE = "uploadQueue";
|
|
|
11
11
|
export declare const DOWNLOAD_QUEUE_TABLE = "downloadQueue";
|
|
12
12
|
export declare const MESSAGES_TABLE = "messages";
|
|
13
13
|
/**
|
|
14
|
-
* Index on messages.apld
|
|
15
|
-
*
|
|
14
|
+
* Index on messages.apld ({@link APLD_PENDING} / {@link APLD_APPLIED} /
|
|
15
|
+
* {@link APLD_ERROR}). Booleans are not valid IndexedDB keys; single-char
|
|
16
|
+
* strings keep keys compact.
|
|
16
17
|
*/
|
|
17
18
|
export declare const MESSAGES_APLD_INDEX = "apld";
|
|
18
19
|
/** Schema version: v3 adds messages.apld index for the apply queue. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ICrypto } from "../../shared/types";
|
|
2
2
|
import { EntityID, Hash } from "../../shared/types";
|
|
3
|
-
import { IMessageStore, IStorableMessage, IStoredMessage, IStoredMessageData } from "../../types";
|
|
3
|
+
import { ApldState, IMessageStore, IStorableMessage, IStoredMessage, IStoredMessageData } from "../../types";
|
|
4
4
|
import { Status } from "../../shared/consts";
|
|
5
5
|
export declare class MemoryMessageStore implements IMessageStore {
|
|
6
6
|
private crypto;
|
|
@@ -10,9 +10,12 @@ export declare class MemoryMessageStore implements IMessageStore {
|
|
|
10
10
|
del(keys: Iterable<Hash>): Promise<void>;
|
|
11
11
|
get(key: Hash): Promise<IStoredMessage | undefined>;
|
|
12
12
|
has(key: Hash): Promise<boolean>;
|
|
13
|
-
list(): Promise<
|
|
13
|
+
list(apld?: ApldState): Promise<IStoredMessage[]>;
|
|
14
14
|
last(eid: EntityID): Promise<IStoredMessage | undefined>;
|
|
15
|
-
listUnapplied(): Promise<IStoredMessage[]>;
|
|
16
15
|
markApplied(keys: Iterable<Hash>): Promise<void>;
|
|
16
|
+
markFailed(entries: Iterable<{
|
|
17
|
+
key: Hash;
|
|
18
|
+
err: Status;
|
|
19
|
+
}>): Promise<void>;
|
|
17
20
|
wipe(): Promise<void>;
|
|
18
21
|
}
|
package/dist/web/types.d.ts
CHANGED
|
@@ -74,10 +74,18 @@ export interface IDownloadQueue {
|
|
|
74
74
|
count: () => Promise<number>;
|
|
75
75
|
wipe(): Promise<void>;
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Apply lifecycle values for archive rows (IDB-indexable single-char strings;
|
|
79
|
+
* booleans are not valid IndexedDB keys). Defined first so {@link ApldState}
|
|
80
|
+
* is only those three literals.
|
|
81
|
+
*/
|
|
82
|
+
export declare const APLD_PENDING: "f";
|
|
83
|
+
export declare const APLD_APPLIED: "t";
|
|
84
|
+
export declare const APLD_ERROR: "e";
|
|
85
|
+
/** Only {@link APLD_PENDING}, {@link APLD_APPLIED}, or {@link APLD_ERROR}. */
|
|
86
|
+
export type ApldState = typeof APLD_PENDING | typeof APLD_APPLIED | typeof APLD_ERROR;
|
|
77
87
|
/**
|
|
78
88
|
* Archive fields shared by read and write.
|
|
79
|
-
* `apld`: true once the msg has been applied by the application state manager;
|
|
80
|
-
* false while still pending apply.
|
|
81
89
|
*/
|
|
82
90
|
export interface IStoredMessageFields {
|
|
83
91
|
eid: EntityID;
|
|
@@ -87,19 +95,23 @@ export interface IStoredMessageFields {
|
|
|
87
95
|
}
|
|
88
96
|
/**
|
|
89
97
|
* What may come back from storage (pre-apld rows can omit the field).
|
|
90
|
-
*
|
|
91
|
-
*
|
|
98
|
+
* Typed rows use only {@link ApldState}; {@link apldFromStored} coerces
|
|
99
|
+
* legacy boolean / unknown values at the storage boundary.
|
|
92
100
|
*/
|
|
93
101
|
export interface IStoredMessageData extends IStoredMessageFields {
|
|
94
|
-
apld?:
|
|
102
|
+
apld?: ApldState;
|
|
103
|
+
/** Status code when apld is {@link APLD_ERROR}. */
|
|
104
|
+
err?: number;
|
|
95
105
|
}
|
|
96
106
|
/**
|
|
97
107
|
* Required shape for every put into the message archive (app/API layer).
|
|
98
|
-
*
|
|
99
|
-
*
|
|
108
|
+
* `apld` is required and must be one of the three {@link ApldState} values.
|
|
109
|
+
* Omit optional fields (`off`, `ctr`, `body`, `err`) rather than storing empties.
|
|
100
110
|
*/
|
|
101
111
|
export type IStoredMessageWrite = IStoredMessageFields & {
|
|
102
|
-
apld:
|
|
112
|
+
apld: ApldState;
|
|
113
|
+
/** Status code when apld is {@link APLD_ERROR}. */
|
|
114
|
+
err?: number;
|
|
103
115
|
};
|
|
104
116
|
export interface IStorableMessage {
|
|
105
117
|
key: Hash;
|
|
@@ -109,29 +121,51 @@ export interface IStoredMessage {
|
|
|
109
121
|
hash: Hash;
|
|
110
122
|
head: IMessageHead;
|
|
111
123
|
body?: EncodedMessage;
|
|
112
|
-
|
|
124
|
+
/** Apply lifecycle — same {@link ApldState} as the archive row. */
|
|
125
|
+
apld: ApldState;
|
|
126
|
+
/** Status code when apld is {@link APLD_ERROR}. */
|
|
127
|
+
err?: number;
|
|
113
128
|
}
|
|
129
|
+
/** True only for the three legal {@link ApldState} values. */
|
|
130
|
+
export declare function isApldState(v: unknown): v is ApldState;
|
|
114
131
|
/**
|
|
115
|
-
* Coerce
|
|
116
|
-
* Applied: true |
|
|
132
|
+
* Coerce raw storage values to {@link ApldState}.
|
|
133
|
+
* Applied: true | APLD_APPLIED. Failed: APLD_ERROR.
|
|
134
|
+
* Pending: false | APLD_PENDING | missing | anything else.
|
|
117
135
|
*/
|
|
118
|
-
export declare function apldFromStored(v: unknown):
|
|
119
|
-
/**
|
|
120
|
-
export declare function normalizeStoredMessageData(data: IStoredMessageData): IStoredMessageWrite;
|
|
121
|
-
/** Pending apply when not yet marked applied. */
|
|
136
|
+
export declare function apldFromStored(v: unknown): ApldState;
|
|
137
|
+
/** Pending apply when not yet applied or terminally failed. */
|
|
122
138
|
export declare function isPendingApply(data: IStoredMessageData): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Apply failures that should not be retried (poison / protocol / shape).
|
|
141
|
+
* Transient storage errors stay pending ({@link APLD_PENDING}) for a later drain.
|
|
142
|
+
*/
|
|
143
|
+
export declare function isTerminalApplyFailure(st: Status): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Mutate a stored row's apply state in place (no copy).
|
|
146
|
+
* Clears `err` unless setting {@link APLD_ERROR}.
|
|
147
|
+
*/
|
|
148
|
+
export declare function setApld(data: IStoredMessageData, apld: ApldState, err?: Status): void;
|
|
123
149
|
export declare function toStoredMessage(hash: Hash, data: IStoredMessageData, crypto: ICrypto): Promise<IStoredMessage>;
|
|
124
150
|
export interface IMessageStore {
|
|
125
151
|
add: (messages: IStorableMessage[]) => Promise<Status[]>;
|
|
126
152
|
get: (key: Hash) => Promise<IStoredMessage | undefined>;
|
|
127
153
|
has: (key: Hash) => Promise<boolean>;
|
|
128
154
|
del: (keys: Iterable<Hash>) => Promise<void>;
|
|
129
|
-
|
|
155
|
+
/**
|
|
156
|
+
* List archive rows. Pass {@link ApldState} to filter by apply lifecycle
|
|
157
|
+
* (e.g. {@link APLD_PENDING} for the apply queue, {@link APLD_ERROR} for
|
|
158
|
+
* diagnostics). Omit for all messages.
|
|
159
|
+
*/
|
|
160
|
+
list: (apld?: ApldState) => Promise<IStoredMessage[]>;
|
|
130
161
|
last: (eid: EntityID) => Promise<IStoredMessage | undefined>;
|
|
131
|
-
/**
|
|
132
|
-
listUnapplied: () => Promise<IStoredMessage[]>;
|
|
133
|
-
/** Mark archive rows as applied (apld = true). */
|
|
162
|
+
/** Mark archive rows as applied ({@link APLD_APPLIED}). */
|
|
134
163
|
markApplied: (keys: Iterable<Hash>) => Promise<void>;
|
|
164
|
+
/** Mark archive rows as terminal apply failure ({@link APLD_ERROR}). */
|
|
165
|
+
markFailed: (entries: Iterable<{
|
|
166
|
+
key: Hash;
|
|
167
|
+
err: Status;
|
|
168
|
+
}>) => Promise<void>;
|
|
135
169
|
wipe(): Promise<void>;
|
|
136
170
|
}
|
|
137
171
|
export interface IStore<Handle extends HostHandle> {
|