any2orca 0.7.3 → 0.9.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/NOTICE +11 -5
  3. package/README.md +5 -3
  4. package/dist/archive/lookupFilamentColorName.d.ts +4 -1
  5. package/dist/archive/zip.js +1 -1
  6. package/dist/cli/commands/diff.js +5 -4
  7. package/dist/cli/main.js +1 -1
  8. package/dist/diff/diffSettings.d.ts +9 -2
  9. package/dist/diff/diffSettings.js +9 -0
  10. package/dist/diff/reference.d.ts +8 -1
  11. package/dist/diff/reference.js +11 -2
  12. package/dist/diff/valueLayout.d.ts +5 -2
  13. package/dist/diff/valueLayout.js +7 -2
  14. package/dist/engine/detectNozzleDiameter.d.ts +3 -1
  15. package/dist/errors.d.ts +4 -1
  16. package/dist/errors.js +23 -0
  17. package/dist/explain/whatChanged.d.ts +5 -1
  18. package/dist/explain/whatChanged.js +2 -0
  19. package/dist/index.d.ts +29 -30
  20. package/dist/index.js +16 -19
  21. package/dist/inspect.d.ts +9 -3
  22. package/dist/inspect.js +11 -5
  23. package/dist/presets/extractPreset.js +2 -2
  24. package/dist/presets/preset.d.ts +1 -1
  25. package/dist/presets/preset.js +7 -1
  26. package/dist/profiles.d.ts +74 -5
  27. package/dist/profiles.js +14 -0
  28. package/dist/project.d.ts +5 -1
  29. package/dist/project.js +4 -2
  30. package/dist/schema.d.ts +32 -5
  31. package/dist/schema.js +3 -1
  32. package/dist/sources/bambuFamily.js +1 -1
  33. package/dist/sources/prusa/policyB.d.ts +1 -1
  34. package/dist/sources/prusa/policyB.js +2 -1
  35. package/dist/sources/reader.d.ts +5 -2
  36. package/dist/sources/reader.js +2 -1
  37. package/dist/stamp.d.ts +40 -1
  38. package/dist/stamp.js +5 -3
  39. package/dist/telemetry.d.ts +37 -3
  40. package/dist/telemetry.js +32 -6
  41. package/dist/version.d.ts +1 -1
  42. package/dist/version.js +1 -1
  43. package/dist/worker-entry.js +2 -3
  44. package/package.json +5 -4
@@ -2,7 +2,7 @@
2
2
  import { sameSetting } from "../diff/diffSettings.js";
3
3
  import { SETTINGS_CATALOG } from "../diff/settingsCatalog.js";
4
4
  import { Any2orcaError } from "../errors.js";
5
- import { loadCatalog } from "../profiles.js";
5
+ import { catalogEngine, loadCatalog } from "../profiles.js";
6
6
  import { Project } from "../project.js";
7
7
  import { checkedChanges, describeChanges, stockValue } from "./preset.js";
8
8
  import { isPresetKey } from "./presetKeys.js";
@@ -56,7 +56,7 @@ export async function extractPreset(input, options) {
56
56
  baseInferred = true;
57
57
  notes.push(`The project doesn't name a U1 profile; it's compared with ${catalog.get(base)?.displayName}, the closest match for its nozzle and layer height.`);
58
58
  }
59
- const loaded = await catalog.load(base);
59
+ const loaded = await catalogEngine(catalog).load(base);
60
60
  const stock = loaded.convertProfile.profile.baselineProjectSettings;
61
61
  const differing = {};
62
62
  for (const key of Object.keys(settings)) {
@@ -17,7 +17,7 @@
17
17
  import "../zodSetup.js";
18
18
  import { z } from "zod";
19
19
  import type { JsonRecord } from "../engine/types.js";
20
- import type { ProfileCatalog } from "../profiles.js";
20
+ import { type ProfileCatalog } from "../profiles.js";
21
21
  export declare const MAX_PRESET_NAME_LENGTH = 40;
22
22
  export declare const MAX_PRESETS_PER_FILE = 100;
23
23
  export declare const MAX_PRESETS_FILE_BYTES: number;
@@ -22,6 +22,7 @@ import { SETTINGS_CATALOG } from "../diff/settingsCatalog.js";
22
22
  import { machineLimitFor } from "../engine/aboveStock.js";
23
23
  import { VARIANT_PROCESS_KEYS } from "../engine/applyHighFlowHotends.js";
24
24
  import { Any2orcaError } from "../errors.js";
25
+ import { catalogEngine } from "../profiles.js";
25
26
  import { isPresetKey, PRESET_EXCLUDED_KEYS, PRESET_KEYS } from "./presetKeys.js";
26
27
  export const MAX_PRESET_NAME_LENGTH = 40;
27
28
  export const MAX_PRESETS_PER_FILE = 100;
@@ -168,7 +169,7 @@ export async function resolvePreset(preset, catalog) {
168
169
  }
169
170
  if (!catalog.get(profileId))
170
171
  throw new Any2orcaError("invalid_preset", `The preset's base profile "${profileId}" isn't in the profile catalog.`);
171
- const loaded = await catalog.load(profileId);
172
+ const loaded = await catalogEngine(catalog).load(profileId);
172
173
  const stock = loaded.convertProfile.profile.baselineProjectSettings;
173
174
  const changes = checkedChanges(parsed.data.changes, stock, notes);
174
175
  return { profileId, changes, described: describeChanges(changes, stock, loaded.convertProfile.printer.machineSettingsConfig), notes };
@@ -262,6 +263,11 @@ export function parsePresetFile(input) {
262
263
  throw new Any2orcaError("invalid_preset", "This isn't a presets file: it isn't valid JSON.");
263
264
  }
264
265
  assertPlainJson(raw, 0);
266
+ // A file this format's later version wrote: say so, rather than "not valid".
267
+ const header = typeof raw === "object" && raw !== null ? raw : {};
268
+ if (header.format === "any2orca-presets" && typeof header.version === "number" && Number.isInteger(header.version) && header.version > 1) {
269
+ throw new Any2orcaError("invalid_preset", `This presets file was saved by a newer any2orca (format version ${header.version}). Update any2orca to open it.`);
270
+ }
265
271
  const parsed = PresetFileSchema.safeParse(raw);
266
272
  if (!parsed.success)
267
273
  throw new Any2orcaError("invalid_preset", `This isn't a valid presets file: ${describeIssues(parsed.error)}`);
@@ -22,6 +22,7 @@ import { z } from "zod";
22
22
  import { type PrusaBundle } from "./sources/prusa/bundle.js";
23
23
  import { Any2orcaError } from "./errors.js";
24
24
  import type { ConvertProfile } from "./engine/runConvertPipeline.js";
25
+ import type { FilamentNameTable } from "./engine/filamentComplianceNames.js";
25
26
  /** Raw access to a catalog. Both methods return parsed JSON; the core validates it. */
26
27
  export interface ProfileSource {
27
28
  /** The catalog index (`index.json`). */
@@ -31,13 +32,13 @@ export interface ProfileSource {
31
32
  /**
32
33
  * The source for an older release this catalog holds, in the folder at
33
34
  * `path` (from index.json `releases`, always `releases/<version>`). Only
34
- * called with a path that passes {@link isReleasePath}. Leave it out for a
35
+ * called with a path of the form `releases/<x.y.z>`. Leave it out for a
35
36
  * catalog with one release.
36
37
  */
37
38
  release?(path: string): ProfileSource;
38
39
  /**
39
40
  * One source-slicer data file (`sources/prusaslicer/<Vendor>.json`). Only
40
- * called with a path the index lists, which passes {@link isSourcePath}.
41
+ * called with a path the index lists (`sources/prusaslicer/<Vendor>-<version>.json`).
41
42
  * Leave it out for a source without such data: a PrusaSlicer project is
42
43
  * then converted with every mapped setting treated as changed.
43
44
  */
@@ -128,7 +129,66 @@ export declare const ProfileIndexSchema: z.ZodObject<{
128
129
  }, z.core.$strip>>;
129
130
  }, z.core.$strip>>;
130
131
  }, z.core.$strip>;
131
- export type ProfileIndex = z.infer<typeof ProfileIndexSchema>;
132
+ /** A printer the catalog has profiles for. */
133
+ export interface ProfileIndexPrinter {
134
+ id: string;
135
+ displayName: string;
136
+ nozzleDiameter: string;
137
+ highFlowSupported: boolean;
138
+ }
139
+ /** A profile as the index lists it. */
140
+ export interface ProfileIndexProfile {
141
+ id: string;
142
+ printerId: string;
143
+ displayName: string;
144
+ nozzleDiameter: string;
145
+ layerHeight: number;
146
+ autoSelectable: boolean;
147
+ highFlowSpeeds: boolean;
148
+ }
149
+ /** A Snapmaker Orca release the catalog holds: this index's own (`path` ".") or an older one's folder. */
150
+ export interface ProfileIndexRelease {
151
+ version: string;
152
+ application: string;
153
+ path: string;
154
+ }
155
+ /** A source-slicer data file the catalog holds (PrusaSlicer's vendor preset bundles). */
156
+ export interface ProfileIndexSource {
157
+ vendor: string;
158
+ name: string;
159
+ path: string;
160
+ slicerVersion: string;
161
+ configVersion: string;
162
+ slicerTag: string;
163
+ }
164
+ /** A catalog's `index.json`, as {@link loadCatalog} checks it. */
165
+ export interface ProfileIndex {
166
+ schema: 1;
167
+ dataVersion: string;
168
+ slicer: {
169
+ name: string;
170
+ version: string;
171
+ application: string;
172
+ };
173
+ /** Where the profiles come from: the target slicer's repository and the release tag and commit they were generated at. */
174
+ source?: {
175
+ repository: string;
176
+ tag: string;
177
+ commit: string;
178
+ };
179
+ defaultProfileId: string;
180
+ printers: ProfileIndexPrinter[];
181
+ profiles: ProfileIndexProfile[];
182
+ retired: RetiredProfile[];
183
+ /** Filament preset names for the Snapmaker/Generic naming options, per printer. */
184
+ filamentNames?: FilamentNameTable;
185
+ /** Every Snapmaker Orca release this catalog holds, newest first. Absent in a catalog with one release. */
186
+ releases?: ProfileIndexRelease[];
187
+ /** Source-slicer data the catalog holds, independent of the Snapmaker Orca release. Absent in older data. */
188
+ sources?: {
189
+ prusaslicer: ProfileIndexSource[];
190
+ };
191
+ }
132
192
  export declare const ProfileFileSchema: z.ZodObject<{
133
193
  schema: z.ZodLiteral<1>;
134
194
  id: z.ZodString;
@@ -186,6 +246,15 @@ export interface LoadedProfile {
186
246
  summary: ProfileSummary;
187
247
  convertProfile: ConvertProfile;
188
248
  }
249
+ /** The engine's side of a catalog: what a conversion runs on. Reached with {@link catalogEngine}; not part of the public API. */
250
+ export interface CatalogEngine {
251
+ load(id: string): Promise<LoadedProfile>;
252
+ prusaBundle(vendor: string, slicerVersion: string): Promise<PrusaBundle | null>;
253
+ }
254
+ /** For tests: gives a stand-in catalog an engine side. */
255
+ export declare function withCatalogEngine<T extends object>(catalog: T, engine: Partial<CatalogEngine>): T;
256
+ /** The engine's access to a catalog. Kept off the class, so the public API holds only what a UI needs. */
257
+ export declare function catalogEngine(catalog: ProfileCatalog): CatalogEngine;
189
258
  /** The catalog itself is missing or malformed (code `profile_data`). */
190
259
  export declare class ProfileDataError extends Any2orcaError {
191
260
  constructor(message: string);
@@ -221,7 +290,7 @@ export declare class ProfileCatalog {
221
290
  * One PrusaSlicer vendor bundle, loaded and checked once, or null when the
222
291
  * catalog doesn't list it or its source can't read source data.
223
292
  */
224
- prusaBundle(vendor: string, slicerVersion: string): Promise<PrusaBundle | null>;
293
+ private prusaBundle;
225
294
  /** The live profile that replaced a retired id, if `id` was retired. */
226
295
  retiredSuccessor(id: string): RetiredProfile | undefined;
227
296
  /** The Snapmaker Orca releases this catalog holds, newest first. The first is the default. */
@@ -234,7 +303,7 @@ export declare class ProfileCatalog {
234
303
  */
235
304
  forRelease(version: string): Promise<ProfileCatalog>;
236
305
  /** Loads and validates one profile. Throws for an id the catalog doesn't list. */
237
- load(id: string): Promise<LoadedProfile>;
306
+ private load;
238
307
  }
239
308
  /** Reads and validates a source's index. Cached per source object. */
240
309
  export declare function loadCatalog(source: ProfileSource | ProfileCatalog): Promise<ProfileCatalog>;
package/dist/profiles.js CHANGED
@@ -141,6 +141,19 @@ export const ProfileFileSchema = z.object({
141
141
  filamentShape: settings,
142
142
  highFlowOverrides: z.record(z.string().max(200), z.string().max(200)),
143
143
  });
144
+ const ENGINES = new WeakMap();
145
+ /** For tests: gives a stand-in catalog an engine side. */
146
+ export function withCatalogEngine(catalog, engine) {
147
+ ENGINES.set(catalog, { load: () => Promise.reject(new ProfileDataError("No profiles in this stand-in.")), prusaBundle: () => Promise.resolve(null), ...engine });
148
+ return catalog;
149
+ }
150
+ /** The engine's access to a catalog. Kept off the class, so the public API holds only what a UI needs. */
151
+ export function catalogEngine(catalog) {
152
+ const engine = ENGINES.get(catalog);
153
+ if (!engine)
154
+ throw new ProfileDataError("Not a profile catalog.");
155
+ return engine;
156
+ }
144
157
  /** The catalog itself is missing or malformed (code `profile_data`). */
145
158
  export class ProfileDataError extends Any2orcaError {
146
159
  constructor(message) {
@@ -167,6 +180,7 @@ export class ProfileCatalog {
167
180
  releaseCatalogs = new Map();
168
181
  bundles = new Map();
169
182
  constructor(index, source) {
183
+ ENGINES.set(this, { load: (id) => this.load(id), prusaBundle: (vendor, slicerVersion) => this.prusaBundle(vendor, slicerVersion) });
170
184
  this.index = index;
171
185
  this.source = source;
172
186
  if (index.releases) {
package/dist/project.d.ts CHANGED
@@ -70,7 +70,11 @@ export interface ConvertOptions {
70
70
  /** Called as the conversion moves through its steps, for a progress display. */
71
71
  onProgress?: (stage: ConvertStage) => void;
72
72
  }
73
- export type ConvertStage = "matching" | "loading-profile" | "merging" | "writing";
73
+ /** The steps of a conversion, in order. */
74
+ export declare const CONVERT_STAGES: readonly ["matching", "loading-profile", "merging", "writing"];
75
+ export type KnownConvertStage = (typeof CONVERT_STAGES)[number];
76
+ /** One of {@link CONVERT_STAGES}, or a step a later any2orca release added: a progress display can show one it doesn't recognize as it is. */
77
+ export type ConvertStage = KnownConvertStage | (string & {});
74
78
  /**
75
79
  * One filament slot of the converted file, in the file's own order. Every
76
80
  * filament is kept, however many: the U1 loads four at a time, but a project,
package/dist/project.js CHANGED
@@ -19,13 +19,15 @@ import { diffSettings } from "./diff/diffSettings.js";
19
19
  import { Any2orcaError } from "./errors.js";
20
20
  import { toWhatChanged } from "./explain/whatChanged.js";
21
21
  import { inspectProject } from "./inspect.js";
22
- import { loadCatalog, ProfileCatalog } from "./profiles.js";
22
+ import { catalogEngine, loadCatalog, ProfileCatalog } from "./profiles.js";
23
23
  import { ConvertRequestSchema, ConvertResponseSchema, HighFlowHotendsSchema, } from "./schema.js";
24
24
  import { resolveAboveStockChoice } from "./engine/aboveStock.js";
25
25
  import { presetFingerprint, resolvePreset } from "./presets/preset.js";
26
26
  import { encodeStamp, STAMP_PATH } from "./stamp.js";
27
27
  import { plainText } from "./plainText.js";
28
28
  import { VERSION } from "./version.js";
29
+ /** The steps of a conversion, in order. */
30
+ export const CONVERT_STAGES = ["matching", "loading-profile", "merging", "writing"];
29
31
  function numericLayerHeight(projectSettings) {
30
32
  const raw = projectSettings.layer_height;
31
33
  const value = typeof raw === "string" ? Number(raw.trim()) : typeof raw === "number" ? raw : NaN;
@@ -242,7 +244,7 @@ export class Project {
242
244
  routeWarnings.push(...choice.notes.map((note) => ` WARN: ${note}`));
243
245
  }
244
246
  progress("loading-profile");
245
- const loaded = await catalog.load(profileId);
247
+ const loaded = await catalogEngine(catalog).load(profileId);
246
248
  progress("merging");
247
249
  if (preset) {
248
250
  const sourceNozzle = detectNozzleDiameter(this.request.projectSettings);
package/dist/schema.d.ts CHANGED
@@ -16,7 +16,19 @@ export declare const ConvertObjectSchema: z.ZodObject<{
16
16
  bbox: z.ZodNullable<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
17
17
  fallbackXy: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
18
18
  }, z.core.$strip>;
19
- export type ConvertObject = z.infer<typeof ConvertObjectSchema>;
19
+ /** A single top-level object's plate assignment and computed bounding box. */
20
+ export interface ConvertObject {
21
+ id: string;
22
+ name?: string;
23
+ sequence?: number;
24
+ isAssembly?: boolean;
25
+ /** Omitted for objects with no plate metadata. */
26
+ plate?: number;
27
+ /** [minX, maxX, minY, maxY], or null when no mesh geometry was found for this object. */
28
+ bbox: [number, number, number, number] | null;
29
+ /** The item transform's raw translation, set only when bbox is null. */
30
+ fallbackXy?: [number, number];
31
+ }
20
32
  /**
21
33
  * A parsed Metadata/project_settings.config: hundreds of slicer settings,
22
34
  * so open-shaped by key, with a cap on its serialized size. A real one runs
@@ -33,7 +45,8 @@ export declare const FilamentComplianceModeSchema: z.ZodEnum<{
33
45
  }>;
34
46
  /** `true` for every toolhead, or exactly one entry per U1 toolhead, T1 to T4. */
35
47
  export declare const HighFlowHotendsSchema: z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodBoolean>]>;
36
- export type HighFlowHotends = z.infer<typeof HighFlowHotendsSchema>;
48
+ /** `true` for every toolhead, or exactly one entry per U1 toolhead, T1 to T4. */
49
+ export type HighFlowHotends = boolean | boolean[];
37
50
  export declare const ConvertRequestSchema: z.ZodObject<{
38
51
  projectSettings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
39
52
  objects: z.ZodArray<z.ZodObject<{
@@ -60,14 +73,19 @@ export declare const ConfigFilesSchema: z.ZodRecord<z.ZodString, z.ZodRecord<z.Z
60
73
  export type ConfigFiles = z.infer<typeof ConfigFilesSchema>;
61
74
  /** objectId -> [dx, dy] shift to apply to that object's transform. */
62
75
  export declare const ShiftsSchema: z.ZodRecord<z.ZodString, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
63
- export type Shifts = z.infer<typeof ShiftsSchema>;
76
+ /** objectId -> [dx, dy] shift to apply to that object's transform. */
77
+ export type Shifts = Record<string, [number, number]>;
78
+ /** How a profile was picked, most confident first. */
79
+ export declare const MATCH_SOURCES: readonly ["auto-tier-name", "auto-exact", "auto-nearest", "default-fallback"];
64
80
  export declare const MatchSourceSchema: z.ZodEnum<{
65
81
  "auto-tier-name": "auto-tier-name";
66
82
  "auto-exact": "auto-exact";
67
83
  "auto-nearest": "auto-nearest";
68
84
  "default-fallback": "default-fallback";
69
85
  }>;
70
- export type MatchSource = z.infer<typeof MatchSourceSchema>;
86
+ export type KnownMatchSource = (typeof MATCH_SOURCES)[number];
87
+ /** One of {@link MATCH_SOURCES}, or a way a later any2orca release added: treat one you don't recognize like "auto-nearest". */
88
+ export type MatchSource = KnownMatchSource | (string & {});
71
89
  export declare const ProfileMatchSchema: z.ZodObject<{
72
90
  profileId: z.ZodString;
73
91
  nozzleDiameter: z.ZodString;
@@ -80,7 +98,16 @@ export declare const ProfileMatchSchema: z.ZodObject<{
80
98
  "default-fallback": "default-fallback";
81
99
  }>;
82
100
  }, z.core.$strip>;
83
- export type ProfileMatch = z.infer<typeof ProfileMatchSchema>;
101
+ /** How the profile for a conversion was chosen. */
102
+ export interface ProfileMatch {
103
+ profileId: string;
104
+ nozzleDiameter: string;
105
+ exact: boolean;
106
+ /** The pick came from the source file's own tier name (e.g. "Extra Fine"), not nearest layer height. */
107
+ matchedByTierName: boolean;
108
+ /** See {@link MatchSource}: "auto-tier-name" and "auto-exact" are confident, "auto-nearest" the closest layer height, "default-fallback" no match at all. */
109
+ matchSource: MatchSource;
110
+ }
84
111
  export declare const ConvertResponseSchema: z.ZodObject<{
85
112
  projectSettings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
86
113
  configFiles: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>;
package/dist/schema.js CHANGED
@@ -62,7 +62,9 @@ export const ConvertRequestSchema = z.object({
62
62
  export const ConfigFilesSchema = z.record(z.string(), z.record(z.string(), z.unknown()));
63
63
  /** objectId -> [dx, dy] shift to apply to that object's transform. */
64
64
  export const ShiftsSchema = z.record(z.string(), z.tuple([z.number(), z.number()]));
65
- export const MatchSourceSchema = z.enum(["auto-tier-name", "auto-exact", "auto-nearest", "default-fallback"]);
65
+ /** How a profile was picked, most confident first. */
66
+ export const MATCH_SOURCES = ["auto-tier-name", "auto-exact", "auto-nearest", "default-fallback"];
67
+ export const MatchSourceSchema = z.enum(MATCH_SOURCES);
66
68
  export const ProfileMatchSchema = z.object({
67
69
  profileId: z.string(),
68
70
  nozzleDiameter: z.string(),
@@ -1,7 +1,7 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  /**
3
3
  * The reader for Bambu Studio and the slicers built on it (Creality Print,
4
- * Anycubic Slicer Next, ElegooSlicer, Flash Studio): a project's settings are
4
+ * Anycubic Slicer Next, ElegooSlicer, Flash Studio, QIDI Studio): a project's settings are
5
5
  * JSON in `Metadata/project_settings.config`, per-object settings and plates
6
6
  * in `Metadata/model_settings.config`, the build in `3D/3dmodel.model`.
7
7
  */
@@ -1,4 +1,4 @@
1
- import type { ProfileCatalog } from "../../profiles.js";
1
+ import { type ProfileCatalog } from "../../profiles.js";
2
2
  import type { ProjectSettings } from "../../schema.js";
3
3
  import type { PrusaProjectInfo } from "../reader.js";
4
4
  import type { PrusaBundle } from "./bundle.js";
@@ -10,6 +10,7 @@
10
10
  * side. Filament values are carried whole, as for every source.
11
11
  */
12
12
  import { SETTINGS_CATALOG } from "../../diff/settingsCatalog.js";
13
+ import { catalogEngine } from "../../profiles.js";
13
14
  import { lookupPrintPresetName, resolvePrintPreset } from "./bundle.js";
14
15
  /** PrusaSlicer keys that identify or describe a preset, never a print setting a creator "changes". */
15
16
  const NOT_COMPARED = new Set(["print_settings_id", "inherits", "compatible_printers", "compatible_printers_condition", "renamed_from", "alias", "notes"]);
@@ -124,7 +125,7 @@ export async function applyPolicyB(prusa, catalog, projectSettings) {
124
125
  // the next bundle is tried, and the fallback carries every mapped print setting, with the note saying so.
125
126
  let bundle;
126
127
  try {
127
- bundle = await catalog.prusaBundle(entry.vendor, entry.slicerVersion);
128
+ bundle = await catalogEngine(catalog).prusaBundle(entry.vendor, entry.slicerVersion);
128
129
  }
129
130
  catch {
130
131
  bundle = null;
@@ -10,8 +10,11 @@
10
10
  * Readers are tried in order; the first whose `detect` says yes reads the file.
11
11
  */
12
12
  import type { ConvertRequest } from "../schema.js";
13
- /** The slicer family a project came from. */
14
- export type SourceFormat = "bambu-family" | "prusaslicer";
13
+ /** The file formats any2orca reads: Bambu Studio's and the slicers built on it, and PrusaSlicer's. */
14
+ export declare const SOURCE_FORMATS: readonly ["bambu-family", "prusaslicer"];
15
+ export type KnownSourceFormat = (typeof SOURCE_FORMATS)[number];
16
+ /** One of {@link SOURCE_FORMATS}, or a format a later any2orca release added. */
17
+ export type SourceFormat = KnownSourceFormat | (string & {});
15
18
  /**
16
19
  * What a PrusaSlicer project keeps for the step that needs profile data
17
20
  * (`convert()`, once the catalog is loaded): the project's settings in
@@ -1 +1,2 @@
1
- export {};
1
+ /** The file formats any2orca reads: Bambu Studio's and the slicers built on it, and PrusaSlicer's. */
2
+ export const SOURCE_FORMATS = ["bambu-family", "prusaslicer"];
package/dist/stamp.d.ts CHANGED
@@ -11,6 +11,8 @@
11
11
  */
12
12
  import "./zodSetup.js";
13
13
  import { z } from "zod";
14
+ import { type HighFlowHotends } from "./schema.js";
15
+ import { type SourceFormat } from "./sources/reader.js";
14
16
  export declare const STAMP_PATH = "Metadata/any2orca.json";
15
17
  /** What this version writes: exactly these fields. */
16
18
  export declare const OutputStampSchema: z.ZodObject<{
@@ -47,7 +49,44 @@ export declare const OutputStampSchema: z.ZodObject<{
47
49
  }, z.core.$strict>>;
48
50
  }, z.core.$strict>;
49
51
  }, z.core.$strict>;
50
- export type OutputStamp = z.infer<typeof OutputStampSchema>;
52
+ /** The preset a file was converted with: its base, the settings it set, and a fingerprint of their values. Never its name. */
53
+ export interface OutputStampPreset {
54
+ base: string;
55
+ keys: string[];
56
+ sha256: string;
57
+ }
58
+ /** The user's choices for values above stock: settings kept at the creator's value, and set to stock. */
59
+ export interface OutputStampAboveStock {
60
+ keep: string[];
61
+ stock: string[];
62
+ }
63
+ /** The stamp a converted file carries; `stamp` stays 1 as long as fields are only added. */
64
+ export interface OutputStamp {
65
+ stamp: 1;
66
+ generator: "any2orca";
67
+ /** The `any2orca` package version that converted the file. */
68
+ version: string;
69
+ profiles: {
70
+ /** The profile catalog's version (`any2orca-profiles` for the bundled one). */
71
+ version: string;
72
+ /** The upstream slicer release the catalog tracks, e.g. "Snapmaker Orca 2.4.0". */
73
+ tracks: string;
74
+ };
75
+ profileId: string;
76
+ /** The source project's format and the slicer version that saved it. Absent in files written before this field: the Bambu Studio family. */
77
+ source?: {
78
+ /** One of {@link SOURCE_FORMATS}, or a format a later any2orca release added. */
79
+ format: SourceFormat;
80
+ slicerVersion?: string;
81
+ };
82
+ options: {
83
+ highFlowHotends: HighFlowHotends;
84
+ hardenedNozzles: boolean;
85
+ filamentComplianceMode: "generic" | "snapmaker" | null;
86
+ preset?: OutputStampPreset;
87
+ aboveStock?: OutputStampAboveStock;
88
+ };
89
+ }
51
90
  export declare function encodeStamp(stamp: OutputStamp): Uint8Array;
52
91
  /** Reads the stamp from a converted file's zip entries, or null if it has none (or an unreadable one). */
53
92
  export declare function decodeStamp(bytes: Uint8Array | undefined): OutputStamp | null;
package/dist/stamp.js CHANGED
@@ -13,6 +13,7 @@
13
13
  import "./zodSetup.js";
14
14
  import { z } from "zod";
15
15
  import { HighFlowHotendsSchema } from "./schema.js";
16
+ import { SOURCE_FORMATS } from "./sources/reader.js";
16
17
  export const STAMP_PATH = "Metadata/any2orca.json";
17
18
  const AboveStockStampSchema = z
18
19
  .object({
@@ -46,7 +47,7 @@ export const OutputStampSchema = z
46
47
  /** The source project's format and the slicer version that saved it. Absent in files written before this field: the Bambu Studio family. */
47
48
  source: z
48
49
  .object({
49
- format: z.enum(["bambu-family", "prusaslicer"]),
50
+ format: z.enum(SOURCE_FORMATS),
50
51
  slicerVersion: z.string().max(64).optional(),
51
52
  })
52
53
  .strict()
@@ -77,8 +78,9 @@ const StampReadSchema = z.object({
77
78
  version: noteText(64),
78
79
  profiles: z.object({ version: noteText(64), tracks: noteText(200) }),
79
80
  profileId: noteText(64),
80
- // Added with the PrusaSlicer reader; absent means the Bambu Studio family.
81
- source: z.object({ format: z.enum(["bambu-family", "prusaslicer"]), slicerVersion: noteText(64).optional() }).optional(),
81
+ // Added with the PrusaSlicer reader; absent means the Bambu Studio family. Any short name, so a file from a later
82
+ // release with a format this one doesn't know still reads as stamped.
83
+ source: z.object({ format: z.string().regex(/^[a-z0-9-]{1,32}$/), slicerVersion: noteText(64).optional() }).optional(),
82
84
  options: z.object({
83
85
  highFlowHotends: HighFlowHotendsSchema,
84
86
  // Added after the first stamps were written; absent means the stock stainless nozzles.
@@ -14,9 +14,14 @@
14
14
  */
15
15
  import "./zodSetup.js";
16
16
  import { z } from "zod";
17
- import type { SourceVendor } from "./inspect.js";
18
- import type { ProfileMatch } from "./schema.js";
17
+ import { type SourceVendor } from "./inspect.js";
18
+ import { type ProfileMatch } from "./schema.js";
19
19
  export declare const REF_PATTERN: RegExp;
20
+ /** How the profile was chosen, as the event says it: "explicit" for a profile the user picked, else the match source. */
21
+ export declare const STATS_MATCH_SOURCES: readonly ["explicit", "auto-tier-name", "auto-exact", "auto-nearest", "default-fallback"];
22
+ export type KnownStatsMatchSource = (typeof STATS_MATCH_SOURCES)[number];
23
+ /** One of {@link STATS_MATCH_SOURCES}, or "other" in a collector for a way a later any2orca release added. */
24
+ export type StatsMatchSource = KnownStatsMatchSource | (string & {});
20
25
  export declare const StatsEventSchema: z.ZodObject<{
21
26
  v: z.ZodLiteral<1>;
22
27
  core: z.ZodString;
@@ -40,11 +45,40 @@ export declare const StatsEventSchema: z.ZodObject<{
40
45
  anycubic: "anycubic";
41
46
  elegoo: "elegoo";
42
47
  prusa: "prusa";
48
+ qidi: "qidi";
43
49
  }>;
44
50
  ref: z.ZodOptional<z.ZodString>;
45
51
  day: z.ZodString;
46
52
  }, z.core.$strict>;
47
- export type StatsEvent = z.infer<typeof StatsEventSchema>;
53
+ /** The one event, exactly as sent. `any2orca telemetry show` prints each field's meaning. */
54
+ export interface StatsEvent {
55
+ /** Event format version. */
56
+ v: 1;
57
+ /** The any2orca version that converted the file. */
58
+ core: string;
59
+ /** The profile used, e.g. "snapmaker-u1-0.4-standard". */
60
+ profileId: string;
61
+ matchSource: StatsMatchSource;
62
+ plates: number;
63
+ objects: number;
64
+ filamentSlots: number;
65
+ /** The printer maker the source file was set up for. */
66
+ sourceVendor: SourceVendor;
67
+ /** Which site sent the user, if it said so: a short slug, never free text. */
68
+ ref?: string;
69
+ /** The UTC date of the conversion, no time of day. */
70
+ day: string;
71
+ }
72
+ /** The event a sender may send: exactly the known fields and values, else null. What `any2orca telemetry show` prints. */
73
+ export declare function parseStatsEvent(value: unknown): StatsEvent | null;
74
+ /**
75
+ * The event as a collector should store it, else null. A sender a release or
76
+ * two newer than the collector may name a maker or a way of matching the
77
+ * collector doesn't know yet; those are stored as "other", so the conversion
78
+ * is still counted, and nothing outside the known lists is ever stored.
79
+ * Any other field, and any value that isn't a short lowercase name, is refused.
80
+ */
81
+ export declare function receiveStatsEvent(value: unknown): StatsEvent | null;
48
82
  /** What is never sent, for the "see exactly what's sent" display. */
49
83
  export declare const NEVER_SENT: readonly string[];
50
84
  export interface StatsEventInput {
package/dist/telemetry.js CHANGED
@@ -15,8 +15,14 @@
15
15
  */
16
16
  import "./zodSetup.js";
17
17
  import { z } from "zod";
18
+ import { SOURCE_VENDORS } from "./inspect.js";
19
+ import { MATCH_SOURCES } from "./schema.js";
18
20
  import { VERSION } from "./version.js";
19
21
  export const REF_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
22
+ /** How the profile was chosen, as the event says it: "explicit" for a profile the user picked, else the match source. */
23
+ export const STATS_MATCH_SOURCES = ["explicit", ...MATCH_SOURCES];
24
+ /** A maker or match-source name as a collector accepts it: short and lowercase, so it can never carry free text. */
25
+ const SHORT_NAME = /^[a-z0-9-]{1,32}$/;
20
26
  export const StatsEventSchema = z
21
27
  .object({
22
28
  v: z.literal(1).describe("event format version"),
@@ -28,15 +34,11 @@ export const StatsEventSchema = z
28
34
  .string()
29
35
  .regex(/^[a-z0-9][a-z0-9.-]{0,63}$/)
30
36
  .describe('the profile used, e.g. "snapmaker-u1-0.4-standard"'),
31
- matchSource: z
32
- .enum(["explicit", "auto-tier-name", "auto-exact", "auto-nearest", "default-fallback"])
33
- .describe("how the profile was chosen"),
37
+ matchSource: z.enum(STATS_MATCH_SOURCES).describe("how the profile was chosen"),
34
38
  plates: z.number().int().min(0).max(10_000).describe("number of plates"),
35
39
  objects: z.number().int().min(0).max(10_000).describe("number of objects"),
36
40
  filamentSlots: z.number().int().min(0).max(1_000).describe("number of filament slots"),
37
- sourceVendor: z
38
- .enum(["bambu", "creality", "anycubic", "snapmaker", "elegoo", "prusa", "flashforge", "other"])
39
- .describe("the printer maker the source file was set up for"),
41
+ sourceVendor: z.enum(SOURCE_VENDORS).describe("the printer maker the source file was set up for"),
40
42
  ref: z.string().regex(REF_PATTERN).optional().describe("which site sent you here, if it said so (a short slug, never free text)"),
41
43
  day: z
42
44
  .string()
@@ -44,6 +46,30 @@ export const StatsEventSchema = z
44
46
  .describe("the UTC date of the conversion (no time of day)"),
45
47
  })
46
48
  .strict();
49
+ /** The event a sender may send: exactly the known fields and values, else null. What `any2orca telemetry show` prints. */
50
+ export function parseStatsEvent(value) {
51
+ const parsed = StatsEventSchema.safeParse(value);
52
+ return parsed.success ? parsed.data : null;
53
+ }
54
+ /** What a collector accepts: the sender's event, with any short lowercase name in the maker and match-source fields. */
55
+ const StatsReceiveSchema = StatsEventSchema.extend({
56
+ matchSource: z.string().regex(SHORT_NAME),
57
+ sourceVendor: z.string().regex(SHORT_NAME),
58
+ }).strict();
59
+ /**
60
+ * The event as a collector should store it, else null. A sender a release or
61
+ * two newer than the collector may name a maker or a way of matching the
62
+ * collector doesn't know yet; those are stored as "other", so the conversion
63
+ * is still counted, and nothing outside the known lists is ever stored.
64
+ * Any other field, and any value that isn't a short lowercase name, is refused.
65
+ */
66
+ export function receiveStatsEvent(value) {
67
+ const parsed = StatsReceiveSchema.safeParse(value);
68
+ if (!parsed.success)
69
+ return null;
70
+ const known = (list, name) => (list.includes(name) ? name : "other");
71
+ return { ...parsed.data, sourceVendor: known(SOURCE_VENDORS, parsed.data.sourceVendor), matchSource: known(STATS_MATCH_SOURCES, parsed.data.matchSource) };
72
+ }
47
73
  /** What is never sent, for the "see exactly what's sent" display. */
48
74
  export const NEVER_SENT = [
49
75
  "your file, or any part of it (no geometry, no settings values)",
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.7.3";
1
+ export declare const VERSION = "0.9.0";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Written by scripts/sync-version.mjs from package.json; a test checks they match.
3
- export const VERSION = "0.7.3";
3
+ export const VERSION = "0.9.0";
@@ -12,7 +12,7 @@
12
12
  * MAX_OPEN_PROJECTS are kept; opening more closes the oldest.
13
13
  */
14
14
  import { diffSettings } from "./diff/diffSettings.js";
15
- import { diffReference, presetDiffSide } from "./diff/reference.js";
15
+ import { diffReference, presetDiffSide, stockDiffSide } from "./diff/reference.js";
16
16
  import { Any2orcaError } from "./errors.js";
17
17
  import { extractPreset } from "./presets/extractPreset.js";
18
18
  import { resolvePreset } from "./presets/preset.js";
@@ -100,8 +100,7 @@ async function handle(request) {
100
100
  return presetDiffSide(s.preset, catalog);
101
101
  }
102
102
  if (typeof s === "object" && s !== null && "stock" in s && typeof s.stock === "string") {
103
- const loaded = await catalog.load(s.stock);
104
- return { label: `Snapmaker's stock ${loaded.summary.displayName} profile`, settings: loaded.convertProfile.profile.baselineProjectSettings, profileId: loaded.summary.id };
103
+ return stockDiffSide(s.stock, catalog);
105
104
  }
106
105
  const { handle: h, label } = (s ?? {});
107
106
  const project = requireProject(h);