@lakeql/schema-generator 0.3.0 → 0.4.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.
|
@@ -20,6 +20,34 @@ type LoadStrategy = (typeof loadStrategies)[number];
|
|
|
20
20
|
*/
|
|
21
21
|
declare const storageTypes: readonly ["s3", "minio"];
|
|
22
22
|
type StorageType = (typeof storageTypes)[number];
|
|
23
|
+
/**
|
|
24
|
+
* Supported partitioning format granularities.
|
|
25
|
+
*/
|
|
26
|
+
declare const partitioningFormats: readonly ["year", "year/month", "year/month/day"];
|
|
27
|
+
type PartitioningFormat = (typeof partitioningFormats)[number];
|
|
28
|
+
/**
|
|
29
|
+
* Supported date components for custom partition format segments.
|
|
30
|
+
*/
|
|
31
|
+
declare const partitioningComponents: readonly ["year", "month", "day", "hour", "minute", "second"];
|
|
32
|
+
type PartitioningComponent = (typeof partitioningComponents)[number];
|
|
33
|
+
/**
|
|
34
|
+
* Validates a custom partitioning format string.
|
|
35
|
+
* - If the value contains no `/` and no `:`, it must match fieldNamePattern (legacy single-field mode).
|
|
36
|
+
* - If it contains `/` or `:`, each segment is validated:
|
|
37
|
+
* - Plain segments must match fieldNamePattern.
|
|
38
|
+
* - Colon segments must be `fieldname:component` where fieldname matches pattern
|
|
39
|
+
* and component is one of the supported partitioning components.
|
|
40
|
+
*
|
|
41
|
+
* Returns null if valid, or an error message string if invalid.
|
|
42
|
+
*/
|
|
43
|
+
declare function validatePartitioningFormat(value: string): string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Partitioning configuration value:
|
|
46
|
+
* - true: partition by write timestamp (default)
|
|
47
|
+
* - false: no partitioning (flat layout)
|
|
48
|
+
* - string: partition by named field
|
|
49
|
+
*/
|
|
50
|
+
type PartitioningValue = boolean | string;
|
|
23
51
|
/**
|
|
24
52
|
* Mutation pipeline configuration for an endpoint.
|
|
25
53
|
*/
|
|
@@ -36,6 +64,10 @@ interface MutationConfig {
|
|
|
36
64
|
region?: string;
|
|
37
65
|
/** Optional custom endpoint. Required for MinIO, optional for S3. */
|
|
38
66
|
endpoint?: string;
|
|
67
|
+
/** Partitioning mode. Default: true */
|
|
68
|
+
partitioning?: PartitioningValue;
|
|
69
|
+
/** Partition path granularity. Default: "year/month/day" */
|
|
70
|
+
partitioningFormat?: string;
|
|
39
71
|
}
|
|
40
72
|
/**
|
|
41
73
|
* Zod schema for the mutation configuration object.
|
|
@@ -54,6 +86,8 @@ declare const mutationConfigSchema: z.ZodObject<{
|
|
|
54
86
|
basePath: z.ZodString;
|
|
55
87
|
region: z.ZodOptional<z.ZodString>;
|
|
56
88
|
endpoint: z.ZodOptional<z.ZodString>;
|
|
89
|
+
partitioning: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
90
|
+
partitioningFormat: z.ZodOptional<z.ZodString>;
|
|
57
91
|
}, z.core.$strip>;
|
|
58
92
|
/**
|
|
59
93
|
* Zod schema for the mutation field: either `false` (disabled) or a config object (enabled).
|
|
@@ -72,6 +106,8 @@ declare const mutationSchema: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObj
|
|
|
72
106
|
basePath: z.ZodString;
|
|
73
107
|
region: z.ZodOptional<z.ZodString>;
|
|
74
108
|
endpoint: z.ZodOptional<z.ZodString>;
|
|
109
|
+
partitioning: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
110
|
+
partitioningFormat: z.ZodOptional<z.ZodString>;
|
|
75
111
|
}, z.core.$strip>]>;
|
|
76
112
|
/**
|
|
77
113
|
* Supported primitive types for field definitions.
|
|
@@ -153,6 +189,8 @@ declare const endpointDefinitionSchema: z.ZodObject<{
|
|
|
153
189
|
basePath: z.ZodString;
|
|
154
190
|
region: z.ZodOptional<z.ZodString>;
|
|
155
191
|
endpoint: z.ZodOptional<z.ZodString>;
|
|
192
|
+
partitioning: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
193
|
+
partitioningFormat: z.ZodOptional<z.ZodString>;
|
|
156
194
|
}, z.core.$strip>]>>;
|
|
157
195
|
}, z.core.$strip>;
|
|
158
196
|
type EndpointDefinitionFormat = z.infer<typeof endpointDefinitionSchema>;
|
|
@@ -165,4 +203,4 @@ declare function findDuplicateFieldNames(fields: FieldDefinition[], path?: strin
|
|
|
165
203
|
path: string[];
|
|
166
204
|
}[];
|
|
167
205
|
//#endregion
|
|
168
|
-
export { ArrayItemDefinition, EndpointDefinitionFormat, FieldDefinition, FieldOptions, FieldValidation, LoadStrategy, MutationConfig, PrimitiveType, StorageType, endpointDefinitionSchema, fieldDefinitionSchema, fieldNamePattern, fieldOptionsSchema, fieldValidationSchema, findDuplicateFieldNames, loadStrategies, metadataFieldPattern, mutationConfigSchema, mutationSchema, primitiveTypes, storageTypes };
|
|
206
|
+
export { ArrayItemDefinition, EndpointDefinitionFormat, FieldDefinition, FieldOptions, FieldValidation, LoadStrategy, MutationConfig, PartitioningComponent, PartitioningFormat, PartitioningValue, PrimitiveType, StorageType, endpointDefinitionSchema, fieldDefinitionSchema, fieldNamePattern, fieldOptionsSchema, fieldValidationSchema, findDuplicateFieldNames, loadStrategies, metadataFieldPattern, mutationConfigSchema, mutationSchema, partitioningComponents, partitioningFormats, primitiveTypes, storageTypes, validatePartitioningFormat };
|
package/dist/endpoint-schema.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as e}from"zod";const t=/^[a-zA-Z_][a-zA-Z0-9_]{0,63}$/u,n=/^[a-zA-Z_][a-zA-Z0-9_]{0,127}$/u,r=[`full_load`,`full_load_append`,`append`],i=[`s3`,`minio`],a=e.object({loadStrategy:e.enum(r),type:e.enum(i).default(`s3`),bucket:e.string().min(1),basePath:e.string().min(1),region:e.string().optional(),endpoint:e.string().optional()}),
|
|
1
|
+
import{z as e}from"zod";const t=/^[a-zA-Z_][a-zA-Z0-9_]{0,63}$/u,n=/^[a-zA-Z_][a-zA-Z0-9_]{0,127}$/u,r=[`full_load`,`full_load_append`,`append`],i=[`s3`,`minio`],a=[`year`,`year/month`,`year/month/day`],o=[`year`,`month`,`day`,`hour`,`minute`,`second`];function s(e){if(!(e.includes(`/`)||e.includes(`:`)))return t.test(e)?null:`Invalid partition field name "${e}". Must match pattern: letters/underscores, no leading digit, max 64 chars.`;let n=e.split(`/`);for(let r of n){if(r===``)return`Invalid partition format: empty segment found in "${e}".`;if(r.includes(`:`)){let e=r.split(`:`);if(e.length!==2)return`Invalid partition segment "${r}": expected format "fieldname:component".`;let[n,i]=e;if(!t.test(n))return`Invalid field name "${n}" in partition segment "${r}".`;if(!o.includes(i))return`Invalid date component "${i}" in partition segment "${r}". Expected one of: ${o.join(`, `)}.`}else if(!t.test(r))return`Invalid field name "${r}" in partition format.`}return null}const c=e.object({loadStrategy:e.enum(r),type:e.enum(i).default(`s3`),bucket:e.string().min(1),basePath:e.string().min(1),region:e.string().optional(),endpoint:e.string().optional(),partitioning:e.union([e.boolean(),e.string().min(1)]).optional(),partitioningFormat:e.string().optional()}).superRefine((e,t)=>{if(e.type===`minio`&&!e.endpoint&&t.addIssue({code:`custom`,path:[`endpoint`],message:`Endpoint is required when storage type is 'minio'. Provide the MinIO server URL (e.g. http://minio:9000).`}),e.partitioning!==!1){if(typeof e.partitioning==`string`){let n=s(e.partitioning);if(n){t.addIssue({code:`custom`,path:[`partitioning`],message:n});return}if(e.partitioning.includes(`/`)||e.partitioning.includes(`:`))return}e.partitioningFormat!==void 0&&!a.includes(e.partitioningFormat)&&t.addIssue({code:`invalid_value`,values:[...a],path:[`partitioningFormat`],message:`Invalid partitioning format. Expected one of: ${a.join(`, `)}`})}}),l=e.union([e.literal(!1),c]),u=[`String`,`Integer`,`Float`,`Boolean`,`Date`,`DateTime`],d=e.union([e.object({type:e.literal(`email`)}),e.object({type:e.literal(`url`)}),e.object({type:e.literal(`uuid`)}),e.object({type:e.literal(`min`),value:e.number()}),e.object({type:e.literal(`max`),value:e.number()}),e.object({type:e.literal(`regex`),pattern:e.string()})]),f=e.object({required:e.boolean().optional(),validations:e.array(d).optional()}),p=e.lazy(()=>e.discriminatedUnion(`type`,[e.object({name:e.string().regex(t),type:e.literal(`String`),options:f.optional()}),e.object({name:e.string().regex(t),type:e.literal(`Integer`),options:f.optional()}),e.object({name:e.string().regex(t),type:e.literal(`Float`),options:f.optional()}),e.object({name:e.string().regex(t),type:e.literal(`Boolean`),options:f.optional()}),e.object({name:e.string().regex(t),type:e.literal(`Date`),options:f.optional()}),e.object({name:e.string().regex(t),type:e.literal(`DateTime`),options:f.optional()}),e.object({name:e.string().regex(t),type:e.literal(`Object`),fields:e.array(p).min(1),options:f.optional()}),e.object({name:e.string().regex(t),type:e.literal(`Array`),items:e.union([e.object({type:e.enum(u)}),e.object({type:e.literal(`Object`),fields:e.array(p).min(1)})]),options:f.optional()})])),m=e.object({version:e.literal(`1.0`),tableName:e.string().regex(n),catalog:e.string().regex(n),schema:e.string().regex(n),fields:e.array(p),mutation:l.optional()});function h(e,t=[]){let n=[],r=new Set;for(let i of e)r.has(i.name)?n.push({name:i.name,path:t}):r.add(i.name),i.type===`Object`&&i.fields&&n.push(...h(i.fields,[...t,i.name])),i.type===`Array`&&i.items?.type===`Object`&&i.items.fields&&n.push(...h(i.items.fields,[...t,i.name,`items`]));return n}export{m as endpointDefinitionSchema,p as fieldDefinitionSchema,t as fieldNamePattern,f as fieldOptionsSchema,d as fieldValidationSchema,h as findDuplicateFieldNames,r as loadStrategies,n as metadataFieldPattern,c as mutationConfigSchema,l as mutationSchema,o as partitioningComponents,a as partitioningFormats,u as primitiveTypes,i as storageTypes,s as validatePartitioningFormat};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakeql/schema-generator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Generates GraphQL schemas, Hive table definitions, and JSON schemas from Trino metadata",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codegen",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"lodash-es": "4.18.1",
|
|
56
56
|
"magic-regexp": "0.11.0",
|
|
57
57
|
"zod": "4.4.3",
|
|
58
|
-
"@lakeql/helpers": "0.1.
|
|
58
|
+
"@lakeql/helpers": "0.1.3"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/json-schema": "7.0.15",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"json-column-parser": "2.0.0",
|
|
66
66
|
"tsdown": "0.22.2",
|
|
67
67
|
"typescript": "6.0.3",
|
|
68
|
-
"vitest": "4.1.
|
|
68
|
+
"vitest": "4.1.9",
|
|
69
69
|
"@lakeql/tsconfig": "0.1.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|