@agentshouse/mdruntime 0.1.0-cd26b960b7262 → 0.1.0-cd35ccee27a19

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.
Files changed (153) hide show
  1. package/dist/acceptance.d.ts +0 -3
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +58 -135
  4. package/dist/actions.js +5 -5
  5. package/dist/adapter.d.ts +26 -45
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/bootstrap.d.ts +1 -1
  8. package/dist/bootstrap.d.ts.map +1 -1
  9. package/dist/bootstrap.js +6 -19
  10. package/dist/change-set.d.ts +4 -0
  11. package/dist/change-set.d.ts.map +1 -1
  12. package/dist/change-set.js +6 -0
  13. package/dist/client.d.ts +4 -11
  14. package/dist/client.d.ts.map +1 -1
  15. package/dist/client.js +21 -8
  16. package/dist/collection.d.ts +22 -4
  17. package/dist/collection.d.ts.map +1 -1
  18. package/dist/collection.js +12 -2
  19. package/dist/connection.d.ts.map +1 -1
  20. package/dist/connection.js +17 -13
  21. package/dist/conversation-live.d.ts +5 -5
  22. package/dist/conversation-live.d.ts.map +1 -1
  23. package/dist/conversation-live.js +7 -6
  24. package/dist/conversation.d.ts +18 -6
  25. package/dist/conversation.d.ts.map +1 -1
  26. package/dist/conversation.js +115 -82
  27. package/dist/declaration.d.ts +10 -0
  28. package/dist/declaration.d.ts.map +1 -0
  29. package/dist/declaration.js +24 -0
  30. package/dist/discovery.d.ts.map +1 -1
  31. package/dist/discovery.js +11 -38
  32. package/dist/failure.d.ts +1 -0
  33. package/dist/failure.d.ts.map +1 -1
  34. package/dist/failure.js +3 -0
  35. package/dist/host.d.ts +17 -2
  36. package/dist/host.d.ts.map +1 -1
  37. package/dist/host.js +34 -4
  38. package/dist/index.d.ts +6 -4
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +4 -2
  41. package/dist/install.d.ts +0 -2
  42. package/dist/install.d.ts.map +1 -1
  43. package/dist/install.js +47 -63
  44. package/dist/lifecycle.d.ts +1 -1
  45. package/dist/lifecycle.d.ts.map +1 -1
  46. package/dist/lifecycle.js +28 -24
  47. package/dist/listing.d.ts +6 -11
  48. package/dist/listing.d.ts.map +1 -1
  49. package/dist/listing.js +25 -62
  50. package/dist/live.d.ts.map +1 -1
  51. package/dist/live.js +3 -1
  52. package/dist/locks.d.ts +2 -4
  53. package/dist/locks.d.ts.map +1 -1
  54. package/dist/locks.js +10 -38
  55. package/dist/lost.d.ts.map +1 -1
  56. package/dist/lost.js +10 -21
  57. package/dist/memory.d.ts +4 -2
  58. package/dist/memory.d.ts.map +1 -1
  59. package/dist/memory.js +22 -9
  60. package/dist/messages.d.ts +0 -3
  61. package/dist/messages.d.ts.map +1 -1
  62. package/dist/messages.js +5 -17
  63. package/dist/model.d.ts +0 -1
  64. package/dist/model.d.ts.map +1 -1
  65. package/dist/model.js +0 -5
  66. package/dist/models.d.ts +4 -8
  67. package/dist/models.d.ts.map +1 -1
  68. package/dist/models.js +97 -136
  69. package/dist/opened.d.ts +1 -1
  70. package/dist/opened.d.ts.map +1 -1
  71. package/dist/opened.js +2 -2
  72. package/dist/opening.d.ts.map +1 -1
  73. package/dist/opening.js +6 -4
  74. package/dist/overlay.d.ts +2 -1
  75. package/dist/overlay.d.ts.map +1 -1
  76. package/dist/overlay.js +32 -21
  77. package/dist/page-metadata.d.ts +8 -0
  78. package/dist/page-metadata.d.ts.map +1 -0
  79. package/dist/page-metadata.js +19 -0
  80. package/dist/parts.d.ts +3 -52
  81. package/dist/parts.d.ts.map +1 -1
  82. package/dist/parts.js +15 -120
  83. package/dist/preparation.d.ts.map +1 -1
  84. package/dist/preparation.js +20 -13
  85. package/dist/presence.d.ts +52 -0
  86. package/dist/presence.d.ts.map +1 -0
  87. package/dist/presence.js +220 -0
  88. package/dist/queries.d.ts.map +1 -1
  89. package/dist/queries.js +4 -6
  90. package/dist/queue.d.ts +40 -0
  91. package/dist/queue.d.ts.map +1 -0
  92. package/dist/queue.js +455 -0
  93. package/dist/reach.d.ts.map +1 -1
  94. package/dist/reach.js +23 -4
  95. package/dist/reads.d.ts.map +1 -1
  96. package/dist/reads.js +4 -1
  97. package/dist/refresh.js +2 -2
  98. package/dist/refusal.d.ts.map +1 -1
  99. package/dist/refusal.js +5 -3
  100. package/dist/replica.d.ts +5 -11
  101. package/dist/replica.d.ts.map +1 -1
  102. package/dist/replica.js +12 -14
  103. package/dist/room-draft.d.ts +3 -3
  104. package/dist/room-draft.d.ts.map +1 -1
  105. package/dist/room-draft.js +33 -49
  106. package/dist/room-drafts.js +3 -3
  107. package/dist/rows.d.ts.map +1 -1
  108. package/dist/rows.js +3 -4
  109. package/dist/runtime.d.ts +7 -16
  110. package/dist/runtime.d.ts.map +1 -1
  111. package/dist/save.d.ts +41 -90
  112. package/dist/save.d.ts.map +1 -1
  113. package/dist/save.js +220 -110
  114. package/dist/saves.d.ts +2 -40
  115. package/dist/saves.d.ts.map +1 -1
  116. package/dist/saves.js +106 -698
  117. package/dist/seed.js +2 -2
  118. package/dist/shown.d.ts +4 -3
  119. package/dist/shown.d.ts.map +1 -1
  120. package/dist/shown.js +24 -26
  121. package/dist/socket.d.ts +0 -3
  122. package/dist/socket.d.ts.map +1 -1
  123. package/dist/socket.js +0 -5
  124. package/dist/store/records.d.ts +2 -2
  125. package/dist/store/records.d.ts.map +1 -1
  126. package/dist/store/records.js +2 -3
  127. package/dist/store.d.ts +8 -5
  128. package/dist/store.d.ts.map +1 -1
  129. package/dist/store.js +32 -12
  130. package/dist/stored.d.ts.map +1 -1
  131. package/dist/stored.js +3 -3
  132. package/dist/surface.d.ts.map +1 -1
  133. package/dist/surface.js +8 -8
  134. package/dist/sync.d.ts.map +1 -1
  135. package/dist/sync.js +55 -66
  136. package/dist/tables.d.ts +0 -4
  137. package/dist/tables.d.ts.map +1 -1
  138. package/dist/tables.js +1 -4
  139. package/dist/validation.d.ts.map +1 -1
  140. package/dist/validation.js +2 -2
  141. package/dist/wire.d.ts +40 -4
  142. package/dist/wire.d.ts.map +1 -1
  143. package/dist/wire.js +12 -3
  144. package/package.json +3 -2
  145. package/dist/job.d.ts +0 -33
  146. package/dist/job.d.ts.map +0 -1
  147. package/dist/job.js +0 -54
  148. package/dist/socket/rooms.d.ts +0 -44
  149. package/dist/socket/rooms.d.ts.map +0 -1
  150. package/dist/socket/rooms.js +0 -90
  151. package/dist/store/fences.d.ts +0 -16
  152. package/dist/store/fences.d.ts.map +0 -1
  153. package/dist/store/fences.js +0 -26
package/dist/wire.js CHANGED
@@ -13,7 +13,7 @@ const MEMBERS = {
13
13
  'binaryFile.show': { reach: 'within', effect: 'read' },
14
14
  'binaryFile.attach': { reach: 'within', effect: 'action' },
15
15
  'binaryFile.part': { reach: 'within', effect: 'read' },
16
- call: { reach: 'actions', effect: 'action' },
16
+ call: { reach: 'within', effect: 'action' },
17
17
  reached: { reach: 'within', effect: 'read' },
18
18
  log: { reach: 'whole', effect: 'read' },
19
19
  cleanUp: { reach: 'whole', effect: 'write' },
@@ -38,6 +38,15 @@ const MEMBERS = {
38
38
  'conversation.interrupt': { reach: 'within', effect: 'action' },
39
39
  'conversation.kill': { reach: 'within', effect: 'action' },
40
40
  'conversation.delete': { reach: 'within', effect: 'action' },
41
+ 'conversation.takeOut': { reach: 'within', effect: 'action' },
42
+ 'conversation.decide': { reach: 'within', effect: 'action' },
43
+ 'conversation.rename': { reach: 'within', effect: 'action' },
44
+ 'conversation.option': { reach: 'within', effect: 'action' },
45
+ 'conversation.retry': { reach: 'within', effect: 'action' },
46
+ 'conversation.pins': { reach: 'within', effect: 'read' },
47
+ 'conversation.pin': { reach: 'within', effect: 'write' },
48
+ 'conversation.openedTurns': { reach: 'within', effect: 'read' },
49
+ 'conversation.openTurn': { reach: 'within', effect: 'write' },
41
50
  'chatDraft.write': { reach: 'within', effect: 'write' },
42
51
  'chatDraft.prepend': { reach: 'within', effect: 'write' },
43
52
  'chatDraft.discard': { reach: 'within', effect: 'write' },
@@ -86,7 +95,7 @@ function body(message) {
86
95
  const record = message;
87
96
  return { kind: record.kind, id: record.id };
88
97
  }
89
- export function request(message) {
98
+ export function wireRequest(message) {
90
99
  const shape = body(message);
91
100
  if (shape === null)
92
101
  return null;
@@ -121,7 +130,7 @@ export function request(message) {
121
130
  }
122
131
  return null;
123
132
  }
124
- export function answer(message) {
133
+ export function wireAnswer(message) {
125
134
  const shape = body(message);
126
135
  if (shape === null)
127
136
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime",
3
- "version": "0.1.0-cd26b960b7262",
3
+ "version": "0.1.0-cd35ccee27a19",
4
4
  "description": "The headless core of MD App",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -54,7 +54,8 @@
54
54
  "LICENSE"
55
55
  ],
56
56
  "dependencies": {
57
- "@agentshouse/mdmodel": "0.1.0-c3c0e116a89f8"
57
+ "@agentshouse/mdmodel": "0.1.0-c16854483af62",
58
+ "@agentshouse/session-content": "0.1.0-cad437697294e"
58
59
  },
59
60
  "peerDependencies": {
60
61
  "react": ">=18"
package/dist/job.d.ts DELETED
@@ -1,33 +0,0 @@
1
- type Job = {
2
- readonly label: string;
3
- readonly kind: 'started' | 'scheduled' | 'ended';
4
- readonly state: string;
5
- readonly next: string | null;
6
- };
7
- export type RunningJob = {
8
- readonly name: string;
9
- readonly running_since: string;
10
- };
11
- export type JobMarker = {
12
- readonly said: string;
13
- readonly at: string;
14
- };
15
- export type OpenJob<At = string | null> = {
16
- readonly name: string;
17
- readonly started: At;
18
- };
19
- export declare function jobOf(said: string): Job;
20
- export declare function closeLast(open: {
21
- readonly key: string;
22
- }[], key: string): void;
23
- export declare function markerMoved<Kept extends {
24
- readonly key: string;
25
- }>(open: Kept[], said: string, opened: (job: Job, key: string) => Kept | null): void;
26
- export declare function openJobs<At>(markers: readonly {
27
- readonly said: string;
28
- readonly at: At;
29
- }[]): readonly OpenJob<At>[];
30
- export declare function jobsRunning(jobs: readonly RunningJob[], now: number): string[];
31
- export declare function sessionEnded(jobs: readonly RunningJob[], now: number): string;
32
- export {};
33
- //# sourceMappingURL=job.d.ts.map
package/dist/job.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AAAA,KAAK,GAAG,GAAG;IACT,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvE,MAAM,MAAM,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,IAAI,IAAI;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAA;CAAE,CAAC;AAQ1F,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CASvC;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAG7E;AAED,wBAAgB,WAAW,CAAC,IAAI,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAC/D,IAAI,EAAE,IAAI,EAAE,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,GAC7C,IAAI,CASN;AAED,wBAAgB,QAAQ,CAAC,EAAE,EACzB,OAAO,EAAE,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAA;CAAE,EAAE,GAC7D,SAAS,OAAO,CAAC,EAAE,CAAC,EAAE,CAQxB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAM9E;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAI7E"}
package/dist/job.js DELETED
@@ -1,54 +0,0 @@
1
- const NEXT_RUN = 'next run ';
2
- const MINUTE = 60_000;
3
- const ENDED = 'Session ended.';
4
- export function jobOf(said) {
5
- const at = said.lastIndexOf(': ');
6
- const label = at === -1 ? said : said.slice(0, at);
7
- const state = at === -1 ? '' : said.slice(at + 2);
8
- if (state === 'running')
9
- return { label, kind: 'started', state, next: null };
10
- if (state === 'scheduled')
11
- return { label, kind: 'scheduled', state, next: null };
12
- return state.startsWith(NEXT_RUN)
13
- ? { label, kind: 'scheduled', state, next: state.slice(NEXT_RUN.length) }
14
- : { label, kind: 'ended', state, next: null };
15
- }
16
- export function closeLast(open, key) {
17
- const at = open.map((one) => one.key).lastIndexOf(key);
18
- if (at !== -1)
19
- open.splice(at, 1);
20
- }
21
- export function markerMoved(open, said, opened) {
22
- const job = jobOf(said);
23
- const started = `job\u0000${job.label}`;
24
- const schedule = `schedule\u0000${job.label}`;
25
- if (job.kind === 'ended')
26
- closeLast(open, started);
27
- if (job.kind !== 'started')
28
- closeLast(open, schedule);
29
- if (job.kind === 'ended')
30
- return;
31
- const kept = opened(job, job.kind === 'started' ? started : schedule);
32
- if (kept !== null)
33
- open.push(kept);
34
- }
35
- export function openJobs(markers) {
36
- const open = [];
37
- for (const { said, at } of markers) {
38
- markerMoved(open, said, (job, key) => job.kind === 'started' ? { key, name: job.label, started: at } : null);
39
- }
40
- return open.map(({ name, started }) => ({ name, started }));
41
- }
42
- export function jobsRunning(jobs, now) {
43
- return jobs.map((job) => {
44
- const since = Date.parse(job.running_since);
45
- const ran = Number.isNaN(since) ? 0 : Math.floor((now - since) / MINUTE);
46
- return ran >= 1 ? `${job.name} (${ran} min)` : job.name;
47
- });
48
- }
49
- export function sessionEnded(jobs, now) {
50
- if (jobs.length === 0)
51
- return ENDED;
52
- const counted = jobs.length === 1 ? '1 background job' : `${jobs.length} background jobs`;
53
- return `${ENDED} ${counted} stopped: ${jobsRunning(jobs, now).join(', ')}`;
54
- }
@@ -1,44 +0,0 @@
1
- import type { DiscoveredRoom, ProviderRefusal, TypedSelection } from '../adapter.js';
2
- import type { ModelState } from '../model.js';
3
- export type RoomDeclaration = Omit<DiscoveredRoom, 'roomVersion' | 'typedSelection'> & {
4
- typedSelection?: TypedSelection | null;
5
- };
6
- export type Declared = {
7
- readonly room: RoomDeclaration | null;
8
- readonly available: boolean;
9
- };
10
- type RoomStanding = {
11
- readonly unreadable: boolean;
12
- readonly refusal: ProviderRefusal | null;
13
- readonly unheldModel: ModelState | null;
14
- readonly stale: boolean;
15
- readonly repairable: {
16
- readonly reset: string | undefined;
17
- } | null;
18
- readonly repairing: boolean;
19
- readonly reloadDue: boolean;
20
- readonly confirmed: boolean;
21
- readonly unpreparable: boolean;
22
- };
23
- export type Rooms = {
24
- declare(locator: string, declared: Declared): void;
25
- declared(locator: string): Declared | undefined;
26
- declarations(): ReadonlyMap<string, Declared>;
27
- discover(room: DiscoveredRoom): void;
28
- discovered(locator: string): DiscoveredRoom | undefined;
29
- discoveredRooms(): readonly DiscoveredRoom[];
30
- undiscoverAll(): void;
31
- standing(locator: string): RoomStanding;
32
- stand(locator: string, change: Partial<RoomStanding>): void;
33
- standingWhere(held: (room: RoomStanding) => boolean): readonly string[];
34
- standAll(change: Partial<RoomStanding>): void;
35
- forget(locator: string): void;
36
- askAgain(locator: string, ask: () => void): void;
37
- readied(locator: string): void;
38
- unreadied(): void;
39
- connectionLost(lapsed: () => void): void;
40
- connectionLive(): void;
41
- };
42
- export declare function createRooms(): Rooms;
43
- export {};
44
- //# sourceMappingURL=rooms.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rooms.d.ts","sourceRoot":"","sources":["../../src/socket/rooms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,cAAc,EAAE,aAAa,GAAG,gBAAgB,CAAC,GAAG;IACrF,cAAc,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9F,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,UAAU,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GAAG,IAAI,CAAC;IACnE,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC,CAAC;AAcF,MAAM,MAAM,KAAK,GAAG;IAClB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IAChD,YAAY,IAAI,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC9C,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IACrC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAAC;IACxD,eAAe,IAAI,SAAS,cAAc,EAAE,CAAC;IAC7C,aAAa,IAAI,IAAI,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAAC;IACxC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;IAC5D,aAAa,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,GAAG,SAAS,MAAM,EAAE,CAAC;IACxE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;IAC9C,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IACjD,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,SAAS,IAAI,IAAI,CAAC;IAClB,cAAc,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IACzC,cAAc,IAAI,IAAI,CAAC;CACxB,CAAC;AAQF,wBAAgB,WAAW,IAAI,KAAK,CAsEnC"}
@@ -1,90 +0,0 @@
1
- const STANDING = {
2
- unreadable: false,
3
- refusal: null,
4
- unheldModel: null,
5
- stale: false,
6
- repairable: null,
7
- repairing: false,
8
- reloadDue: false,
9
- confirmed: false,
10
- unpreparable: false,
11
- };
12
- // A Room the Provider answers not ready is asked again after these waits, the last repeating, so a chunk build that catches up within seconds installs at once and a long one is asked every 15 seconds.
13
- const NOT_READY_MS = [1_000, 2_000, 3_000, 5_000, 8_000, 11_000, 15_000];
14
- // A Room that locks offline stays readable this long after the connection drops, so a laptop waking or changing network keeps working while a disconnected device locks soon after.
15
- const LOCK_GRACE_MS = 120_000;
16
- export function createRooms() {
17
- const declared = new Map();
18
- const discovered = new Map();
19
- const standings = new Map();
20
- const unready = new Map();
21
- let lockGrace = null;
22
- function readied(locator) {
23
- const held = unready.get(locator);
24
- if (held === undefined)
25
- return;
26
- if (held.timer !== null)
27
- clearTimeout(held.timer);
28
- unready.delete(locator);
29
- }
30
- return {
31
- declare(locator, room) {
32
- declared.set(locator, room);
33
- },
34
- declared: (locator) => declared.get(locator),
35
- declarations: () => declared,
36
- discover(room) {
37
- discovered.set(room.locator, room);
38
- },
39
- discovered: (locator) => discovered.get(locator),
40
- discoveredRooms: () => [...discovered.values()],
41
- undiscoverAll() {
42
- discovered.clear();
43
- },
44
- standing: (locator) => standings.get(locator) ?? STANDING,
45
- stand(locator, change) {
46
- standings.set(locator, { ...(standings.get(locator) ?? STANDING), ...change });
47
- },
48
- standingWhere: (held) => [...standings].filter(([, room]) => held(room)).map(([locator]) => locator),
49
- standAll(change) {
50
- for (const [locator, room] of standings)
51
- standings.set(locator, { ...room, ...change });
52
- },
53
- forget(locator) {
54
- declared.delete(locator);
55
- discovered.delete(locator);
56
- const { repairing, reloadDue } = standings.get(locator) ?? STANDING;
57
- standings.set(locator, { ...STANDING, repairing, reloadDue });
58
- },
59
- askAgain(locator, ask) {
60
- const held = unready.get(locator) ?? { tries: 0, timer: null };
61
- unready.set(locator, held);
62
- if (held.timer !== null)
63
- return;
64
- const wait = NOT_READY_MS[Math.min(held.tries, NOT_READY_MS.length - 1)];
65
- held.tries += 1;
66
- held.timer = setTimeout(() => {
67
- held.timer = null;
68
- ask();
69
- }, wait);
70
- },
71
- readied,
72
- unreadied() {
73
- for (const locator of [...unready.keys()])
74
- readied(locator);
75
- },
76
- connectionLost(lapsed) {
77
- if (lockGrace !== null)
78
- return;
79
- lockGrace = setTimeout(() => {
80
- lockGrace = null;
81
- lapsed();
82
- }, LOCK_GRACE_MS);
83
- },
84
- connectionLive() {
85
- if (lockGrace !== null)
86
- clearTimeout(lockGrace);
87
- lockGrace = null;
88
- },
89
- };
90
- }
@@ -1,16 +0,0 @@
1
- type Fence = {
2
- readonly at: number;
3
- readonly written: boolean;
4
- };
5
- export type Fences = {
6
- has(locator: string): boolean;
7
- of(locator: string): Fence | undefined;
8
- raise(locator: string, at: number): boolean;
9
- mark(locator: string, written: boolean): void;
10
- lift(locator: string): void;
11
- count(): number;
12
- since(locator: string, count: number): boolean;
13
- };
14
- export declare function createFences(): Fences;
15
- export {};
16
- //# sourceMappingURL=fences.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fences.d.ts","sourceRoot":"","sources":["../../src/store/fences.ts"],"names":[],"mappings":"AAAA,KAAK,KAAK,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAEhE,MAAM,MAAM,MAAM,GAAG;IACnB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9B,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;IACvC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,IAAI,MAAM,CAAC;IAChB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAChD,CAAC;AAEF,wBAAgB,YAAY,IAAI,MAAM,CAwBrC"}
@@ -1,26 +0,0 @@
1
- export function createFences() {
2
- const fencedAt = new Map();
3
- let fencings = 0;
4
- const lastFenced = new Map();
5
- return {
6
- has: (locator) => fencedAt.has(locator),
7
- of: (locator) => fencedAt.get(locator),
8
- raise(locator, at) {
9
- if (fencedAt.has(locator))
10
- return false;
11
- fencedAt.set(locator, { at, written: false });
12
- lastFenced.set(locator, ++fencings);
13
- return true;
14
- },
15
- mark(locator, written) {
16
- const fence = fencedAt.get(locator);
17
- if (fence !== undefined)
18
- fencedAt.set(locator, { ...fence, written });
19
- },
20
- lift(locator) {
21
- fencedAt.delete(locator);
22
- },
23
- count: () => fencings,
24
- since: (locator, count) => fencedAt.has(locator) || (lastFenced.get(locator) ?? 0) > count,
25
- };
26
- }