@toa.io/extensions.chronicles 1.0.0-alpha.332 → 1.0.0-alpha.335

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 (82) hide show
  1. package/LICENSE +22 -0
  2. package/components/chronicles.encounters/manifest.toa.yaml +108 -0
  3. package/components/{chronicles.ingestion → chronicles.encounters}/operations/anonymous.js +1 -1
  4. package/components/chronicles.encounters/operations/describe.js +4 -0
  5. package/components/{chronicles.ingestion → chronicles.encounters}/operations/identified.js +1 -1
  6. package/components/{chronicles.ingestion → chronicles.encounters}/types/toa.d.ts +13 -0
  7. package/components/chronicles.queries/manifest.toa.yaml +39 -15
  8. package/components/chronicles.queries/operations/define.js +1 -1
  9. package/components/chronicles.queries/types/toa.d.ts +8 -3
  10. package/components/{chronicles.facts → chronicles.relay}/manifest.toa.yaml +14 -3
  11. package/components/chronicles.relay/operations/encounter.js +4 -0
  12. package/components/{chronicles.facts → chronicles.relay}/operations/record.js +1 -1
  13. package/components/{chronicles.facts → chronicles.relay}/types/toa.d.ts +5 -0
  14. package/guides/clickhouse.md +19 -0
  15. package/guides/log.md +52 -0
  16. package/package.json +8 -4
  17. package/readme.md +459 -142
  18. package/store/clickhouse.scope.sql +29 -0
  19. package/store/clickhouse.sql +99 -0
  20. package/transpiled/Client.d.ts +19 -6
  21. package/transpiled/Client.js +89 -37
  22. package/transpiled/Client.js.map +1 -1
  23. package/transpiled/Factory.d.ts +13 -5
  24. package/transpiled/Factory.js +32 -23
  25. package/transpiled/Factory.js.map +1 -1
  26. package/transpiled/Provider.d.ts +76 -25
  27. package/transpiled/Provider.js.map +1 -1
  28. package/transpiled/Publisher.d.ts +50 -0
  29. package/transpiled/Publisher.js +169 -0
  30. package/transpiled/Publisher.js.map +1 -0
  31. package/transpiled/Reader.d.ts +15 -3
  32. package/transpiled/Reader.js +98 -14
  33. package/transpiled/Reader.js.map +1 -1
  34. package/transpiled/Recorder.d.ts +21 -11
  35. package/transpiled/Recorder.js +49 -24
  36. package/transpiled/Recorder.js.map +1 -1
  37. package/transpiled/Relay.d.ts +14 -0
  38. package/transpiled/Relay.js +27 -0
  39. package/transpiled/Relay.js.map +1 -0
  40. package/transpiled/Sender.d.ts +8 -4
  41. package/transpiled/Sender.js +27 -10
  42. package/transpiled/Sender.js.map +1 -1
  43. package/transpiled/Service.d.ts +26 -0
  44. package/transpiled/Service.js +70 -0
  45. package/transpiled/Service.js.map +1 -0
  46. package/transpiled/agent.d.ts +16 -0
  47. package/transpiled/agent.js +48 -0
  48. package/transpiled/agent.js.map +1 -0
  49. package/transpiled/clickhouse/Client.d.ts +5 -8
  50. package/transpiled/clickhouse/Client.js +12 -14
  51. package/transpiled/clickhouse/Client.js.map +1 -1
  52. package/transpiled/clickhouse/Provider.d.ts +20 -18
  53. package/transpiled/clickhouse/Provider.js +97 -72
  54. package/transpiled/clickhouse/Provider.js.map +1 -1
  55. package/transpiled/clickhouse/ddl.d.ts +3 -20
  56. package/transpiled/clickhouse/ddl.js +6 -79
  57. package/transpiled/clickhouse/ddl.js.map +1 -1
  58. package/transpiled/clickhouse/views.d.ts +11 -0
  59. package/transpiled/clickhouse/views.js +97 -0
  60. package/transpiled/clickhouse/views.js.map +1 -0
  61. package/transpiled/contract.d.ts +12 -0
  62. package/transpiled/contract.js +58 -0
  63. package/transpiled/contract.js.map +1 -0
  64. package/transpiled/index.d.ts +9 -3
  65. package/transpiled/settings.d.ts +6 -4
  66. package/transpiled/settings.js +27 -14
  67. package/transpiled/settings.js.map +1 -1
  68. package/transpiled/store.d.ts +3 -3
  69. package/transpiled/store.js +3 -3
  70. package/transpiled/store.js.map +1 -1
  71. package/components/chronicles.ingestion/manifest.toa.yaml +0 -60
  72. package/transpiled/Facts.d.ts +0 -9
  73. package/transpiled/Facts.js +0 -16
  74. package/transpiled/Facts.js.map +0 -1
  75. package/transpiled/Scribe.d.ts +0 -25
  76. package/transpiled/Scribe.js +0 -61
  77. package/transpiled/Scribe.js.map +0 -1
  78. package/transpiled/Writer.d.ts +0 -14
  79. package/transpiled/Writer.js +0 -50
  80. package/transpiled/Writer.js.map +0 -1
  81. /package/components/{chronicles.facts → chronicles.encounters}/types/index.d.ts +0 -0
  82. /package/components/{chronicles.ingestion → chronicles.relay}/types/index.d.ts +0 -0
@@ -1,38 +1,38 @@
1
+ import type { Property } from '@toa.io/definitions/extensions.chronicles';
1
2
  /**
2
- * Where the log is kept. A provider holds the log's two tables — `events`, a row for everything
3
- * that happened, and `states`, each entity as it stands — and reads them in a dialect of its own,
4
- * which is what an agent writes its queries in.
3
+ * Where the log is read. A provider reads the log's tables — `events`, a row for everything a
4
+ * component did, `states`, each entity as it stands, and `encounters`, what clients sent — in a
5
+ * dialect of its own, which is what an agent writes its queries in. What it reads is what the store
6
+ * lets the context's user read; it creates nothing there but the views it is asked to.
5
7
  */
6
8
  export interface Provider {
7
- /** what a query is written in, which `describe` tells whoever writes one */
8
- readonly dialect: string;
9
+ /** how the store is read: its dialect and what is particular to it, for whoever writes a query */
10
+ readonly guide: string;
9
11
  /** the names a view cannot take: the provider's own tables */
10
12
  readonly tables: string[];
11
- /** the tables, and the reader queries run as, made what the settings say */
12
- provision(): Promise<void>;
13
- /**
14
- * Rows of `events`, written once however often a row of one `id` is written; and states, each
15
- * kept where it is of a higher version than the one there.
16
- */
17
- write(rows: Row[], states: State[]): Promise<void>;
18
- /** the labels, with their counts, their times and the fields of their payloads */
13
+ /** the fields of declared properties, at every depth, each with the type its view reads it as */
14
+ fields(properties: Record<string, Property>): Field[];
15
+ /** the labels written, with their counts and their times */
19
16
  labels(): Promise<Label[]>;
20
- /** the components with a state, with how many entities each has and the fields of the state */
17
+ /** the components with a state, with how many entities each has */
21
18
  states(): Promise<Summary[]>;
19
+ /** the names of encounters, with their counts, their times and the fields their payloads have */
20
+ encounters(): Promise<Encountered[]>;
22
21
  /** a statement of the dialect, run as a reader that can read the log and nothing else */
23
22
  query(sql: string): Promise<Result>;
24
23
  /** refuses what a view could not be: anything but one statement a query could run */
25
24
  validate(sql: string): Promise<void>;
25
+ /** the views defined over the log */
26
26
  views(): Promise<View[]>;
27
27
  /** a view of `name`, replacing one there is; with `refresh`, recomputed on that cycle */
28
- define(name: string, sql: string, refresh?: number): Promise<void>;
28
+ define(definition: Definition): Promise<void>;
29
29
  drop(name: string): Promise<void>;
30
30
  }
31
- /** A row of the log. */
31
+ /** A row of `events`. */
32
32
  export interface Row {
33
33
  /** the same however many times it is delivered */
34
34
  id: string;
35
- /** `<component>.<event>`, `<component>.<name>` for a fact, `agent.<name>` for a browser */
35
+ /** `<component>.<event>`, or `<component>.<name>` for a fact */
36
36
  label: string;
37
37
  /** the component it is of */
38
38
  component: string;
@@ -44,9 +44,6 @@ export interface Row {
44
44
  version: number | null;
45
45
  /** the identity it is of, where something says so */
46
46
  identity: string | null;
47
- /** the address and the country of the browser that sent it, where one did */
48
- ip: string | null;
49
- country: string | null;
50
47
  /** the W3C traceparent of the call that caused it */
51
48
  trace: string | null;
52
49
  payload: object;
@@ -60,23 +57,77 @@ export interface State {
60
57
  time: number;
61
58
  payload: object;
62
59
  }
60
+ /** A row of `encounters`: what a client sent. */
61
+ export interface Encounter {
62
+ /** the client's own */
63
+ id: string;
64
+ name: string;
65
+ /** when it happened, by the gateway's clock, at the distance from sending the client measured */
66
+ time: number;
67
+ /** when the gateway received it */
68
+ received: number;
69
+ /** the client's id of itself, and of the period of its activity, where it gave them */
70
+ visitor: string | null;
71
+ session: string | null;
72
+ /** the identity the gateway verified the client to be */
73
+ identity: string | null;
74
+ /** the address and the country the request came from */
75
+ ip: string | null;
76
+ country: string | null;
77
+ /** the origin of the page that sent it, and the client's `user-agent` */
78
+ origin: string | null;
79
+ agent: string | null;
80
+ /** what the agent says the client is: its browser, its system, its kind of device */
81
+ browser: string | null;
82
+ os: string | null;
83
+ device: string | null;
84
+ payload: object;
85
+ }
86
+ export interface Label {
87
+ label: string;
88
+ rows: number;
89
+ first: string;
90
+ last: string;
91
+ }
63
92
  export interface Summary {
64
93
  component: string;
65
94
  entities: number;
66
- paths: string[];
95
+ /** when the latest change of an entity was made */
96
+ last: string;
67
97
  }
68
- export interface Label {
69
- label: string;
98
+ export interface Encountered {
99
+ name: string;
70
100
  rows: number;
71
101
  first: string;
72
102
  last: string;
73
- paths: string[];
103
+ received: string;
104
+ /** the paths of the latest payloads, each with the types it was sent as */
105
+ fields: Array<{
106
+ path: string;
107
+ types: string[];
108
+ }>;
74
109
  }
75
- export interface View {
110
+ /** A field of a declared payload, and the type its view reads it as. */
111
+ export interface Field {
112
+ path: string;
113
+ type: string;
114
+ description?: string;
115
+ /** the expression that reads it from its table in its type, of a property of the payload */
116
+ read?: string;
117
+ }
118
+ export interface Definition {
76
119
  name: string;
77
120
  sql: string;
78
121
  /** seconds between computations of a view that is a table */
79
122
  refresh?: number;
123
+ title?: string;
124
+ description?: string;
125
+ }
126
+ export interface View extends Definition {
127
+ /** what a query reads it by */
128
+ read: string;
129
+ /** when a view that is a table was last computed */
130
+ refreshed?: string;
80
131
  }
81
132
  export interface Result {
82
133
  columns: Array<{
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../source/Provider.ts"],"names":[],"mappings":"AAgHA,kEAAkE;AAClE,MAAM,OAAO,OAAQ,SAAQ,KAAK;CAAG"}
1
+ {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../source/Provider.ts"],"names":[],"mappings":"AAiLA,kEAAkE;AAClE,MAAM,OAAO,OAAQ,SAAQ,KAAK;CAAG"}
@@ -0,0 +1,50 @@
1
+ import { Connector } from '@toa.io/core';
2
+ import type { Encounter, Row, State } from './Provider.ts';
3
+ import type { User } from './settings.ts';
4
+ /**
5
+ * Rows to the broker of the log: each a JSON message to the exchange `chronicles` under the key of
6
+ * its table, with the scope of the context and when it expires. A publication resolves once the
7
+ * broker has confirmed it, which is what the caller acknowledges what it carried by.
8
+ *
9
+ * The connection is made by the first publication and not before, and nothing waits for it to
10
+ * start: while the broker is away, a publication waits for it, and what it carries waits, unacknowledged,
11
+ * where it came from.
12
+ */
13
+ export declare class Publisher extends Connector {
14
+ private readonly url;
15
+ private readonly scope;
16
+ private readonly retention;
17
+ private io?;
18
+ private opened?;
19
+ /** aborted as the publisher stops: what waits for the broker then gives up, to be delivered again */
20
+ private closing;
21
+ private stopped;
22
+ /** where it publishes, which a publisher of other settings does not */
23
+ readonly address: string;
24
+ constructor(address: string, user: User, scope: string, retention?: number);
25
+ publish(rows: Row[], states?: State[], encounters?: Encounter[]): Promise<void>;
26
+ /**
27
+ * Fails what waits for the broker, and what is published from now on, so the service publishing
28
+ * through it is not held open by what would wait for the broker past the service's own end: it
29
+ * is delivered again, to this process or another.
30
+ */
31
+ get done(): boolean;
32
+ stop(): void;
33
+ protected open(): Promise<void>;
34
+ /**
35
+ * A connection still being made is not waited for — it may never be — but closed once it is,
36
+ * and what waits for it is failed, so it is delivered again, to this process or another.
37
+ */
38
+ protected close(): Promise<void>;
39
+ private connection;
40
+ private route;
41
+ }
42
+ /**
43
+ * A row as the store reads it: of a scope, its times in the store's format, and when it expires,
44
+ * where it does.
45
+ */
46
+ export declare function message(row: Row | State | Encounter, scope: string, until: string | null): Record<string, unknown>;
47
+ /** When a row stops being kept: its time and the retention, or the end of the store's time. */
48
+ export declare function expires(from: number, retention: number | undefined): string;
49
+ /** A `DateTime64(3)` as the store reads one without guessing: UTC, to the millisecond. */
50
+ export declare function timestamp(ms: number): string;
@@ -0,0 +1,169 @@
1
+ import { createConnection } from 'node:net';
2
+ import { connect } from 'comq';
3
+ import { console } from 'openspan';
4
+ import { Connector } from '@toa.io/core';
5
+ import { EXCHANGE } from '@toa.io/definitions/extensions.chronicles';
6
+ /**
7
+ * Rows to the broker of the log: each a JSON message to the exchange `chronicles` under the key of
8
+ * its table, with the scope of the context and when it expires. A publication resolves once the
9
+ * broker has confirmed it, which is what the caller acknowledges what it carried by.
10
+ *
11
+ * The connection is made by the first publication and not before, and nothing waits for it to
12
+ * start: while the broker is away, a publication waits for it, and what it carries waits, unacknowledged,
13
+ * where it came from.
14
+ */
15
+ export class Publisher extends Connector {
16
+ url;
17
+ scope;
18
+ retention;
19
+ io;
20
+ opened;
21
+ /** aborted as the publisher stops: what waits for the broker then gives up, to be delivered again */
22
+ closing = new AbortController();
23
+ stopped = false;
24
+ /** where it publishes, which a publisher of other settings does not */
25
+ address;
26
+ // eslint-disable-next-line max-params
27
+ constructor(address, user, scope, retention) {
28
+ super();
29
+ this.address = address;
30
+ const url = new URL(address);
31
+ url.username = encodeURIComponent(user.username);
32
+ url.password = encodeURIComponent(user.password);
33
+ this.url = url.href;
34
+ this.scope = scope;
35
+ this.retention = retention;
36
+ }
37
+ async publish(rows, states = [], encounters = []) {
38
+ if (this.stopped)
39
+ throw new Error('The chronicles are stopping');
40
+ const io = await this.connection();
41
+ await Promise.all([
42
+ ...rows.map(async (row) => await this.route(io, 'events', row, row.time)),
43
+ ...states.map(async (state) => await this.route(io, 'states', state)),
44
+ ...encounters.map(async (encounter) => await this.route(io, 'encounters', encounter, encounter.received))
45
+ ]);
46
+ }
47
+ /**
48
+ * Fails what waits for the broker, and what is published from now on, so the service publishing
49
+ * through it is not held open by what would wait for the broker past the service's own end: it
50
+ * is delivered again, to this process or another.
51
+ */
52
+ get done() {
53
+ return this.stopped;
54
+ }
55
+ stop() {
56
+ this.stopped = true;
57
+ this.closing.abort();
58
+ }
59
+ async open() {
60
+ this.stopped = false;
61
+ this.closing = new AbortController();
62
+ }
63
+ /**
64
+ * A connection still being made is not waited for — it may never be — but closed once it is,
65
+ * and what waits for it is failed, so it is delivered again, to this process or another.
66
+ */
67
+ async close() {
68
+ const { io, opened } = this;
69
+ this.io = undefined;
70
+ this.opened = undefined;
71
+ this.stop();
72
+ if (opened !== undefined)
73
+ await opened.close();
74
+ else
75
+ void io?.then(async (late) => await late.close(), () => undefined);
76
+ }
77
+ async connection() {
78
+ this.io ??= reachable(this.url, this.closing.signal)
79
+ .then(async () => await connect(this.url))
80
+ .then((io) => {
81
+ this.opened = io;
82
+ return io;
83
+ }, (error) => {
84
+ this.io = undefined;
85
+ console.warn('Chronicles failed to reach their broker', {
86
+ error: error instanceof Error ? error.message : String(error)
87
+ });
88
+ throw error;
89
+ });
90
+ const { signal } = this.closing;
91
+ // a publication waits for the broker a while, and then fails, so what it carries is
92
+ // delivered again rather than held: a process that stops is not kept by one that never ends
93
+ return await new Promise((resolve, reject) => {
94
+ function away() {
95
+ reject(new Error('The broker of the chronicles is away'));
96
+ }
97
+ function closing() {
98
+ reject(new Error('The chronicles are closing'));
99
+ }
100
+ const timer = setTimeout(away, WAIT);
101
+ signal.addEventListener('abort', closing, { once: true });
102
+ this.io.then(resolve, reject).finally(() => {
103
+ clearTimeout(timer);
104
+ signal.removeEventListener('abort', closing);
105
+ });
106
+ });
107
+ }
108
+ // eslint-disable-next-line max-params
109
+ async route(io, table, row, from) {
110
+ const body = message(row, this.scope, from === undefined ? null : expires(from, this.retention));
111
+ await io.route(EXCHANGE, table, body, 'application/json');
112
+ }
113
+ }
114
+ /**
115
+ * Resolves once the broker accepts a connection, trying again until it does or `signal` aborts.
116
+ * A connection is asked of comq only then: one it is asked for keeps trying for as long as it
117
+ * takes, and is no longer the publisher's to give up.
118
+ */
119
+ async function reachable(url, signal) {
120
+ const { protocol, hostname, port } = new URL(url);
121
+ const target = { host: hostname, port: Number(port === '' ? DEFAULT[protocol] : port) };
122
+ while (!signal.aborted) {
123
+ const reached = await new Promise((resolve) => {
124
+ const socket = createConnection(target);
125
+ function settle(ok) {
126
+ socket.destroy();
127
+ resolve(ok);
128
+ }
129
+ socket.setTimeout(PROBE);
130
+ socket.once('connect', () => settle(true));
131
+ socket.once('timeout', () => settle(false));
132
+ socket.once('error', () => settle(false));
133
+ });
134
+ if (reached)
135
+ return;
136
+ await new Promise((resolve) => setTimeout(resolve, PROBE).unref());
137
+ }
138
+ throw new Error('The chronicles are closing');
139
+ }
140
+ /**
141
+ * A row as the store reads it: of a scope, its times in the store's format, and when it expires,
142
+ * where it does.
143
+ */
144
+ export function message(row, scope, until) {
145
+ const body = { scope, ...row, time: timestamp(row.time) };
146
+ if ('received' in row)
147
+ body.received = timestamp(row.received);
148
+ if (until !== null)
149
+ body.expires = until;
150
+ return body;
151
+ }
152
+ /** When a row stops being kept: its time and the retention, or the end of the store's time. */
153
+ export function expires(from, retention) {
154
+ if (retention === undefined)
155
+ return FOREVER;
156
+ return timestamp(from + retention * DAY).slice(0, 19);
157
+ }
158
+ /** A `DateTime64(3)` as the store reads one without guessing: UTC, to the millisecond. */
159
+ export function timestamp(ms) {
160
+ return new Date(ms).toISOString().replace('T', ' ').replace('Z', '');
161
+ }
162
+ const DAY = 86_400_000;
163
+ /** milliseconds a publication waits for the broker */
164
+ const WAIT = 10_000;
165
+ /** milliseconds a try to reach the broker takes, and between two of them */
166
+ const PROBE = 1_000;
167
+ const DEFAULT = { 'amqp:': 5672, 'amqps:': 5671 };
168
+ const FOREVER = '2106-01-01 00:00:00';
169
+ //# sourceMappingURL=Publisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Publisher.js","sourceRoot":"","sources":["../source/Publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAA;AAKpE;;;;;;;;GAQG;AACH,MAAM,OAAO,SAAU,SAAQ,SAAS;IACrB,GAAG,CAAQ;IACX,KAAK,CAAQ;IACb,SAAS,CAAoB;IACtC,EAAE,CAAc;IAChB,MAAM,CAAK;IAEnB,qGAAqG;IAC7F,OAAO,GAAG,IAAI,eAAe,EAAE,CAAA;IAC/B,OAAO,GAAG,KAAK,CAAA;IAEvB,uEAAuE;IACvD,OAAO,CAAQ;IAE/B,sCAAs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,CAAA;AACzE,MAAM,OAAO,GAAG,qBAAqB,CAAA"}
@@ -1,16 +1,28 @@
1
1
  import { Connector } from '@toa.io/core';
2
2
  import type { Provider } from './Provider.ts';
3
+ import type { extensions } from '@toa.io/core/types';
4
+ import type { Settings } from '@toa.io/definitions/extensions.chronicles';
3
5
  /**
4
- * What `chronicles.queries` reads the log through: queries in the provider's dialect, and views
5
- * made from a statement the provider let a query run.
6
+ * What `chronicles.queries` reads the log through: queries in the provider's dialect, views made
7
+ * from a statement the provider let a query run, and what the log holds — how it is read, what the
8
+ * components declare, what the context documents of encounters, and what the store has written.
6
9
  */
7
10
  export declare class Reader extends Connector {
8
11
  readonly name = "chronicles";
12
+ private readonly host;
9
13
  private readonly provider;
10
- constructor(provider: () => Provider);
14
+ private readonly settings;
15
+ private encounters?;
16
+ constructor(host: extensions.Host, provider: () => Provider, settings: () => Settings);
11
17
  invoke(method: string, ...args: any[]): Promise<unknown>;
12
18
  private describe;
13
19
  private query;
14
20
  private define;
15
21
  private drop;
22
+ /**
23
+ * What the configuration of `chronicles.encounters` documents, asked of that component, which is
24
+ * in this service where the context serves encounters. Found on the first ask and not before: an
25
+ * aspect is made ahead of the components of its composition.
26
+ */
27
+ private documented;
16
28
  }
@@ -1,15 +1,24 @@
1
- import { Connector, exceptions } from '@toa.io/core';
1
+ import { readFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { Connector, Locator, exceptions } from '@toa.io/core';
4
+ import { ENCOUNTERS, NAMESPACE } from '@toa.io/definitions/extensions.chronicles';
2
5
  import { Refusal } from './Provider.js';
3
6
  /**
4
- * What `chronicles.queries` reads the log through: queries in the provider's dialect, and views
5
- * made from a statement the provider let a query run.
7
+ * What `chronicles.queries` reads the log through: queries in the provider's dialect, views made
8
+ * from a statement the provider let a query run, and what the log holds — how it is read, what the
9
+ * components declare, what the context documents of encounters, and what the store has written.
6
10
  */
7
11
  export class Reader extends Connector {
8
12
  name = 'chronicles';
13
+ host;
9
14
  provider;
10
- constructor(provider) {
15
+ settings;
16
+ encounters;
17
+ constructor(host, provider, settings) {
11
18
  super();
19
+ this.host = host;
12
20
  this.provider = provider;
21
+ this.settings = settings;
13
22
  }
14
23
  async invoke(method, ...args) {
15
24
  switch (method) {
@@ -18,7 +27,7 @@ export class Reader extends Connector {
18
27
  case 'query':
19
28
  return await this.query(args[0]);
20
29
  case 'define':
21
- return await this.define(args[0], args[1], args[2]);
30
+ return await this.define(args[0]);
22
31
  case 'drop':
23
32
  return await this.drop(args[0]);
24
33
  default:
@@ -27,23 +36,54 @@ export class Reader extends Connector {
27
36
  }
28
37
  async describe() {
29
38
  const provider = this.provider();
30
- return {
31
- dialect: provider.dialect,
32
- labels: await provider.labels(),
33
- states: await provider.states(),
34
- views: await provider.views()
35
- };
39
+ const settings = this.settings();
40
+ const [written, kept, sent, views, documented] = await Promise.all([
41
+ provider.labels(),
42
+ provider.states(),
43
+ provider.encounters(),
44
+ provider.views(),
45
+ this.documented(settings)
46
+ ]);
47
+ const declared = { ...settings.events, ...settings.facts };
48
+ const stated = Object.fromEntries(Object.entries(settings.states).map(([label, contract]) => [
49
+ component(label),
50
+ contract
51
+ ]));
52
+ const labels = merge(written.map(({ label, ...stats }) => [label, stats]), Object.keys(declared)).map(([label, stats]) => ({
53
+ label,
54
+ ...about(declared[label], provider),
55
+ ...(stats ?? { rows: 0 })
56
+ }));
57
+ const states = merge(kept.map(({ component, ...stats }) => [component, stats]), Object.keys(stated)).map(([component, stats]) => ({
58
+ component,
59
+ ...about(stated[component], provider),
60
+ ...(stats ?? { entities: 0 })
61
+ }));
62
+ const encounters = merge(sent.map(({ name, ...stats }) => [name, stats]), Object.keys(documented)).map(([name, stats]) => {
63
+ const { description, fields: told = {} } = documented[name] ?? {};
64
+ const fields = (stats?.fields ?? []).map((field) => told[field.path] === undefined
65
+ ? field
66
+ : { ...field, description: told[field.path] });
67
+ return {
68
+ name,
69
+ ...(description === undefined ? {} : { description }),
70
+ ...(stats ?? { rows: 0 }),
71
+ fields
72
+ };
73
+ });
74
+ return { guide: `${GUIDE}\n${provider.guide}`, labels, states, encounters, views };
36
75
  }
37
76
  async query(sql) {
38
77
  return await refused(async () => await this.provider().query(statement(sql)));
39
78
  }
40
- async define(name, sql, refresh) {
79
+ async define(definition) {
41
80
  const provider = this.provider();
81
+ const { name } = definition;
42
82
  if (provider.tables.includes(name))
43
83
  return new Error('RESERVED', {
44
84
  cause: { message: `'${name}' is a table of the log` }
45
85
  });
46
- const select = statement(sql);
86
+ const select = statement(definition.sql);
47
87
  const invalid = await refused(async () => await provider.validate(select));
48
88
  if (invalid instanceof Error)
49
89
  return invalid;
@@ -52,7 +92,7 @@ export class Reader extends Connector {
52
92
  return new Error('EXHAUSTED', {
53
93
  cause: { message: `A context has at most ${MAX_VIEWS} views` }
54
94
  });
55
- const defined = await refused(async () => await provider.define(name, select, refresh));
95
+ const defined = await refused(async () => await provider.define({ ...definition, sql: select }));
56
96
  return defined instanceof Error ? defined : undefined;
57
97
  }
58
98
  async drop(name) {
@@ -63,6 +103,47 @@ export class Reader extends Connector {
63
103
  await provider.drop(name);
64
104
  return undefined;
65
105
  }
106
+ /**
107
+ * What the configuration of `chronicles.encounters` documents, asked of that component, which is
108
+ * in this service where the context serves encounters. Found on the first ask and not before: an
109
+ * aspect is made ahead of the components of its composition.
110
+ */
111
+ async documented(settings) {
112
+ if (!settings.encounters)
113
+ return {};
114
+ this.encounters ??= (async () => {
115
+ const remote = await this.host.remote(LOCATOR, SOURCE);
116
+ this.depends(remote);
117
+ await remote.connect();
118
+ return remote;
119
+ })().catch((error) => {
120
+ this.encounters = undefined;
121
+ throw error;
122
+ });
123
+ const remote = await this.encounters;
124
+ return (await remote.invoke('describe', {}));
125
+ }
126
+ }
127
+ /**
128
+ * Of what was written and what is declared, by key, in order: a key declared and not yet written
129
+ * has no statistics, and one written and no longer declared has nothing else.
130
+ */
131
+ function merge(written, declared) {
132
+ const by = new Map(written);
133
+ const keys = [...new Set([...by.keys(), ...declared])].sort();
134
+ return keys.map((key) => [key, by.get(key)]);
135
+ }
136
+ /** What a declaration says of a label or a state: its meaning, and its fields. */
137
+ function about(contract, provider) {
138
+ if (contract === undefined)
139
+ return {};
140
+ return {
141
+ description: contract.description,
142
+ fields: provider.fields(contract.properties)
143
+ };
144
+ }
145
+ function component(label) {
146
+ return label.slice(0, label.lastIndexOf('.'));
66
147
  }
67
148
  /** One statement: a trailing semicolon is an agent's habit. */
68
149
  function statement(sql) {
@@ -78,5 +159,8 @@ async function refused(fn) {
78
159
  throw exception;
79
160
  }
80
161
  }
162
+ const LOCATOR = new Locator(ENCOUNTERS, NAMESPACE);
163
+ const SOURCE = { service: 'chronicles' };
81
164
  const MAX_VIEWS = 50;
165
+ const GUIDE = readFileSync(resolve(import.meta.dirname, '../guides/log.md'), 'utf8');
82
166
  //# sourceMappingURL=Reader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Reader.js","sourceRoot":"","sources":["../source/Reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAGvC;;;GAGG;AACH,MAAM,OAAO,MAAO,SAAQ,SAAS;IACnB,IAAI,GAAG,YAAY,CAAA;IAElB,QAAQ,CAAgB;IAEzC,YAAmB,QAAwB;QACzC,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,GAAG,IAAW;QAChD,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,UAAU;gBACb,OAAO,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAA;YAC9B,KAAK,OAAO;gBACV,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;YAClC,KAAK,QAAQ;gBACX,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,I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