@toa.io/extensions.chronicles 0.0.0-stage → 1.0.0-alpha.333

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 (83) hide show
  1. package/LICENSE +22 -0
  2. package/components/chronicles.encounters/manifest.toa.yaml +108 -0
  3. package/components/chronicles.encounters/operations/anonymous.js +4 -0
  4. package/components/chronicles.encounters/operations/describe.js +4 -0
  5. package/components/chronicles.encounters/operations/identified.js +4 -0
  6. package/components/chronicles.encounters/types/index.d.ts +3 -0
  7. package/components/chronicles.encounters/types/toa.d.ts +36 -0
  8. package/components/chronicles.queries/manifest.toa.yaml +139 -0
  9. package/components/chronicles.queries/operations/define.js +3 -0
  10. package/components/chronicles.queries/operations/describe.js +3 -0
  11. package/components/chronicles.queries/operations/drop.js +3 -0
  12. package/components/chronicles.queries/operations/query.js +3 -0
  13. package/components/chronicles.queries/types/index.d.ts +3 -0
  14. package/components/chronicles.queries/types/toa.d.ts +49 -0
  15. package/components/chronicles.relay/manifest.toa.yaml +43 -0
  16. package/components/chronicles.relay/operations/encounter.js +4 -0
  17. package/components/chronicles.relay/operations/record.js +4 -0
  18. package/components/chronicles.relay/types/index.d.ts +3 -0
  19. package/components/chronicles.relay/types/toa.d.ts +24 -0
  20. package/guides/clickhouse.md +19 -0
  21. package/guides/log.md +52 -0
  22. package/package.json +39 -4
  23. package/readme.md +686 -0
  24. package/store/clickhouse.scope.sql +29 -0
  25. package/store/clickhouse.sql +99 -0
  26. package/transpiled/Client.d.ts +32 -0
  27. package/transpiled/Client.js +173 -0
  28. package/transpiled/Client.js.map +1 -0
  29. package/transpiled/Factory.d.ts +24 -0
  30. package/transpiled/Factory.js +62 -0
  31. package/transpiled/Factory.js.map +1 -0
  32. package/transpiled/Provider.d.ts +142 -0
  33. package/transpiled/Provider.js +4 -0
  34. package/transpiled/Provider.js.map +1 -0
  35. package/transpiled/Publisher.d.ts +50 -0
  36. package/transpiled/Publisher.js +169 -0
  37. package/transpiled/Publisher.js.map +1 -0
  38. package/transpiled/Reader.d.ts +28 -0
  39. package/transpiled/Reader.js +166 -0
  40. package/transpiled/Reader.js.map +1 -0
  41. package/transpiled/Recorder.d.ts +38 -0
  42. package/transpiled/Recorder.js +107 -0
  43. package/transpiled/Recorder.js.map +1 -0
  44. package/transpiled/Relay.d.ts +14 -0
  45. package/transpiled/Relay.js +27 -0
  46. package/transpiled/Relay.js.map +1 -0
  47. package/transpiled/Sender.d.ts +25 -0
  48. package/transpiled/Sender.js +86 -0
  49. package/transpiled/Sender.js.map +1 -0
  50. package/transpiled/Service.d.ts +26 -0
  51. package/transpiled/Service.js +70 -0
  52. package/transpiled/Service.js.map +1 -0
  53. package/transpiled/address.d.ts +7 -0
  54. package/transpiled/address.js +27 -0
  55. package/transpiled/address.js.map +1 -0
  56. package/transpiled/agent.d.ts +16 -0
  57. package/transpiled/agent.js +48 -0
  58. package/transpiled/agent.js.map +1 -0
  59. package/transpiled/clickhouse/Client.d.ts +35 -0
  60. package/transpiled/clickhouse/Client.js +71 -0
  61. package/transpiled/clickhouse/Client.js.map +1 -0
  62. package/transpiled/clickhouse/Provider.d.ts +35 -0
  63. package/transpiled/clickhouse/Provider.js +169 -0
  64. package/transpiled/clickhouse/Provider.js.map +1 -0
  65. package/transpiled/clickhouse/ddl.d.ts +9 -0
  66. package/transpiled/clickhouse/ddl.js +15 -0
  67. package/transpiled/clickhouse/ddl.js.map +1 -0
  68. package/transpiled/clickhouse/views.d.ts +11 -0
  69. package/transpiled/clickhouse/views.js +97 -0
  70. package/transpiled/clickhouse/views.js.map +1 -0
  71. package/transpiled/contract.d.ts +12 -0
  72. package/transpiled/contract.js +58 -0
  73. package/transpiled/contract.js.map +1 -0
  74. package/transpiled/index.d.ts +15 -0
  75. package/transpiled/index.js +2 -0
  76. package/transpiled/index.js.map +1 -0
  77. package/transpiled/settings.d.ts +13 -0
  78. package/transpiled/settings.js +48 -0
  79. package/transpiled/settings.js.map +1 -0
  80. package/transpiled/store.d.ts +5 -0
  81. package/transpiled/store.js +11 -0
  82. package/transpiled/store.js.map +1 -0
  83. package/README.md +0 -3
@@ -0,0 +1,9 @@
1
+ /** The log's tables, which a view is not named after. */
2
+ export declare const TABLES: string[];
3
+ /** What a query answers at most, which the provider cuts a result at to tell it is cut. */
4
+ export declare const LIMITS: {
5
+ rows: number;
6
+ };
7
+ /** An identifier, quoted: a scope, which may have hyphens, or a name held to letters and digits. */
8
+ export declare function id(name: string): string;
9
+ export declare function literal(value: string): string;
@@ -0,0 +1,15 @@
1
+ /** The log's tables, which a view is not named after. */
2
+ export const TABLES = ['events', 'states', 'encounters'];
3
+ /** What a query answers at most, which the provider cuts a result at to tell it is cut. */
4
+ export const LIMITS = { rows: 10_000 };
5
+ /** An identifier, quoted: a scope, which may have hyphens, or a name held to letters and digits. */
6
+ export function id(name) {
7
+ if (!IDENTIFIER.test(name))
8
+ throw new Error(`'${name}' is not a ClickHouse identifier chronicles accept`);
9
+ return '`' + name + '`';
10
+ }
11
+ export function literal(value) {
12
+ return "'" + value.replace(/\\/g, '\\\\').replace(/'/g, "\\'") + "'";
13
+ }
14
+ const IDENTIFIER = /^[a-zA-Z0-9_][a-zA-Z0-9_-]*$/;
15
+ //# sourceMappingURL=ddl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ddl.js","sourceRoot":"","sources":["../../source/clickhouse/ddl.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAA;AAExD,2FAA2F;AAC3F,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AAEtC,oGAAoG;AACpG,MAAM,UAAU,EAAE,CAAC,IAAY;IAC7B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,oDAAoD,CAAC,CAAA;IAE/E,OAAO,GAAG,GAAG,IAAI,GAAG,GAAG,CAAA;AACzB,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,GAAG,CAAA;AACtE,CAAC;AAED,MAAM,UAAU,GAAG,8BAA8B,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { Property } from '@toa.io/definitions/extensions.chronicles';
2
+ import type { Field } from '../Provider.ts';
3
+ /**
4
+ * How a declared property is read from the payload in its type, by `JSONExtract`, which reads what
5
+ * is not of the type as `NULL` rather than failing the query — a row written under an earlier
6
+ * contract is read by the one there is now.
7
+ */
8
+ /** The fields of a contract, at every depth, each with the type its column reads it as. */
9
+ export declare function fields(properties: Record<string, Property>, prefix?: string): Field[];
10
+ /** What a property reads as, `NULL` aside. */
11
+ export declare function type(property: Property): string;
@@ -0,0 +1,97 @@
1
+ import { id, literal } from './ddl.js';
2
+ /**
3
+ * How a declared property is read from the payload in its type, by `JSONExtract`, which reads what
4
+ * is not of the type as `NULL` rather than failing the query — a row written under an earlier
5
+ * contract is read by the one there is now.
6
+ */
7
+ /** The fields of a contract, at every depth, each with the type its column reads it as. */
8
+ export function fields(properties, prefix = '') {
9
+ const found = [];
10
+ for (const [name, property] of Object.entries(properties)) {
11
+ if (empty(property))
12
+ continue;
13
+ const path = prefix === '' ? name : `${prefix}.${name}`;
14
+ const field = { path, type: type(property), description: property.description };
15
+ // a property of a property is read inside the one that holds it
16
+ if (prefix === '')
17
+ field.read = extract(name, property);
18
+ found.push(field);
19
+ const nested = property.type === 'array' ? property.items : property;
20
+ if (nested.type === 'object')
21
+ found.push(...fields(nested.properties, path));
22
+ }
23
+ return found;
24
+ }
25
+ /** What a property reads as, `NULL` aside. */
26
+ export function type(property) {
27
+ switch (property.type) {
28
+ case 'object':
29
+ return `Tuple(${members(property, type)})`;
30
+ case 'array':
31
+ return `Array(${type(property.items)})`;
32
+ default:
33
+ return scalar(property);
34
+ }
35
+ }
36
+ /** The column of a property: a value of the type, or `NULL` where it was not one. */
37
+ function column(property) {
38
+ switch (property.type) {
39
+ case 'object':
40
+ return `Tuple(${members(property, column)})`;
41
+ case 'array':
42
+ return `Array(${column(property.items)})`;
43
+ default:
44
+ return property.enum === undefined
45
+ ? `Nullable(${scalar(property)})`
46
+ : 'LowCardinality(Nullable(String))';
47
+ }
48
+ }
49
+ function scalar(property) {
50
+ if (property.enum !== undefined)
51
+ return 'LowCardinality(String)';
52
+ const formatted = property.format === undefined ? undefined : FORMATS[property.format];
53
+ return formatted?.type === property.type ? formatted.as : SCALARS[property.type];
54
+ }
55
+ function members(property, of) {
56
+ return Object.entries(property.properties)
57
+ .filter(([, nested]) => !empty(nested))
58
+ .map(([name, nested]) => `${name} ${of(nested)}`)
59
+ .join(', ');
60
+ }
61
+ /**
62
+ * An object is read from the JSON of its paths, which is an object however few of them a row has;
63
+ * anything else from the JSON of its value, which is `null` where a row has none.
64
+ */
65
+ function extract(name, property) {
66
+ const json = property.type === 'object'
67
+ ? `toJSONString(payload.^${id(name)})`
68
+ : `ifNull(toJSONString(payload.${id(name)}), 'null')`;
69
+ return `JSONExtract(${json}, ${literal(column(property))})`;
70
+ }
71
+ /** An object of no properties is no column: a tuple of nothing is no type. */
72
+ function empty(property) {
73
+ const nested = property.type === 'array' ? property.items : property;
74
+ return (nested.type === 'object' &&
75
+ Object.values(nested.properties ?? {}).every((member) => empty(member)));
76
+ }
77
+ const SCALARS = {
78
+ string: 'String',
79
+ integer: 'Int64',
80
+ number: 'Float64',
81
+ boolean: 'Bool'
82
+ };
83
+ const FORMATS = {
84
+ 'date-time': { type: 'string', as: "DateTime64(3, 'UTC')" },
85
+ 'iso-date-time': { type: 'string', as: "DateTime64(3, 'UTC')" },
86
+ date: { type: 'string', as: 'Date32' },
87
+ time: { type: 'string', as: 'Time64(3)' },
88
+ 'iso-time': { type: 'string', as: 'Time64(3)' },
89
+ uuid: { type: 'string', as: 'UUID' },
90
+ ipv4: { type: 'string', as: 'IPv4' },
91
+ ipv6: { type: 'string', as: 'IPv6' },
92
+ int32: { type: 'integer', as: 'Int32' },
93
+ int64: { type: 'integer', as: 'Int64' },
94
+ float: { type: 'number', as: 'Float32' },
95
+ double: { type: 'number', as: 'Float64' }
96
+ };
97
+ //# sourceMappingURL=views.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"views.js","sourceRoot":"","sources":["../../source/clickhouse/views.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAItC;;;;GAIG;AAEH,2FAA2F;AAC3F,MAAM,UAAU,MAAM,CAAC,UAAoC,EAAE,MAAM,GAAG,EAAE;IACtE,MAAM,KAAK,GAAY,EAAE,CAAA;IAEzB,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1D,IAAI,KAAK,CAAC,QAAQ,CAAC;YAAE,SAAQ;QAE7B,MAAM,IAAI,GAAG,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,CAAA;QAEvD,MAAM,KAAK,GAAU,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAA;QAEtF,gEAAgE;QAChE,IAAI,MAAM,KAAK,EAAE;YAAE,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QAEvD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAEjB,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAM,CAAC,CAAC,CAAC,QAA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;AAED,MAAM,OAAO,GAA2B;IACtC,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,OAAO;IAChB,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,MAAM;CAChB,CAAA;AAED,MAAM,OAAO,GAAiD;IAC5D,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,sBAAsB,EAAE;IAC3D,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,sBAAsB,EAAE;IAC/D,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE;IACtC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,WAAW,EAAE;IACzC,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,WAAW,EAAE;IAC/C,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE;IACpC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE;IACpC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE;IACpC,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE;IACvC,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE;IACvC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE;IACxC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE;CAC1C,CAAA"}
@@ -0,0 +1,12 @@
1
+ import type { Property } from '@toa.io/definitions/extensions.chronicles';
2
+ /**
3
+ * What of a payload is written: the declared properties, at every depth, and nothing else. A
4
+ * value that is not of its declared type is a payload the contract does not admit, which throws a
5
+ * `Mismatch` naming where; `null` is admitted for any property, and an absent one stays absent.
6
+ */
7
+ export declare function project(payload: object, properties: Record<string, Property>, path?: string): Record<string, unknown>;
8
+ /** A payload's value at `path` is not of the type its contract declares. */
9
+ export declare class Mismatch extends Error {
10
+ readonly path: string;
11
+ constructor(path: string, property: Property);
12
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * What of a payload is written: the declared properties, at every depth, and nothing else. A
3
+ * value that is not of its declared type is a payload the contract does not admit, which throws a
4
+ * `Mismatch` naming where; `null` is admitted for any property, and an absent one stays absent.
5
+ */
6
+ export function project(payload, properties, path = '') {
7
+ const projected = {};
8
+ for (const [name, property] of Object.entries(properties)) {
9
+ const value = payload[name];
10
+ if (value === undefined)
11
+ continue;
12
+ projected[name] = fit(value, property, path === '' ? name : `${path}.${name}`);
13
+ }
14
+ return projected;
15
+ }
16
+ function fit(value, property, path) {
17
+ if (value === null)
18
+ return null;
19
+ switch (property.type) {
20
+ case 'string':
21
+ if (typeof value !== 'string')
22
+ throw new Mismatch(path, property);
23
+ if (property.enum !== undefined && !property.enum.includes(value))
24
+ throw new Mismatch(path, property);
25
+ return value;
26
+ case 'integer':
27
+ if (!Number.isInteger(value))
28
+ throw new Mismatch(path, property);
29
+ return value;
30
+ case 'number':
31
+ if (typeof value !== 'number' || !Number.isFinite(value))
32
+ throw new Mismatch(path, property);
33
+ return value;
34
+ case 'boolean':
35
+ if (typeof value !== 'boolean')
36
+ throw new Mismatch(path, property);
37
+ return value;
38
+ case 'object':
39
+ if (typeof value !== 'object' || Array.isArray(value))
40
+ throw new Mismatch(path, property);
41
+ return project(value, property.properties ?? {}, path);
42
+ case 'array':
43
+ if (!Array.isArray(value))
44
+ throw new Mismatch(path, property);
45
+ return value.map((item, index) => fit(item, property.items, `${path}[${index}]`));
46
+ }
47
+ }
48
+ /** A payload's value at `path` is not of the type its contract declares. */
49
+ export class Mismatch extends Error {
50
+ path;
51
+ constructor(path, property) {
52
+ super(property.enum === undefined
53
+ ? `'${path}' is not of the type '${property.type}'`
54
+ : `'${path}' is not one of ${property.enum.map((value) => `'${value}'`).join(', ')}`);
55
+ this.path = path;
56
+ }
57
+ }
58
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../source/contract.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,OAAO,CACrB,OAAe,EACf,UAAoC,EACpC,IAAI,GAAG,EAAE;IAET,MAAM,SAAS,GAA4B,EAAE,CAAA;IAE7C,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAI,OAAmC,CAAC,IAAI,CAAC,CAAA;QAExD,IAAI,KAAK,KAAK,SAAS;YAAE,SAAQ;QAEjC,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAA;IAChF,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,SAAS,GAAG,CAAC,KAAc,EAAE,QAAkB,EAAE,IAAY;IAC3D,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAE/B,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,QAAQ;YACX,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAAE,MAAM,IAAI,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YAEjE,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAC/D,MAAM,IAAI,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YAEpC,OAAO,KAAK,CAAA;QACd,KAAK,SAAS;YACZ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AAI,IAAI,yBAAyB,QAAQ,CAAC,IAAI,GAAG;YACnD,CAAC,CAAC,IAAI,IAAI,mBAAmB,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACvF,CAAA;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ export { Factory } from './Factory.ts';
2
+ /** `context.chronicles` of a component that declares `chronicles`. */
3
+ export interface Chronicles {
4
+ /**
5
+ * Writes a fact that changes no state to the log, under `<component>.<name>`, of which what the
6
+ * component declares of it is written. Resolves once the broker has it; nothing retries it.
7
+ * Throws for a name the component does not declare, or a payload its declaration does not admit.
8
+ */
9
+ send(name: string, payload?: object, options?: Options): Promise<void>;
10
+ }
11
+ /** What a fact is said to be of: the operation knows whose it is, the extension does not. */
12
+ export interface Options {
13
+ /** the identity the fact is of */
14
+ identity?: string;
15
+ }
@@ -0,0 +1,2 @@
1
+ export { Factory } from './Factory.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,13 @@
1
+ import type { Settings } from '@toa.io/definitions/extensions.chronicles';
2
+ /** Where the log is published and read, and what it is kept of, as the service is deployed with them. */
3
+ export declare function settings(): Settings;
4
+ /** The users of the broker the rows are published to, and of the store they are read from. */
5
+ export declare function credentials(): Credentials;
6
+ export interface Credentials {
7
+ broker: User;
8
+ store: User;
9
+ }
10
+ export interface User {
11
+ username: string;
12
+ password: string;
13
+ }
@@ -0,0 +1,48 @@
1
+ import { environment } from '@toa.io/generic';
2
+ import { KEYS, SETTINGS } from '@toa.io/definitions/extensions.chronicles';
3
+ /** Where the log is published and read, and what it is kept of, as the service is deployed with them. */
4
+ export function settings() {
5
+ const value = environment.get(SETTINGS);
6
+ if (value !== undefined)
7
+ return JSON.parse(value);
8
+ if (dev())
9
+ return DEV;
10
+ throw new Error(`${SETTINGS} is not set, so nothing says where the log is kept.`);
11
+ }
12
+ /** The users of the broker the rows are published to, and of the store they are read from. */
13
+ export function credentials() {
14
+ const [brokerUsername, brokerPassword, storeUsername, storePassword] = KEYS.map((key) => environment.get(`${SETTINGS}_${key.toUpperCase()}`));
15
+ if (brokerUsername !== undefined &&
16
+ brokerPassword !== undefined &&
17
+ storeUsername !== undefined &&
18
+ storePassword !== undefined)
19
+ return {
20
+ broker: { username: brokerUsername, password: brokerPassword },
21
+ store: { username: storeUsername, password: storePassword }
22
+ };
23
+ // the development stack's broker, and the context's user of its store, as the reference setup
24
+ // makes one
25
+ if (dev())
26
+ return {
27
+ broker: { username: 'developer', password: 'secret' },
28
+ store: { username: environment.scope(), password: 'secret' }
29
+ };
30
+ throw new Error(`${SETTINGS}_{${KEYS.join(',').toUpperCase()}} are not all set.`);
31
+ }
32
+ function dev() {
33
+ return environment.get('TOA_DEV') === '1';
34
+ }
35
+ // Toa's own development stack is not on the conventional ports, which the applications built on
36
+ // Toa are on. See CONTRIBUTING.md.
37
+ const DEV = {
38
+ broker: 'amqp://localhost:31010',
39
+ store: { provider: 'clickhouse', url: 'http://localhost:31030' },
40
+ encounters: true,
41
+ ip: 'truncated',
42
+ events: {},
43
+ states: {},
44
+ facts: {},
45
+ identities: {},
46
+ timestamps: {}
47
+ };
48
+ //# sourceMappingURL=settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../source/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAA;AAG1E,yGAAyG;AACzG,MAAM,UAAU,QAAQ;IACtB,MAAM,KAAK,GA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CAAC,KAAK,GAAG,CAAA;AAC3C,CAAC;AAED,gGAAgG;AAChG,mCAAmC;AACnC,MAAM,GAAG,GAAa;IACpB,MAAM,EAAE,wBAAwB;IAChC,KAAK,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,EAAE,wBAAwB,EAAE;IAChE,UAAU,EAAE,IAAI;IAChB,EAAE,EAAE,WAAW;IACf,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;IACV,KAAK,EAAE,EAAE;IACT,UAAU,EAAE,EAAE;IACd,UAAU,EAAE,EAAE;CACf,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { Provider } from './Provider.ts';
2
+ import type { User } from './settings.ts';
3
+ import type { Settings } from '@toa.io/definitions/extensions.chronicles';
4
+ /** The provider the annotation names, read as the context's user of it. */
5
+ export declare function provider(settings: Settings, user: User, scope: string): Provider;
@@ -0,0 +1,11 @@
1
+ import { ClickHouseProvider } from './clickhouse/Provider.js';
2
+ /** The provider the annotation names, read as the context's user of it. */
3
+ export function provider(settings, user, scope) {
4
+ switch (settings.store.provider) {
5
+ case 'clickhouse':
6
+ return new ClickHouseProvider(settings.store.url, user, scope);
7
+ default:
8
+ throw new Error(`Chronicles have no store '${String(settings.store.provider)}'`);
9
+ }
10
+ }
11
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../source/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAK7D,2EAA2E;AAC3E,MAAM,UAAU,QAAQ,CAAC,QAAkB,EAAE,IAAU,EAAE,KAAa;IACpE,QAAQ,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAChC,KAAK,YAAY;YACf,OAAO,IAAI,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;QAChE;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IACpF,CAAC;AACH,CAAC"}
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.