densing 0.1.0 → 0.1.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/dist/index.js +30 -7
- package/dist/schema/type-generator.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
19
|
+
|
|
1
20
|
// src/schema/builder.ts
|
|
2
21
|
var bool = (name, defaultValue = false) => ({
|
|
3
22
|
type: "bool",
|
|
@@ -144,8 +163,6 @@ var createRecursiveUnion = (name, discriminatorOptions, createVariants, maxDepth
|
|
|
144
163
|
return union(name, enumeration("type", discriminatorOptions), recursiveVariants);
|
|
145
164
|
};
|
|
146
165
|
// src/schema/type-generator.ts
|
|
147
|
-
import { writeFileSync } from "fs";
|
|
148
|
-
import { resolve } from "path";
|
|
149
166
|
var generateTypes = (schema2, rootTypeName = "SchemaData") => {
|
|
150
167
|
const types = [];
|
|
151
168
|
const processedTypes = new Set;
|
|
@@ -161,11 +178,17 @@ ${rootFields}
|
|
|
161
178
|
|
|
162
179
|
`);
|
|
163
180
|
};
|
|
164
|
-
var generateTypesFile = (schema2, outputPath, rootTypeName = "SchemaData") => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
181
|
+
var generateTypesFile = async (schema2, outputPath, rootTypeName = "SchemaData") => {
|
|
182
|
+
try {
|
|
183
|
+
const { writeFileSync } = await import("fs");
|
|
184
|
+
const { resolve } = await import("path");
|
|
185
|
+
const types = generateTypes(schema2, rootTypeName);
|
|
186
|
+
const fullPath = resolve(outputPath);
|
|
187
|
+
writeFileSync(fullPath, types, "utf-8");
|
|
188
|
+
console.log(`Types written to: ${fullPath}`);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
throw new Error("generateTypesFile requires Node.js environment with fs module. Use generateTypes() instead for browser environments.");
|
|
191
|
+
}
|
|
169
192
|
};
|
|
170
193
|
var getFieldType = (field, types, processedTypes) => {
|
|
171
194
|
switch (field.type) {
|
|
@@ -5,8 +5,9 @@ import { DenseSchema } from '../schema-type';
|
|
|
5
5
|
export declare const generateTypes: (schema: DenseSchema, rootTypeName?: string) => string;
|
|
6
6
|
/**
|
|
7
7
|
* Generate types and write to a .d.ts file
|
|
8
|
+
* Note: This function requires Node.js fs module and will not work in browser environments
|
|
8
9
|
*/
|
|
9
|
-
export declare const generateTypesFile: (schema: DenseSchema, outputPath: string, rootTypeName?: string) => void
|
|
10
|
+
export declare const generateTypesFile: (schema: DenseSchema, outputPath: string, rootTypeName?: string) => Promise<void>;
|
|
10
11
|
/**
|
|
11
12
|
* Generate types and write to console (for convenience)
|
|
12
13
|
*/
|
package/package.json
CHANGED