@reventlessdev/reventless-spec 3.0.0-alpha.132 → 3.0.0-alpha.133
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
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
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.133 (2026-09-08)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **spec:** a field declares the value a form opens it on ([1d541fe](https://github.com/ReventlessDev/reventless-core/commit/1d541fe497e1df2ff48b72e26a06a1b8fd3c9e06))
|
|
11
|
+
|
|
12
|
+
|
|
6
13
|
# 3.0.0-alpha.132 (2026-09-08)
|
|
7
14
|
|
|
8
15
|
### Features
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-spec",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.133",
|
|
4
4
|
"description": "Specifications for Reventless",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"sury": "11.0.0-rc.2",
|
|
26
26
|
"sury-ppx": "11.0.0-rc.2",
|
|
27
27
|
"yaml": "^2.8.3",
|
|
28
|
-
"@reventlessdev/rescript-node": "2.0.0-alpha.
|
|
28
|
+
"@reventlessdev/rescript-node": "2.0.0-alpha.10"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"rescript": "12.3.0",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
The value a field opens with where nobody has said otherwise, published as JSON
|
|
3
|
+
Schema's own `default` keyword.
|
|
4
|
+
|
|
5
|
+
A statement about the domain: an order line is for one of the thing unless the
|
|
6
|
+
shopper says two. A consumer that finds no default opens the field blank rather
|
|
7
|
+
than inventing one.
|
|
8
|
+
|
|
9
|
+
Write `@default(1)` — see `DefaultInference`, which desugars to the constructors
|
|
10
|
+
below. The marker rides on the field's own schema rather than in a record-level
|
|
11
|
+
spec keyed by field name, which is what makes it work at any depth: a record
|
|
12
|
+
nested inside a command carries no such spec, and its fields are the ones a
|
|
13
|
+
repeating group opens blank.
|
|
14
|
+
|
|
15
|
+
@example
|
|
16
|
+
```rescript
|
|
17
|
+
@schema
|
|
18
|
+
type lineItem = {
|
|
19
|
+
@ref("AvailableProducts") productId: string,
|
|
20
|
+
@default(1) quantity: int,
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
*/
|
|
24
|
+
let defaultId: S.Metadata.Id.t<JSON.t> = S.Metadata.Id.make(
|
|
25
|
+
~namespace="reventless",
|
|
26
|
+
~name="default",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
/** Layers a default onto whatever the field already resolved to. Wraps rather
|
|
30
|
+
than replaces, for the reason `Sensitive.mark` does: a field carries at most
|
|
31
|
+
one `@s.matches`. */
|
|
32
|
+
let mark = (schema: S.t<'a>, value: JSON.t): S.t<'a> =>
|
|
33
|
+
schema->S.Metadata.set(~id=defaultId, value)
|
|
34
|
+
|
|
35
|
+
let int = (schema: S.t<int>, value: int): S.t<int> => schema->mark(JSON.Encode.int(value))
|
|
36
|
+
|
|
37
|
+
let float = (schema: S.t<float>, value: float): S.t<float> =>
|
|
38
|
+
schema->mark(JSON.Encode.float(value))
|
|
39
|
+
|
|
40
|
+
let string = (schema: S.t<string>, value: string): S.t<string> =>
|
|
41
|
+
schema->mark(JSON.Encode.string(value))
|
|
42
|
+
|
|
43
|
+
let bool = (schema: S.t<bool>, value: bool): S.t<bool> => schema->mark(JSON.Encode.bool(value))
|
|
44
|
+
|
|
45
|
+
/** The default a field declares. An optional field keeps its marker inside the
|
|
46
|
+
wrapper sury builds for `f?: t`, so the outer schema is read first and a
|
|
47
|
+
marker on the wrapper wins — the precedence `Semantic.getFrom` follows. */
|
|
48
|
+
let rec getFrom = (schema: S.t<unknown>): option<JSON.t> =>
|
|
49
|
+
switch S.Metadata.get(schema, ~id=defaultId) {
|
|
50
|
+
| Some(_) as found => found
|
|
51
|
+
| None => schema->Semantic.unwrapOptional->Option.flatMap(getFrom)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let get = (fieldSchema: S.t<'a>): option<JSON.t> => fieldSchema->S.castToUnknown->getFrom
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Sury from "sury";
|
|
4
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
|
+
import * as Semantic$Reventless from "../semantic/Semantic.res.mjs";
|
|
6
|
+
|
|
7
|
+
let defaultId = Sury.$Metadata_Id_make("reventless", "default");
|
|
8
|
+
|
|
9
|
+
function mark(schema, value) {
|
|
10
|
+
return Sury.$Metadata_set(schema, defaultId, value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function int(schema, value) {
|
|
14
|
+
return Sury.$Metadata_set(schema, defaultId, value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function float(schema, value) {
|
|
18
|
+
return Sury.$Metadata_set(schema, defaultId, value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function string(schema, value) {
|
|
22
|
+
return Sury.$Metadata_set(schema, defaultId, value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function bool(schema, value) {
|
|
26
|
+
return Sury.$Metadata_set(schema, defaultId, value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getFrom(schema) {
|
|
30
|
+
let found = Sury.$Metadata_get(schema, defaultId);
|
|
31
|
+
if (found !== undefined) {
|
|
32
|
+
return found;
|
|
33
|
+
} else {
|
|
34
|
+
return Stdlib_Option.flatMap(Semantic$Reventless.unwrapOptional(schema), getFrom);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let get = getFrom;
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
defaultId,
|
|
42
|
+
mark,
|
|
43
|
+
int,
|
|
44
|
+
float,
|
|
45
|
+
string,
|
|
46
|
+
bool,
|
|
47
|
+
getFrom,
|
|
48
|
+
get,
|
|
49
|
+
}
|
|
50
|
+
/* defaultId Not a pure module */
|