@artinstack/migrator 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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Stateless content normalizer and migration framework for transforming **WordPress**, **SmugMug**, **Squarespace**, and similar sources into a platform-agnostic schema.
4
4
 
5
- **Public from day one.** Portable parsers and JSON export are useful without any specific host. Job orchestration, credentials, and UI are implemented separately via `MigrationSink`.
5
+ Portable parsers and JSON export are useful without any specific host. Job orchestration, credentials, and UI are implemented separately via `MigrationSink`.
6
6
 
7
7
  See [docs/architecture.md](./docs/architecture.md) for the high-level blueprint: data flow, DTOs, sink contract, and source mappings.
8
8
 
@@ -150,4 +150,4 @@ interface BundleCounts {
150
150
  }
151
151
  declare function bundleCounts(bundle: EntityBundle): BundleCounts;
152
152
 
153
- export { type AdapterContext as A, type BundleCounts as B, type EntityBundle as E, type MigrationAdapter as M, type NormalizedAsset as N, type PortfolioMediaLink as P, type SourceMetadata as S, type ValidationIssue as V, type MigrationPlatform as a, type EntityKey as b, type EntityType as c, type MigrationCursor as d, type NormalizedAssetExif as e, type NormalizedCategory as f, type NormalizedEntity as g, type NormalizedPage as h, type NormalizedPortfolio as i, type NormalizedPost as j, type NormalizedTag as k, type PublishStatus as l, type ValidationResult as m, bundleCounts as n, collectEntities as o, emptyBundle as p, entityKey as q };
153
+ export { type AdapterContext as A, type BundleCounts as B, type EntityBundle as E, type MigrationAdapter as M, type NormalizedAsset as N, type PortfolioMediaLink as P, type SourceMetadata as S, type ValidationResult as V, type MigrationPlatform as a, type EntityKey as b, type EntityType as c, type MigrationCursor as d, type NormalizedAssetExif as e, type NormalizedCategory as f, type NormalizedEntity as g, type NormalizedPage as h, type NormalizedPortfolio as i, type NormalizedPost as j, type NormalizedTag as k, type PublishStatus as l, type ValidationIssue as m, bundleCounts as n, collectEntities as o, emptyBundle as p, entityKey as q };
@@ -0,0 +1,147 @@
1
+ // src/normalizer/validate.ts
2
+ import { z } from "zod";
3
+ var migrationPlatformSchema = z.enum(["wordpress", "smugmug", "squarespace"]);
4
+ var publishStatusSchema = z.enum(["draft", "published", "archived"]);
5
+ var sourceMetadataSchema = z.object({
6
+ platform: migrationPlatformSchema,
7
+ id: z.string().min(1),
8
+ url: z.string().optional(),
9
+ path: z.string().optional(),
10
+ exportedAt: z.string().optional()
11
+ });
12
+ var normalizedPostSchema = z.object({
13
+ type: z.literal("post"),
14
+ source: sourceMetadataSchema,
15
+ sourceId: z.string().min(1),
16
+ title: z.string().min(1),
17
+ slug: z.string().min(1),
18
+ excerpt: z.string().optional(),
19
+ contentHtml: z.string(),
20
+ publishedAt: z.string().optional(),
21
+ status: publishStatusSchema,
22
+ categorySlugs: z.array(z.string().min(1)).optional(),
23
+ tagSlugs: z.array(z.string().min(1)).optional(),
24
+ sourceFeaturedMediaId: z.string().optional(),
25
+ featuredAssetSourceId: z.string().optional(),
26
+ seoTitle: z.string().optional(),
27
+ seoDescription: z.string().optional()
28
+ });
29
+ var normalizedPageSchema = z.object({
30
+ type: z.literal("page"),
31
+ source: sourceMetadataSchema,
32
+ sourceId: z.string().min(1),
33
+ title: z.string().min(1),
34
+ slug: z.string().min(1),
35
+ contentHtml: z.string(),
36
+ contentCss: z.string().optional(),
37
+ isHomePage: z.boolean().optional(),
38
+ status: publishStatusSchema,
39
+ seoTitle: z.string().optional(),
40
+ seoDescription: z.string().optional()
41
+ });
42
+ var normalizedAssetExifSchema = z.object({
43
+ iso: z.number().optional(),
44
+ aperture: z.number().optional(),
45
+ shutter: z.string().optional(),
46
+ focalLength: z.number().optional()
47
+ });
48
+ var normalizedAssetSchema = z.object({
49
+ type: z.literal("asset"),
50
+ source: sourceMetadataSchema,
51
+ sourceId: z.string().min(1),
52
+ sourceUrl: z.string().min(1),
53
+ filename: z.string().min(1),
54
+ mimeType: z.string().optional(),
55
+ caption: z.string().optional(),
56
+ altText: z.string().optional(),
57
+ keywords: z.array(z.string()).optional(),
58
+ exif: normalizedAssetExifSchema.optional(),
59
+ portfolioSourceId: z.string().optional(),
60
+ sort: z.number().optional()
61
+ });
62
+ var normalizedPortfolioSchema = z.object({
63
+ type: z.literal("portfolio"),
64
+ source: sourceMetadataSchema,
65
+ sourceId: z.string().min(1),
66
+ title: z.string().min(1),
67
+ slug: z.string().min(1),
68
+ description: z.string().optional(),
69
+ parentSourceId: z.string().optional()
70
+ });
71
+ var normalizedCategorySchema = z.object({
72
+ type: z.literal("category"),
73
+ source: sourceMetadataSchema,
74
+ sourceId: z.string().min(1),
75
+ name: z.string().min(1),
76
+ slug: z.string().min(1)
77
+ });
78
+ var normalizedTagSchema = z.object({
79
+ type: z.literal("tag"),
80
+ source: sourceMetadataSchema,
81
+ sourceId: z.string().min(1),
82
+ name: z.string().min(1),
83
+ slug: z.string().min(1)
84
+ });
85
+ var normalizedEntitySchema = z.discriminatedUnion("type", [
86
+ normalizedPostSchema,
87
+ normalizedPageSchema,
88
+ normalizedAssetSchema,
89
+ normalizedPortfolioSchema,
90
+ normalizedCategorySchema,
91
+ normalizedTagSchema
92
+ ]);
93
+ function zodIssuesToValidationIssues(issues) {
94
+ return issues.map((issue) => ({
95
+ code: issue.code,
96
+ message: issue.message,
97
+ path: issue.path.length > 0 ? issue.path.join(".") : void 0
98
+ }));
99
+ }
100
+ function parseToValidationResult(schema, value) {
101
+ const result = schema.safeParse(value);
102
+ if (result.success) {
103
+ return { ok: true, issues: [] };
104
+ }
105
+ return { ok: false, issues: zodIssuesToValidationIssues(result.error.issues) };
106
+ }
107
+ function validateNormalizedPost(post) {
108
+ return parseToValidationResult(normalizedPostSchema, post);
109
+ }
110
+ function validateNormalizedPage(page) {
111
+ return parseToValidationResult(normalizedPageSchema, page);
112
+ }
113
+ function validateNormalizedAsset(asset) {
114
+ return parseToValidationResult(normalizedAssetSchema, asset);
115
+ }
116
+ function validateNormalizedPortfolio(portfolio) {
117
+ return parseToValidationResult(normalizedPortfolioSchema, portfolio);
118
+ }
119
+ function validateNormalizedCategory(category) {
120
+ return parseToValidationResult(normalizedCategorySchema, category);
121
+ }
122
+ function validateNormalizedTag(tag) {
123
+ return parseToValidationResult(normalizedTagSchema, tag);
124
+ }
125
+ function validateNormalizedEntity(entity) {
126
+ return parseToValidationResult(normalizedEntitySchema, entity);
127
+ }
128
+
129
+ export {
130
+ sourceMetadataSchema,
131
+ normalizedPostSchema,
132
+ normalizedPageSchema,
133
+ normalizedAssetExifSchema,
134
+ normalizedAssetSchema,
135
+ normalizedPortfolioSchema,
136
+ normalizedCategorySchema,
137
+ normalizedTagSchema,
138
+ normalizedEntitySchema,
139
+ validateNormalizedPost,
140
+ validateNormalizedPage,
141
+ validateNormalizedAsset,
142
+ validateNormalizedPortfolio,
143
+ validateNormalizedCategory,
144
+ validateNormalizedTag,
145
+ validateNormalizedEntity
146
+ };
147
+ //# sourceMappingURL=chunk-5QEF5O5T.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/normalizer/validate.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport type { ValidationIssue, ValidationResult } from \"./types.js\";\n\nconst migrationPlatformSchema = z.enum([\"wordpress\", \"smugmug\", \"squarespace\"]);\nconst publishStatusSchema = z.enum([\"draft\", \"published\", \"archived\"]);\n\nexport const sourceMetadataSchema = z.object({\n platform: migrationPlatformSchema,\n id: z.string().min(1),\n url: z.string().optional(),\n path: z.string().optional(),\n exportedAt: z.string().optional(),\n});\n\nexport const normalizedPostSchema = z.object({\n type: z.literal(\"post\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n title: z.string().min(1),\n slug: z.string().min(1),\n excerpt: z.string().optional(),\n contentHtml: z.string(),\n publishedAt: z.string().optional(),\n status: publishStatusSchema,\n categorySlugs: z.array(z.string().min(1)).optional(),\n tagSlugs: z.array(z.string().min(1)).optional(),\n sourceFeaturedMediaId: z.string().optional(),\n featuredAssetSourceId: z.string().optional(),\n seoTitle: z.string().optional(),\n seoDescription: z.string().optional(),\n});\n\nexport const normalizedPageSchema = z.object({\n type: z.literal(\"page\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n title: z.string().min(1),\n slug: z.string().min(1),\n contentHtml: z.string(),\n contentCss: z.string().optional(),\n isHomePage: z.boolean().optional(),\n status: publishStatusSchema,\n seoTitle: z.string().optional(),\n seoDescription: z.string().optional(),\n});\n\nexport const normalizedAssetExifSchema = z.object({\n iso: z.number().optional(),\n aperture: z.number().optional(),\n shutter: z.string().optional(),\n focalLength: z.number().optional(),\n});\n\nexport const normalizedAssetSchema = z.object({\n type: z.literal(\"asset\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n sourceUrl: z.string().min(1),\n filename: z.string().min(1),\n mimeType: z.string().optional(),\n caption: z.string().optional(),\n altText: z.string().optional(),\n keywords: z.array(z.string()).optional(),\n exif: normalizedAssetExifSchema.optional(),\n portfolioSourceId: z.string().optional(),\n sort: z.number().optional(),\n});\n\nexport const normalizedPortfolioSchema = z.object({\n type: z.literal(\"portfolio\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n title: z.string().min(1),\n slug: z.string().min(1),\n description: z.string().optional(),\n parentSourceId: z.string().optional(),\n});\n\nexport const normalizedCategorySchema = z.object({\n type: z.literal(\"category\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n name: z.string().min(1),\n slug: z.string().min(1),\n});\n\nexport const normalizedTagSchema = z.object({\n type: z.literal(\"tag\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n name: z.string().min(1),\n slug: z.string().min(1),\n});\n\nexport const normalizedEntitySchema = z.discriminatedUnion(\"type\", [\n normalizedPostSchema,\n normalizedPageSchema,\n normalizedAssetSchema,\n normalizedPortfolioSchema,\n normalizedCategorySchema,\n normalizedTagSchema,\n]);\n\nfunction zodIssuesToValidationIssues(issues: z.ZodIssue[]): ValidationIssue[] {\n return issues.map((issue) => ({\n code: issue.code,\n message: issue.message,\n path: issue.path.length > 0 ? issue.path.join(\".\") : undefined,\n }));\n}\n\nfunction parseToValidationResult(schema: z.ZodTypeAny, value: unknown): ValidationResult {\n const result = schema.safeParse(value);\n if (result.success) {\n return { ok: true, issues: [] };\n }\n return { ok: false, issues: zodIssuesToValidationIssues(result.error.issues) };\n}\n\n/** Opt-in structural check for a normalized post DTO (no cross-entity FK validation). */\nexport function validateNormalizedPost(post: unknown): ValidationResult {\n return parseToValidationResult(normalizedPostSchema, post);\n}\n\n/** Opt-in structural check for a normalized page DTO (no cross-entity FK validation). */\nexport function validateNormalizedPage(page: unknown): ValidationResult {\n return parseToValidationResult(normalizedPageSchema, page);\n}\n\n/** Opt-in structural check for a normalized asset DTO. */\nexport function validateNormalizedAsset(asset: unknown): ValidationResult {\n return parseToValidationResult(normalizedAssetSchema, asset);\n}\n\n/** Opt-in structural check for a normalized portfolio DTO. */\nexport function validateNormalizedPortfolio(portfolio: unknown): ValidationResult {\n return parseToValidationResult(normalizedPortfolioSchema, portfolio);\n}\n\n/** Opt-in structural check for a normalized category DTO. */\nexport function validateNormalizedCategory(category: unknown): ValidationResult {\n return parseToValidationResult(normalizedCategorySchema, category);\n}\n\n/** Opt-in structural check for a normalized tag DTO. */\nexport function validateNormalizedTag(tag: unknown): ValidationResult {\n return parseToValidationResult(normalizedTagSchema, tag);\n}\n\n/** Opt-in structural check for any normalized entity discriminated by `type`. */\nexport function validateNormalizedEntity(entity: unknown): ValidationResult {\n return parseToValidationResult(normalizedEntitySchema, entity);\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAIlB,IAAM,0BAA0B,EAAE,KAAK,CAAC,aAAa,WAAW,aAAa,CAAC;AAC9E,IAAM,sBAAsB,EAAE,KAAK,CAAC,SAAS,aAAa,UAAU,CAAC;AAE9D,IAAM,uBAAuB,EAAE,OAAO;AAAA,EAC3C,UAAU;AAAA,EACV,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACpB,KAAK,EAAE,OAAO,EAAE,SAAS;AAAA,EACzB,MAAM,EAAE,OAAO,EAAE,S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,2BAA2B,UAAqC;AAC9E,SAAO,wBAAwB,0BAA0B,QAAQ;AACnE;AAGO,SAAS,sBAAsB,KAAgC;AACpE,SAAO,wBAAwB,qBAAqB,GAAG;AACzD;AAGO,SAAS,yBAAyB,QAAmC;AAC1E,SAAO,wBAAwB,wBAAwB,MAAM;AAC/D;","names":[]}
@@ -1,4 +1,4 @@
1
- import { f as NormalizedCategory, k as NormalizedTag, N as NormalizedAsset, i as NormalizedPortfolio, j as NormalizedPost, h as NormalizedPage, P as PortfolioMediaLink, b as EntityKey, g as NormalizedEntity, a as MigrationPlatform, E as EntityBundle, M as MigrationAdapter } from './bundle-BfZqiKV_.js';
1
+ import { f as NormalizedCategory, k as NormalizedTag, N as NormalizedAsset, i as NormalizedPortfolio, j as NormalizedPost, h as NormalizedPage, P as PortfolioMediaLink, b as EntityKey, g as NormalizedEntity, a as MigrationPlatform, E as EntityBundle, M as MigrationAdapter } from './bundle-DYPSKSQH.js';
2
2
  import { Readable } from 'node:stream';
3
3
 
4
4
  interface RewriteInlineImageRef {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { M as MigrationAdapter, a as MigrationPlatform } from './bundle-BfZqiKV_.js';
2
- export { A as AdapterContext, B as BundleCounts, E as EntityBundle, b as EntityKey, c as EntityType, d as MigrationCursor, N as NormalizedAsset, e as NormalizedAssetExif, f as NormalizedCategory, g as NormalizedEntity, h as NormalizedPage, i as NormalizedPortfolio, j as NormalizedPost, k as NormalizedTag, P as PortfolioMediaLink, l as PublishStatus, S as SourceMetadata, V as ValidationIssue, m as ValidationResult, n as bundleCounts, o as collectEntities, p as emptyBundle, q as entityKey } from './bundle-BfZqiKV_.js';
3
- export { EntityState, MigrationCheckpoint, TrackedEntity, buildPortfolioMediaLinks, isTerminalState, shouldProcessEntity } from './normalizer/index.js';
4
- export { C as ConflictReport, D as DryRunOptions, a as DryRunResult, F as FALLBACK_ASSET_BYTES, b as FilesystemMigrationSink, M as MIGRATION_WRITE_STAGES, c as MigrationRedirect, d as MigrationReport, e as MigrationRunMode, f as MigrationRunOptions, g as MigrationRunResult, h as MigrationSink, i as MigrationWriteStage, R as RewriteInlineImageRef, j as RewriteInlineImagesOptions, k as RewriteInlineImagesResult, S as StorageEstimate, U as UploadAssetInput, l as UploadAssetResult, m as UploadedAssetRef, W as WriteFilesystemOptions, n as analyzeConflicts, o as buildMigrationReport, p as buildRedirectMap, q as bundleToCombinedJson, r as createFilesystemMigrationSink, s as detectRedirectLoops, t as emptyConflictReport, u as estimateStorage, v as hasBlockingConflicts, w as hasWarnings, x as portfolioMediaMatchesBundle, y as rewriteInlineImages, z as runDryRun, A as runMigration, B as runMigrationFromBundle, E as staleUrlsFromEstimate, G as writeFilesystemExport } from './index-DQNzrygx.js';
1
+ import { M as MigrationAdapter, a as MigrationPlatform, V as ValidationResult } from './bundle-DYPSKSQH.js';
2
+ export { A as AdapterContext, B as BundleCounts, E as EntityBundle, b as EntityKey, c as EntityType, d as MigrationCursor, N as NormalizedAsset, e as NormalizedAssetExif, f as NormalizedCategory, g as NormalizedEntity, h as NormalizedPage, i as NormalizedPortfolio, j as NormalizedPost, k as NormalizedTag, P as PortfolioMediaLink, l as PublishStatus, S as SourceMetadata, m as ValidationIssue, n as bundleCounts, o as collectEntities, p as emptyBundle, q as entityKey } from './bundle-DYPSKSQH.js';
3
+ export { EntityState, MigrationCheckpoint, TrackedEntity, buildPortfolioMediaLinks, isTerminalState, normalizedAssetExifSchema, normalizedAssetSchema, normalizedCategorySchema, normalizedEntitySchema, normalizedPageSchema, normalizedPortfolioSchema, normalizedPostSchema, normalizedTagSchema, shouldProcessEntity, sourceMetadataSchema, validateNormalizedAsset, validateNormalizedCategory, validateNormalizedEntity, validateNormalizedPage, validateNormalizedPortfolio, validateNormalizedPost, validateNormalizedTag } from './normalizer/index.js';
4
+ export { C as ConflictReport, D as DryRunOptions, a as DryRunResult, F as FALLBACK_ASSET_BYTES, b as FilesystemMigrationSink, M as MIGRATION_WRITE_STAGES, c as MigrationRedirect, d as MigrationReport, e as MigrationRunMode, f as MigrationRunOptions, g as MigrationRunResult, h as MigrationSink, i as MigrationWriteStage, R as RewriteInlineImageRef, j as RewriteInlineImagesOptions, k as RewriteInlineImagesResult, S as StorageEstimate, U as UploadAssetInput, l as UploadAssetResult, m as UploadedAssetRef, W as WriteFilesystemOptions, n as analyzeConflicts, o as buildMigrationReport, p as buildRedirectMap, q as bundleToCombinedJson, r as createFilesystemMigrationSink, s as detectRedirectLoops, t as emptyConflictReport, u as estimateStorage, v as hasBlockingConflicts, w as hasWarnings, x as portfolioMediaMatchesBundle, y as rewriteInlineImages, z as runDryRun, A as runMigration, B as runMigrationFromBundle, E as staleUrlsFromEstimate, G as writeFilesystemExport } from './index-CtRzFhUw.js';
5
5
  import { z } from 'zod';
6
6
  import 'node:stream';
7
7
 
@@ -333,4 +333,56 @@ declare function htmlToGrapes(html: string, options?: HtmlToGrapesOptions): Grap
333
333
  /** Parse `<style>` blocks and class rules into Grapes root `styles[]`. */
334
334
  declare function cssToStyles(css: string): GrapesStyleRule[];
335
335
 
336
- export { type GrapesComponent, type GrapesProjectSnapshot, type GrapesStyleRule, type HtmlToGrapesOptions, MigrationAdapter, MigrationPlatform, SMUGMUG_API_BASE, SMUGMUG_OAUTH_ENDPOINTS, SQUARESPACE_JSON_FORMAT, SmugMugApiClient, type SmugMugClientOptions, type SmugMugCredentials, type SquarespaceClientOptions, type SquarespaceCollectTarget, SquarespaceCollectionClient, buildJsonPrettyUrl, buildSmugMugAuthorizationHeader, cssToStyles, getAdapter, htmlToGrapes, mapJsonPrettyWire, readSmugMugCredentialsFromEnv, signSmugMugOAuthRequest, smugMugCredentialsSchema, smugmugAdapter, squarespaceAdapter, wordpressAdapter };
336
+ declare const grapesStyleRuleSchema: z.ZodObject<{
337
+ selectors: z.ZodArray<z.ZodString, "many">;
338
+ style: z.ZodRecord<z.ZodString, z.ZodString>;
339
+ }, "strip", z.ZodTypeAny, {
340
+ style: Record<string, string>;
341
+ selectors: string[];
342
+ }, {
343
+ style: Record<string, string>;
344
+ selectors: string[];
345
+ }>;
346
+ declare const grapesComponentSchema: z.ZodType<GrapesComponent>;
347
+ declare const grapesProjectSnapshotSchema: z.ZodObject<{
348
+ content: z.ZodArray<z.ZodType<GrapesComponent, z.ZodTypeDef, GrapesComponent>, "many">;
349
+ styles: z.ZodArray<z.ZodObject<{
350
+ selectors: z.ZodArray<z.ZodString, "many">;
351
+ style: z.ZodRecord<z.ZodString, z.ZodString>;
352
+ }, "strip", z.ZodTypeAny, {
353
+ style: Record<string, string>;
354
+ selectors: string[];
355
+ }, {
356
+ style: Record<string, string>;
357
+ selectors: string[];
358
+ }>, "many">;
359
+ contentHtml: z.ZodOptional<z.ZodString>;
360
+ contentCss: z.ZodOptional<z.ZodString>;
361
+ }, "strip", z.ZodTypeAny, {
362
+ content: GrapesComponent[];
363
+ styles: {
364
+ style: Record<string, string>;
365
+ selectors: string[];
366
+ }[];
367
+ contentHtml?: string | undefined;
368
+ contentCss?: string | undefined;
369
+ }, {
370
+ content: GrapesComponent[];
371
+ styles: {
372
+ style: Record<string, string>;
373
+ selectors: string[];
374
+ }[];
375
+ contentHtml?: string | undefined;
376
+ contentCss?: string | undefined;
377
+ }>;
378
+ interface ValidateGrapesProjectSnapshotOptions {
379
+ /** When set, every component `type` in the tree must be in this allowlist. */
380
+ allowedComponentTypes?: string[];
381
+ }
382
+ /**
383
+ * Opt-in structural check for a Grapes project snapshot (not a full Grapes editor project file).
384
+ * Does not validate host-specific component registries unless `allowedComponentTypes` is passed.
385
+ */
386
+ declare function validateGrapesProjectSnapshot(snapshot: unknown, options?: ValidateGrapesProjectSnapshotOptions): ValidationResult;
387
+
388
+ export { type GrapesComponent, type GrapesProjectSnapshot, type GrapesStyleRule, type HtmlToGrapesOptions, MigrationAdapter, MigrationPlatform, SMUGMUG_API_BASE, SMUGMUG_OAUTH_ENDPOINTS, SQUARESPACE_JSON_FORMAT, SmugMugApiClient, type SmugMugClientOptions, type SmugMugCredentials, type SquarespaceClientOptions, type SquarespaceCollectTarget, SquarespaceCollectionClient, type ValidateGrapesProjectSnapshotOptions, ValidationResult, buildJsonPrettyUrl, buildSmugMugAuthorizationHeader, cssToStyles, getAdapter, grapesComponentSchema, grapesProjectSnapshotSchema, grapesStyleRuleSchema, htmlToGrapes, mapJsonPrettyWire, readSmugMugCredentialsFromEnv, signSmugMugOAuthRequest, smugMugCredentialsSchema, smugmugAdapter, squarespaceAdapter, validateGrapesProjectSnapshot, wordpressAdapter };
package/dist/index.js CHANGED
@@ -11,7 +11,24 @@ import {
11
11
  squarespaceAdapter,
12
12
  wordpressAdapter
13
13
  } from "./chunk-FXXKLYO5.js";
14
- import "./chunk-2RWAXT6O.js";
14
+ import {
15
+ normalizedAssetExifSchema,
16
+ normalizedAssetSchema,
17
+ normalizedCategorySchema,
18
+ normalizedEntitySchema,
19
+ normalizedPageSchema,
20
+ normalizedPortfolioSchema,
21
+ normalizedPostSchema,
22
+ normalizedTagSchema,
23
+ sourceMetadataSchema,
24
+ validateNormalizedAsset,
25
+ validateNormalizedCategory,
26
+ validateNormalizedEntity,
27
+ validateNormalizedPage,
28
+ validateNormalizedPortfolio,
29
+ validateNormalizedPost,
30
+ validateNormalizedTag
31
+ } from "./chunk-5QEF5O5T.js";
15
32
  import {
16
33
  FALLBACK_ASSET_BYTES,
17
34
  FilesystemMigrationSink,
@@ -327,6 +344,74 @@ function serializeContentHtml($) {
327
344
  const rootHtml = $.root().html()?.trim();
328
345
  return rootHtml || void 0;
329
346
  }
347
+
348
+ // src/transformers/validate-snapshot.ts
349
+ import { z } from "zod";
350
+ var grapesStyleRuleSchema = z.object({
351
+ selectors: z.array(z.string().min(1)).min(1),
352
+ style: z.record(z.string(), z.string())
353
+ });
354
+ var grapesComponentSchema = z.lazy(
355
+ () => z.object({
356
+ type: z.string().min(1),
357
+ tagName: z.string().optional(),
358
+ attributes: z.record(z.string(), z.string()).optional(),
359
+ classes: z.array(z.string()).optional(),
360
+ components: z.array(grapesComponentSchema).optional(),
361
+ content: z.string().optional(),
362
+ void: z.boolean().optional()
363
+ })
364
+ );
365
+ var grapesProjectSnapshotSchema = z.object({
366
+ content: z.array(grapesComponentSchema),
367
+ styles: z.array(grapesStyleRuleSchema),
368
+ contentHtml: z.string().optional(),
369
+ contentCss: z.string().optional()
370
+ });
371
+ function zodIssuesToValidationIssues(issues) {
372
+ return issues.map((issue) => ({
373
+ code: issue.code,
374
+ message: issue.message,
375
+ path: issue.path.length > 0 ? issue.path.join(".") : void 0
376
+ }));
377
+ }
378
+ function collectComponentTypes(components) {
379
+ const types = [];
380
+ for (const component of components) {
381
+ types.push(component.type);
382
+ if (component.components?.length) {
383
+ types.push(...collectComponentTypes(component.components));
384
+ }
385
+ }
386
+ return types;
387
+ }
388
+ function validateAllowedComponentTypes(snapshot, allowedComponentTypes) {
389
+ const allowlist = new Set(allowedComponentTypes);
390
+ const issues = [];
391
+ for (const componentType of collectComponentTypes(snapshot.content)) {
392
+ if (!allowlist.has(componentType)) {
393
+ issues.push({
394
+ code: "invalid_component_type",
395
+ message: `Component type "${componentType}" is not in allowedComponentTypes`,
396
+ path: "content"
397
+ });
398
+ }
399
+ }
400
+ return issues;
401
+ }
402
+ function validateGrapesProjectSnapshot(snapshot, options = {}) {
403
+ const result = grapesProjectSnapshotSchema.safeParse(snapshot);
404
+ if (!result.success) {
405
+ return { ok: false, issues: zodIssuesToValidationIssues(result.error.issues) };
406
+ }
407
+ if (options.allowedComponentTypes?.length) {
408
+ const typeIssues = validateAllowedComponentTypes(result.data, options.allowedComponentTypes);
409
+ if (typeIssues.length > 0) {
410
+ return { ok: false, issues: typeIssues };
411
+ }
412
+ }
413
+ return { ok: true, issues: [] };
414
+ }
330
415
  export {
331
416
  FALLBACK_ASSET_BYTES,
332
417
  FilesystemMigrationSink,
@@ -353,11 +438,22 @@ export {
353
438
  entityKey,
354
439
  estimateStorage,
355
440
  getAdapter,
441
+ grapesComponentSchema,
442
+ grapesProjectSnapshotSchema,
443
+ grapesStyleRuleSchema,
356
444
  hasBlockingConflicts,
357
445
  hasWarnings,
358
446
  htmlToGrapes,
359
447
  isTerminalState,
360
448
  mapJsonPrettyWire,
449
+ normalizedAssetExifSchema,
450
+ normalizedAssetSchema,
451
+ normalizedCategorySchema,
452
+ normalizedEntitySchema,
453
+ normalizedPageSchema,
454
+ normalizedPortfolioSchema,
455
+ normalizedPostSchema,
456
+ normalizedTagSchema,
361
457
  portfolioMediaMatchesBundle,
362
458
  readSmugMugCredentialsFromEnv,
363
459
  rewriteInlineImages,
@@ -368,8 +464,17 @@ export {
368
464
  signSmugMugOAuthRequest,
369
465
  smugMugCredentialsSchema,
370
466
  smugmugAdapter,
467
+ sourceMetadataSchema,
371
468
  squarespaceAdapter,
372
469
  staleUrlsFromEstimate,
470
+ validateGrapesProjectSnapshot,
471
+ validateNormalizedAsset,
472
+ validateNormalizedCategory,
473
+ validateNormalizedEntity,
474
+ validateNormalizedPage,
475
+ validateNormalizedPortfolio,
476
+ validateNormalizedPost,
477
+ validateNormalizedTag,
373
478
  wordpressAdapter,
374
479
  writeFilesystemExport
375
480
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transformers/html-to-grapes/index.ts","../src/transformers/css-to-styles/index.ts","../src/transformers/html-to-grapes/walk.ts"],"sourcesContent":["import * as cheerio from \"cheerio\";\n\nimport { cssToStyles } from \"../css-to-styles/index.js\";\nimport type { GrapesProjectSnapshot, HtmlToGrapesOptions } from \"./types.js\";\nimport { walkHtmlToComponents } from \"./walk.js\";\n\nexport type {\n GrapesComponent,\n GrapesProjectSnapshot,\n GrapesStyleRule,\n HtmlToGrapesOptions,\n} from \"./types.js\";\n\n/** Cheerio HTML walk → Grapes `content` + root `styles`. */\nexport function htmlToGrapes(html: string, options: HtmlToGrapesOptions = {}): GrapesProjectSnapshot {\n const trimmed = html.trim();\n if (!trimmed) {\n return { content: [], styles: [] };\n }\n\n const $ = cheerio.load(trimmed, { xml: false });\n const styleBlocks: string[] = [];\n\n $(\"style\").each((_, element) => {\n styleBlocks.push($(element).html() ?? \"\");\n $(element).remove();\n });\n\n const contentCss = styleBlocks.join(\"\\n\").trim();\n const styles = cssToStyles(contentCss);\n const content = walkHtmlToComponents($, options);\n const contentHtml = serializeContentHtml($);\n\n return {\n content,\n styles,\n ...(contentHtml ? { contentHtml } : {}),\n ...(contentCss ? { contentCss } : {}),\n };\n}\n\nfunction serializeContentHtml($: cheerio.CheerioAPI): string | undefined {\n const body = $(\"body\");\n if (body.length) {\n const html = body.html()?.trim();\n return html || undefined;\n }\n\n const rootHtml = $.root().html()?.trim();\n return rootHtml || undefined;\n}\n","import type { GrapesStyleRule } from \"../html-to-grapes/types.js\";\n\nfunction stripCssComments(css: string): string {\n return css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\");\n}\n\nfunction parseDeclarations(block: string): Record<string, string> {\n const style: Record<string, string> = {};\n for (const declaration of block.split(\";\")) {\n const trimmed = declaration.trim();\n if (!trimmed) continue;\n const separator = trimmed.indexOf(\":\");\n if (separator === -1) continue;\n const property = trimmed.slice(0, separator).trim();\n const value = trimmed.slice(separator + 1).trim();\n if (!property || !value) continue;\n style[property] = value;\n }\n return style;\n}\n\n/** Parse `<style>` blocks and class rules into Grapes root `styles[]`. */\nexport function cssToStyles(css: string): GrapesStyleRule[] {\n const cleaned = stripCssComments(css);\n const rules: GrapesStyleRule[] = [];\n const rulePattern = /([^{]+)\\{([^}]*)\\}/g;\n\n for (const match of cleaned.matchAll(rulePattern)) {\n const selectorText = match[1]?.trim() ?? \"\";\n const declarationBlock = match[2] ?? \"\";\n if (!selectorText || selectorText.startsWith(\"@\")) continue;\n\n const style = parseDeclarations(declarationBlock);\n if (Object.keys(style).length === 0) continue;\n\n const selectors = selectorText\n .split(\",\")\n .map((selector) => selector.trim())\n .filter(Boolean);\n\n if (selectors.length === 0) continue;\n rules.push({ selectors, style });\n }\n\n return rules;\n}\n","import type { Cheerio, CheerioAPI } from \"cheerio\";\nimport type { AnyNode } from \"domhandler\";\n\nimport type { GrapesComponent, HtmlToGrapesOptions } from \"./types.js\";\n\ntype CheerioSelection = Cheerio<AnyNode>;\n\nconst INLINE_TAGS = new Set([\n \"a\",\n \"abbr\",\n \"b\",\n \"br\",\n \"cite\",\n \"code\",\n \"del\",\n \"em\",\n \"i\",\n \"img\",\n \"ins\",\n \"mark\",\n \"q\",\n \"s\",\n \"small\",\n \"span\",\n \"strong\",\n \"sub\",\n \"sup\",\n \"u\",\n \"wbr\",\n]);\n\nconst VOID_TAGS = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"link\",\n \"meta\",\n \"param\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\nconst TEXT_CONTAINER_TAGS = new Set([\n \"blockquote\",\n \"figcaption\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"label\",\n \"li\",\n \"p\",\n \"pre\",\n \"td\",\n \"th\",\n]);\n\nconst SKIP_TAGS = new Set([\"script\", \"style\", \"noscript\", \"template\"]);\n\nconst DEFAULT_TYPES: Record<string, string> = {\n a: \"link\",\n img: \"image\",\n};\n\nfunction tagNameOf($el: CheerioSelection): string | undefined {\n const raw = $el.prop(\"tagName\");\n return typeof raw === \"string\" ? raw.toLowerCase() : undefined;\n}\n\nfunction applyElementMeta(\n component: GrapesComponent,\n meta: Pick<GrapesComponent, \"attributes\" | \"classes\">,\n): GrapesComponent {\n if (meta.attributes) component.attributes = meta.attributes;\n if (meta.classes) component.classes = meta.classes;\n return component;\n}\n\nfunction pickElementMeta($el: CheerioSelection): Pick<GrapesComponent, \"attributes\" | \"classes\"> {\n const attributes: Record<string, string> = {};\n const classes: string[] = [];\n\n if (typeof $el.attr() === \"object\") {\n for (const [key, value] of Object.entries($el.attr() ?? {})) {\n if (key === \"class\") {\n classes.push(...value.split(/\\s+/).filter(Boolean));\n continue;\n }\n attributes[key] = value;\n }\n }\n\n return {\n attributes: Object.keys(attributes).length > 0 ? attributes : undefined,\n classes: classes.length > 0 ? classes : undefined,\n };\n}\n\nfunction resolveComponentType(\n tagName: string,\n classes: string[] | undefined,\n options: HtmlToGrapesOptions,\n): string {\n if (options.componentMap && classes) {\n for (const className of classes) {\n const mapped = options.componentMap[className];\n if (mapped) return mapped;\n }\n }\n return DEFAULT_TYPES[tagName] ?? \"default\";\n}\n\nfunction hasOnlyInlineContent($: CheerioAPI, $el: CheerioSelection): boolean {\n let inlineOnly = true;\n\n $el.contents().each((_, node) => {\n if (!inlineOnly) return;\n const $child = $(node);\n if ($child.get(0)?.type === \"text\") return;\n const childTag = tagNameOf($child);\n if (!childTag || !INLINE_TAGS.has(childTag)) {\n inlineOnly = false;\n return;\n }\n if (!hasOnlyInlineContent($, $child)) {\n inlineOnly = false;\n }\n });\n\n return inlineOnly;\n}\n\nfunction walkChildren(\n $: CheerioAPI,\n $el: CheerioSelection,\n options: HtmlToGrapesOptions,\n): GrapesComponent[] {\n const components: GrapesComponent[] = [];\n\n $el.contents().each((_, node) => {\n const walked = walkNode($, $(node), options);\n if (!walked) return;\n if (Array.isArray(walked)) {\n components.push(...walked);\n } else {\n components.push(walked);\n }\n });\n\n return components;\n}\n\nfunction walkNode(\n $: CheerioAPI,\n $el: CheerioSelection,\n options: HtmlToGrapesOptions,\n): GrapesComponent | GrapesComponent[] | null {\n const node = $el.get(0);\n if (!node) return null;\n\n if (node.type === \"text\") {\n const text = \"data\" in node ? String(node.data ?? \"\") : \"\";\n if (!text.trim()) return null;\n return { type: \"textnode\", content: text };\n }\n\n if (node.type !== \"tag\") return null;\n\n const tagName = tagNameOf($el);\n if (!tagName || SKIP_TAGS.has(tagName)) return null;\n\n const meta = pickElementMeta($el);\n\n if (VOID_TAGS.has(tagName)) {\n return applyElementMeta(\n {\n type: resolveComponentType(tagName, meta.classes, options),\n tagName,\n void: true,\n },\n meta,\n );\n }\n\n if (TEXT_CONTAINER_TAGS.has(tagName) && hasOnlyInlineContent($, $el)) {\n return applyElementMeta(\n {\n type: \"text\",\n tagName,\n content: $el.html() ?? \"\",\n },\n meta,\n );\n }\n\n if (INLINE_TAGS.has(tagName)) {\n return applyElementMeta(\n {\n type: \"text\",\n content: $.html($el) ?? \"\",\n },\n meta,\n );\n }\n\n const components = walkChildren($, $el, options);\n const component = applyElementMeta(\n {\n type: resolveComponentType(tagName, meta.classes, options),\n tagName,\n },\n meta,\n );\n\n if (components.length > 0) {\n component.components = components;\n }\n\n return component;\n}\n\nfunction appendWalked(\n content: GrapesComponent[],\n walked: GrapesComponent | GrapesComponent[] | null,\n): void {\n if (!walked) return;\n if (Array.isArray(walked)) {\n content.push(...walked);\n return;\n }\n content.push(walked);\n}\n\nfunction walkNodes(\n $: CheerioAPI,\n $nodes: CheerioSelection,\n content: GrapesComponent[],\n options: HtmlToGrapesOptions,\n): void {\n $nodes.each((_, node) => {\n appendWalked(content, walkNode($, $(node), options));\n });\n}\n\nexport function walkHtmlToComponents(\n $: CheerioAPI,\n options: HtmlToGrapesOptions = {},\n): GrapesComponent[] {\n const content: GrapesComponent[] = [];\n const body = $(\"body\");\n\n if (body.length) {\n walkNodes($, body.contents(), content, options);\n return content;\n }\n\n const children = $.root().children();\n if (children.length) {\n walkNodes($, children, content, options);\n } else {\n walkNodes($, $.root().contents(), content, options);\n }\n\n return content;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,YAAY,aAAa;;;ACEzB,SAAS,iBAAiB,KAAqB;AAC7C,SAAO,IAAI,QAAQ,qBAAqB,EAAE;AAC5C;AAEA,SAAS,kBAAkB,OAAuC;AAChE,QAAM,QAAgC,CAAC;AACvC,aAAW,eAAe,MAAM,MAAM,GAAG,GAAG;AAC1C,UAAM,UAAU,YAAY,KAAK;AACjC,QAAI,CAAC,QAAS;AACd,UAAM,YAAY,QAAQ,QAAQ,GAAG;AACrC,QAAI,cAAc,GAAI;AACtB,UAAM,WAA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Y;AACrB;","names":[]}
1
+ {"version":3,"sources":["../src/transformers/html-to-grapes/index.ts","../src/transformers/css-to-styles/index.ts","../src/transformers/html-to-grapes/walk.ts","../src/transformers/validate-snapshot.ts"],"sourcesContent":["import * as cheerio from \"cheerio\";\n\nimport { cssToStyles } from \"../css-to-styles/index.js\";\nimport type { GrapesProjectSnapshot, HtmlToGrapesOptions } from \"./types.js\";\nimport { walkHtmlToComponents } from \"./walk.js\";\n\nexport type {\n GrapesComponent,\n GrapesProjectSnapshot,\n GrapesStyleRule,\n HtmlToGrapesOptions,\n} from \"./types.js\";\n\n/** Cheerio HTML walk → Grapes `content` + root `styles`. */\nexport function htmlToGrapes(html: string, options: HtmlToGrapesOptions = {}): GrapesProjectSnapshot {\n const trimmed = html.trim();\n if (!trimmed) {\n return { content: [], styles: [] };\n }\n\n const $ = cheerio.load(trimmed, { xml: false });\n const styleBlocks: string[] = [];\n\n $(\"style\").each((_, element) => {\n styleBlocks.push($(element).html() ?? \"\");\n $(element).remove();\n });\n\n const contentCss = styleBlocks.join(\"\\n\").trim();\n const styles = cssToStyles(contentCss);\n const content = walkHtmlToComponents($, options);\n const contentHtml = serializeContentHtml($);\n\n return {\n content,\n styles,\n ...(contentHtml ? { contentHtml } : {}),\n ...(contentCss ? { contentCss } : {}),\n };\n}\n\nfunction serializeContentHtml($: cheerio.CheerioAPI): string | undefined {\n const body = $(\"body\");\n if (body.length) {\n const html = body.html()?.trim();\n return html || undefined;\n }\n\n const rootHtml = $.root().html()?.trim();\n return rootHtml || undefined;\n}\n","import type { GrapesStyleRule } from \"../html-to-grapes/types.js\";\n\nfunction stripCssComments(css: string): string {\n return css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\");\n}\n\nfunction parseDeclarations(block: string): Record<string, string> {\n const style: Record<string, string> = {};\n for (const declaration of block.split(\";\")) {\n const trimmed = declaration.trim();\n if (!trimmed) continue;\n const separator = trimmed.indexOf(\":\");\n if (separator === -1) continue;\n const property = trimmed.slice(0, separator).trim();\n const value = trimmed.slice(separator + 1).trim();\n if (!property || !value) continue;\n style[property] = value;\n }\n return style;\n}\n\n/** Parse `<style>` blocks and class rules into Grapes root `styles[]`. */\nexport function cssToStyles(css: string): GrapesStyleRule[] {\n const cleaned = stripCssComments(css);\n const rules: GrapesStyleRule[] = [];\n const rulePattern = /([^{]+)\\{([^}]*)\\}/g;\n\n for (const match of cleaned.matchAll(rulePattern)) {\n const selectorText = match[1]?.trim() ?? \"\";\n const declarationBlock = match[2] ?? \"\";\n if (!selectorText || selectorText.startsWith(\"@\")) continue;\n\n const style = parseDeclarations(declarationBlock);\n if (Object.keys(style).length === 0) continue;\n\n const selectors = selectorText\n .split(\",\")\n .map((selector) => selector.trim())\n .filter(Boolean);\n\n if (selectors.length === 0) continue;\n rules.push({ selectors, style });\n }\n\n return rules;\n}\n","import type { Cheerio, CheerioAPI } from \"cheerio\";\nimport type { AnyNode } from \"domhandler\";\n\nimport type { GrapesComponent, HtmlToGrapesOptions } from \"./types.js\";\n\ntype CheerioSelection = Cheerio<AnyNode>;\n\nconst INLINE_TAGS = new Set([\n \"a\",\n \"abbr\",\n \"b\",\n \"br\",\n \"cite\",\n \"code\",\n \"del\",\n \"em\",\n \"i\",\n \"img\",\n \"ins\",\n \"mark\",\n \"q\",\n \"s\",\n \"small\",\n \"span\",\n \"strong\",\n \"sub\",\n \"sup\",\n \"u\",\n \"wbr\",\n]);\n\nconst VOID_TAGS = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"link\",\n \"meta\",\n \"param\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\nconst TEXT_CONTAINER_TAGS = new Set([\n \"blockquote\",\n \"figcaption\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"label\",\n \"li\",\n \"p\",\n \"pre\",\n \"td\",\n \"th\",\n]);\n\nconst SKIP_TAGS = new Set([\"script\", \"style\", \"noscript\", \"template\"]);\n\nconst DEFAULT_TYPES: Record<string, string> = {\n a: \"link\",\n img: \"image\",\n};\n\nfunction tagNameOf($el: CheerioSelection): string | undefined {\n const raw = $el.prop(\"tagName\");\n return typeof raw === \"string\" ? raw.toLowerCase() : undefined;\n}\n\nfunction applyElementMeta(\n component: GrapesComponent,\n meta: Pick<GrapesComponent, \"attributes\" | \"classes\">,\n): GrapesComponent {\n if (meta.attributes) component.attributes = meta.attributes;\n if (meta.classes) component.classes = meta.classes;\n return component;\n}\n\nfunction pickElementMeta($el: CheerioSelection): Pick<GrapesComponent, \"attributes\" | \"classes\"> {\n const attributes: Record<string, string> = {};\n const classes: string[] = [];\n\n if (typeof $el.attr() === \"object\") {\n for (const [key, value] of Object.entries($el.attr() ?? {})) {\n if (key === \"class\") {\n classes.push(...value.split(/\\s+/).filter(Boolean));\n continue;\n }\n attributes[key] = value;\n }\n }\n\n return {\n attributes: Object.keys(attributes).length > 0 ? attributes : undefined,\n classes: classes.length > 0 ? classes : undefined,\n };\n}\n\nfunction resolveComponentType(\n tagName: string,\n classes: string[] | undefined,\n options: HtmlToGrapesOptions,\n): string {\n if (options.componentMap && classes) {\n for (const className of classes) {\n const mapped = options.componentMap[className];\n if (mapped) return mapped;\n }\n }\n return DEFAULT_TYPES[tagName] ?? \"default\";\n}\n\nfunction hasOnlyInlineContent($: CheerioAPI, $el: CheerioSelection): boolean {\n let inlineOnly = true;\n\n $el.contents().each((_, node) => {\n if (!inlineOnly) return;\n const $child = $(node);\n if ($child.get(0)?.type === \"text\") return;\n const childTag = tagNameOf($child);\n if (!childTag || !INLINE_TAGS.has(childTag)) {\n inlineOnly = false;\n return;\n }\n if (!hasOnlyInlineContent($, $child)) {\n inlineOnly = false;\n }\n });\n\n return inlineOnly;\n}\n\nfunction walkChildren(\n $: CheerioAPI,\n $el: CheerioSelection,\n options: HtmlToGrapesOptions,\n): GrapesComponent[] {\n const components: GrapesComponent[] = [];\n\n $el.contents().each((_, node) => {\n const walked = walkNode($, $(node), options);\n if (!walked) return;\n if (Array.isArray(walked)) {\n components.push(...walked);\n } else {\n components.push(walked);\n }\n });\n\n return components;\n}\n\nfunction walkNode(\n $: CheerioAPI,\n $el: CheerioSelection,\n options: HtmlToGrapesOptions,\n): GrapesComponent | GrapesComponent[] | null {\n const node = $el.get(0);\n if (!node) return null;\n\n if (node.type === \"text\") {\n const text = \"data\" in node ? String(node.data ?? \"\") : \"\";\n if (!text.trim()) return null;\n return { type: \"textnode\", content: text };\n }\n\n if (node.type !== \"tag\") return null;\n\n const tagName = tagNameOf($el);\n if (!tagName || SKIP_TAGS.has(tagName)) return null;\n\n const meta = pickElementMeta($el);\n\n if (VOID_TAGS.has(tagName)) {\n return applyElementMeta(\n {\n type: resolveComponentType(tagName, meta.classes, options),\n tagName,\n void: true,\n },\n meta,\n );\n }\n\n if (TEXT_CONTAINER_TAGS.has(tagName) && hasOnlyInlineContent($, $el)) {\n return applyElementMeta(\n {\n type: \"text\",\n tagName,\n content: $el.html() ?? \"\",\n },\n meta,\n );\n }\n\n if (INLINE_TAGS.has(tagName)) {\n return applyElementMeta(\n {\n type: \"text\",\n content: $.html($el) ?? \"\",\n },\n meta,\n );\n }\n\n const components = walkChildren($, $el, options);\n const component = applyElementMeta(\n {\n type: resolveComponentType(tagName, meta.classes, options),\n tagName,\n },\n meta,\n );\n\n if (components.length > 0) {\n component.components = components;\n }\n\n return component;\n}\n\nfunction appendWalked(\n content: GrapesComponent[],\n walked: GrapesComponent | GrapesComponent[] | null,\n): void {\n if (!walked) return;\n if (Array.isArray(walked)) {\n content.push(...walked);\n return;\n }\n content.push(walked);\n}\n\nfunction walkNodes(\n $: CheerioAPI,\n $nodes: CheerioSelection,\n content: GrapesComponent[],\n options: HtmlToGrapesOptions,\n): void {\n $nodes.each((_, node) => {\n appendWalked(content, walkNode($, $(node), options));\n });\n}\n\nexport function walkHtmlToComponents(\n $: CheerioAPI,\n options: HtmlToGrapesOptions = {},\n): GrapesComponent[] {\n const content: GrapesComponent[] = [];\n const body = $(\"body\");\n\n if (body.length) {\n walkNodes($, body.contents(), content, options);\n return content;\n }\n\n const children = $.root().children();\n if (children.length) {\n walkNodes($, children, content, options);\n } else {\n walkNodes($, $.root().contents(), content, options);\n }\n\n return content;\n}\n","import { z } from \"zod\";\n\nimport type { ValidationIssue, ValidationResult } from \"../normalizer/types.js\";\nimport type { GrapesComponent, GrapesProjectSnapshot } from \"./html-to-grapes/types.js\";\n\nexport const grapesStyleRuleSchema = z.object({\n selectors: z.array(z.string().min(1)).min(1),\n style: z.record(z.string(), z.string()),\n});\n\nexport const grapesComponentSchema: z.ZodType<GrapesComponent> = z.lazy(() =>\n z.object({\n type: z.string().min(1),\n tagName: z.string().optional(),\n attributes: z.record(z.string(), z.string()).optional(),\n classes: z.array(z.string()).optional(),\n components: z.array(grapesComponentSchema).optional(),\n content: z.string().optional(),\n void: z.boolean().optional(),\n }),\n);\n\nexport const grapesProjectSnapshotSchema = z.object({\n content: z.array(grapesComponentSchema),\n styles: z.array(grapesStyleRuleSchema),\n contentHtml: z.string().optional(),\n contentCss: z.string().optional(),\n});\n\nexport interface ValidateGrapesProjectSnapshotOptions {\n /** When set, every component `type` in the tree must be in this allowlist. */\n allowedComponentTypes?: string[];\n}\n\nfunction zodIssuesToValidationIssues(issues: z.ZodIssue[]): ValidationIssue[] {\n return issues.map((issue) => ({\n code: issue.code,\n message: issue.message,\n path: issue.path.length > 0 ? issue.path.join(\".\") : undefined,\n }));\n}\n\nfunction collectComponentTypes(components: GrapesComponent[]): string[] {\n const types: string[] = [];\n for (const component of components) {\n types.push(component.type);\n if (component.components?.length) {\n types.push(...collectComponentTypes(component.components));\n }\n }\n return types;\n}\n\nfunction validateAllowedComponentTypes(\n snapshot: GrapesProjectSnapshot,\n allowedComponentTypes: string[],\n): ValidationIssue[] {\n const allowlist = new Set(allowedComponentTypes);\n const issues: ValidationIssue[] = [];\n\n for (const componentType of collectComponentTypes(snapshot.content)) {\n if (!allowlist.has(componentType)) {\n issues.push({\n code: \"invalid_component_type\",\n message: `Component type \"${componentType}\" is not in allowedComponentTypes`,\n path: \"content\",\n });\n }\n }\n\n return issues;\n}\n\n/**\n * Opt-in structural check for a Grapes project snapshot (not a full Grapes editor project file).\n * Does not validate host-specific component registries unless `allowedComponentTypes` is passed.\n */\nexport function validateGrapesProjectSnapshot(\n snapshot: unknown,\n options: ValidateGrapesProjectSnapshotOptions = {},\n): ValidationResult {\n const result = grapesProjectSnapshotSchema.safeParse(snapshot);\n if (!result.success) {\n return { ok: false, issues: zodIssuesToValidationIssues(result.error.issues) };\n }\n\n if (options.allowedComponentTypes?.length) {\n const typeIssues = validateAllowedComponentTypes(result.data, options.allowedComponentTypes);\n if (typeIssues.length > 0) {\n return { ok: false, issues: typeIssues };\n }\n }\n\n return { ok: true, issues: [] };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,YAAY,aAAa;;;ACEzB,SAAS,iBAAiB,KAAqB;AAC7C,SAAO,IAAI,QAAQ,qBAAqB,EAAE;AAC5C;AAEA,SAAS,kBAAkB,OAAuC;AAChE,QAAM,QAAgC,CAAC;AACvC,aAAW,eAAe,MAAM,MAAM,GAAG,GAAG;AAC1C,UAAM,UAAU,YAAY,KAAK;AACjC,QAAI,CAAC,QAAS;AACd,UAAM,YAAY,QAAQ,QAAQ,GAAG;AACrC,QAAI,cAAc,GAAI;AACtB,UAAM,WAAW,QAAQ,MAAM,GAAG,SAAS,EAAE,KAAK;AAClD,UAAM,QAAQ,QAAQ,MAAM,YAAY,CAAC,EAAE,KAAK;AAChD,QAAI,CAAC,YAAY,CAAC,MAAO;AACzB,UAAM,QAAQ,IAAI;AAAA,EACpB;AACA,SAAO;AACT;AAGO,SAAS,YAAY,KAAgC;AAC1D,QAAM,UAAU,iBAAiB,GAAG;AACpC,QAAM,QAA2B,CAAC;AAClC,QAAM,cAAc;AAEpB,aAAW,SAAS,QAAQ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