@skmtc/core 0.27.0 → 0.28.0
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/esm/context/CoreContext.d.ts.map +1 -1
- package/esm/context/CoreContext.js +4 -2
- package/esm/context/GenerateContext.d.ts +12 -0
- package/esm/context/GenerateContext.d.ts.map +1 -1
- package/esm/context/GenerateContext.js +90 -14
- package/esm/context/generateTypes.d.ts +31 -0
- package/esm/context/generateTypes.d.ts.map +1 -1
- package/esm/dsl/model/ModelDriver.d.ts.map +1 -1
- package/esm/dsl/model/ModelDriver.js +1 -2
- package/esm/dsl/model/toModelProjectionBase.d.ts +1 -1
- package/esm/dsl/model/toModelProjectionBase.d.ts.map +1 -1
- package/esm/dsl/model/toModelProjectionBase.js +9 -9
- package/esm/dsl/operation/gql/GqlOperationDriver.d.ts.map +1 -1
- package/esm/dsl/operation/gql/GqlOperationDriver.js +1 -3
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +1 -1
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.d.ts.map +1 -1
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.js +9 -15
- package/esm/dsl/operation/oas/OasOperationDriver.d.ts.map +1 -1
- package/esm/dsl/operation/oas/OasOperationDriver.js +1 -3
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.d.ts +1 -1
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.d.ts.map +1 -1
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.js +9 -15
- package/esm/dsl/webhook/WebhookDriver.d.ts.map +1 -1
- package/esm/dsl/webhook/WebhookDriver.js +1 -3
- package/esm/dsl/webhook/toWebhookProjectionBase.d.ts +1 -1
- package/esm/dsl/webhook/toWebhookProjectionBase.d.ts.map +1 -1
- package/esm/dsl/webhook/toWebhookProjectionBase.js +9 -15
- package/esm/enrichments/EnrichmentAudit.d.ts +79 -0
- package/esm/enrichments/EnrichmentAudit.d.ts.map +1 -0
- package/esm/enrichments/EnrichmentAudit.js +210 -0
- package/esm/enrichments/EnrichmentWarning.d.ts +72 -0
- package/esm/enrichments/EnrichmentWarning.d.ts.map +1 -0
- package/esm/enrichments/EnrichmentWarning.js +50 -0
- package/esm/enrichments/findUnknownKeys.d.ts +40 -0
- package/esm/enrichments/findUnknownKeys.d.ts.map +1 -0
- package/esm/enrichments/findUnknownKeys.js +80 -0
- package/esm/enrichments/parseEnrichmentUmbrella.d.ts +63 -0
- package/esm/enrichments/parseEnrichmentUmbrella.d.ts.map +1 -0
- package/esm/enrichments/parseEnrichmentUmbrella.js +66 -0
- package/esm/enrichments/toEnrichmentDescriptor.d.ts.map +1 -1
- package/esm/enrichments/toEnrichmentDescriptor.js +1 -20
- package/esm/enrichments/valibotShape.d.ts +51 -0
- package/esm/enrichments/valibotShape.d.ts.map +1 -0
- package/esm/enrichments/valibotShape.js +37 -0
- package/esm/helpers/nearestKey.d.ts +18 -0
- package/esm/helpers/nearestKey.d.ts.map +1 -0
- package/esm/helpers/nearestKey.js +60 -0
- package/esm/mod.d.ts +2 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -0
- package/esm/run/toArtifacts.d.ts.map +1 -1
- package/esm/run/toArtifacts.js +2 -1
- package/esm/types/Manifest.d.ts +9 -0
- package/esm/types/Manifest.d.ts.map +1 -1
- package/esm/types/Manifest.js +2 -0
- package/package.json +1 -1
- package/script/context/CoreContext.d.ts.map +1 -1
- package/script/context/CoreContext.js +4 -2
- package/script/context/GenerateContext.d.ts +12 -0
- package/script/context/GenerateContext.d.ts.map +1 -1
- package/script/context/GenerateContext.js +90 -14
- package/script/context/generateTypes.d.ts +31 -0
- package/script/context/generateTypes.d.ts.map +1 -1
- package/script/dsl/model/ModelDriver.d.ts.map +1 -1
- package/script/dsl/model/ModelDriver.js +1 -5
- package/script/dsl/model/toModelProjectionBase.d.ts +1 -1
- package/script/dsl/model/toModelProjectionBase.d.ts.map +1 -1
- package/script/dsl/model/toModelProjectionBase.js +9 -45
- package/script/dsl/operation/gql/GqlOperationDriver.d.ts.map +1 -1
- package/script/dsl/operation/gql/GqlOperationDriver.js +1 -6
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +1 -1
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts.map +1 -1
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.js +9 -51
- package/script/dsl/operation/oas/OasOperationDriver.d.ts.map +1 -1
- package/script/dsl/operation/oas/OasOperationDriver.js +1 -6
- package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts +1 -1
- package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts.map +1 -1
- package/script/dsl/operation/oas/toOasOperationProjectionBase.js +9 -51
- package/script/dsl/webhook/WebhookDriver.d.ts.map +1 -1
- package/script/dsl/webhook/WebhookDriver.js +1 -6
- package/script/dsl/webhook/toWebhookProjectionBase.d.ts +1 -1
- package/script/dsl/webhook/toWebhookProjectionBase.d.ts.map +1 -1
- package/script/dsl/webhook/toWebhookProjectionBase.js +9 -51
- package/script/enrichments/EnrichmentAudit.d.ts +79 -0
- package/script/enrichments/EnrichmentAudit.d.ts.map +1 -0
- package/script/enrichments/EnrichmentAudit.js +215 -0
- package/script/enrichments/EnrichmentWarning.d.ts +72 -0
- package/script/enrichments/EnrichmentWarning.d.ts.map +1 -0
- package/script/enrichments/EnrichmentWarning.js +87 -0
- package/script/enrichments/findUnknownKeys.d.ts +40 -0
- package/script/enrichments/findUnknownKeys.d.ts.map +1 -0
- package/script/enrichments/findUnknownKeys.js +84 -0
- package/script/enrichments/parseEnrichmentUmbrella.d.ts +63 -0
- package/script/enrichments/parseEnrichmentUmbrella.d.ts.map +1 -0
- package/script/enrichments/parseEnrichmentUmbrella.js +103 -0
- package/script/enrichments/toEnrichmentDescriptor.d.ts.map +1 -1
- package/script/enrichments/toEnrichmentDescriptor.js +10 -29
- package/script/enrichments/valibotShape.d.ts +51 -0
- package/script/enrichments/valibotShape.d.ts.map +1 -0
- package/script/enrichments/valibotShape.js +44 -0
- package/script/helpers/nearestKey.d.ts +18 -0
- package/script/helpers/nearestKey.d.ts.map +1 -0
- package/script/helpers/nearestKey.js +64 -0
- package/script/mod.d.ts +2 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +2 -0
- package/script/run/toArtifacts.d.ts.map +1 -1
- package/script/run/toArtifacts.js +2 -1
- package/script/types/Manifest.d.ts +9 -0
- package/script/types/Manifest.d.ts.map +1 -1
- package/script/types/Manifest.js +2 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview The enrichment-warning surface — the manifest's record of
|
|
4
|
+
* enrichment config that did not do what the consumer intended.
|
|
5
|
+
*
|
|
6
|
+
* Three validation layers precede this one: structural validation at CLI
|
|
7
|
+
* load (`generatorEnrichments`), the per-leaf Valibot parse at generate
|
|
8
|
+
* time (a wrongly-typed value in a reached leaf throws), and the
|
|
9
|
+
* missing-`'main'` variant throw (`toVariantList`). All three are loud.
|
|
10
|
+
* What they cannot see is *addressing*: a typo'd generator id, path,
|
|
11
|
+
* method, or model name makes `get()` miss silently — defaults apply and
|
|
12
|
+
* the config entry is dead. Unknown leaf keys are equally silent:
|
|
13
|
+
* `v.object` strips them before the generator sees them.
|
|
14
|
+
*
|
|
15
|
+
* `EnrichmentWarning` is the shared shape for both detectors:
|
|
16
|
+
*
|
|
17
|
+
* - the **consumption audit** (`EnrichmentAudit`) — records every
|
|
18
|
+
* enrichment lookup the engine performs during the generate walk and,
|
|
19
|
+
* post-walk, flags configured entries no lookup ever touched;
|
|
20
|
+
* - **unknown-key detection** (`findUnknownKeys`, run inside
|
|
21
|
+
* `parseEnrichmentUmbrella`) — flags leaf keys the generator's schema
|
|
22
|
+
* does not declare.
|
|
23
|
+
*
|
|
24
|
+
* Both are warn-level and fail-open: generation output is never affected.
|
|
25
|
+
* The warnings ride the manifest (`manifest.enrichmentWarnings`) so
|
|
26
|
+
* post-run diagnostics can re-read them without re-running.
|
|
27
|
+
*
|
|
28
|
+
* @module EnrichmentWarning
|
|
29
|
+
*/
|
|
30
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
33
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
34
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
35
|
+
}
|
|
36
|
+
Object.defineProperty(o, k2, desc);
|
|
37
|
+
}) : (function(o, m, k, k2) {
|
|
38
|
+
if (k2 === undefined) k2 = k;
|
|
39
|
+
o[k2] = m[k];
|
|
40
|
+
}));
|
|
41
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
42
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
43
|
+
}) : function(o, v) {
|
|
44
|
+
o["default"] = v;
|
|
45
|
+
});
|
|
46
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
47
|
+
var ownKeys = function(o) {
|
|
48
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
49
|
+
var ar = [];
|
|
50
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
51
|
+
return ar;
|
|
52
|
+
};
|
|
53
|
+
return ownKeys(o);
|
|
54
|
+
};
|
|
55
|
+
return function (mod) {
|
|
56
|
+
if (mod && mod.__esModule) return mod;
|
|
57
|
+
var result = {};
|
|
58
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
59
|
+
__setModuleDefault(result, mod);
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
})();
|
|
63
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
+
exports.formatEnrichmentPath = exports.enrichmentWarning = exports.enrichmentWarningType = void 0;
|
|
65
|
+
const v = __importStar(require("valibot"));
|
|
66
|
+
exports.enrichmentWarningType = v.picklist([
|
|
67
|
+
'UNCONSUMED_ENRICHMENT',
|
|
68
|
+
'UNKNOWN_GENERATOR_ID',
|
|
69
|
+
'UNKNOWN_ENRICHMENT_KEY',
|
|
70
|
+
'SKIPPED_SUBJECT_ENRICHMENT',
|
|
71
|
+
'SKIPPED_GENERATOR_ENRICHMENT'
|
|
72
|
+
]);
|
|
73
|
+
exports.enrichmentWarning = v.object({
|
|
74
|
+
level: v.picklist(['warning', 'info']),
|
|
75
|
+
type: exports.enrichmentWarningType,
|
|
76
|
+
path: v.array(v.string()),
|
|
77
|
+
message: v.string(),
|
|
78
|
+
suggestion: v.optional(v.string())
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Render a routing path for warning messages:
|
|
82
|
+
* `['@skmtc/gen-shadcn-form', '/pets', 'post']` →
|
|
83
|
+
* `'@skmtc/gen-shadcn-form → /pets → post'`. The arrow separator keeps
|
|
84
|
+
* segments visually distinct even when they contain dots or slashes.
|
|
85
|
+
*/
|
|
86
|
+
const formatEnrichmentPath = (path) => path.join(' → ');
|
|
87
|
+
exports.formatEnrichmentPath = formatEnrichmentPath;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Unknown-key detection for enrichment leaves.
|
|
3
|
+
*
|
|
4
|
+
* Valibot's `v.object` strips keys the schema does not declare — a
|
|
5
|
+
* misspelled optional key (`submitLabl` for `submitLabel`) parses cleanly
|
|
6
|
+
* and the generator silently sees the default. `findUnknownKeys` walks a
|
|
7
|
+
* value against its schema and reports every key the schema would drop,
|
|
8
|
+
* so `parseEnrichmentUmbrella` can surface them as
|
|
9
|
+
* `UNKNOWN_ENRICHMENT_KEY` warnings.
|
|
10
|
+
*
|
|
11
|
+
* Comparing against the *schema* (not the parsed output) keeps the check
|
|
12
|
+
* immune to `v.pipe` transforms that legitimately reshape output, and
|
|
13
|
+
* gives correct "did you mean …?" suggestions — the intended key is in
|
|
14
|
+
* the schema's entries even when it is optional and absent from the
|
|
15
|
+
* parsed value. This is deliberately a warning layer, not
|
|
16
|
+
* `v.strictObject`: a shared client.json paired with an older generator
|
|
17
|
+
* version stays survivable under version skew instead of hard-failing.
|
|
18
|
+
*
|
|
19
|
+
* The walk is fail-open: unions, intersections, loose objects, and any
|
|
20
|
+
* shape it cannot attribute keys to are left alone.
|
|
21
|
+
*
|
|
22
|
+
* @module findUnknownKeys
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* One key the schema would silently drop. `path` runs from the walked
|
|
26
|
+
* root down to the unknown key (array indices as strings); `suggestion`
|
|
27
|
+
* is the nearest declared key at the same level, when a plausible typo
|
|
28
|
+
* target exists.
|
|
29
|
+
*/
|
|
30
|
+
export type UnknownKey = {
|
|
31
|
+
path: string[];
|
|
32
|
+
suggestion?: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Every key in `value` that `schema` does not declare and `v.parse` would
|
|
36
|
+
* therefore drop. Wrong-typed values are not this function's concern —
|
|
37
|
+
* the subsequent `v.parse` throws on those as before.
|
|
38
|
+
*/
|
|
39
|
+
export declare const findUnknownKeys: (schema: unknown, value: unknown) => UnknownKey[];
|
|
40
|
+
//# sourceMappingURL=findUnknownKeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findUnknownKeys.d.ts","sourceRoot":"","sources":["../../src/enrichments/findUnknownKeys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAgDD;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,OAAO,EAAE,OAAO,OAAO,KAAG,UAAU,EAI3E,CAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Unknown-key detection for enrichment leaves.
|
|
4
|
+
*
|
|
5
|
+
* Valibot's `v.object` strips keys the schema does not declare — a
|
|
6
|
+
* misspelled optional key (`submitLabl` for `submitLabel`) parses cleanly
|
|
7
|
+
* and the generator silently sees the default. `findUnknownKeys` walks a
|
|
8
|
+
* value against its schema and reports every key the schema would drop,
|
|
9
|
+
* so `parseEnrichmentUmbrella` can surface them as
|
|
10
|
+
* `UNKNOWN_ENRICHMENT_KEY` warnings.
|
|
11
|
+
*
|
|
12
|
+
* Comparing against the *schema* (not the parsed output) keeps the check
|
|
13
|
+
* immune to `v.pipe` transforms that legitimately reshape output, and
|
|
14
|
+
* gives correct "did you mean …?" suggestions — the intended key is in
|
|
15
|
+
* the schema's entries even when it is optional and absent from the
|
|
16
|
+
* parsed value. This is deliberately a warning layer, not
|
|
17
|
+
* `v.strictObject`: a shared client.json paired with an older generator
|
|
18
|
+
* version stays survivable under version skew instead of hard-failing.
|
|
19
|
+
*
|
|
20
|
+
* The walk is fail-open: unions, intersections, loose objects, and any
|
|
21
|
+
* shape it cannot attribute keys to are left alone.
|
|
22
|
+
*
|
|
23
|
+
* @module findUnknownKeys
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.findUnknownKeys = void 0;
|
|
27
|
+
const valibotShape_js_1 = require("./valibotShape.js");
|
|
28
|
+
const nearestKey_js_1 = require("../helpers/nearestKey.js");
|
|
29
|
+
const isRecord = (input) => typeof input === 'object' && input !== null && !Array.isArray(input);
|
|
30
|
+
const walk = (rawSchema, value, path, out) => {
|
|
31
|
+
if (value === undefined || value === null)
|
|
32
|
+
return;
|
|
33
|
+
if (!(0, valibotShape_js_1.isValibotSchema)(rawSchema))
|
|
34
|
+
return;
|
|
35
|
+
// A piped schema spreads its base, so `type` / `entries` / `item` are
|
|
36
|
+
// still visible here — no explicit pipe handling needed.
|
|
37
|
+
const { inner } = (0, valibotShape_js_1.unwrap)(rawSchema);
|
|
38
|
+
switch (inner.type) {
|
|
39
|
+
case 'object': {
|
|
40
|
+
if (!isRecord(value) || !(0, valibotShape_js_1.isEntriesRecord)(inner.entries))
|
|
41
|
+
return;
|
|
42
|
+
const entries = inner.entries;
|
|
43
|
+
const declared = Object.keys(entries);
|
|
44
|
+
for (const [key, member] of Object.entries(value)) {
|
|
45
|
+
if (key in entries) {
|
|
46
|
+
walk(entries[key], member, [...path, key], out);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const suggestion = (0, nearestKey_js_1.nearestKey)(key, declared);
|
|
50
|
+
out.push({ path: [...path, key], ...(suggestion !== undefined ? { suggestion } : {}) });
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
case 'record': {
|
|
55
|
+
if (!isRecord(value))
|
|
56
|
+
return;
|
|
57
|
+
for (const [key, member] of Object.entries(value)) {
|
|
58
|
+
walk(inner.value, member, [...path, key], out);
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
case 'array': {
|
|
63
|
+
if (!Array.isArray(value))
|
|
64
|
+
return;
|
|
65
|
+
value.forEach((member, index) => walk(inner.item, member, [...path, String(index)], out));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
default:
|
|
69
|
+
// Leaves, unions, intersections, loose/strict objects: nothing to
|
|
70
|
+
// attribute, or Valibot itself errors loudly (strict). Fail open.
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Every key in `value` that `schema` does not declare and `v.parse` would
|
|
76
|
+
* therefore drop. Wrong-typed values are not this function's concern —
|
|
77
|
+
* the subsequent `v.parse` throws on those as before.
|
|
78
|
+
*/
|
|
79
|
+
const findUnknownKeys = (schema, value) => {
|
|
80
|
+
const out = [];
|
|
81
|
+
walk(schema, value, [], out);
|
|
82
|
+
return out;
|
|
83
|
+
};
|
|
84
|
+
exports.findUnknownKeys = findUnknownKeys;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The shared umbrella-parse seam for the projection-base
|
|
3
|
+
* factories.
|
|
4
|
+
*
|
|
5
|
+
* Every `static toEnrichments` — OAS operation, webhook, GQL operation,
|
|
6
|
+
* model — assembles the same `{ subject, generator, stack }` umbrella
|
|
7
|
+
* from three storage spots and parses it through the generator's
|
|
8
|
+
* composite schema. This helper centralizes that assembly so both
|
|
9
|
+
* enrichment-validation mechanisms ride one seam:
|
|
10
|
+
*
|
|
11
|
+
* - the reads go through `context.readEnrichment` — the recording
|
|
12
|
+
* accessor feeding the consumption audit (`EnrichmentAudit`);
|
|
13
|
+
* - the raw values are diffed against the schema (`findUnknownKeys`)
|
|
14
|
+
* and dropped keys surface as `UNKNOWN_ENRICHMENT_KEY` warnings.
|
|
15
|
+
*
|
|
16
|
+
* The `stack` scope is exempt from unknown-key detection: it is a single
|
|
17
|
+
* bag shared by every generator in the composition, and each consumer
|
|
18
|
+
* declares only the fields it reads — keys other generators own are
|
|
19
|
+
* expected, not typos.
|
|
20
|
+
*
|
|
21
|
+
* A wrong-typed value still throws exactly as before — the `v.parse` at
|
|
22
|
+
* the end is unchanged, and unknown-key detection runs first so a
|
|
23
|
+
* throwing leaf doesn't hide a dropped key.
|
|
24
|
+
*
|
|
25
|
+
* @module parseEnrichmentUmbrella
|
|
26
|
+
*/
|
|
27
|
+
import * as v from 'valibot';
|
|
28
|
+
import { type EnrichmentWarning } from './EnrichmentWarning.js';
|
|
29
|
+
/**
|
|
30
|
+
* Minimal structural view of the context the parse needs. Any
|
|
31
|
+
* `GenerateContext` satisfies it; kept structural so the helper stays
|
|
32
|
+
* decoupled from the full context type and is trivially testable.
|
|
33
|
+
*/
|
|
34
|
+
type UmbrellaParseContext = {
|
|
35
|
+
readEnrichment: (segments: readonly string[]) => unknown;
|
|
36
|
+
reportEnrichmentWarning: (warning: EnrichmentWarning) => void;
|
|
37
|
+
};
|
|
38
|
+
type ParseEnrichmentUmbrellaArgs<EnrichmentType> = {
|
|
39
|
+
context: UmbrellaParseContext;
|
|
40
|
+
generatorId: string;
|
|
41
|
+
/**
|
|
42
|
+
* Subject routing segments under `[generatorId]`, including the
|
|
43
|
+
* variant — `[path, method, variant]` for OAS operations,
|
|
44
|
+
* `[name, method, variant]` for webhooks,
|
|
45
|
+
* `[rootKind, fieldName, variant]` for GQL operations,
|
|
46
|
+
* `[refName, variant]` for models.
|
|
47
|
+
*/
|
|
48
|
+
subjectSegments: readonly string[];
|
|
49
|
+
/** The generator's composite `{ subject, generator, stack }` schema. */
|
|
50
|
+
schema: v.GenericSchema<EnrichmentType>;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Assemble and parse one `{ subject, generator, stack }` enrichment
|
|
54
|
+
* umbrella, recording the reads for the consumption audit and reporting
|
|
55
|
+
* schema-dropped keys.
|
|
56
|
+
*
|
|
57
|
+
* @throws on a wrong-typed value, exactly like the raw `v.parse` this
|
|
58
|
+
* wraps — the generator's item is then recorded as `error` and the run
|
|
59
|
+
* continues (fail-open).
|
|
60
|
+
*/
|
|
61
|
+
export declare const parseEnrichmentUmbrella: <EnrichmentType>({ context, generatorId, subjectSegments, schema }: ParseEnrichmentUmbrellaArgs<EnrichmentType>) => EnrichmentType;
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=parseEnrichmentUmbrella.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseEnrichmentUmbrella.d.ts","sourceRoot":"","sources":["../../src/enrichments/parseEnrichmentUmbrella.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAG5B,OAAO,EAAwB,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAErF;;;;GAIG;AACH,KAAK,oBAAoB,GAAG;IAC1B,cAAc,EAAE,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAA;IACxD,uBAAuB,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAA;CAC9D,CAAA;AAED,KAAK,2BAA2B,CAAC,cAAc,IAAI;IACjD,OAAO,EAAE,oBAAoB,CAAA;IAC7B,WAAW,EAAE,MAAM,CAAA;IACnB;;;;;;OAMG;IACH,eAAe,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,wEAAwE;IACxE,MAAM,EAAE,CAAC,CAAC,aAAa,CAAC,cAAc,CAAC,CAAA;CACxC,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,GAAI,cAAc,EAAE,mDAKrD,2BAA2B,CAAC,cAAc,CAAC,KAAG,cAgChD,CAAA"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview The shared umbrella-parse seam for the projection-base
|
|
4
|
+
* factories.
|
|
5
|
+
*
|
|
6
|
+
* Every `static toEnrichments` — OAS operation, webhook, GQL operation,
|
|
7
|
+
* model — assembles the same `{ subject, generator, stack }` umbrella
|
|
8
|
+
* from three storage spots and parses it through the generator's
|
|
9
|
+
* composite schema. This helper centralizes that assembly so both
|
|
10
|
+
* enrichment-validation mechanisms ride one seam:
|
|
11
|
+
*
|
|
12
|
+
* - the reads go through `context.readEnrichment` — the recording
|
|
13
|
+
* accessor feeding the consumption audit (`EnrichmentAudit`);
|
|
14
|
+
* - the raw values are diffed against the schema (`findUnknownKeys`)
|
|
15
|
+
* and dropped keys surface as `UNKNOWN_ENRICHMENT_KEY` warnings.
|
|
16
|
+
*
|
|
17
|
+
* The `stack` scope is exempt from unknown-key detection: it is a single
|
|
18
|
+
* bag shared by every generator in the composition, and each consumer
|
|
19
|
+
* declares only the fields it reads — keys other generators own are
|
|
20
|
+
* expected, not typos.
|
|
21
|
+
*
|
|
22
|
+
* A wrong-typed value still throws exactly as before — the `v.parse` at
|
|
23
|
+
* the end is unchanged, and unknown-key detection runs first so a
|
|
24
|
+
* throwing leaf doesn't hide a dropped key.
|
|
25
|
+
*
|
|
26
|
+
* @module parseEnrichmentUmbrella
|
|
27
|
+
*/
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}) : (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
o[k2] = m[k];
|
|
38
|
+
}));
|
|
39
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
+
}) : function(o, v) {
|
|
42
|
+
o["default"] = v;
|
|
43
|
+
});
|
|
44
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
45
|
+
var ownKeys = function(o) {
|
|
46
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
47
|
+
var ar = [];
|
|
48
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
49
|
+
return ar;
|
|
50
|
+
};
|
|
51
|
+
return ownKeys(o);
|
|
52
|
+
};
|
|
53
|
+
return function (mod) {
|
|
54
|
+
if (mod && mod.__esModule) return mod;
|
|
55
|
+
var result = {};
|
|
56
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
57
|
+
__setModuleDefault(result, mod);
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
})();
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
exports.parseEnrichmentUmbrella = void 0;
|
|
63
|
+
const v = __importStar(require("valibot"));
|
|
64
|
+
const Enrichments_js_1 = require("../types/Enrichments.js");
|
|
65
|
+
const findUnknownKeys_js_1 = require("./findUnknownKeys.js");
|
|
66
|
+
const EnrichmentWarning_js_1 = require("./EnrichmentWarning.js");
|
|
67
|
+
/**
|
|
68
|
+
* Assemble and parse one `{ subject, generator, stack }` enrichment
|
|
69
|
+
* umbrella, recording the reads for the consumption audit and reporting
|
|
70
|
+
* schema-dropped keys.
|
|
71
|
+
*
|
|
72
|
+
* @throws on a wrong-typed value, exactly like the raw `v.parse` this
|
|
73
|
+
* wraps — the generator's item is then recorded as `error` and the run
|
|
74
|
+
* continues (fail-open).
|
|
75
|
+
*/
|
|
76
|
+
const parseEnrichmentUmbrella = ({ context, generatorId, subjectSegments, schema }) => {
|
|
77
|
+
const raw = {
|
|
78
|
+
subject: context.readEnrichment([generatorId, ...subjectSegments]),
|
|
79
|
+
generator: context.readEnrichment([generatorId, Enrichments_js_1.GENERATOR_ENRICHMENT_KEY]),
|
|
80
|
+
stack: context.readEnrichment([Enrichments_js_1.STACK_ENRICHMENT_KEY])
|
|
81
|
+
};
|
|
82
|
+
// Diff the generator-owned scopes against the schema (stack excluded —
|
|
83
|
+
// shared bag). Walking the umbrella keeps the scope schemas attributed
|
|
84
|
+
// without reaching into the composite's entries.
|
|
85
|
+
const unknownKeys = (0, findUnknownKeys_js_1.findUnknownKeys)(schema, { subject: raw.subject, generator: raw.generator });
|
|
86
|
+
for (const { path, suggestion } of unknownKeys) {
|
|
87
|
+
const [scope, ...leafPath] = path;
|
|
88
|
+
const routingPath = scope === 'subject'
|
|
89
|
+
? [generatorId, ...subjectSegments, ...leafPath]
|
|
90
|
+
: [generatorId, Enrichments_js_1.GENERATOR_ENRICHMENT_KEY, ...leafPath];
|
|
91
|
+
context.reportEnrichmentWarning({
|
|
92
|
+
level: 'warning',
|
|
93
|
+
type: 'UNKNOWN_ENRICHMENT_KEY',
|
|
94
|
+
path: routingPath,
|
|
95
|
+
message: `unknown enrichment key '${routingPath[routingPath.length - 1]}' at ` +
|
|
96
|
+
`'${(0, EnrichmentWarning_js_1.formatEnrichmentPath)(routingPath.slice(0, -1))}' — ignored` +
|
|
97
|
+
(suggestion !== undefined ? ` (did you mean '${suggestion}'?)` : ''),
|
|
98
|
+
...(suggestion !== undefined ? { suggestion } : {})
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return v.parse(schema, raw);
|
|
102
|
+
};
|
|
103
|
+
exports.parseEnrichmentUmbrella = parseEnrichmentUmbrella;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toEnrichmentDescriptor.d.ts","sourceRoot":"","sources":["../../src/enrichments/toEnrichmentDescriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"toEnrichmentDescriptor.d.ts","sourceRoot":"","sources":["../../src/enrichments/toEnrichmentDescriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAA;AAUjC;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAA;IACX,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,oDAAoD;IACpD,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,8BAA8B;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,GACD;IACE,IAAI,EAAE,cAAc,CAAA;IACpB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB,GACD;IACE,IAAI,EAAE,OAAO,CAAA;IACb,0BAA0B;IAC1B,IAAI,EAAE,eAAe,CAAA;CACtB,GACD;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,kCAAkC;IAClC,MAAM,EAAE,eAAe,EAAE,CAAA;CAC1B,CAAA;AAEL;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,oBAAoB,CAAA;AAExE,sEAAsE;AACtE,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;AAEzD,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,OAAO,GAAG,SAAS,CAAA;AAE3D;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,WAAW,CAAA;IACxB;;;;;OAKG;IACH,eAAe,EAAE,OAAO,CAAA;IACxB,MAAM,EAAE,eAAe,EAAE,CAAA;CAC1B,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,cAAc,GAAG,OAAO,GAAG,SAAS,CAAA;IACpE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC,CAAC,aAAa,CAAA;IACnD;;;;;;OAMG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,OAAO,CAAA;CACxC,CAAA;AAwGD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,CAAC,CAAC,aAAa,GAAG,SAAS,KAAG,eAAe,EAKvF,CAAA;AAsBD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,gBAAgB,KAAG,oBAK/D,CAAA"}
|
|
@@ -2,27 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toEnrichmentDescriptor = exports.toEnrichmentFields = void 0;
|
|
4
4
|
const ModuleSelect_js_1 = require("../types/ModuleSelect.js");
|
|
5
|
-
const
|
|
6
|
-
input !== null &&
|
|
7
|
-
'type' in input &&
|
|
8
|
-
typeof input.type === 'string';
|
|
9
|
-
const isEntriesRecord = (input) => typeof input === 'object' && input !== null;
|
|
5
|
+
const valibotShape_js_1 = require("./valibotShape.js");
|
|
10
6
|
const isOptionsArray = (input) => Array.isArray(input);
|
|
11
|
-
const WRAPPER_TYPES = new Set(['optional', 'nullable', 'nullish']);
|
|
12
|
-
const unwrap = (schema) => {
|
|
13
|
-
if (WRAPPER_TYPES.has(schema.type) && isValibotSchema(schema.wrapped)) {
|
|
14
|
-
return { inner: schema.wrapped, optional: true };
|
|
15
|
-
}
|
|
16
|
-
return { inner: schema, optional: false };
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* A `v.pipe(base, …actions)` schema spreads `base` and adds a `pipe` array
|
|
20
|
-
* whose first element IS the original base schema. The `moduleSelect`
|
|
21
|
-
* registry lookup must therefore also check the pipe's base, or piping a
|
|
22
|
-
* moduleSelect through metadata (`v.title(…)`) would silently demote it to
|
|
23
|
-
* a generic object widget.
|
|
24
|
-
*/
|
|
25
|
-
const baseOf = (schema) => Array.isArray(schema.pipe) && isValibotSchema(schema.pipe[0]) ? schema.pipe[0] : schema;
|
|
26
7
|
/** The `v.title(…)` metadata riding a piped schema, if any — the field label. */
|
|
27
8
|
const titleOf = (schema) => {
|
|
28
9
|
if (!Array.isArray(schema.pipe))
|
|
@@ -49,7 +30,7 @@ const titleOf = (schema) => {
|
|
|
49
30
|
* rule is structural — it names no scope, so it composes with the generic
|
|
50
31
|
* object walk rather than special-casing `subject` / `generator` / `stack`.
|
|
51
32
|
*/
|
|
52
|
-
const isOmittedMember = (rawSchema) => isValibotSchema(rawSchema) && unwrap(rawSchema).inner.type === 'undefined';
|
|
33
|
+
const isOmittedMember = (rawSchema) => (0, valibotShape_js_1.isValibotSchema)(rawSchema) && (0, valibotShape_js_1.unwrap)(rawSchema).inner.type === 'undefined';
|
|
53
34
|
const toLabel = (key) => {
|
|
54
35
|
if (key === '')
|
|
55
36
|
return '';
|
|
@@ -57,7 +38,7 @@ const toLabel = (key) => {
|
|
|
57
38
|
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
58
39
|
};
|
|
59
40
|
const typeFor = (schema) => {
|
|
60
|
-
const moduleType = (0, ModuleSelect_js_1.moduleTypeOf)(schema) ?? (0, ModuleSelect_js_1.moduleTypeOf)(baseOf(schema));
|
|
41
|
+
const moduleType = (0, ModuleSelect_js_1.moduleTypeOf)(schema) ?? (0, ModuleSelect_js_1.moduleTypeOf)((0, valibotShape_js_1.baseOf)(schema));
|
|
61
42
|
if (moduleType !== undefined) {
|
|
62
43
|
return { type: 'moduleSelect', moduleType };
|
|
63
44
|
}
|
|
@@ -73,14 +54,14 @@ const typeFor = (schema) => {
|
|
|
73
54
|
return { type: 'select', options: opts };
|
|
74
55
|
}
|
|
75
56
|
case 'object': {
|
|
76
|
-
const entries = isEntriesRecord(schema.entries) ? schema.entries : {};
|
|
57
|
+
const entries = (0, valibotShape_js_1.isEntriesRecord)(schema.entries) ? schema.entries : {};
|
|
77
58
|
return {
|
|
78
59
|
type: 'object',
|
|
79
60
|
fields: walkEntries(entries)
|
|
80
61
|
};
|
|
81
62
|
}
|
|
82
63
|
case 'array': {
|
|
83
|
-
if (isValibotSchema(schema.item)) {
|
|
64
|
+
if ((0, valibotShape_js_1.isValibotSchema)(schema.item)) {
|
|
84
65
|
return { type: 'array', item: walkFromShape('', schema.item) };
|
|
85
66
|
}
|
|
86
67
|
// An unrecognisable item schema degrades to a text item — consistent
|
|
@@ -92,14 +73,14 @@ const typeFor = (schema) => {
|
|
|
92
73
|
}
|
|
93
74
|
};
|
|
94
75
|
const walkFromShape = (key, rawSchema) => {
|
|
95
|
-
const { inner, optional } = unwrap(rawSchema);
|
|
76
|
+
const { inner, optional } = (0, valibotShape_js_1.unwrap)(rawSchema);
|
|
96
77
|
// A `v.title(…)` label wins over the key-derived one; the title may ride
|
|
97
78
|
// the schema itself or sit inside an optional wrapper.
|
|
98
79
|
const label = titleOf(inner) ?? titleOf(rawSchema) ?? toLabel(key);
|
|
99
80
|
return { key, label, optional, ...typeFor(inner) };
|
|
100
81
|
};
|
|
101
82
|
const walkField = (key, rawSchema) => {
|
|
102
|
-
if (!isValibotSchema(rawSchema)) {
|
|
83
|
+
if (!(0, valibotShape_js_1.isValibotSchema)(rawSchema)) {
|
|
103
84
|
return { key, label: toLabel(key), optional: false, type: 'text' };
|
|
104
85
|
}
|
|
105
86
|
return walkFromShape(key, rawSchema);
|
|
@@ -134,10 +115,10 @@ const walkEntries = (entries) => Object.keys(entries)
|
|
|
134
115
|
* when only the field shape is needed.
|
|
135
116
|
*/
|
|
136
117
|
const toEnrichmentFields = (schema) => {
|
|
137
|
-
if (!isValibotSchema(schema))
|
|
118
|
+
if (!(0, valibotShape_js_1.isValibotSchema)(schema))
|
|
138
119
|
return [];
|
|
139
|
-
const { inner } = unwrap(schema);
|
|
140
|
-
if (inner.type !== 'object' || !isEntriesRecord(inner.entries))
|
|
120
|
+
const { inner } = (0, valibotShape_js_1.unwrap)(schema);
|
|
121
|
+
if (inner.type !== 'object' || !(0, valibotShape_js_1.isEntriesRecord)(inner.entries))
|
|
141
122
|
return [];
|
|
142
123
|
return walkEntries(inner.entries);
|
|
143
124
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Structural view of Valibot schemas as observed at runtime.
|
|
3
|
+
*
|
|
4
|
+
* Valibot's declared `GenericSchema` is opaque (intentionally a black box
|
|
5
|
+
* for parse calls) but the runtime objects expose tagged-union shape via
|
|
6
|
+
* `type` plus the wrapper / container properties below. The walkers that
|
|
7
|
+
* traverse generator enrichment schemas — `toEnrichmentDescriptor` (form
|
|
8
|
+
* projection) and `findUnknownKeys` (dropped-key detection) — narrow into
|
|
9
|
+
* this view once at each entry point and stay inside it.
|
|
10
|
+
*
|
|
11
|
+
* @module valibotShape
|
|
12
|
+
*/
|
|
13
|
+
import type * as v from 'valibot';
|
|
14
|
+
/**
|
|
15
|
+
* The runtime shape of a Valibot schema node. `wrapped` carries the inner
|
|
16
|
+
* schema of `optional` / `nullable` / `nullish` wrappers; `entries` the
|
|
17
|
+
* member schemas of an `object`; `item` an `array`'s element schema;
|
|
18
|
+
* `key` / `value` a `record`'s key and value schemas; `options` a
|
|
19
|
+
* `picklist` / union's choices; `pipe` a `v.pipe(...)`'s action chain
|
|
20
|
+
* (whose first element is the base schema).
|
|
21
|
+
*/
|
|
22
|
+
export type ValibotSchemaShape = {
|
|
23
|
+
readonly type: string;
|
|
24
|
+
readonly wrapped?: unknown;
|
|
25
|
+
readonly entries?: unknown;
|
|
26
|
+
readonly item?: unknown;
|
|
27
|
+
readonly key?: unknown;
|
|
28
|
+
readonly value?: unknown;
|
|
29
|
+
readonly options?: unknown;
|
|
30
|
+
readonly pipe?: unknown;
|
|
31
|
+
};
|
|
32
|
+
export declare const isValibotSchema: (input: unknown) => input is ValibotSchemaShape;
|
|
33
|
+
export declare const isEntriesRecord: (input: unknown) => input is Record<string, v.GenericSchema>;
|
|
34
|
+
/**
|
|
35
|
+
* Strip a single `optional` / `nullable` / `nullish` wrapper, reporting
|
|
36
|
+
* whether one was present. Wrappers don't nest in practice (a schema is
|
|
37
|
+
* declared optional once), so one level suffices.
|
|
38
|
+
*/
|
|
39
|
+
export declare const unwrap: (schema: ValibotSchemaShape) => {
|
|
40
|
+
inner: ValibotSchemaShape;
|
|
41
|
+
optional: boolean;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A `v.pipe(base, …actions)` schema spreads `base` and adds a `pipe` array
|
|
45
|
+
* whose first element IS the original base schema. Lookups keyed on schema
|
|
46
|
+
* *identity* (e.g. the `moduleSelect` registry) must therefore also check
|
|
47
|
+
* the pipe's base, or piping a schema through metadata (`v.title(…)`)
|
|
48
|
+
* would silently break the lookup.
|
|
49
|
+
*/
|
|
50
|
+
export declare const baseOf: (schema: ValibotSchemaShape) => ValibotSchemaShape;
|
|
51
|
+
//# sourceMappingURL=valibotShape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valibotShape.d.ts","sourceRoot":"","sources":["../../src/enrichments/valibotShape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAA;AAEjC;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,kBAIH,CAAA;AAEvD,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,aAAa,CAC3C,CAAA;AAI7C;;;;GAIG;AACH,eAAO,MAAM,MAAM,GACjB,QAAQ,kBAAkB,KACzB;IAAE,KAAK,EAAE,kBAAkB,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAKhD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,GAAI,QAAQ,kBAAkB,KAAG,kBACqC,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Structural view of Valibot schemas as observed at runtime.
|
|
4
|
+
*
|
|
5
|
+
* Valibot's declared `GenericSchema` is opaque (intentionally a black box
|
|
6
|
+
* for parse calls) but the runtime objects expose tagged-union shape via
|
|
7
|
+
* `type` plus the wrapper / container properties below. The walkers that
|
|
8
|
+
* traverse generator enrichment schemas — `toEnrichmentDescriptor` (form
|
|
9
|
+
* projection) and `findUnknownKeys` (dropped-key detection) — narrow into
|
|
10
|
+
* this view once at each entry point and stay inside it.
|
|
11
|
+
*
|
|
12
|
+
* @module valibotShape
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.baseOf = exports.unwrap = exports.isEntriesRecord = exports.isValibotSchema = void 0;
|
|
16
|
+
const isValibotSchema = (input) => typeof input === 'object' &&
|
|
17
|
+
input !== null &&
|
|
18
|
+
'type' in input &&
|
|
19
|
+
typeof input.type === 'string';
|
|
20
|
+
exports.isValibotSchema = isValibotSchema;
|
|
21
|
+
const isEntriesRecord = (input) => typeof input === 'object' && input !== null;
|
|
22
|
+
exports.isEntriesRecord = isEntriesRecord;
|
|
23
|
+
const WRAPPER_TYPES = new Set(['optional', 'nullable', 'nullish']);
|
|
24
|
+
/**
|
|
25
|
+
* Strip a single `optional` / `nullable` / `nullish` wrapper, reporting
|
|
26
|
+
* whether one was present. Wrappers don't nest in practice (a schema is
|
|
27
|
+
* declared optional once), so one level suffices.
|
|
28
|
+
*/
|
|
29
|
+
const unwrap = (schema) => {
|
|
30
|
+
if (WRAPPER_TYPES.has(schema.type) && (0, exports.isValibotSchema)(schema.wrapped)) {
|
|
31
|
+
return { inner: schema.wrapped, optional: true };
|
|
32
|
+
}
|
|
33
|
+
return { inner: schema, optional: false };
|
|
34
|
+
};
|
|
35
|
+
exports.unwrap = unwrap;
|
|
36
|
+
/**
|
|
37
|
+
* A `v.pipe(base, …actions)` schema spreads `base` and adds a `pipe` array
|
|
38
|
+
* whose first element IS the original base schema. Lookups keyed on schema
|
|
39
|
+
* *identity* (e.g. the `moduleSelect` registry) must therefore also check
|
|
40
|
+
* the pipe's base, or piping a schema through metadata (`v.title(…)`)
|
|
41
|
+
* would silently break the lookup.
|
|
42
|
+
*/
|
|
43
|
+
const baseOf = (schema) => Array.isArray(schema.pipe) && (0, exports.isValibotSchema)(schema.pipe[0]) ? schema.pipe[0] : schema;
|
|
44
|
+
exports.baseOf = baseOf;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Nearest-key suggestion for "did you mean …?" hints.
|
|
3
|
+
*
|
|
4
|
+
* Used by the enrichment validation surfaces (`EnrichmentAudit`,
|
|
5
|
+
* `findUnknownKeys`) to pair an unrecognized key with its closest known
|
|
6
|
+
* sibling. Pure string utility — no context, no schema awareness.
|
|
7
|
+
*
|
|
8
|
+
* @module nearestKey
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The candidate closest to `target`, or `undefined` when nothing is close
|
|
12
|
+
* enough to be a plausible typo. A case-only mismatch (`POST` for `post`)
|
|
13
|
+
* always wins; otherwise candidates compete within a small edit-distance
|
|
14
|
+
* budget (1 for short keys, 2 otherwise). An exact match returns
|
|
15
|
+
* `undefined` — a key that exists needs no suggestion.
|
|
16
|
+
*/
|
|
17
|
+
export declare const nearestKey: (target: string, candidates: Iterable<string>) => string | undefined;
|
|
18
|
+
//# sourceMappingURL=nearestKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nearestKey.d.ts","sourceRoot":"","sources":["../../src/helpers/nearestKey.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA+BH;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,EAAE,YAAY,QAAQ,CAAC,MAAM,CAAC,KAAG,MAAM,GAAG,SAmBlF,CAAA"}
|