@reventlessdev/reventless-core 3.0.0-alpha.327 → 3.0.0-alpha.329
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/CHANGELOG.md +18 -0
- package/package.json +8 -8
- package/src/CommandSent.res +22 -0
- package/src/CommandSent.res.mjs +22 -0
- package/src/Projection.res +26 -1
- package/src/Projection.res.mjs +19 -1
- package/src/RowChange.res +37 -0
- package/src/RowChange.res.mjs +62 -0
- package/src/components/Api/GraphQL_FragmentGenerator.res +22 -0
- package/src/components/Api/GraphQL_FragmentGenerator.res.mjs +20 -4
- package/src/components/Api/GraphQL_SchemaInspector.res.mjs +2 -2
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +1 -0
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +4 -2
- package/src/components/CommandGenerator/CommandGenerator_Callback.res +2 -1
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +1 -1
- package/src/components/CommandTopic/CommandTopic.res.mjs +6 -0
- package/src/components/CommandTopic/CommandTopic_Helpers.res +44 -2
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +69 -11
- package/src/components/EventMapper/EventMapper_Callback.res +8 -2
- package/src/components/EventMapper/EventMapper_Callback.res.mjs +3 -2
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res +5 -1
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res.mjs +2 -1
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +4 -0
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +3 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +4 -0
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +4 -2
- package/src/components/QueryDb/QueryDb_Operations.res +2 -0
- package/src/components/QueryDb/QueryDb_Operations.res.mjs +3 -0
- package/src/components/Task/Task_Builder.res +5 -3
- package/src/components/Task/Task_Builder.res.mjs +2 -1
- package/src/plugin/component/Plugin_Callback.res +6 -2
- package/src/plugin/component/Plugin_Callback.res.mjs +3 -2
- package/src/util/Metrics.res +151 -16
- package/src/util/Metrics.res.mjs +123 -3
- package/tests/api/GraphQL_FragmentGeneratorTest.res.mjs +2 -2
- package/tests/api/IdentitySemanticTest.res.mjs +1 -1
- package/tests/commandgenerator/CommandGeneratorCallbackTest.res +33 -0
- package/tests/commandgenerator/CommandGeneratorCallbackTest.res.mjs +51 -0
- package/tests/commandtopic/CommandOutcomeLineTest.res +121 -0
- package/tests/commandtopic/CommandOutcomeLineTest.res.mjs +149 -0
- package/tests/querydb/RowChangeTest.res +87 -0
- package/tests/querydb/RowChangeTest.res.mjs +157 -0
- package/tests/util/MetricsTest.res +72 -0
- package/tests/util/MetricsTest.res.mjs +108 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 3.0.0-alpha.329 (2026-11-05)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* each command's outcome is written as a line of its own ([84e5e3f](https://github.com/ReventlessDev/reventless-core/commit/84e5e3fa4d77e629c6f72d9079a8f82f6b26a5ac))
|
|
11
|
+
* the API's line names the door a command came through ([e1f707f](https://github.com/ReventlessDev/reventless-core/commit/e1f707f2bff6e6fe29c43557e294b86a07c075fc))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# 3.0.0-alpha.328 (2026-11-02)
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* a view row knows its last change, and the local platform keeps every change ([1a1fd71](https://github.com/ReventlessDev/reventless-core/commit/1a1fd7117d9837696a7c0080dcd6f0983e57780c))
|
|
19
|
+
* every component that sends a command names it in a line of its own ([84d5742](https://github.com/ReventlessDev/reventless-core/commit/84d57420fe58d47f483e726d1748b1a98da7f1b8))
|
|
20
|
+
* **local:** the app's API logs each request and subscription it answers ([31a163c](https://github.com/ReventlessDev/reventless-core/commit/31a163c945d8929e9a604cc0dc8a74939320f85e))
|
|
21
|
+
* **local:** the local platform counts its metrics instead of logging them ([76c6094](https://github.com/ReventlessDev/reventless-core/commit/76c60946fa74520519dccb4ae39fae5880817832))
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
# 3.0.0-alpha.327 (2026-11-01)
|
|
7
25
|
|
|
8
26
|
### Features
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.329",
|
|
4
4
|
"description": "Core package for Reventless framework",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"jest": {
|
|
@@ -28,17 +28,17 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"sury": "11.0.0",
|
|
30
30
|
"uuid": "^13.0.0",
|
|
31
|
-
"@reventlessdev/rescript-fast-csv": "2.0.0-alpha.
|
|
32
|
-
"@reventlessdev/rescript-effect": "1.0.0-alpha.1",
|
|
31
|
+
"@reventlessdev/rescript-fast-csv": "2.0.0-alpha.26",
|
|
33
32
|
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
|
|
34
33
|
"@reventlessdev/rescript-jest": "1.0.0-alpha.13",
|
|
35
|
-
"@reventlessdev/rescript-node": "2.0.0-alpha.
|
|
34
|
+
"@reventlessdev/rescript-node": "2.0.0-alpha.26",
|
|
35
|
+
"@reventlessdev/rescript-effect": "1.0.0-alpha.1",
|
|
36
36
|
"@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
|
|
37
|
-
"@reventlessdev/rescript-ssh2": "2.0.0-alpha.26",
|
|
38
37
|
"@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
|
|
39
|
-
"@reventlessdev/
|
|
40
|
-
"@reventlessdev/reventless-
|
|
41
|
-
"@reventlessdev/reventless-
|
|
38
|
+
"@reventlessdev/rescript-ssh2": "2.0.0-alpha.27",
|
|
39
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.223",
|
|
40
|
+
"@reventlessdev/reventless-spec": "3.0.0-alpha.194",
|
|
41
|
+
"@reventlessdev/reventless-interop": "3.0.0-alpha.42"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"rescript": "12.3.1",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The line a component writes when it sends a command, under its own name and with the
|
|
2
|
+
// command's ids: `AutomationSlice(NotificationIntake) sending command: RequestNotification({…})`.
|
|
3
|
+
// The plugin's command topic publishes for every sender alike and cannot say whose a command
|
|
4
|
+
// is; this line does, as the API's `generated command` and a contract's `EP→` line do.
|
|
5
|
+
|
|
6
|
+
let log = (~comp: string, cmdJson: Message.commandJson) =>
|
|
7
|
+
EffectLogger.logInfo(
|
|
8
|
+
~comp,
|
|
9
|
+
~ids=EffectLogger.idsOf(cmdJson.meta),
|
|
10
|
+
~detail=cmdJson.commandJson,
|
|
11
|
+
`sending command: ${LogFormat.cmdDetailNoId(cmdJson)}`,
|
|
12
|
+
)->Effect.runSync
|
|
13
|
+
|
|
14
|
+
/** The same publishing, each command announced first under `comp`. */
|
|
15
|
+
let announcing = (
|
|
16
|
+
~comp: string,
|
|
17
|
+
publishJsons: ReventlessInfra.CommandTopic.publishJsons,
|
|
18
|
+
): ReventlessInfra.CommandTopic.publishJsons =>
|
|
19
|
+
cmdJsons => {
|
|
20
|
+
cmdJsons->Array.forEach(cmdJson => log(~comp, cmdJson))
|
|
21
|
+
publishJsons(cmdJsons)
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as LogFormat$ReventlessCore from "./util/LogFormat.res.mjs";
|
|
5
|
+
import * as EffectLogger$ReventlessCore from "./util/EffectLogger.res.mjs";
|
|
6
|
+
|
|
7
|
+
function log(comp, cmdJson) {
|
|
8
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, cmdJson.commandJson, EffectLogger$ReventlessCore.idsOf(undefined, undefined, cmdJson.meta), `sending command: ` + LogFormat$ReventlessCore.cmdDetailNoId(cmdJson)));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function announcing(comp, publishJsons) {
|
|
12
|
+
return cmdJsons => {
|
|
13
|
+
cmdJsons.forEach(cmdJson => log(comp, cmdJson));
|
|
14
|
+
return publishJsons(cmdJsons);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
log,
|
|
20
|
+
announcing,
|
|
21
|
+
}
|
|
22
|
+
/* effect/Effect Not a pure module */
|
package/src/Projection.res
CHANGED
|
@@ -303,7 +303,7 @@ let stateToString: 'a => string = state =>
|
|
|
303
303
|
let statesToString: array<'a> => string = states =>
|
|
304
304
|
states->Array.map(stateToString)->Array.joinUnsafe(", ")
|
|
305
305
|
|
|
306
|
-
let
|
|
306
|
+
let applyAction = async (
|
|
307
307
|
~comp="Projection",
|
|
308
308
|
~sources: array<changeSource>=[],
|
|
309
309
|
~onChange: option<rowChange<'state> => unit>=?,
|
|
@@ -491,6 +491,31 @@ let handleAction = async (
|
|
|
491
491
|
}
|
|
492
492
|
}
|
|
493
493
|
|
|
494
|
+
/** Applies one action to the store, its rows stamped with the last of its sources as their
|
|
495
|
+
`_change` ([RowChange]). Without a source the rows are written unstamped. */
|
|
496
|
+
let handleAction = (
|
|
497
|
+
~comp="Projection",
|
|
498
|
+
~sources: array<changeSource>=[],
|
|
499
|
+
~onChange: option<rowChange<'state> => unit>=?,
|
|
500
|
+
action,
|
|
501
|
+
operations,
|
|
502
|
+
subIdConfig,
|
|
503
|
+
) => {
|
|
504
|
+
let apply = () => applyAction(~comp, ~sources, ~onChange?, action, operations, subIdConfig)
|
|
505
|
+
switch sources->Array.at(-1) {
|
|
506
|
+
| Some(s) =>
|
|
507
|
+
RowChange.during(
|
|
508
|
+
{
|
|
509
|
+
flow: ?s.correlationId,
|
|
510
|
+
msgId: s.msgId,
|
|
511
|
+
at: Date.make()->Date.toISOString,
|
|
512
|
+
},
|
|
513
|
+
apply,
|
|
514
|
+
)
|
|
515
|
+
| None => apply()
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
494
519
|
let actionsWithId = action =>
|
|
495
520
|
switch action {
|
|
496
521
|
| Ignore => []
|
package/src/Projection.res.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import * as Message$ReventlessCore from "./Message.res.mjs";
|
|
|
20
20
|
import * as QueryDb$ReventlessCore from "./components/QueryDb/QueryDb.res.mjs";
|
|
21
21
|
import * as QueryDb$ReventlessInfra from "@reventlessdev/reventless-infra/src/components/QueryDb.res.mjs";
|
|
22
22
|
import * as LogFormat$ReventlessCore from "./util/LogFormat.res.mjs";
|
|
23
|
+
import * as RowChange$ReventlessCore from "./RowChange.res.mjs";
|
|
23
24
|
|
|
24
25
|
let log = Logger$ReventlessCore.fromEnv();
|
|
25
26
|
|
|
@@ -289,7 +290,7 @@ function statesToString(states) {
|
|
|
289
290
|
return states.map(stateToString).join(", ");
|
|
290
291
|
}
|
|
291
292
|
|
|
292
|
-
async function
|
|
293
|
+
async function applyAction($staropt$star, $staropt$star$1, onChange, action, operations, subIdConfig) {
|
|
293
294
|
let saveBatch = operations.saveBatch;
|
|
294
295
|
let save = operations.save;
|
|
295
296
|
let loadStream = operations.loadStream;
|
|
@@ -512,6 +513,22 @@ async function handleAction($staropt$star, $staropt$star$1, onChange, action, op
|
|
|
512
513
|
}
|
|
513
514
|
}
|
|
514
515
|
|
|
516
|
+
function handleAction(compOpt, sourcesOpt, onChange, action, operations, subIdConfig) {
|
|
517
|
+
let comp = compOpt !== undefined ? compOpt : "Projection";
|
|
518
|
+
let sources = sourcesOpt !== undefined ? sourcesOpt : [];
|
|
519
|
+
let apply = () => applyAction(comp, sources, onChange, action, operations, subIdConfig);
|
|
520
|
+
let s = sources.at(-1);
|
|
521
|
+
if (s !== undefined) {
|
|
522
|
+
return RowChange$ReventlessCore.during({
|
|
523
|
+
flow: s.correlationId,
|
|
524
|
+
msgId: s.msgId,
|
|
525
|
+
at: new Date().toISOString()
|
|
526
|
+
}, apply);
|
|
527
|
+
} else {
|
|
528
|
+
return apply();
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
515
532
|
function actionsWithId(action) {
|
|
516
533
|
if (typeof action !== "object") {
|
|
517
534
|
return [];
|
|
@@ -896,6 +913,7 @@ export {
|
|
|
896
913
|
applyChanges,
|
|
897
914
|
stateToString,
|
|
898
915
|
statesToString,
|
|
916
|
+
applyAction,
|
|
899
917
|
handleAction,
|
|
900
918
|
actionsWithId,
|
|
901
919
|
groupSourcedById,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// The change a projection is writing, stamped on the rows it writes as `_change`: the flow,
|
|
2
|
+
// the event and the time. A projection runs each action `during` its change; the encoder
|
|
3
|
+
// that turns a row into JSON reads it back with `stampInto`. The value follows the call
|
|
4
|
+
// and what it awaits, so rows written at the same time each get their own.
|
|
5
|
+
|
|
6
|
+
/** The last change of a row: its flow, the event behind it, and when it was written. */
|
|
7
|
+
type t = {flow?: string, msgId: string, at: string}
|
|
8
|
+
|
|
9
|
+
/** The key a row carries it under; no state field may use it. */
|
|
10
|
+
let key = "_change"
|
|
11
|
+
|
|
12
|
+
let storage: NodeAsyncHooks.asyncLocalStorage<t> = NodeAsyncHooks.makeAsyncLocalStorage()
|
|
13
|
+
|
|
14
|
+
/** Runs `f` with `change` as the change its writes stamp. */
|
|
15
|
+
let during = (change: t, f: unit => 'a): 'a => storage->NodeAsyncHooks.run(change, f)
|
|
16
|
+
|
|
17
|
+
/** The change being written, outside a projection none. */
|
|
18
|
+
let current = (): option<t> => storage->NodeAsyncHooks.getStore
|
|
19
|
+
|
|
20
|
+
let toJson = (c: t): JSON.t =>
|
|
21
|
+
[("msgId", JSON.Encode.string(c.msgId)), ("at", JSON.Encode.string(c.at))]
|
|
22
|
+
->Array.concat(c.flow->Option.mapOr([], f => [("flow", JSON.Encode.string(f))]))
|
|
23
|
+
->Dict.fromArray
|
|
24
|
+
->JSON.Encode.object
|
|
25
|
+
|
|
26
|
+
/** Adds the current change to a row about to be stored. */
|
|
27
|
+
let stampInto = (row: dict<JSON.t>) => current()->Option.forEach(c => row->Dict.set(key, toJson(c)))
|
|
28
|
+
|
|
29
|
+
/** The same for a row as JSON; a value that is not an object is left as it is. */
|
|
30
|
+
let stamp = (row: JSON.t): JSON.t =>
|
|
31
|
+
switch (current(), row) {
|
|
32
|
+
| (Some(c), JSON.Object(d)) =>
|
|
33
|
+
let d = d->Dict.copy
|
|
34
|
+
d->Dict.set(key, toJson(c))
|
|
35
|
+
JSON.Object(d)
|
|
36
|
+
| _ => row
|
|
37
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
|
+
import * as Nodeasync_hooks from "node:async_hooks";
|
|
5
|
+
|
|
6
|
+
let key = "_change";
|
|
7
|
+
|
|
8
|
+
let storage = new Nodeasync_hooks.AsyncLocalStorage();
|
|
9
|
+
|
|
10
|
+
function during(change, f) {
|
|
11
|
+
return storage.run(change, f);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function current() {
|
|
15
|
+
return storage.getStore();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function toJson(c) {
|
|
19
|
+
return Object.fromEntries([
|
|
20
|
+
[
|
|
21
|
+
"msgId",
|
|
22
|
+
c.msgId
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
"at",
|
|
26
|
+
c.at
|
|
27
|
+
]
|
|
28
|
+
].concat(Stdlib_Option.mapOr(c.flow, [], f => [[
|
|
29
|
+
"flow",
|
|
30
|
+
f
|
|
31
|
+
]])));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function stampInto(row) {
|
|
35
|
+
Stdlib_Option.forEach(storage.getStore(), c => {
|
|
36
|
+
row[key] = toJson(c);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function stamp(row) {
|
|
41
|
+
let match = storage.getStore();
|
|
42
|
+
if (match === undefined) {
|
|
43
|
+
return row;
|
|
44
|
+
}
|
|
45
|
+
if (typeof row !== "object" || row === null || Array.isArray(row)) {
|
|
46
|
+
return row;
|
|
47
|
+
}
|
|
48
|
+
let d = Object.assign({}, row);
|
|
49
|
+
d[key] = toJson(match);
|
|
50
|
+
return d;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
key,
|
|
55
|
+
storage,
|
|
56
|
+
during,
|
|
57
|
+
current,
|
|
58
|
+
toJson,
|
|
59
|
+
stampInto,
|
|
60
|
+
stamp,
|
|
61
|
+
}
|
|
62
|
+
/* storage Not a pure module */
|
|
@@ -38,6 +38,15 @@ let commandResultSdlTypes: array<string> = [
|
|
|
38
38
|
}`,
|
|
39
39
|
]
|
|
40
40
|
|
|
41
|
+
// The last change a view row was written by: its flow, the event behind it and the time
|
|
42
|
+
// (`RowChange`). Every view type carries it as `_change`, answered to elevated callers only;
|
|
43
|
+
// emitted once per fragment that has a view, deduped by name like the command results.
|
|
44
|
+
let rowChangeSdlType = `type RowChange {
|
|
45
|
+
flow: String
|
|
46
|
+
msgId: String!
|
|
47
|
+
at: String!
|
|
48
|
+
}`
|
|
49
|
+
|
|
41
50
|
// ── SchemaType → GraphQL type reference ──────────────────────────────────────
|
|
42
51
|
|
|
43
52
|
let rec fromSchemaType = (
|
|
@@ -196,6 +205,7 @@ let deriveObjectTypeWithNested = (
|
|
|
196
205
|
~excludeFields: array<string>=[],
|
|
197
206
|
~includeIdParam: bool=true,
|
|
198
207
|
~resolvedFields: array<resolvedFieldEntry>=[],
|
|
208
|
+
~rowChange: bool=false,
|
|
199
209
|
schema: S.t<unknown>,
|
|
200
210
|
): array<string> => {
|
|
201
211
|
reportUnclassifiedUnions(~typeName, schema)
|
|
@@ -241,6 +251,14 @@ let deriveObjectTypeWithNested = (
|
|
|
241
251
|
} else {
|
|
242
252
|
mainType
|
|
243
253
|
}
|
|
254
|
+
if rowChange && filteredFields->Dict.get(RowChange.key)->Option.isSome {
|
|
255
|
+
JsError.throwWithMessage(
|
|
256
|
+
`${typeName}.${RowChange.key} is a field of the state record, and every view row carries its last change under that name. Name the field something else.`,
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
let mainTypeWithId = rowChange
|
|
260
|
+
? mainTypeWithId->String.replace("{\n", `{\n ${RowChange.key}: RowChange\n`)
|
|
261
|
+
: mainTypeWithId
|
|
244
262
|
// A cross-table field shares the type with the state record's own fields, so
|
|
245
263
|
// a name already taken would emit the field twice and fail the whole document
|
|
246
264
|
// — for every plugin in the merge, not just this one. Refuse at build time,
|
|
@@ -935,6 +953,7 @@ let generate = (
|
|
|
935
953
|
~excludeFields,
|
|
936
954
|
~includeIdParam,
|
|
937
955
|
~resolvedFields=entry.resolvedFields->Option.getOr([]),
|
|
956
|
+
~rowChange=true,
|
|
938
957
|
entry.stateSchema,
|
|
939
958
|
)
|
|
940
959
|
nestedTypes->Array.forEach(t => {
|
|
@@ -1080,6 +1099,9 @@ let generate = (
|
|
|
1080
1099
|
if mutations->Array.length > 0 {
|
|
1081
1100
|
commandResultSdlTypes->Array.forEach(t => types->Array.push(t))
|
|
1082
1101
|
}
|
|
1102
|
+
if queryEntries->Array.length > 0 {
|
|
1103
|
+
types->Array.push(rowChangeSdlType)
|
|
1104
|
+
}
|
|
1083
1105
|
|
|
1084
1106
|
GraphQL_Stitcher.encode({
|
|
1085
1107
|
types,
|
|
@@ -8,6 +8,7 @@ import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js
|
|
|
8
8
|
import * as Semantic$Reventless from "@reventlessdev/reventless-spec/src/semantic/Semantic.res.mjs";
|
|
9
9
|
import * as ReadModel$Reventless from "@reventlessdev/reventless-spec/src/components/ReadModel.res.mjs";
|
|
10
10
|
import * as Logger$ReventlessCore from "../../util/Logger.res.mjs";
|
|
11
|
+
import * as RowChange$ReventlessCore from "../../RowChange.res.mjs";
|
|
11
12
|
import * as Api_Naming$ReventlessCore from "./Api_Naming.res.mjs";
|
|
12
13
|
import * as SchemaType$ReventlessCore from "./SchemaType.res.mjs";
|
|
13
14
|
import * as SchemaWalker$ReventlessCore from "../../plugin/component/SchemaWalker.res.mjs";
|
|
@@ -39,6 +40,12 @@ let commandResultSdlTypes = [
|
|
|
39
40
|
}`
|
|
40
41
|
];
|
|
41
42
|
|
|
43
|
+
let rowChangeSdlType = `type RowChange {
|
|
44
|
+
flow: String
|
|
45
|
+
msgId: String!
|
|
46
|
+
at: String!
|
|
47
|
+
}`;
|
|
48
|
+
|
|
42
49
|
function fromSchemaType(_required, _asInputOpt, _st, collectedTypes, seenTypes) {
|
|
43
50
|
while (true) {
|
|
44
51
|
let asInputOpt = _asInputOpt;
|
|
@@ -156,10 +163,11 @@ function resolvedFieldSdl(param) {
|
|
|
156
163
|
}
|
|
157
164
|
}
|
|
158
165
|
|
|
159
|
-
function deriveObjectTypeWithNested(typeName, excludeFieldsOpt, includeIdParamOpt, resolvedFieldsOpt, schema) {
|
|
166
|
+
function deriveObjectTypeWithNested(typeName, excludeFieldsOpt, includeIdParamOpt, resolvedFieldsOpt, rowChangeOpt, schema) {
|
|
160
167
|
let excludeFields = excludeFieldsOpt !== undefined ? excludeFieldsOpt : [];
|
|
161
168
|
let includeIdParam = includeIdParamOpt !== undefined ? includeIdParamOpt : true;
|
|
162
169
|
let resolvedFields = resolvedFieldsOpt !== undefined ? resolvedFieldsOpt : [];
|
|
170
|
+
let rowChange = rowChangeOpt !== undefined ? rowChangeOpt : false;
|
|
163
171
|
reportUnclassifiedUnions(typeName, schema);
|
|
164
172
|
let fields = SchemaType$ReventlessCore.fromSuryObject(typeName, schema);
|
|
165
173
|
if (fields === undefined) {
|
|
@@ -186,6 +194,10 @@ function deriveObjectTypeWithNested(typeName, excludeFieldsOpt, includeIdParamOp
|
|
|
186
194
|
seenTypes.add(typeName);
|
|
187
195
|
let mainType = objectRefToGraphQL(undefined, typeName, filteredFields, collectedTypes, seenTypes);
|
|
188
196
|
let mainTypeWithId = includeIdParam ? mainType.replace(`type ` + typeName + ` {\n`, `type ` + typeName + ` implements Node {\n id: ID!\n`) : mainType;
|
|
197
|
+
if (rowChange && Stdlib_Option.isSome(filteredFields[RowChange$ReventlessCore.key])) {
|
|
198
|
+
Stdlib_JsError.throwWithMessage(typeName + `.` + RowChange$ReventlessCore.key + ` is a field of the state record, and every view row carries its last change under that name. Name the field something else.`);
|
|
199
|
+
}
|
|
200
|
+
let mainTypeWithId$1 = rowChange ? mainTypeWithId.replace("{\n", `{\n ` + RowChange$ReventlessCore.key + `: RowChange\n`) : mainTypeWithId;
|
|
189
201
|
resolvedFields.forEach(param => {
|
|
190
202
|
let fieldName = param.fieldName;
|
|
191
203
|
if (Stdlib_Option.isSome(filteredFields[fieldName]) || includeIdParam && fieldName === "id") {
|
|
@@ -194,9 +206,9 @@ function deriveObjectTypeWithNested(typeName, excludeFieldsOpt, includeIdParamOp
|
|
|
194
206
|
});
|
|
195
207
|
let mainTypeComplete;
|
|
196
208
|
if (resolvedFields.length === 0) {
|
|
197
|
-
mainTypeComplete = mainTypeWithId;
|
|
209
|
+
mainTypeComplete = mainTypeWithId$1;
|
|
198
210
|
} else {
|
|
199
|
-
let body = mainTypeWithId.slice(0, mainTypeWithId.length - 1 | 0);
|
|
211
|
+
let body = mainTypeWithId$1.slice(0, mainTypeWithId$1.length - 1 | 0);
|
|
200
212
|
mainTypeComplete = body + resolvedFields.map(resolvedFieldSdl).join("\n") + "\n}";
|
|
201
213
|
}
|
|
202
214
|
return collectedTypes.concat([mainTypeComplete]);
|
|
@@ -624,7 +636,7 @@ function generate(mutationEntries, queryEntries) {
|
|
|
624
636
|
seenTypes.add(entry.returnTypeName);
|
|
625
637
|
let fields = entry.excludeFields;
|
|
626
638
|
let excludeFields = fields !== undefined ? fields : [];
|
|
627
|
-
let nestedTypes = deriveObjectTypeWithNested(entry.returnTypeName, excludeFields, includeIdParam, Stdlib_Option.getOr(entry.resolvedFields, []), entry.stateSchema);
|
|
639
|
+
let nestedTypes = deriveObjectTypeWithNested(entry.returnTypeName, excludeFields, includeIdParam, Stdlib_Option.getOr(entry.resolvedFields, []), true, entry.stateSchema);
|
|
628
640
|
nestedTypes.forEach(t => {
|
|
629
641
|
types.push(t);
|
|
630
642
|
});
|
|
@@ -703,6 +715,9 @@ function generate(mutationEntries, queryEntries) {
|
|
|
703
715
|
types.push(t);
|
|
704
716
|
});
|
|
705
717
|
}
|
|
718
|
+
if (queryEntries.length !== 0) {
|
|
719
|
+
types.push(rowChangeSdlType);
|
|
720
|
+
}
|
|
706
721
|
return GraphQL_Stitcher$ReventlessCore.encode({
|
|
707
722
|
types: types,
|
|
708
723
|
mutations: mutations,
|
|
@@ -715,6 +730,7 @@ function generate(mutationEntries, queryEntries) {
|
|
|
715
730
|
export {
|
|
716
731
|
log,
|
|
717
732
|
commandResultSdlTypes,
|
|
733
|
+
rowChangeSdlType,
|
|
718
734
|
fromSchemaType,
|
|
719
735
|
objectRefToGraphQL,
|
|
720
736
|
deriveFieldType,
|
|
@@ -13,7 +13,7 @@ function inspectScalar(schema) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function inspectObjectType(typeName, schema) {
|
|
16
|
-
let types = GraphQL_FragmentGenerator$ReventlessCore.deriveObjectTypeWithNested(typeName, undefined, undefined, undefined, schema);
|
|
16
|
+
let types = GraphQL_FragmentGenerator$ReventlessCore.deriveObjectTypeWithNested(typeName, undefined, undefined, undefined, undefined, schema);
|
|
17
17
|
return types[types.length - 1 | 0];
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -42,7 +42,7 @@ function inspectMutationFields(fieldPrefix, commandSchema) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
function inspectQueryFields(name, typeName, stateSchema) {
|
|
45
|
-
let types = GraphQL_FragmentGenerator$ReventlessCore.deriveObjectTypeWithNested(typeName, undefined, undefined, undefined, stateSchema);
|
|
45
|
+
let types = GraphQL_FragmentGenerator$ReventlessCore.deriveObjectTypeWithNested(typeName, undefined, undefined, undefined, undefined, stateSchema);
|
|
46
46
|
let typeDef = types[types.length - 1 | 0];
|
|
47
47
|
let singleQuery = GraphQL_FragmentGenerator$ReventlessCore.deriveObjectQueryField(name, typeName, undefined, undefined);
|
|
48
48
|
let pluralName = name + "s";
|
|
@@ -462,6 +462,7 @@ module Make = (
|
|
|
462
462
|
}
|
|
463
463
|
|
|
464
464
|
let phase2 = async (publishJsons: ReventlessInfra.CommandTopic.publishJsons) => {
|
|
465
|
+
let publishJsons = CommandSent.announcing(~comp=`AutomationSlice(${Spec.name})`, publishJsons)
|
|
465
466
|
let currentTime = await Clock.currentTimeMillis->Effect.runPromise
|
|
466
467
|
// A `Failed` row at or past the ceiling is one an older build left stranded,
|
|
467
468
|
// or one whose Spec lowered `maxRetries` under it. Either way it is abandoned
|
|
@@ -15,6 +15,7 @@ import * as Message$Reventless from "@reventlessdev/reventless-spec/src/types/Me
|
|
|
15
15
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
16
16
|
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
17
17
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
18
|
+
import * as CommandSent$ReventlessCore from "../../CommandSent.res.mjs";
|
|
18
19
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
19
20
|
import * as AutomationSlice_Route$ReventlessCore from "./AutomationSlice_Route.res.mjs";
|
|
20
21
|
import * as AutomationSlice_Schedules$ReventlessCore from "./AutomationSlice_Schedules.res.mjs";
|
|
@@ -326,6 +327,7 @@ function Make(Spec) {
|
|
|
326
327
|
scheduleChanges.contents = [];
|
|
327
328
|
};
|
|
328
329
|
let phase2 = async publishJsons => {
|
|
330
|
+
let publishJsons$1 = CommandSent$ReventlessCore.announcing(`AutomationSlice(` + Spec.name + `)`, publishJsons);
|
|
329
331
|
let currentTime = await Effect.runPromise(Clock.currentTimeMillis);
|
|
330
332
|
let newlyAbandoned = [];
|
|
331
333
|
Object.entries(todoItems).forEach(param => {
|
|
@@ -424,7 +426,7 @@ function Make(Spec) {
|
|
|
424
426
|
}
|
|
425
427
|
if (commands.length !== 0) {
|
|
426
428
|
try {
|
|
427
|
-
await publishJsons(commands);
|
|
429
|
+
await publishJsons$1(commands);
|
|
428
430
|
} catch (raw_exn$1) {
|
|
429
431
|
let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
|
|
430
432
|
let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$1), Stdlib_JsExn.message), "unknown");
|
|
@@ -462,7 +464,7 @@ function Make(Spec) {
|
|
|
462
464
|
return;
|
|
463
465
|
}
|
|
464
466
|
try {
|
|
465
|
-
return await publishJsons(abandonmentCommands);
|
|
467
|
+
return await publishJsons$1(abandonmentCommands);
|
|
466
468
|
} catch (raw_exn$2) {
|
|
467
469
|
let exn$2 = Primitive_exceptions.internalToException(raw_exn$2);
|
|
468
470
|
let errMsg$2 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$2), Stdlib_JsExn.message), "unknown");
|
|
@@ -222,12 +222,13 @@ let makeGenerateCommand = (
|
|
|
222
222
|
// Render `Name({fields})` without the standalone id: it's the command's
|
|
223
223
|
// partition-tag value, already shown among the fields, so a leading
|
|
224
224
|
// `(id)` would just duplicate it.
|
|
225
|
+
// `via` names the door the request came through: `Mutation.<field>`, `mcp/tools/<tool>`.
|
|
225
226
|
EffectLogger.logInfo(
|
|
226
227
|
~comp=`CommandGenerator(${serviceName})`,
|
|
227
228
|
~ids=EffectLogger.idsOf(meta),
|
|
228
229
|
~detail=commandJson,
|
|
229
230
|
`generated command: ${commandJson->LogFormat.cmdLabelOfJson}`,
|
|
230
|
-
)
|
|
231
|
+
)->Effect.annotateLogs("via", payload.meta.info)
|
|
231
232
|
)
|
|
232
233
|
->Effect.flatMap(((meta, commandJson, id)) => {
|
|
233
234
|
switch commandJson->Message.decode(commandSchema) {
|
|
@@ -127,7 +127,7 @@ function makeGenerateCommand(publishJsons, publishJsonsAndWait, serviceName, com
|
|
|
127
127
|
];
|
|
128
128
|
}), param => {
|
|
129
129
|
let commandJson = param[1];
|
|
130
|
-
return EffectLogger$ReventlessCore.logInfo(`CommandGenerator(` + serviceName + `)`, commandJson, EffectLogger$ReventlessCore.idsOf(undefined, undefined, param[0]), `generated command: ` + LogFormat$ReventlessCore.cmdLabelOfJson(commandJson));
|
|
130
|
+
return Effect.annotateLogs(EffectLogger$ReventlessCore.logInfo(`CommandGenerator(` + serviceName + `)`, commandJson, EffectLogger$ReventlessCore.idsOf(undefined, undefined, param[0]), `generated command: ` + LogFormat$ReventlessCore.cmdLabelOfJson(commandJson)), "via", payload.meta.info);
|
|
131
131
|
}), param => {
|
|
132
132
|
let id = param[2];
|
|
133
133
|
let commandJson = param[1];
|
|
@@ -33,6 +33,10 @@ let registerCommandOutcome = CommandTopic_Helpers$ReventlessCore.registerCommand
|
|
|
33
33
|
|
|
34
34
|
let clearCommandOutcome = CommandTopic_Helpers$ReventlessCore.clearCommandOutcome;
|
|
35
35
|
|
|
36
|
+
let outcomeLines = CommandTopic_Helpers$ReventlessCore.outcomeLines;
|
|
37
|
+
|
|
38
|
+
let logOutcome = CommandTopic_Helpers$ReventlessCore.logOutcome;
|
|
39
|
+
|
|
36
40
|
let fireCommandOutcome = CommandTopic_Helpers$ReventlessCore.fireCommandOutcome;
|
|
37
41
|
|
|
38
42
|
let acceptedResultChannel = CommandTopic_Helpers$ReventlessCore.acceptedResultChannel;
|
|
@@ -69,6 +73,8 @@ export {
|
|
|
69
73
|
nextOutcomeHookId,
|
|
70
74
|
registerCommandOutcome,
|
|
71
75
|
clearCommandOutcome,
|
|
76
|
+
outcomeLines,
|
|
77
|
+
logOutcome,
|
|
72
78
|
fireCommandOutcome,
|
|
73
79
|
acceptedResultChannel,
|
|
74
80
|
rejectedResultChannel,
|
|
@@ -86,6 +86,42 @@ let clearCommandOutcome = () => {
|
|
|
86
86
|
commandOutcomeHooks := []
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/** Whether each outcome is also written as an info line, `command accepted` or `command
|
|
90
|
+
rejected`, under `CommandTopic(<component>)` with the command's ids: where a deployed
|
|
91
|
+
platform's tools read what became of a command. The local platform turns it off, since its
|
|
92
|
+
tap carries every outcome already. */
|
|
93
|
+
let outcomeLines = ref(true)
|
|
94
|
+
|
|
95
|
+
let logOutcome = (r: commandOutcomeReport) => {
|
|
96
|
+
let str = JSON.Encode.string
|
|
97
|
+
let (message, fields) = switch r.outcome {
|
|
98
|
+
| OutcomeAccepted({entityId, eventCount}) => (
|
|
99
|
+
"command accepted",
|
|
100
|
+
[("outcome", str("accepted")), ("eventCount", JSON.Encode.int(eventCount))]->Array.concat(
|
|
101
|
+
entityId->Option.mapOr([], e => [("entityId", str(e))]),
|
|
102
|
+
),
|
|
103
|
+
)
|
|
104
|
+
| OutcomeRejected({errorCode, cause}) => (
|
|
105
|
+
"command rejected",
|
|
106
|
+
[
|
|
107
|
+
("outcome", str("rejected")),
|
|
108
|
+
("errorCode", str(errorCode)),
|
|
109
|
+
("cause", str(refusalCauseToGraphQL(cause))),
|
|
110
|
+
],
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
EffectLogger.logInfo(
|
|
114
|
+
~comp=`CommandTopic(${r.component})`,
|
|
115
|
+
~ids={
|
|
116
|
+
msgId: r.reference,
|
|
117
|
+
correlationId: ?r.correlationId,
|
|
118
|
+
causationId: ?r.causationId,
|
|
119
|
+
},
|
|
120
|
+
~detail=JSON.Object(Dict.fromArray([("component", str(r.component))]->Array.concat(fields))),
|
|
121
|
+
message,
|
|
122
|
+
)->Effect.runSync
|
|
123
|
+
}
|
|
124
|
+
|
|
89
125
|
// Fired from reportAccepted/reportRejected below, which both write-side kinds call
|
|
90
126
|
// unconditionally — so this sees fire-and-forget dispatches too, not just the ones a
|
|
91
127
|
// producer awaited on the side-channels.
|
|
@@ -100,11 +136,16 @@ let fireCommandOutcome = (
|
|
|
100
136
|
~correlationId: option<string>=?,
|
|
101
137
|
~causationId: option<string>=?,
|
|
102
138
|
outcome: observedOutcome,
|
|
103
|
-
) =>
|
|
139
|
+
) => {
|
|
140
|
+
let report = {component, reference, ?correlationId, ?causationId, outcome}
|
|
141
|
+
if outcomeLines.contents {
|
|
142
|
+
try logOutcome(report) catch {
|
|
143
|
+
| _ => ()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
104
146
|
switch commandOutcomeHooks.contents {
|
|
105
147
|
| [] => ()
|
|
106
148
|
| hooks =>
|
|
107
|
-
let report = {component, reference, ?correlationId, ?causationId, outcome}
|
|
108
149
|
hooks->Array.forEach(({hook}) =>
|
|
109
150
|
switch hook(report) {
|
|
110
151
|
| () => ()
|
|
@@ -119,6 +160,7 @@ let fireCommandOutcome = (
|
|
|
119
160
|
}
|
|
120
161
|
)
|
|
121
162
|
}
|
|
163
|
+
}
|
|
122
164
|
|
|
123
165
|
// Side-channel for publishJsonsAndWait result propagation.
|
|
124
166
|
// Set by runInlineAndCollect before invoking the handler; cleared after.
|