@knapsack/mdx-adapter 4.92.2--canary.ab2a72c.0 → 4.92.2--canary.58dd175.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.
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EAKZ,MAAM,wBAAwB,CAAC;AAGhC,wBAAgB,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CA2GhE"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EAKZ,MAAM,wBAAwB,CAAC;AAOhC,wBAAgB,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CA4GhE"}
package/dist/parser.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { basename, extname, join } from 'node:path';
3
3
  import { stringify as stringifyYaml } from 'yaml';
4
- import { buildLogContext, SOURCE_TYPE_TO_EVT } from '@knapsack/adapter-core';
4
+ import { buildLogContext, SOURCE_TYPE_TO_EVT, sourceTag, } from '@knapsack/adapter-core';
5
5
  export function parse(config, deps) {
6
6
  const ref = basename(config.path, extname(config.path));
7
7
  const siteId = config.siteId ?? 'unknown';
@@ -10,6 +10,7 @@ export function parse(config, deps) {
10
10
  sourceKey: config.sourceKey,
11
11
  siteId,
12
12
  };
13
+ const tag = sourceTag({ sourceType: 'MDX', sourceKey: config.sourceKey });
13
14
  const start = Date.now();
14
15
  deps.logger.info('Parse started', buildLogContext({
15
16
  context: logCtx,
@@ -36,7 +37,7 @@ export function parse(config, deps) {
36
37
  },
37
38
  }));
38
39
  deps.writeFile({
39
- path: join(deps.outputPath, 'raw', config.sourceKey, `${ref}.json`),
40
+ path: join(deps.outputPath, 'raw', tag, `${ref}.json`),
40
41
  content: JSON.stringify({ ref, content }),
41
42
  });
42
43
  items.push({ ref, refType: 'document', stage: 'parse' });
@@ -76,7 +77,7 @@ export function parse(config, deps) {
76
77
  },
77
78
  };
78
79
  deps.writeFile({
79
- path: join(deps.outputPath, 'raw', config.sourceKey, 'manifest.yml'),
80
+ path: join(deps.outputPath, 'raw', tag, 'manifest.yml'),
80
81
  content: stringifyYaml(manifest),
81
82
  });
82
83
  deps.logger.info('Parse complete', buildLogContext({
@@ -1 +1 @@
1
- {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EAKZ,MAAM,wBAAwB,CAAC;AAGhC,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAkJpE"}
1
+ {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EAKZ,MAAM,wBAAwB,CAAC;AAiDhC,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAoKpE"}
@@ -1,9 +1,35 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
4
- import { buildLogContext, SOURCE_TYPE_TO_EVT } from '@knapsack/adapter-core';
4
+ import { buildEntityFrontmatter, buildLogContext, contentHash, SOURCE_TYPE_TO_EVT, sourceTag, tagFilenameForEntity, } from '@knapsack/adapter-core';
5
+ const RESERVED_FRONTMATTER_KEYS = new Set([
6
+ 'key',
7
+ 'sourceKey',
8
+ 'source',
9
+ 'lastIngested',
10
+ 'contentHash',
11
+ 'platform',
12
+ 'import',
13
+ ]);
14
+ function splitMdxFrontmatter(raw) {
15
+ const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
16
+ if (!match) {
17
+ return { frontmatter: {}, body: raw };
18
+ }
19
+ const parsed = parseYaml(match[1] ?? '');
20
+ return {
21
+ frontmatter: parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)
22
+ ? parsed
23
+ : {},
24
+ body: raw.slice(match[0].length),
25
+ };
26
+ }
27
+ function omitReservedFrontmatter(frontmatter) {
28
+ return Object.fromEntries(Object.entries(frontmatter).filter(([key]) => !RESERVED_FRONTMATTER_KEYS.has(key)));
29
+ }
5
30
  export function transform(config, deps) {
6
31
  const start = Date.now();
32
+ const lastIngested = new Date().toISOString();
7
33
  const logCtx = {
8
34
  sourceType: 'MDX',
9
35
  sourceKey: config.sourceKey,
@@ -18,8 +44,13 @@ export function transform(config, deps) {
18
44
  outcome: null,
19
45
  },
20
46
  }));
21
- const rawDir = join(deps.outputPath, 'raw', config.sourceKey);
22
- const sourcesDir = join(deps.outputPath, 'sources', config.sourceKey);
47
+ // PCIF entity-stage source tag — used as folder name + filename tag
48
+ const tag = sourceTag({
49
+ sourceType: 'MDX',
50
+ sourceKey: config.sourceKey,
51
+ });
52
+ const rawDir = join(deps.outputPath, 'raw', tag);
53
+ const sourcesDir = join(deps.outputPath, 'sources', tag);
23
54
  const manifest = parseYaml(readFileSync(join(rawDir, 'manifest.yml'), 'utf-8'));
24
55
  const entities = [];
25
56
  let errors = 0;
@@ -47,10 +78,21 @@ export function transform(config, deps) {
47
78
  try {
48
79
  // Read the raw extraction
49
80
  const raw = JSON.parse(readFileSync(join(rawDir, `${item.ref}.json`), 'utf-8'));
81
+ const { frontmatter, body } = splitMdxFrontmatter(raw.content);
82
+ const content = buildEntityFrontmatter({
83
+ entityKind: 'DOCUMENT',
84
+ key: `document/${item.ref}`,
85
+ sourceKey: `mdx://${config.sourceKey}/${item.ref}`,
86
+ source: 'mdx',
87
+ lastIngested,
88
+ contentHash: contentHash(body),
89
+ ...omitReservedFrontmatter(frontmatter),
90
+ }) + `\n\n${body}`;
50
91
  // Write transformed MDX to sources/{sourceKey}/document/
92
+ const taggedName = tagFilenameForEntity(`${item.ref}.mdx`, tag);
51
93
  deps.writeFile({
52
- path: join(sourcesDir, 'document', `${item.ref}.mdx`),
53
- content: raw.content,
94
+ path: join(sourcesDir, 'document', taggedName),
95
+ content,
54
96
  });
55
97
  entities.push({
56
98
  canonicalKey: `document/${item.ref}`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@knapsack/mdx-adapter",
3
3
  "description": "MDX Context Adapter",
4
- "version": "4.92.2--canary.ab2a72c.0",
4
+ "version": "4.92.2--canary.58dd175.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -23,13 +23,13 @@
23
23
  },
24
24
  "author": "Knapsack (https://www.knapsack.cloud)",
25
25
  "dependencies": {
26
- "@knapsack/adapter-core": "4.92.2--canary.ab2a72c.0",
26
+ "@knapsack/adapter-core": "4.92.2--canary.58dd175.0",
27
27
  "@mdx-js/mdx": "^3.0.0",
28
28
  "yaml": "^2.7.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@knapsack/eslint-config-starter": "4.92.2--canary.ab2a72c.0",
32
- "@knapsack/typescript-config-starter": "4.92.2--canary.ab2a72c.0",
31
+ "@knapsack/eslint-config-starter": "4.92.2--canary.58dd175.0",
32
+ "@knapsack/typescript-config-starter": "4.92.2--canary.58dd175.0",
33
33
  "@types/node": "^22.19.11",
34
34
  "eslint": "^9.20.0",
35
35
  "typescript": "^5.9.3",
@@ -44,5 +44,5 @@
44
44
  "directory": "libs/ingest-pipeline/adapters/mdx",
45
45
  "type": "git"
46
46
  },
47
- "gitHead": "ab2a72c3adb82c2d02f4a15fa664658fa67461c8"
47
+ "gitHead": "58dd17555746c4fc1f24574ad947929a04080370"
48
48
  }