@twin.org/tools-core 0.0.3-next.14 → 0.0.3-next.15

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/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # TWIN Tools Core
2
2
 
3
- Shared components for the tools.
3
+ This package provides shared utilities and models for tooling packages. It centralises common behaviours so command line apps and supporting modules can build on one dependable foundation.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```shell
8
- npm install @twin.org/tools-core-models
8
+ npm install @twin.org/tools-core
9
9
  ```
10
10
 
11
11
  ## Examples
package/docs/changelog.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.15](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.3-next.14...tools-core-v0.0.3-next.15) (2026-03-10)
4
+
5
+
6
+ ### Features
7
+
8
+ * use jsdoc tags for json-ld markup ([1ea872e](https://github.com/twinfoundation/tools/commit/1ea872e07a1cc0e94178158a57383d64008e02e3))
9
+
3
10
  ## [0.0.3-next.14](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.3-next.13...tools-core-v0.0.3-next.14) (2026-03-06)
4
11
 
5
12
 
package/docs/examples.md CHANGED
@@ -1 +1,180 @@
1
- # @twin.org/tools-core - Examples
1
+ # Tools Core Examples
2
+
3
+ Use these helpers to normalise generated schemas and keep references consistent before writing documents.
4
+
5
+ ## JsonSchemaHelper
6
+
7
+ ```typescript
8
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
9
+
10
+ console.log(JsonSchemaHelper.SCHEMA_VERSION); // "https://json-schema.org/draft/2020-12/schema"
11
+ ```
12
+
13
+ ```typescript
14
+ import type { IJsonSchema } from '@twin.org/tools-core';
15
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
16
+
17
+ const schemaObject: IJsonSchema = {
18
+ type: 'array',
19
+ items: [{ type: 'string' }, { type: 'number' }],
20
+ additionalItems: { type: 'boolean' }
21
+ };
22
+
23
+ JsonSchemaHelper.processArrays(schemaObject);
24
+
25
+ console.log(schemaObject.prefixItems); // [{ type: "string" }, { type: "number" }]
26
+
27
+ console.log(schemaObject.items); // { type: "boolean" }
28
+ ```
29
+
30
+ ```typescript
31
+ import type { IJsonSchema } from '@twin.org/tools-core';
32
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
33
+
34
+ const schemaDictionary: { [key: string]: IJsonSchema } = {
35
+ id: { $ref: '#/definitions/Partial%3CIOrder%3E' },
36
+ amount: { type: 'number' }
37
+ };
38
+
39
+ JsonSchemaHelper.processSchemaDictionary(schemaDictionary);
40
+
41
+ console.log(schemaDictionary.id.$ref); // "Order"
42
+ ```
43
+
44
+ ```typescript
45
+ import type { IJsonSchema } from '@twin.org/tools-core';
46
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
47
+
48
+ const schemaArray: IJsonSchema[] = [
49
+ {
50
+ items: [{ type: 'string' }],
51
+ additionalItems: { type: 'number' }
52
+ },
53
+ {
54
+ items: [{ type: 'string' }],
55
+ additionalItems: { type: 'number' }
56
+ }
57
+ ];
58
+
59
+ JsonSchemaHelper.processSchemaArray(schemaArray);
60
+
61
+ console.log(schemaArray[0].prefixItems); // [{ type: "string" }]
62
+ ```
63
+
64
+ ```typescript
65
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
66
+
67
+ console.log(JsonSchemaHelper.normaliseTypeName('#/definitions/Pick%3CIOrder%2C%22id%22%3E')); // "#/definitions/Order"
68
+ ```
69
+
70
+ ```typescript
71
+ import type { IJsonSchema } from '@twin.org/tools-core';
72
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
73
+
74
+ const allSchemas: { [id: string]: IJsonSchema } = {
75
+ Order: {
76
+ type: 'object',
77
+ properties: {
78
+ customer: { $ref: '#/definitions/Customer' }
79
+ }
80
+ },
81
+ Customer: {
82
+ type: 'object',
83
+ properties: {
84
+ name: { type: 'string' }
85
+ }
86
+ }
87
+ };
88
+
89
+ const extracted: { [id: string]: IJsonSchema } = {};
90
+
91
+ JsonSchemaHelper.extractTypesFromSchema(allSchemas, allSchemas.Order, extracted);
92
+
93
+ console.log(Object.keys(extracted)); // ["Customer"]
94
+ ```
95
+
96
+ ```typescript
97
+ import type { IJsonSchema } from '@twin.org/tools-core';
98
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
99
+
100
+ const allSchemas: { [id: string]: IJsonSchema } = {
101
+ Order: {
102
+ type: 'object',
103
+ properties: {
104
+ customer: { $ref: '#/definitions/Customer' }
105
+ }
106
+ },
107
+ Customer: {
108
+ type: 'object',
109
+ properties: {
110
+ name: { type: 'string' }
111
+ }
112
+ }
113
+ };
114
+
115
+ const referencedSchemas: { [id: string]: IJsonSchema } = {};
116
+
117
+ JsonSchemaHelper.extractTypes(allSchemas, ['Order'], referencedSchemas);
118
+
119
+ console.log(Object.keys(referencedSchemas)); // ["Order", "Customer"]
120
+ ```
121
+
122
+ ```typescript
123
+ import type { IJsonSchema } from '@twin.org/tools-core';
124
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
125
+
126
+ const schemas: { [id: string]: IJsonSchema } = {
127
+ Order: {
128
+ type: 'object',
129
+ properties: {
130
+ customer: { $ref: '#/definitions/Customer' }
131
+ }
132
+ },
133
+ Customer: {
134
+ type: 'object',
135
+ properties: {
136
+ name: { type: 'string' }
137
+ }
138
+ }
139
+ };
140
+
141
+ JsonSchemaHelper.expandTypes(schemas, ['Customer']);
142
+
143
+ console.log(schemas.Order.properties?.customer); // { type: "object", properties: { name: { type: "string" } } }
144
+ ```
145
+
146
+ ```typescript
147
+ import type { IJsonSchema } from '@twin.org/tools-core';
148
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
149
+
150
+ const schemas: { [id: string]: IJsonSchema } = {
151
+ Customer: {
152
+ type: 'object',
153
+ properties: {
154
+ name: { type: 'string' }
155
+ }
156
+ }
157
+ };
158
+
159
+ const customerRef: IJsonSchema = { $ref: '#/definitions/Customer' };
160
+
161
+ JsonSchemaHelper.expandSchemaTypes(schemas, customerRef, ['Customer']);
162
+
163
+ console.log(customerRef); // { type: "object", properties: { name: { type: "string" } } }
164
+ ```
165
+
166
+ ```typescript
167
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
168
+
169
+ const regex = JsonSchemaHelper.stringToRegEx('/Order.*/');
170
+
171
+ console.log(regex.test('OrderCreated')); // true
172
+ ```
173
+
174
+ ## OpenApiHelper
175
+
176
+ ```typescript
177
+ import { OpenApiHelper } from '@twin.org/tools-core';
178
+
179
+ console.log(OpenApiHelper.API_VERSION); // "3.1.1"
180
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@twin.org/tools-core",
3
- "version": "0.0.3-next.14",
4
- "description": "Shared components for the tools",
3
+ "version": "0.0.3-next.15",
4
+ "description": "Shared utilities and models for tooling packages",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/twinfoundation/tools.git",