@ndla/types-taxonomy 1.0.35 → 1.0.37
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/build/scripts/generate-openapi.d.ts +1 -0
- package/build/scripts/generate-openapi.js +128 -0
- package/build/scripts/generate-openapi.js.map +1 -0
- package/build/taxonomy-api.d.ts +8322 -0
- package/build/taxonomy-api.js +3 -0
- package/build/taxonomy-api.js.map +1 -0
- package/openapi.json +1 -0
- package/package.json +7 -3
- package/scripts/generate-openapi.ts +49 -0
- package/taxonomy-api.ts +8321 -838
- package/mise.toml +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Part of NDLA taxonomy-api
|
|
4
|
+
* Copyright (C) 2025 NDLA
|
|
5
|
+
*
|
|
6
|
+
* See LICENSE
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
43
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
44
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
45
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
46
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
47
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
48
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
52
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
53
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
54
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
58
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
60
|
+
switch (op[0]) {
|
|
61
|
+
case 0: case 1: t = op; break;
|
|
62
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
63
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
64
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
65
|
+
default:
|
|
66
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
67
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
68
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
69
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
70
|
+
if (t[2]) _.ops.pop();
|
|
71
|
+
_.trys.pop(); continue;
|
|
72
|
+
}
|
|
73
|
+
op = body.call(thisArg, _);
|
|
74
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
75
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
79
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
80
|
+
};
|
|
81
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
82
|
+
var node_fs_1 = __importDefault(require("node:fs"));
|
|
83
|
+
var openapi_typescript_1 = __importStar(require("openapi-typescript"));
|
|
84
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
85
|
+
if (process.argv.length !== 2) {
|
|
86
|
+
throw new Error("Invalid use");
|
|
87
|
+
}
|
|
88
|
+
var BLOB = typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier("Blob"));
|
|
89
|
+
var NULL = typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNull()); // `null`
|
|
90
|
+
function generate_types(appName) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
+
var jsonFile, schema, ast, outputPath, output;
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
switch (_a.label) {
|
|
95
|
+
case 0:
|
|
96
|
+
jsonFile = "./openapi.json";
|
|
97
|
+
console.log("Parsing ".concat(jsonFile, " to generate typescript files..."));
|
|
98
|
+
return [4 /*yield*/, node_fs_1.default.promises.readFile(jsonFile, "utf8")];
|
|
99
|
+
case 1:
|
|
100
|
+
schema = _a.sent();
|
|
101
|
+
return [4 /*yield*/, (0, openapi_typescript_1.default)(JSON.parse(schema), {
|
|
102
|
+
exportType: true,
|
|
103
|
+
// https://openapi-ts.dev/migration-guide#defaultnonnullable-true-by-default
|
|
104
|
+
defaultNonNullable: false,
|
|
105
|
+
transform: function (schemaObject, _options) {
|
|
106
|
+
if (schemaObject.format === "binary") {
|
|
107
|
+
if (schemaObject.nullable) {
|
|
108
|
+
return typescript_1.default.factory.createUnionTypeNode([BLOB, NULL]);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return BLOB;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
})];
|
|
116
|
+
case 2:
|
|
117
|
+
ast = _a.sent();
|
|
118
|
+
outputPath = "./taxonomy-api.ts";
|
|
119
|
+
output = (0, openapi_typescript_1.astToString)(ast);
|
|
120
|
+
console.log("Outputting to ".concat(outputPath));
|
|
121
|
+
node_fs_1.default.writeFileSync(outputPath, output);
|
|
122
|
+
return [2 /*return*/];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
generate_types(process.argv[2]);
|
|
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