@nu-art/schema-to-types 0.300.8 → 0.400.1

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/main.js CHANGED
@@ -1,22 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfigArg = void 0;
4
- const schema_to_types_1 = require("./schema-to-types");
5
- const getConfigArg = () => {
1
+ // main.ts
2
+ import { processConfig } from './schema-to-types.js';
3
+ export const getConfigArg = () => {
6
4
  const configArgPrefix = '--config=';
7
5
  const configArg = process.argv.find(arg => arg.startsWith(configArgPrefix));
8
- if (!configArg) {
6
+ if (!configArg)
9
7
  return;
10
- }
11
8
  return configArg.substring(configArgPrefix.length);
12
9
  };
13
- exports.getConfigArg = getConfigArg;
14
10
  const main = async () => {
15
- const configPath = (0, exports.getConfigArg)();
11
+ const configPath = getConfigArg();
16
12
  if (!configPath) {
17
- console.log("Usage: ts-node generate-types.ts --config=<config-file-path>");
13
+ console.log('Usage: ts-node generate-types.ts --config=<config-file-path>');
18
14
  process.exit(1);
19
15
  }
20
- await (0, schema_to_types_1.processConfig)(configPath).catch(console.error);
16
+ await processConfig(configPath).catch(console.error);
21
17
  };
22
18
  main();
19
+ //# sourceMappingURL=main.js.map
package/main.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"/Users/tacb0ss/dev/nu-art/beamz/_thunderstorm/schema-to-types/src/main/","sources":["main.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAEnD,MAAM,CAAC,MAAM,YAAY,GAAG,GAAuB,EAAE;IACpD,MAAM,eAAe,GAAG,WAAW,CAAC;IACpC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC;IAC5E,IAAI,CAAC,SAAS;QAAE,OAAO;IACvB,OAAO,SAAS,CAAC,SAAS,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE;IACvB,MAAM,UAAU,GAAG,YAAY,EAAE,CAAC;IAClC,IAAI,CAAC,UAAU,EAAE,CAAC;QACjB,OAAO,CAAC,GAAG,CAAC,8DAA8D,CAAC,CAAC;QAC5E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IACD,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACtD,CAAC,CAAC;AAEF,IAAI,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@nu-art/schema-to-types",
3
- "version": "0.300.8",
3
+ "version": "0.400.1",
4
4
  "description": "schema-to-types - Express & Typescript based backend framework",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "import": "./index.js"
10
+ }
11
+ },
5
12
  "keywords": [
6
13
  "TacB0sS",
7
14
  "infra",
@@ -24,8 +31,6 @@
24
31
  },
25
32
  "license": "Apache-2.0",
26
33
  "author": "TacB0sS",
27
- "main": "index.js",
28
- "types": "index.d.ts",
29
34
  "files": [
30
35
  "**/*"
31
36
  ],
@@ -33,6 +38,16 @@
33
38
  "build": "tsc"
34
39
  },
35
40
  "dependencies": {
36
- "json-schema-to-typescript": "^13.1.1"
41
+ "@apidevtools/json-schema-ref-parser": "^14.2.0",
42
+ "command-line-args": "^6.0.1",
43
+ "quicktype-core": "^23.2.6"
44
+ },
45
+ "devDependencies": {
46
+ "@types/readable-stream": "^4.0.21",
47
+ "@types/urijs": "^1.19.25",
48
+ "@types/command-line-args": "^5.2.3"
49
+ },
50
+ "unitConfig": {
51
+ "type": "typescript-lib"
37
52
  }
38
- }
53
+ }
@@ -1,56 +1,50 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.processConfig = void 0;
27
- const fs = __importStar(require("fs"));
28
- const path = __importStar(require("path"));
29
- const json_schema_to_typescript_1 = require("json-schema-to-typescript");
1
+ // schema-to-types.ts
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
+ import $RefParser from '@apidevtools/json-schema-ref-parser';
5
+ import { FetchingJSONSchemaStore, InputData, JSONSchemaInput, quicktype, TypeScriptTargetLanguage, } from 'quicktype-core';
6
+ /**
7
+ * Generate TypeScript defs from a JSON Schema file.
8
+ * - Bundles all external $refs into a single schema object
9
+ * - Emits only type/interface declarations (no runtime helpers)
10
+ */
30
11
  const generateTypeScriptType = async (inputPath, outputPath) => {
31
- const options = {
32
- $refOptions: {
33
- resolve: {
34
- // Resolves local file references
35
- file: {
36
- read(file) {
37
- const filePath = path.resolve(path.dirname(inputPath), file.url);
38
- return fs.promises.readFile(filePath, 'utf8');
39
- }
40
- }
41
- }
42
- }
43
- };
44
- const ts = await (0, json_schema_to_typescript_1.compileFromFile)(inputPath, options);
12
+ // Inline external refs but keep internal $ref to avoid cycles
13
+ const bundledSchema = await $RefParser.bundle(path.resolve(inputPath));
14
+ const topLevelName = inferTopLevelName(outputPath, inputPath);
15
+ const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore());
16
+ await schemaInput.addSource({
17
+ name: topLevelName,
18
+ schema: JSON.stringify(bundledSchema),
19
+ });
20
+ const inputData = new InputData();
21
+ inputData.addInput(schemaInput);
22
+ const { lines } = await quicktype({
23
+ inputData,
24
+ lang: new TypeScriptTargetLanguage(),
25
+ rendererOptions: { 'just-types': 'true' }, // <= only types/interfaces
26
+ });
27
+ const ts = [
28
+ `// Generated from ${path.basename(inputPath)} — do not edit by hand.`,
29
+ `// ${new Date().toISOString()}`,
30
+ '',
31
+ ...lines,
32
+ '',
33
+ ].join('\n');
45
34
  const outputDir = path.dirname(outputPath);
46
- if (!fs.existsSync(outputDir)) {
35
+ if (!fs.existsSync(outputDir))
47
36
  fs.mkdirSync(outputDir, { recursive: true });
48
- }
49
- fs.writeFileSync(outputPath, ts);
37
+ fs.writeFileSync(outputPath, ts, 'utf8');
50
38
  };
51
- const processConfig = async (configPath) => {
39
+ function inferTopLevelName(outputPath, fallbackPath) {
40
+ const base = path.basename(outputPath || fallbackPath).replace(/\.(d\.)?tsx?$/i, '').trim();
41
+ const name = base.replace(/[^A-Za-z0-9_$]/g, '_'); // best-effort valid TS identifier
42
+ return name.length ? name : 'Schema';
43
+ }
44
+ export const processConfig = async (configPath) => {
52
45
  const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
53
- for (const schemaConfig of config)
54
- await generateTypeScriptType(schemaConfig.input, schemaConfig.output);
46
+ for (const { input, output } of config) {
47
+ await generateTypeScriptType(input, output);
48
+ }
55
49
  };
56
- exports.processConfig = processConfig;
50
+ //# sourceMappingURL=schema-to-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-to-types.js","sourceR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
9
- "dom"
10
- ],
11
- "declaration": true,
12
- "resolveJsonModule": true,
13
- "esModuleInterop": true,
14
- "experimentalDecorators": true,
15
- "moduleResolution": "node",
16
- "noUnusedLocals": true,
17
- "module": "commonjs",
18
- "sourceMap": true,
19
- "strict": true
20
- },
21
- "esModuleInterop": true,
22
- "module": "ES2020"
23
- }