@reventlessdev/reventless-spec 3.0.0-alpha.117 → 3.0.0-alpha.118
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 +19 -0
- package/package.json +3 -3
- package/src/components/CapabilityManifest.res +1 -1
- package/src/components/CapabilityManifest.res.mjs +13 -12
- package/src/components/DcbDecode.res +8 -8
- package/src/components/DcbDecode.res.mjs +9 -8
- package/src/components/DcbTag.res +43 -42
- package/src/components/DcbTag.res.mjs +90 -87
- package/src/components/DcbValidation.res +6 -6
- package/src/components/DcbValidation.res.mjs +6 -6
- package/src/components/DisplayName.res.mjs +3 -3
- package/src/components/Owner.res +1 -1
- package/src/components/Owner.res.mjs +7 -7
- package/src/components/Plugin.res +8 -11
- package/src/components/Plugin.res.mjs +133 -134
- package/src/components/Reference.res.mjs +5 -5
- package/src/components/StateAnnotations.res +23 -0
- package/src/components/StateAnnotations.res.mjs +3 -3
- package/src/generator/PlatformCodegen.res +17 -14
- package/src/generator/PlatformCodegen.res.mjs +1 -1
- package/src/generator/PlatformGenerator.res +1 -1
- package/src/semantic/Bytes.res.mjs +2 -2
- package/src/semantic/Color.res.mjs +2 -2
- package/src/semantic/Currency.res.mjs +167 -167
- package/src/semantic/DateRange.res.mjs +2 -2
- package/src/semantic/Duration.res.mjs +2 -2
- package/src/semantic/Email.res +2 -2
- package/src/semantic/Email.res.mjs +3 -2
- package/src/semantic/FileRef.res +28 -0
- package/src/semantic/FileRef.res.mjs +17 -0
- package/src/semantic/GeoPoint.res +14 -10
- package/src/semantic/GeoPoint.res.mjs +10 -17
- package/src/semantic/ImageRef.res +51 -0
- package/src/semantic/ImageRef.res.mjs +17 -0
- package/src/semantic/Media_Ref.res +33 -0
- package/src/semantic/Media_Ref.res.mjs +37 -0
- package/src/semantic/Money.res +7 -5
- package/src/semantic/Money.res.mjs +6 -9
- package/src/semantic/Offload.res +29 -43
- package/src/semantic/Offload.res.mjs +18 -49
- package/src/semantic/Percent.res.mjs +2 -2
- package/src/semantic/Phone.res.mjs +2 -2
- package/src/semantic/Semantic.res +24 -6
- package/src/semantic/Semantic.res.mjs +13 -12
- package/src/semantic/StorageRef.res +33 -19
- package/src/semantic/StorageRef.res.mjs +14 -14
- package/src/semantic/UploadableFile.res +30 -0
- package/src/semantic/UploadableFile.res.mjs +23 -0
- package/src/semantic/UploadableImage.res +56 -0
- package/src/semantic/UploadableImage.res.mjs +23 -0
- package/src/semantic/Url.res +8 -2
- package/src/semantic/Url.res.mjs +3 -2
- package/src/types/Authorization.res.mjs +7 -7
- package/src/types/DateTime.res.mjs +2 -2
- package/src/types/Id.res.mjs +6 -4
- package/src/types/Identity.res +0 -1
- package/src/types/Identity.res.mjs +12 -14
- package/src/types/Message.res +29 -10
- package/src/types/Message.res.mjs +56 -37
- package/src/types/ReadConsistency.res.mjs +5 -5
- package/src/types/Schedule.res.mjs +37 -37
- package/src/types/StoredEvent.res +2 -2
- package/src/types/StoredEvent.res.mjs +11 -10
- package/src/types/Visibility.res.mjs +4 -4
- package/src/util/Util_Sury.res +32 -0
- package/src/util/Util_Sury.res.mjs +39 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
An image the platform stores, referenced by the path its store minted.
|
|
3
|
+
|
|
4
|
+
## What this says that `@storageRef` does not
|
|
5
|
+
|
|
6
|
+
`@storageRef("productImages") imageUrl?: string` states two facts and declares
|
|
7
|
+
only one. It says *where* the value lives — typed, validated, provisioned — and
|
|
8
|
+
leaves *what the value is* to be guessed from the field being called `imageUrl`.
|
|
9
|
+
This type states both, so the same declaration picks the renderer and the upload
|
|
10
|
+
endpoint.
|
|
11
|
+
|
|
12
|
+
## No store argument
|
|
13
|
+
|
|
14
|
+
The store is the field's name, pluralised, derived by the ppx —
|
|
15
|
+
`productImage: UploadableImage.t` requires the `productImages` store. So a field
|
|
16
|
+
declares its store by being named, and renaming the field renames the store:
|
|
17
|
+
treat a rename of a live field as a data migration, or keep the old store with an
|
|
18
|
+
explicit `@storageRef("…")`, which still wins.
|
|
19
|
+
|
|
20
|
+
The stored value is unchanged from `StorageRef`: an origin-relative
|
|
21
|
+
`/{prefix}/{key}` string, validated by the same refinement. Retyping an existing
|
|
22
|
+
`@storageRef` field to this one alters no stored bytes — only the field's *name*
|
|
23
|
+
does, and only because the store is derived from it.
|
|
24
|
+
|
|
25
|
+
@example
|
|
26
|
+
```rescript
|
|
27
|
+
@schema type command =
|
|
28
|
+
| ChangeProductImage({
|
|
29
|
+
productId: @s.matches(DcbTag.string) string,
|
|
30
|
+
productImage: UploadableImage.t,
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/** Transparent `string`, for `StorageRef.t`'s reason: the marker refines an
|
|
36
|
+
existing field rather than replacing it, so nothing stored changes. */
|
|
37
|
+
type t = string
|
|
38
|
+
|
|
39
|
+
external unsafe: string => t = "%identity"
|
|
40
|
+
external toString: t => string = "%identity"
|
|
41
|
+
|
|
42
|
+
/** The grammar, which is `StorageRef`'s — one definition, no second copy. */
|
|
43
|
+
let fromString = (raw: string): result<t, string> => StorageRef.fromString(raw)
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
The schema for a field of this type, bound to the store the ppx derived.
|
|
47
|
+
|
|
48
|
+
Prefer typing the field `UploadableImage.t` and letting `UploadableInference`
|
|
49
|
+
call this. Written by hand it needs the derived store name, which defeats the
|
|
50
|
+
point of the type.
|
|
51
|
+
*/
|
|
52
|
+
let forField = (~plugin: option<string>=?, ~store: string): S.t<t> =>
|
|
53
|
+
StorageRef.refinement->Semantic.mark(
|
|
54
|
+
~id=Semantic.Id.uploadableImage,
|
|
55
|
+
~payload=StoredIn({plugin, store, threshold: None}),
|
|
56
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Semantic$Reventless from "./Semantic.res.mjs";
|
|
4
|
+
import * as StorageRef$Reventless from "./StorageRef.res.mjs";
|
|
5
|
+
|
|
6
|
+
let fromString = StorageRef$Reventless.fromString;
|
|
7
|
+
|
|
8
|
+
function forField(plugin, store) {
|
|
9
|
+
return Semantic$Reventless.mark(StorageRef$Reventless.refinement, Semantic$Reventless.Id.uploadableImage, {
|
|
10
|
+
TAG: "StoredIn",
|
|
11
|
+
_0: {
|
|
12
|
+
plugin: plugin,
|
|
13
|
+
store: store,
|
|
14
|
+
threshold: undefined
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
fromString,
|
|
21
|
+
forField,
|
|
22
|
+
}
|
|
23
|
+
/* Semantic-Reventless Not a pure module */
|
package/src/semantic/Url.res
CHANGED
|
@@ -33,7 +33,13 @@ external toString: t => string = "%identity"
|
|
|
33
33
|
|
|
34
34
|
// Sury's parse, held once — `fromString` runs it and adds the scheme check, and
|
|
35
35
|
// `schema` derives from `fromString`. One grammar, in one place.
|
|
36
|
-
|
|
36
|
+
//
|
|
37
|
+
// `S.uri`, not `S.url`: sury 11 turned `S.url` into a `URL` *instance*, whose
|
|
38
|
+
// `href` is normalised (`http://x` comes back `http://x/`). This value is written
|
|
39
|
+
// to an append-only log, so the address has to survive the round trip as the
|
|
40
|
+
// caller wrote it. `S.uri` is the string-preserving arm — it still rejects what
|
|
41
|
+
// does not parse, and returns exactly what it was given.
|
|
42
|
+
let grammar: S.t<string> = S.uri
|
|
37
43
|
|
|
38
44
|
// Schemes are case-insensitive per RFC 3986, and `HTTPS://x` parses fine, so the
|
|
39
45
|
// allowlist has to fold case or it rejects a valid address on a technicality.
|
|
@@ -44,7 +50,7 @@ let hasWebScheme = (raw: string): bool => {
|
|
|
44
50
|
|
|
45
51
|
/** Validate a raw string as an `http`/`https` URL, saying why when it is not one. */
|
|
46
52
|
let fromString = (raw: string): result<t, string> =>
|
|
47
|
-
switch raw->S.parseOrThrow(grammar) {
|
|
53
|
+
switch raw->S.parseOrThrow(~to=grammar) {
|
|
48
54
|
| value =>
|
|
49
55
|
if hasWebScheme(value) {
|
|
50
56
|
Ok(value)
|
package/src/semantic/Url.res.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as S from "sury/src/S.res.mjs";
|
|
4
|
+
import * as Sury from "sury";
|
|
4
5
|
import * as Semantic$Reventless from "./Semantic.res.mjs";
|
|
5
6
|
|
|
6
|
-
let grammar =
|
|
7
|
+
let grammar = Sury.uri;
|
|
7
8
|
|
|
8
9
|
function hasWebScheme(raw) {
|
|
9
10
|
let lower = raw.toLowerCase();
|
|
@@ -37,7 +38,7 @@ function fromString(raw) {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
let schema = Semantic$Reventless.refined(
|
|
41
|
+
let schema = Semantic$Reventless.refined(Sury.string, Semantic$Reventless.Id.url, fromString);
|
|
41
42
|
|
|
42
43
|
export {
|
|
43
44
|
grammar,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as Sury from "sury";
|
|
4
4
|
|
|
5
|
-
let permissionSchema =
|
|
6
|
-
|
|
5
|
+
let permissionSchema = Sury.union([
|
|
6
|
+
Sury.$schema(s => ({
|
|
7
7
|
TAG: "AllowGroups",
|
|
8
|
-
_0: s.m(
|
|
8
|
+
_0: s.m(Sury.array(Sury.string))
|
|
9
9
|
})),
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
Sury.literal("AllowAuthenticated"),
|
|
11
|
+
Sury.literal("AllowAnonymous"),
|
|
12
|
+
Sury.literal("DenyAll")
|
|
13
13
|
]);
|
|
14
14
|
|
|
15
15
|
function isAllowed(rule, identity) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as Sury from "sury";
|
|
4
4
|
import * as Semantic$Reventless from "../semantic/Semantic.res.mjs";
|
|
5
5
|
|
|
6
|
-
let string = Semantic$Reventless.mark(
|
|
6
|
+
let string = Semantic$Reventless.mark(Sury.string, Semantic$Reventless.Id.dateTime, undefined);
|
|
7
7
|
|
|
8
8
|
function isDateTime(fieldSchema) {
|
|
9
9
|
return Semantic$Reventless.has(fieldSchema, Semantic$Reventless.Id.dateTime);
|
package/src/types/Id.res.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as Sury from "sury";
|
|
4
4
|
import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
|
|
5
5
|
|
|
6
|
+
let schema = Sury.string;
|
|
7
|
+
|
|
6
8
|
let cmp = Primitive_string.compare;
|
|
7
9
|
|
|
8
10
|
let StringPure = {
|
|
9
|
-
schema:
|
|
11
|
+
schema: schema,
|
|
10
12
|
cmp: cmp
|
|
11
13
|
};
|
|
12
14
|
|
|
@@ -23,7 +25,7 @@ function String_toString(prim) {
|
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
let $$String = {
|
|
26
|
-
schema:
|
|
28
|
+
schema: schema,
|
|
27
29
|
make: String_make,
|
|
28
30
|
makeFromString: String_makeFromString,
|
|
29
31
|
toString: String_toString,
|
|
@@ -34,4 +36,4 @@ export {
|
|
|
34
36
|
StringPure,
|
|
35
37
|
$$String,
|
|
36
38
|
}
|
|
37
|
-
/*
|
|
39
|
+
/* schema Not a pure module */
|
package/src/types/Identity.res
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as Sury from "sury";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
S.literal("InMemory"),
|
|
10
|
-
S.schema(s => ({
|
|
5
|
+
let providerSchema = Sury.union([
|
|
6
|
+
Sury.literal("Cognito"),
|
|
7
|
+
Sury.literal("InMemory"),
|
|
8
|
+
Sury.$schema(s => ({
|
|
11
9
|
TAG: "Custom",
|
|
12
|
-
_0: s.m(
|
|
10
|
+
_0: s.m(Sury.string)
|
|
13
11
|
}))
|
|
14
12
|
]);
|
|
15
13
|
|
|
16
|
-
let schema =
|
|
17
|
-
userId: s.m(
|
|
18
|
-
username: s.m(
|
|
19
|
-
groups: s.m(
|
|
20
|
-
claims: s.m(
|
|
14
|
+
let schema = Sury.$schema(s => ({
|
|
15
|
+
userId: s.m(Sury.string),
|
|
16
|
+
username: s.m(Sury.string),
|
|
17
|
+
groups: s.m(Sury.array(Sury.string)),
|
|
18
|
+
claims: s.m(Sury.$option(Sury.dict(Sury.string))),
|
|
21
19
|
provider: s.m(providerSchema)
|
|
22
20
|
}));
|
|
23
21
|
|
|
@@ -48,4 +46,4 @@ export {
|
|
|
48
46
|
hasGroup,
|
|
49
47
|
getClaim,
|
|
50
48
|
}
|
|
51
|
-
/*
|
|
49
|
+
/* providerSchema Not a pure module */
|
package/src/types/Message.res
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
S.enableJson()
|
|
2
1
|
|
|
3
2
|
/** Identifies the service that produced or is addressed by a message. */
|
|
4
3
|
@schema
|
|
@@ -182,6 +181,25 @@ type commandJson = {
|
|
|
182
181
|
let fillMissingDefaults: (S.t<'a>, JSON.t, array<string>) => JSON.t = %raw(`function(schema, json, scalarFills){
|
|
183
182
|
function isSchema(x){ return x && typeof x === "object" && typeof x.type === "string"; }
|
|
184
183
|
function firstConst(anyOf){ var m=(anyOf||[]).find(function(s){return s.const!==undefined;}); return m ? m.const : undefined; }
|
|
184
|
+
// Which object-typed member of an anyOf a plain (untagged) object value belongs to.
|
|
185
|
+
// Scored by how many of the value's own keys the member declares, so an untagged
|
|
186
|
+
// either-or codec resolves by shape: an offload field is a sentinel-keyed reference
|
|
187
|
+
// object OR the inline value, and healing an inline payload against the reference
|
|
188
|
+
// member would invent a reference with an empty key that then decodes cleanly —
|
|
189
|
+
// corruption, not an error. Ties keep the earliest member, which is the declared
|
|
190
|
+
// preference order; a value sharing no key with any member is a tie at zero and
|
|
191
|
+
// picks the first, the same guess this made before scoring existed.
|
|
192
|
+
function bestObjectMember(members, value){
|
|
193
|
+
var keys=Object.keys(value), best, bestScore=-1;
|
|
194
|
+
for(var i=0;i<members.length;i++){
|
|
195
|
+
var s=members[i];
|
|
196
|
+
if(s.type!=="object") continue;
|
|
197
|
+
var props=s.properties||{}, score=0;
|
|
198
|
+
for(var k=0;k<keys.length;k++){ if(Object.prototype.hasOwnProperty.call(props,keys[k])) score++; }
|
|
199
|
+
if(score>bestScore){ bestScore=score; best=s; }
|
|
200
|
+
}
|
|
201
|
+
return best;
|
|
202
|
+
}
|
|
185
203
|
function scalarDefault(schema){
|
|
186
204
|
if(schema.const!==undefined) return schema.const;
|
|
187
205
|
switch(schema.type){
|
|
@@ -197,8 +215,9 @@ let fillMissingDefaults: (S.t<'a>, JSON.t, array<string>) => JSON.t = %raw(`func
|
|
|
197
215
|
case "object": {
|
|
198
216
|
if(value===undefined){ value={}; }
|
|
199
217
|
else if(value===null || typeof value!=="object" || Array.isArray(value)) return value;
|
|
200
|
-
var
|
|
201
|
-
|
|
218
|
+
var props=schema.properties||{};
|
|
219
|
+
var names=Object.keys(props);
|
|
220
|
+
for(var i=0;i<names.length;i++){ var n=names[i]; value[n]=fill(props[n], value[n], path+"."+n); }
|
|
202
221
|
return value;
|
|
203
222
|
}
|
|
204
223
|
case "array": {
|
|
@@ -206,7 +225,7 @@ let fillMissingDefaults: (S.t<'a>, JSON.t, array<string>) => JSON.t = %raw(`func
|
|
|
206
225
|
if(value===undefined) return [];
|
|
207
226
|
return value;
|
|
208
227
|
}
|
|
209
|
-
case "
|
|
228
|
+
case "anyOf": {
|
|
210
229
|
var has=schema.has||{};
|
|
211
230
|
if(value===undefined){
|
|
212
231
|
if(has.null) return null;
|
|
@@ -218,8 +237,8 @@ let fillMissingDefaults: (S.t<'a>, JSON.t, array<string>) => JSON.t = %raw(`func
|
|
|
218
237
|
var members=schema.anyOf||[];
|
|
219
238
|
if(Array.isArray(value)){ var a=members.find(function(s){return s.type==="array";}); return a ? fill(a,value,path) : value; }
|
|
220
239
|
if(typeof value==="object"){
|
|
221
|
-
var m=members.find(function(s){return s.type==="object" &&
|
|
222
|
-
if(!m) m=members
|
|
240
|
+
var m=members.find(function(s){return s.type==="object" && s.properties && s.properties.TAG && s.properties.TAG.const===value.TAG;});
|
|
241
|
+
if(!m) m=bestObjectMember(members, value);
|
|
223
242
|
return m ? fill(m,value,path) : value;
|
|
224
243
|
}
|
|
225
244
|
return value;
|
|
@@ -239,11 +258,11 @@ let fillMissingDefaults: (S.t<'a>, JSON.t, array<string>) => JSON.t = %raw(`func
|
|
|
239
258
|
|
|
240
259
|
// Strict parse with a single schema-migration-on-read retry (see fillMissingDefaults).
|
|
241
260
|
let parseJsonTolerant = (json, schema) =>
|
|
242
|
-
switch json->
|
|
261
|
+
switch json->Util_Sury.fromJson(schema) {
|
|
243
262
|
| value => value
|
|
244
263
|
| exception firstErr =>
|
|
245
264
|
let scalarFills = []
|
|
246
|
-
switch fillMissingDefaults(schema, json, scalarFills)->
|
|
265
|
+
switch fillMissingDefaults(schema, json, scalarFills)->Util_Sury.fromJson(schema) {
|
|
247
266
|
| value =>
|
|
248
267
|
// Only the invented values are worth a line. A heal that used nothing but
|
|
249
268
|
// schema-derived defaults is the mechanism working as designed.
|
|
@@ -285,7 +304,7 @@ Encode a value to JSON using a sury schema.
|
|
|
285
304
|
let json = event->Message.encode(Category.eventSchema)
|
|
286
305
|
```
|
|
287
306
|
*/
|
|
288
|
-
let encode = (value, schema: S.t<'a>) => value->
|
|
307
|
+
let encode = (value, schema: S.t<'a>) => value->Util_Sury.toJson(schema)
|
|
289
308
|
|
|
290
309
|
/** Raised by adapters when an incoming event JSON cannot be matched to a known event variant. */
|
|
291
310
|
exception InvalidEvent(JSON.t)
|
|
@@ -319,7 +338,7 @@ let variantNameOfJson = json =>
|
|
|
319
338
|
let composeEventJson' = (id, meta, eventJson) =>
|
|
320
339
|
[
|
|
321
340
|
("id", id->JSON.Encode.string),
|
|
322
|
-
("meta", meta->
|
|
341
|
+
("meta", meta->Util_Sury.toJson(metaSchema)),
|
|
323
342
|
("event", eventJson),
|
|
324
343
|
]
|
|
325
344
|
->Dict.fromArray
|
|
@@ -1,43 +1,63 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as Sury from "sury";
|
|
4
4
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
import * as Util_Sury$Reventless from "../util/Util_Sury.res.mjs";
|
|
6
|
+
|
|
7
|
+
let serviceSchema = Sury.string;
|
|
8
|
+
|
|
9
|
+
let metaSchema = Sury.$schema(s => ({
|
|
10
|
+
service: s.m(serviceSchema),
|
|
11
|
+
time: s.m(Sury.string),
|
|
12
|
+
ip: s.m(Sury.$option(Sury.string)),
|
|
13
|
+
user: s.m(Sury.$option(Sury.string)),
|
|
14
|
+
msgId: s.m(Sury.string),
|
|
15
|
+
correlationId: s.m(Sury.string),
|
|
16
|
+
causationId: s.m(Sury.$option(Sury.string)),
|
|
17
|
+
traceparent: s.m(Sury.$option(Sury.string)),
|
|
18
|
+
schemaVersion: s.m(Sury.$option(Sury.string)),
|
|
19
|
+
headers: s.m(Sury.$option(Sury.dict(Sury.string)))
|
|
19
20
|
}));
|
|
20
21
|
|
|
21
|
-
let contextSchema =
|
|
22
|
-
id: s.m(
|
|
22
|
+
let contextSchema = Sury.$schema(s => ({
|
|
23
|
+
id: s.m(Sury.string),
|
|
23
24
|
meta: s.m(metaSchema)
|
|
24
25
|
}));
|
|
25
26
|
|
|
26
|
-
let statusChangeSchema =
|
|
27
|
-
at: s.m(
|
|
28
|
-
by: s.m(
|
|
27
|
+
let statusChangeSchema = Sury.$schema(s => ({
|
|
28
|
+
at: s.m(Sury.string),
|
|
29
|
+
by: s.m(Sury.string)
|
|
29
30
|
}));
|
|
30
31
|
|
|
31
|
-
let commandJsonSchema =
|
|
32
|
-
id: s.m(
|
|
32
|
+
let commandJsonSchema = Sury.$schema(s => ({
|
|
33
|
+
id: s.m(Sury.string),
|
|
33
34
|
meta: s.m(metaSchema),
|
|
34
|
-
commandJson: s.m(
|
|
35
|
-
delay: s.m(
|
|
35
|
+
commandJson: s.m(Sury.json),
|
|
36
|
+
delay: s.m(Sury.$option(Sury.int))
|
|
36
37
|
}));
|
|
37
38
|
|
|
38
39
|
let fillMissingDefaults = (function(schema, json, scalarFills){
|
|
39
40
|
function isSchema(x){ return x && typeof x === "object" && typeof x.type === "string"; }
|
|
40
41
|
function firstConst(anyOf){ var m=(anyOf||[]).find(function(s){return s.const!==undefined;}); return m ? m.const : undefined; }
|
|
42
|
+
// Which object-typed member of an anyOf a plain (untagged) object value belongs to.
|
|
43
|
+
// Scored by how many of the value's own keys the member declares, so an untagged
|
|
44
|
+
// either-or codec resolves by shape: an offload field is a sentinel-keyed reference
|
|
45
|
+
// object OR the inline value, and healing an inline payload against the reference
|
|
46
|
+
// member would invent a reference with an empty key that then decodes cleanly —
|
|
47
|
+
// corruption, not an error. Ties keep the earliest member, which is the declared
|
|
48
|
+
// preference order; a value sharing no key with any member is a tie at zero and
|
|
49
|
+
// picks the first, the same guess this made before scoring existed.
|
|
50
|
+
function bestObjectMember(members, value){
|
|
51
|
+
var keys=Object.keys(value), best, bestScore=-1;
|
|
52
|
+
for(var i=0;i<members.length;i++){
|
|
53
|
+
var s=members[i];
|
|
54
|
+
if(s.type!=="object") continue;
|
|
55
|
+
var props=s.properties||{}, score=0;
|
|
56
|
+
for(var k=0;k<keys.length;k++){ if(Object.prototype.hasOwnProperty.call(props,keys[k])) score++; }
|
|
57
|
+
if(score>bestScore){ bestScore=score; best=s; }
|
|
58
|
+
}
|
|
59
|
+
return best;
|
|
60
|
+
}
|
|
41
61
|
function scalarDefault(schema){
|
|
42
62
|
if(schema.const!==undefined) return schema.const;
|
|
43
63
|
switch(schema.type){
|
|
@@ -53,8 +73,9 @@ let fillMissingDefaults = (function(schema, json, scalarFills){
|
|
|
53
73
|
case "object": {
|
|
54
74
|
if(value===undefined){ value={}; }
|
|
55
75
|
else if(value===null || typeof value!=="object" || Array.isArray(value)) return value;
|
|
56
|
-
var
|
|
57
|
-
|
|
76
|
+
var props=schema.properties||{};
|
|
77
|
+
var names=Object.keys(props);
|
|
78
|
+
for(var i=0;i<names.length;i++){ var n=names[i]; value[n]=fill(props[n], value[n], path+"."+n); }
|
|
58
79
|
return value;
|
|
59
80
|
}
|
|
60
81
|
case "array": {
|
|
@@ -62,7 +83,7 @@ let fillMissingDefaults = (function(schema, json, scalarFills){
|
|
|
62
83
|
if(value===undefined) return [];
|
|
63
84
|
return value;
|
|
64
85
|
}
|
|
65
|
-
case "
|
|
86
|
+
case "anyOf": {
|
|
66
87
|
var has=schema.has||{};
|
|
67
88
|
if(value===undefined){
|
|
68
89
|
if(has.null) return null;
|
|
@@ -74,8 +95,8 @@ let fillMissingDefaults = (function(schema, json, scalarFills){
|
|
|
74
95
|
var members=schema.anyOf||[];
|
|
75
96
|
if(Array.isArray(value)){ var a=members.find(function(s){return s.type==="array";}); return a ? fill(a,value,path) : value; }
|
|
76
97
|
if(typeof value==="object"){
|
|
77
|
-
var m=members.find(function(s){return s.type==="object" &&
|
|
78
|
-
if(!m) m=members
|
|
98
|
+
var m=members.find(function(s){return s.type==="object" && s.properties && s.properties.TAG && s.properties.TAG.const===value.TAG;});
|
|
99
|
+
if(!m) m=bestObjectMember(members, value);
|
|
79
100
|
return m ? fill(m,value,path) : value;
|
|
80
101
|
}
|
|
81
102
|
return value;
|
|
@@ -95,12 +116,12 @@ let fillMissingDefaults = (function(schema, json, scalarFills){
|
|
|
95
116
|
|
|
96
117
|
function parseJsonTolerant(json, schema) {
|
|
97
118
|
try {
|
|
98
|
-
return
|
|
119
|
+
return Util_Sury$Reventless.fromJson(json, schema);
|
|
99
120
|
} catch (firstErr) {
|
|
100
121
|
let scalarFills = [];
|
|
101
122
|
let value;
|
|
102
123
|
try {
|
|
103
|
-
value =
|
|
124
|
+
value = Util_Sury$Reventless.fromJson(fillMissingDefaults(schema, json, scalarFills), schema);
|
|
104
125
|
} catch (exn) {
|
|
105
126
|
throw firstErr;
|
|
106
127
|
}
|
|
@@ -113,12 +134,12 @@ function parseJsonTolerant(json, schema) {
|
|
|
113
134
|
|
|
114
135
|
let decode = parseJsonTolerant;
|
|
115
136
|
|
|
116
|
-
let encode =
|
|
137
|
+
let encode = Util_Sury$Reventless.toJson;
|
|
117
138
|
|
|
118
139
|
let InvalidEvent = /* @__PURE__ */Primitive_exceptions.create("Message-Reventless.InvalidEvent");
|
|
119
140
|
|
|
120
141
|
function toEventSchema$p(idSchema, eventSchema) {
|
|
121
|
-
return
|
|
142
|
+
return Sury.object(s => ({
|
|
122
143
|
id: s.f("id", idSchema),
|
|
123
144
|
meta: s.f("meta", metaSchema),
|
|
124
145
|
event: s.f("event", eventSchema)
|
|
@@ -156,7 +177,7 @@ function composeEventJson$p(id, meta, eventJson) {
|
|
|
156
177
|
],
|
|
157
178
|
[
|
|
158
179
|
"meta",
|
|
159
|
-
|
|
180
|
+
Util_Sury$Reventless.toJson(meta, metaSchema)
|
|
160
181
|
],
|
|
161
182
|
[
|
|
162
183
|
"event",
|
|
@@ -165,8 +186,6 @@ function composeEventJson$p(id, meta, eventJson) {
|
|
|
165
186
|
]);
|
|
166
187
|
}
|
|
167
188
|
|
|
168
|
-
let serviceSchema = S.string;
|
|
169
|
-
|
|
170
189
|
export {
|
|
171
190
|
serviceSchema,
|
|
172
191
|
metaSchema,
|
|
@@ -183,4 +202,4 @@ export {
|
|
|
183
202
|
variantNameOfJson,
|
|
184
203
|
composeEventJson$p,
|
|
185
204
|
}
|
|
186
|
-
/*
|
|
205
|
+
/* serviceSchema Not a pure module */
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as Sury from "sury";
|
|
4
4
|
|
|
5
|
-
let schema =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
let schema = Sury.union([
|
|
6
|
+
Sury.literal("EscalateOnRetry"),
|
|
7
|
+
Sury.literal("AlwaysStrong"),
|
|
8
|
+
Sury.literal("AlwaysEventual")
|
|
9
9
|
]);
|
|
10
10
|
|
|
11
11
|
function toString(v) {
|
|
@@ -1,61 +1,61 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as Sury from "sury";
|
|
4
4
|
|
|
5
|
-
let
|
|
6
|
-
|
|
5
|
+
let yearSchema = Sury.int;
|
|
6
|
+
|
|
7
|
+
let monthSchema = Sury.int;
|
|
8
|
+
|
|
9
|
+
let daySchema = Sury.int;
|
|
10
|
+
|
|
11
|
+
let hourSchema = Sury.int;
|
|
12
|
+
|
|
13
|
+
let minuteSchema = Sury.int;
|
|
14
|
+
|
|
15
|
+
let rateSchema = Sury.union([
|
|
16
|
+
Sury.$schema(s => ({
|
|
7
17
|
TAG: "Single",
|
|
8
|
-
_0: s.m(
|
|
9
|
-
_1: s.m(
|
|
10
|
-
_2: s.m(
|
|
11
|
-
_3: s.m(
|
|
12
|
-
_4: s.m(
|
|
18
|
+
_0: s.m(yearSchema),
|
|
19
|
+
_1: s.m(monthSchema),
|
|
20
|
+
_2: s.m(daySchema),
|
|
21
|
+
_3: s.m(hourSchema),
|
|
22
|
+
_4: s.m(minuteSchema)
|
|
13
23
|
})),
|
|
14
|
-
|
|
24
|
+
Sury.$schema(s => ({
|
|
15
25
|
TAG: "Minutes",
|
|
16
|
-
_0: s.m(
|
|
26
|
+
_0: s.m(Sury.int)
|
|
17
27
|
})),
|
|
18
|
-
|
|
28
|
+
Sury.$schema(s => ({
|
|
19
29
|
TAG: "Hours",
|
|
20
|
-
_0: s.m(
|
|
30
|
+
_0: s.m(Sury.int)
|
|
21
31
|
})),
|
|
22
|
-
|
|
32
|
+
Sury.$schema(s => ({
|
|
23
33
|
TAG: "Days",
|
|
24
|
-
_0: s.m(
|
|
34
|
+
_0: s.m(Sury.int)
|
|
25
35
|
})),
|
|
26
|
-
|
|
36
|
+
Sury.$schema(s => ({
|
|
27
37
|
TAG: "Daily",
|
|
28
|
-
_0: s.m(
|
|
29
|
-
_1: s.m(
|
|
38
|
+
_0: s.m(hourSchema),
|
|
39
|
+
_1: s.m(minuteSchema)
|
|
30
40
|
})),
|
|
31
|
-
|
|
41
|
+
Sury.$schema(s => ({
|
|
32
42
|
TAG: "Weekdays",
|
|
33
|
-
_0: s.m(
|
|
34
|
-
_1: s.m(
|
|
43
|
+
_0: s.m(hourSchema),
|
|
44
|
+
_1: s.m(minuteSchema)
|
|
35
45
|
})),
|
|
36
|
-
|
|
46
|
+
Sury.$schema(s => ({
|
|
37
47
|
TAG: "WeekdaysAndSaturday",
|
|
38
|
-
_0: s.m(
|
|
39
|
-
_1: s.m(
|
|
48
|
+
_0: s.m(hourSchema),
|
|
49
|
+
_1: s.m(minuteSchema)
|
|
40
50
|
}))
|
|
41
51
|
]);
|
|
42
52
|
|
|
43
|
-
let scheduleSchema =
|
|
44
|
-
name: s.m(
|
|
53
|
+
let scheduleSchema = Sury.$schema(s => ({
|
|
54
|
+
name: s.m(Sury.string),
|
|
45
55
|
rate: s.m(rateSchema),
|
|
46
|
-
payload: s.m(
|
|
56
|
+
payload: s.m(Sury.string)
|
|
47
57
|
}));
|
|
48
58
|
|
|
49
|
-
let yearSchema = S.int;
|
|
50
|
-
|
|
51
|
-
let monthSchema = S.int;
|
|
52
|
-
|
|
53
|
-
let daySchema = S.int;
|
|
54
|
-
|
|
55
|
-
let hourSchema = S.int;
|
|
56
|
-
|
|
57
|
-
let minuteSchema = S.int;
|
|
58
|
-
|
|
59
59
|
export {
|
|
60
60
|
yearSchema,
|
|
61
61
|
monthSchema,
|
|
@@ -65,4 +65,4 @@ export {
|
|
|
65
65
|
rateSchema,
|
|
66
66
|
scheduleSchema,
|
|
67
67
|
}
|
|
68
|
-
/*
|
|
68
|
+
/* yearSchema Not a pure module */
|
|
@@ -39,8 +39,8 @@ let toStoredEventSchema = (idSchema: S.t<'id>): S.t<storedEvent<'id>> =>
|
|
|
39
39
|
|
|
40
40
|
/** Decode a `storedEvent<'id>` from JSON. */
|
|
41
41
|
let decode = (json, idSchema) =>
|
|
42
|
-
json->
|
|
42
|
+
json->Util_Sury.fromJson(toStoredEventSchema(idSchema))
|
|
43
43
|
|
|
44
44
|
/** Encode a `storedEvent<'id>` to JSON. */
|
|
45
45
|
let encode = (stored, idSchema) =>
|
|
46
|
-
stored->
|
|
46
|
+
stored->Util_Sury.toJson(toStoredEventSchema(idSchema))
|