schema-markdown 1.2.8 → 1.2.10
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/lib/parser.js +7 -3
- package/lib/schema.js +8 -5
- package/lib/schemaUtil.js +3 -3
- package/lib/typeModel.js +2 -2
- package/package.json +3 -3
package/lib/parser.js
CHANGED
|
@@ -7,7 +7,8 @@ import {validateTypeModelErrors} from './schemaUtil.js';
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
// Built-in types
|
|
10
|
-
const builtinTypes = new Set(['bool', 'date', 'datetime', 'float', 'int', '
|
|
10
|
+
const builtinTypes = new Set(['any', 'bool', 'date', 'datetime', 'float', 'int', 'string', 'uuid']);
|
|
11
|
+
const builtinDeprecated = {'object': 'any'};
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
// Schema Markdown regex
|
|
@@ -213,7 +214,7 @@ export function parseSchemaMarkdown(text, {types = {}, filename = '', validate =
|
|
|
213
214
|
const definitionBaseIds = match.groups.baseIds;
|
|
214
215
|
|
|
215
216
|
// Type already defined?
|
|
216
|
-
if (builtinTypes.has(definitionId) || definitionId in types) {
|
|
217
|
+
if (builtinTypes.has(definitionId) || definitionId in builtinDeprecated || definitionId in types) {
|
|
217
218
|
addError(`Redefinition of type '${definitionId}'`, filename, linenum);
|
|
218
219
|
}
|
|
219
220
|
|
|
@@ -391,7 +392,7 @@ export function parseSchemaMarkdown(text, {types = {}, filename = '', validate =
|
|
|
391
392
|
const definitionId = match.groups.id;
|
|
392
393
|
|
|
393
394
|
// Type already defined?
|
|
394
|
-
if (builtinTypes.has(definitionId) || definitionId in types) {
|
|
395
|
+
if (builtinTypes.has(definitionId) || definitionId in builtinDeprecated || definitionId in types) {
|
|
395
396
|
addError(`Redefinition of type '${definitionId}'`, filename, linenum);
|
|
396
397
|
}
|
|
397
398
|
|
|
@@ -514,6 +515,9 @@ function parseTypedef(matchTypedef) {
|
|
|
514
515
|
|
|
515
516
|
// Helper function to create a type model
|
|
516
517
|
function createType(typeName) {
|
|
518
|
+
if (typeName in builtinDeprecated) {
|
|
519
|
+
return {'builtin': builtinDeprecated[typeName]};
|
|
520
|
+
}
|
|
517
521
|
if (builtinTypes.has(typeName)) {
|
|
518
522
|
return {'builtin': typeName};
|
|
519
523
|
}
|
package/lib/schema.js
CHANGED
|
@@ -136,7 +136,7 @@ export function validateType(types, typeName, value, memberFqn = null) {
|
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
// Regular expressions used by validateTypeHelper
|
|
139
|
-
const rDate =
|
|
139
|
+
const rDate = /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/;
|
|
140
140
|
const rDatetime = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
141
141
|
|
|
142
142
|
|
|
@@ -200,9 +200,12 @@ function validateTypeHelper(types, type, value, memberFqn) {
|
|
|
200
200
|
// Convert string?
|
|
201
201
|
if (typeof value === 'string') {
|
|
202
202
|
// Valid date format?
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
const mDate = value.match(rDate);
|
|
204
|
+
if (mDate !== null) {
|
|
205
|
+
const year = Number.parseInt(mDate.groups.year, 10);
|
|
206
|
+
const month = Number.parseInt(mDate.groups.month, 10);
|
|
207
|
+
const day = Number.parseInt(mDate.groups.day, 10);
|
|
208
|
+
valueNew = new Date(year, month - 1, day);
|
|
206
209
|
} else if (rDatetime.test(value)) {
|
|
207
210
|
valueNew = new Date(value);
|
|
208
211
|
} else {
|
|
@@ -216,7 +219,7 @@ function validateTypeHelper(types, type, value, memberFqn) {
|
|
|
216
219
|
|
|
217
220
|
// For date type, clear hours, minutes, seconds, and milliseconds
|
|
218
221
|
if (builtin === 'date') {
|
|
219
|
-
valueNew = new Date(valueNew.getFullYear(), valueNew.getMonth(), valueNew.
|
|
222
|
+
valueNew = new Date(valueNew.getFullYear(), valueNew.getMonth(), valueNew.getDate());
|
|
220
223
|
}
|
|
221
224
|
}
|
|
222
225
|
|
package/lib/schemaUtil.js
CHANGED
|
@@ -57,7 +57,7 @@ export function validateTypeModelErrors(types) {
|
|
|
57
57
|
// Check member type and attributes
|
|
58
58
|
validateTypeModelType(errors, types, member.type, 'attr' in member ? member.attr : null, struct.name, member.name);
|
|
59
59
|
}
|
|
60
|
-
} catch
|
|
60
|
+
} catch {
|
|
61
61
|
errors.push([typeName, null, `Circular base type detected for type '${typeName}'`]);
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -93,7 +93,7 @@ export function validateTypeModelErrors(types) {
|
|
|
93
93
|
errors.push([typeName, valueName, `Redefinition of '${typeName}' value '${valueName}'`]);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
} catch
|
|
96
|
+
} catch {
|
|
97
97
|
errors.push([typeName, null, `Circular base type detected for type '${typeName}'`]);
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -147,7 +147,7 @@ export function validateTypeModelErrors(types) {
|
|
|
147
147
|
}
|
|
148
148
|
memberSections[memberName].push(sectionStruct.name);
|
|
149
149
|
}
|
|
150
|
-
} catch
|
|
150
|
+
} catch {
|
|
151
151
|
// Do nothing
|
|
152
152
|
}
|
|
153
153
|
}
|
package/lib/typeModel.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "schema-markdown",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.10",
|
|
5
5
|
"description": "A schema definition and validation library",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"schema",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"test": "node --test test/"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"c8": "~
|
|
28
|
-
"eslint": "~
|
|
27
|
+
"c8": "~10.1",
|
|
28
|
+
"eslint": "~9.14",
|
|
29
29
|
"jsdoc": "~4.0"
|
|
30
30
|
}
|
|
31
31
|
}
|