@pdtf/schemas 3.6.0-1 → 3.6.0-11

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.
@@ -2,9 +2,24 @@ const { dereference } = require("@jdw/jst");
2
2
  const traverse = require("traverse");
3
3
  const jp = require("jsonpointer");
4
4
  const fs = require("fs");
5
+ const path = require("path");
5
6
  const merge = require("deepmerge");
6
7
 
7
- const combinedSchema = require("../schemas/v3/combined.json");
8
+ const combinedPath =
9
+ process.env.COMBINED_PATH ||
10
+ path.resolve(__dirname, "../schemas/v3/combined.json");
11
+ const outputDir =
12
+ process.env.OUTPUT_DIR ||
13
+ path.resolve(__dirname, "../schemas/v3");
14
+
15
+ if (!fs.existsSync(combinedPath)) {
16
+ throw new Error(`Combined schema not found: ${combinedPath}`);
17
+ }
18
+ if (!fs.existsSync(outputDir)) {
19
+ fs.mkdirSync(outputDir, { recursive: true });
20
+ }
21
+
22
+ const combinedSchema = JSON.parse(fs.readFileSync(combinedPath, "utf8"));
8
23
 
9
24
  const extractFields = [
10
25
  "baspi4",
@@ -14,7 +29,9 @@ const extractFields = [
14
29
  "ntsl",
15
30
  "ntsl2",
16
31
  "ta6",
32
+ "ta6ed6",
17
33
  "ta7",
34
+ "ta7ed5",
18
35
  "ta10",
19
36
  "lpe1",
20
37
  "fme1",
@@ -97,6 +114,23 @@ const flattenSkeleton = (schema) => {
97
114
 
98
115
  const extractOverlay = (sourceSchema, ref) => {
99
116
  const refName = `${ref}Ref`;
117
+ const extendedTagMap = {
118
+ Type: "type",
119
+ MinLength: "minLength",
120
+ MaxLength: "maxLength",
121
+ Pattern: "pattern",
122
+ Minimum: "minimum",
123
+ Maximum: "maximum",
124
+ MinItems: "minItems",
125
+ MaxItems: "maxItems",
126
+ UniqueItems: "uniqueItems",
127
+ AdditionalProperties: "additionalProperties",
128
+ Format: "format",
129
+ MinProperties: "minProperties",
130
+ MaxProperties: "maxProperties",
131
+ MultipleOf: "multipleOf",
132
+ Const: "const",
133
+ };
100
134
  const returnSchema = {
101
135
  $schema: "http://json-schema.org/draft-07/schema#",
102
136
  $id: `https://trust.propdata.org.uk/schemas/v3/overlays/${ref}.json`,
@@ -107,7 +141,7 @@ const extractOverlay = (sourceSchema, ref) => {
107
141
  if (element[refName]) {
108
142
  jp.set(returnSchema, `${path}/${refName}`, element[refName]);
109
143
 
110
- if (element.discriminator) {
144
+ if (element.discriminator && Array.isArray(element.oneOf)) {
111
145
  jp.set(returnSchema, `${path}/discriminator`, element.discriminator);
112
146
  const { propertyName } = element.discriminator;
113
147
  element.oneOf.forEach((oneOf, index) => {
@@ -134,7 +168,7 @@ const extractOverlay = (sourceSchema, ref) => {
134
168
  }
135
169
 
136
170
  // also handle discriminator properties nested in items
137
- if (element.items?.discriminator) {
171
+ if (element.items?.discriminator && Array.isArray(element.items.oneOf)) {
138
172
  jp.set(
139
173
  returnSchema,
140
174
  `${path}/items/discriminator`,
@@ -184,6 +218,18 @@ const extractOverlay = (sourceSchema, ref) => {
184
218
  if (element[refEnum]) {
185
219
  jp.set(returnSchema, `${path}/enum`, element[refEnum]);
186
220
  }
221
+
222
+ const refConst = `${ref}Const`;
223
+ if (Object.prototype.hasOwnProperty.call(element, refConst)) {
224
+ jp.set(returnSchema, `${path}/const`, element[refConst]);
225
+ }
226
+
227
+ Object.entries(extendedTagMap).forEach(([suffix, schemaKey]) => {
228
+ const tagKey = `${ref}${suffix}`;
229
+ if (Object.prototype.hasOwnProperty.call(element, tagKey)) {
230
+ jp.set(returnSchema, `${path}/${schemaKey}`, element[tagKey]);
231
+ }
232
+ });
187
233
  });
188
234
  return returnSchema;
189
235
  };
@@ -198,11 +244,15 @@ const deleteProperties = (sourceSchema, propertyNames) => {
198
244
  };
199
245
 
200
246
  const overlays = {};
247
+ const overlaysDir = path.join(outputDir, "overlays");
248
+ if (!fs.existsSync(overlaysDir)) {
249
+ fs.mkdirSync(overlaysDir, { recursive: true });
250
+ }
201
251
 
202
252
  extractFields.forEach((key) => {
203
253
  let overlay = extractOverlay(combinedSchema, key);
204
254
  overlays[key] = overlay;
205
- const fileName = `../schemas/v3/overlays/${key}.json`;
255
+ const fileName = path.join(overlaysDir, `${key}.json`);
206
256
  fs.writeFileSync(fileName, JSON.stringify(overlay, null, 2));
207
257
  console.log(`Overlay ${key} written to ${fileName}`);
208
258
  });
@@ -212,14 +262,30 @@ const coreSchema = deleteProperties(combinedSchema, [
212
262
  ...extractFields.map((item) => `${item}Ref`),
213
263
  ...extractFields.map((item) => `${item}Required`),
214
264
  ...extractFields.map((item) => `${item}Title`),
265
+ ...extractFields.map((item) => `${item}Description`),
215
266
  ...extractFields.map((item) => `${item}Enum`),
267
+ ...extractFields.map((item) => `${item}Type`),
268
+ ...extractFields.map((item) => `${item}MinLength`),
269
+ ...extractFields.map((item) => `${item}MaxLength`),
270
+ ...extractFields.map((item) => `${item}Pattern`),
271
+ ...extractFields.map((item) => `${item}Minimum`),
272
+ ...extractFields.map((item) => `${item}Maximum`),
273
+ ...extractFields.map((item) => `${item}MinItems`),
274
+ ...extractFields.map((item) => `${item}MaxItems`),
275
+ ...extractFields.map((item) => `${item}UniqueItems`),
276
+ ...extractFields.map((item) => `${item}AdditionalProperties`),
277
+ ...extractFields.map((item) => `${item}Format`),
278
+ ...extractFields.map((item) => `${item}MinProperties`),
279
+ ...extractFields.map((item) => `${item}MaxProperties`),
280
+ ...extractFields.map((item) => `${item}MultipleOf`),
281
+ ...extractFields.map((item) => `${item}Const`),
216
282
  ]);
217
283
 
218
284
  fs.writeFileSync(
219
- "../schemas/v3/pdtf-transaction.json",
285
+ path.join(outputDir, "pdtf-transaction.json"),
220
286
  JSON.stringify(coreSchema, null, 2)
221
287
  );
222
- console.log("Core schema written to ../schemas/v3/pdtf-transaction.json");
288
+ console.log(`Core schema written to ${path.join(outputDir, "pdtf-transaction.json")}`);
223
289
 
224
290
  const skeletonSchema = deleteProperties(coreSchema, [
225
291
  "$schema",
@@ -238,10 +304,10 @@ const skeletonSchema = deleteProperties(coreSchema, [
238
304
  const skeletonSchemaFlattened = flattenSkeleton(skeletonSchema);
239
305
 
240
306
  fs.writeFileSync(
241
- "../schemas/v3/skeleton.json",
307
+ path.join(outputDir, "skeleton.json"),
242
308
  JSON.stringify(skeletonSchemaFlattened, null, 2)
243
309
  );
244
- console.log("Flat Skeleton schema written to ../schemas/v3/skeleton.json");
310
+ console.log(`Flat Skeleton schema written to ${path.join(outputDir, "skeleton.json")}`);
245
311
 
246
312
  // Generate compact skeleton format for better token efficiency
247
313
  const toCompact = (obj, indent = "") => {
@@ -308,7 +374,7 @@ const innerContent = toCompact(skeletonSchemaFlattened, "");
308
374
  const compactSkeleton = innerContent ? innerContent : "";
309
375
 
310
376
  fs.writeFileSync(
311
- "../schemas/v3/compactSkeleton.txt",
377
+ path.join(outputDir, "compactSkeleton.txt"),
312
378
  compactSkeleton
313
379
  );
314
- console.log("Compact Skeleton written to ../schemas/v3/compactSkeleton.txt");
380
+ console.log(`Compact Skeleton written to ${path.join(outputDir, "compactSkeleton.txt")}`);
@@ -6,7 +6,7 @@ const combinedSchema = require("../schemas/v3/combined.json");
6
6
  // Extract fields that have overlay-specific properties
7
7
  const extractFields = [
8
8
  "baspi4", "baspi5", "nts", "nts2", "ntsl", "ntsl2",
9
- "ta6", "ta7", "ta10", "lpe1", "fme1", "piq",
9
+ "ta6", "ta7", "ta7ed5", "ta10", "lpe1", "fme1", "piq",
10
10
  "con29R", "con29DW", "llc1", "rds", "oc1", "sr24",
11
11
  ];
12
12