@planning-inspectorate/data-model 1.11.0
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/.azure/ci.yml +60 -0
- package/.azure/release.yml +57 -0
- package/.github/dependabot.yml +11 -0
- package/.husky/install.mjs +7 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +11 -0
- package/.prettierrc +19 -0
- package/LICENSE +21 -0
- package/README.md +237 -0
- package/commitlint.config.js +8 -0
- package/docs/README.md +85 -0
- package/docs/appeal-document.md +776 -0
- package/docs/appeal-event-estimate.md +108 -0
- package/docs/appeal-event.md +404 -0
- package/docs/appeal-has.md +1960 -0
- package/docs/appeal-representation.md +375 -0
- package/docs/appeal-s78.md +3607 -0
- package/docs/appeal.md +1879 -0
- package/docs/case-schedule.md +8 -0
- package/docs/dart-response.md +1413 -0
- package/docs/employee.md +70 -0
- package/docs/entraid.md +108 -0
- package/docs/folder.md +147 -0
- package/docs/gettimesheets-response.md +188 -0
- package/docs/interested-party.md +284 -0
- package/docs/listed-building.md +113 -0
- package/docs/listed-buildings.md +113 -0
- package/docs/nsip-document.md +966 -0
- package/docs/nsip-exam-timetable-defs-event.md +223 -0
- package/docs/nsip-exam-timetable-defs-line-item.md +51 -0
- package/docs/nsip-exam-timetable-defs.md +3 -0
- package/docs/nsip-exam-timetable-submission.md +113 -0
- package/docs/nsip-exam-timetable.md +352 -0
- package/docs/nsip-project-update.md +163 -0
- package/docs/nsip-project.md +2098 -0
- package/docs/nsip-representation-defs-attachment.md +133 -0
- package/docs/nsip-representation-defs.md +3 -0
- package/docs/nsip-representation.md +448 -0
- package/docs/nsip-subscription.md +193 -0
- package/docs/pins-inspector.md +184 -0
- package/docs/pins-lpa.md +260 -0
- package/docs/s51-advice.md +460 -0
- package/docs/service-user.md +575 -0
- package/eslint.config.js +21 -0
- package/jsconfig.json +12 -0
- package/package.json +55 -0
- package/pins_data_model/__init__.py +0 -0
- package/pins_data_model/gen_models.py +51 -0
- package/pins_data_model/load_schemas.py +51 -0
- package/pins_data_model/models/__init__.py +0 -0
- package/pins_data_model/models/model_appeal_document.py +294 -0
- package/pins_data_model/models/model_appeal_event.py +117 -0
- package/pins_data_model/models/model_appeal_event_estimate.py +37 -0
- package/pins_data_model/models/model_appeal_has.py +585 -0
- package/pins_data_model/models/model_appeal_representation.py +132 -0
- package/pins_data_model/models/model_appeal_s78.py +864 -0
- package/pins_data_model/models/model_case_schedule.py +11 -0
- package/pins_data_model/models/model_dart_response.py +292 -0
- package/pins_data_model/models/model_entraid.py +37 -0
- package/pins_data_model/models/model_folder.py +56 -0
- package/pins_data_model/models/model_gettimesheets_response.py +45 -0
- package/pins_data_model/models/model_listed_building.py +33 -0
- package/pins_data_model/models/model_listed_buildings.py +33 -0
- package/pins_data_model/models/model_nsip_document.py +199 -0
- package/pins_data_model/models/model_nsip_exam_timetable.py +90 -0
- package/pins_data_model/models/model_nsip_project.py +488 -0
- package/pins_data_model/models/model_nsip_project_update.py +60 -0
- package/pins_data_model/models/model_nsip_representation.py +83 -0
- package/pins_data_model/models/model_nsip_subscription.py +60 -0
- package/pins_data_model/models/model_pins_inspector.py +53 -0
- package/pins_data_model/models/model_pins_lpa.py +69 -0
- package/pins_data_model/models/model_s51_advice.py +109 -0
- package/pins_data_model/models/model_service_user.py +121 -0
- package/requirements.txt +2 -0
- package/schemas/__init__.py +0 -0
- package/schemas/appeal-document.schema.json +250 -0
- package/schemas/appeal-event-estimate.schema.json +31 -0
- package/schemas/appeal-event.schema.json +123 -0
- package/schemas/appeal-has.schema.json +576 -0
- package/schemas/appeal-representation.schema.json +131 -0
- package/schemas/appeal-s78.schema.json +1060 -0
- package/schemas/commands/__init__.py +0 -0
- package/schemas/commands/appeal-common-submission.schema.json +202 -0
- package/schemas/commands/appeal-has-submission.schema.json +82 -0
- package/schemas/commands/appeal-representation-submission.schema.json +192 -0
- package/schemas/commands/appeal-s78-submission.schema.json +100 -0
- package/schemas/commands/appellant-submission.schema.json +164 -0
- package/schemas/commands/interested-party.schema.json +80 -0
- package/schemas/commands/lpa-questionnaire-common.schema.json +110 -0
- package/schemas/commands/lpa-questionnaire-has.schema.json +69 -0
- package/schemas/commands/lpa-questionnaire-s78.schema.json +218 -0
- package/schemas/commands/lpa-questionnaire.schema.json +125 -0
- package/schemas/commands/new-deadline-submission.schema.json +59 -0
- package/schemas/commands/nsip-exam-timetable-submission.schema.json +27 -0
- package/schemas/commands/register-nsip-subscription.schema.json +32 -0
- package/schemas/commands/register-representation.schema.json +51 -0
- package/schemas/dart-response.schema.json +350 -0
- package/schemas/entraid.schema.json +31 -0
- package/schemas/folder.schema.json +49 -0
- package/schemas/gettimesheets-response.schema.json +46 -0
- package/schemas/listed-building.schema.json +31 -0
- package/schemas/listed-buildings.schema.json +31 -0
- package/schemas/nsip-document.schema.json +235 -0
- package/schemas/nsip-exam-timetable.schema.json +101 -0
- package/schemas/nsip-project-update.schema.json +49 -0
- package/schemas/nsip-project.schema.json +539 -0
- package/schemas/nsip-representation.schema.json +110 -0
- package/schemas/nsip-subscription.schema.json +52 -0
- package/schemas/pins-inspector.schema.json +47 -0
- package/schemas/pins-lpa.schema.json +63 -0
- package/schemas/s51-advice.schema.json +113 -0
- package/schemas/service-user.schema.json +152 -0
- package/setup.py +15 -0
- package/src/enums.cjs +632 -0
- package/src/enums.d.ts +573 -0
- package/src/enums.js +573 -0
- package/src/gen-docs.js +34 -0
- package/src/gen-enums.js +119 -0
- package/src/gen-types.js +70 -0
- package/src/index.cjs +746 -0
- package/src/index.d.ts +18 -0
- package/src/index.js +34 -0
- package/src/lib/load.js +78 -0
- package/src/schemas.d.ts +4570 -0
- package/tests/appeals/appeal-event.test.js +62 -0
- package/tests/appeals/commands/appeal-representation-submission.test.js +107 -0
- package/tests/appeals/commands/has-questionnaire.test.js +92 -0
- package/tests/appeals/commands/has-submission.test.js +113 -0
- package/tests/appeals/commands/s78-questionnaire.test.js +96 -0
- package/tests/appeals/commands/s78-submission.test.js +119 -0
- package/tests/schemas.test.js +97 -0
package/src/gen-enums.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import url from 'url';
|
|
4
|
+
import { loadAllSchemas } from './index.js';
|
|
5
|
+
import snakeCase from 'lodash.snakecase';
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
export const constPath = path.join(__dirname, 'enums.js');
|
|
10
|
+
export const constTsPath = path.join(__dirname, 'enums.d.ts');
|
|
11
|
+
|
|
12
|
+
const SPACING = ' ';
|
|
13
|
+
const NEW_LINE = '\r\n';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Load all schemas and generate JS constant definitions
|
|
17
|
+
*/
|
|
18
|
+
async function run() {
|
|
19
|
+
const s = await loadAllSchemas();
|
|
20
|
+
|
|
21
|
+
/** @type {Object<string, string[]>} */
|
|
22
|
+
const enumProps = {};
|
|
23
|
+
|
|
24
|
+
for (const schemaName of Object.keys(s.schemas).sort()) {
|
|
25
|
+
const schema = s.schemas[schemaName];
|
|
26
|
+
collectEnumProps(enumProps, schema.properties, schemaPrefix(schemaName));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let output = '';
|
|
30
|
+
let tsOutput = '';
|
|
31
|
+
|
|
32
|
+
for (const name of Object.keys(enumProps).sort()) {
|
|
33
|
+
output += generateConstants(name, enumProps[name]) + NEW_LINE.repeat(2);
|
|
34
|
+
tsOutput += generateConstants(name, enumProps[name], { ts: true }) + NEW_LINE.repeat(2);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await fs.writeFile(constPath, output);
|
|
38
|
+
await fs.writeFile(constTsPath, tsOutput);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Generate JS code to define exported constants for the given enum values
|
|
43
|
+
*
|
|
44
|
+
* @param {string} name
|
|
45
|
+
* @param {string[]} values
|
|
46
|
+
* @param {Object} opts
|
|
47
|
+
* @param {boolean} [opts.ts] - whether to generate the TS type or JS code
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
function generateConstants(name, values, { ts = false } = {}) {
|
|
51
|
+
const freezeStart = ts ? '' : 'Object.freeze(';
|
|
52
|
+
const freezeEnd = ts ? '' : ')';
|
|
53
|
+
const exportPrefix = 'export ';
|
|
54
|
+
const lines = [`${exportPrefix}const ${formatName(name)} = ${freezeStart}{`];
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} line
|
|
57
|
+
* @param {number} spacing
|
|
58
|
+
*/
|
|
59
|
+
const addWithSpace = (line, spacing = 0) => lines.push(SPACING.repeat(spacing) + line);
|
|
60
|
+
|
|
61
|
+
for (const value of values.sort()) {
|
|
62
|
+
addWithSpace(`${formatName(value)}: '${value}',`, 1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
lines.push(`}${freezeEnd};`);
|
|
66
|
+
|
|
67
|
+
return lines.join(NEW_LINE);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Format a name for use as a constant value: UPPER_SNAKE_CASE
|
|
72
|
+
*
|
|
73
|
+
* @param {string} name
|
|
74
|
+
* @returns {string}
|
|
75
|
+
*/
|
|
76
|
+
function formatName(name) {
|
|
77
|
+
return snakeCase(name).toUpperCase();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param {Object<string, string[]>} map
|
|
83
|
+
* @param {Object<string, {type?: string|string[], enum?: string[]}>} properties
|
|
84
|
+
* @param {string} [prefix]
|
|
85
|
+
*/
|
|
86
|
+
function collectEnumProps(map, properties = {}, prefix) {
|
|
87
|
+
for (const [key, prop] of Object.entries(properties)) {
|
|
88
|
+
const name = prefix ? prefix + '_' + key : key;
|
|
89
|
+
|
|
90
|
+
const hasStringEnum = (p) =>
|
|
91
|
+
p && p.enum && Array.isArray(p.enum) && p.type && (p.type === 'string' || p.type.includes('string'));
|
|
92
|
+
const getEnumValues = (p) => p.filter((e) => e !== null);
|
|
93
|
+
const collectEnumFromProp = (p) => {
|
|
94
|
+
if (hasStringEnum(p)) {
|
|
95
|
+
map[name] = getEnumValues(p.enum);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
collectEnumFromProp(prop);
|
|
100
|
+
collectEnumFromProp(prop.items);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Generate a prefix based on the schema name
|
|
106
|
+
*
|
|
107
|
+
* @param {string} schemaName
|
|
108
|
+
* @returns {string|undefined}
|
|
109
|
+
*/
|
|
110
|
+
function schemaPrefix(schemaName) {
|
|
111
|
+
if (schemaName.toLowerCase().includes('appeal')) {
|
|
112
|
+
return 'appeal';
|
|
113
|
+
}
|
|
114
|
+
if (schemaName.toLowerCase().includes('nsip')) {
|
|
115
|
+
return 'nsip';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
run().catch(console.error);
|
package/src/gen-types.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import url from 'url';
|
|
4
|
+
import { loadAllSchemas } from './index.js';
|
|
5
|
+
import { compile } from 'json-schema-to-typescript';
|
|
6
|
+
import { schemasPath, commandsPath } from './index.js';
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
9
|
+
|
|
10
|
+
export const typesPath = path.join(__dirname, 'schemas.d.ts');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Load all schemas and generate TypeScript definitions
|
|
14
|
+
*/
|
|
15
|
+
async function run() {
|
|
16
|
+
const s = await loadAllSchemas();
|
|
17
|
+
|
|
18
|
+
let types = '';
|
|
19
|
+
let first = true;
|
|
20
|
+
|
|
21
|
+
for (const schemaName of Object.keys(s.schemas).sort()) {
|
|
22
|
+
const schema = s.schemas[schemaName];
|
|
23
|
+
types += await compile(schema, schema['$id'], options(first));
|
|
24
|
+
types += '\n';
|
|
25
|
+
first = false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (const commandName of Object.keys(s.commands).sort()) {
|
|
29
|
+
const schema = s.commands[commandName];
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
commandName.startsWith('appeal') ||
|
|
33
|
+
commandName.startsWith('appellant') ||
|
|
34
|
+
commandName.startsWith('lpa-questionnaire')
|
|
35
|
+
) {
|
|
36
|
+
// hack to allow nested $ref links to function in tests and gen types,
|
|
37
|
+
// can we leverage a better means to resolve $refs that aligns with how tests/appeals references this
|
|
38
|
+
types += await compile(schema, schema['$id'], options(first, commandsPath));
|
|
39
|
+
} else {
|
|
40
|
+
types += await compile(schema, schema['$id'], options(first));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
types += '\n';
|
|
44
|
+
first = false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await fs.writeFile(typesPath, types);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @param {boolean} first
|
|
53
|
+
* @returns {Partial<import('json-schema-to-typescript').Options>}
|
|
54
|
+
*/
|
|
55
|
+
function options(first, refPath = schemasPath) {
|
|
56
|
+
return {
|
|
57
|
+
// don't allow additional properties if not explicit in the schema
|
|
58
|
+
additionalProperties: false,
|
|
59
|
+
// we're joining all the definitions into one, so just put the comment in once
|
|
60
|
+
bannerComment: first ? undefined : '',
|
|
61
|
+
// resolve $refs from the schemas folder
|
|
62
|
+
cwd: refPath,
|
|
63
|
+
declareExternallyReferenced: true,
|
|
64
|
+
style: {
|
|
65
|
+
singleQuote: true
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
run().catch(console.error);
|