@maplibre-yaml/core 0.2.2 → 0.3.0-alpha.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.
@@ -102,8 +102,30 @@ var GeoJSONSourceSchema = z.object({
102
102
  generateId: z.boolean().optional(),
103
103
  promoteId: z.union([z.string(), z.record(z.string())]).optional(),
104
104
  attribution: z.string().optional()
105
- }).passthrough().refine((data) => data.url || data.data || data.prefetchedData, {
106
- message: 'GeoJSON source requires at least one of: url, data, or prefetchedData. Use "url" to fetch from an endpoint, "data" for inline GeoJSON, or "prefetchedData" for build-time fetched data.'
105
+ }).passthrough().superRefine((d, ctx) => {
106
+ if (!d.url && !d.data && !d.prefetchedData) {
107
+ ctx.addIssue({
108
+ code: z.ZodIssueCode.custom,
109
+ message: 'GeoJSON source requires at least one of: url, data, or prefetchedData. Use "url" to fetch from an endpoint, "data" for inline GeoJSON, or "prefetchedData" for build-time fetched data.'
110
+ });
111
+ return;
112
+ }
113
+ if (typeof d.data === "string" && /^(\.\.?|\/?src)\//.test(d.data)) {
114
+ ctx.addIssue({
115
+ code: z.ZodIssueCode.custom,
116
+ path: ["data"],
117
+ // Recommends `data: "/data/..."` rather than `url:` because the
118
+ // `url:` field is schema-validated with z.string().url(), which
119
+ // requires a fully-qualified URL (`https://...`) and rejects
120
+ // root-relative paths. MapLibre treats a string in `data:` as a
121
+ // URL and fetches it correctly. Until url: relaxes to accept
122
+ // root-relative paths (see follow-up), `data: "/path"` is the
123
+ // working pattern for files served from public/.
124
+ message: `GeoJSON source.data must be an inline GeoJSON object or a URL. "${d.data}" is a local source-directory path that won't resolve at runtime. Move the file to public/ and reference the public-served URL:
125
+ data: "/data/<filename>.geojson"
126
+ (\`url:\` requires a fully-qualified https:// URL and won't accept root-relative paths; use \`data:\` for runtime URLs to public assets.)`
127
+ });
128
+ }
107
129
  });
108
130
  var VectorSourceSchema = z.object({
109
131
  type: z.literal("vector").describe("Source type"),