@twin.org/data-core 0.0.1-next.3 → 0.0.1-next.30
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/cjs/index.cjs +4 -0
- package/dist/esm/index.mjs +4 -0
- package/docs/changelog.md +15 -1
- package/docs/reference/classes/DataTypeHelper.md +19 -9
- package/docs/reference/classes/JsonSchemaHelper.md +27 -13
- package/docs/reference/interfaces/IDataTypeHandler.md +13 -5
- package/docs/reference/interfaces/IIdentifierHandler.md +9 -3
- package/docs/reference/type-aliases/ISchemaValidationError.md +1 -1
- package/docs/reference/type-aliases/ValidationMode.md +1 -1
- package/package.json +3 -29
package/dist/cjs/index.cjs
CHANGED
|
@@ -77,6 +77,10 @@ class JsonSchemaHelper {
|
|
|
77
77
|
static async validate(schema, data, additionalTypes) {
|
|
78
78
|
const ajv = new Ajv({
|
|
79
79
|
allowUnionTypes: true,
|
|
80
|
+
// Disable strict tuples as it causes issues with the schema validation when
|
|
81
|
+
// you have an array with fixed elements e.g. myType: [string, ...string[]]
|
|
82
|
+
// https://github.com/ajv-validator/ajv/issues/1417
|
|
83
|
+
strictTuples: false,
|
|
80
84
|
loadSchema: async (uri) => {
|
|
81
85
|
const subTypeHandler = DataTypeHandlerFactory.getIfExists(uri);
|
|
82
86
|
if (core.Is.function(subTypeHandler?.jsonSchema)) {
|
package/dist/esm/index.mjs
CHANGED
|
@@ -75,6 +75,10 @@ class JsonSchemaHelper {
|
|
|
75
75
|
static async validate(schema, data, additionalTypes) {
|
|
76
76
|
const ajv = new Ajv({
|
|
77
77
|
allowUnionTypes: true,
|
|
78
|
+
// Disable strict tuples as it causes issues with the schema validation when
|
|
79
|
+
// you have an array with fixed elements e.g. myType: [string, ...string[]]
|
|
80
|
+
// https://github.com/ajv-validator/ajv/issues/1417
|
|
81
|
+
strictTuples: false,
|
|
78
82
|
loadSchema: async (uri) => {
|
|
79
83
|
const subTypeHandler = DataTypeHandlerFactory.getIfExists(uri);
|
|
80
84
|
if (Is.function(subTypeHandler?.jsonSchema)) {
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @twin.org/data-core - Changelog
|
|
2
2
|
|
|
3
|
-
## v0.0.1-next.
|
|
3
|
+
## [0.0.1-next.30](https://github.com/twinfoundation/data/compare/data-core-v0.0.1-next.29...data-core-v0.0.1-next.30) (2025-04-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* use shared store mechanism ([#3](https://github.com/twinfoundation/data/issues/3)) ([33eb221](https://github.com/twinfoundation/data/commit/33eb221ccec2b4a79549c06e9a04225009b93a46))
|
|
9
|
+
|
|
10
|
+
## [0.0.1-next.29](https://github.com/twinfoundation/data/compare/data-core-v0.0.1-next.28...data-core-v0.0.1-next.29) (2025-03-28)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add document cache access methods ([dbf1e36](https://github.com/twinfoundation/data/commit/dbf1e36d176c5f428f8c52628fb5a1ff7a6a174a))
|
|
16
|
+
|
|
17
|
+
## v0.0.1-next.28
|
|
4
18
|
|
|
5
19
|
- Initial Release
|
|
@@ -4,41 +4,51 @@ Class to help with data types.
|
|
|
4
4
|
|
|
5
5
|
## Constructors
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### Constructor
|
|
8
8
|
|
|
9
|
-
> **new DataTypeHelper**():
|
|
9
|
+
> **new DataTypeHelper**(): `DataTypeHelper`
|
|
10
10
|
|
|
11
11
|
#### Returns
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
`DataTypeHelper`
|
|
14
14
|
|
|
15
15
|
## Methods
|
|
16
16
|
|
|
17
17
|
### validate()
|
|
18
18
|
|
|
19
|
-
> `static` **validate**(`propertyName`, `dataType`, `data`, `validationFailures`, `validationMode
|
|
19
|
+
> `static` **validate**(`propertyName`, `dataType`, `data`, `validationFailures`, `validationMode?`): `Promise`\<`boolean`\>
|
|
20
20
|
|
|
21
21
|
Validate a data type.
|
|
22
22
|
|
|
23
23
|
#### Parameters
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
##### propertyName
|
|
26
|
+
|
|
27
|
+
`string`
|
|
26
28
|
|
|
27
29
|
The name of the property being validated to use in error messages.
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
##### dataType
|
|
30
32
|
|
|
31
33
|
The data type to validate.
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
`undefined` | `string`
|
|
36
|
+
|
|
37
|
+
##### data
|
|
38
|
+
|
|
39
|
+
`unknown`
|
|
34
40
|
|
|
35
41
|
The data to validate.
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
##### validationFailures
|
|
44
|
+
|
|
45
|
+
`IValidationFailure`[]
|
|
38
46
|
|
|
39
47
|
The list of validation failures to add to.
|
|
40
48
|
|
|
41
|
-
|
|
49
|
+
##### validationMode?
|
|
50
|
+
|
|
51
|
+
[`ValidationMode`](../type-aliases/ValidationMode.md)
|
|
42
52
|
|
|
43
53
|
The validation mode to use, defaults to either.
|
|
44
54
|
|
|
@@ -4,13 +4,13 @@ A helper for JSON schemas.
|
|
|
4
4
|
|
|
5
5
|
## Constructors
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### Constructor
|
|
8
8
|
|
|
9
|
-
> **new JsonSchemaHelper**():
|
|
9
|
+
> **new JsonSchemaHelper**(): `JsonSchemaHelper`
|
|
10
10
|
|
|
11
11
|
#### Returns
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
`JsonSchemaHelper`
|
|
14
14
|
|
|
15
15
|
## Properties
|
|
16
16
|
|
|
@@ -24,25 +24,31 @@ The schema version.
|
|
|
24
24
|
|
|
25
25
|
### validate()
|
|
26
26
|
|
|
27
|
-
> `static` **validate**\<`T`\>(`schema`, `data`, `additionalTypes
|
|
27
|
+
> `static` **validate**\<`T`\>(`schema`, `data`, `additionalTypes?`): `Promise`\<[`ISchemaValidationResult`](../interfaces/ISchemaValidationResult.md)\>
|
|
28
28
|
|
|
29
29
|
Validates data against the schema.
|
|
30
30
|
|
|
31
31
|
#### Type Parameters
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
##### T
|
|
34
|
+
|
|
35
|
+
`T` = `unknown`
|
|
34
36
|
|
|
35
37
|
#### Parameters
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
##### schema
|
|
40
|
+
|
|
41
|
+
`JSONSchema7`
|
|
38
42
|
|
|
39
43
|
The schema to validate the data with.
|
|
40
44
|
|
|
41
|
-
|
|
45
|
+
##### data
|
|
46
|
+
|
|
47
|
+
`T`
|
|
42
48
|
|
|
43
49
|
The data to be validated.
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
##### additionalTypes?
|
|
46
52
|
|
|
47
53
|
Additional types to add for reference, not already in DataTypeHandlerFactory.
|
|
48
54
|
|
|
@@ -62,11 +68,15 @@ Get the property type from a schema.
|
|
|
62
68
|
|
|
63
69
|
#### Parameters
|
|
64
70
|
|
|
65
|
-
|
|
71
|
+
##### schema
|
|
72
|
+
|
|
73
|
+
`JSONSchema7`
|
|
66
74
|
|
|
67
75
|
The schema to extract the types from.
|
|
68
76
|
|
|
69
|
-
|
|
77
|
+
##### propertyName
|
|
78
|
+
|
|
79
|
+
`string`
|
|
70
80
|
|
|
71
81
|
The name of the property to get the type for.
|
|
72
82
|
|
|
@@ -80,17 +90,21 @@ The types of the property.
|
|
|
80
90
|
|
|
81
91
|
### entitySchemaToJsonSchema()
|
|
82
92
|
|
|
83
|
-
> `static` **entitySchemaToJsonSchema**(`entitySchema`, `baseDomain
|
|
93
|
+
> `static` **entitySchemaToJsonSchema**(`entitySchema`, `baseDomain?`): `JSONSchema7`
|
|
84
94
|
|
|
85
95
|
Convert an entity schema to JSON schema e.g https://example.com/schemas/.
|
|
86
96
|
|
|
87
97
|
#### Parameters
|
|
88
98
|
|
|
89
|
-
|
|
99
|
+
##### entitySchema
|
|
90
100
|
|
|
91
101
|
The entity schema to convert.
|
|
92
102
|
|
|
93
|
-
|
|
103
|
+
`undefined` | `IEntitySchema`\<`unknown`\>
|
|
104
|
+
|
|
105
|
+
##### baseDomain?
|
|
106
|
+
|
|
107
|
+
`string`
|
|
94
108
|
|
|
95
109
|
The base domain for local schemas e.g. https://example.com/
|
|
96
110
|
|
|
@@ -36,25 +36,33 @@ The JSON schema for the data type.
|
|
|
36
36
|
|
|
37
37
|
### validate()?
|
|
38
38
|
|
|
39
|
-
> `optional` **validate**(`propertyName`, `value`, `failures`, `container
|
|
39
|
+
> `optional` **validate**(`propertyName`, `value`, `failures`, `container?`): `Promise`\<`boolean`\>
|
|
40
40
|
|
|
41
41
|
A method for validating the data type.
|
|
42
42
|
|
|
43
43
|
#### Parameters
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
##### propertyName
|
|
46
|
+
|
|
47
|
+
`string`
|
|
46
48
|
|
|
47
49
|
The name of the property being validated.
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
##### value
|
|
52
|
+
|
|
53
|
+
`unknown`
|
|
50
54
|
|
|
51
55
|
The value to validate.
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
##### failures
|
|
58
|
+
|
|
59
|
+
`IValidationFailure`[]
|
|
54
60
|
|
|
55
61
|
List of failures to add to.
|
|
56
62
|
|
|
57
|
-
|
|
63
|
+
##### container?
|
|
64
|
+
|
|
65
|
+
`unknown`
|
|
58
66
|
|
|
59
67
|
The object which contains this one.
|
|
60
68
|
|
|
@@ -20,15 +20,21 @@ A method for validating the identifier.
|
|
|
20
20
|
|
|
21
21
|
#### Parameters
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
##### propertyName
|
|
24
|
+
|
|
25
|
+
`string`
|
|
24
26
|
|
|
25
27
|
The name of the property being validated.
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
##### value
|
|
30
|
+
|
|
31
|
+
`unknown`
|
|
28
32
|
|
|
29
33
|
The value to validate.
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
##### failures
|
|
36
|
+
|
|
37
|
+
`IValidationFailure`[]
|
|
32
38
|
|
|
33
39
|
List of failures to add to.
|
|
34
40
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Type Alias: ValidationMode
|
|
2
2
|
|
|
3
|
-
> **ValidationMode
|
|
3
|
+
> **ValidationMode** = *typeof* [`ValidationMode`](../variables/ValidationMode.md)\[keyof *typeof* [`ValidationMode`](../variables/ValidationMode.md)\]
|
|
4
4
|
|
|
5
5
|
Validation modes for validating data types.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/data-core",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.30",
|
|
4
4
|
"description": "Definitions and helpers for using with data and schemas",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,19 +13,6 @@
|
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"clean": "rimraf dist coverage",
|
|
18
|
-
"build": "tspc",
|
|
19
|
-
"test": "vitest --run --config ./vitest.config.ts --no-cache",
|
|
20
|
-
"coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
|
|
21
|
-
"bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
|
|
22
|
-
"bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
|
|
23
|
-
"bundle": "npm run bundle:esm && npm run bundle:cjs",
|
|
24
|
-
"docs:clean": "rimraf docs/reference",
|
|
25
|
-
"docs:generate": "typedoc",
|
|
26
|
-
"docs": "npm run docs:clean && npm run docs:generate",
|
|
27
|
-
"dist": "npm run clean && npm run build && npm run test && npm run bundle && npm run docs"
|
|
28
|
-
},
|
|
29
16
|
"dependencies": {
|
|
30
17
|
"@twin.org/core": "next",
|
|
31
18
|
"@twin.org/entity": "next",
|
|
@@ -35,27 +22,14 @@
|
|
|
35
22
|
"ajv": "8.17.1",
|
|
36
23
|
"ajv-formats": "3.0.1"
|
|
37
24
|
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@twin.org/nameof-transformer": "next",
|
|
40
|
-
"@vitest/coverage-v8": "2.1.1",
|
|
41
|
-
"copyfiles": "2.4.1",
|
|
42
|
-
"rimraf": "6.0.1",
|
|
43
|
-
"rollup": "4.22.0",
|
|
44
|
-
"rollup-plugin-typescript2": "0.36.0",
|
|
45
|
-
"ts-patch": "3.2.1",
|
|
46
|
-
"typedoc": "0.26.7",
|
|
47
|
-
"typedoc-plugin-markdown": "4.2.7",
|
|
48
|
-
"typescript": "5.6.2",
|
|
49
|
-
"vitest": "2.1.1"
|
|
50
|
-
},
|
|
51
25
|
"main": "./dist/cjs/index.cjs",
|
|
52
26
|
"module": "./dist/esm/index.mjs",
|
|
53
27
|
"types": "./dist/types/index.d.ts",
|
|
54
28
|
"exports": {
|
|
55
29
|
".": {
|
|
30
|
+
"types": "./dist/types/index.d.ts",
|
|
56
31
|
"require": "./dist/cjs/index.cjs",
|
|
57
|
-
"import": "./dist/esm/index.mjs"
|
|
58
|
-
"types": "./dist/types/index.d.ts"
|
|
32
|
+
"import": "./dist/esm/index.mjs"
|
|
59
33
|
}
|
|
60
34
|
},
|
|
61
35
|
"files": [
|