pi-daddy 0.49.0 → 0.49.1
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 +4 -0
- package/README.md +2 -0
- package/dist/governance/retention-contract.js +3 -3
- package/dist/governance/retention-contract.js.map +1 -1
- package/dist/governance/retention-validator.d.ts +7 -0
- package/dist/governance/retention-validator.d.ts.map +1 -0
- package/dist/governance/retention-validator.js +100 -0
- package/dist/governance/retention-validator.js.map +1 -0
- package/package.json +1 -1
- package/src/governance/retention-contract.ts +3 -3
- package/src/governance/retention-validator.ts +110 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog — pi-daddy
|
|
2
2
|
|
|
3
|
+
## 0.49.1 — 2026-10-10
|
|
4
|
+
|
|
5
|
+
- Fix standalone diagnostic export failing when Pi host peers are absent. Retention validation is dependency-free; no resolver hook or separate TypeBox installation is needed. The packaged smoke test now performs real offline exports and verifies filtered hashes, evidence gaps and unchanged source files.
|
|
6
|
+
|
|
3
7
|
## 0.49.0 — 2026-10-09
|
|
4
8
|
|
|
5
9
|
- Add a compact dashboard Settings view (`s`) for session Auto, JEV activation and child wall/idle timeouts. JEV uses the parent Pi paid-call and LoRA-storage dialogs; Auto cannot answer them. Timeout changes apply to future children. Depth, active-descendant and per-call limits remain visible startup settings. Update all ecosystem packages and restart Pi.
|
package/README.md
CHANGED
|
@@ -473,6 +473,8 @@ with only the files and retention roots you intend to inspect; relative paths re
|
|
|
473
473
|
pi-daddy diagnostics export selection.json /absolute/path/new-private-bundle
|
|
474
474
|
```
|
|
475
475
|
|
|
476
|
+
This offline command runs directly from the installed package without a Pi process or host-provided TypeBox.
|
|
477
|
+
|
|
476
478
|
The destination must be new with an existing canonical parent. It contains `inventory.json` and deduplicated
|
|
477
479
|
`objects/` files, with directories mode 0700 and files mode 0600. Originals remain untouched. Each entry records
|
|
478
480
|
its source digest and filtered-object digest separately; unchanged JSON strings inside packets retain their exact
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compileRetentionShape } from "./retention-validator.js";
|
|
2
2
|
import { parseRetentionJson } from "./retention-json.js";
|
|
3
3
|
const string = (maxLength = 512) => ({
|
|
4
4
|
type: "string",
|
|
@@ -113,7 +113,7 @@ export const RETENTION_SCHEMA = freeze({
|
|
|
113
113
|
},
|
|
114
114
|
],
|
|
115
115
|
});
|
|
116
|
-
const
|
|
116
|
+
const validateShape = compileRetentionShape(RETENTION_SCHEMA);
|
|
117
117
|
function freeze(value) {
|
|
118
118
|
if (value && typeof value === "object") {
|
|
119
119
|
for (const child of Object.values(value))
|
|
@@ -154,7 +154,7 @@ export function buildExecutionRetentionManifest(value) {
|
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
inspect(value, 0);
|
|
157
|
-
if (!
|
|
157
|
+
if (!validateShape(value))
|
|
158
158
|
throw new TypeError("invalid execution-retention 2.x manifest");
|
|
159
159
|
const m = JSON.parse(JSON.stringify(value));
|
|
160
160
|
if (m.native.sessionId !== m.nativeSession.sessionId ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retention-contract.js","sourceRoot":"","sources":["../../src/governance/retention-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"retention-contract.js","sourceRoot":"","sources":["../../src/governance/retention-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzD,MAAM,MAAM,GAAG,CAAC,SAAS,GAAG,GAAG,EAAE,EAAE,CAAC,CAAC;IACnC,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,CAAC;IACZ,SAAS;IACT,OAAO,EAAE,8BAA8B;CACxC,CAAC,CAAC;AACH,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC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O,CAAC,MAAM,KAAK,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC;QAE9G,MAAM,IAAI,SAAS,CAAC,iDAAiD,CAAC,CAAC;IACzE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC;AACD,MAAM,UAAU,+BAA+B,CAAC,IAAY;IAC1D,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI;QAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;IAClG,qGAAqG;IACrG,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,SAAS,CAAC,wBAAwB,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,+BAA+B,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Dependency-free evaluator for the fixed retention schema; unsupported vocabulary fails at construction. */
|
|
2
|
+
type Check = (value: unknown) => boolean;
|
|
3
|
+
type Schema = Record<string, any>;
|
|
4
|
+
/** This is internal retention vocabulary, not a general JSON Schema implementation. */
|
|
5
|
+
export declare function compileRetentionShape(schema: Schema): Check;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=retention-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention-validator.d.ts","sourceRoot":"","sources":["../../src/governance/retention-validator.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,KAAK,KAAK,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AACzC,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AA6BlC,uFAAuF;AACvF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CA6E3D"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2
|
+
const keywords = new Set([
|
|
3
|
+
"$schema",
|
|
4
|
+
"$id",
|
|
5
|
+
"type",
|
|
6
|
+
"const",
|
|
7
|
+
"enum",
|
|
8
|
+
"properties",
|
|
9
|
+
"required",
|
|
10
|
+
"additionalProperties",
|
|
11
|
+
"minLength",
|
|
12
|
+
"maxLength",
|
|
13
|
+
"pattern",
|
|
14
|
+
"minimum",
|
|
15
|
+
"maximum",
|
|
16
|
+
"items",
|
|
17
|
+
"maxItems",
|
|
18
|
+
"uniqueItems",
|
|
19
|
+
"anyOf",
|
|
20
|
+
"oneOf",
|
|
21
|
+
"allOf",
|
|
22
|
+
"not",
|
|
23
|
+
"if",
|
|
24
|
+
"then",
|
|
25
|
+
"else",
|
|
26
|
+
]);
|
|
27
|
+
/** This is internal retention vocabulary, not a general JSON Schema implementation. */
|
|
28
|
+
export function compileRetentionShape(schema) {
|
|
29
|
+
for (const key of Object.keys(schema))
|
|
30
|
+
if (!keywords.has(key))
|
|
31
|
+
throw new TypeError(`unsupported retention schema keyword: ${key}`);
|
|
32
|
+
const checks = [];
|
|
33
|
+
if (schema.type !== undefined) {
|
|
34
|
+
const types = {
|
|
35
|
+
object,
|
|
36
|
+
array: Array.isArray,
|
|
37
|
+
string: (value) => typeof value === "string",
|
|
38
|
+
boolean: (value) => typeof value === "boolean",
|
|
39
|
+
integer: Number.isInteger,
|
|
40
|
+
null: (value) => value === null,
|
|
41
|
+
};
|
|
42
|
+
if (!Object.hasOwn(types, schema.type))
|
|
43
|
+
throw new TypeError("unsupported retention schema type");
|
|
44
|
+
checks.push(types[schema.type]);
|
|
45
|
+
}
|
|
46
|
+
if (Object.hasOwn(schema, "const"))
|
|
47
|
+
checks.push((value) => value === schema.const);
|
|
48
|
+
if (schema.enum)
|
|
49
|
+
checks.push((value) => schema.enum.includes(value));
|
|
50
|
+
if (schema.properties) {
|
|
51
|
+
const properties = Object.entries(schema.properties).map(([key, shape]) => [key, compileRetentionShape(shape)]);
|
|
52
|
+
checks.push((value) => !object(value) || properties.every(([key, check]) => !Object.hasOwn(value, key) || check(value[key])));
|
|
53
|
+
}
|
|
54
|
+
if (schema.required)
|
|
55
|
+
checks.push((value) => !object(value) || schema.required.every((key) => Object.hasOwn(value, key)));
|
|
56
|
+
if (schema.additionalProperties !== undefined) {
|
|
57
|
+
if (schema.additionalProperties !== false)
|
|
58
|
+
throw new TypeError("unsupported retention additionalProperties");
|
|
59
|
+
checks.push((value) => !object(value) || Object.keys(value).every((key) => Object.hasOwn(schema.properties ?? {}, key)));
|
|
60
|
+
}
|
|
61
|
+
if (schema.pattern) {
|
|
62
|
+
const pattern = new RegExp(schema.pattern);
|
|
63
|
+
checks.push((value) => typeof value !== "string" || pattern.test(value));
|
|
64
|
+
}
|
|
65
|
+
if (schema.minLength !== undefined || schema.maxLength !== undefined)
|
|
66
|
+
checks.push((value) => typeof value !== "string" ||
|
|
67
|
+
([...value].length >= (schema.minLength ?? 0) && [...value].length <= (schema.maxLength ?? Infinity)));
|
|
68
|
+
if (schema.minimum !== undefined || schema.maximum !== undefined)
|
|
69
|
+
checks.push((value) => typeof value !== "number" || (value >= (schema.minimum ?? -Infinity) && value <= (schema.maximum ?? Infinity)));
|
|
70
|
+
if (schema.items) {
|
|
71
|
+
const check = compileRetentionShape(schema.items);
|
|
72
|
+
checks.push((value) => !Array.isArray(value) || value.every(check));
|
|
73
|
+
}
|
|
74
|
+
if (schema.maxItems !== undefined)
|
|
75
|
+
checks.push((value) => !Array.isArray(value) || value.length <= schema.maxItems);
|
|
76
|
+
if (schema.uniqueItems)
|
|
77
|
+
checks.push((value) => !Array.isArray(value) || new Set(value).size === value.length);
|
|
78
|
+
for (const kind of ["anyOf", "oneOf", "allOf"]) {
|
|
79
|
+
if (!schema[kind])
|
|
80
|
+
continue;
|
|
81
|
+
const alternatives = schema[kind].map(compileRetentionShape);
|
|
82
|
+
checks.push((value) => kind === "anyOf"
|
|
83
|
+
? alternatives.some((check) => check(value))
|
|
84
|
+
: kind === "allOf"
|
|
85
|
+
? alternatives.every((check) => check(value))
|
|
86
|
+
: alternatives.filter((check) => check(value)).length === 1);
|
|
87
|
+
}
|
|
88
|
+
if (schema.not) {
|
|
89
|
+
const check = compileRetentionShape(schema.not);
|
|
90
|
+
checks.push((value) => !check(value));
|
|
91
|
+
}
|
|
92
|
+
if (schema.if) {
|
|
93
|
+
const condition = compileRetentionShape(schema.if);
|
|
94
|
+
const yes = schema.then ? compileRetentionShape(schema.then) : () => true;
|
|
95
|
+
const no = schema.else ? compileRetentionShape(schema.else) : () => true;
|
|
96
|
+
checks.push((value) => (condition(value) ? yes(value) : no(value)));
|
|
97
|
+
}
|
|
98
|
+
return (value) => checks.every((check) => check(value));
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=retention-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention-validator.js","sourceRoot":"","sources":["../../src/governance/retention-validator.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,GAAG,CAAC,KAAc,EAAoC,EAAE,CAClE,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACvE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IACvB,SAAS;IACT,KAAK;IACL,MAAM;IACN,OAAO;IACP,MAAM;IACN,YAAY;IACZ,UAAU;IACV,sBAAsB;IACtB,WAAW;IACX,WAAW;IACX,SAAS;IACT,SAAS;IACT,SAAS;IACT,OAAO;IACP,UAAU;IACV,aAAa;IACb,OAAO;IACP,OAAO;IACP,OAAO;IACP,KAAK;IACL,IAAI;IACJ,MAAM;IACN,MAAM;CACP,CAAC,CAAC;AAEH,uFAAuF;AACvF,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CA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AAM,CAAC,EAAE,EAAE,CAAC;QACd,MAAM,SAAS,GAAG,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;QAC1E,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;QACzE,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-daddy",
|
|
3
|
-
"version": "0.49.
|
|
3
|
+
"version": "0.49.1",
|
|
4
4
|
"description": "Capability governance for pi sub-agents: spawn Agent Skills (SKILL.md) definitions whose allowed-tools becomes a grant that can only narrow going down a delegation tree, enforced by pi's own --tools allowlist, with an append-only ledger.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compileRetentionShape } from "./retention-validator.ts";
|
|
2
2
|
import { parseRetentionJson } from "./retention-json.ts";
|
|
3
3
|
import type { ExecutionRetentionManifest } from "./execution-retention.ts";
|
|
4
4
|
|
|
@@ -121,7 +121,7 @@ export const RETENTION_SCHEMA = freeze({
|
|
|
121
121
|
},
|
|
122
122
|
],
|
|
123
123
|
});
|
|
124
|
-
const
|
|
124
|
+
const validateShape = compileRetentionShape(RETENTION_SCHEMA);
|
|
125
125
|
function freeze<T>(value: T): T {
|
|
126
126
|
if (value && typeof value === "object") {
|
|
127
127
|
for (const child of Object.values(value)) freeze(child);
|
|
@@ -166,7 +166,7 @@ export function buildExecutionRetentionManifest(value: unknown): ExecutionRetent
|
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
168
|
inspect(value, 0);
|
|
169
|
-
if (!
|
|
169
|
+
if (!validateShape(value)) throw new TypeError("invalid execution-retention 2.x manifest");
|
|
170
170
|
const m = JSON.parse(JSON.stringify(value)) as ExecutionRetentionManifest;
|
|
171
171
|
if (
|
|
172
172
|
m.native.sessionId !== m.nativeSession.sessionId ||
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** Dependency-free evaluator for the fixed retention schema; unsupported vocabulary fails at construction. */
|
|
2
|
+
type Check = (value: unknown) => boolean;
|
|
3
|
+
type Schema = Record<string, any>;
|
|
4
|
+
const object = (value: unknown): value is Record<string, unknown> =>
|
|
5
|
+
value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
|
+
const keywords = new Set([
|
|
7
|
+
"$schema",
|
|
8
|
+
"$id",
|
|
9
|
+
"type",
|
|
10
|
+
"const",
|
|
11
|
+
"enum",
|
|
12
|
+
"properties",
|
|
13
|
+
"required",
|
|
14
|
+
"additionalProperties",
|
|
15
|
+
"minLength",
|
|
16
|
+
"maxLength",
|
|
17
|
+
"pattern",
|
|
18
|
+
"minimum",
|
|
19
|
+
"maximum",
|
|
20
|
+
"items",
|
|
21
|
+
"maxItems",
|
|
22
|
+
"uniqueItems",
|
|
23
|
+
"anyOf",
|
|
24
|
+
"oneOf",
|
|
25
|
+
"allOf",
|
|
26
|
+
"not",
|
|
27
|
+
"if",
|
|
28
|
+
"then",
|
|
29
|
+
"else",
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
/** This is internal retention vocabulary, not a general JSON Schema implementation. */
|
|
33
|
+
export function compileRetentionShape(schema: Schema): Check {
|
|
34
|
+
for (const key of Object.keys(schema))
|
|
35
|
+
if (!keywords.has(key)) throw new TypeError(`unsupported retention schema keyword: ${key}`);
|
|
36
|
+
const checks: Check[] = [];
|
|
37
|
+
if (schema.type !== undefined) {
|
|
38
|
+
const types: Record<string, Check> = {
|
|
39
|
+
object,
|
|
40
|
+
array: Array.isArray,
|
|
41
|
+
string: (value) => typeof value === "string",
|
|
42
|
+
boolean: (value) => typeof value === "boolean",
|
|
43
|
+
integer: Number.isInteger,
|
|
44
|
+
null: (value) => value === null,
|
|
45
|
+
};
|
|
46
|
+
if (!Object.hasOwn(types, schema.type)) throw new TypeError("unsupported retention schema type");
|
|
47
|
+
checks.push(types[schema.type]);
|
|
48
|
+
}
|
|
49
|
+
if (Object.hasOwn(schema, "const")) checks.push((value) => value === schema.const);
|
|
50
|
+
if (schema.enum) checks.push((value) => schema.enum.includes(value));
|
|
51
|
+
if (schema.properties) {
|
|
52
|
+
const properties = Object.entries(schema.properties).map(
|
|
53
|
+
([key, shape]) => [key, compileRetentionShape(shape as Schema)] as const,
|
|
54
|
+
);
|
|
55
|
+
checks.push(
|
|
56
|
+
(value) => !object(value) || properties.every(([key, check]) => !Object.hasOwn(value, key) || check(value[key])),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
if (schema.required)
|
|
60
|
+
checks.push((value) => !object(value) || schema.required.every((key: string) => Object.hasOwn(value, key)));
|
|
61
|
+
if (schema.additionalProperties !== undefined) {
|
|
62
|
+
if (schema.additionalProperties !== false) throw new TypeError("unsupported retention additionalProperties");
|
|
63
|
+
checks.push(
|
|
64
|
+
(value) => !object(value) || Object.keys(value).every((key) => Object.hasOwn(schema.properties ?? {}, key)),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
if (schema.pattern) {
|
|
68
|
+
const pattern = new RegExp(schema.pattern);
|
|
69
|
+
checks.push((value) => typeof value !== "string" || pattern.test(value));
|
|
70
|
+
}
|
|
71
|
+
if (schema.minLength !== undefined || schema.maxLength !== undefined)
|
|
72
|
+
checks.push(
|
|
73
|
+
(value) =>
|
|
74
|
+
typeof value !== "string" ||
|
|
75
|
+
([...value].length >= (schema.minLength ?? 0) && [...value].length <= (schema.maxLength ?? Infinity)),
|
|
76
|
+
);
|
|
77
|
+
if (schema.minimum !== undefined || schema.maximum !== undefined)
|
|
78
|
+
checks.push(
|
|
79
|
+
(value) =>
|
|
80
|
+
typeof value !== "number" || (value >= (schema.minimum ?? -Infinity) && value <= (schema.maximum ?? Infinity)),
|
|
81
|
+
);
|
|
82
|
+
if (schema.items) {
|
|
83
|
+
const check = compileRetentionShape(schema.items);
|
|
84
|
+
checks.push((value) => !Array.isArray(value) || value.every(check));
|
|
85
|
+
}
|
|
86
|
+
if (schema.maxItems !== undefined) checks.push((value) => !Array.isArray(value) || value.length <= schema.maxItems);
|
|
87
|
+
if (schema.uniqueItems) checks.push((value) => !Array.isArray(value) || new Set(value).size === value.length);
|
|
88
|
+
for (const kind of ["anyOf", "oneOf", "allOf"] as const) {
|
|
89
|
+
if (!schema[kind]) continue;
|
|
90
|
+
const alternatives = schema[kind].map(compileRetentionShape) as Check[];
|
|
91
|
+
checks.push((value) =>
|
|
92
|
+
kind === "anyOf"
|
|
93
|
+
? alternatives.some((check) => check(value))
|
|
94
|
+
: kind === "allOf"
|
|
95
|
+
? alternatives.every((check) => check(value))
|
|
96
|
+
: alternatives.filter((check) => check(value)).length === 1,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (schema.not) {
|
|
100
|
+
const check = compileRetentionShape(schema.not);
|
|
101
|
+
checks.push((value) => !check(value));
|
|
102
|
+
}
|
|
103
|
+
if (schema.if) {
|
|
104
|
+
const condition = compileRetentionShape(schema.if);
|
|
105
|
+
const yes = schema.then ? compileRetentionShape(schema.then) : () => true;
|
|
106
|
+
const no = schema.else ? compileRetentionShape(schema.else) : () => true;
|
|
107
|
+
checks.push((value) => (condition(value) ? yes(value) : no(value)));
|
|
108
|
+
}
|
|
109
|
+
return (value) => checks.every((check) => check(value));
|
|
110
|
+
}
|