@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,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable Text helpers for the Sanity adapter.
|
|
3
|
+
*
|
|
4
|
+
* Portable Text is Sanity's structured rich-text format: an array of
|
|
5
|
+
* "blocks" (paragraphs / headings / list items), each containing
|
|
6
|
+
* "spans" of text with marks. Custom block types are common — image
|
|
7
|
+
* blocks, callouts, embedded references — so the detector errs on
|
|
8
|
+
* the side of "is this an array where every entry is a typed
|
|
9
|
+
* object?" rather than requiring `_type: 'block'` everywhere.
|
|
10
|
+
*
|
|
11
|
+
* Phase 6 PR #2 keeps Portable Text content lossless: we pass the
|
|
12
|
+
* array through to `data` unchanged so Prenta can store it as JSON
|
|
13
|
+
* and consumers can render with `@portabletext/to-html`,
|
|
14
|
+
* `@portabletext/react`, etc. The integrity walker surfaces broken
|
|
15
|
+
* markDef references and unresolved internal references as warnings.
|
|
16
|
+
*/
|
|
17
|
+
import type { SanityReference } from './types.js';
|
|
18
|
+
/**
|
|
19
|
+
* Lightweight structural detector — returns true when `value` looks
|
|
20
|
+
* like a Portable Text array (or an array of custom blocks like
|
|
21
|
+
* inline images). Pure structural inspection, no Sanity-schema
|
|
22
|
+
* knowledge required.
|
|
23
|
+
*
|
|
24
|
+
* Rules:
|
|
25
|
+
* - Must be a non-empty array.
|
|
26
|
+
* - Every item must be a plain object with a string `_type` field.
|
|
27
|
+
* - At least one item must look like a real text block
|
|
28
|
+
* (`_type === 'block'` with `children` array) so we don't
|
|
29
|
+
* misidentify e.g. a `references[]` array as Portable Text.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isPortableTextArray(value: unknown): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* A reference found inside Portable Text (either a markDef link, an
|
|
34
|
+
* inline reference block, or an embedded image's asset ref).
|
|
35
|
+
* Adapters resolve these against the set of imported documents +
|
|
36
|
+
* known assets to decide whether to emit a warning.
|
|
37
|
+
*/
|
|
38
|
+
export interface PortableTextRefHit {
|
|
39
|
+
/** Path-ish string for diagnostics, e.g. `body[3].markDefs[0]`. */
|
|
40
|
+
path: string;
|
|
41
|
+
/** Inline reference target document id. */
|
|
42
|
+
ref: string;
|
|
43
|
+
/** Whether the reference is marked `_weak`. */
|
|
44
|
+
weak: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Walk the Portable Text array and collect every `{ _type:
|
|
48
|
+
* 'reference', _ref }` it contains. Used to surface broken refs the
|
|
49
|
+
* same way top-level reference fields are.
|
|
50
|
+
*
|
|
51
|
+
* We don't try to be exhaustive about every conceivable custom
|
|
52
|
+
* block shape — just hit the common cases: markDefs (link
|
|
53
|
+
* annotations), inline reference blocks, and image-block asset
|
|
54
|
+
* refs. Custom blocks the adapter doesn't recognize get a
|
|
55
|
+
* warning at the adapter level, not here.
|
|
56
|
+
*/
|
|
57
|
+
export declare function collectReferences(blocks: readonly unknown[], basePath: string): PortableTextRefHit[];
|
|
58
|
+
/**
|
|
59
|
+
* Light-weight `value is SanityReference` guard used by the walker
|
|
60
|
+
* + the field mapper. Lives here (rather than in `types.ts`) so the
|
|
61
|
+
* non-runtime types module stays free of executable code.
|
|
62
|
+
*/
|
|
63
|
+
export declare function isReference(value: unknown): value is SanityReference;
|
|
64
|
+
//# sourceMappingURL=portable-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portable-text.d.ts","sourceRoot":"","sources":["../../../src/adapters/sanity/portable-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAe3D;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAA;IACZ,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAA;IACX,+CAA+C;IAC/C,IAAI,EAAE,OAAO,CAAA;CACd;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,OAAO,EAAE,EAC1B,QAAQ,EAAE,MAAM,GACf,kBAAkB,EAAE,CA4CtB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAIpE"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable Text helpers for the Sanity adapter.
|
|
3
|
+
*
|
|
4
|
+
* Portable Text is Sanity's structured rich-text format: an array of
|
|
5
|
+
* "blocks" (paragraphs / headings / list items), each containing
|
|
6
|
+
* "spans" of text with marks. Custom block types are common — image
|
|
7
|
+
* blocks, callouts, embedded references — so the detector errs on
|
|
8
|
+
* the side of "is this an array where every entry is a typed
|
|
9
|
+
* object?" rather than requiring `_type: 'block'` everywhere.
|
|
10
|
+
*
|
|
11
|
+
* Phase 6 PR #2 keeps Portable Text content lossless: we pass the
|
|
12
|
+
* array through to `data` unchanged so Prenta can store it as JSON
|
|
13
|
+
* and consumers can render with `@portabletext/to-html`,
|
|
14
|
+
* `@portabletext/react`, etc. The integrity walker surfaces broken
|
|
15
|
+
* markDef references and unresolved internal references as warnings.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Lightweight structural detector — returns true when `value` looks
|
|
19
|
+
* like a Portable Text array (or an array of custom blocks like
|
|
20
|
+
* inline images). Pure structural inspection, no Sanity-schema
|
|
21
|
+
* knowledge required.
|
|
22
|
+
*
|
|
23
|
+
* Rules:
|
|
24
|
+
* - Must be a non-empty array.
|
|
25
|
+
* - Every item must be a plain object with a string `_type` field.
|
|
26
|
+
* - At least one item must look like a real text block
|
|
27
|
+
* (`_type === 'block'` with `children` array) so we don't
|
|
28
|
+
* misidentify e.g. a `references[]` array as Portable Text.
|
|
29
|
+
*/
|
|
30
|
+
export function isPortableTextArray(value) {
|
|
31
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
32
|
+
return false;
|
|
33
|
+
let sawBlock = false;
|
|
34
|
+
for (const entry of value) {
|
|
35
|
+
if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const t = entry._type;
|
|
39
|
+
if (typeof t !== 'string')
|
|
40
|
+
return false;
|
|
41
|
+
if (t === 'block') {
|
|
42
|
+
const children = entry.children;
|
|
43
|
+
if (Array.isArray(children))
|
|
44
|
+
sawBlock = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return sawBlock;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Walk the Portable Text array and collect every `{ _type:
|
|
51
|
+
* 'reference', _ref }` it contains. Used to surface broken refs the
|
|
52
|
+
* same way top-level reference fields are.
|
|
53
|
+
*
|
|
54
|
+
* We don't try to be exhaustive about every conceivable custom
|
|
55
|
+
* block shape — just hit the common cases: markDefs (link
|
|
56
|
+
* annotations), inline reference blocks, and image-block asset
|
|
57
|
+
* refs. Custom blocks the adapter doesn't recognize get a
|
|
58
|
+
* warning at the adapter level, not here.
|
|
59
|
+
*/
|
|
60
|
+
export function collectReferences(blocks, basePath) {
|
|
61
|
+
const hits = [];
|
|
62
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
63
|
+
const block = blocks[i];
|
|
64
|
+
if (block === null || typeof block !== 'object' || Array.isArray(block))
|
|
65
|
+
continue;
|
|
66
|
+
const path = `${basePath}[${i}]`;
|
|
67
|
+
// Use an untyped record view — Sanity Portable Text blocks are
|
|
68
|
+
// structurally either `_type: 'block'` (text), `_type:
|
|
69
|
+
// 'reference'`, or a custom embedded type. Narrowing through
|
|
70
|
+
// `PortableTextBlock` here causes TS to reduce the
|
|
71
|
+
// `isReference` branch to `never`.
|
|
72
|
+
const b = block;
|
|
73
|
+
if (b._type === 'block' && Array.isArray(b.markDefs)) {
|
|
74
|
+
for (let j = 0; j < b.markDefs.length; j++) {
|
|
75
|
+
const def = b.markDefs[j];
|
|
76
|
+
if (def && typeof def === 'object') {
|
|
77
|
+
const candidate = def.reference;
|
|
78
|
+
if (isReference(candidate)) {
|
|
79
|
+
hits.push({
|
|
80
|
+
path: `${path}.markDefs[${j}].reference`,
|
|
81
|
+
ref: candidate._ref,
|
|
82
|
+
weak: candidate._weak === true,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Inline reference block — `{ _type: 'reference', _ref: '...' }`
|
|
89
|
+
// appearing at top level of a Portable Text array.
|
|
90
|
+
if (isReference(b)) {
|
|
91
|
+
hits.push({ path, ref: b._ref, weak: b._weak === true });
|
|
92
|
+
}
|
|
93
|
+
// Embedded image block — `{ _type: 'image', asset: { _ref: '...' } }`.
|
|
94
|
+
const asset = b.asset;
|
|
95
|
+
if (isReference(asset)) {
|
|
96
|
+
hits.push({ path: `${path}.asset`, ref: asset._ref, weak: asset._weak === true });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return hits;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Light-weight `value is SanityReference` guard used by the walker
|
|
103
|
+
* + the field mapper. Lives here (rather than in `types.ts`) so the
|
|
104
|
+
* non-runtime types module stays free of executable code.
|
|
105
|
+
*/
|
|
106
|
+
export function isReference(value) {
|
|
107
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
108
|
+
return false;
|
|
109
|
+
const v = value;
|
|
110
|
+
return v._type === 'reference' && typeof v._ref === 'string';
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=portable-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portable-text.js","sourceRoot":"","sources":["../../../src/adapters/sanity/portable-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAC7D,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACxE,OAAO,KAAK,CAAA;QACd,CAAC;QACD,MAAM,CAAC,GAAI,KAA6B,CAAC,KAAK,CAAA;QAC9C,IAAI,OAAO,CAAC,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAA;QACvC,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC;YAClB,MAAM,QAAQ,GAAI,KAAgC,CAAC,QAAQ,CAAA;YAC3D,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;gBAAE,QAAQ,GAAG,I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AAS,CAAC,KAAK,KAAK,IAAI;yBAC/B,CAAC,CAAA;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,iEAAiE;QACjE,mDAAmD;QACnD,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC,CAAA;QAC1D,CAAC;QAED,uEAAuE;QACvE,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAA;QACrB,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC,CAAA;QACnF,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrF,MAAM,CAAC,GAAG,KAAgC,CAAA;IAC1C,OAAO,CAAC,CAAC,KAAK,KAAK,WAAW,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAA;AAC9D,CAAC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the structural shapes the Sanity adapter
|
|
3
|
+
* recognizes in a Sanity dataset export (NDJSON).
|
|
4
|
+
*
|
|
5
|
+
* These are deliberately narrow — we type only the bits the adapter
|
|
6
|
+
* actually inspects (system fields, well-known type markers like
|
|
7
|
+
* slug / reference / image, and Portable Text blocks). Everything
|
|
8
|
+
* else stays as `unknown` so the field mapper passes it through
|
|
9
|
+
* unchanged.
|
|
10
|
+
*
|
|
11
|
+
* Sanity's own SDK doesn't publish a stable shape for export records
|
|
12
|
+
* (the export format is documented but versioned implicitly), so we
|
|
13
|
+
* lean on structural duck-typing in the parser rather than trying
|
|
14
|
+
* to model the whole Sanity schema language.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The minimum every Sanity document has after `sanity dataset export`.
|
|
18
|
+
* `_rev` and the timestamps aren't always present (e.g. on certain
|
|
19
|
+
* system docs or partial fixtures) so they're optional.
|
|
20
|
+
*/
|
|
21
|
+
export interface SanityDoc {
|
|
22
|
+
_id: string;
|
|
23
|
+
_type: string;
|
|
24
|
+
_createdAt?: string;
|
|
25
|
+
_updatedAt?: string;
|
|
26
|
+
_rev?: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
/** `{ _type: 'slug', current: 'my-page' }` */
|
|
30
|
+
export interface SanitySlug {
|
|
31
|
+
_type: 'slug';
|
|
32
|
+
current: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `{ _type: 'reference', _ref: 'doc-id' }` — points at another
|
|
36
|
+
* document. `_weak: true` means "don't validate the target exists",
|
|
37
|
+
* `_strengthenOnPublish` is a draft-mode flag we ignore.
|
|
38
|
+
*/
|
|
39
|
+
export interface SanityReference {
|
|
40
|
+
_type: 'reference';
|
|
41
|
+
_ref: string;
|
|
42
|
+
_weak?: boolean;
|
|
43
|
+
_strengthenOnPublish?: unknown;
|
|
44
|
+
_key?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* `{ _type: 'image', asset: { _ref: 'image-...-1200x800-jpg' }, ... }`
|
|
48
|
+
* — the inline `image` value embedded in a document. The asset ref
|
|
49
|
+
* is a separate `sanity.imageAsset` document in the export, but the
|
|
50
|
+
* dimensions / extension are encoded in the ref itself so we can
|
|
51
|
+
* surface them without resolving the asset record.
|
|
52
|
+
*/
|
|
53
|
+
export interface SanityImage {
|
|
54
|
+
_type: 'image';
|
|
55
|
+
asset?: SanityReference;
|
|
56
|
+
alt?: string;
|
|
57
|
+
hotspot?: unknown;
|
|
58
|
+
crop?: unknown;
|
|
59
|
+
_key?: string;
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
}
|
|
62
|
+
/** `{ _type: 'file', asset: { _ref: 'file-...-pdf' } }` */
|
|
63
|
+
export interface SanityFile {
|
|
64
|
+
_type: 'file';
|
|
65
|
+
asset?: SanityReference;
|
|
66
|
+
_key?: string;
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Portable Text block. The Sanity Portable Text schema is open-ended
|
|
71
|
+
* (custom blocks can extend `_type`), but every "real" text block has
|
|
72
|
+
* `_type === 'block'`, an array of `children` (spans), and an
|
|
73
|
+
* optional `markDefs` array describing inline annotations
|
|
74
|
+
* (links, etc.).
|
|
75
|
+
*/
|
|
76
|
+
export interface PortableTextBlock {
|
|
77
|
+
_type: 'block';
|
|
78
|
+
_key?: string;
|
|
79
|
+
children: PortableTextSpan[];
|
|
80
|
+
markDefs?: PortableTextMarkDef[];
|
|
81
|
+
style?: string;
|
|
82
|
+
listItem?: string;
|
|
83
|
+
level?: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A run of text inside a Portable Text block. `marks` are either
|
|
87
|
+
* primitive style keys (`'strong'`, `'em'`) or `_key` references
|
|
88
|
+
* into the parent block's `markDefs`.
|
|
89
|
+
*/
|
|
90
|
+
export interface PortableTextSpan {
|
|
91
|
+
_type: 'span';
|
|
92
|
+
_key?: string;
|
|
93
|
+
text: string;
|
|
94
|
+
marks?: string[];
|
|
95
|
+
}
|
|
96
|
+
/** An entry in `markDefs` — e.g. a link annotation. */
|
|
97
|
+
export interface PortableTextMarkDef {
|
|
98
|
+
_key: string;
|
|
99
|
+
_type: string;
|
|
100
|
+
[key: string]: unknown;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The asset documents Sanity emits alongside content (`_type:
|
|
104
|
+
* 'sanity.imageAsset'`, `'sanity.fileAsset'`). We don't import these
|
|
105
|
+
* as Prenta documents — they're skipped by default — but we
|
|
106
|
+
* remember their URLs (when present) so inline image/file refs can
|
|
107
|
+
* surface a resolved URL in `data`.
|
|
108
|
+
*/
|
|
109
|
+
export interface SanityImageAssetDoc extends SanityDoc {
|
|
110
|
+
_type: 'sanity.imageAsset';
|
|
111
|
+
url?: string;
|
|
112
|
+
path?: string;
|
|
113
|
+
assetId?: string;
|
|
114
|
+
extension?: string;
|
|
115
|
+
mimeType?: string;
|
|
116
|
+
metadata?: {
|
|
117
|
+
dimensions?: {
|
|
118
|
+
width?: number;
|
|
119
|
+
height?: number;
|
|
120
|
+
aspectRatio?: number;
|
|
121
|
+
};
|
|
122
|
+
[key: string]: unknown;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export interface SanityFileAssetDoc extends SanityDoc {
|
|
126
|
+
_type: 'sanity.fileAsset';
|
|
127
|
+
url?: string;
|
|
128
|
+
path?: string;
|
|
129
|
+
assetId?: string;
|
|
130
|
+
extension?: string;
|
|
131
|
+
mimeType?: string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Free-form per-import config the operator can supply via
|
|
135
|
+
* `prenta-import sanity ./export.ndjson --config sanity.json`.
|
|
136
|
+
*/
|
|
137
|
+
export interface SanityAdapterConfig {
|
|
138
|
+
/**
|
|
139
|
+
* Sanity `_type` → Prenta `collection`. Documents whose `_type`
|
|
140
|
+
* isn't in the map fall back to using `_type` as the collection
|
|
141
|
+
* slug (and a warning fires so the operator can decide whether to
|
|
142
|
+
* extend the map).
|
|
143
|
+
*/
|
|
144
|
+
typeMap?: Record<string, string>;
|
|
145
|
+
/**
|
|
146
|
+
* When `true` (default), documents whose `_id` starts with
|
|
147
|
+
* `drafts.` are skipped. Set to `false` to import drafts as
|
|
148
|
+
* regular documents — typically only useful for one-off migrations
|
|
149
|
+
* of a Sanity dataset that intentionally publishes drafts.
|
|
150
|
+
*/
|
|
151
|
+
dropDrafts?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* When `true`, the system fields (`_id`, `_type`, `_createdAt`,
|
|
154
|
+
* `_updatedAt`, `_rev`) are preserved on `data` in addition to
|
|
155
|
+
* being lifted into `sourceId`/`sourceType`. Default `false`.
|
|
156
|
+
*/
|
|
157
|
+
includeSystemFields?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Sanity project ID. Combined with `dataset` and the asset id
|
|
160
|
+
* encoded in image refs, this lets the adapter produce CDN URLs
|
|
161
|
+
* for inline images without needing the exported `*.tar.gz`
|
|
162
|
+
* blobs.
|
|
163
|
+
*/
|
|
164
|
+
projectId?: string;
|
|
165
|
+
/** Sanity dataset name (default `production`). */
|
|
166
|
+
dataset?: string;
|
|
167
|
+
/**
|
|
168
|
+
* Explicit override for the asset CDN host. Use this when the
|
|
169
|
+
* project serves through a custom domain. Wins over
|
|
170
|
+
* `projectId` + `dataset` if set.
|
|
171
|
+
*/
|
|
172
|
+
assetBaseUrl?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Sanity `_type` strings to skip entirely — neither imported nor
|
|
175
|
+
* counted as `unknown`. Defaults to the system asset types
|
|
176
|
+
* (`sanity.imageAsset`, `sanity.fileAsset`, `sanity.imageMetadata`)
|
|
177
|
+
* — those are handled out-of-band as URL providers, not imported
|
|
178
|
+
* as their own documents.
|
|
179
|
+
*/
|
|
180
|
+
ignoreTypes?: string[];
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/sanity/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE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,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the structural shapes the Sanity adapter
|
|
3
|
+
* recognizes in a Sanity dataset export (NDJSON).
|
|
4
|
+
*
|
|
5
|
+
* These are deliberately narrow — we type only the bits the adapter
|
|
6
|
+
* actually inspects (system fields, well-known type markers like
|
|
7
|
+
* slug / reference / image, and Portable Text blocks). Everything
|
|
8
|
+
* else stays as `unknown` so the field mapper passes it through
|
|
9
|
+
* unchanged.
|
|
10
|
+
*
|
|
11
|
+
* Sanity's own SDK doesn't publish a stable shape for export records
|
|
12
|
+
* (the export format is documented but versioned implicitly), so we
|
|
13
|
+
* lean on structural duck-typing in the parser rather than trying
|
|
14
|
+
* to model the whole Sanity schema language.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/adapters/sanity/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset URL resolution for the Strapi adapter.
|
|
3
|
+
*
|
|
4
|
+
* Strapi exports media in two places:
|
|
5
|
+
*
|
|
6
|
+
* - **Inline on entity data.** Single-media fields have the
|
|
7
|
+
* media object embedded directly (`{ id, url, mime, ... }`);
|
|
8
|
+
* multi-media fields hold an array of such objects.
|
|
9
|
+
* - **In `assets/metadata.jsonl`.** A separate manifest of
|
|
10
|
+
* every asset in the project, useful for entities that
|
|
11
|
+
* reference media by id only (rare for v4/v5, common for
|
|
12
|
+
* legacy v3 exports).
|
|
13
|
+
*
|
|
14
|
+
* The adapter builds an `AssetEntry` map from the metadata file
|
|
15
|
+
* once, then the field mapper consults it whenever an inline
|
|
16
|
+
* media object is missing fields the manifest can fill in.
|
|
17
|
+
*
|
|
18
|
+
* URL handling matches the Contentful adapter: relative URLs
|
|
19
|
+
* (`/uploads/foo.jpg`) get prefixed with `mediaBaseUrl` if the
|
|
20
|
+
* operator provided one; absolute and protocol-relative URLs pass
|
|
21
|
+
* through.
|
|
22
|
+
*/
|
|
23
|
+
import type { StrapiAssetRecord, StrapiMedia } from './types.js';
|
|
24
|
+
export interface AssetEntry {
|
|
25
|
+
url: string;
|
|
26
|
+
fileName?: string;
|
|
27
|
+
contentType?: string;
|
|
28
|
+
size?: number;
|
|
29
|
+
width?: number;
|
|
30
|
+
height?: number;
|
|
31
|
+
alternativeText?: string;
|
|
32
|
+
caption?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build a `{ assetId → AssetEntry }` map from the export's
|
|
36
|
+
* `assets/metadata.jsonl`. Asset ids are normalized to strings
|
|
37
|
+
* because Strapi uses numeric ids and Prenta references stringify
|
|
38
|
+
* everything.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildAssetMap(assets: readonly StrapiAssetRecord[] | undefined, options?: {
|
|
41
|
+
mediaBaseUrl?: string;
|
|
42
|
+
}): Map<string, AssetEntry>;
|
|
43
|
+
/**
|
|
44
|
+
* Lift inline media objects to a normalized AssetEntry. Used by
|
|
45
|
+
* the field mapper for single-media and multi-media fields.
|
|
46
|
+
*/
|
|
47
|
+
export declare function liftInlineMedia(media: StrapiMedia, options?: {
|
|
48
|
+
mediaBaseUrl?: string;
|
|
49
|
+
}): AssetEntry;
|
|
50
|
+
/**
|
|
51
|
+
* Detect whether `value` looks like a Strapi media object. We
|
|
52
|
+
* require `id` plus at least one media-specific field so plain
|
|
53
|
+
* `{ id: 1 }` relation stubs don't get mistaken for media.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isStrapiMedia(value: unknown): value is StrapiMedia;
|
|
56
|
+
//# sourceMappingURL=asset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../../src/adapters/strapi/asset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEhE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,SAAS,iBAAiB,EAAE,GAAG,SAAS,EAChD,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAO,GACtC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CASzB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAO,GACtC,UAAU,CAEZ;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAUlE"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset URL resolution for the Strapi adapter.
|
|
3
|
+
*
|
|
4
|
+
* Strapi exports media in two places:
|
|
5
|
+
*
|
|
6
|
+
* - **Inline on entity data.** Single-media fields have the
|
|
7
|
+
* media object embedded directly (`{ id, url, mime, ... }`);
|
|
8
|
+
* multi-media fields hold an array of such objects.
|
|
9
|
+
* - **In `assets/metadata.jsonl`.** A separate manifest of
|
|
10
|
+
* every asset in the project, useful for entities that
|
|
11
|
+
* reference media by id only (rare for v4/v5, common for
|
|
12
|
+
* legacy v3 exports).
|
|
13
|
+
*
|
|
14
|
+
* The adapter builds an `AssetEntry` map from the metadata file
|
|
15
|
+
* once, then the field mapper consults it whenever an inline
|
|
16
|
+
* media object is missing fields the manifest can fill in.
|
|
17
|
+
*
|
|
18
|
+
* URL handling matches the Contentful adapter: relative URLs
|
|
19
|
+
* (`/uploads/foo.jpg`) get prefixed with `mediaBaseUrl` if the
|
|
20
|
+
* operator provided one; absolute and protocol-relative URLs pass
|
|
21
|
+
* through.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Build a `{ assetId → AssetEntry }` map from the export's
|
|
25
|
+
* `assets/metadata.jsonl`. Asset ids are normalized to strings
|
|
26
|
+
* because Strapi uses numeric ids and Prenta references stringify
|
|
27
|
+
* everything.
|
|
28
|
+
*/
|
|
29
|
+
export function buildAssetMap(assets, options = {}) {
|
|
30
|
+
const out = new Map();
|
|
31
|
+
if (!assets)
|
|
32
|
+
return out;
|
|
33
|
+
for (const a of assets) {
|
|
34
|
+
if (a?.id === undefined || a?.id === null)
|
|
35
|
+
continue;
|
|
36
|
+
const entry = toAssetEntry(a, options.mediaBaseUrl);
|
|
37
|
+
out.set(String(a.id), entry);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Lift inline media objects to a normalized AssetEntry. Used by
|
|
43
|
+
* the field mapper for single-media and multi-media fields.
|
|
44
|
+
*/
|
|
45
|
+
export function liftInlineMedia(media, options = {}) {
|
|
46
|
+
return toAssetEntry(media, options.mediaBaseUrl);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Detect whether `value` looks like a Strapi media object. We
|
|
50
|
+
* require `id` plus at least one media-specific field so plain
|
|
51
|
+
* `{ id: 1 }` relation stubs don't get mistaken for media.
|
|
52
|
+
*/
|
|
53
|
+
export function isStrapiMedia(value) {
|
|
54
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
55
|
+
return false;
|
|
56
|
+
const v = value;
|
|
57
|
+
if (v.id === undefined || v.id === null)
|
|
58
|
+
return false;
|
|
59
|
+
return (typeof v.url === 'string' ||
|
|
60
|
+
typeof v.mime === 'string' ||
|
|
61
|
+
typeof v.hash === 'string' ||
|
|
62
|
+
typeof v.ext === 'string');
|
|
63
|
+
}
|
|
64
|
+
function toAssetEntry(src, mediaBaseUrl) {
|
|
65
|
+
const entry = { url: normalizeUrl(src.url, mediaBaseUrl) };
|
|
66
|
+
if (src.name)
|
|
67
|
+
entry.fileName = src.name;
|
|
68
|
+
if (src.mime)
|
|
69
|
+
entry.contentType = src.mime;
|
|
70
|
+
if (typeof src.size === 'number')
|
|
71
|
+
entry.size = src.size;
|
|
72
|
+
if (typeof src.width === 'number')
|
|
73
|
+
entry.width = src.width;
|
|
74
|
+
if (typeof src.height === 'number')
|
|
75
|
+
entry.height = src.height;
|
|
76
|
+
if (src.alternativeText)
|
|
77
|
+
entry.alternativeText = src.alternativeText;
|
|
78
|
+
if (src.caption)
|
|
79
|
+
entry.caption = src.caption;
|
|
80
|
+
return entry;
|
|
81
|
+
}
|
|
82
|
+
function normalizeUrl(url, base) {
|
|
83
|
+
if (!url)
|
|
84
|
+
return '';
|
|
85
|
+
if (url.startsWith('//'))
|
|
86
|
+
return `https:${url}`;
|
|
87
|
+
if (url.startsWith('http://') || url.startsWith('https://'))
|
|
88
|
+
return url;
|
|
89
|
+
if (url.startsWith('/') && base) {
|
|
90
|
+
return base.replace(/\/$/, '') + url;
|
|
91
|
+
}
|
|
92
|
+
return url;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=asset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.js","sourceRoot":"","sources":["../../../src/adapters/strapi/asset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAeH;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAgD,EAChD,UAAqC,EAAE;IAEvC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAsB,CAAA;IACzC,IAAI,CAAC,MAAM;QAAE,OAAO,GAAG,CAAA;IACvB,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,CAAC,EAAE,EAAE,KAAK,SAAS,IAAI,CAAC,EAAE,EAAE,KAAK,IAAI;YAAE,SAAQ;QACnD,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;QACnD,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAkB,EAClB,UAAqC,EAAE;IAEvC,OAAO,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrF,MAAM,CAAC,GAAG,KAAgC,CAAA;IAC1C,IAAI,CAAC,CAAC,EAAE,KAAK,SAAS,IAAI,CAAC,CAAC,EAAE,KAAK,IAAI;QAAE,OAAO,K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IAC/C,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC;QAAE,OAAO,GAAG,CAAA;IACvE,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,CAAA;IACtC,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `strapi` — adapter for Strapi v4/v5 `data-transfer` datasets.
|
|
3
|
+
*
|
|
4
|
+
* The CLI takes the path to the extracted dataset directory (or a
|
|
5
|
+
* single `entities/*.jsonl` file). The adapter reads:
|
|
6
|
+
*
|
|
7
|
+
* - every `entities/*.jsonl` → entity records
|
|
8
|
+
* - `assets/metadata.jsonl` → asset manifest (URLs, mime, dims)
|
|
9
|
+
* - `links/links.jsonl` → cross-entity relations and i18n joins
|
|
10
|
+
*
|
|
11
|
+
* Two-pass: first pass filters entities (publishedOnly, locale,
|
|
12
|
+
* ignoreTypes, shouldInclude) and seeds the
|
|
13
|
+
* `(type, ref) → collection` map so cross-references resolve in
|
|
14
|
+
* either direction. Second pass walks each entity with the
|
|
15
|
+
* resolved context, weaving sidecar relations onto the right
|
|
16
|
+
* fields.
|
|
17
|
+
*/
|
|
18
|
+
import type { ImportAdapter } from '../../types.js';
|
|
19
|
+
export declare const strapiAdapter: ImportAdapter;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/strapi/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,KAAK,EAEV,aAAa,EAKd,MAAM,gBAAgB,CAAA;AAoBvB,eAAO,MAAM,aAAa,EAAE,aA2J3B,CAAA"}
|