zelos-recad 0.1.0 → 0.2.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/README.md +18 -5
- package/UPSTREAM-LICENSE +21 -21
- package/build-info.json +26 -0
- package/mcp/index.js +2 -1
- package/package.json +22 -10
- package/protocol/src/bundle.d.ts +7 -1
- package/protocol/src/contracts.d.ts +18 -6
- package/protocol/src/contracts.js +20 -7
- package/protocol/src/native-evidence.d.ts +20 -0
- package/service/app.js +4 -2
- package/service/options.d.ts +2 -1
- package/service/options.js +2 -1
- package/shared/build-identity.d.mts +6 -0
- package/shared/build-identity.mjs +63 -0
- package/shared/client.d.mts +1 -0
- package/shared/client.mjs +9 -0
- package/shared/command.d.mts +1 -0
- package/shared/command.mjs +22 -4
- package/shared/contracts/src/paths.d.ts +3 -0
- package/shared/contracts/src/paths.js +31 -0
- package/shared/mcp.d.mts +1 -0
- package/shared/service-storage/src/capacity.d.ts +36 -0
- package/shared/service-storage/src/capacity.js +71 -0
- package/shared/service-storage/src/consumption.d.ts +15 -0
- package/shared/service-storage/src/consumption.js +27 -0
- package/shared/service-storage/src/documents.d.ts +43 -0
- package/shared/service-storage/src/documents.js +210 -0
- package/shared/service-storage/src/downloads.d.ts +10 -0
- package/shared/service-storage/src/downloads.js +58 -0
- package/shared/service-storage/src/files.d.ts +18 -0
- package/shared/service-storage/src/files.js +118 -0
- package/shared/service-storage/src/footprint.d.ts +14 -0
- package/shared/service-storage/src/footprint.js +72 -0
- package/shared/service-storage/src/process-temp.d.ts +22 -0
- package/shared/service-storage/src/process-temp.js +181 -0
- package/shared/service-storage/src/quota.d.ts +30 -0
- package/shared/service-storage/src/quota.js +166 -0
- package/shared/service-storage/src/retention.d.ts +38 -0
- package/shared/service-storage/src/retention.js +148 -0
- package/shared/service-storage/src/staging.d.ts +15 -0
- package/shared/service-storage/src/staging.js +116 -0
- package/source/README.md +1 -3
- package/source/mcp/index.ts +2 -1
- package/source/package.json +4 -2
- package/source/protocol/src/contracts.ts +20 -7
- package/source/protocol/src/native-evidence.ts +21 -0
- package/source/rebuild.mjs +12 -4
- package/source/service/app.ts +6 -2
- package/source/service/options.ts +3 -2
- package/source/shared/build-identity.d.mts +6 -0
- package/source/shared/build-identity.mjs +63 -0
- package/source/shared/client.d.mts +1 -0
- package/source/shared/client.mjs +9 -0
- package/source/shared/command.d.mts +1 -0
- package/source/shared/command.mjs +22 -4
- package/source/shared/contracts/src/paths.ts +33 -0
- package/source/shared/mcp.d.mts +1 -0
- package/source/shared/service-storage/src/capacity.ts +101 -0
- package/source/shared/service-storage/src/consumption.ts +45 -0
- package/source/shared/service-storage/src/documents.ts +262 -0
- package/source/shared/service-storage/src/downloads.ts +62 -0
- package/source/shared/service-storage/src/files.ts +135 -0
- package/source/shared/service-storage/src/footprint.ts +78 -0
- package/source/shared/service-storage/src/process-temp.ts +205 -0
- package/source/shared/service-storage/src/quota.ts +198 -0
- package/source/shared/service-storage/src/retention.ts +180 -0
- package/source/shared/service-storage/src/staging.ts +106 -0
- package/source/src/application-objects.ts +2 -2
- package/source/src/assets.ts +15 -0
- package/source/src/block-clip.ts +1 -1
- package/source/src/block-metadata.ts +12 -5
- package/source/src/build-info.ts +15 -0
- package/source/src/cad-engine.ts +18 -8
- package/source/src/command.ts +2 -2
- package/source/src/constraints.ts +2 -2
- package/source/src/conversion.ts +2 -0
- package/source/src/dwg-fallback.ts +2 -0
- package/source/src/dwg.ts +7 -0
- package/source/src/dxf-export.ts +3 -3
- package/source/src/dxf.ts +7 -4
- package/source/src/native-evidence.ts +33 -1
- package/source/src/native-segmented-path.ts +22 -35
- package/source/src/point-dictionaries.ts +65 -0
- package/source/src/readback.ts +7 -6
- package/source/src/reader.ts +19 -10
- package/source/src/render-operation.ts +39 -7
- package/source/src/runner.ts +5 -4
- package/source/src/runtime/documents.ts +23 -142
- package/source/src/runtime/index.ts +71 -17
- package/source/src/runtime/jobs.ts +176 -153
- package/source/src/runtime/managed-worker.ts +37 -0
- package/source/src/runtime/storage-policy.ts +39 -0
- package/source/src/runtime/storage.ts +9 -44
- package/source/src/source-scene.ts +125 -23
- package/source/src/text/glyphs.ts +63 -0
- package/source/src/text/ink-bounds.ts +7 -36
- package/source/src/text/scene-geometry.ts +92 -0
- package/source/src/text/source-fonts.ts +31 -0
- package/source/src/vendor-object-data.ts +265 -0
- package/source/src/xref.ts +4 -3
- package/source/tsconfig.json +4 -2
- package/src/application-objects.js +2 -2
- package/src/assets.d.ts +9 -0
- package/src/assets.js +14 -0
- package/src/block-clip.js +1 -1
- package/src/block-metadata.js +11 -5
- package/src/build-info.d.ts +2 -0
- package/src/build-info.js +14 -0
- package/src/cad-engine.js +19 -8
- package/src/command.js +2 -2
- package/src/constraints.js +2 -2
- package/src/conversion.d.ts +2 -0
- package/src/conversion.js +2 -0
- package/src/dwg-fallback.d.ts +1 -0
- package/src/dwg-fallback.js +2 -0
- package/src/dwg.d.ts +3 -0
- package/src/dwg.js +7 -0
- package/src/dxf-export.js +3 -3
- package/src/dxf.d.ts +14 -1
- package/src/dxf.js +7 -3
- package/src/native-evidence.d.ts +33 -1
- package/src/native-evidence.js +33 -0
- package/src/native-segmented-path.js +1 -3
- package/src/point-dictionaries.d.ts +12 -0
- package/src/point-dictionaries.js +88 -0
- package/src/readback.d.ts +12 -4
- package/src/readback.js +7 -6
- package/src/reader.d.ts +12 -1
- package/src/reader.js +22 -11
- package/src/render-operation.js +36 -7
- package/src/runner.js +5 -4
- package/src/runtime/documents.d.ts +8 -20
- package/src/runtime/documents.js +17 -116
- package/src/runtime/index.d.ts +41 -4
- package/src/runtime/index.js +72 -18
- package/src/runtime/jobs.d.ts +21 -2
- package/src/runtime/jobs.js +120 -100
- package/src/runtime/managed-worker.d.ts +8 -0
- package/src/runtime/managed-worker.js +29 -0
- package/src/runtime/storage-policy.d.ts +25 -0
- package/src/runtime/storage-policy.js +29 -0
- package/src/runtime/storage.d.ts +1 -7
- package/src/runtime/storage.js +1 -38
- package/src/source-scene.d.ts +4 -2
- package/src/source-scene.js +136 -20
- package/src/text/glyphs.d.ts +12 -0
- package/src/text/glyphs.js +53 -0
- package/src/text/ink-bounds.d.ts +2 -1
- package/src/text/ink-bounds.js +6 -34
- package/src/text/scene-geometry.d.ts +21 -0
- package/src/text/scene-geometry.js +70 -0
- package/src/text/source-fonts.d.ts +7 -0
- package/src/text/source-fonts.js +30 -0
- package/src/vendor-object-data.d.ts +19 -0
- package/src/vendor-object-data.js +241 -0
- package/src/xref.js +3 -3
- package/vendor/libredwg/COPYING +674 -674
- package/vendor/libredwg/Dockerfile +2 -0
- package/vendor/libredwg/README.md +41 -28
- package/vendor/libredwg/build-local.sh +1 -1
- package/vendor/libredwg/libredwg-web.wasm +0 -0
- package/vendor/libredwg/manifest.json +5 -3
- package/vendor/libredwg/opaque-object-binding.patch +29 -0
- package/vendor/libredwg/rebuild.mjs +2 -1
- package/source/service/README.md +0 -152
- package/source/src/text/UPSTREAM.md +0 -26
package/src/dxf.js
CHANGED
|
@@ -6,7 +6,7 @@ import { binaryDxfSentinel, binaryDxfToText } from "./binary-dxf.js";
|
|
|
6
6
|
const structural = new Set(['BLOCK', 'ENDBLK', 'SEQEND', 'VERTEX']);
|
|
7
7
|
/** Validate the DXF envelope and retain source fields omitted by the upstream
|
|
8
8
|
* reader. Changes are confined to its in-memory adapter copy. */
|
|
9
|
-
export function inspectDxf(bytes) {
|
|
9
|
+
export function inspectDxf(bytes, retainPointDictionaries = false) {
|
|
10
10
|
const binary = bytes.subarray(0, 22).equals(binaryDxfSentinel);
|
|
11
11
|
const binaryLegacy = binary && bytes[22] === 0 && bytes[23] !== 0;
|
|
12
12
|
if (binary)
|
|
@@ -35,7 +35,7 @@ export function inspectDxf(bytes) {
|
|
|
35
35
|
}
|
|
36
36
|
if (code === 2 && current?.type === 'SECTION')
|
|
37
37
|
section = value;
|
|
38
|
-
current?.pairs.push({ code, value, line: i + 1 });
|
|
38
|
+
current?.pairs.push({ code, value, line: i + 1, ...(retainPointDictionaries && ['POINT', 'DICTIONARY', 'XRECORD'].includes(current.type) ? { rawValue: lines[i + 1] } : {}) });
|
|
39
39
|
}
|
|
40
40
|
if (!records.some((r) => r.type === 'SECTION') || records.at(-1)?.type !== 'EOF')
|
|
41
41
|
throw new CadError('INVALID_DXF', 'DXF 缺少 SECTION 或 EOF');
|
|
@@ -51,10 +51,13 @@ export function inspectDxf(bytes) {
|
|
|
51
51
|
// Keep segments as raw bytes for envelope edits, while retained metadata uses
|
|
52
52
|
// the same declared text encoding as the CAD reader (including legacy GBK).
|
|
53
53
|
for (const record of records)
|
|
54
|
-
for (const pair of record.pairs)
|
|
54
|
+
for (const pair of record.pairs) {
|
|
55
55
|
pair.value = iconv
|
|
56
56
|
.decode(Buffer.from(pair.value, 'latin1'), encoding)
|
|
57
57
|
.replace(/\\U\+([0-9a-f]{4})/gi, (_, n) => String.fromCharCode(parseInt(n, 16)));
|
|
58
|
+
if (pair.rawValue !== undefined)
|
|
59
|
+
pair.rawValue = iconv.decode(Buffer.from(pair.rawValue, 'latin1'), encoding).replace(/\\U\+([0-9a-f]{4})/gi, (_, n) => String.fromCharCode(parseInt(n, 16)));
|
|
60
|
+
}
|
|
58
61
|
const legacyR12 = versionIndex >= 0 && header.pairs[versionIndex + 1]?.value === 'AC1009';
|
|
59
62
|
const pairOf = (r, code) => {
|
|
60
63
|
let applicationDepth = 0;
|
|
@@ -251,6 +254,7 @@ export function inspectDxf(bytes) {
|
|
|
251
254
|
throw new CadError('INVALID_DXF', 'DXF 包含重复图元句柄');
|
|
252
255
|
const blockExtensions = dxfBlockMetadata(records);
|
|
253
256
|
return {
|
|
257
|
+
pointDictionaryRecords: retainPointDictionaries ? records.filter(r => ['POINT', 'DICTIONARY', 'XRECORD'].includes(r.type)) : undefined,
|
|
254
258
|
blockMetadata: blockExtensions.metadata,
|
|
255
259
|
blockClips: captureDxfBlockClips(records, blockExtensions.filters),
|
|
256
260
|
xrefSettings: (() => {
|
package/src/native-evidence.d.ts
CHANGED
|
@@ -1,8 +1,40 @@
|
|
|
1
|
-
import type { CadNativeDocument } from 'zelos-recad/protocol/native-evidence';
|
|
1
|
+
import type { CadNativeDocument, CadNativeRecord } from 'zelos-recad/protocol/native-evidence';
|
|
2
2
|
export interface NativeCapture {
|
|
3
3
|
documents: CadNativeDocument[];
|
|
4
4
|
references: Map<object, string>;
|
|
5
5
|
}
|
|
6
|
+
/** Keep every record in referenced blocks, including hidden INSERTs/attributes,
|
|
7
|
+
* then follow definition references. Geometry records and private payloads stay intact. */
|
|
8
|
+
export declare function sceneNativeDocuments(documents: CadNativeDocument[], instanceRecordIds: string[]): {
|
|
9
|
+
records: CadNativeRecord[];
|
|
10
|
+
blocks: {
|
|
11
|
+
id: string;
|
|
12
|
+
handle: string;
|
|
13
|
+
name: string;
|
|
14
|
+
space: CadNativeRecord["space"];
|
|
15
|
+
}[];
|
|
16
|
+
selection: {
|
|
17
|
+
basis: "scene-referenced-block-closure";
|
|
18
|
+
parsedRecords: number;
|
|
19
|
+
parsedBlocks: number;
|
|
20
|
+
excludedRecords: number;
|
|
21
|
+
excludedBlocks: number;
|
|
22
|
+
};
|
|
23
|
+
coverage: {
|
|
24
|
+
records: number;
|
|
25
|
+
attributes: number;
|
|
26
|
+
xdataPartialRecords: number;
|
|
27
|
+
basis: "parsed-block-records-and-attached-attributes";
|
|
28
|
+
registeredApps: string[];
|
|
29
|
+
xdataQueries: number;
|
|
30
|
+
missingExpected: unknown[];
|
|
31
|
+
decodeIssues: unknown[];
|
|
32
|
+
status: "captured" | "partial";
|
|
33
|
+
};
|
|
34
|
+
sourceSha256: string;
|
|
35
|
+
applicationObjects?: unknown[];
|
|
36
|
+
pointDictionaries?: import("zelos-recad/protocol/native-evidence").CadPointDictionaryEvidence[];
|
|
37
|
+
}[];
|
|
6
38
|
/** Called once per original database, before XREF relocation and print adapters. */
|
|
7
39
|
export declare function captureNativeEvidence(db: any, sourceSha256: string, options?: {
|
|
8
40
|
textFields?: Map<string, any>;
|
package/src/native-evidence.js
CHANGED
|
@@ -2,6 +2,39 @@ import { CadError } from "./contracts.js";
|
|
|
2
2
|
import { nativeLinearPath } from "./native-linear-path.js";
|
|
3
3
|
import { nativeCircularPath } from "./native-circular-path.js";
|
|
4
4
|
import { nativeSegmentedPath } from "./native-segmented-path.js";
|
|
5
|
+
/** Keep every record in referenced blocks, including hidden INSERTs/attributes,
|
|
6
|
+
* then follow definition references. Geometry records and private payloads stay intact. */
|
|
7
|
+
export function sceneNativeDocuments(documents, instanceRecordIds) {
|
|
8
|
+
const byBlock = new Map(), owners = new Map();
|
|
9
|
+
for (const doc of documents)
|
|
10
|
+
for (const record of doc.records) {
|
|
11
|
+
const block = record.sourceSha256 + ':' + record.blockHandle;
|
|
12
|
+
if (!byBlock.has(block))
|
|
13
|
+
byBlock.set(block, []);
|
|
14
|
+
byBlock.get(block).push(record);
|
|
15
|
+
owners.set(record.id, block);
|
|
16
|
+
}
|
|
17
|
+
const selected = new Set(), pending = instanceRecordIds.map(id => owners.get(id) || id);
|
|
18
|
+
while (pending.length) {
|
|
19
|
+
const id = pending.pop();
|
|
20
|
+
if (selected.has(id))
|
|
21
|
+
continue;
|
|
22
|
+
selected.add(id);
|
|
23
|
+
for (const record of byBlock.get(id) || [])
|
|
24
|
+
if (record.insert?.definitionId)
|
|
25
|
+
pending.push(record.insert.definitionId);
|
|
26
|
+
}
|
|
27
|
+
return documents.map(doc => {
|
|
28
|
+
const records = doc.records.filter(record => selected.has(record.sourceSha256 + ':' + record.blockHandle)), blocks = doc.blocks.filter(block => selected.has(block.id));
|
|
29
|
+
return { ...doc, records, blocks,
|
|
30
|
+
selection: { basis: 'scene-referenced-block-closure',
|
|
31
|
+
parsedRecords: doc.records.length, parsedBlocks: doc.blocks.length,
|
|
32
|
+
excludedRecords: doc.records.length - records.length, excludedBlocks: doc.blocks.length - blocks.length },
|
|
33
|
+
coverage: { ...doc.coverage, records: records.length,
|
|
34
|
+
attributes: records.filter(record => record.entityType === 'ATTRIB').length,
|
|
35
|
+
xdataPartialRecords: records.filter(record => record.xdataStatus === 'partial').length }, };
|
|
36
|
+
});
|
|
37
|
+
}
|
|
5
38
|
const handle = (v) => String(v || '').toUpperCase();
|
|
6
39
|
const point = (v) => v && [v.x, v.y, v.z ?? 0].every(Number.isFinite) ? [v.x, v.y, v.z ?? 0] : null;
|
|
7
40
|
const number = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
|
|
@@ -23,9 +23,7 @@ export function nativeSegmentedPath(entity) {
|
|
|
23
23
|
const arc = nativeArcParameters(p.arc);
|
|
24
24
|
if (!arc)
|
|
25
25
|
return;
|
|
26
|
-
const at = (t) => arc.center.map((n, j) => n +
|
|
27
|
-
arc.axisX[j] * Math.cos(arc.start + t * arc.sweep) +
|
|
28
|
-
arc.axisY[j] * Math.sin(arc.start + t * arc.sweep));
|
|
26
|
+
const at = (t) => arc.center.map((n, j) => n + arc.axisX[j] * Math.cos(arc.start + t * arc.sweep) + arc.axisY[j] * Math.sin(arc.start + t * arc.sweep));
|
|
29
27
|
if (near(from, at(1)) && near(to, at(0))) {
|
|
30
28
|
arc.start += arc.sweep;
|
|
31
29
|
arc.sweep = -arc.sweep;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CadPointDictionaryEvidence } from 'zelos-recad/protocol/native-evidence';
|
|
2
|
+
export declare function captureDwgPointDictionaries(model: any, sourceSha256: string): CadPointDictionaryEvidence[];
|
|
3
|
+
type DxfRecord = {
|
|
4
|
+
type: string;
|
|
5
|
+
pairs: {
|
|
6
|
+
code: number;
|
|
7
|
+
value: string;
|
|
8
|
+
rawValue?: string;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
export declare function captureDxfPointDictionaries(input: DxfRecord[], sourceSha256: string): CadPointDictionaryEvidence[];
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { CadError } from "./contracts.js";
|
|
3
|
+
const handle = (value) => String(value || '').toUpperCase();
|
|
4
|
+
/** Retain the complete owner tree as source data; no vendor electrical meaning is inferred. */
|
|
5
|
+
function capture(points, records, sourceSha256) {
|
|
6
|
+
const index = new Map(records.map(record => [record.handle, record]));
|
|
7
|
+
if (index.size !== records.length)
|
|
8
|
+
throw new CadError('POINT_DICTIONARY', 'POINT字典记录句柄重复');
|
|
9
|
+
return points.filter(point => point.dictionaries.length).map(point => {
|
|
10
|
+
const visited = new Set(), closure = [];
|
|
11
|
+
function visit(id, owner) {
|
|
12
|
+
const record = index.get(id);
|
|
13
|
+
if (!record || record.ownerHandle !== owner || visited.has(id))
|
|
14
|
+
throw new CadError('POINT_DICTIONARY', 'POINT字典闭包缺件、所属或循环引用异常', { point: point.handle, handle: id, owner });
|
|
15
|
+
visited.add(id);
|
|
16
|
+
closure.push(record);
|
|
17
|
+
if (record.kind === 'DICTIONARY')
|
|
18
|
+
for (const entry of record.entries)
|
|
19
|
+
visit(entry.handle, id);
|
|
20
|
+
}
|
|
21
|
+
for (const id of point.dictionaries) {
|
|
22
|
+
if (index.get(id)?.kind !== 'DICTIONARY')
|
|
23
|
+
throw new CadError('POINT_DICTIONARY', 'POINT扩展根需要字典记录', { point: point.handle, handle: id });
|
|
24
|
+
visit(id, point.handle);
|
|
25
|
+
}
|
|
26
|
+
const recordsJson = JSON.stringify(closure, (_key, value) => {
|
|
27
|
+
if (typeof value === 'number' && !Number.isFinite(value))
|
|
28
|
+
throw new CadError('POINT_DICTIONARY', 'POINT字典存在非有限数值');
|
|
29
|
+
return value;
|
|
30
|
+
});
|
|
31
|
+
return { format: 'XDTrace.NativePointDictionaryEvidence/1', sourceSha256, pointHandle: point.handle, dictionaryHandles: point.dictionaries,
|
|
32
|
+
semanticStatus: 'uninterpreted', recordsJson, sha256: createHash('sha256').update(recordsJson).digest('hex') };
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export function captureDwgPointDictionaries(model, sourceSha256) {
|
|
36
|
+
const entities = [...model.entities, ...model.tables.BLOCK_RECORD.entries.flatMap((b) => b.entities)];
|
|
37
|
+
const points = [...new Map(entities.filter((e) => e.type === 'POINT').map((e) => [handle(e.handle), e])).values()];
|
|
38
|
+
if (!points.some(e => e.ownerDictionaryHardId && e.ownerDictionaryHardId !== '0'))
|
|
39
|
+
return [];
|
|
40
|
+
const dictionaries = model.objects.DICTIONARY.map((raw) => ({ kind: 'DICTIONARY', handle: handle(raw.handle), ownerHandle: handle(raw.ownerHandle), raw,
|
|
41
|
+
entries: Object.entries(raw.entries).map(([name, id]) => ({ name, handle: handle(id) })) }));
|
|
42
|
+
const records = (model.objects.XRECORD || []).map((raw) => ({ kind: 'XRECORD', handle: handle(raw.handle), ownerHandle: handle(raw.ownerHandle), raw }));
|
|
43
|
+
return capture(points.map(e => ({ handle: handle(e.handle), dictionaries: e.ownerDictionaryHardId && e.ownerDictionaryHardId !== '0' ? [handle(e.ownerDictionaryHardId)] : [] })), [...dictionaries, ...records], sourceSha256);
|
|
44
|
+
}
|
|
45
|
+
export function captureDxfPointDictionaries(input, sourceSha256) {
|
|
46
|
+
const value = (r, code) => {
|
|
47
|
+
let depth = 0;
|
|
48
|
+
for (const p of r.pairs) {
|
|
49
|
+
if (p.code === 102) {
|
|
50
|
+
if (p.value.startsWith('{'))
|
|
51
|
+
depth++;
|
|
52
|
+
else if (p.value === '}')
|
|
53
|
+
depth--;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!depth && p.code === code)
|
|
57
|
+
return p.value;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const points = input.filter(r => r.type === 'POINT').map(r => {
|
|
61
|
+
const dictionaries = [];
|
|
62
|
+
let inside = false;
|
|
63
|
+
for (const p of r.pairs) {
|
|
64
|
+
if (p.code === 102) {
|
|
65
|
+
inside = p.value === '{ACAD_XDICTIONARY';
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (inside && p.code === 360)
|
|
69
|
+
dictionaries.push(handle(p.value));
|
|
70
|
+
}
|
|
71
|
+
return { handle: handle(value(r, 5)), dictionaries };
|
|
72
|
+
});
|
|
73
|
+
if (!points.some(p => p.dictionaries.length))
|
|
74
|
+
return [];
|
|
75
|
+
const records = input.filter(r => r.type === 'DICTIONARY' || r.type === 'XRECORD').map(r => {
|
|
76
|
+
const entries = [];
|
|
77
|
+
if (r.type === 'DICTIONARY')
|
|
78
|
+
for (const [i, p] of r.pairs.entries())
|
|
79
|
+
if (p.code === 3) {
|
|
80
|
+
const ref = r.pairs[i + 1];
|
|
81
|
+
if (!ref || ![350, 360].includes(ref.code))
|
|
82
|
+
throw new CadError('POINT_DICTIONARY', 'DXF字典条目缺少句柄');
|
|
83
|
+
entries.push({ name: p.value, handle: handle(ref.value) });
|
|
84
|
+
}
|
|
85
|
+
return { kind: r.type, handle: handle(value(r, 5)), ownerHandle: handle(value(r, 330)), raw: r.pairs.map(({ code, value, rawValue }) => ({ code, value: rawValue ?? value })), ...(r.type === 'DICTIONARY' ? { entries } : {}) };
|
|
86
|
+
});
|
|
87
|
+
return capture(points, records, sourceSha256);
|
|
88
|
+
}
|
package/src/readback.d.ts
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* database writer currently allocates colliding object handles. Consumers must
|
|
4
4
|
* allocate fresh handles and compare geometry and GROUP membership explicitly.
|
|
5
5
|
*/
|
|
6
|
-
export declare function readbackSnapshot(db: any, sourceSha256: string, textSize: number
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export declare function readbackSnapshot(db: any, sourceSha256: string, textSize: number, source?: {
|
|
7
|
+
block: any;
|
|
8
|
+
blocks: any[];
|
|
9
|
+
layout: string;
|
|
10
|
+
}): {
|
|
10
11
|
header: {
|
|
11
12
|
$INSUNITS: any;
|
|
12
13
|
$LTSCALE: any;
|
|
@@ -59,4 +60,11 @@ export declare function readbackSnapshot(db: any, sourceSha256: string, textSize
|
|
|
59
60
|
type: string;
|
|
60
61
|
dxf: any;
|
|
61
62
|
}[];
|
|
63
|
+
sourceSelection?: {
|
|
64
|
+
layout: string;
|
|
65
|
+
handles: string[];
|
|
66
|
+
} | undefined;
|
|
67
|
+
format: string;
|
|
68
|
+
version: number;
|
|
69
|
+
sourceSha256: string;
|
|
62
70
|
};
|
package/src/readback.js
CHANGED
|
@@ -6,7 +6,7 @@ const { AcDbDxfFiler } = createRequire(import.meta.url)('@mlightcad/data-model')
|
|
|
6
6
|
* database writer currently allocates colliding object handles. Consumers must
|
|
7
7
|
* allocate fresh handles and compare geometry and GROUP membership explicitly.
|
|
8
8
|
*/
|
|
9
|
-
export function readbackSnapshot(db, sourceSha256, textSize) {
|
|
9
|
+
export function readbackSnapshot(db, sourceSha256, textSize, source) {
|
|
10
10
|
const record = (item, type) => {
|
|
11
11
|
item = item.xdtraceReadbackOriginal ?? item;
|
|
12
12
|
const filer = new AcDbDxfFiler({ database: db, precision: 16, version: 'AC1032' });
|
|
@@ -61,19 +61,20 @@ export function readbackSnapshot(db, sourceSha256, textSize) {
|
|
|
61
61
|
return { handle: String(item.objectId).toUpperCase(), type, dxf: filer.toString() };
|
|
62
62
|
};
|
|
63
63
|
const blocks = [...db.tables.blockTable.newIterator()];
|
|
64
|
-
const model = db.tables.blockTable.modelSpace;
|
|
64
|
+
const model = source?.block || db.tables.blockTable.modelSpace;
|
|
65
65
|
const modelRecords = [...model.newIterator()];
|
|
66
|
-
const definitions = blocks.filter((block) => block !== model && !block.name.toUpperCase().startsWith('*PAPER_SPACE'));
|
|
66
|
+
const definitions = blocks.filter((block) => block !== model && block !== db.tables.blockTable.modelSpace && !block.name.toUpperCase().startsWith('*PAPER_SPACE') && (!source || source.blocks.includes(block)));
|
|
67
67
|
for (const block of blocks) {
|
|
68
|
-
if (block.name.toUpperCase().startsWith('*PAPER_SPACE') && [...block.newIterator()].length)
|
|
68
|
+
if (!source && block.name.toUpperCase().startsWith('*PAPER_SPACE') && [...block.newIterator()].length)
|
|
69
69
|
throw new CadError('READBACK_LAYOUT', '最终二维交付不能包含未映射的图纸空间实体');
|
|
70
|
-
if (block.isXref || block.isUnresolvedXref)
|
|
70
|
+
if ((!source || source.blocks.includes(block)) && (block.isXref || block.isUnresolvedXref))
|
|
71
71
|
throw new CadError('READBACK_XREF', '最终交付必须自包含,不能引用外部图纸');
|
|
72
72
|
}
|
|
73
73
|
return {
|
|
74
74
|
format: 'XDTrace.RecadReadback',
|
|
75
75
|
version: 1,
|
|
76
76
|
sourceSha256,
|
|
77
|
+
...(source ? { sourceSelection: { layout: source.layout, handles: modelRecords.map((r) => String(r.objectId).toUpperCase()) } } : {}),
|
|
77
78
|
header: {
|
|
78
79
|
$INSUNITS: db.insunits,
|
|
79
80
|
$LTSCALE: db.ltscale,
|
|
@@ -93,7 +94,7 @@ export function readbackSnapshot(db, sourceSha256, textSize) {
|
|
|
93
94
|
linetypes: [...db.tables.linetypeTable.newIterator()].map((item) => record(item, 'LTYPE')),
|
|
94
95
|
styles: [...db.tables.textStyleTable.newIterator()].map((item) => record(item, 'STYLE')),
|
|
95
96
|
},
|
|
96
|
-
groups: [...db.objects.group.entries()].map(([name, group]) => ({
|
|
97
|
+
groups: [...db.objects.group.entries()].filter(([, group]) => !source || [...group.entityIds].every(id => modelRecords.some((r) => String(r.objectId) === String(id)))).map(([name, group]) => ({
|
|
97
98
|
...record(group, 'GROUP'),
|
|
98
99
|
name,
|
|
99
100
|
description: group.name,
|
package/src/reader.d.ts
CHANGED
|
@@ -4,13 +4,23 @@ import { type RasterSource } from './raster-image.js';
|
|
|
4
4
|
import { type TextImportFields, type MTextImportFields } from './text/imports.js';
|
|
5
5
|
/** Read with the same independent decoder for root drawings and bundled dependencies.
|
|
6
6
|
* Keep omitted source fields until all references have been rebound. */
|
|
7
|
-
export declare function readDrawing(source: string, recover?: boolean, nativeEvidence?: boolean): Promise<{
|
|
7
|
+
export declare function readDrawing(source: string, recover?: boolean, nativeEvidence?: boolean, retainPointDictionaries?: boolean): Promise<{
|
|
8
8
|
db: any;
|
|
9
9
|
nativeCapture: import("./native-evidence.js").NativeCapture | undefined;
|
|
10
10
|
sourcePath: string;
|
|
11
11
|
sourceSha256: string;
|
|
12
12
|
isDwg: boolean;
|
|
13
13
|
dxf: {
|
|
14
|
+
pointDictionaryRecords: {
|
|
15
|
+
type: string;
|
|
16
|
+
pairs: {
|
|
17
|
+
code: number;
|
|
18
|
+
value: string;
|
|
19
|
+
line: number;
|
|
20
|
+
rawValue?: string;
|
|
21
|
+
}[];
|
|
22
|
+
section: string;
|
|
23
|
+
}[] | undefined;
|
|
14
24
|
blockMetadata: Map<string, BlockMetadata>;
|
|
15
25
|
blockClips: Map<string, BlockClip>;
|
|
16
26
|
xrefSettings: {
|
|
@@ -52,6 +62,7 @@ export declare function readDrawing(source: string, recover?: boolean, nativeEvi
|
|
|
52
62
|
decodeIssues: any[];
|
|
53
63
|
constraintGroups: any[];
|
|
54
64
|
applicationObjects: any[];
|
|
65
|
+
pointDictionaries: import("../protocol/src/native-evidence.js").CadPointDictionaryEvidence[];
|
|
55
66
|
dwgDecoder: {
|
|
56
67
|
revision: string;
|
|
57
68
|
wasmSha256: string;
|
package/src/reader.js
CHANGED
|
@@ -12,7 +12,9 @@ import { alignDwgDictionaries } from "./dwg-dictionaries.js";
|
|
|
12
12
|
import { inspectDxf } from "./dxf.js";
|
|
13
13
|
import { installReaderAdapters } from "./reader-adapters.js";
|
|
14
14
|
import { captureNativeEvidence } from "./native-evidence.js";
|
|
15
|
-
import {
|
|
15
|
+
import { captureCcObjects, validateCcOwnership } from "./vendor-object-data.js";
|
|
16
|
+
import { captureDwgPointDictionaries, captureDxfPointDictionaries } from "./point-dictionaries.js";
|
|
17
|
+
import { createDwgDecoder, readDwgBytes, dwgErrorFlags, normalizeDwgLineweights, normalizeDwgLayerPlotFlags, convertDwgWithArrays, } from "./dwg.js";
|
|
16
18
|
import { captureDwgLineTypes } from "./line-type.js";
|
|
17
19
|
import { captureDwgImages } from "./raster-image.js";
|
|
18
20
|
import { captureDwgText } from "./text/imports.js";
|
|
@@ -23,7 +25,7 @@ const { AcDbDatabase, AcDbDatabaseConverterManager, AcDbFileType, } = require('@
|
|
|
23
25
|
const { AcDbLibreDwgConverter } = require('@mlightcad/libredwg-converter');
|
|
24
26
|
/** Read with the same independent decoder for root drawings and bundled dependencies.
|
|
25
27
|
* Keep omitted source fields until all references have been rebound. */
|
|
26
|
-
export async function readDrawing(source, recover = false, nativeEvidence = false) {
|
|
28
|
+
export async function readDrawing(source, recover = false, nativeEvidence = false, retainPointDictionaries = false) {
|
|
27
29
|
const inputStat = statSync(source);
|
|
28
30
|
if (!inputStat.isFile() || !inputStat.size || inputStat.size > CAD_INPUT_LIMITS.inputBytes)
|
|
29
31
|
throw new CadError('INPUT_SIZE', 'CAD 输入必须是 1 字节至 200 MiB 的普通文件');
|
|
@@ -37,7 +39,9 @@ export async function readDrawing(source, recover = false, nativeEvidence = fals
|
|
|
37
39
|
const isDwg = extension === '.dwg';
|
|
38
40
|
if (isDwg && !/^AC10\d{2}$/.test(original.subarray(0, 6).toString('ascii')))
|
|
39
41
|
throw new CadError('INPUT_FORMAT', 'DWG 文件头无效');
|
|
40
|
-
const
|
|
42
|
+
const retainPoints = nativeEvidence || retainPointDictionaries;
|
|
43
|
+
const dxf = isDwg ? undefined : inspectDxf(original, retainPoints);
|
|
44
|
+
let pointDictionaries = dxf?.pointDictionaryRecords ? captureDxfPointDictionaries(dxf.pointDictionaryRecords, sourceSha256) : [];
|
|
41
45
|
const bytes = dxf?.bytes || original;
|
|
42
46
|
let dwgStats;
|
|
43
47
|
let decodeIssues = [];
|
|
@@ -93,7 +97,7 @@ export async function readDrawing(source, recover = false, nativeEvidence = fals
|
|
|
93
97
|
throw dwgFailure;
|
|
94
98
|
}
|
|
95
99
|
constraintGroups = captureConstraintGroups(module, pointer, sourceSha256, recover);
|
|
96
|
-
applicationObjects = captureApplicationObjects(module, pointer, sourceSha256);
|
|
100
|
+
applicationObjects = [...captureApplicationObjects(module, pointer, sourceSha256), ...captureCcObjects(module, pointer, original, sourceSha256, lib.dwg_get_codepage(pointer))];
|
|
97
101
|
let result;
|
|
98
102
|
try {
|
|
99
103
|
result = convertDwgWithArrays(lib, pointer, decodeIssues.filter((r) => r.quarantined));
|
|
@@ -107,6 +111,11 @@ export async function readDrawing(source, recover = false, nativeEvidence = fals
|
|
|
107
111
|
});
|
|
108
112
|
}
|
|
109
113
|
validateApplicationOwnership(applicationObjects, result.database);
|
|
114
|
+
validateCcOwnership(applicationObjects, result.database);
|
|
115
|
+
if (retainPoints)
|
|
116
|
+
pointDictionaries = captureDwgPointDictionaries(result.database, sourceSha256);
|
|
117
|
+
const retained = new Set(applicationObjects.filter(r => r.disposition === 'retained-data').map(r => r.handle));
|
|
118
|
+
decodeIssues = decodeIssues.map(issue => retained.has(issue.handle) ? { ...issue, retainedApplicationData: true } : issue);
|
|
110
119
|
captureDwgLeaders(result.database, lib, pointer);
|
|
111
120
|
dwgViewports = captureDwgViewports(result.database, lib, pointer);
|
|
112
121
|
const header = result.database.header;
|
|
@@ -177,6 +186,7 @@ export async function readDrawing(source, recover = false, nativeEvidence = fals
|
|
|
177
186
|
blockMetadata = classified.metadata;
|
|
178
187
|
blockClips = captureDwgBlockClips(result.database, extensions, extendedFilters, classified.filters);
|
|
179
188
|
normalizeDwgLineweights(result.database);
|
|
189
|
+
normalizeDwgLayerPlotFlags(result.database, original.subarray(0, 6).toString('ascii'));
|
|
180
190
|
captureDwgTextStyles(result.database, lib, module, pointer);
|
|
181
191
|
captureDwgLineTypes(result.database, lib, pointer);
|
|
182
192
|
dwgImages = captureDwgImages(result.database, lib, pointer);
|
|
@@ -235,13 +245,13 @@ export async function readDrawing(source, recover = false, nativeEvidence = fals
|
|
|
235
245
|
}
|
|
236
246
|
for (const item of blockMetadata.values())
|
|
237
247
|
item.sourceSha256 = sourceSha256;
|
|
238
|
-
const nativeCapture = nativeEvidence
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
248
|
+
const nativeCapture = nativeEvidence ? captureNativeEvidence(db, sourceSha256, {
|
|
249
|
+
textFields: dxf?.textFields ?? dwgTextFields, expected: dxf?.expected, decodeIssues,
|
|
250
|
+
}) : undefined;
|
|
251
|
+
if (nativeCapture && applicationObjects.length)
|
|
252
|
+
nativeCapture.documents[0].applicationObjects = structuredClone(applicationObjects);
|
|
253
|
+
if (nativeCapture && pointDictionaries.length)
|
|
254
|
+
nativeCapture.documents[0].pointDictionaries = pointDictionaries;
|
|
245
255
|
return {
|
|
246
256
|
db,
|
|
247
257
|
nativeCapture,
|
|
@@ -253,6 +263,7 @@ export async function readDrawing(source, recover = false, nativeEvidence = fals
|
|
|
253
263
|
decodeIssues,
|
|
254
264
|
constraintGroups,
|
|
255
265
|
applicationObjects,
|
|
266
|
+
pointDictionaries,
|
|
256
267
|
dwgDecoder,
|
|
257
268
|
dwgTextRecoveries,
|
|
258
269
|
dwgTextWarnings,
|
package/src/render-operation.js
CHANGED
|
@@ -3,7 +3,12 @@ import path from 'node:path';
|
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { collectedBounds } from "./layout-bounds.js";
|
|
5
5
|
import { suggestPlotRegions } from "./plot-regions.js";
|
|
6
|
-
import { sourceScene } from "./source-scene.js";
|
|
6
|
+
import { sourceScene, sceneJsonBytes } from "./source-scene.js";
|
|
7
|
+
import { sceneNativeDocuments } from "./native-evidence.js";
|
|
8
|
+
import { nativeEvidenceSummary } from 'zelos-recad/protocol/native-evidence';
|
|
9
|
+
import { textGlyphs } from "./text/glyphs.js";
|
|
10
|
+
import { textSceneGeometry } from "./text/scene-geometry.js";
|
|
11
|
+
import { sourceFontResources } from "./text/source-fonts.js";
|
|
7
12
|
import { viewportRoots } from "./layouts.js";
|
|
8
13
|
import { textInkBounds } from "./text/ink-bounds.js";
|
|
9
14
|
import { installTextAffineWriter } from "./text/affine-writer.js";
|
|
@@ -32,7 +37,7 @@ export async function renderCad(context) {
|
|
|
32
37
|
for (const entity of allRecords)
|
|
33
38
|
if (!activeHandles.has(String(entity.objectId).toUpperCase()))
|
|
34
39
|
entity.worldDraw = () => undefined;
|
|
35
|
-
|
|
40
|
+
let print = request.operation === 'render' && request.print !== 'auto'
|
|
36
41
|
? request.print
|
|
37
42
|
: renderSchema.parse({
|
|
38
43
|
paperWidthMm: 297,
|
|
@@ -40,7 +45,7 @@ export async function renderCad(context) {
|
|
|
40
45
|
window: { min: { x: 0, y: 0 }, max: { x: 297, y: 210 } },
|
|
41
46
|
png: false,
|
|
42
47
|
});
|
|
43
|
-
|
|
48
|
+
let plan = createPrintPlan(print);
|
|
44
49
|
installLineEndPolicy(print);
|
|
45
50
|
const blockingWarnings = warnings.filter((w) => !(recover && w.code === 'CONSTRAINT_SAVED_GEOMETRY'));
|
|
46
51
|
if (blockingWarnings.length)
|
|
@@ -234,7 +239,7 @@ export async function renderCad(context) {
|
|
|
234
239
|
renderer.ltscale = db.ltscale;
|
|
235
240
|
renderer.celtscale = db.celtscale;
|
|
236
241
|
renderer.showLineWeight = true;
|
|
237
|
-
|
|
242
|
+
const exportOptions = {
|
|
238
243
|
paper: { widthMm: plan.nativePageMm.width, heightMm: plan.nativePageMm.height },
|
|
239
244
|
fitBox: identityPaperFrame(plan),
|
|
240
245
|
background: 'none',
|
|
@@ -255,7 +260,8 @@ export async function renderCad(context) {
|
|
|
255
260
|
throw new CadError('SHAPE_UNSUPPORTED', 'SHX/SHAPE 字形引擎尚未接入');
|
|
256
261
|
},
|
|
257
262
|
},
|
|
258
|
-
}
|
|
263
|
+
};
|
|
264
|
+
renderer.configureExport(exportOptions);
|
|
259
265
|
renderer.textFontManager = fontManager;
|
|
260
266
|
renderer.currentBackgroundColor = 0xffffff;
|
|
261
267
|
renderer.changeForeground(0x000000);
|
|
@@ -331,7 +337,8 @@ export async function renderCad(context) {
|
|
|
331
337
|
if (!settled)
|
|
332
338
|
throw new CadError('RENDER_UNSETTLED', '嵌套图形或字体未完成加载');
|
|
333
339
|
const bounds = { min: { x: Infinity, y: Infinity }, max: { x: -Infinity, y: -Infinity } };
|
|
334
|
-
const
|
|
340
|
+
const glyphs = textGlyphs(fontManager);
|
|
341
|
+
const textInk = textInkBounds(glyphs);
|
|
335
342
|
report.layoutObjects = [];
|
|
336
343
|
for (const root of roots) {
|
|
337
344
|
if (root.box.isEmpty())
|
|
@@ -379,9 +386,12 @@ export async function renderCad(context) {
|
|
|
379
386
|
report.resourcesManifestSha256 = assets.manifestSha256;
|
|
380
387
|
report.images = [...assets.images].map(([name, e]) => ({ name, sha256: e.sha256 }));
|
|
381
388
|
if (request.operation === 'scene') {
|
|
389
|
+
if (request.fontResources)
|
|
390
|
+
report.artifacts.push(...sourceFontResources(assets.fonts, new Set(usedFonts.keys()), options.output));
|
|
382
391
|
const scene = sourceScene(roots, db, textInk, {
|
|
383
392
|
layout: selection.selected.name,
|
|
384
393
|
space: selection.selected,
|
|
394
|
+
sheetMode: request.sheetMode,
|
|
385
395
|
sourceSha256,
|
|
386
396
|
engine: report.engine,
|
|
387
397
|
resourcesManifestSha256: assets.manifestSha256,
|
|
@@ -390,8 +400,18 @@ export async function renderCad(context) {
|
|
|
390
400
|
omissions: report.omissions,
|
|
391
401
|
fontSubstitutions: report.fontSubstitutions,
|
|
392
402
|
textOmissions: report.textOmissions,
|
|
393
|
-
}, drawing.nativeCapture);
|
|
403
|
+
}, drawing.nativeCapture, request.textGeometry ? textSceneGeometry(glyphs) : undefined);
|
|
394
404
|
const file = path.join(options.output, 'scene.json');
|
|
405
|
+
const beforeBytes = sceneJsonBytes(scene);
|
|
406
|
+
if (beforeBytes > 160 * 1024 * 1024 && scene.nativeEvidence) {
|
|
407
|
+
scene.nativeEvidence.documents = sceneNativeDocuments(scene.nativeEvidence.documents, scene.nativeEvidence.instances.map((instance) => instance.recordId));
|
|
408
|
+
nativeEvidenceSummary(scene, sourceSha256);
|
|
409
|
+
if (drawing.nativeCapture)
|
|
410
|
+
drawing.nativeCapture.documents = scene.nativeEvidence.documents;
|
|
411
|
+
report.nativeSceneSelection = { basis: 'scene-referenced-block-closure', beforeBytes, afterBytes: sceneJsonBytes(scene) };
|
|
412
|
+
}
|
|
413
|
+
if ((report.nativeSceneSelection?.afterBytes ?? beforeBytes) > 160 * 1024 * 1024)
|
|
414
|
+
throw new CadError('SCENE_LIMIT', '源场景超过 160 MiB 成果预算');
|
|
395
415
|
const bytes = Buffer.from(JSON.stringify(scene));
|
|
396
416
|
if (bytes.length > 160 * 1024 * 1024)
|
|
397
417
|
throw new CadError('SCENE_LIMIT', '源场景超过 160 MiB 成果预算');
|
|
@@ -401,6 +421,15 @@ export async function renderCad(context) {
|
|
|
401
421
|
}
|
|
402
422
|
return;
|
|
403
423
|
}
|
|
424
|
+
if (request.operation === 'render' && request.print === 'auto') {
|
|
425
|
+
print = renderSchema.parse(report.suggestedPrint.overview);
|
|
426
|
+
plan = createPrintPlan(print);
|
|
427
|
+
renderer.configureExport({ ...exportOptions,
|
|
428
|
+
paper: { widthMm: plan.nativePageMm.width, heightMm: plan.nativePageMm.height },
|
|
429
|
+
fitBox: identityPaperFrame(plan),
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
report.printSelection = request.operation === 'render' && request.print === 'auto' ? 'auto-overview' : 'explicit';
|
|
404
433
|
const prepared = preparePlotRoots(roots, db, plan);
|
|
405
434
|
report.excludedFromPlot = prepared.excluded;
|
|
406
435
|
const boundPlan = {
|
package/src/runner.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { spawnTemporary } from "../shared/service-storage/src/process-temp.js";
|
|
2
3
|
import { readFileSync, appendFileSync, mkdirSync, renameSync, statSync } from 'node:fs';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
@@ -6,7 +7,7 @@ import { promisify } from 'node:util';
|
|
|
6
7
|
import { CadError } from "./contracts.js";
|
|
7
8
|
import { writeJson, hashFile } from "./io.js";
|
|
8
9
|
import { runtimePython } from "./runtime-paths.js";
|
|
9
|
-
import { cadErrorRecord, classifyDwgFailure,
|
|
10
|
+
import { cadErrorRecord, classifyDwgFailure, isDrawingArtifact, } from "./dwg-fallback.js";
|
|
10
11
|
// An explicit dependency lets regression tests inject a source-import failure
|
|
11
12
|
// while retaining the real isolated conversion/read workers. HTTP inputs never
|
|
12
13
|
// select an executor or enable fault injection.
|
|
@@ -108,7 +109,7 @@ export function createWorkerRunner(executePhase = runWorkerOnce) {
|
|
|
108
109
|
unchanged();
|
|
109
110
|
remaining();
|
|
110
111
|
for (const artifact of result.artifacts) {
|
|
111
|
-
if (!
|
|
112
|
+
if (!isDrawingArtifact(artifact.name))
|
|
112
113
|
throw new CadError('ARTIFACT_NAME', '工作进程返回了未知成果');
|
|
113
114
|
const file = path.join(readDir, artifact.name);
|
|
114
115
|
if (hashFile(file) !== artifact.sha256 || statSync(file).size !== artifact.bytes)
|
|
@@ -176,7 +177,7 @@ export async function runWorkerOnce(options, controls) {
|
|
|
176
177
|
const requestFile = path.join(options.output, 'request.json');
|
|
177
178
|
writeJson(requestFile, options);
|
|
178
179
|
const entry = fileURLToPath(new URL(import.meta.url.endsWith('.ts') ? './worker.ts' : './worker.js', import.meta.url));
|
|
179
|
-
const child =
|
|
180
|
+
const child = spawnTemporary(options.output)(process.execPath, [
|
|
180
181
|
'--max-old-space-size=768',
|
|
181
182
|
...(import.meta.url.endsWith('.ts') ? ['--import', import.meta.resolve('tsx')] : []),
|
|
182
183
|
entry,
|
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
fileName: string;
|
|
8
|
-
accessedAt: number;
|
|
9
|
-
}
|
|
10
|
-
export declare class DocumentStore {
|
|
11
|
-
private data;
|
|
12
|
-
private retentionMs;
|
|
13
|
-
private maxStorageBytes;
|
|
14
|
-
readonly root: string;
|
|
1
|
+
import { DocumentStore as SharedDocumentStore, type StoredDocument } from '../../shared/service-storage/src/documents.js';
|
|
2
|
+
import type { StorageQuota } from '../../shared/service-storage/src/quota.js';
|
|
3
|
+
import type { Readable } from 'node:stream';
|
|
4
|
+
export type { StoredDocument } from '../../shared/service-storage/src/documents.js';
|
|
5
|
+
/** Shared document persistence; the public runtime owns upload cancellation and close. */
|
|
6
|
+
export declare class DocumentStore extends SharedDocumentStore {
|
|
15
7
|
private closed;
|
|
16
8
|
private readonly uploads;
|
|
17
|
-
|
|
18
|
-
constructor(data: string, retentionMs?: number, maxStorageBytes?: number);
|
|
19
|
-
close(): Promise<void>;
|
|
20
|
-
get(id: string): StoredDocument;
|
|
9
|
+
constructor(data: string, retentionMs?: number, maxStorageBytes?: number, quota?: StorageQuota);
|
|
21
10
|
upload(stream: Readable, fileName?: string): Promise<StoredDocument>;
|
|
22
|
-
|
|
23
|
-
private cleanup;
|
|
11
|
+
close(): Promise<void>;
|
|
24
12
|
}
|