@contentrain/wp-import 0.1.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/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/index.d.mts +98 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1654 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Contentrain
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @contentrain/wp-import
|
|
2
|
+
|
|
3
|
+
WordPress importers for the Contentrain migration pipeline — ported from a corpus-measured import chain, not written fresh: the identity formulas, PHP-serialized meta decoding, and reference-resolution passes carried over intact.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
WXR file or REST API ──► RawIR (source-faithful, provenance-stamped)
|
|
7
|
+
RawIR ──► .contentrain content store (pure file map) + EntrySourceMap
|
|
8
|
+
RawIR + EntrySourceMap ──► CommentsExport (live-service intake payload)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { parseWxr, fetchRestRawIR, rawToContentrain, buildCommentsExport } from '@contentrain/wp-import'
|
|
15
|
+
|
|
16
|
+
// Highest offline rung: a WXR export file
|
|
17
|
+
const { raw, stats } = await parseWxr(createReadStream('export.xml'))
|
|
18
|
+
|
|
19
|
+
// Or the REST rungs (public, or Application Password → rest_auth)
|
|
20
|
+
const { raw: viaRest } = await fetchRestRawIR({ origin: 'https://site.example', auth: { user, appPassword } })
|
|
21
|
+
|
|
22
|
+
// RawIR → .contentrain (pure: returns { files, entry_source_map, report })
|
|
23
|
+
const { files, entry_source_map } = rawToContentrain(raw)
|
|
24
|
+
|
|
25
|
+
// Comments intake payload for a live comments service
|
|
26
|
+
const commentsExport = buildCommentsExport(raw, entry_source_map)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Guarantees
|
|
30
|
+
|
|
31
|
+
- **Provenance on every document** — which access rung produced it (`rest_public` / `rest_auth` / `wxr` / `bridge`); absence at a low rung is information, not an error.
|
|
32
|
+
- **Unresolved references are marked, never dropped** (`resolved` flags, ghost terms joining the pool, dropped-relation counts in the report).
|
|
33
|
+
- **Shared identity formulas** — `hexId('posts:' + slug)` — so WXR and REST imports of the same site agree on every entry id (delta imports depend on this).
|
|
34
|
+
- **UTC dates** — GMT columns preferred, stamped ISO 8601 `Z`.
|
|
35
|
+
- **Pure conversion** — `rawToContentrain` returns a canonical-serialized file map (sorted keys, 2-space indent, trailing newline); writing to disk is the caller's one line.
|
|
36
|
+
- **EntrySourceMap produced at the only place that can know it** — the WP-id → entry-address mapping the comments intake requires.
|
|
37
|
+
|
|
38
|
+
Streaming WXR parse (sax): a 100 MB export holds only its records in memory.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { CommentsExport, EntrySourceMap, HandoffComments, RawIR } from "@contentrain/types";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
|
|
4
|
+
//#region src/wxr.d.ts
|
|
5
|
+
interface WxrStats {
|
|
6
|
+
serialized: {
|
|
7
|
+
detected: number;
|
|
8
|
+
decoded: number;
|
|
9
|
+
failed: number;
|
|
10
|
+
keys: string[];
|
|
11
|
+
};
|
|
12
|
+
acf_fields: number;
|
|
13
|
+
unresolved_terms: number;
|
|
14
|
+
counts: Record<string, number>;
|
|
15
|
+
}
|
|
16
|
+
interface WxrParseResult {
|
|
17
|
+
raw: RawIR;
|
|
18
|
+
stats: WxrStats;
|
|
19
|
+
}
|
|
20
|
+
declare function parseWxr(input: string | Readable, opts?: {
|
|
21
|
+
tool?: string;
|
|
22
|
+
}): Promise<WxrParseResult>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/rest.d.ts
|
|
25
|
+
interface RestImportOptions {
|
|
26
|
+
origin: string;
|
|
27
|
+
/** Injectable for tests and for hosts that need custom dispatch. */
|
|
28
|
+
fetchImpl?: typeof fetch;
|
|
29
|
+
/** WordPress Application Password credentials — lifts the rung to rest_auth. */
|
|
30
|
+
auth?: {
|
|
31
|
+
user: string;
|
|
32
|
+
appPassword: string;
|
|
33
|
+
};
|
|
34
|
+
perPage?: number;
|
|
35
|
+
tool?: string;
|
|
36
|
+
}
|
|
37
|
+
interface RestImportResult {
|
|
38
|
+
raw: RawIR;
|
|
39
|
+
warnings: string[];
|
|
40
|
+
}
|
|
41
|
+
declare function fetchRestRawIR(options: RestImportOptions): Promise<RestImportResult>;
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/contentrain.d.ts
|
|
44
|
+
interface ImportReport {
|
|
45
|
+
slug_rewritten: number;
|
|
46
|
+
slug_fallback: number;
|
|
47
|
+
title_fallback: number;
|
|
48
|
+
meta_fields: Record<string, string>;
|
|
49
|
+
acf_fields: Record<string, string>;
|
|
50
|
+
skipped_types: string[];
|
|
51
|
+
dropped_relations: number;
|
|
52
|
+
models: Record<string, {
|
|
53
|
+
kind: string;
|
|
54
|
+
domain: string;
|
|
55
|
+
fields: number;
|
|
56
|
+
entries: number;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
59
|
+
interface ContentrainResult {
|
|
60
|
+
files: Record<string, string>;
|
|
61
|
+
entry_source_map: EntrySourceMap;
|
|
62
|
+
report: ImportReport;
|
|
63
|
+
}
|
|
64
|
+
declare function rawToContentrain(raw: RawIR, opts?: {
|
|
65
|
+
updatedBy?: string;
|
|
66
|
+
}): ContentrainResult;
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/comments.d.ts
|
|
69
|
+
declare function buildCommentsExport(raw: RawIR, entries: EntrySourceMap, opts?: {
|
|
70
|
+
generated_at?: string;
|
|
71
|
+
}): CommentsExport;
|
|
72
|
+
/** Handoff summary for the export: counts + closed threads + what could not be addressed. */
|
|
73
|
+
declare function summarizeComments(exp: CommentsExport): HandoffComments;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/php-unserialize.d.ts
|
|
76
|
+
interface UnserializeResult {
|
|
77
|
+
ok: boolean;
|
|
78
|
+
serialized: boolean;
|
|
79
|
+
value: unknown;
|
|
80
|
+
error?: string;
|
|
81
|
+
}
|
|
82
|
+
declare function looksSerialized(s: unknown): s is string;
|
|
83
|
+
declare function phpUnserialize(str: string): unknown;
|
|
84
|
+
/** Attempt a decode; on failure the value stays exactly as it was. */
|
|
85
|
+
declare function tryUnserialize(s: string): UnserializeResult;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/core.d.ts
|
|
88
|
+
declare const strip: (s: unknown) => string;
|
|
89
|
+
/** Entry id: deterministic hex from a stable key (model:slug style). */
|
|
90
|
+
declare const hexId: (s: string) => string;
|
|
91
|
+
/** Canonical serialization: sorted keys, 2-space indent, trailing newline. */
|
|
92
|
+
declare const canon: (o: unknown) => string;
|
|
93
|
+
/** Taxonomy → model id. */
|
|
94
|
+
declare const taxModelId: (t: string) => string;
|
|
95
|
+
declare const slugify: (s: unknown) => string;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { type ContentrainResult, type ImportReport, type RestImportOptions, type RestImportResult, type UnserializeResult, type WxrParseResult, type WxrStats, buildCommentsExport, canon, fetchRestRawIR, hexId, looksSerialized, parseWxr, phpUnserialize, rawToContentrain, slugify, strip, summarizeComments, taxModelId, tryUnserialize };
|
|
98
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/wxr.ts","../src/rest.ts","../src/contentrain.ts","../src/comments.ts","../src/php-unserialize.ts","../src/core.ts"],"mappings":";;;;UA0BiB,QAAA;EACf,UAAA;IAAc,QAAA;IAAkB,OAAA;IAAiB,MAAA;IAAgB,IAAA;EAAA;EACjE,UAAA;EACA,gBAAA;EACA,MAAA,EAAQ,MAAA;AAAA;AAAA,UAGO,cAAA;EACf,GAAA,EAAK,KAAA;EACL,KAAA,EAAO,QAAA;AAAA;AAAA,iBAiBa,QAAA,CAAS,KAAA,WAAgB,QAAA,EAAU,IAAA;EAAS,IAAA;AAAA,IAAkB,OAAA,CAAQ,cAAA;;;UCrC3E,iBAAA;EACf,MAAA;;EAEA,SAAA,UAAmB,KAAA;EDQI;ECNvB,IAAA;IAAS,IAAA;IAAc,WAAA;EAAA;EACvB,OAAA;EACA,IAAA;AAAA;AAAA,UAGe,gBAAA;EACf,GAAA,EAAK,KAAA;EACL,QAAA;AAAA;AAAA,iBA0BoB,cAAA,CAAe,OAAA,EAAS,iBAAA,GAAoB,OAAA,CAAQ,gBAAA;;;UC1BzD,YAAA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