@knapsack/mdx-adapter 4.92.2--canary.eb7e898.0 → 4.92.2--canary.77d16bf.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,CA6GhE"}
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,11 +37,11 @@ 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' });
43
- deps.emit({ stage: 'parse', type: 'item.extracted', ref });
44
+ deps.emit({ stage: 'parse', type: 'item.ok', ref });
44
45
  }
45
46
  catch (err) {
46
47
  const message = err instanceof Error ? err.message : String(err);
@@ -56,7 +57,7 @@ export function parse(config, deps) {
56
57
  error: err instanceof Error ? err : undefined,
57
58
  }));
58
59
  items.push({ ref, refType: 'document', stage: 'parse', error: message });
59
- deps.emit({ stage: 'parse', type: 'item.failed', ref, error: message });
60
+ deps.emit({ stage: 'parse', type: 'item.error', ref, error: message });
60
61
  errors += 1;
61
62
  }
62
63
  const manifest = {
@@ -67,16 +68,18 @@ export function parse(config, deps) {
67
68
  items,
68
69
  stages: {
69
70
  parse: {
71
+ status: errors > 0 ? 'failure' : 'success',
70
72
  discoveredItemCount: 1,
71
73
  itemCount: items.length - errors,
72
74
  errors,
73
75
  durationMs: Date.now() - start,
76
+ startedAt: new Date(start).toISOString(),
74
77
  completedAt: new Date().toISOString(),
75
78
  },
76
79
  },
77
80
  };
78
81
  deps.writeFile({
79
- path: join(deps.outputPath, 'raw', config.sourceKey, 'manifest.yml'),
82
+ path: join(deps.outputPath, 'raw', tag, 'manifest.yml'),
80
83
  content: stringifyYaml(manifest),
81
84
  });
82
85
  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,CAsKpE"}
@@ -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;
@@ -37,7 +68,7 @@ export function transform(config, deps) {
37
68
  }));
38
69
  deps.emit({
39
70
  stage: 'transform',
40
- type: 'item.failed',
71
+ type: 'item.error',
41
72
  ref: item.ref,
42
73
  error: item.error,
43
74
  });
@@ -47,17 +78,28 @@ 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
+ extraFields: 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}`,
57
99
  entityKind: 'DOCUMENT',
58
100
  sourceKey: config.sourceKey,
59
101
  });
60
- deps.emit({ stage: 'transform', type: 'item.extracted', ref: item.ref });
102
+ deps.emit({ stage: 'transform', type: 'item.ok', ref: item.ref });
61
103
  deps.logger.info('Transform normalize succeeded', buildLogContext({
62
104
  context: logCtx,
63
105
  evt: {
@@ -84,7 +126,7 @@ export function transform(config, deps) {
84
126
  }));
85
127
  deps.emit({
86
128
  stage: 'transform',
87
- type: 'item.failed',
129
+ type: 'item.error',
88
130
  ref: item.ref,
89
131
  error: message,
90
132
  });
@@ -98,9 +140,11 @@ export function transform(config, deps) {
98
140
  stages: {
99
141
  ...manifest.stages,
100
142
  transform: {
143
+ status: errors > 0 ? 'failure' : 'success',
101
144
  itemCount: entities.length,
102
145
  errors,
103
146
  durationMs: Date.now() - start,
147
+ startedAt: new Date(start).toISOString(),
104
148
  completedAt: new Date().toISOString(),
105
149
  },
106
150
  },
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.eb7e898.0",
4
+ "version": "4.92.2--canary.77d16bf.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -23,16 +23,16 @@
23
23
  },
24
24
  "author": "Knapsack (https://www.knapsack.cloud)",
25
25
  "dependencies": {
26
- "@knapsack/adapter-core": "4.92.2--canary.eb7e898.0",
26
+ "@knapsack/adapter-core": "4.92.2--canary.77d16bf.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.eb7e898.0",
32
- "@knapsack/typescript-config-starter": "4.92.2--canary.eb7e898.0",
31
+ "@knapsack/eslint-config-starter": "4.92.2--canary.77d16bf.0",
32
+ "@knapsack/typescript-config-starter": "4.92.2--canary.77d16bf.0",
33
33
  "@types/node": "^22.19.11",
34
34
  "eslint": "^9.20.0",
35
- "typescript": "^6.0.0",
35
+ "typescript": "^5.9.3",
36
36
  "vitest": "^4.0.18"
37
37
  },
38
38
  "license": "GPL-2.0-or-later",
@@ -44,5 +44,5 @@
44
44
  "directory": "libs/ingest-pipeline/adapters/mdx",
45
45
  "type": "git"
46
46
  },
47
- "gitHead": "eb7e898467cd0ff7b1e27faa3cffc69ccd985720"
47
+ "gitHead": "77d16bf68c911461c261b5247b563a73e9c1eae6"
48
48
  }
package/tsconfig.json CHANGED
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "types": ["node"],
4
3
  "target": "ES2022",
5
4
  "module": "NodeNext",
6
5
  "moduleResolution": "NodeNext",