@lakeql/schema-generator 0.2.1 → 0.4.0
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.
|
@@ -15,14 +15,59 @@ declare const metadataFieldPattern: RegExp;
|
|
|
15
15
|
*/
|
|
16
16
|
declare const loadStrategies: readonly ["full_load", "full_load_append", "append"];
|
|
17
17
|
type LoadStrategy = (typeof loadStrategies)[number];
|
|
18
|
+
/**
|
|
19
|
+
* Supported storage adapter types.
|
|
20
|
+
*/
|
|
21
|
+
declare const storageTypes: readonly ["s3", "minio"];
|
|
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;
|
|
18
51
|
/**
|
|
19
52
|
* Mutation pipeline configuration for an endpoint.
|
|
20
53
|
*/
|
|
21
54
|
interface MutationConfig {
|
|
22
55
|
/** Load strategy for the write pipeline. */
|
|
23
56
|
loadStrategy: LoadStrategy;
|
|
24
|
-
/**
|
|
57
|
+
/** Storage adapter type. Defaults to "s3". */
|
|
58
|
+
type: StorageType;
|
|
59
|
+
/** S3/MinIO bucket name for endpoint data. */
|
|
60
|
+
bucket: string;
|
|
61
|
+
/** Base path for endpoint data. */
|
|
25
62
|
basePath: string;
|
|
63
|
+
/** Optional region override (falls back to AWS_DEFAULT_REGION env var for S3). */
|
|
64
|
+
region?: string;
|
|
65
|
+
/** Optional custom endpoint. Required for MinIO, optional for S3. */
|
|
66
|
+
endpoint?: string;
|
|
67
|
+
/** Partitioning mode. Default: true */
|
|
68
|
+
partitioning?: PartitioningValue;
|
|
69
|
+
/** Partition path granularity. Default: "year/month/day" */
|
|
70
|
+
partitioningFormat?: string;
|
|
26
71
|
}
|
|
27
72
|
/**
|
|
28
73
|
* Zod schema for the mutation configuration object.
|
|
@@ -33,7 +78,16 @@ declare const mutationConfigSchema: z.ZodObject<{
|
|
|
33
78
|
full_load_append: "full_load_append";
|
|
34
79
|
append: "append";
|
|
35
80
|
}>;
|
|
81
|
+
type: z.ZodDefault<z.ZodEnum<{
|
|
82
|
+
s3: "s3";
|
|
83
|
+
minio: "minio";
|
|
84
|
+
}>>;
|
|
85
|
+
bucket: z.ZodString;
|
|
36
86
|
basePath: z.ZodString;
|
|
87
|
+
region: z.ZodOptional<z.ZodString>;
|
|
88
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
89
|
+
partitioning: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
90
|
+
partitioningFormat: z.ZodOptional<z.ZodString>;
|
|
37
91
|
}, z.core.$strip>;
|
|
38
92
|
/**
|
|
39
93
|
* Zod schema for the mutation field: either `false` (disabled) or a config object (enabled).
|
|
@@ -44,7 +98,16 @@ declare const mutationSchema: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObj
|
|
|
44
98
|
full_load_append: "full_load_append";
|
|
45
99
|
append: "append";
|
|
46
100
|
}>;
|
|
101
|
+
type: z.ZodDefault<z.ZodEnum<{
|
|
102
|
+
s3: "s3";
|
|
103
|
+
minio: "minio";
|
|
104
|
+
}>>;
|
|
105
|
+
bucket: z.ZodString;
|
|
47
106
|
basePath: z.ZodString;
|
|
107
|
+
region: z.ZodOptional<z.ZodString>;
|
|
108
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
109
|
+
partitioning: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
110
|
+
partitioningFormat: z.ZodOptional<z.ZodString>;
|
|
48
111
|
}, z.core.$strip>]>;
|
|
49
112
|
/**
|
|
50
113
|
* Supported primitive types for field definitions.
|
|
@@ -118,7 +181,16 @@ declare const endpointDefinitionSchema: z.ZodObject<{
|
|
|
118
181
|
full_load_append: "full_load_append";
|
|
119
182
|
append: "append";
|
|
120
183
|
}>;
|
|
184
|
+
type: z.ZodDefault<z.ZodEnum<{
|
|
185
|
+
s3: "s3";
|
|
186
|
+
minio: "minio";
|
|
187
|
+
}>>;
|
|
188
|
+
bucket: z.ZodString;
|
|
121
189
|
basePath: z.ZodString;
|
|
190
|
+
region: z.ZodOptional<z.ZodString>;
|
|
191
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
192
|
+
partitioning: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
193
|
+
partitioningFormat: z.ZodOptional<z.ZodString>;
|
|
122
194
|
}, z.core.$strip>]>>;
|
|
123
195
|
}, z.core.$strip>;
|
|
124
196
|
type EndpointDefinitionFormat = z.infer<typeof endpointDefinitionSchema>;
|
|
@@ -131,4 +203,4 @@ declare function findDuplicateFieldNames(fields: FieldDefinition[], path?: strin
|
|
|
131
203
|
path: string[];
|
|
132
204
|
}[];
|
|
133
205
|
//#endregion
|
|
134
|
-
export { ArrayItemDefinition, EndpointDefinitionFormat, FieldDefinition, FieldOptions, FieldValidation, LoadStrategy, MutationConfig, PrimitiveType, endpointDefinitionSchema, fieldDefinitionSchema, fieldNamePattern, fieldOptionsSchema, fieldValidationSchema, findDuplicateFieldNames, loadStrategies, metadataFieldPattern, mutationConfigSchema, mutationSchema, primitiveTypes };
|
|
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=e.object({loadStrategy:e.enum(r),basePath:e.string().min(1)}),a=e.union([e.literal(!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=[`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.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.0",
|
|
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": {
|