@agentshouse/mdmodel 0.1.0-alpha.6 → 0.1.0-alpha.7
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/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +15 -37
- package/dist/schema.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -3
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,iBAAiB,CAAC;AAkB7D,wBAAgB,cAAc,CAC5B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EAC3C,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,gBAAgB,GAAG,YAAY,GAAG,YAAY,CAAA;CAAE,GAAG,SAAS,CAUrF"}
|
package/dist/schema.js
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import formatsPlugin from 'ajv-formats';
|
|
3
|
-
const addFormats = formatsPlugin;
|
|
4
|
-
const ajv = new Ajv({
|
|
5
|
-
allErrors: true,
|
|
6
|
-
strict: false,
|
|
7
|
-
validateFormats: true
|
|
8
|
-
});
|
|
9
|
-
addFormats(ajv, [
|
|
10
|
-
'date'
|
|
11
|
-
]);
|
|
1
|
+
import { Validator } from '@cfworker/json-schema';
|
|
12
2
|
function scalarSchema(spec) {
|
|
13
3
|
if (spec.kind === 'string' || spec.kind === 'reference') return {
|
|
14
4
|
type: 'string'
|
|
@@ -35,36 +25,24 @@ function fieldSchema(spec) {
|
|
|
35
25
|
return scalarSchema(spec);
|
|
36
26
|
}
|
|
37
27
|
function ruleFor(error) {
|
|
38
|
-
|
|
39
|
-
if (error.keyword === 'enum') return 'field-enum';
|
|
40
|
-
return 'field-kind';
|
|
41
|
-
}
|
|
42
|
-
function locationFor(error) {
|
|
43
|
-
if (error.keyword === 'required' && typeof error.params.missingProperty === 'string') {
|
|
44
|
-
return error.params.missingProperty;
|
|
45
|
-
}
|
|
46
|
-
const path = error.instancePath.replace(/^\//, '').split('/');
|
|
47
|
-
return path[0] ?? '';
|
|
28
|
+
return error.keyword === 'enum' ? 'field-enum' : 'field-kind';
|
|
48
29
|
}
|
|
49
30
|
export function validateFields(fields, values) {
|
|
50
|
-
const properties = {};
|
|
51
|
-
const required = [];
|
|
52
31
|
for (const [name, spec] of Object.entries(fields)){
|
|
53
|
-
|
|
54
|
-
|
|
32
|
+
if (spec.required && values[name] === undefined) return {
|
|
33
|
+
field: name,
|
|
34
|
+
rule: 'required-field'
|
|
35
|
+
};
|
|
55
36
|
}
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return
|
|
65
|
-
field: locationFor(error),
|
|
66
|
-
rule: ruleFor(error)
|
|
67
|
-
};
|
|
37
|
+
for (const [name, spec] of Object.entries(fields)){
|
|
38
|
+
if (values[name] === undefined) continue;
|
|
39
|
+
const result = new Validator(fieldSchema(spec), '2020-12', false).validate(values[name]);
|
|
40
|
+
if (!result.valid) return {
|
|
41
|
+
field: name,
|
|
42
|
+
rule: ruleFor(result.errors[0])
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
68
46
|
}
|
|
69
47
|
|
|
70
48
|
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdmodel/src/schema.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdmodel/src/schema.ts"],"sourcesContent":["import { Validator, type OutputUnit } from '@cfworker/json-schema';\nimport type { FieldSpec, ScalarSpec } from './definition.js';\n\nfunction scalarSchema(spec: ScalarSpec): Record<string, unknown> {\n if (spec.kind === 'string' || spec.kind === 'reference') return { type: 'string' };\n if (spec.kind === 'number') return { type: 'number' };\n if (spec.kind === 'date') return { type: 'string', format: 'date' };\n return { type: 'string', enum: [...spec.values] };\n}\n\nfunction fieldSchema(spec: FieldSpec): Record<string, unknown> {\n if (spec.kind === 'list') return { type: 'array', items: scalarSchema(spec.of) };\n return scalarSchema(spec);\n}\n\nfunction ruleFor(error: OutputUnit): 'field-enum' | 'field-kind' {\n return error.keyword === 'enum' ? 'field-enum' : 'field-kind';\n}\n\nexport function validateFields(\n fields: Readonly<Record<string, FieldSpec>>,\n values: Readonly<Record<string, unknown>>,\n): { field: string; rule: 'required-field' | 'field-enum' | 'field-kind' } | undefined {\n for (const [name, spec] of Object.entries(fields)) {\n if (spec.required && values[name] === undefined) return { field: name, rule: 'required-field' };\n }\n for (const [name, spec] of Object.entries(fields)) {\n if (values[name] === undefined) continue;\n const result = new Validator(fieldSchema(spec), '2020-12', false).validate(values[name]);\n if (!result.valid) return { field: name, rule: ruleFor(result.errors[0]!) };\n }\n return undefined;\n}\n"],"names":["Validator","scalarSchema","spec","kind","type","format","enum","values","fieldSchema","items","of","ruleFor","error","keyword","validateFields","fields","name","Object","entries","required","undefined","field","rule","result","validate","valid","errors"],"mappings":"AAAA,SAASA,SAAS,QAAyB,wBAAwB;AAGnE,SAASC,aAAaC,IAAgB;IACpC,IAAIA,KAAKC,IAAI,KAAK,YAAYD,KAAKC,IAAI,KAAK,aAAa,OAAO;QAAEC,MAAM;IAAS;IACjF,IAAIF,KAAKC,IAAI,KAAK,UAAU,OAAO;QAAEC,MAAM;IAAS;IACpD,IAAIF,KAAKC,IAAI,KAAK,QAAQ,OAAO;QAAEC,MAAM;QAAUC,QAAQ;IAAO;IAClE,OAAO;QAAED,MAAM;QAAUE,MAAM;eAAIJ,KAAKK,MAAM;SAAC;IAAC;AAClD;AAEA,SAASC,YAAYN,IAAe;IAClC,IAAIA,KAAKC,IAAI,KAAK,QAAQ,OAAO;QAAEC,MAAM;QAASK,OAAOR,aAAaC,KAAKQ,EAAE;IAAE;IAC/E,OAAOT,aAAaC;AACtB;AAEA,SAASS,QAAQC,KAAiB;IAChC,OAAOA,MAAMC,OAAO,KAAK,SAAS,eAAe;AACnD;AAEA,OAAO,SAASC,eACdC,MAA2C,EAC3CR,MAAyC;IAEzC,KAAK,MAAM,CAACS,MAAMd,KAAK,IAAIe,OAAOC,OAAO,CAACH,QAAS;QACjD,IAAIb,KAAKiB,QAAQ,IAAIZ,MAAM,CAACS,KAAK,KAAKI,WAAW,OAAO;YAAEC,OAAOL;YAAMM,MAAM;QAAiB;IAChG;IACA,KAAK,MAAM,CAACN,MAAMd,KAAK,IAAIe,OAAOC,OAAO,CAACH,QAAS;QACjD,IAAIR,MAAM,CAACS,KAAK,KAAKI,WAAW;QAChC,MAAMG,SAAS,IAAIvB,UAAUQ,YAAYN,OAAO,WAAW,OAAOsB,QAAQ,CAACjB,MAAM,CAACS,KAAK;QACvF,IAAI,CAACO,OAAOE,KAAK,EAAE,OAAO;YAAEJ,OAAOL;YAAMM,MAAMX,QAAQY,OAAOG,MAAM,CAAC,EAAE;QAAG;IAC5E;IACA,OAAON;AACT"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.1.0-alpha.7";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdmodel/src/version.ts"],"sourcesContent":["export const VERSION = '0.1.0-alpha.
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdmodel/src/version.ts"],"sourcesContent":["export const VERSION = '0.1.0-alpha.7';\n"],"names":["VERSION"],"mappings":"AAAA,OAAO,MAAMA,UAAU,gBAAgB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdmodel",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.7",
|
|
4
4
|
"description": "MD Type language, parser, validator, structured change application, Markdown syntax profile, and conformance fixtures",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"url": "https://github.com/agentshouse/mdmodel/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"
|
|
39
|
-
"ajv-formats": "3.0.1"
|
|
38
|
+
"@cfworker/json-schema": "4.1.1"
|
|
40
39
|
}
|
|
41
40
|
}
|