@oeave/bakery3 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +562 -2
- package/dist/animation-B1h0Ryvj.d.ts +97 -0
- package/dist/bake/index.d.ts +369 -0
- package/dist/bake/index.js +9 -0
- package/dist/bake/index.js.map +1 -0
- package/dist/bake-DZ-CJR6f.d.ts +1364 -0
- package/dist/catalog/index.d.ts +100 -0
- package/dist/catalog/index.js +154 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/catalog.gen-BM-aNf7n.d.ts +733 -0
- package/dist/chunk-3G5QL4F4.js +145 -0
- package/dist/chunk-3G5QL4F4.js.map +1 -0
- package/dist/chunk-4E5VV4QY.js +12 -0
- package/dist/chunk-4E5VV4QY.js.map +1 -0
- package/dist/chunk-62M6XXNX.js +142 -0
- package/dist/chunk-62M6XXNX.js.map +1 -0
- package/dist/chunk-6FYI6AJM.js +1157 -0
- package/dist/chunk-6FYI6AJM.js.map +1 -0
- package/dist/chunk-6NYR73Y7.js +832 -0
- package/dist/chunk-6NYR73Y7.js.map +1 -0
- package/dist/chunk-APWUCEEB.js +118 -0
- package/dist/chunk-APWUCEEB.js.map +1 -0
- package/dist/chunk-HNMSWQU7.js +1709 -0
- package/dist/chunk-HNMSWQU7.js.map +1 -0
- package/dist/chunk-JFYUDERE.js +1412 -0
- package/dist/chunk-JFYUDERE.js.map +1 -0
- package/dist/chunk-KNUAOILG.js +551 -0
- package/dist/chunk-KNUAOILG.js.map +1 -0
- package/dist/chunk-KZLVTSBI.js +191 -0
- package/dist/chunk-KZLVTSBI.js.map +1 -0
- package/dist/chunk-LAKXC4WR.js +2028 -0
- package/dist/chunk-LAKXC4WR.js.map +1 -0
- package/dist/chunk-NXBAZGNB.js +1107 -0
- package/dist/chunk-NXBAZGNB.js.map +1 -0
- package/dist/chunk-QRCT5UGZ.js +3286 -0
- package/dist/chunk-QRCT5UGZ.js.map +1 -0
- package/dist/chunk-S4AJTLLN.js +23 -0
- package/dist/chunk-S4AJTLLN.js.map +1 -0
- package/dist/chunk-UWBP7B54.js +92 -0
- package/dist/chunk-UWBP7B54.js.map +1 -0
- package/dist/chunk-XK35ANPJ.js +346 -0
- package/dist/chunk-XK35ANPJ.js.map +1 -0
- package/dist/chunk-Z7IYVH22.js +4781 -0
- package/dist/chunk-Z7IYVH22.js.map +1 -0
- package/dist/chunk-ZEBVAIJJ.js +156 -0
- package/dist/chunk-ZEBVAIJJ.js.map +1 -0
- package/dist/devtools/index.d.ts +536 -0
- package/dist/devtools/index.js +15 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/environments/index.d.ts +93 -0
- package/dist/environments/index.js +382 -0
- package/dist/environments/index.js.map +1 -0
- package/dist/hotspots/index.d.ts +111 -0
- package/dist/hotspots/index.js +285 -0
- package/dist/hotspots/index.js.map +1 -0
- package/dist/index.d.ts +975 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/node/index.cjs +5240 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +4927 -0
- package/dist/node/index.d.ts +597 -0
- package/dist/node/index.js +1328 -0
- package/dist/node/index.js.map +1 -0
- package/dist/prepare-BtjY4G3q.d.ts +112 -0
- package/dist/presets/index.d.ts +562 -0
- package/dist/presets/index.js +14 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/r3f/index.d.ts +159 -0
- package/dist/r3f/index.js +592 -0
- package/dist/r3f/index.js.map +1 -0
- package/dist/room-FS26KAPQ.js +9 -0
- package/dist/room-FS26KAPQ.js.map +1 -0
- package/dist/rooms.gen-DItzBR9k.d.ts +1462 -0
- package/dist/session-VCIQEO26.js +9 -0
- package/dist/session-VCIQEO26.js.map +1 -0
- package/dist/shapes/index.d.ts +222 -0
- package/dist/shapes/index.js +836 -0
- package/dist/shapes/index.js.map +1 -0
- package/dist/testRun-20OARnQr.d.ts +1139 -0
- package/dist/timeline-ChwgD7bT.d.ts +470 -0
- package/dist/tsl/index.d.ts +165 -0
- package/dist/tsl/index.js +310 -0
- package/dist/tsl/index.js.map +1 -0
- package/package.json +170 -4
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Bakery3Error } from './chunk-3G5QL4F4.js';
|
|
2
|
+
|
|
3
|
+
// src/set.ts
|
|
4
|
+
var RenderSet = class {
|
|
5
|
+
/** The batch underneath: pause, resume, retry, the export. */
|
|
6
|
+
batch;
|
|
7
|
+
id;
|
|
8
|
+
key;
|
|
9
|
+
/** What the call that made this set recorded. Empty for a set fetched by id. */
|
|
10
|
+
recorded;
|
|
11
|
+
/** Item key → position, for a set small enough to have asked for an order. */
|
|
12
|
+
order;
|
|
13
|
+
constructor(batch, recorded = emptyRecorded()) {
|
|
14
|
+
this.batch = batch;
|
|
15
|
+
this.id = batch.id;
|
|
16
|
+
this.key = batch.key;
|
|
17
|
+
this.recorded = recorded;
|
|
18
|
+
}
|
|
19
|
+
/** Counts and cost from the latest record. No request. */
|
|
20
|
+
progress() {
|
|
21
|
+
return this.batch.progress();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Until every picture is terminal. One long-poll on the set, however many
|
|
25
|
+
* pictures it has. Resolves with the final counts: pictures that failed
|
|
26
|
+
* are in `failures()`, they do not reject the wait.
|
|
27
|
+
*/
|
|
28
|
+
async wait(options = {}) {
|
|
29
|
+
await this.batch.wait(options);
|
|
30
|
+
return this.batch.progress();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Every finished picture, a page at a time. Safe on a set of any size,
|
|
34
|
+
* and safe to call before the set is done: it walks what has completed
|
|
35
|
+
* so far.
|
|
36
|
+
*/
|
|
37
|
+
async *images() {
|
|
38
|
+
for await (const item of this.batch.items({ state: "completed" })) {
|
|
39
|
+
if (!item.result) continue;
|
|
40
|
+
yield {
|
|
41
|
+
key: item.key,
|
|
42
|
+
id: item.id,
|
|
43
|
+
...who(item.metadata),
|
|
44
|
+
url: item.result.url,
|
|
45
|
+
width: item.result.width,
|
|
46
|
+
height: item.result.height,
|
|
47
|
+
cost: item.result.cost,
|
|
48
|
+
...item.metadata ? { metadata: item.metadata } : {},
|
|
49
|
+
result: item.result
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Every picture that did not render, with the reason and the fix.
|
|
55
|
+
* `error.retryable` tells the two kinds apart: false is a refusal, the
|
|
56
|
+
* scene's fault and the same next time; true ran out of attempts on a
|
|
57
|
+
* fault of ours, and `set.batch.retry()` queues it again.
|
|
58
|
+
*/
|
|
59
|
+
async *failures() {
|
|
60
|
+
for await (const item of this.batch.items({ state: "failed" })) {
|
|
61
|
+
yield {
|
|
62
|
+
key: item.key,
|
|
63
|
+
id: item.id,
|
|
64
|
+
...who(item.metadata),
|
|
65
|
+
error: item.error ? Bakery3Error.from(item.error) : new Bakery3Error({
|
|
66
|
+
code: "WorkerFailure",
|
|
67
|
+
message: "Ended with no result and no reason.",
|
|
68
|
+
retryable: true
|
|
69
|
+
}),
|
|
70
|
+
...item.metadata ? { metadata: item.metadata } : {}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Wait, then every picture in one array, in camera order for a
|
|
76
|
+
* `render({ cameras })`: one picture per camera, or a rejection. Rejects
|
|
77
|
+
* with `RenderSetRefused` when a picture was turned down at submission
|
|
78
|
+
* (it has no render, and the array would be one short with every later
|
|
79
|
+
* picture in the wrong place), and otherwise with the first failure, as
|
|
80
|
+
* `job.result()` does. The pictures that did render are still there:
|
|
81
|
+
* walk `images()`, each named by its `camera`.
|
|
82
|
+
*
|
|
83
|
+
* It collects, so it is for a handful of pictures. For a catalog, walk
|
|
84
|
+
* `images()`.
|
|
85
|
+
*/
|
|
86
|
+
async result(options = {}) {
|
|
87
|
+
await this.wait(options);
|
|
88
|
+
if (this.recorded.refused > 0) throw new RenderSetRefused(this.recorded);
|
|
89
|
+
for await (const failure of this.failures()) throw failure.error;
|
|
90
|
+
const images = [];
|
|
91
|
+
for await (const image of this.images()) images.push(image);
|
|
92
|
+
const order = this.order;
|
|
93
|
+
if (order)
|
|
94
|
+
images.sort((a, b) => (order.get(a.key) ?? 0) - (order.get(b.key) ?? 0));
|
|
95
|
+
return images;
|
|
96
|
+
}
|
|
97
|
+
/** Cancel every picture that has not finished. What completed, completed. */
|
|
98
|
+
async cancel() {
|
|
99
|
+
await this.batch.cancel();
|
|
100
|
+
}
|
|
101
|
+
/** @internal */
|
|
102
|
+
ordered(keys) {
|
|
103
|
+
this.order = new Map(keys.map((key, index) => [key, index]));
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var RenderSetRefused = class extends Bakery3Error {
|
|
108
|
+
/** Which pictures, and why: the first fifty when a run refused more. */
|
|
109
|
+
refusals;
|
|
110
|
+
/** How many were refused in all. */
|
|
111
|
+
refused;
|
|
112
|
+
/** How many pictures were asked for. */
|
|
113
|
+
requested;
|
|
114
|
+
constructor(recorded) {
|
|
115
|
+
const first = recorded.refusals[0];
|
|
116
|
+
const names = recorded.refusals.slice(0, 3).map(describeRefusal);
|
|
117
|
+
const more = recorded.refused - names.length;
|
|
118
|
+
super({
|
|
119
|
+
code: first?.error.code ?? "InvalidRequest",
|
|
120
|
+
message: `${recorded.refused} of ${recorded.images} pictures ${recorded.refused === 1 ? "was" : "were"} refused: ${names.join("; ")}${more > 0 ? `; and ${more} more` : ""}.`,
|
|
121
|
+
why: "A picture refused when it was submitted never renders. An array of the rest would be shorter than the list you asked for, with every later picture in the wrong place, so result() gives none.",
|
|
122
|
+
fix: "Read error.refusals for each refused picture and its reason. The pictures that were accepted still render: set.images() walks them, each named by its camera.",
|
|
123
|
+
docs: "https://bakery3.com/docs/batches#errors",
|
|
124
|
+
retryable: false
|
|
125
|
+
});
|
|
126
|
+
this.name = "RenderSetRefused";
|
|
127
|
+
this.refusals = recorded.refusals.map(({ error, ...who2 }) => ({
|
|
128
|
+
...who2,
|
|
129
|
+
error: Bakery3Error.from(error)
|
|
130
|
+
}));
|
|
131
|
+
this.refused = recorded.refused;
|
|
132
|
+
this.requested = recorded.images;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
function describeRefusal(refusal) {
|
|
136
|
+
const name = [refusal.variant, refusal.finish, refusal.camera, refusal.shot].filter(Boolean).join(" / ") || refusal.key;
|
|
137
|
+
return `"${name}" (${refusal.error.message.replace(/\.$/, "")})`;
|
|
138
|
+
}
|
|
139
|
+
function who(metadata) {
|
|
140
|
+
const out = {};
|
|
141
|
+
if (typeof metadata?.variant === "string") out.variant = metadata.variant;
|
|
142
|
+
else if (typeof metadata?.sku === "string") out.variant = metadata.sku;
|
|
143
|
+
if (typeof metadata?.finish === "string") out.finish = metadata.finish;
|
|
144
|
+
if (typeof metadata?.camera === "string") out.camera = metadata.camera;
|
|
145
|
+
if (typeof metadata?.shot === "string") out.shot = metadata.shot;
|
|
146
|
+
if (metadata?.kind === "video" || metadata?.kind === "image")
|
|
147
|
+
out.kind = metadata.kind;
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
function emptyRecorded() {
|
|
151
|
+
return { variants: 0, images: 0, adopted: 0, refused: 0, refusals: [] };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { RenderSet, RenderSetRefused, emptyRecorded, who };
|
|
155
|
+
//# sourceMappingURL=chunk-ZEBVAIJJ.js.map
|
|
156
|
+
//# sourceMappingURL=chunk-ZEBVAIJJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/set.ts"],"names":["who"],"mappings":";;;AAiFO,IAAM,YAAN,MAAgB;AAAA;AAAA,EAEZ,KAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA;AAAA;AAAA,EAEA,QAAA;AAAA;AAAA,EAED,KAAA;AAAA,EAER,WAAA,CAAY,KAAA,EAAc,QAAA,GAAqB,aAAA,EAAc,EAAG;AAC9D,IAAA,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W,QAAA,EAAU,GAAA,CAAI,SAAS,QAAA,CAAS,MAAA;AAChE,EAAA,IAAI,OAAO,QAAA,EAAU,MAAA,KAAW,QAAA,EAAU,GAAA,CAAI,SAAS,QAAA,CAAS,MAAA;AAChE,EAAA,IAAI,OAAO,QAAA,EAAU,IAAA,KAAS,QAAA,EAAU,GAAA,CAAI,OAAO,QAAA,CAAS,IAAA;AAC5D,EAAA,IAAI,QAAA,EAAU,IAAA,KAAS,OAAA,IAAW,QAAA,EAAU,IAAA,KAAS,OAAA;AACnD,IAAA,GAAA,CAAI,OAAO,QAAA,CAAS,IAAA;AACtB,EAAA,OAAO,GAAA;AACT;AAEO,SAAS,aAAA,GAA0B;AACxC,EAAA,OAAO,EAAE,QAAA,EAAU,CAAA,EAAG,MAAA,EAAQ,CAAA,EAAG,OAAA,EAAS,CAAA,EAAG,OAAA,EAAS,CAAA,EAAG,QAAA,EAAU,EAAC,EAAE;AACxE","file":"chunk-ZEBVAIJJ.js","sourcesContent":["/**\n * A set of pictures: what every many-pictures call hands back.\n *\n * `render({ cameras })` and `renderVariants()` in the browser, and\n * `renderBatch()` from Node, all record into a batch and return one of\n * these, so a set of three and a catalog of six thousand are the same object\n * with the same guarantees: one ceiling for all of it, one poll for all of\n * it, results walked a page at a time and never held.\n *\n * No three.js here: the server entry imports this file.\n */\n\nimport type { RenderError, RenderResult } from './protocol/index.js';\nimport type { Batch, BatchProgress, WaitOptions } from './batch.js';\nimport { Bakery3Error } from './errors.js';\n\n/** One finished picture of a set. */\nexport type RenderSetImage = {\n /** The item's key: `variant/finish/camera`, as recorded. */\n key: string;\n /** The render's id. */\n id: string;\n variant?: string;\n finish?: string;\n camera?: string;\n /** The shot this is, for a set recorded with shots. */\n shot?: string;\n /** `'video'` when the url is a clip. */\n kind?: 'image' | 'video';\n /** Signed and expiring. Copy the bytes; do not serve from it. */\n url: string;\n width: number;\n height: number;\n /** What this picture cost. Nothing, when it was adopted from an earlier run. */\n cost: number;\n metadata?: Record<string, unknown>;\n result: RenderResult;\n};\n\n/** One picture that did not render, and why. */\nexport type RenderSetFailure = {\n key: string;\n id: string;\n variant?: string;\n finish?: string;\n camera?: string;\n shot?: string;\n error: Bakery3Error;\n metadata?: Record<string, unknown>;\n};\n\n/** One picture turned down when it was submitted: it has no render and never will. */\nexport type RenderSetRefusal = {\n key: string;\n variant?: string;\n finish?: string;\n camera?: string;\n shot?: string;\n error: RenderError;\n};\n\n/** What a recording did, in numbers small enough to keep. */\nexport type Recorded = {\n variants: number;\n images: number;\n /** Already rendered under their keys in an earlier run. Cost nothing. */\n adopted: number;\n /** Turned down alone at admission (a spec that does not parse, an item over its own ceiling). */\n refused: number;\n /** The first of those, with their reasons. Capped, because a broken pipeline refuses every item. */\n refusals: RenderSetRefusal[];\n};\n\n/** What a whole run would cost, from `quoteVariants()`. Nothing was admitted. */\nexport type VariantsQuote = Recorded & {\n /** Σ estimate over the pictures that would render. */\n estimated: number;\n /** Σ maximum: what admission would reserve, and the number to set `maxCost` from. */\n maximum: number;\n};\n\nexport class RenderSet {\n /** The batch underneath: pause, resume, retry, the export. */\n readonly batch: Batch;\n readonly id: string;\n readonly key: string;\n /** What the call that made this set recorded. Empty for a set fetched by id. */\n readonly recorded: Recorded;\n /** Item key → position, for a set small enough to have asked for an order. */\n private order?: Map<string, number>;\n\n constructor(batch: Batch, recorded: Recorded = emptyRecorded()) {\n this.batch = batch;\n this.id = batch.id;\n this.key = batch.key;\n this.recorded = recorded;\n }\n\n /** Counts and cost from the latest record. No request. */\n progress(): BatchProgress {\n return this.batch.progress();\n }\n\n /**\n * Until every picture is terminal. One long-poll on the set, however many\n * pictures it has. Resolves with the final counts: pictures that failed\n * are in `failures()`, they do not reject the wait.\n */\n async wait(options: WaitOptions = {}): Promise<BatchProgress> {\n await this.batch.wait(options);\n return this.batch.progress();\n }\n\n /**\n * Every finished picture, a page at a time. Safe on a set of any size,\n * and safe to call before the set is done: it walks what has completed\n * so far.\n */\n async *images(): AsyncIterable<RenderSetImage> {\n for await (const item of this.batch.items({ state: 'completed' })) {\n if (!item.result) continue;\n yield {\n key: item.key,\n id: item.id,\n ...who(item.metadata),\n url: item.result.url,\n width: item.result.width,\n height: item.result.height,\n cost: item.result.cost,\n ...(item.metadata ? { metadata: item.metadata } : {}),\n result: item.result,\n };\n }\n }\n\n /**\n * Every picture that did not render, with the reason and the fix.\n * `error.retryable` tells the two kinds apart: false is a refusal, the\n * scene's fault and the same next time; true ran out of attempts on a\n * fault of ours, and `set.batch.retry()` queues it again.\n */\n async *failures(): AsyncIterable<RenderSetFailure> {\n for await (const item of this.batch.items({ state: 'failed' })) {\n yield {\n key: item.key,\n id: item.id,\n ...who(item.metadata),\n error: item.error\n ? Bakery3Error.from(item.error)\n : new Bakery3Error({\n code: 'WorkerFailure',\n message: 'Ended with no result and no reason.',\n retryable: true,\n }),\n ...(item.metadata ? { metadata: item.metadata } : {}),\n };\n }\n }\n\n /**\n * Wait, then every picture in one array, in camera order for a\n * `render({ cameras })`: one picture per camera, or a rejection. Rejects\n * with `RenderSetRefused` when a picture was turned down at submission\n * (it has no render, and the array would be one short with every later\n * picture in the wrong place), and otherwise with the first failure, as\n * `job.result()` does. The pictures that did render are still there:\n * walk `images()`, each named by its `camera`.\n *\n * It collects, so it is for a handful of pictures. For a catalog, walk\n * `images()`.\n */\n async result(options: WaitOptions = {}): Promise<RenderSetImage[]> {\n await this.wait(options);\n if (this.recorded.refused > 0) throw new RenderSetRefused(this.recorded);\n for await (const failure of this.failures()) throw failure.error;\n const images: RenderSetImage[] = [];\n for await (const image of this.images()) images.push(image);\n const order = this.order;\n if (order)\n images.sort((a, b) => (order.get(a.key) ?? 0) - (order.get(b.key) ?? 0));\n return images;\n }\n\n /** Cancel every picture that has not finished. What completed, completed. */\n async cancel(): Promise<void> {\n await this.batch.cancel();\n }\n\n /** @internal */\n ordered(keys: string[]): this {\n this.order = new Map(keys.map((key, index) => [key, index]));\n return this;\n }\n}\n\n/**\n * Pictures of a set were turned down when they were submitted, so the set\n * cannot give one picture per camera (or per variant) in order.\n *\n * `refusals` says which and why. Its `code` is the first refusal's. The\n * pictures that were accepted render as usual: `set.images()` walks them.\n */\nexport class RenderSetRefused extends Bakery3Error {\n /** Which pictures, and why: the first fifty when a run refused more. */\n readonly refusals: Array<\n Omit<RenderSetRefusal, 'error'> & { error: Bakery3Error }\n >;\n /** How many were refused in all. */\n readonly refused: number;\n /** How many pictures were asked for. */\n readonly requested: number;\n\n constructor(recorded: Recorded) {\n const first = recorded.refusals[0];\n const names = recorded.refusals.slice(0, 3).map(describeRefusal);\n const more = recorded.refused - names.length;\n super({\n code: first?.error.code ?? 'InvalidRequest',\n message: `${recorded.refused} of ${recorded.images} pictures ${recorded.refused === 1 ? 'was' : 'were'} refused: ${names.join('; ')}${more > 0 ? `; and ${more} more` : ''}.`,\n why: 'A picture refused when it was submitted never renders. An array of the rest would be shorter than the list you asked for, with every later picture in the wrong place, so result() gives none.',\n fix: 'Read error.refusals for each refused picture and its reason. The pictures that were accepted still render: set.images() walks them, each named by its camera.',\n docs: 'https://bakery3.com/docs/batches#errors',\n retryable: false,\n });\n this.name = 'RenderSetRefused';\n this.refusals = recorded.refusals.map(({ error, ...who }) => ({\n ...who,\n error: Bakery3Error.from(error),\n }));\n this.refused = recorded.refused;\n this.requested = recorded.images;\n }\n}\n\nfunction describeRefusal(refusal: RenderSetRefusal): string {\n const name =\n [refusal.variant, refusal.finish, refusal.camera, refusal.shot]\n .filter(Boolean)\n .join(' / ') || refusal.key;\n return `\"${name}\" (${refusal.error.message.replace(/\\.$/, '')})`;\n}\n\n/** The variant, finish, camera and shot an item was recorded under, from its metadata. */\nexport function who(\n metadata: Record<string, unknown> | undefined,\n): Pick<RenderSetImage, 'variant' | 'finish' | 'camera' | 'shot' | 'kind'> {\n const out: Pick<\n RenderSetImage,\n 'variant' | 'finish' | 'camera' | 'shot' | 'kind'\n > = {};\n if (typeof metadata?.variant === 'string') out.variant = metadata.variant;\n // The catalog recorder's own word for it.\n else if (typeof metadata?.sku === 'string') out.variant = metadata.sku;\n if (typeof metadata?.finish === 'string') out.finish = metadata.finish;\n if (typeof metadata?.camera === 'string') out.camera = metadata.camera;\n if (typeof metadata?.shot === 'string') out.shot = metadata.shot;\n if (metadata?.kind === 'video' || metadata?.kind === 'image')\n out.kind = metadata.kind;\n return out;\n}\n\nexport function emptyRecorded(): Recorded {\n return { variants: 0, images: 0, adopted: 0, refused: 0, refusals: [] };\n}\n"]}
|