@reventlessdev/reventless-core 3.0.0-alpha.211 → 3.0.0-alpha.213
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 +22 -0
- package/package.json +7 -7
- package/src/Projection.res +5 -2
- package/src/Projection.res.mjs +2 -1
- package/src/admin/Platform_AdminApi.res +2 -0
- package/src/admin/Platform_AdminApi.res.mjs +3 -1
- package/src/admin/Platform_ComponentDefinitionsApi.res +26 -5
- package/src/admin/Platform_ComponentDefinitionsApi.res.mjs +21 -5
- package/src/admin/Platform_PluginStructuresApi.res +132 -0
- package/src/admin/Platform_PluginStructuresApi.res.mjs +117 -0
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +30 -0
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +12 -0
- package/src/components/Dcb/Dcb_Builder.res +6 -2
- package/src/components/Dcb/Dcb_Builder.res.mjs +2 -2
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +32 -0
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +13 -0
- package/src/plugin/component/Plugin_Builder.res +6 -13
- package/src/plugin/component/Plugin_Builder.res.mjs +2 -16
- package/src/plugin/component/Plugin_Helpers.res +21 -3
- package/src/plugin/component/Plugin_Helpers.res.mjs +16 -0
- package/src/util/LogFormat.res +52 -1
- package/src/util/LogFormat.res.mjs +21 -2
- package/src/util/StoreLayout.res +38 -0
- package/src/util/StoreLayout.res.mjs +22 -0
- package/tests/admin/Platform_ComponentDefinitionsApiTest.res +12 -7
- package/tests/admin/Platform_ComponentDefinitionsApiTest.res.mjs +2 -2
- package/tests/admin/Platform_PluginStructuresApiTest.res +144 -0
- package/tests/admin/Platform_PluginStructuresApiTest.res.mjs +197 -0
- package/tests/api/GraphQL_FragmentGeneratorTest.res +40 -0
- package/tests/api/GraphQL_FragmentGeneratorTest.res.mjs +35 -0
- package/tests/logger/LogFormatTest.res +42 -0
- package/tests/logger/LogFormatTest.res.mjs +37 -0
|
@@ -22,6 +22,38 @@ type todoRow = {
|
|
|
22
22
|
lastError?: string,
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/** The item schema seen through the `JSON.t` the row actually stores.
|
|
26
|
+
|
|
27
|
+
`item` holds `Spec.outboundItemSchema`-encoded JSON, so the item schema
|
|
28
|
+
already describes the stored value exactly — only the ReScript types
|
|
29
|
+
disagree. */
|
|
30
|
+
external itemAsJson: S.t<'item> => S.t<JSON.t> = "%identity"
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
The row schema as the API describes it: `item` carried by the slice's own item
|
|
34
|
+
schema instead of as opaque JSON.
|
|
35
|
+
|
|
36
|
+
`todoRowSchema` types `item` as `JSON.t`, which the schema→GraphQL IR can only
|
|
37
|
+
classify as `Unknown` — and `Unknown` renders as `String!`. The field then
|
|
38
|
+
serves a stored object through a String, which fails at execution ("String
|
|
39
|
+
cannot represent value: { … }") the moment a client selects it. Describing the
|
|
40
|
+
item shape gives the field a real object type instead.
|
|
41
|
+
|
|
42
|
+
Shape only: never encode or parse a row with this. The runtime field is `JSON.t`
|
|
43
|
+
and the identity cast above would have `S.parseOrThrow` hand back an item where
|
|
44
|
+
the row's own code expects JSON.
|
|
45
|
+
*/
|
|
46
|
+
let todoRowSchemaFor = (itemSchema: S.t<'item>): S.t<todoRow> =>
|
|
47
|
+
S.schema(s => {
|
|
48
|
+
item: s.matches(itemSchema->itemAsJson),
|
|
49
|
+
status: s.matches(todoStatusSchema),
|
|
50
|
+
createdAt: s.matches(S.string),
|
|
51
|
+
processedAt: ?s.matches(S.option(S.string)),
|
|
52
|
+
completedAt: ?s.matches(S.option(S.string)),
|
|
53
|
+
retryCount: s.matches(S.int),
|
|
54
|
+
lastError: ?s.matches(S.option(S.string)),
|
|
55
|
+
})
|
|
56
|
+
|
|
25
57
|
/**
|
|
26
58
|
The runtime protocol between a built callback and whoever drives it.
|
|
27
59
|
|
|
@@ -29,6 +29,18 @@ let todoRowSchema = S.schema(s => ({
|
|
|
29
29
|
lastError: s.m(S.option(S.string))
|
|
30
30
|
}));
|
|
31
31
|
|
|
32
|
+
function todoRowSchemaFor(itemSchema) {
|
|
33
|
+
return S.schema(s => ({
|
|
34
|
+
item: s.m(itemSchema),
|
|
35
|
+
status: s.m(todoStatusSchema),
|
|
36
|
+
createdAt: s.m(S.string),
|
|
37
|
+
processedAt: s.m(S.option(S.string)),
|
|
38
|
+
completedAt: s.m(S.option(S.string)),
|
|
39
|
+
retryCount: s.m(S.int),
|
|
40
|
+
lastError: s.m(S.option(S.string))
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
|
|
32
44
|
function Make(Spec) {
|
|
33
45
|
return Translation => {
|
|
34
46
|
let todoItems = {};
|
|
@@ -168,6 +180,7 @@ function Make(Spec) {
|
|
|
168
180
|
export {
|
|
169
181
|
todoStatusSchema,
|
|
170
182
|
todoRowSchema,
|
|
183
|
+
todoRowSchemaFor,
|
|
171
184
|
Make,
|
|
172
185
|
}
|
|
173
186
|
/* Not a pure module */
|
|
@@ -621,20 +621,13 @@ module Make = (
|
|
|
621
621
|
|
|
622
622
|
// Offload the two large pluginDefinition fields at deploy time when a
|
|
623
623
|
// provider offers an object store (AWS writes a content-addressed object
|
|
624
|
-
// and returns a reference)
|
|
625
|
-
//
|
|
626
|
-
//
|
|
627
|
-
//
|
|
628
|
-
//
|
|
624
|
+
// and returns a reference). Computed HERE, at graph-construction time —
|
|
625
|
+
// both values are concrete and the hook (which creates the object resource)
|
|
626
|
+
// MUST run outside the Pulumi.Output.apply below: a resource cannot be
|
|
627
|
+
// created inside .apply, and an apply callback is skipped entirely on
|
|
628
|
+
// `pulumi preview` when its inputs are still unknown.
|
|
629
629
|
// Unconditional: these fields are always large enough to be worth offloading.
|
|
630
|
-
let toPayload =
|
|
631
|
-
switch Plugin_Helpers.offloadHook.contents {
|
|
632
|
-
| Some(hook) =>
|
|
633
|
-
Reventless.Offload.Offloaded(
|
|
634
|
-
hook(~store, ~bytes=value->S.reverseConvertToJsonStringOrThrow(schema)),
|
|
635
|
-
)
|
|
636
|
-
| None => Reventless.Offload.Inline(value)
|
|
637
|
-
}
|
|
630
|
+
let toPayload = Plugin_Helpers.offloadPayload
|
|
638
631
|
let apiSchemaFragmentPayload = toPayload(
|
|
639
632
|
apiSchemaFragment,
|
|
640
633
|
~schema=Reventless.Plugin.apiSchemaFragmentSchema,
|
|
@@ -425,22 +425,8 @@ function Make(Spec) {
|
|
|
425
425
|
});
|
|
426
426
|
let pushSchema = Spec.hooks.preResolversSchemaHook;
|
|
427
427
|
let schemaPushed = pushSchema !== undefined ? pushSchema(extra$1, version, apiSchemaFragment) : Pulumi.output();
|
|
428
|
-
let
|
|
429
|
-
|
|
430
|
-
if (hook !== undefined) {
|
|
431
|
-
return {
|
|
432
|
-
TAG: "Offloaded",
|
|
433
|
-
_0: hook(store, S.reverseConvertToJsonStringOrThrow(value, schema, undefined))
|
|
434
|
-
};
|
|
435
|
-
} else {
|
|
436
|
-
return {
|
|
437
|
-
TAG: "Inline",
|
|
438
|
-
_0: value
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
let apiSchemaFragmentPayload = toPayload(apiSchemaFragment, Plugin$Reventless.apiSchemaFragmentSchema, "pluginApiFragments");
|
|
443
|
-
let structurePayload = Stdlib_Option.map(pluginStructure, s => toPayload(s, Plugin$Reventless.pluginStructureSchema, "pluginStructures"));
|
|
428
|
+
let apiSchemaFragmentPayload = Plugin_Helpers$ReventlessCore.offloadPayload(apiSchemaFragment, Plugin$Reventless.apiSchemaFragmentSchema, "pluginApiFragments");
|
|
429
|
+
let structurePayload = Stdlib_Option.map(pluginStructure, s => Plugin_Helpers$ReventlessCore.offloadPayload(s, Plugin$Reventless.pluginStructureSchema, "pluginStructures"));
|
|
444
430
|
let builderOutputs = Pulumi.all([
|
|
445
431
|
Pulumi.all([
|
|
446
432
|
interstackAdminExtensionPoints,
|
|
@@ -788,9 +788,10 @@ let clearOnPluginDeployed = () => {
|
|
|
788
788
|
// ---------------------------------------------------------------------------
|
|
789
789
|
// Deploy-time offload hook — content-addresses a large pluginDefinition field
|
|
790
790
|
// to an object store and returns the reference. Set by a provider that can
|
|
791
|
-
// write objects (AWS creates a BucketObject
|
|
792
|
-
// the fields stay Inline. `bytes` is the
|
|
793
|
-
// the provider hashes it, stores it at
|
|
791
|
+
// write objects (AWS creates a BucketObject, local writes to its process-local
|
|
792
|
+
// object store); when unset the fields stay Inline. `bytes` is the
|
|
793
|
+
// already-serialized JSON of the value; the provider hashes it, stores it at
|
|
794
|
+
// `sha256/<hash>`, and returns the ref.
|
|
794
795
|
// Fired synchronously at graph-construction time (the value is concrete and a
|
|
795
796
|
// resource cannot be created inside a Pulumi.Output.apply).
|
|
796
797
|
// ---------------------------------------------------------------------------
|
|
@@ -806,6 +807,23 @@ let clearOffload = () => {
|
|
|
806
807
|
offloadHook.contents = None
|
|
807
808
|
}
|
|
808
809
|
|
|
810
|
+
/**
|
|
811
|
+
Carry a large `pluginDefinition` field by reference when a provider registered an
|
|
812
|
+
offload hook, inline otherwise.
|
|
813
|
+
|
|
814
|
+
One implementation for both construction sites — `Plugin_Builder`'s deploy-time
|
|
815
|
+
definition and the local platform's synthetic one — so a provider that offloads
|
|
816
|
+
cannot end up offloading through one path and inlining through the other.
|
|
817
|
+
*/
|
|
818
|
+
let offloadPayload = (value: 'a, ~schema: S.t<'a>, ~store: string): Reventless.Offload.payload<'a> =>
|
|
819
|
+
switch offloadHook.contents {
|
|
820
|
+
| Some(hook) =>
|
|
821
|
+
Reventless.Offload.Offloaded(
|
|
822
|
+
hook(~store, ~bytes=value->S.reverseConvertToJsonStringOrThrow(schema)),
|
|
823
|
+
)
|
|
824
|
+
| None => Reventless.Offload.Inline(value)
|
|
825
|
+
}
|
|
826
|
+
|
|
809
827
|
// ---------------------------------------------------------------------------
|
|
810
828
|
// Platform-deployed hook — fires after deployPlatform / makePlatform
|
|
811
829
|
// completes, providing platform-level metadata with resolved values.
|
|
@@ -430,6 +430,21 @@ function clearOffload() {
|
|
|
430
430
|
offloadHook.contents = undefined;
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
+
function offloadPayload(value, schema, store) {
|
|
434
|
+
let hook = offloadHook.contents;
|
|
435
|
+
if (hook !== undefined) {
|
|
436
|
+
return {
|
|
437
|
+
TAG: "Offloaded",
|
|
438
|
+
_0: hook(store, S.reverseConvertToJsonStringOrThrow(value, schema, undefined))
|
|
439
|
+
};
|
|
440
|
+
} else {
|
|
441
|
+
return {
|
|
442
|
+
TAG: "Inline",
|
|
443
|
+
_0: value
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
433
448
|
let onPlatformDeployedHook = {
|
|
434
449
|
contents: undefined
|
|
435
450
|
};
|
|
@@ -1030,6 +1045,7 @@ export {
|
|
|
1030
1045
|
offloadHook,
|
|
1031
1046
|
registerOffload,
|
|
1032
1047
|
clearOffload,
|
|
1048
|
+
offloadPayload,
|
|
1033
1049
|
onPlatformDeployedHook,
|
|
1034
1050
|
lastPlatformDeployedInfo,
|
|
1035
1051
|
registerOnPlatformDeployed,
|
package/src/util/LogFormat.res
CHANGED
|
@@ -28,6 +28,41 @@
|
|
|
28
28
|
// styling primitive through `LogFormat.bold` rather than the spec namespace.
|
|
29
29
|
let bold = Reventless.AnsiStyle.bold
|
|
30
30
|
|
|
31
|
+
// ─── Value truncation ────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
@val external logEnv: dict<string> = "process.env"
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
Per-value character budget for rendered payloads, before the rest is elided.
|
|
37
|
+
|
|
38
|
+
A detail line exists to say *which* command or event this is, not to reproduce
|
|
39
|
+
it: a single field can be arbitrarily large (a plugin structure, a pasted
|
|
40
|
+
document, an inline offload payload), and one of those turns a log into
|
|
41
|
+
something no one reads. Truncation is per value rather than per line so a large
|
|
42
|
+
field costs its neighbours nothing — the small fields that identify the message
|
|
43
|
+
stay visible next to it.
|
|
44
|
+
|
|
45
|
+
`REVENTLESS_LOG_MAX_VALUE` overrides the budget; `0` disables truncation for a
|
|
46
|
+
session that genuinely needs the whole payload.
|
|
47
|
+
*/
|
|
48
|
+
let maxValueChars =
|
|
49
|
+
logEnv
|
|
50
|
+
->Dict.get("REVENTLESS_LOG_MAX_VALUE")
|
|
51
|
+
->Option.flatMap(v => Int.fromString(v))
|
|
52
|
+
->Option.getOr(512)
|
|
53
|
+
|
|
54
|
+
/** `s` capped at `maxValueChars`, with what was dropped named rather than
|
|
55
|
+
silently missing — a truncated line must not read like a complete one. */
|
|
56
|
+
let truncate = (s: string): string => {
|
|
57
|
+
let len = s->String.length
|
|
58
|
+
if maxValueChars <= 0 || len <= maxValueChars {
|
|
59
|
+
s
|
|
60
|
+
} else {
|
|
61
|
+
`${s->String.slice(~start=0, ~end=maxValueChars)}…(+${(len - maxValueChars)
|
|
62
|
+
->Int.toString} chars)`
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
31
66
|
// ─── Commands ────────────────────────────────────────────────────────────────
|
|
32
67
|
|
|
33
68
|
// "Add" (bold)
|
|
@@ -46,6 +81,16 @@ let cmdSummary = (msg: Message.commandJson): string =>
|
|
|
46
81
|
let cmdSummaries = (msgs: array<Message.commandJson>): string =>
|
|
47
82
|
`[${msgs->Array.map(cmdSummary)->Array.join(",")}]`
|
|
48
83
|
|
|
84
|
+
/**
|
|
85
|
+
`JSON.stringify` is typed as total but returns `undefined` — not a string — for
|
|
86
|
+
the one value `JSON.t` cannot represent: the `undefined` a ReScript record's
|
|
87
|
+
*absent* optional field leaves behind as an own property of the JS object. Read
|
|
88
|
+
the result as nullable so an absent field is dropped instead of reaching a
|
|
89
|
+
string function as `undefined`. An explicit `null` still stringifies to `"null"`
|
|
90
|
+
and keeps printing.
|
|
91
|
+
*/
|
|
92
|
+
external stringifiedOrAbsent: string => Nullable.t<string> = "%identity"
|
|
93
|
+
|
|
49
94
|
// Strip TAG from a variant JSON, return remaining fields as a compact string.
|
|
50
95
|
// {"TAG":"Add","name":"Cat 1"} → {name:"Cat 1"}
|
|
51
96
|
// "Add" (bare string variant) → ""
|
|
@@ -56,7 +101,13 @@ let variantFields = (json: JSON.t): string =>
|
|
|
56
101
|
dict
|
|
57
102
|
->Dict.toArray
|
|
58
103
|
->Array.filter(((k, _)) => k != "TAG")
|
|
59
|
-
->Array.
|
|
104
|
+
->Array.filterMap(((k, v)) =>
|
|
105
|
+
v
|
|
106
|
+
->JSON.stringify
|
|
107
|
+
->stringifiedOrAbsent
|
|
108
|
+
->Nullable.toOption
|
|
109
|
+
->Option.map(s => `${k}:${s->truncate}`)
|
|
110
|
+
)
|
|
60
111
|
->Array.join(",")
|
|
61
112
|
fields == "" ? "" : `, {${fields}}`
|
|
62
113
|
| _ => ""
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
|
|
3
4
|
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
5
|
+
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
4
6
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
5
7
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
8
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
6
9
|
import * as AnsiStyle$Reventless from "@reventlessdev/reventless-spec/src/AnsiStyle.res.mjs";
|
|
7
10
|
import * as Message$ReventlessCore from "../Message.res.mjs";
|
|
8
11
|
|
|
12
|
+
let maxValueChars = Stdlib_Option.getOr(Stdlib_Option.flatMap(process.env["REVENTLESS_LOG_MAX_VALUE"], v => Stdlib_Int.fromString(v, undefined)), 512);
|
|
13
|
+
|
|
14
|
+
function truncate(s) {
|
|
15
|
+
let len = s.length;
|
|
16
|
+
if (maxValueChars <= 0 || len <= maxValueChars) {
|
|
17
|
+
return s;
|
|
18
|
+
} else {
|
|
19
|
+
return s.slice(0, maxValueChars) + `…(+` + (len - maxValueChars | 0).toString() + ` chars)`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
9
23
|
function cmdName(msg) {
|
|
10
24
|
return AnsiStyle$Reventless.bold(Message$ReventlessCore.variantNameOfJson(msg.commandJson));
|
|
11
25
|
}
|
|
@@ -26,7 +40,10 @@ function variantFields(json) {
|
|
|
26
40
|
if (typeof json !== "object" || json === null || Array.isArray(json)) {
|
|
27
41
|
return "";
|
|
28
42
|
}
|
|
29
|
-
let fields = Object.entries(json).filter(param => param[0] !== "TAG")
|
|
43
|
+
let fields = Stdlib_Array.filterMap(Object.entries(json).filter(param => param[0] !== "TAG"), param => {
|
|
44
|
+
let k = param[0];
|
|
45
|
+
return Stdlib_Option.map(Primitive_option.fromNullable(JSON.stringify(param[1])), s => k + `:` + truncate(s));
|
|
46
|
+
}).join(",");
|
|
30
47
|
if (fields === "") {
|
|
31
48
|
return "";
|
|
32
49
|
} else {
|
|
@@ -220,6 +237,8 @@ let fmtActions = actionNames;
|
|
|
220
237
|
|
|
221
238
|
export {
|
|
222
239
|
bold,
|
|
240
|
+
maxValueChars,
|
|
241
|
+
truncate,
|
|
223
242
|
cmdName,
|
|
224
243
|
cmdNames,
|
|
225
244
|
cmdSummary,
|
|
@@ -254,4 +273,4 @@ export {
|
|
|
254
273
|
fmtAction,
|
|
255
274
|
fmtActions,
|
|
256
275
|
}
|
|
257
|
-
/*
|
|
276
|
+
/* maxValueChars Not a pure module */
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Where a declared object store's keys are rooted.
|
|
2
|
+
//
|
|
3
|
+
// Lives in core beside StorePrefixCollision, and for the same reason: the rule
|
|
4
|
+
// is about a namespace, not about a cloud. The deployed platform roots an S3
|
|
5
|
+
// store's keys here, the local platform roots its filesystem store's keys here,
|
|
6
|
+
// and a reset attributes an object to the plugin that declared its store by
|
|
7
|
+
// reading the prefix back off the key. Three readers of one rule — so it is one
|
|
8
|
+
// function, not three strings that happen to agree today.
|
|
9
|
+
//
|
|
10
|
+
// Qualifying by plugin is what makes the prefix an identity rather than a label:
|
|
11
|
+
// two plugins may both declare a store called `images`, and only the qualified
|
|
12
|
+
// form keeps their objects apart (which is the collision StorePrefixCollision
|
|
13
|
+
// refuses when it cannot).
|
|
14
|
+
|
|
15
|
+
/** The prefix a store's object keys are rooted at: `{plugin}/{store}`.
|
|
16
|
+
|
|
17
|
+
A stored ref is independent of whether the store got its own bucket or a
|
|
18
|
+
prefix inside a shared one — refs live in an append-only log, so one that
|
|
19
|
+
encoded its physical layout would be unrewritable and environment-specific. */
|
|
20
|
+
let keyPrefixFor = (~plugin: string, ~store: string): string => `${plugin}/${store}`
|
|
21
|
+
|
|
22
|
+
/** The same prefix from the qualified `{plugin}.{store}` key that a
|
|
23
|
+
`pluginStructure.requiredStores` entry carries and that the `Upload_Presign`
|
|
24
|
+
mutation's `store` argument names.
|
|
25
|
+
|
|
26
|
+
Splits on the FIRST `.` — a store name may contain dots, a plugin name may
|
|
27
|
+
not. An unqualified key (no `.`) is returned as-is rather than guessed at:
|
|
28
|
+
it is not a `{plugin}.{store}` and inventing a plugin for it would attribute
|
|
29
|
+
objects to a plugin that never declared them. */
|
|
30
|
+
let prefixOfQualified = (qualified: string): string =>
|
|
31
|
+
switch qualified->String.indexOfOpt(".") {
|
|
32
|
+
| Some(i) =>
|
|
33
|
+
keyPrefixFor(
|
|
34
|
+
~plugin=qualified->String.slice(~start=0, ~end=i),
|
|
35
|
+
~store=qualified->String.slice(~start=i + 1, ~end=qualified->String.length),
|
|
36
|
+
)
|
|
37
|
+
| None => qualified
|
|
38
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_String from "@rescript/runtime/lib/es6/Stdlib_String.js";
|
|
4
|
+
|
|
5
|
+
function keyPrefixFor(plugin, store) {
|
|
6
|
+
return plugin + `/` + store;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function prefixOfQualified(qualified) {
|
|
10
|
+
let i = Stdlib_String.indexOfOpt(qualified, ".");
|
|
11
|
+
if (i !== undefined) {
|
|
12
|
+
return keyPrefixFor(qualified.slice(0, i), qualified.slice(i + 1 | 0, qualified.length));
|
|
13
|
+
} else {
|
|
14
|
+
return qualified;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
keyPrefixFor,
|
|
20
|
+
prefixOfQualified,
|
|
21
|
+
}
|
|
22
|
+
/* No side effect */
|
|
@@ -163,17 +163,22 @@ describe("encodePluginStructureEntry", () => {
|
|
|
163
163
|
)
|
|
164
164
|
|
|
165
165
|
// Translation-slice externalSystem: absent on the fixture above (both None), so it
|
|
166
|
-
// must serialize as null — the "no external box" case.
|
|
166
|
+
// must serialize as null — the "no external box" case. The leading field keeps the
|
|
167
|
+
// two directions apart; `targetName` sits between them and is pinned here too.
|
|
167
168
|
testSync("encodes None outbound externalSystem as null", () =>
|
|
168
|
-
expect(
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
expect(
|
|
170
|
+
json->String.includes(
|
|
171
|
+
"\"inboundCommandTypes\":[\"Ship\"],\"targetName\":null,\"externalSystem\":null",
|
|
172
|
+
),
|
|
173
|
+
)->toEqual(true)
|
|
171
174
|
)
|
|
172
175
|
|
|
173
176
|
testSync("encodes None inbound externalSystem as null", () =>
|
|
174
|
-
expect(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
expect(
|
|
178
|
+
json->String.includes(
|
|
179
|
+
"\"commandTypes\":[\"RecordPayment\"],\"targetName\":\"Order\",\"externalSystem\":null",
|
|
180
|
+
),
|
|
181
|
+
)->toEqual(true)
|
|
177
182
|
)
|
|
178
183
|
})
|
|
179
184
|
|
|
@@ -183,10 +183,10 @@ globalThis.describe("encodePluginStructureEntry", () => {
|
|
|
183
183
|
globalThis.expect(json.includes("\"events\":[{\"name\":\"ProductAdded\"")).toEqual(true);
|
|
184
184
|
});
|
|
185
185
|
globalThis.test("encodes None outbound externalSystem as null", () => {
|
|
186
|
-
globalThis.expect(json.includes("\"inboundCommandTypes\":[\"Ship\"],\"externalSystem\":null")).toEqual(true);
|
|
186
|
+
globalThis.expect(json.includes("\"inboundCommandTypes\":[\"Ship\"],\"targetName\":null,\"externalSystem\":null")).toEqual(true);
|
|
187
187
|
});
|
|
188
188
|
globalThis.test("encodes None inbound externalSystem as null", () => {
|
|
189
|
-
globalThis.expect(json.includes("\"commandTypes\":[\"RecordPayment\"],\"externalSystem\":null")).toEqual(true);
|
|
189
|
+
globalThis.expect(json.includes("\"commandTypes\":[\"RecordPayment\"],\"targetName\":\"Order\",\"externalSystem\":null")).toEqual(true);
|
|
190
190
|
});
|
|
191
191
|
});
|
|
192
192
|
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Asserts what makes `Platform_PluginStructures` different from
|
|
2
|
+
// `Platform_ComponentDefinitions`: nothing is filtered out, and the structure-level
|
|
3
|
+
// collections the AutoUI entry does not carry are present. A developer tool draws
|
|
4
|
+
// its graph from this response, so a component or a bridge missing here is a graph
|
|
5
|
+
// that silently disagrees with the source.
|
|
6
|
+
|
|
7
|
+
open JestGlobals
|
|
8
|
+
open Reventless.Plugin
|
|
9
|
+
|
|
10
|
+
let publicRm: queryableDef = {
|
|
11
|
+
name: "Products",
|
|
12
|
+
queryField: "Catalog_Products",
|
|
13
|
+
schema: "{}",
|
|
14
|
+
consumedEventTypes: ["ProductAdded"],
|
|
15
|
+
linkedWriteSide: ["Product"],
|
|
16
|
+
labelField: "displayName",
|
|
17
|
+
searchableFields: ["displayName"],
|
|
18
|
+
labelFieldSource: Some("annotation"),
|
|
19
|
+
statusField: None,
|
|
20
|
+
visibility: None,
|
|
21
|
+
chapter: Some("Inventory"),
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// The component `Platform_ComponentDefinitions` drops and this query must keep.
|
|
25
|
+
let internalRm: queryableDef = {
|
|
26
|
+
...publicRm,
|
|
27
|
+
name: "ProductAudit",
|
|
28
|
+
queryField: "Catalog_ProductAudit",
|
|
29
|
+
visibility: Some("Internal"),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let structure: pluginStructure = {
|
|
33
|
+
readModels: [publicRm, internalRm],
|
|
34
|
+
stateViewSlices: [internalRm],
|
|
35
|
+
stateChangeSlices: [],
|
|
36
|
+
aggregates: [],
|
|
37
|
+
automationSlices: [],
|
|
38
|
+
outboundTranslationSlices: [],
|
|
39
|
+
inboundTranslationSlices: [],
|
|
40
|
+
extensions: [],
|
|
41
|
+
extensionPoints: Some([
|
|
42
|
+
{
|
|
43
|
+
name: "Catalog.Products",
|
|
44
|
+
delegateNames: ["onAdded"],
|
|
45
|
+
sourceEventTypes: ["Catalog.ProductAdded"],
|
|
46
|
+
commandTypes: None,
|
|
47
|
+
},
|
|
48
|
+
]),
|
|
49
|
+
requiredStores: Some(["Catalog.images"]),
|
|
50
|
+
requiredStoreDeclarations: Some([
|
|
51
|
+
{store: "Catalog.images", component: "Product", field: "image", annotation: Some("images")},
|
|
52
|
+
]),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let encoded = Platform_PluginStructuresApi.encodePluginStructureEntry(
|
|
56
|
+
~pluginId="Catalog",
|
|
57
|
+
structure,
|
|
58
|
+
)
|
|
59
|
+
let json = encoded->JSON.stringify
|
|
60
|
+
|
|
61
|
+
let namesOf = (key): array<string> =>
|
|
62
|
+
encoded
|
|
63
|
+
->JSON.Decode.object
|
|
64
|
+
->Option.flatMap(d => d->Dict.get(key))
|
|
65
|
+
->Option.flatMap(JSON.Decode.array)
|
|
66
|
+
->Option.getOr([])
|
|
67
|
+
->Array.filterMap(v =>
|
|
68
|
+
v->JSON.Decode.object->Option.flatMap(o => o->Dict.get("name"))->Option.flatMap(JSON.Decode.string)
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
describe("Platform_PluginStructures entry", () => {
|
|
72
|
+
testSync("carries the structure-level keys the AutoUI entry omits", () => {
|
|
73
|
+
let dict = encoded->JSON.Decode.object->Option.getOr(Dict.make())
|
|
74
|
+
let keys = dict->Dict.keysToArray->Array.toSorted(String.compare)
|
|
75
|
+
expect(keys)->toEqual([
|
|
76
|
+
"aggregates",
|
|
77
|
+
"automationSlices",
|
|
78
|
+
"extensionPoints",
|
|
79
|
+
"extensions",
|
|
80
|
+
"inboundTranslationSlices",
|
|
81
|
+
"outboundTranslationSlices",
|
|
82
|
+
"pluginId",
|
|
83
|
+
"readModels",
|
|
84
|
+
"requiredStoreDeclarations",
|
|
85
|
+
"requiredStores",
|
|
86
|
+
"stateChangeSlices",
|
|
87
|
+
"stateViewSlices",
|
|
88
|
+
])
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
// The whole reason this query exists as a separate field.
|
|
92
|
+
testSync("keeps Internal read models", () =>
|
|
93
|
+
expect(namesOf("readModels"))->toEqual(["Products", "ProductAudit"])
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
testSync("keeps Internal state-view slices", () =>
|
|
97
|
+
expect(namesOf("stateViewSlices"))->toEqual(["ProductAudit"])
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
testSync("carries visibility so a consumer can tell which are Internal", () =>
|
|
101
|
+
expect(json->String.includes("\"visibility\":\"Internal\""))->toEqual(true)
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
testSync("encodes the chapter band", () =>
|
|
105
|
+
expect(json->String.includes("\"chapter\":\"Inventory\""))->toEqual(true)
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
testSync("encodes extension points with their source event types", () =>
|
|
109
|
+
expect(
|
|
110
|
+
json->String.includes(
|
|
111
|
+
"\"extensionPoints\":[{\"name\":\"Catalog.Products\",\"delegateNames\":[\"onAdded\"],\"sourceEventTypes\":[\"Catalog.ProductAdded\"],\"commandTypes\":null}]",
|
|
112
|
+
),
|
|
113
|
+
)->toEqual(true)
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
testSync("encodes required stores with their provenance", () =>
|
|
117
|
+
expect(json->String.includes("\"requiredStores\":[\"Catalog.images\"]"))->toEqual(true)
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// A structure persisted before these fields existed decodes as None, and null is the
|
|
122
|
+
// honest wire value — an empty list would claim the plugin has no extension points
|
|
123
|
+
// when the truth is that the deployment cannot say.
|
|
124
|
+
describe("absent optional collections", () => {
|
|
125
|
+
let bare: pluginStructure = {
|
|
126
|
+
...structure,
|
|
127
|
+
extensionPoints: None,
|
|
128
|
+
requiredStores: None,
|
|
129
|
+
requiredStoreDeclarations: None,
|
|
130
|
+
}
|
|
131
|
+
let bareJson =
|
|
132
|
+
Platform_PluginStructuresApi.encodePluginStructureEntry(
|
|
133
|
+
~pluginId="Catalog",
|
|
134
|
+
bare,
|
|
135
|
+
)->JSON.stringify
|
|
136
|
+
|
|
137
|
+
testSync("encodes absent extensionPoints as null", () =>
|
|
138
|
+
expect(bareJson->String.includes("\"extensionPoints\":null"))->toEqual(true)
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
testSync("encodes absent requiredStores as null", () =>
|
|
142
|
+
expect(bareJson->String.includes("\"requiredStores\":null"))->toEqual(true)
|
|
143
|
+
)
|
|
144
|
+
})
|