@themeparks/typelib 1.0.3 → 1.0.4
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_types.d.ts","sourceRoot":"","sources":["../src/generate_types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate_types.d.ts","sourceRoot":"","sources":["../src/generate_types.ts"],"names":[],"mappings":"AAwXA;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,EAChC,UAAgC,EAChC,SAA8B,EAC9B,kBAA0C,EAC7C;;;;CAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CA4CrB"}
|
package/dist/generate_types.js
CHANGED
|
@@ -91,6 +91,14 @@ function getTypeFromSchema(schema, rootSchema, registry, tracker, typeName) {
|
|
|
91
91
|
// Handle enums specially - create union type of string literals
|
|
92
92
|
return schema.enum.map(value => `'${value}'`).join(' | ');
|
|
93
93
|
}
|
|
94
|
+
if (schema.oneOf || schema.anyOf) {
|
|
95
|
+
// Handle oneOf/anyOf - create union type
|
|
96
|
+
const variants = schema.oneOf || schema.anyOf;
|
|
97
|
+
if (variants && Array.isArray(variants)) {
|
|
98
|
+
const types = variants.map(variant => getTypeFromSchema(variant, rootSchema, registry, tracker));
|
|
99
|
+
return types.join(' | ');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
94
102
|
if (schema.$ref) {
|
|
95
103
|
try {
|
|
96
104
|
const resolved = resolveReference(schema.$ref, rootSchema, registry, tracker);
|
|
@@ -126,7 +134,18 @@ function getTypeFromSchema(schema, rootSchema, registry, tracker, typeName) {
|
|
|
126
134
|
}
|
|
127
135
|
case 'object': {
|
|
128
136
|
if (!schema.properties) {
|
|
129
|
-
|
|
137
|
+
// Check if propertyNames constraint exists
|
|
138
|
+
let keyType = 'string';
|
|
139
|
+
if (schema.propertyNames?.$ref) {
|
|
140
|
+
const resolved = resolveReference(schema.propertyNames.$ref, rootSchema, registry, tracker);
|
|
141
|
+
keyType = resolved.typeName;
|
|
142
|
+
}
|
|
143
|
+
// Check if additionalProperties has a type constraint
|
|
144
|
+
let valueType = 'any';
|
|
145
|
+
if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {
|
|
146
|
+
valueType = getTypeFromSchema(schema.additionalProperties, rootSchema, registry, tracker);
|
|
147
|
+
}
|
|
148
|
+
const recordType = `Record<${keyType}, ${valueType}>`;
|
|
130
149
|
if (typeName) {
|
|
131
150
|
return `extends ${recordType} {}`;
|
|
132
151
|
}
|
|
@@ -194,7 +213,12 @@ async function generateTypeFile(schemaPath, registry, outputDir, typeRegistryImp
|
|
|
194
213
|
continue;
|
|
195
214
|
}
|
|
196
215
|
}
|
|
197
|
-
if (typeSchema.
|
|
216
|
+
if (typeSchema.oneOf || typeSchema.anyOf) {
|
|
217
|
+
// Handle oneOf/anyOf - create type alias with union
|
|
218
|
+
const typeStr = getTypeFromSchema(typeSchema, schema, registry, tracker);
|
|
219
|
+
output += `${description}export type ${name} = ${typeStr};\n\n`;
|
|
220
|
+
}
|
|
221
|
+
else if (typeSchema.enum && Array.isArray(typeSchema.enum)) {
|
|
198
222
|
// generate a native enum for enum types
|
|
199
223
|
output += `export enum ${name}Enum {\n`;
|
|
200
224
|
typeSchema.enum.forEach((value) => {
|
|
@@ -211,8 +235,8 @@ async function generateTypeFile(schemaPath, registry, outputDir, typeRegistryImp
|
|
|
211
235
|
typeSchema.enum.forEach((value) => {
|
|
212
236
|
if (value) {
|
|
213
237
|
output += ` case '${value.toLowerCase()}':\n`;
|
|
214
|
-
if (value.includes(' ')) {
|
|
215
|
-
// Handle spaces in enum values
|
|
238
|
+
if (value.includes(' ') || value.includes('-')) {
|
|
239
|
+
// Handle spaces and hyphens in enum values
|
|
216
240
|
output += ` return ${name}Enum["${value}"];\n`;
|
|
217
241
|
}
|
|
218
242
|
else {
|
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
export declare enum LanguageCodeEnum {
|
|
2
|
+
"en" = "en",
|
|
3
|
+
"en-gb" = "en-gb",
|
|
4
|
+
"en-us" = "en-us",
|
|
5
|
+
"de" = "de",
|
|
6
|
+
"fr" = "fr",
|
|
7
|
+
"es" = "es",
|
|
8
|
+
"it" = "it",
|
|
9
|
+
"nl" = "nl",
|
|
10
|
+
"ja" = "ja",
|
|
11
|
+
"ko" = "ko",
|
|
12
|
+
"zh" = "zh"
|
|
13
|
+
}
|
|
14
|
+
/** Supported language codes for ThemeParks.wiki */
|
|
15
|
+
export type LanguageCode = keyof typeof LanguageCodeEnum;
|
|
16
|
+
export declare function StringToLanguageCode(value: string): LanguageCodeEnum;
|
|
17
|
+
/** A string with multiple language translations */
|
|
18
|
+
export interface MultilangString extends Record<LanguageCode, string> {
|
|
19
|
+
}
|
|
20
|
+
/** A string that may be localised or a simple string */
|
|
21
|
+
export type LocalisedString = MultilangString | string;
|
|
1
22
|
export declare enum EntityTypeEnum {
|
|
2
23
|
"DESTINATION" = "DESTINATION",
|
|
3
24
|
"PARK" = "PARK",
|
|
@@ -41,7 +62,7 @@ export type Entity = {
|
|
|
41
62
|
/** Unique entity identifier */
|
|
42
63
|
id: string;
|
|
43
64
|
/** Entity name */
|
|
44
|
-
name:
|
|
65
|
+
name: LocalisedString;
|
|
45
66
|
/** Type of entity */
|
|
46
67
|
entityType: EntityType;
|
|
47
68
|
/** Parent entity identifier, must always be set when entityType is not DESTINATION */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.types.d.ts","sourceRoot":"","sources":["../../src/types/entities.types.ts"],"names":[],"mappings":"AAEA,oBAAY,cAAc;IACtB,aAAa,gBAAgB;IAC7B,MAAM,SAAS;IACf,YAAY,eAAe;IAC3B,YAAY,eAAe;IAC3B,MAAM,SAAS;IACf,OAAO,UAAU;CACpB;AAED,kDAAkD;AAClD,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,cAAc,CAAC;AAGrD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,c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MAAM,CAAC;IAEX,kBAAkB;IAClB,IAAI,EAAE,eAAe,CAAC;IAEtB,qBAAqB;IACrB,UAAU,EAAE,UAAU,CAAC;IAEvB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB,oFAAoF;IACpF,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB,sBAAsB;IACtB,QAAQ,EAAE,MAAM,CAAC;IAEjB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,cAAc,CAAC;IAE1B,+CAA+C;IAC/C,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB,CAAA"}
|
|
@@ -1,4 +1,47 @@
|
|
|
1
1
|
// THIS FILE IS GENERATED - DO NOT EDIT DIRECTLY
|
|
2
|
+
export var LanguageCodeEnum;
|
|
3
|
+
(function (LanguageCodeEnum) {
|
|
4
|
+
LanguageCodeEnum["en"] = "en";
|
|
5
|
+
LanguageCodeEnum["en-gb"] = "en-gb";
|
|
6
|
+
LanguageCodeEnum["en-us"] = "en-us";
|
|
7
|
+
LanguageCodeEnum["de"] = "de";
|
|
8
|
+
LanguageCodeEnum["fr"] = "fr";
|
|
9
|
+
LanguageCodeEnum["es"] = "es";
|
|
10
|
+
LanguageCodeEnum["it"] = "it";
|
|
11
|
+
LanguageCodeEnum["nl"] = "nl";
|
|
12
|
+
LanguageCodeEnum["ja"] = "ja";
|
|
13
|
+
LanguageCodeEnum["ko"] = "ko";
|
|
14
|
+
LanguageCodeEnum["zh"] = "zh";
|
|
15
|
+
})(LanguageCodeEnum || (LanguageCodeEnum = {}));
|
|
16
|
+
// Function to convert string to LanguageCodeEnum
|
|
17
|
+
export function StringToLanguageCode(value) {
|
|
18
|
+
const lowerValue = value.toLowerCase();
|
|
19
|
+
switch (lowerValue) {
|
|
20
|
+
case 'en':
|
|
21
|
+
return LanguageCodeEnum.en;
|
|
22
|
+
case 'en-gb':
|
|
23
|
+
return LanguageCodeEnum["en-gb"];
|
|
24
|
+
case 'en-us':
|
|
25
|
+
return LanguageCodeEnum["en-us"];
|
|
26
|
+
case 'de':
|
|
27
|
+
return LanguageCodeEnum.de;
|
|
28
|
+
case 'fr':
|
|
29
|
+
return LanguageCodeEnum.fr;
|
|
30
|
+
case 'es':
|
|
31
|
+
return LanguageCodeEnum.es;
|
|
32
|
+
case 'it':
|
|
33
|
+
return LanguageCodeEnum.it;
|
|
34
|
+
case 'nl':
|
|
35
|
+
return LanguageCodeEnum.nl;
|
|
36
|
+
case 'ja':
|
|
37
|
+
return LanguageCodeEnum.ja;
|
|
38
|
+
case 'ko':
|
|
39
|
+
return LanguageCodeEnum.ko;
|
|
40
|
+
case 'zh':
|
|
41
|
+
return LanguageCodeEnum.zh;
|
|
42
|
+
}
|
|
43
|
+
throw new Error('Unknown LanguageCode value: ' + value);
|
|
44
|
+
}
|
|
2
45
|
export var EntityTypeEnum;
|
|
3
46
|
(function (EntityTypeEnum) {
|
|
4
47
|
EntityTypeEnum["DESTINATION"] = "DESTINATION";
|
|
@@ -60,6 +103,46 @@ export function StringToAttractionType(value) {
|
|
|
60
103
|
}
|
|
61
104
|
// Runtime Schema Registration
|
|
62
105
|
import { registerTypeSchema } from "../type_register.js";
|
|
106
|
+
registerTypeSchema("LanguageCode", {
|
|
107
|
+
"type": "string",
|
|
108
|
+
"enum": [
|
|
109
|
+
"en",
|
|
110
|
+
"en-gb",
|
|
111
|
+
"en-us",
|
|
112
|
+
"de",
|
|
113
|
+
"fr",
|
|
114
|
+
"es",
|
|
115
|
+
"it",
|
|
116
|
+
"nl",
|
|
117
|
+
"ja",
|
|
118
|
+
"ko",
|
|
119
|
+
"zh"
|
|
120
|
+
],
|
|
121
|
+
"description": "Supported language codes for ThemeParks.wiki"
|
|
122
|
+
});
|
|
123
|
+
registerTypeSchema("MultilangString", {
|
|
124
|
+
"type": "object",
|
|
125
|
+
"description": "A string with multiple language translations",
|
|
126
|
+
"propertyNames": {
|
|
127
|
+
"$ref": "#/properties/LanguageCode"
|
|
128
|
+
},
|
|
129
|
+
"additionalProperties": {
|
|
130
|
+
"type": "string",
|
|
131
|
+
"description": "The string in the specified language"
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
registerTypeSchema("LocalisedString", {
|
|
135
|
+
"oneOf": [
|
|
136
|
+
{
|
|
137
|
+
"$ref": "#/properties/MultilangString"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"type": "string",
|
|
141
|
+
"description": "A simple string, no localisation. English where available, or native language if not."
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
"description": "A string that may be localised or a simple string"
|
|
145
|
+
});
|
|
63
146
|
registerTypeSchema("EntityType", {
|
|
64
147
|
"type": "string",
|
|
65
148
|
"enum": [
|
|
@@ -138,7 +221,7 @@ registerTypeSchema("Entity", {
|
|
|
138
221
|
"description": "Unique entity identifier"
|
|
139
222
|
},
|
|
140
223
|
"name": {
|
|
141
|
-
"
|
|
224
|
+
"$ref": "#/properties/LocalisedString",
|
|
142
225
|
"description": "Entity name"
|
|
143
226
|
},
|
|
144
227
|
"entityType": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@themeparks/typelib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
29
29
|
"generate:types": "npx tsx ./src/run_generate_types.ts",
|
|
30
30
|
"build": "npm run generate:types && tsc",
|
|
31
|
-
"prepublishOnly": "npm run build"
|
|
31
|
+
"prepublishOnly": "npm run build",
|
|
32
|
+
"runpublish": "npm publish --access public"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/node": "^24.5.2",
|
package/typesrc/entities.json
CHANGED
|
@@ -3,6 +3,46 @@
|
|
|
3
3
|
"title": "Entities",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
6
|
+
"LanguageCode": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"enum": [
|
|
9
|
+
"en",
|
|
10
|
+
"en-gb",
|
|
11
|
+
"en-us",
|
|
12
|
+
"de",
|
|
13
|
+
"fr",
|
|
14
|
+
"es",
|
|
15
|
+
"it",
|
|
16
|
+
"nl",
|
|
17
|
+
"ja",
|
|
18
|
+
"ko",
|
|
19
|
+
"zh"
|
|
20
|
+
],
|
|
21
|
+
"description": "Supported language codes for ThemeParks.wiki"
|
|
22
|
+
},
|
|
23
|
+
"MultilangString": {
|
|
24
|
+
"type": "object",
|
|
25
|
+
"description": "A string with multiple language translations",
|
|
26
|
+
"propertyNames": {
|
|
27
|
+
"$ref": "#/properties/LanguageCode"
|
|
28
|
+
},
|
|
29
|
+
"additionalProperties": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "The string in the specified language"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"LocalisedString": {
|
|
35
|
+
"oneOf": [
|
|
36
|
+
{
|
|
37
|
+
"$ref": "#/properties/MultilangString"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"type": "string",
|
|
41
|
+
"description": "A simple string, no localisation. English where available, or native language if not."
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"description": "A string that may be localised or a simple string"
|
|
45
|
+
},
|
|
6
46
|
"EntityType": {
|
|
7
47
|
"type": "string",
|
|
8
48
|
"enum": [
|
|
@@ -81,7 +121,7 @@
|
|
|
81
121
|
"description": "Unique entity identifier"
|
|
82
122
|
},
|
|
83
123
|
"name": {
|
|
84
|
-
"
|
|
124
|
+
"$ref": "#/properties/LocalisedString",
|
|
85
125
|
"description": "Entity name"
|
|
86
126
|
},
|
|
87
127
|
"entityType": {
|