@lakeql/schema-generator 0.2.0 → 0.2.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/json-schema.mjs +1 -1
- package/package.json +1 -1
package/dist/json-schema.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as e}from"@lakeql/helpers/object-helper";import{createRegExp as t,global as n,not as r}from"magic-regexp";function i(e){return{$schema:`https://json-schema.org/draft-07/schema#`,...s(e),additionalProperties:!1}}function a(e){let i=t(r.letter,[n]),a=e.toString().replace(i,``);switch(a){case`varchar`:return{type:`string`};case`decimal`:case`double`:case`float`:return{type:`number`};case`integer`:case`bigint`:return{type:`integer`};case`boolean`:return{type:`boolean`};case`timestamp`:return{format:`date-time`,type:`string`};case`date`:return{format:`date`,type:`string`};default:throw Error(`Type ${a.toString()} is unknown.`)}}function o(t){if(t.length>1)throw Error("We expect that an array has only one element ( e.g. a primitive like `varchar` or an object like `row()`.");if(Array.isArray(t[0]))throw TypeError(`We currently do not support 'array of array'. Feel free to raise an issue.`);if(typeof t[0]==`string`)return{items:a(t[0]),type:`array`};if(e(t[0]))return{items:s(t[0]),type:`array`};throw Error("Unexpected case in `json-generator.handleArray`")}function s(t){let n={additionalProperties:!1,properties:{},type:`object`};for(let[r,i]of Object.entries(t))
|
|
1
|
+
import{isObject as e}from"@lakeql/helpers/object-helper";import{createRegExp as t,global as n,not as r}from"magic-regexp";function i(e){return{$schema:`https://json-schema.org/draft-07/schema#`,...s(e),additionalProperties:!1}}function a(e){let i=t(r.letter,[n]),a=e.toString().replace(i,``);switch(a){case`varchar`:return{type:`string`};case`decimal`:case`double`:case`float`:return{type:`number`};case`integer`:case`bigint`:return{type:`integer`};case`boolean`:return{type:`boolean`};case`timestamp`:return{format:`date-time`,type:`string`};case`date`:return{format:`date`,type:`string`};default:throw Error(`Type ${a.toString()} is unknown.`)}}function o(t){if(t.length>1)throw Error("We expect that an array has only one element ( e.g. a primitive like `varchar` or an object like `row()`.");if(Array.isArray(t[0]))throw TypeError(`We currently do not support 'array of array'. Feel free to raise an issue.`);if(typeof t[0]==`string`)return{items:a(t[0]),type:`array`};if(e(t[0]))return{items:s(t[0]),type:`array`};throw Error("Unexpected case in `json-generator.handleArray`")}function s(t){let n={additionalProperties:!1,properties:{},type:`object`};for(let[r,i]of Object.entries(t))typeof i==`string`&&(n.properties[r]=a(i)),Array.isArray(i)&&(n.properties[r]=o(i)),e(i)&&(n.properties[r]=s(i));return n}function c(e){switch(e){case`String`:return{type:`string`};case`Integer`:return{type:`integer`};case`Float`:return{type:`number`};case`Boolean`:return{type:`boolean`};case`Date`:return{type:`string`,format:`date`};case`DateTime`:return{type:`string`,format:`date-time`};default:return{type:`string`}}}function l(e){return e.type===`Object`&&e.fields?{type:`object`,properties:d(e.fields),additionalProperties:!1}:c(e.type)}function u(e){switch(e.type){case`Object`:return{type:`object`,properties:d(e.fields??[]),additionalProperties:!1};case`Array`:return{type:`array`,items:e.items?l(e.items):{type:`string`}};default:return c(e.type)}}function d(e){let t={};for(let n of e)t[n.name]=u(n);return t}function f(e){return{$schema:`https://json-schema.org/draft-07/schema#`,type:`object`,properties:d(e),additionalProperties:!1}}export{i as generateJsonSchema,f as generateJsonSchemaFromFields};
|