@prenta/import 0.5.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.
- package/CHANGELOG.md +686 -0
- package/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/adapter.d.ts +47 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +60 -0
- package/dist/adapter.js.map +1 -0
- package/dist/adapters/contentful/asset.d.ts +47 -0
- package/dist/adapters/contentful/asset.d.ts.map +1 -0
- package/dist/adapters/contentful/asset.js +88 -0
- package/dist/adapters/contentful/asset.js.map +1 -0
- package/dist/adapters/contentful/index.d.ts +24 -0
- package/dist/adapters/contentful/index.d.ts.map +1 -0
- package/dist/adapters/contentful/index.js +242 -0
- package/dist/adapters/contentful/index.js.map +1 -0
- package/dist/adapters/contentful/locale.d.ts +66 -0
- package/dist/adapters/contentful/locale.d.ts.map +1 -0
- package/dist/adapters/contentful/locale.js +125 -0
- package/dist/adapters/contentful/locale.js.map +1 -0
- package/dist/adapters/contentful/map.d.ts +69 -0
- package/dist/adapters/contentful/map.d.ts.map +1 -0
- package/dist/adapters/contentful/map.js +174 -0
- package/dist/adapters/contentful/map.js.map +1 -0
- package/dist/adapters/contentful/rich-text.d.ts +52 -0
- package/dist/adapters/contentful/rich-text.d.ts.map +1 -0
- package/dist/adapters/contentful/rich-text.js +95 -0
- package/dist/adapters/contentful/rich-text.js.map +1 -0
- package/dist/adapters/contentful/types.d.ts +189 -0
- package/dist/adapters/contentful/types.d.ts.map +1 -0
- package/dist/adapters/contentful/types.js +26 -0
- package/dist/adapters/contentful/types.js.map +1 -0
- package/dist/adapters/identity.d.ts +27 -0
- package/dist/adapters/identity.d.ts.map +1 -0
- package/dist/adapters/identity.js +116 -0
- package/dist/adapters/identity.js.map +1 -0
- package/dist/adapters/sanity/asset.d.ts +45 -0
- package/dist/adapters/sanity/asset.d.ts.map +1 -0
- package/dist/adapters/sanity/asset.js +79 -0
- package/dist/adapters/sanity/asset.js.map +1 -0
- package/dist/adapters/sanity/index.d.ts +19 -0
- package/dist/adapters/sanity/index.d.ts.map +1 -0
- package/dist/adapters/sanity/index.js +165 -0
- package/dist/adapters/sanity/index.js.map +1 -0
- package/dist/adapters/sanity/map.d.ts +75 -0
- package/dist/adapters/sanity/map.d.ts.map +1 -0
- package/dist/adapters/sanity/map.js +245 -0
- package/dist/adapters/sanity/map.js.map +1 -0
- package/dist/adapters/sanity/parse.d.ts +64 -0
- package/dist/adapters/sanity/parse.d.ts.map +1 -0
- package/dist/adapters/sanity/parse.js +71 -0
- package/dist/adapters/sanity/parse.js.map +1 -0
- package/dist/adapters/sanity/portable-text.d.ts +64 -0
- package/dist/adapters/sanity/portable-text.d.ts.map +1 -0
- package/dist/adapters/sanity/portable-text.js +112 -0
- package/dist/adapters/sanity/portable-text.js.map +1 -0
- package/dist/adapters/sanity/types.d.ts +182 -0
- package/dist/adapters/sanity/types.d.ts.map +1 -0
- package/dist/adapters/sanity/types.js +17 -0
- package/dist/adapters/sanity/types.js.map +1 -0
- package/dist/adapters/strapi/asset.d.ts +56 -0
- package/dist/adapters/strapi/asset.d.ts.map +1 -0
- package/dist/adapters/strapi/asset.js +94 -0
- package/dist/adapters/strapi/asset.js.map +1 -0
- package/dist/adapters/strapi/index.d.ts +20 -0
- package/dist/adapters/strapi/index.d.ts.map +1 -0
- package/dist/adapters/strapi/index.js +205 -0
- package/dist/adapters/strapi/index.js.map +1 -0
- package/dist/adapters/strapi/links.d.ts +79 -0
- package/dist/adapters/strapi/links.d.ts.map +1 -0
- package/dist/adapters/strapi/links.js +98 -0
- package/dist/adapters/strapi/links.js.map +1 -0
- package/dist/adapters/strapi/loader.d.ts +68 -0
- package/dist/adapters/strapi/loader.d.ts.map +1 -0
- package/dist/adapters/strapi/loader.js +177 -0
- package/dist/adapters/strapi/loader.js.map +1 -0
- package/dist/adapters/strapi/map.d.ts +53 -0
- package/dist/adapters/strapi/map.d.ts.map +1 -0
- package/dist/adapters/strapi/map.js +193 -0
- package/dist/adapters/strapi/map.js.map +1 -0
- package/dist/adapters/strapi/types.d.ts +174 -0
- package/dist/adapters/strapi/types.d.ts.map +1 -0
- package/dist/adapters/strapi/types.js +31 -0
- package/dist/adapters/strapi/types.js.map +1 -0
- package/dist/adapters/strapi/uid.d.ts +44 -0
- package/dist/adapters/strapi/uid.d.ts.map +1 -0
- package/dist/adapters/strapi/uid.js +58 -0
- package/dist/adapters/strapi/uid.js.map +1 -0
- package/dist/adapters/wordpress/attachments.d.ts +37 -0
- package/dist/adapters/wordpress/attachments.d.ts.map +1 -0
- package/dist/adapters/wordpress/attachments.js +134 -0
- package/dist/adapters/wordpress/attachments.js.map +1 -0
- package/dist/adapters/wordpress/authors.d.ts +24 -0
- package/dist/adapters/wordpress/authors.d.ts.map +1 -0
- package/dist/adapters/wordpress/authors.js +40 -0
- package/dist/adapters/wordpress/authors.js.map +1 -0
- package/dist/adapters/wordpress/index.d.ts +19 -0
- package/dist/adapters/wordpress/index.d.ts.map +1 -0
- package/dist/adapters/wordpress/index.js +281 -0
- package/dist/adapters/wordpress/index.js.map +1 -0
- package/dist/adapters/wordpress/map.d.ts +61 -0
- package/dist/adapters/wordpress/map.d.ts.map +1 -0
- package/dist/adapters/wordpress/map.js +265 -0
- package/dist/adapters/wordpress/map.js.map +1 -0
- package/dist/adapters/wordpress/parse.d.ts +50 -0
- package/dist/adapters/wordpress/parse.d.ts.map +1 -0
- package/dist/adapters/wordpress/parse.js +141 -0
- package/dist/adapters/wordpress/parse.js.map +1 -0
- package/dist/adapters/wordpress/terms.d.ts +46 -0
- package/dist/adapters/wordpress/terms.d.ts.map +1 -0
- package/dist/adapters/wordpress/terms.js +87 -0
- package/dist/adapters/wordpress/terms.js.map +1 -0
- package/dist/adapters/wordpress/types.d.ts +201 -0
- package/dist/adapters/wordpress/types.d.ts.map +1 -0
- package/dist/adapters/wordpress/types.js +24 -0
- package/dist/adapters/wordpress/types.js.map +1 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +266 -0
- package/dist/cli.js.map +1 -0
- package/dist/formatter.d.ts +12 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +48 -0
- package/dist/formatter.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/migrate.d.ts +151 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +255 -0
- package/dist/migrate.js.map +1 -0
- package/dist/registry.d.ts +39 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +62 -0
- package/dist/registry.js.map +1 -0
- package/dist/runner.d.ts +33 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +61 -0
- package/dist/runner.js.map +1 -0
- package/dist/types.d.ts +173 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the structural shapes the Contentful adapter
|
|
3
|
+
* recognizes in a `contentful-export` JSON dump.
|
|
4
|
+
*
|
|
5
|
+
* Contentful exports are a single JSON document with top-level
|
|
6
|
+
* arrays for content types, entries, assets, locales, etc. The
|
|
7
|
+
* shapes here cover only what the adapter actually inspects —
|
|
8
|
+
* everything else passes through `unknown`.
|
|
9
|
+
*
|
|
10
|
+
* Key differences from Sanity that drive the design:
|
|
11
|
+
*
|
|
12
|
+
* - **Single JSON document**, not NDJSON. The whole file parses
|
|
13
|
+
* in one go, so the parser is just `JSON.parse` with a defensive
|
|
14
|
+
* structural check.
|
|
15
|
+
* - **Every field is locale-wrapped:** `{ title: { 'en-US': 'x' } }`.
|
|
16
|
+
* The adapter unwraps to the primary locale by default; an `all`
|
|
17
|
+
* strategy preserves the locale map for downstream
|
|
18
|
+
* multi-language tooling.
|
|
19
|
+
* - **Links are first-class system objects** —
|
|
20
|
+
* `{ sys: { type: 'Link', linkType: 'Entry'|'Asset', id } }`.
|
|
21
|
+
* Same resolution model as Sanity references.
|
|
22
|
+
* - **Assets carry URLs** directly in the export — no
|
|
23
|
+
* `projectId`/`dataset` config required.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* The system block every Contentful object (entry, asset, content
|
|
27
|
+
* type) has. The adapter only needs the bits used for
|
|
28
|
+
* identification, link resolution, and publish-state filtering.
|
|
29
|
+
*/
|
|
30
|
+
export interface ContentfulSys {
|
|
31
|
+
id: string;
|
|
32
|
+
type: 'Entry' | 'Asset' | 'ContentType' | 'Link' | string;
|
|
33
|
+
/** Set when the entity has a published version (i.e. it's live). */
|
|
34
|
+
publishedVersion?: number;
|
|
35
|
+
/** Set on links — `'Entry'` or `'Asset'`. */
|
|
36
|
+
linkType?: 'Entry' | 'Asset' | string;
|
|
37
|
+
/** Set on entries — points at the content type. */
|
|
38
|
+
contentType?: {
|
|
39
|
+
sys: {
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
createdAt?: string;
|
|
44
|
+
updatedAt?: string;
|
|
45
|
+
publishedAt?: string;
|
|
46
|
+
locale?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A single entry from the export's top-level `entries` array.
|
|
50
|
+
* `fields` is a record of locale-wrapped values. We don't enforce
|
|
51
|
+
* the locale-wrapping at the type level because some hand-edited
|
|
52
|
+
* exports omit it for single-locale projects; the field mapper
|
|
53
|
+
* handles both shapes.
|
|
54
|
+
*/
|
|
55
|
+
export interface ContentfulEntry {
|
|
56
|
+
sys: ContentfulSys;
|
|
57
|
+
fields: Record<string, unknown>;
|
|
58
|
+
metadata?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Asset entries carry an inner `file` field with `url`,
|
|
62
|
+
* `contentType`, dimensions, etc. Locale-wrapped same as entries.
|
|
63
|
+
*/
|
|
64
|
+
export interface ContentfulAsset {
|
|
65
|
+
sys: ContentfulSys;
|
|
66
|
+
fields: {
|
|
67
|
+
title?: Record<string, string>;
|
|
68
|
+
description?: Record<string, string>;
|
|
69
|
+
file?: Record<string, ContentfulAssetFile>;
|
|
70
|
+
};
|
|
71
|
+
metadata?: Record<string, unknown>;
|
|
72
|
+
}
|
|
73
|
+
export interface ContentfulAssetFile {
|
|
74
|
+
url?: string;
|
|
75
|
+
fileName?: string;
|
|
76
|
+
contentType?: string;
|
|
77
|
+
details?: {
|
|
78
|
+
size?: number;
|
|
79
|
+
image?: {
|
|
80
|
+
width?: number;
|
|
81
|
+
height?: number;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
upload?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The link shape Contentful uses for every cross-document
|
|
88
|
+
* reference. Both entry-to-entry and entry-to-asset use the same
|
|
89
|
+
* envelope; `sys.linkType` discriminates.
|
|
90
|
+
*/
|
|
91
|
+
export interface ContentfulLink {
|
|
92
|
+
sys: {
|
|
93
|
+
type: 'Link';
|
|
94
|
+
linkType: 'Entry' | 'Asset';
|
|
95
|
+
id: string;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Contentful's Rich Text format. Tree of nodes; `nodeType:
|
|
100
|
+
* 'document'` at the root, paragraphs/headings/lists below,
|
|
101
|
+
* `nodeType: 'text'` leaves with marks. Embedded entries and
|
|
102
|
+
* inline links live in their own `nodeType` variants
|
|
103
|
+
* (`embedded-entry-block`, `embedded-asset-block`, `entry-hyperlink`,
|
|
104
|
+
* `asset-hyperlink`).
|
|
105
|
+
*/
|
|
106
|
+
export interface RichTextDocument {
|
|
107
|
+
nodeType: 'document';
|
|
108
|
+
data: Record<string, unknown>;
|
|
109
|
+
content: RichTextNode[];
|
|
110
|
+
}
|
|
111
|
+
export interface RichTextNode {
|
|
112
|
+
nodeType: string;
|
|
113
|
+
data?: Record<string, unknown>;
|
|
114
|
+
content?: RichTextNode[];
|
|
115
|
+
value?: string;
|
|
116
|
+
marks?: Array<{
|
|
117
|
+
type: string;
|
|
118
|
+
}>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Top-level shape of a `contentful-export` JSON file. Everything
|
|
122
|
+
* outside `entries`, `assets`, and `locales` is preserved as
|
|
123
|
+
* `unknown` because the adapter doesn't touch it.
|
|
124
|
+
*/
|
|
125
|
+
export interface ContentfulExport {
|
|
126
|
+
entries?: ContentfulEntry[];
|
|
127
|
+
assets?: ContentfulAsset[];
|
|
128
|
+
locales?: ContentfulLocale[];
|
|
129
|
+
contentTypes?: unknown[];
|
|
130
|
+
[key: string]: unknown;
|
|
131
|
+
}
|
|
132
|
+
export interface ContentfulLocale {
|
|
133
|
+
code: string;
|
|
134
|
+
name?: string;
|
|
135
|
+
default?: boolean;
|
|
136
|
+
fallbackCode?: string | null;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Per-import config. Loaded via
|
|
140
|
+
* `prenta-import contentful ./export.json --config ./contentful.json`.
|
|
141
|
+
*/
|
|
142
|
+
export interface ContentfulAdapterConfig {
|
|
143
|
+
/**
|
|
144
|
+
* Contentful contentType id → Prenta collection slug. Untyped:
|
|
145
|
+
* unmapped types fall back to the contentType id silently.
|
|
146
|
+
* Typed: unmapped types fall back AND warn.
|
|
147
|
+
*/
|
|
148
|
+
typeMap?: Record<string, string>;
|
|
149
|
+
/**
|
|
150
|
+
* Locale to lift to top-level when `localeStrategy: 'primary-only'`.
|
|
151
|
+
* If omitted, the adapter uses the locale marked `default: true`
|
|
152
|
+
* in the export, falling back to the first locale, falling back
|
|
153
|
+
* to `'en-US'`.
|
|
154
|
+
*/
|
|
155
|
+
primaryLocale?: string;
|
|
156
|
+
/**
|
|
157
|
+
* How to handle locale-wrapped field values:
|
|
158
|
+
* - `primary-only` (default) — unwrap to the primary locale; the
|
|
159
|
+
* document is a single-language record.
|
|
160
|
+
* - `all` — preserve the `{ [locale]: value }` map verbatim.
|
|
161
|
+
* - `primary-with-fallback` — like `primary-only`, but if the
|
|
162
|
+
* primary locale value is missing, fall back through the
|
|
163
|
+
* locale's `fallbackCode` chain.
|
|
164
|
+
*/
|
|
165
|
+
localeStrategy?: 'primary-only' | 'all' | 'primary-with-fallback';
|
|
166
|
+
/**
|
|
167
|
+
* Skip entries that don't have `sys.publishedVersion`. Default
|
|
168
|
+
* `true` — most migrations want only the live content.
|
|
169
|
+
*/
|
|
170
|
+
publishedOnly?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Preserve `sys.*` on `data` when `true`. Default `false` —
|
|
173
|
+
* `sourceId` / `sourceType` already carry the bits operators
|
|
174
|
+
* usually want.
|
|
175
|
+
*/
|
|
176
|
+
includeSystemFields?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* When `true`, emit assets as Prenta documents in their own
|
|
179
|
+
* `assets` collection (configurable via `assetCollection`). When
|
|
180
|
+
* `false` (default), assets are consumed only for URL-map
|
|
181
|
+
* building and never become Prenta documents.
|
|
182
|
+
*/
|
|
183
|
+
importAssets?: boolean;
|
|
184
|
+
/** Collection slug for asset documents when `importAssets: true`. */
|
|
185
|
+
assetCollection?: string;
|
|
186
|
+
/** Additional contentType ids to skip entirely. */
|
|
187
|
+
ignoreTypes?: string[];
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/contentful/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,aAAa,GAAG,MAAM,GAAG,MAAM,CAAA;IACzD,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO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AAa,CAAC,EAAE,MAAM,CAAA;IACtB;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,cAAc,GAAG,KAAK,GAAG,uBAAuB,CAAA;IACjE;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,qEAAqE;IACrE,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the structural shapes the Contentful adapter
|
|
3
|
+
* recognizes in a `contentful-export` JSON dump.
|
|
4
|
+
*
|
|
5
|
+
* Contentful exports are a single JSON document with top-level
|
|
6
|
+
* arrays for content types, entries, assets, locales, etc. The
|
|
7
|
+
* shapes here cover only what the adapter actually inspects —
|
|
8
|
+
* everything else passes through `unknown`.
|
|
9
|
+
*
|
|
10
|
+
* Key differences from Sanity that drive the design:
|
|
11
|
+
*
|
|
12
|
+
* - **Single JSON document**, not NDJSON. The whole file parses
|
|
13
|
+
* in one go, so the parser is just `JSON.parse` with a defensive
|
|
14
|
+
* structural check.
|
|
15
|
+
* - **Every field is locale-wrapped:** `{ title: { 'en-US': 'x' } }`.
|
|
16
|
+
* The adapter unwraps to the primary locale by default; an `all`
|
|
17
|
+
* strategy preserves the locale map for downstream
|
|
18
|
+
* multi-language tooling.
|
|
19
|
+
* - **Links are first-class system objects** —
|
|
20
|
+
* `{ sys: { type: 'Link', linkType: 'Entry'|'Asset', id } }`.
|
|
21
|
+
* Same resolution model as Sanity references.
|
|
22
|
+
* - **Assets carry URLs** directly in the export — no
|
|
23
|
+
* `projectId`/`dataset` config required.
|
|
24
|
+
*/
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/adapters/contentful/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `identity` — the trivial adapter that reads
|
|
3
|
+
* already-Prenta-shaped JSON and emits it unchanged after a
|
|
4
|
+
* structural validation pass.
|
|
5
|
+
*
|
|
6
|
+
* Three roles this adapter plays:
|
|
7
|
+
*
|
|
8
|
+
* 1. **Pipeline reference.** It's the minimal "adapter that
|
|
9
|
+
* compiles" — useful when someone is implementing a new adapter
|
|
10
|
+
* and wants a known-good shape to compare against.
|
|
11
|
+
* 2. **Validation gate.** Operators with a hand-curated migration
|
|
12
|
+
* JSON can run `prenta-import identity ./content.json` to confirm
|
|
13
|
+
* every document satisfies the {@link ImportedDocument} contract
|
|
14
|
+
* before committing the file or piping it to the Prenta API.
|
|
15
|
+
* 3. **Test harness.** The framework's CLI integration tests use
|
|
16
|
+
* this adapter to verify routing, write behaviour, and exit codes
|
|
17
|
+
* without coupling to a heavier adapter implementation.
|
|
18
|
+
*
|
|
19
|
+
* Accepts a JSON file containing either a single document, an array
|
|
20
|
+
* of documents, or `{ documents: [...] }` (the same shape the CLI
|
|
21
|
+
* emits with `--write`). Surfaces malformed documents as
|
|
22
|
+
* {@link UnresolvedField} entries rather than silently dropping
|
|
23
|
+
* them — operators can fix the file and re-run.
|
|
24
|
+
*/
|
|
25
|
+
import type { ImportAdapter } from '../types.js';
|
|
26
|
+
export declare const identityAdapter: ImportAdapter;
|
|
27
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/adapters/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,OAAO,KAAK,EAEV,aAAa,EAId,MAAM,aAAa,CAAA;AAEpB,eAAO,MAAM,eAAe,EAAE,aAoE7B,CAAA"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `identity` — the trivial adapter that reads
|
|
3
|
+
* already-Prenta-shaped JSON and emits it unchanged after a
|
|
4
|
+
* structural validation pass.
|
|
5
|
+
*
|
|
6
|
+
* Three roles this adapter plays:
|
|
7
|
+
*
|
|
8
|
+
* 1. **Pipeline reference.** It's the minimal "adapter that
|
|
9
|
+
* compiles" — useful when someone is implementing a new adapter
|
|
10
|
+
* and wants a known-good shape to compare against.
|
|
11
|
+
* 2. **Validation gate.** Operators with a hand-curated migration
|
|
12
|
+
* JSON can run `prenta-import identity ./content.json` to confirm
|
|
13
|
+
* every document satisfies the {@link ImportedDocument} contract
|
|
14
|
+
* before committing the file or piping it to the Prenta API.
|
|
15
|
+
* 3. **Test harness.** The framework's CLI integration tests use
|
|
16
|
+
* this adapter to verify routing, write behaviour, and exit codes
|
|
17
|
+
* without coupling to a heavier adapter implementation.
|
|
18
|
+
*
|
|
19
|
+
* Accepts a JSON file containing either a single document, an array
|
|
20
|
+
* of documents, or `{ documents: [...] }` (the same shape the CLI
|
|
21
|
+
* emits with `--write`). Surfaces malformed documents as
|
|
22
|
+
* {@link UnresolvedField} entries rather than silently dropping
|
|
23
|
+
* them — operators can fix the file and re-run.
|
|
24
|
+
*/
|
|
25
|
+
import { readFileSync } from 'node:fs';
|
|
26
|
+
import { buildResult, isImportedDocument } from '../adapter.js';
|
|
27
|
+
export const identityAdapter = {
|
|
28
|
+
name: 'identity',
|
|
29
|
+
description: 'Read Prenta-shaped JSON and emit it unchanged (validation only).',
|
|
30
|
+
docsUrl: 'https://github.com/actuate-media/prenta/blob/main/docs/import.md#identity-adapter',
|
|
31
|
+
run(options) {
|
|
32
|
+
const raw = readFileSync(options.input, 'utf-8');
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = JSON.parse(raw);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
// Surface as a single unresolved-field instead of crashing — the
|
|
39
|
+
// CLI then exits 2 and the operator can fix the JSON without
|
|
40
|
+
// reading a stack trace.
|
|
41
|
+
const issue = {
|
|
42
|
+
source: { field: '<root>' },
|
|
43
|
+
code: 'invalid-json',
|
|
44
|
+
reason: `Input file is not valid JSON: ${err.message}`,
|
|
45
|
+
hint: 'Ensure the file contains a JSON document, array, or { documents: [...] } envelope.',
|
|
46
|
+
};
|
|
47
|
+
return buildResult({
|
|
48
|
+
adapter: identityAdapter.name,
|
|
49
|
+
documents: [],
|
|
50
|
+
unresolved: [issue],
|
|
51
|
+
totals: { totalRead: 0, converted: 0, skipped: 0 },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const inputDocs = unwrapDocuments(parsed);
|
|
55
|
+
const documents = [];
|
|
56
|
+
const unresolved = [];
|
|
57
|
+
let skipped = 0;
|
|
58
|
+
for (let i = 0; i < inputDocs.length; i++) {
|
|
59
|
+
const doc = inputDocs[i];
|
|
60
|
+
if (options.shouldInclude) {
|
|
61
|
+
const synthSource = isImportedDocument(doc)
|
|
62
|
+
? { type: doc.sourceType, id: doc.sourceId ?? String(i) }
|
|
63
|
+
: { id: String(i) };
|
|
64
|
+
if (!options.shouldInclude(synthSource)) {
|
|
65
|
+
skipped++;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!isImportedDocument(doc)) {
|
|
70
|
+
unresolved.push({
|
|
71
|
+
source: { id: String(i), field: '<document>' },
|
|
72
|
+
code: 'invalid-shape',
|
|
73
|
+
reason: `Item at index ${i} does not match ImportedDocument shape.`,
|
|
74
|
+
rawValue: doc,
|
|
75
|
+
hint: 'Required: collection (string), data (object). Optional: slug, sourceId, sourceType (string).',
|
|
76
|
+
});
|
|
77
|
+
skipped++;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
documents.push(doc);
|
|
81
|
+
}
|
|
82
|
+
return buildResult({
|
|
83
|
+
adapter: identityAdapter.name,
|
|
84
|
+
documents,
|
|
85
|
+
unresolved,
|
|
86
|
+
totals: {
|
|
87
|
+
totalRead: inputDocs.length,
|
|
88
|
+
converted: documents.length,
|
|
89
|
+
skipped,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Accept the three shapes the CLI's `--write` output can take so the
|
|
96
|
+
* identity adapter doubles as a "validate the CLI's output" tool:
|
|
97
|
+
*
|
|
98
|
+
* - `ImportedDocument` (single)
|
|
99
|
+
* - `ImportedDocument[]`
|
|
100
|
+
* - `{ documents: ImportedDocument[] }` (the `--write` envelope)
|
|
101
|
+
*
|
|
102
|
+
* Anything else is returned as a single-element array so the
|
|
103
|
+
* validation pass can flag it as `invalid-shape` per-document instead
|
|
104
|
+
* of crashing.
|
|
105
|
+
*/
|
|
106
|
+
function unwrapDocuments(parsed) {
|
|
107
|
+
if (Array.isArray(parsed))
|
|
108
|
+
return parsed;
|
|
109
|
+
if (parsed !== null && typeof parsed === 'object') {
|
|
110
|
+
const envelope = parsed.documents;
|
|
111
|
+
if (Array.isArray(envelope))
|
|
112
|
+
return envelope;
|
|
113
|
+
}
|
|
114
|
+
return [parsed];
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/adapters/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAS/D,MAAM,CAAC,MAAM,eAAe,GAAkB;IAC5C,IAAI,EAAE,UAAU;IAChB,WAAW,EAAE,kEAAkE;IAC/E,OAAO,EAAE,mFAAmF;IAC5F,GAAG,CAAC,OAAuB;QAC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CAAC,MAAM,CAAC,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanity asset URL construction.
|
|
3
|
+
*
|
|
4
|
+
* Sanity image asset references encode everything you need to
|
|
5
|
+
* resolve the asset URL right in the ref string:
|
|
6
|
+
*
|
|
7
|
+
* image-<id>-<width>x<height>-<ext>
|
|
8
|
+
*
|
|
9
|
+
* For example:
|
|
10
|
+
* image-Tb9Ew8CXIwaY6R1kjMvI0uRR-3024x4032-jpg
|
|
11
|
+
*
|
|
12
|
+
* gets turned into:
|
|
13
|
+
* https://cdn.sanity.io/images/<projectId>/<dataset>/Tb9Ew8CXIwaY6R1kjMvI0uRR-3024x4032.jpg
|
|
14
|
+
*
|
|
15
|
+
* Files use the same shape with `file-` prefix and no dimensions.
|
|
16
|
+
*
|
|
17
|
+
* The adapter prefers an explicit `assetBaseUrl` over
|
|
18
|
+
* `projectId`+`dataset` so projects that serve assets through a
|
|
19
|
+
* custom domain don't have to compose the CDN URL by hand.
|
|
20
|
+
*/
|
|
21
|
+
import type { SanityAdapterConfig } from './types.js';
|
|
22
|
+
export interface ParsedAssetRef {
|
|
23
|
+
kind: 'image' | 'file';
|
|
24
|
+
id: string;
|
|
25
|
+
/** Width in pixels (images only). */
|
|
26
|
+
width?: number;
|
|
27
|
+
/** Height in pixels (images only). */
|
|
28
|
+
height?: number;
|
|
29
|
+
extension: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Decode an asset ref string into its components. Returns `null`
|
|
33
|
+
* for refs that don't match the expected shape — the field mapper
|
|
34
|
+
* surfaces those as unresolved fields with a fix-it hint, rather
|
|
35
|
+
* than guessing what the malformed ref points at.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseAssetRef(ref: string): ParsedAssetRef | null;
|
|
38
|
+
/**
|
|
39
|
+
* Build the asset URL for a parsed ref. Returns `null` when the
|
|
40
|
+
* config doesn't carry enough info to construct one — the adapter
|
|
41
|
+
* then warns and preserves the raw ref so the operator can decide
|
|
42
|
+
* whether to ingest the assets out of band or add config.
|
|
43
|
+
*/
|
|
44
|
+
export declare function assetUrlFrom(parsed: ParsedAssetRef, config: Pick<SanityAdapterConfig, 'assetBaseUrl' | 'projectId' | 'dataset'>): string | null;
|
|
45
|
+
//# sourceMappingURL=asset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../../src/adapters/sanity/asset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,GAAG,MAAM,CAAA;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB;AAKD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAoBhE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,GAAG,WAAW,GAAG,SAAS,CAAC,GAC1E,MAAM,GAAG,IAAI,CA0Bf"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanity asset URL construction.
|
|
3
|
+
*
|
|
4
|
+
* Sanity image asset references encode everything you need to
|
|
5
|
+
* resolve the asset URL right in the ref string:
|
|
6
|
+
*
|
|
7
|
+
* image-<id>-<width>x<height>-<ext>
|
|
8
|
+
*
|
|
9
|
+
* For example:
|
|
10
|
+
* image-Tb9Ew8CXIwaY6R1kjMvI0uRR-3024x4032-jpg
|
|
11
|
+
*
|
|
12
|
+
* gets turned into:
|
|
13
|
+
* https://cdn.sanity.io/images/<projectId>/<dataset>/Tb9Ew8CXIwaY6R1kjMvI0uRR-3024x4032.jpg
|
|
14
|
+
*
|
|
15
|
+
* Files use the same shape with `file-` prefix and no dimensions.
|
|
16
|
+
*
|
|
17
|
+
* The adapter prefers an explicit `assetBaseUrl` over
|
|
18
|
+
* `projectId`+`dataset` so projects that serve assets through a
|
|
19
|
+
* custom domain don't have to compose the CDN URL by hand.
|
|
20
|
+
*/
|
|
21
|
+
const IMAGE_REF = /^image-([a-zA-Z0-9]+)-(\d+)x(\d+)-([a-zA-Z0-9]+)$/;
|
|
22
|
+
const FILE_REF = /^file-([a-zA-Z0-9_]+)-([a-zA-Z0-9]+)$/;
|
|
23
|
+
/**
|
|
24
|
+
* Decode an asset ref string into its components. Returns `null`
|
|
25
|
+
* for refs that don't match the expected shape — the field mapper
|
|
26
|
+
* surfaces those as unresolved fields with a fix-it hint, rather
|
|
27
|
+
* than guessing what the malformed ref points at.
|
|
28
|
+
*/
|
|
29
|
+
export function parseAssetRef(ref) {
|
|
30
|
+
const img = IMAGE_REF.exec(ref);
|
|
31
|
+
if (img) {
|
|
32
|
+
return {
|
|
33
|
+
kind: 'image',
|
|
34
|
+
id: img[1],
|
|
35
|
+
width: Number(img[2]),
|
|
36
|
+
height: Number(img[3]),
|
|
37
|
+
extension: img[4],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const file = FILE_REF.exec(ref);
|
|
41
|
+
if (file) {
|
|
42
|
+
return {
|
|
43
|
+
kind: 'file',
|
|
44
|
+
id: file[1],
|
|
45
|
+
extension: file[2],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build the asset URL for a parsed ref. Returns `null` when the
|
|
52
|
+
* config doesn't carry enough info to construct one — the adapter
|
|
53
|
+
* then warns and preserves the raw ref so the operator can decide
|
|
54
|
+
* whether to ingest the assets out of band or add config.
|
|
55
|
+
*/
|
|
56
|
+
export function assetUrlFrom(parsed, config) {
|
|
57
|
+
const filename = parsed.kind === 'image' && parsed.width && parsed.height
|
|
58
|
+
? `${parsed.id}-${parsed.width}x${parsed.height}.${parsed.extension}`
|
|
59
|
+
: `${parsed.id}.${parsed.extension}`;
|
|
60
|
+
// `assetBaseUrl`, when set, is treated as the full base including
|
|
61
|
+
// any `/images/...` or `/files/...` segment the operator wants —
|
|
62
|
+
// we just append the filename. That keeps custom-domain projects
|
|
63
|
+
// simple (they can hand-craft their full base URL).
|
|
64
|
+
if (config.assetBaseUrl) {
|
|
65
|
+
const trimmed = config.assetBaseUrl.endsWith('/')
|
|
66
|
+
? config.assetBaseUrl.slice(0, -1)
|
|
67
|
+
: config.assetBaseUrl;
|
|
68
|
+
return `${trimmed}/${filename}`;
|
|
69
|
+
}
|
|
70
|
+
// Canonical Sanity CDN shape:
|
|
71
|
+
// https://cdn.sanity.io/<images|files>/<projectId>/<dataset>/<filename>
|
|
72
|
+
if (config.projectId) {
|
|
73
|
+
const dataset = config.dataset ?? 'production';
|
|
74
|
+
const folder = parsed.kind === 'image' ? 'images' : 'files';
|
|
75
|
+
return `https://cdn.sanity.io/${folder}/${config.projectId}/${dataset}/${filename}`;
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=asset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.js","sourceRoot":"","sources":["../../../src/adapters/sanity/asset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAcH,MAAM,SAAS,GAAG,mDAAmD,CAAA;AACrE,MAAM,QAAQ,GAAG,uCAAuC,CAAA;AAExD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC/B,IAAI,GAAG,EAAE,CAAC;QAC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Q,EAAE,CAAA;IACjC,CAAC;IAED,8BAA8B;IAC9B,0EAA0E;IAC1E,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,YAAY,CAAA;QAC9C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAA;QAC3D,OAAO,yBAAyB,MAAM,IAAI,MAAM,CAAC,SAAS,IAAI,OAAO,IAAI,QAAQ,EAAE,CAAA;IACrF,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sanity` — adapter for Sanity dataset NDJSON exports.
|
|
3
|
+
*
|
|
4
|
+
* Reads the output of `sanity dataset export <name> <file.tar.gz>`
|
|
5
|
+
* (the NDJSON `data.ndjson` inside the archive) and produces
|
|
6
|
+
* Prenta-shaped `ImportedDocument`s. Asset binaries inside the
|
|
7
|
+
* `.tar.gz` aren't read by this adapter — the operator either
|
|
8
|
+
* uploads them separately or configures asset URL resolution via
|
|
9
|
+
* `projectId` + `dataset` / `assetBaseUrl`.
|
|
10
|
+
*
|
|
11
|
+
* Two-pass: the adapter walks the records once to build the
|
|
12
|
+
* resolution context (doc id → target collection, asset id → URL),
|
|
13
|
+
* then walks again invoking `mapDocument` per-record. That order
|
|
14
|
+
* means in-export references can resolve in either direction
|
|
15
|
+
* regardless of how the records are arranged in the file.
|
|
16
|
+
*/
|
|
17
|
+
import type { ImportAdapter } from '../../types.js';
|
|
18
|
+
export declare const sanityAdapter: ImportAdapter;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/sanity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,EAEV,aAAa,EAKd,MAAM,gBAAgB,CAAA;AAQvB,eAAO,MAAM,aAAa,EAAE,aAiH3B,CAAA"}
|