@agentshouse/mdruntime 0.1.0-cb8a03985803b → 0.1.0-cb9a984171ffb
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/README.md +14 -13
- package/dist/acceptance.js +1 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -6
- package/dist/adapter.d.ts +113 -21
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -7
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +347 -0
- package/dist/binary.d.ts +6 -2
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +10 -3
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +3 -0
- package/dist/chat-types.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +2 -4
- package/dist/client.d.ts +17 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +24 -54
- package/dist/collection.d.ts +6 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +23 -9
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +2 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +72 -41
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +11 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +18 -9
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +17 -8
- package/dist/conversation-row.d.ts +8 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +20 -7
- package/dist/conversation.d.ts +16 -11
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +183 -139
- package/dist/declaration.js +1 -1
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +30 -5
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +1 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +3 -0
- package/dist/entry.d.ts +14 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +45 -16
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +4 -2
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/host.d.ts +6 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +68 -27
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +67 -0
- package/dist/index.d.ts +13 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/install.d.ts +8 -2
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +40 -33
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +38 -25
- package/dist/listing.d.ts +24 -12
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +50 -21
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +94 -36
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +4 -2
- package/dist/lost.js +1 -1
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +167 -33
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +60 -20
- package/dist/messages.d.ts +8 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +14 -3
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +4 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +3 -3
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +26 -10
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +200 -69
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +18 -2
- package/dist/outcome.d.ts +21 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +18 -3
- package/dist/overlay.d.ts +4 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +3 -5
- package/dist/parts.d.ts +3 -1
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -7
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +195 -78
- package/dist/presence.d.ts +8 -2
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +24 -13
- package/dist/queries.d.ts +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +114 -66
- package/dist/query.d.ts +2 -2
- package/dist/questions.d.ts +1 -0
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +51 -21
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +122 -23
- package/dist/react.d.ts +6 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +19 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +17 -10
- package/dist/reads.d.ts +1 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +2 -2
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +2 -1
- package/dist/reference-forms.d.ts +4 -0
- package/dist/reference-forms.d.ts.map +1 -0
- package/dist/reference-forms.js +74 -0
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +4 -4
- package/dist/room-draft.d.ts +28 -3
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +235 -14
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +11 -6
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +11 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +24 -10
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +4 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +17 -86
- package/dist/saves.d.ts +4 -2
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +75 -22
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/shown.d.ts +3 -1
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +72 -41
- package/dist/socket/session.d.ts +4 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +1 -0
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +1 -0
- package/dist/source.d.ts +7 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +15 -2
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +18 -3
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +57 -21
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store.d.ts +14 -9
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +12 -5
- package/dist/stored.d.ts +38 -14
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +210 -52
- package/dist/surface.d.ts +13 -7
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +52 -17
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +49 -27
- package/dist/tables.d.ts +22 -49
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +70 -325
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +1 -2
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +50 -10
- package/dist/wire.d.ts +28 -13
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +17 -12
- package/package.json +3 -3
package/dist/messages.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sql } from '@agentshouse/mdmodel';
|
|
2
|
+
import { text } from './column.js';
|
|
2
3
|
import { EXCERPT } from './read.js';
|
|
3
4
|
import { tablesOf } from './stored.js';
|
|
4
5
|
const SAID_BY_HOUSE = `json_extract(message, '$.role') = 'house'`;
|
|
@@ -15,6 +16,7 @@ export const MESSAGE_TABLES = [
|
|
|
15
16
|
const NEWEST_FIRST = 'ORDER BY position DESC, identity DESC LIMIT 1';
|
|
16
17
|
const OLDEST_FIRST = 'ORDER BY position, identity LIMIT 1';
|
|
17
18
|
const OF_THE_ROW = 'SELECT id FROM conversation_messages WHERE conversation = listed.value';
|
|
19
|
+
const READ_UNTIL = `(SELECT julianday(json_extract(value, '$')) FROM replica_facts WHERE name = 'readUntil')`;
|
|
18
20
|
export const ROWS = `WITH chosen AS (
|
|
19
21
|
SELECT listed.value AS conversation,
|
|
20
22
|
(${OF_THE_ROW} AND ${ANSWERS_THE_TURN} ${NEWEST_FIRST}) AS answer,
|
|
@@ -27,7 +29,14 @@ export const ROWS = `WITH chosen AS (
|
|
|
27
29
|
substr(said.text, 1, ${EXCERPT}) AS said_text,
|
|
28
30
|
json_extract(said.message, '$.role') AS said_role,
|
|
29
31
|
json_extract(said.message, '$.accepted_at') AS said_at,
|
|
32
|
+
answer.turn AS answered,
|
|
33
|
+
json_extract(answer.message, '$.content.state') AS saved_state,
|
|
34
|
+
json_extract(answer.message, '$.accepted_at') AS saved_at,
|
|
30
35
|
substr(json_extract(answer.message, '$.failure'), 1, ${EXCERPT}) AS failure,
|
|
36
|
+
COALESCE(
|
|
37
|
+
(SELECT value FROM conversation_facts WHERE conversation = chosen.conversation AND name = 'openedTurn'),
|
|
38
|
+
CASE WHEN julianday(json_extract(answer.message, '$.accepted_at')) < ${READ_UNTIL} THEN answer.turn END
|
|
39
|
+
) AS opened_turn,
|
|
31
40
|
json_extract(opened.message, '$.source') AS opened_source,
|
|
32
41
|
json_extract(opened.message, '$.sender') AS opened_sender,
|
|
33
42
|
asking.identity AS asking_identity,
|
|
@@ -40,9 +49,6 @@ export const ROWS = `WITH chosen AS (
|
|
|
40
49
|
LEFT JOIN conversation_messages answer ON answer.id = chosen.answer
|
|
41
50
|
LEFT JOIN conversation_messages opened ON opened.id = chosen.opened
|
|
42
51
|
LEFT JOIN conversation_messages asking ON asking.id = chosen.asking`;
|
|
43
|
-
function text(value) {
|
|
44
|
-
return typeof value === 'string' ? value : String(value);
|
|
45
|
-
}
|
|
46
52
|
export function heldConversations(connection, conversations) {
|
|
47
53
|
const named = conversations === null ? '' : ' AND conversation IN (SELECT value FROM json_each(?))';
|
|
48
54
|
const bound = conversations === null ? [] : [JSON.stringify(conversations)];
|
|
@@ -126,6 +132,11 @@ export function conversationRows(connection, conversations) {
|
|
|
126
132
|
role: textOrNull(row.said_role),
|
|
127
133
|
at: textOrNull(row.said_at),
|
|
128
134
|
},
|
|
135
|
+
answered: textOrNull(row.answered),
|
|
136
|
+
saved: row.saved_state === null || row.saved_at === null
|
|
137
|
+
? null
|
|
138
|
+
: { state: JSON.parse(text(row.saved_state)), at: text(row.saved_at) },
|
|
139
|
+
openedTurn: textOrNull(row.opened_turn),
|
|
129
140
|
failure: textOrNull(row.failure),
|
|
130
141
|
opened: row.opened_source === null ? null : heldSource(row.opened_source, row.opened_sender),
|
|
131
142
|
asking: row.asking_identity === null
|
package/dist/modal.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/modal.ts"],"names":[],"mappings":"AAMA,wBAAgB,UAAU,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAI1D"}
|
package/dist/modal.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function unfocused(page) {
|
|
2
|
+
let held = page.activeElement;
|
|
3
|
+
while (held?.shadowRoot?.activeElement)
|
|
4
|
+
held = held.shadowRoot.activeElement;
|
|
5
|
+
held.blur();
|
|
6
|
+
}
|
|
7
|
+
export function shownModal(dialog) {
|
|
8
|
+
unfocused(dialog.ownerDocument);
|
|
9
|
+
dialog.showModal();
|
|
10
|
+
unfocused(dialog.ownerDocument);
|
|
11
|
+
}
|
package/dist/model.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type StoredModel = Extract<ModelState, {
|
|
|
31
31
|
}> | Omit<Extract<ModelState, {
|
|
32
32
|
status: 'current' | 'cached';
|
|
33
33
|
}>, 'types'>;
|
|
34
|
-
export type TypesResult = {
|
|
34
|
+
export type TypesResult<Types = readonly MdType[]> = {
|
|
35
35
|
status: Open<'unavailable'>;
|
|
36
36
|
reason: ModelUnavailableReason;
|
|
37
37
|
types: null;
|
|
@@ -40,7 +40,7 @@ export type TypesResult = {
|
|
|
40
40
|
identity: string;
|
|
41
41
|
version: string;
|
|
42
42
|
verifiedWith: ModelIdentity;
|
|
43
|
-
types:
|
|
43
|
+
types: Types;
|
|
44
44
|
schema: string | null;
|
|
45
45
|
revision: string | null;
|
|
46
46
|
};
|
|
@@ -50,6 +50,8 @@ export type ValidationReceipt = {
|
|
|
50
50
|
source: Open<'current' | 'cached'>;
|
|
51
51
|
};
|
|
52
52
|
export declare const NO_MODEL: ModelState;
|
|
53
|
+
export declare function sortedTypes(types: VerifiedModel['types']): readonly MdType[];
|
|
53
54
|
export declare function modelTypes(state: ModelState): TypesResult;
|
|
55
|
+
export declare function modelResult<Types>(state: ModelState, types: (held: VerifiedModel['types']) => Types): TypesResult<Types>;
|
|
54
56
|
export declare function storedModel(state: ModelState): StoredModel;
|
|
55
57
|
//# sourceMappingURL=model.d.ts.map
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAC/F,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,cAAc,GAAG,SAAS,GAAG,cAAc,CAAC,CAAC;AACvF,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,MAAM,GAAG,UAAU,CA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C,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,SAAS,MAAM,EAAE,CAI5E;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAEzD;AACD,wBAAgB,WAAW,CAAC,KAAK,EAC/B,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,KAAK,GAC7C,WAAW,CAAC,KAAK,CAAC,CAYpB;AACD,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAI1D"}
|
package/dist/model.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export const NO_MODEL = { status: 'unavailable', reason: 'not-acquired' };
|
|
2
|
+
export function sortedTypes(types) {
|
|
3
|
+
return Object.values(types).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
4
|
+
}
|
|
2
5
|
export function modelTypes(state) {
|
|
6
|
+
return modelResult(state, sortedTypes);
|
|
7
|
+
}
|
|
8
|
+
export function modelResult(state, types) {
|
|
3
9
|
return state.status === 'unavailable'
|
|
4
10
|
? { ...state, types: null }
|
|
5
11
|
: {
|
|
@@ -9,7 +15,7 @@ export function modelTypes(state) {
|
|
|
9
15
|
verifiedWith: { ...state.verifiedWith },
|
|
10
16
|
schema: state.snapshot.schema,
|
|
11
17
|
revision: state.snapshot.revision,
|
|
12
|
-
types:
|
|
18
|
+
types: types(state.types),
|
|
13
19
|
};
|
|
14
20
|
}
|
|
15
21
|
export function storedModel(state) {
|
package/dist/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAOnE,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAGvD,OAAO,KAAK,EAAE,OA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aAAa,EACrB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,eAAe,iBAkB7B;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,EAC1C,MAAM,EAAE,SAAS,GAAG,QAAQ,EAC5B,KAAK,EAAE,YAAY,iBAkDpB;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBvF"}
|
package/dist/models.js
CHANGED
|
@@ -35,7 +35,7 @@ function recordAlone(store, record) {
|
|
|
35
35
|
}
|
|
36
36
|
function unheld(runtime, locator, model) {
|
|
37
37
|
runtime.presence.modelled(locator, model);
|
|
38
|
-
emitRooms(runtime);
|
|
38
|
+
emitRooms(runtime, [locator]);
|
|
39
39
|
}
|
|
40
40
|
function recorded(runtime, locator, declaration, model) {
|
|
41
41
|
const { store, socket } = runtime;
|
|
@@ -94,7 +94,7 @@ export async function scoped(runtime, result, locator, declaration) {
|
|
|
94
94
|
await retainModel(runtime, locator, declaration, { status: 'unavailable', reason: 'not-readable' }, true);
|
|
95
95
|
if (!socket.continuing())
|
|
96
96
|
return;
|
|
97
|
-
emitRooms(runtime);
|
|
97
|
+
emitRooms(runtime, [locator]);
|
|
98
98
|
}
|
|
99
99
|
export async function settleModels(runtime, held, status, local) {
|
|
100
100
|
const { store, socket, presence } = runtime;
|
|
@@ -129,7 +129,7 @@ export async function settleModels(runtime, held, status, local) {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
if (unchanged.length > 0)
|
|
132
|
-
emitRooms(runtime);
|
|
132
|
+
emitRooms(runtime, unchanged.map(([locator]) => locator));
|
|
133
133
|
const kept = new Set(unchanged.map(([locator]) => locator));
|
|
134
134
|
return [...held].filter(([locator]) => !kept.has(locator) &&
|
|
135
135
|
owed(stored.get(locator)?.record.model ?? unheldModelOf(runtime, locator)));
|
package/dist/name.d.ts
CHANGED
package/dist/name.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../src/name.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../src/name.ts"],"names":[],"mappings":"AA+GA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK9C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D"}
|
package/dist/name.js
CHANGED
|
@@ -97,22 +97,18 @@ function lowerLetterOf(character) {
|
|
|
97
97
|
function codePoint(character) {
|
|
98
98
|
return WORDLIKE.test(character) ? `-u${character.codePointAt(0)?.toString(16) ?? ''}-` : '-';
|
|
99
99
|
}
|
|
100
|
-
function latin(text
|
|
100
|
+
function latin(text) {
|
|
101
101
|
return [...text]
|
|
102
102
|
.map((character) => {
|
|
103
103
|
if ((character.codePointAt(0) ?? 0) < 0x80)
|
|
104
104
|
return character;
|
|
105
105
|
const lower = character.toLowerCase();
|
|
106
|
-
|
|
107
|
-
return lower === character ? letter : `${letter.charAt(0).toUpperCase()}${letter.slice(1)}`;
|
|
106
|
+
return lowerLetterOf(lower) ?? codePoint(lower);
|
|
108
107
|
})
|
|
109
108
|
.join('');
|
|
110
109
|
}
|
|
111
|
-
export function transliterated(text) {
|
|
112
|
-
return latin(text, () => '-');
|
|
113
|
-
}
|
|
114
110
|
export function nameFrom(title) {
|
|
115
|
-
return latin(title
|
|
111
|
+
return latin(title)
|
|
116
112
|
.toLowerCase()
|
|
117
113
|
.replace(/[^a-z0-9]+/g, '-')
|
|
118
114
|
.replace(/^-+|-+$/g, '');
|
package/dist/observation.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { QueryCoverage, QueryDocument, QueryGroup, QueryResult } from './query.js';
|
|
1
|
+
import type { PendingRoom, QueryCoverage, QueryDocument, QueryGroup, QueryResult } from './query.js';
|
|
2
|
+
import type { ReadinessShown, RoomCoverage } from './readiness.js';
|
|
3
|
+
import type { AppRoom, ListedRooms } from './listing.js';
|
|
2
4
|
export type Observation<T> = {
|
|
3
5
|
current(): T;
|
|
4
6
|
subscribe(listener: (value: T) => void): () => void;
|
|
@@ -9,15 +11,24 @@ export type KeyedResult = {
|
|
|
9
11
|
result: QueryResult;
|
|
10
12
|
keys: readonly RowKey[];
|
|
11
13
|
};
|
|
12
|
-
export type
|
|
13
|
-
changed: readonly (readonly [
|
|
14
|
-
removed: readonly
|
|
15
|
-
order: readonly
|
|
14
|
+
export type KeyedChange<K, T> = {
|
|
15
|
+
readonly changed: readonly (readonly [K, T])[];
|
|
16
|
+
readonly removed: readonly K[];
|
|
17
|
+
readonly order: readonly K[] | null;
|
|
18
|
+
};
|
|
19
|
+
export type QueryChange = KeyedChange<RowKey, QueryDocument | QueryGroup> & {
|
|
16
20
|
coverage?: QueryCoverage;
|
|
17
21
|
next?: string | null;
|
|
18
22
|
total?: number;
|
|
19
23
|
};
|
|
20
|
-
export type
|
|
24
|
+
export type ReadinessChange = {
|
|
25
|
+
readonly shown: ReadinessShown;
|
|
26
|
+
readonly rooms: KeyedChange<string, RoomCoverage>;
|
|
27
|
+
};
|
|
28
|
+
export type PendingChange = {
|
|
29
|
+
readonly pending: KeyedChange<string, PendingRoom>;
|
|
30
|
+
};
|
|
31
|
+
export type QueryMessage = KeyedResult | QueryChange | PendingChange;
|
|
21
32
|
export type Observed = {
|
|
22
33
|
observation: Observation<unknown>;
|
|
23
34
|
receive(message: unknown): void;
|
|
@@ -25,16 +36,21 @@ export type Observed = {
|
|
|
25
36
|
};
|
|
26
37
|
export declare function rowsOf(result: QueryResult): readonly (QueryDocument | QueryGroup)[];
|
|
27
38
|
export declare function whole(message: QueryMessage): message is KeyedResult;
|
|
39
|
+
export declare function pendingChange(message: QueryMessage): message is PendingChange;
|
|
40
|
+
export declare function unchanged(change: KeyedChange<unknown, unknown>): boolean;
|
|
41
|
+
export declare function keyedChange<K, H, T>(held: ReadonlyMap<K, H>, keys: readonly K[], rows: readonly T[], same: (was: H, now: T) => boolean): KeyedChange<K, T>;
|
|
42
|
+
export declare function keyedAt<K, H, T>(held: ReadonlyMap<K, H>, at: ReadonlyMap<K, T | null>, same: (was: H, now: T) => boolean): KeyedChange<K, T> | null;
|
|
43
|
+
export declare function keyedInto<K, T>(held: Map<K, T>, change: KeyedChange<K, T>): void;
|
|
44
|
+
export declare function samePending(was: PendingRoom, now: PendingRoom): boolean;
|
|
45
|
+
export declare function appRooms({ rooms, models }: ListedRooms): readonly AppRoom[];
|
|
28
46
|
export declare function replaces(topic: string, message: unknown): boolean;
|
|
29
|
-
export declare function applied(keyed: KeyedResult, message: QueryMessage): KeyedResult;
|
|
30
47
|
export declare function observed(first: unknown, stop: () => void, topic: string): Observed;
|
|
31
48
|
export declare function opened(watch: (deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void, topic: string): Promise<Observation<unknown>>;
|
|
32
49
|
export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
|
|
33
50
|
export type Digest = {
|
|
34
|
-
readonly pending: string
|
|
51
|
+
readonly pending: Map<string, PendingRoom>;
|
|
35
52
|
} | {
|
|
36
|
-
readonly
|
|
37
|
-
readonly rows: ReadonlyMap<RowKey, number>;
|
|
53
|
+
readonly rows: Map<RowKey, number>;
|
|
38
54
|
readonly coverage: string;
|
|
39
55
|
readonly next: string | undefined;
|
|
40
56
|
readonly total: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAA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AAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAa1E;AAED,MAAM,MAAM,MAAM,GACd;IAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;CAAE,GAC9C;IACE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC,CAAC;AAEN,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAa3C;AAMD,wBAAgB,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,WAAW,GAAG,MAAM,CAU9D;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CAkB3E;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,YAAY,GAAG,IAAI,CAsBjF"}
|
package/dist/observation.js
CHANGED
|
@@ -6,55 +6,198 @@ export function rowsOf(result) {
|
|
|
6
6
|
export function whole(message) {
|
|
7
7
|
return 'result' in message;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
return
|
|
9
|
+
export function pendingChange(message) {
|
|
10
|
+
return 'pending' in message;
|
|
11
11
|
}
|
|
12
|
-
export function
|
|
13
|
-
return
|
|
12
|
+
export function unchanged(change) {
|
|
13
|
+
return change.changed.length === 0 && change.removed.length === 0 && change.order === null;
|
|
14
14
|
}
|
|
15
|
-
export function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
for (const key of
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
export function keyedChange(held, keys, rows, same) {
|
|
16
|
+
const present = new Set(keys);
|
|
17
|
+
const changed = keys.flatMap((key, at) => {
|
|
18
|
+
const was = held.get(key);
|
|
19
|
+
return was !== undefined && same(was, rows[at]) ? [] : [[key, rows[at]]];
|
|
20
|
+
});
|
|
21
|
+
const removed = [];
|
|
22
|
+
const kept = [];
|
|
23
|
+
for (const key of held.keys())
|
|
24
|
+
(present.has(key) ? kept : removed).push(key);
|
|
25
|
+
const moved = kept.length !== keys.length || kept.some((key, at) => keys[at] !== key);
|
|
26
|
+
return { changed, removed, order: moved ? keys : null };
|
|
27
|
+
}
|
|
28
|
+
export function keyedAt(held, at, same) {
|
|
29
|
+
const changed = [];
|
|
30
|
+
const removed = [];
|
|
31
|
+
for (const [key, now] of at) {
|
|
32
|
+
const was = held.get(key);
|
|
33
|
+
if (was === undefined) {
|
|
34
|
+
if (now !== null)
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
else if (now === null)
|
|
38
|
+
removed.push(key);
|
|
39
|
+
else if (!same(was, now))
|
|
40
|
+
changed.push([key, now]);
|
|
41
|
+
}
|
|
42
|
+
return { changed, removed, order: null };
|
|
43
|
+
}
|
|
44
|
+
export function keyedInto(held, change) {
|
|
45
|
+
for (const key of change.removed)
|
|
46
|
+
held.delete(key);
|
|
47
|
+
for (const [key, row] of change.changed)
|
|
48
|
+
held.set(key, row);
|
|
49
|
+
if (change.order === null)
|
|
50
|
+
return;
|
|
51
|
+
const placed = change.order.map((key) => [key, held.get(key)]);
|
|
52
|
+
held.clear();
|
|
53
|
+
for (const [key, row] of placed)
|
|
54
|
+
held.set(key, row);
|
|
55
|
+
}
|
|
56
|
+
export function samePending(was, now) {
|
|
57
|
+
return was.awaits === now.awaits;
|
|
58
|
+
}
|
|
59
|
+
function keyedRows(keys, rows) {
|
|
60
|
+
const held = new Map(keys.map((key, at) => [key, rows[at]]));
|
|
61
|
+
let shown = rows;
|
|
62
|
+
return {
|
|
63
|
+
rows: () => shown,
|
|
64
|
+
apply(change) {
|
|
65
|
+
if (unchanged(change))
|
|
66
|
+
return shown;
|
|
67
|
+
keyedInto(held, change);
|
|
68
|
+
shown = [...held.values()];
|
|
69
|
+
return shown;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function heldModels(held, sent) {
|
|
74
|
+
return new Map(Object.entries(sent).map(([key, types]) => [key, held.get(key) ?? types]));
|
|
75
|
+
}
|
|
76
|
+
function namedModels(models, rooms) {
|
|
77
|
+
const named = new Set(rooms.flatMap(({ model, typedSelection }) => [model.types, typedSelection?.model.types]));
|
|
78
|
+
return new Map([...models].filter(([, types]) => named.has(types)));
|
|
79
|
+
}
|
|
80
|
+
function typed(model, models) {
|
|
81
|
+
return model.types === null ? model : { ...model, types: models.get(model.types) };
|
|
82
|
+
}
|
|
83
|
+
function appRoom({ model, typedSelection, ...room }, models) {
|
|
84
|
+
return {
|
|
85
|
+
...room,
|
|
86
|
+
model: typed(model, models),
|
|
87
|
+
typedSelection: typedSelection === null
|
|
88
|
+
? null
|
|
89
|
+
: { roots: typedSelection.roots, model: typed(typedSelection.model, models) },
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function appRooms({ rooms, models }) {
|
|
93
|
+
const held = heldModels(new Map(), models);
|
|
94
|
+
return rooms.map((room) => appRoom(room, held));
|
|
95
|
+
}
|
|
96
|
+
function keyedRooms(first) {
|
|
97
|
+
let models = new Map();
|
|
98
|
+
let held = keyedRows([], []);
|
|
99
|
+
const whole = (listed) => {
|
|
100
|
+
models = heldModels(models, listed.models);
|
|
101
|
+
held = keyedRows(listed.rooms.map(({ locator }) => locator), listed.rooms.map((room) => appRoom(room, models)));
|
|
102
|
+
return held.rows();
|
|
35
103
|
};
|
|
36
104
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
105
|
+
value: whole(first),
|
|
106
|
+
next(message) {
|
|
107
|
+
if ('rooms' in message)
|
|
108
|
+
return whole(message);
|
|
109
|
+
const change = message;
|
|
110
|
+
const sent = heldModels(models, change.models);
|
|
111
|
+
const rows = held.apply({
|
|
112
|
+
changed: change.changed.map(([locator, room]) => [locator, appRoom(room, sent)]),
|
|
113
|
+
removed: change.removed,
|
|
114
|
+
order: change.order,
|
|
115
|
+
});
|
|
116
|
+
models = namedModels(new Map([...models, ...sent]), rows);
|
|
117
|
+
return rows;
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function covered(readiness) {
|
|
122
|
+
return keyedRows(readiness.coverage.rooms.map(({ room }) => room), readiness.coverage.rooms);
|
|
123
|
+
}
|
|
124
|
+
function keyedReadiness(first) {
|
|
125
|
+
let held = covered(first);
|
|
126
|
+
return {
|
|
127
|
+
value: first,
|
|
128
|
+
next(message) {
|
|
129
|
+
if (!('shown' in message)) {
|
|
130
|
+
held = covered(message);
|
|
131
|
+
return message;
|
|
132
|
+
}
|
|
133
|
+
const { shown, rooms } = message;
|
|
134
|
+
return { ...shown, coverage: { ...shown.coverage, rooms: held.apply(rooms) } };
|
|
135
|
+
},
|
|
41
136
|
};
|
|
42
137
|
}
|
|
138
|
+
function awaiting(pending) {
|
|
139
|
+
return keyedRows(pending.map(({ room }) => room), pending);
|
|
140
|
+
}
|
|
43
141
|
function keyedResult(first) {
|
|
44
|
-
let
|
|
142
|
+
let result = first.result;
|
|
143
|
+
let rows = keyedRows([], []);
|
|
144
|
+
let pending = awaiting([]);
|
|
145
|
+
const take = ({ result: next, keys }) => {
|
|
146
|
+
result = next;
|
|
147
|
+
if ('pending' in next)
|
|
148
|
+
pending = awaiting(next.pending);
|
|
149
|
+
else
|
|
150
|
+
rows = keyedRows(keys, rowsOf(next));
|
|
151
|
+
return result;
|
|
152
|
+
};
|
|
153
|
+
take(first);
|
|
45
154
|
return {
|
|
46
155
|
value: first.result,
|
|
47
156
|
next(message) {
|
|
48
|
-
|
|
49
|
-
|
|
157
|
+
const asked = message;
|
|
158
|
+
if (whole(asked))
|
|
159
|
+
return take(asked);
|
|
160
|
+
if (pendingChange(asked)) {
|
|
161
|
+
if ('pending' in result)
|
|
162
|
+
result = { pending: pending.apply(asked.pending) };
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
if ('pending' in result)
|
|
166
|
+
return result;
|
|
167
|
+
const kept = rows.apply(asked);
|
|
168
|
+
const coverage = asked.coverage ?? result.coverage;
|
|
169
|
+
const next = asked.next === undefined ? result.next : (asked.next ?? undefined);
|
|
170
|
+
const total = asked.total ?? result.total;
|
|
171
|
+
const window = {
|
|
172
|
+
...(next === undefined ? {} : { next }),
|
|
173
|
+
...(total === undefined ? {} : { total }),
|
|
174
|
+
};
|
|
175
|
+
result =
|
|
176
|
+
'groups' in result
|
|
177
|
+
? { groups: kept, coverage, ...window }
|
|
178
|
+
: { documents: kept, coverage, ...window };
|
|
179
|
+
return result;
|
|
50
180
|
},
|
|
51
181
|
};
|
|
52
182
|
}
|
|
183
|
+
const FOLDS = {
|
|
184
|
+
query: (first) => keyedResult(first),
|
|
185
|
+
rooms: (first) => keyedRooms(first),
|
|
186
|
+
readiness: (first) => keyedReadiness(first),
|
|
187
|
+
};
|
|
188
|
+
const WHOLE = {
|
|
189
|
+
query: (message) => whole(message),
|
|
190
|
+
rooms: (message) => 'rooms' in message,
|
|
191
|
+
readiness: (message) => !('shown' in message),
|
|
192
|
+
};
|
|
193
|
+
export function replaces(topic, message) {
|
|
194
|
+
return WHOLE[topic]?.(message) ?? true;
|
|
195
|
+
}
|
|
53
196
|
function replaced(first) {
|
|
54
197
|
return { value: first, next: (message) => message };
|
|
55
198
|
}
|
|
56
199
|
export function observed(first, stop, topic) {
|
|
57
|
-
const reducer =
|
|
200
|
+
const reducer = (FOLDS[topic] ?? replaced)(first);
|
|
58
201
|
let value = reducer.value;
|
|
59
202
|
let open = true;
|
|
60
203
|
const listeners = new Set();
|
|
@@ -135,10 +278,9 @@ function rowDigest(row) {
|
|
|
135
278
|
}
|
|
136
279
|
export function digestOf({ result, keys }) {
|
|
137
280
|
if ('pending' in result)
|
|
138
|
-
return { pending:
|
|
281
|
+
return { pending: new Map(result.pending.map((room) => [room.room, room])) };
|
|
139
282
|
const rows = rowsOf(result);
|
|
140
283
|
return {
|
|
141
|
-
keys,
|
|
142
284
|
rows: new Map(keys.map((key, index) => [key, rowDigest(rows[index])])),
|
|
143
285
|
coverage: JSON.stringify(result.coverage),
|
|
144
286
|
next: result.next,
|
|
@@ -146,16 +288,22 @@ export function digestOf({ result, keys }) {
|
|
|
146
288
|
};
|
|
147
289
|
}
|
|
148
290
|
export function digestApplied(digest, message) {
|
|
149
|
-
if (whole(message)
|
|
150
|
-
return
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
291
|
+
if (whole(message))
|
|
292
|
+
return digestOf(message);
|
|
293
|
+
if (pendingChange(message)) {
|
|
294
|
+
if ('pending' in digest)
|
|
295
|
+
keyedInto(digest.pending, message.pending);
|
|
296
|
+
return digest;
|
|
297
|
+
}
|
|
298
|
+
if ('pending' in digest)
|
|
299
|
+
return digest;
|
|
300
|
+
keyedInto(digest.rows, {
|
|
301
|
+
changed: message.changed.map(([key, row]) => [key, rowDigest(row)]),
|
|
302
|
+
removed: message.removed,
|
|
303
|
+
order: message.order,
|
|
304
|
+
});
|
|
156
305
|
return {
|
|
157
|
-
|
|
158
|
-
rows,
|
|
306
|
+
rows: digest.rows,
|
|
159
307
|
coverage: message.coverage === undefined ? digest.coverage : JSON.stringify(message.coverage),
|
|
160
308
|
next: message.next === undefined ? digest.next : (message.next ?? undefined),
|
|
161
309
|
total: message.total ?? digest.total,
|
|
@@ -163,35 +311,18 @@ export function digestApplied(digest, message) {
|
|
|
163
311
|
}
|
|
164
312
|
export function changeOf(previous, next) {
|
|
165
313
|
const after = next.result;
|
|
166
|
-
if ('pending' in previous
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
: next;
|
|
314
|
+
if ('pending' in previous && 'pending' in after) {
|
|
315
|
+
const pending = keyedChange(previous.pending, after.pending.map(({ room }) => room), after.pending, samePending);
|
|
316
|
+
return unchanged(pending) ? null : { pending };
|
|
170
317
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
const row = later[index];
|
|
176
|
-
if (previous.rows.get(key) !== rowDigest(row))
|
|
177
|
-
changed.push([key, row]);
|
|
178
|
-
});
|
|
179
|
-
const removed = previous.keys.filter((key) => !present.has(key));
|
|
180
|
-
const kept = previous.keys.filter((key) => present.has(key));
|
|
181
|
-
const moved = kept.length !== next.keys.length || kept.some((key, index) => next.keys[index] !== key);
|
|
182
|
-
const coverage = JSON.stringify(after.coverage);
|
|
183
|
-
const covered = previous.coverage !== coverage;
|
|
318
|
+
if ('pending' in previous || 'pending' in after)
|
|
319
|
+
return next;
|
|
320
|
+
const rows = keyedChange(previous.rows, next.keys, rowsOf(after), (was, row) => was === rowDigest(row));
|
|
321
|
+
const covered = previous.coverage !== JSON.stringify(after.coverage);
|
|
184
322
|
const framing = reframed(previous, after);
|
|
185
|
-
if (
|
|
323
|
+
if (unchanged(rows) && !covered && framing === null)
|
|
186
324
|
return null;
|
|
187
|
-
}
|
|
188
|
-
return {
|
|
189
|
-
changed,
|
|
190
|
-
removed,
|
|
191
|
-
order: moved ? next.keys : null,
|
|
192
|
-
...(covered ? { coverage: after.coverage } : {}),
|
|
193
|
-
...framing,
|
|
194
|
-
};
|
|
325
|
+
return { ...rows, ...(covered ? { coverage: after.coverage } : {}), ...framing };
|
|
195
326
|
}
|
|
196
327
|
function reframed(before, after) {
|
|
197
328
|
const next = before.next === after.next ? {} : { next: after.next ?? null };
|
package/dist/online.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Authorization } from './adapter.js';
|
|
2
|
+
import type { Runtime } from './runtime.js';
|
|
3
|
+
export declare function offline(runtime: Runtime): Promise<boolean>;
|
|
4
|
+
export declare function askedOnline<T extends {
|
|
5
|
+
readonly kind: string;
|
|
6
|
+
}>(runtime: Runtime, ask: (authorization: Authorization) => Promise<T>): Promise<T | null>;
|
|
7
|
+
//# sourceMappingURL=online.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"online.d.ts","sourceRoot":"","sources":["../src/online.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,wBAAsB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAOhE;AAED,wBAAsB,WAAW,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EACnE,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,CAAC,aAAa,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,GAChD,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAgBnB"}
|
package/dist/online.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { connectionNow } from './preparation.js';
|
|
2
|
+
import { refuse } from './refusal.js';
|
|
3
|
+
export async function offline(runtime) {
|
|
4
|
+
const { socket } = runtime;
|
|
5
|
+
return (socket.closed() ||
|
|
6
|
+
socket.session.now().refusal !== null ||
|
|
7
|
+
(await connectionNow(runtime)) !== 'connected');
|
|
8
|
+
}
|
|
9
|
+
export async function askedOnline(runtime, ask) {
|
|
10
|
+
const { socket } = runtime;
|
|
11
|
+
try {
|
|
12
|
+
await socket.authorize();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const { closed, authorization, refusal } = socket.session.now();
|
|
18
|
+
if (closed || authorization === undefined || refusal !== null)
|
|
19
|
+
return null;
|
|
20
|
+
try {
|
|
21
|
+
const answer = await ask(authorization);
|
|
22
|
+
if (answer.kind === 'revoked-authorization')
|
|
23
|
+
await refuse(runtime, 'revoked-authorization');
|
|
24
|
+
return answer;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|