@terrafirmagreg-team/recipe 1.2.28 → 1.2.29
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/package.json +5 -5
- package/src/components/cards/slot-hitbox.tsx +22 -4
- package/src/components/tree.tsx +4 -4
- package/src/components/views/alloy/list.tsx +1 -0
- package/src/components/views/browser/axis-switcher.tsx +6 -7
- package/src/components/views/browser/card-grid.tsx +10 -2
- package/src/components/views/browser/index.tsx +23 -9
- package/src/components/views/browser/item-panel/index.tsx +125 -75
- package/src/components/views/browser/item-panel-grid/cell.tsx +0 -6
- package/src/components/views/browser/item-panel-grid/index.tsx +10 -5
- package/src/components/views/browser/item-view/tags.tsx +2 -0
- package/src/components/views/browser/type-view.tsx +5 -4
- package/src/components/views/calc/calculator/index.tsx +2 -0
- package/src/components/views/calc/sidebar.tsx +4 -1
- package/src/components/views/forge/list.tsx +1 -0
- package/src/hooks/alloy/use-fluid-colors.ts +2 -3
- package/src/hooks/alloy/use-mix-state.ts +2 -0
- package/src/hooks/calc/use-actions.ts +6 -4
- package/src/hooks/calc/use-data.ts +1 -0
- package/src/hooks/calc/use-share.ts +6 -4
- package/src/hooks/use-add-to-calc.ts +2 -1
- package/src/hooks/use-index.ts +19 -8
- package/src/hooks/use-mount-limit.ts +9 -3
- package/src/hooks/use-panel-warmup.ts +129 -0
- package/src/hooks/use-query.ts +8 -2
- package/src/hooks/use-session.ts +11 -4
- package/src/lib/browser/fluid-outputs.ts +2 -3
- package/src/lib/cards/model.ts +5 -1
- package/src/lib/client/recipe.ts +23 -29
- package/src/lib/client-index/catalog.ts +2 -3
- package/src/lib/client-index/chrome.test.ts +87 -0
- package/src/lib/client-index/chrome.ts +27 -134
- package/src/lib/client-index/prepared-catalog.ts +80 -0
- package/src/lib/client-index/registry.ts +3 -4
- package/src/lib/client-index/rows.test.ts +127 -0
- package/src/lib/client-index/rows.ts +51 -194
- package/src/lib/client-index/store.ts +2 -3
- package/src/lib/client-index/tooltips.ts +2 -3
- package/src/lib/links.ts +10 -3
- package/src/types/catalog.ts +18 -0
- package/src/types/index.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { datasetCacheKey, type DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
2
2
|
import type { RecipeChrome, RecipeCompactIndex } from '@terrafirmagreg-team/recipe/types';
|
|
3
3
|
import { loadDatasetRecipeCategories } from '@terrafirmagreg-team/recipe/lib/data/category/load';
|
|
4
4
|
import { stackDisplayName } from '@terrafirmagreg-team/game/lib/entry/display';
|
|
@@ -44,7 +44,7 @@ const indexCache = createDatasetCache(
|
|
|
44
44
|
return loadRecipeStructureFromDump(dataset, chrome);
|
|
45
45
|
},
|
|
46
46
|
(dataset, chrome) =>
|
|
47
|
-
|
|
47
|
+
datasetCacheKey(dataset, chrome ? (Object.keys(chrome.names)[0] ?? '') : ''),
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
const skeletonCache = createDatasetCache(
|
|
@@ -88,4 +88,3 @@ export function recipeItemName(
|
|
|
88
88
|
): string {
|
|
89
89
|
return stackDisplayName(names[lang] ?? names.en_us, id);
|
|
90
90
|
}
|
|
91
|
-
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { mock, test } from 'node:test';
|
|
3
|
+
import { datasetCacheKey, type DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
4
|
+
import { createAsyncCache } from '@terrafirmagreg-team/data/lib/async-cache';
|
|
5
|
+
import type { PreparedCatalog } from '../../types/catalog';
|
|
6
|
+
import { parseCatalogLabels, parsePreparedCatalog } from './prepared-catalog';
|
|
7
|
+
|
|
8
|
+
const catalog: PreparedCatalog = {
|
|
9
|
+
items: ['test:item{mode:1}'],
|
|
10
|
+
fluids: [],
|
|
11
|
+
usedIds: ['#test:ores'],
|
|
12
|
+
tabs: [{ id: 'test:tab', order: 0, display: {} }],
|
|
13
|
+
tabItems: { 'test:tab': ['test:item{mode:1}'] },
|
|
14
|
+
categories: [{ id: 'test:craft', order: 0, workstations: [] }],
|
|
15
|
+
groups: [{ id: 'test:group', members: ['test:item{mode:1}'] }],
|
|
16
|
+
};
|
|
17
|
+
const requests: string[] = [];
|
|
18
|
+
const names = { 'test:item{mode:1}': 'Item' };
|
|
19
|
+
|
|
20
|
+
mock.module('@terrafirmagreg-team/dump/lib/dump/client/dump', {
|
|
21
|
+
namedExports: {
|
|
22
|
+
clientDumpJson: async (_dataset: DatasetRef, path: string) => {
|
|
23
|
+
requests.push(path);
|
|
24
|
+
if (path === 'registry/catalog.json') return catalog;
|
|
25
|
+
if (path === 'lang/fr_fr.catalog.json') {
|
|
26
|
+
return { mods: { test: 'Test' }, names: { 'test:tab': 'Outils' }, groups: { 'test:group': 'Groupe' } };
|
|
27
|
+
}
|
|
28
|
+
if (path === 'lang/en_us.catalog.json') {
|
|
29
|
+
return { mods: { test: 'Test' }, names: { 'test:tab': 'Tools' }, groups: { 'test:group': 'Group' } };
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`Unexpected request ${path}`);
|
|
32
|
+
},
|
|
33
|
+
clientDumpNames: async (_dataset: DatasetRef, lang: string) => {
|
|
34
|
+
requests.push(`names/${lang}.ndjson`);
|
|
35
|
+
return names;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
mock.module('@terrafirmagreg-team/dump/lib/dump/reader', {
|
|
40
|
+
namedExports: {
|
|
41
|
+
createDatasetCache: <A extends unknown[], V>(
|
|
42
|
+
loader: (dataset: DatasetRef, ...args: A) => Promise<V>,
|
|
43
|
+
key = (dataset: DatasetRef, ...args: A) => datasetCacheKey(dataset, ...args),
|
|
44
|
+
) => createAsyncCache(loader, key),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('chrome requests only prepared projections and shares neutral arrays across locales', async () => {
|
|
49
|
+
const { loadRecipeChromeClient, loadRecipeEntityNames } = await import('./chrome');
|
|
50
|
+
const dataset = { id: 'fixture', version: '1', revision: 'a' };
|
|
51
|
+
const en = await loadRecipeChromeClient(dataset, 'en_us');
|
|
52
|
+
assert.deepEqual(requests, ['registry/catalog.json', 'lang/en_us.catalog.json']);
|
|
53
|
+
assert.equal(en.items, catalog.items);
|
|
54
|
+
assert.equal(en.names.en_us['test:tab'], 'Tools');
|
|
55
|
+
assert.equal(en.groups?.[0].name, 'Group');
|
|
56
|
+
const fr = await loadRecipeChromeClient(dataset, 'fr_fr');
|
|
57
|
+
assert.deepEqual(requests, [
|
|
58
|
+
'registry/catalog.json', 'lang/en_us.catalog.json', 'lang/fr_fr.catalog.json',
|
|
59
|
+
]);
|
|
60
|
+
assert.equal(fr.items, en.items);
|
|
61
|
+
assert.equal(fr.fluids, en.fluids);
|
|
62
|
+
assert.equal(fr.usedIds, en.usedIds);
|
|
63
|
+
assert.equal(fr.tabs, en.tabs);
|
|
64
|
+
assert.equal(fr.categories, en.categories);
|
|
65
|
+
assert.equal(fr.tabItems, en.tabItems);
|
|
66
|
+
assert.equal(fr.groups?.[0].members, en.groups?.[0].members);
|
|
67
|
+
assert.equal(fr.groups?.[0].name, 'Groupe');
|
|
68
|
+
assert.equal(await loadRecipeChromeClient(dataset, 'en_us'), en);
|
|
69
|
+
assert.equal(await loadRecipeEntityNames(dataset, en, 'en_us'), names);
|
|
70
|
+
assert.equal(await loadRecipeEntityNames(dataset, fr, 'en_us'), names);
|
|
71
|
+
assert.equal(requests.filter((path) => path.startsWith('names/')).length, 1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('required projections reject missing fields, old shapes and malformed rows', () => {
|
|
75
|
+
assert.throws(() => parsePreparedCatalog(undefined));
|
|
76
|
+
for (const field of Object.keys(catalog)) {
|
|
77
|
+
const invalid: Record<string, unknown> = { ...catalog };
|
|
78
|
+
delete invalid[field];
|
|
79
|
+
assert.throws(() => parsePreparedCatalog(invalid));
|
|
80
|
+
}
|
|
81
|
+
assert.throws(() => parsePreparedCatalog({ ...catalog, tabs: {} }));
|
|
82
|
+
assert.throws(() => parsePreparedCatalog({ ...catalog, categories: [{ id: 'test:craft' }] }));
|
|
83
|
+
assert.throws(() => parseCatalogLabels({ mods: {}, names: {} }));
|
|
84
|
+
assert.throws(() => parseCatalogLabels({ mods: {}, names: {}, groups: { bad: 1 } }));
|
|
85
|
+
const empty = { items: [], fluids: [], usedIds: [], tabs: [], tabItems: {}, categories: [], groups: [] };
|
|
86
|
+
assert.deepEqual(parsePreparedCatalog(empty), empty);
|
|
87
|
+
});
|
|
@@ -1,149 +1,43 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
3
|
-
RecipeCategory,
|
|
4
|
-
RecipeChrome,
|
|
5
|
-
RecipeStackGroup,
|
|
6
|
-
} from '@terrafirmagreg-team/recipe/types';
|
|
1
|
+
import { datasetCacheKey, type DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
2
|
+
import type { RecipeChrome } from '@terrafirmagreg-team/recipe/types';
|
|
7
3
|
import {
|
|
8
|
-
|
|
4
|
+
clientDumpJson,
|
|
9
5
|
clientDumpNames,
|
|
10
|
-
loadClientManifest,
|
|
11
6
|
} from '@terrafirmagreg-team/dump/lib/dump/client/dump';
|
|
12
|
-
import {
|
|
13
|
-
creativeTabName,
|
|
14
|
-
dumpTextString,
|
|
15
|
-
} from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
|
|
16
|
-
import { loadClientRegistryOrder } from '@terrafirmagreg-team/dump/lib/dump/client/registry';
|
|
17
|
-
import { loadClientTagMembers } from '@terrafirmagreg-team/dump/lib/dump/client/tags';
|
|
18
|
-
import { loadClientTabs } from '@terrafirmagreg-team/dump/lib/dump/client/tabs';
|
|
19
|
-
import { loadDatasetRecipeCategories } from '@terrafirmagreg-team/recipe/lib/data/category/load';
|
|
20
|
-
import { loadClientRegistryGroups } from '@terrafirmagreg-team/dump/lib/dump/client/groups';
|
|
21
|
-
import { loadClientModNames } from '@terrafirmagreg-team/dump/lib/dump/client/mods';
|
|
22
|
-
import {
|
|
23
|
-
stackIdBase,
|
|
24
|
-
stackIdFromRef,
|
|
25
|
-
} from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
|
|
26
7
|
import { createDatasetCache } from '@terrafirmagreg-team/dump/lib/dump/reader';
|
|
8
|
+
import { parseCatalogLabels, parsePreparedCatalog } from './prepared-catalog';
|
|
27
9
|
|
|
28
|
-
async
|
|
29
|
-
dataset
|
|
30
|
-
|
|
31
|
-
ids: Iterable<string>,
|
|
32
|
-
): Promise<Record<string, string>> {
|
|
33
|
-
const table = await clientDumpNames(dataset, lang);
|
|
34
|
-
for (const id of ids) {
|
|
35
|
-
if (table[id] === undefined && table[stackIdBase(id)] === undefined) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
`dump names missing id "${id}" for ${dataset.id} lang=${lang}`,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return { ...table };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function clientNamedCategories(
|
|
45
|
-
dataset: DatasetRef,
|
|
46
|
-
lang: string,
|
|
47
|
-
types: string[],
|
|
48
|
-
categories: RecipeCategory[],
|
|
49
|
-
): Promise<Record<string, string>> {
|
|
50
|
-
const map = await clientDumpLangNames(dataset, lang);
|
|
51
|
-
const byId = new Map(categories.map((row) => [row.id, row]));
|
|
52
|
-
const names: Record<string, string> = {};
|
|
53
|
-
for (const id of types) {
|
|
54
|
-
names[id] = creativeTabName(map, byId.get(id)?.display?.name ?? id);
|
|
55
|
-
}
|
|
56
|
-
return names;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function clientUsedIds(dataset: DatasetRef): Promise<string[]> {
|
|
60
|
-
const manifest = await loadClientManifest(dataset);
|
|
61
|
-
return manifest?.indexes.used ?? [];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function clientRecipeGroups(
|
|
65
|
-
dataset: DatasetRef,
|
|
66
|
-
lang: string,
|
|
67
|
-
): Promise<RecipeStackGroup[]> {
|
|
68
|
-
const rows = await loadClientRegistryGroups(dataset);
|
|
69
|
-
if (!rows.length) return [];
|
|
70
|
-
const map = await clientDumpLangNames(dataset, lang);
|
|
71
|
-
return rows.map((row) => ({
|
|
72
|
-
id: row.id,
|
|
73
|
-
...(row.name ? { name: dumpTextString(map, row.name) } : {}),
|
|
74
|
-
members: row.members,
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
10
|
+
const loadCatalog = createDatasetCache(async (dataset: DatasetRef) =>
|
|
11
|
+
parsePreparedCatalog(await clientDumpJson(dataset, 'registry/catalog.json')),
|
|
12
|
+
);
|
|
77
13
|
|
|
78
14
|
const loadChrome = createDatasetCache(
|
|
79
15
|
async (dataset: DatasetRef, lang: string): Promise<RecipeChrome> => {
|
|
80
|
-
const [
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
loadClientTabs(dataset),
|
|
84
|
-
loadDatasetRecipeCategories(dataset),
|
|
85
|
-
clientUsedIds(dataset),
|
|
86
|
-
]);
|
|
87
|
-
const tabs = creative.tabs;
|
|
88
|
-
const tabItems = Object.keys(creative.members).length
|
|
89
|
-
? creative.members
|
|
90
|
-
: undefined;
|
|
91
|
-
const types = categories.map((row) => row.id);
|
|
92
|
-
const [groups, mods, categoryNames, tabNames] = await Promise.all([
|
|
93
|
-
clientRecipeGroups(dataset, lang),
|
|
94
|
-
loadClientModNames(dataset, lang),
|
|
95
|
-
clientNamedCategories(dataset, lang, types, categories),
|
|
96
|
-
clientDumpLangNames(dataset, lang).then((map) => {
|
|
97
|
-
const names: Record<string, string> = {};
|
|
98
|
-
for (const tab of tabs) {
|
|
99
|
-
names[tab.id] = creativeTabName(map, tab.display.name ?? tab.id);
|
|
100
|
-
}
|
|
101
|
-
return names;
|
|
102
|
-
}),
|
|
16
|
+
const [catalog, labels] = await Promise.all([
|
|
17
|
+
loadCatalog(dataset),
|
|
18
|
+
clientDumpJson(dataset, `lang/${lang}.catalog.json`).then(parseCatalogLabels),
|
|
103
19
|
]);
|
|
104
20
|
return {
|
|
105
|
-
items,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
21
|
+
items: catalog.items,
|
|
22
|
+
fluids: catalog.fluids,
|
|
23
|
+
usedIds: catalog.usedIds,
|
|
24
|
+
tabs: catalog.tabs,
|
|
25
|
+
tabItems: catalog.tabItems,
|
|
26
|
+
categories: catalog.categories,
|
|
27
|
+
groups: catalog.groups.map((group) => ({
|
|
28
|
+
...group,
|
|
29
|
+
name: labels.groups[group.id],
|
|
30
|
+
})),
|
|
31
|
+
mods: labels.mods,
|
|
32
|
+
names: { [lang]: labels.names },
|
|
116
33
|
};
|
|
117
34
|
},
|
|
118
35
|
);
|
|
119
36
|
|
|
120
37
|
const loadEntityNames = createDatasetCache(
|
|
121
|
-
|
|
122
|
-
dataset
|
|
123
|
-
|
|
124
|
-
lang: string,
|
|
125
|
-
): Promise<Record<string, string>> => {
|
|
126
|
-
const [itemTags, blockTags] = await Promise.all([
|
|
127
|
-
loadClientTagMembers(dataset, 'item'),
|
|
128
|
-
loadClientTagMembers(dataset, 'block'),
|
|
129
|
-
]);
|
|
130
|
-
const tagIds = new Set([
|
|
131
|
-
...Object.keys(itemTags ?? {}),
|
|
132
|
-
...Object.keys(blockTags ?? {}),
|
|
133
|
-
]);
|
|
134
|
-
const nameIds = [
|
|
135
|
-
...chrome.items,
|
|
136
|
-
...(chrome.fluids ?? []),
|
|
137
|
-
...tagIds,
|
|
138
|
-
...(chrome.usedIds ?? []),
|
|
139
|
-
...Object.values(chrome.tabItems ?? {}).flat(),
|
|
140
|
-
...(chrome.tabs ?? []).flatMap((tab) =>
|
|
141
|
-
tab.icon ? [stackIdFromRef(tab.icon)] : [],
|
|
142
|
-
),
|
|
143
|
-
];
|
|
144
|
-
return clientEntityNames(dataset, lang, nameIds);
|
|
145
|
-
},
|
|
146
|
-
(dataset, _chrome, lang) => `${dataset.id}/${dataset.version ?? ''} ${lang}`,
|
|
38
|
+
(dataset: DatasetRef, lang: string): Promise<Record<string, string>> =>
|
|
39
|
+
clientDumpNames(dataset, lang),
|
|
40
|
+
(dataset, lang) => datasetCacheKey(dataset, lang),
|
|
147
41
|
);
|
|
148
42
|
|
|
149
43
|
export function loadRecipeChromeClient(
|
|
@@ -155,9 +49,8 @@ export function loadRecipeChromeClient(
|
|
|
155
49
|
|
|
156
50
|
export function loadRecipeEntityNames(
|
|
157
51
|
dataset: DatasetRef,
|
|
158
|
-
|
|
52
|
+
_chrome: RecipeChrome,
|
|
159
53
|
lang: string,
|
|
160
54
|
): Promise<Record<string, string>> {
|
|
161
|
-
return loadEntityNames(dataset,
|
|
55
|
+
return loadEntityNames(dataset, lang);
|
|
162
56
|
}
|
|
163
|
-
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { asRecord } from '@terrafirmagreg-team/dump/lib/dump/contract/read';
|
|
2
|
+
import { asTaggedReference } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
|
|
3
|
+
import type { DumpCreativeTab } from '@terrafirmagreg-team/dump/lib/dump/data/tab/dto';
|
|
4
|
+
import type { RecipeCategory } from '@terrafirmagreg-team/recipe/types';
|
|
5
|
+
import type { CatalogLabels, PreparedCatalog } from '@terrafirmagreg-team/recipe/types/catalog';
|
|
6
|
+
|
|
7
|
+
function strings(value: unknown): value is string[] {
|
|
8
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function stringMap(value: unknown): value is Record<string, string> {
|
|
12
|
+
const row = asRecord(value);
|
|
13
|
+
return !!row && Object.values(row).every((item) => typeof item === 'string');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function members(value: unknown): value is Record<string, string[]> {
|
|
17
|
+
const row = asRecord(value);
|
|
18
|
+
return !!row && Object.values(row).every(strings);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function orderedRow(value: unknown): value is Record<string, unknown> & { id: string; order: number } {
|
|
22
|
+
const row = asRecord(value);
|
|
23
|
+
return !!row && typeof row.id === 'string' && typeof row.order === 'number' &&
|
|
24
|
+
Number.isFinite(row.order) &&
|
|
25
|
+
(row.icon === undefined || !!asTaggedReference(row.icon));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function tab(value: unknown): value is DumpCreativeTab {
|
|
29
|
+
return orderedRow(value) && !!asRecord(value.display);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function category(value: unknown): value is RecipeCategory {
|
|
33
|
+
if (!orderedRow(value)) return false;
|
|
34
|
+
if (!Array.isArray(value.workstations) ||
|
|
35
|
+
!value.workstations.every((ref) => !!asTaggedReference(ref))) return false;
|
|
36
|
+
if (value.layout === undefined) return true;
|
|
37
|
+
const layout = asRecord(value.layout);
|
|
38
|
+
return !!layout && typeof layout.w === 'number' && typeof layout.h === 'number' &&
|
|
39
|
+
(layout.scale === undefined || typeof layout.scale === 'number') &&
|
|
40
|
+
(layout.margin === undefined || typeof layout.margin === 'number') &&
|
|
41
|
+
(layout.image === undefined || typeof layout.image === 'string') &&
|
|
42
|
+
Array.isArray(layout.slots) && layout.slots.every((value) => {
|
|
43
|
+
const slot = asRecord(value);
|
|
44
|
+
return !!slot && typeof slot.id === 'string' && typeof slot.role === 'string' &&
|
|
45
|
+
['x', 'y', 'w', 'h'].every((key) => typeof slot[key] === 'number');
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function group(value: unknown): value is PreparedCatalog['groups'][number] {
|
|
50
|
+
const row = asRecord(value);
|
|
51
|
+
return !!row && typeof row.id === 'string' && strings(row.members);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function parsePreparedCatalog(value: unknown): PreparedCatalog {
|
|
55
|
+
const row = asRecord(value);
|
|
56
|
+
if (!row || !strings(row.items) || !strings(row.fluids) || !strings(row.usedIds) ||
|
|
57
|
+
!Array.isArray(row.tabs) || !row.tabs.every(tab) ||
|
|
58
|
+
!members(row.tabItems) || !Array.isArray(row.categories) ||
|
|
59
|
+
!row.categories.every(category) || !Array.isArray(row.groups) ||
|
|
60
|
+
!row.groups.every(group)) {
|
|
61
|
+
throw new Error('Invalid required registry/catalog.json');
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
items: row.items,
|
|
65
|
+
fluids: row.fluids,
|
|
66
|
+
usedIds: row.usedIds,
|
|
67
|
+
tabs: row.tabs,
|
|
68
|
+
tabItems: row.tabItems,
|
|
69
|
+
categories: row.categories,
|
|
70
|
+
groups: row.groups,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function parseCatalogLabels(value: unknown): CatalogLabels {
|
|
75
|
+
const row = asRecord(value);
|
|
76
|
+
if (!row || !stringMap(row.mods) || !stringMap(row.names) || !stringMap(row.groups)) {
|
|
77
|
+
throw new Error('Invalid required locale catalog');
|
|
78
|
+
}
|
|
79
|
+
return { mods: row.mods, names: row.names, groups: row.groups };
|
|
80
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { datasetCacheKey, type DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
2
2
|
import { clientRegistryUsesEntries } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
|
|
3
3
|
import { loadClientTagMembers } from '@terrafirmagreg-team/dump/lib/dump/client/tags';
|
|
4
4
|
import {
|
|
@@ -82,7 +82,7 @@ const tagMembersByKindCache = createDatasetCache(
|
|
|
82
82
|
return (await loadClientTagMembers(dataset, memberKind)) ?? {};
|
|
83
83
|
},
|
|
84
84
|
(dataset, kind) =>
|
|
85
|
-
|
|
85
|
+
datasetCacheKey(dataset, registryField(kind) === 'blocks' ? 'block' : 'item'),
|
|
86
86
|
);
|
|
87
87
|
|
|
88
88
|
const allTagMembersCache = createDatasetCache(
|
|
@@ -97,7 +97,7 @@ const allTagMembersCache = createDatasetCache(
|
|
|
97
97
|
}
|
|
98
98
|
return merged;
|
|
99
99
|
},
|
|
100
|
-
(dataset) =>
|
|
100
|
+
(dataset) => datasetCacheKey(dataset, 'all'),
|
|
101
101
|
);
|
|
102
102
|
|
|
103
103
|
function loadTagMembersByKind(
|
|
@@ -112,4 +112,3 @@ export function loadAllTagMembers(
|
|
|
112
112
|
): Promise<Record<string, string[]>> {
|
|
113
113
|
return allTagMembersCache(dataset);
|
|
114
114
|
}
|
|
115
|
-
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test, type TestContext } from 'node:test';
|
|
3
|
+
import { gzipSync } from 'node:zlib';
|
|
4
|
+
import type { DatasetSnapshot } from '@terrafirmagreg-team/sites/location';
|
|
5
|
+
import type { PreparedRecipeRow } from '@terrafirmagreg-team/dump/lib/dump/gen';
|
|
6
|
+
import type { SnapshotIndex } from '@terrafirmagreg-team/dump/types/snapshot';
|
|
7
|
+
import type { RecipeCompactIndex } from '@terrafirmagreg-team/recipe/types';
|
|
8
|
+
import { clientRecipeFileRels, loadClientRecipe } from '../client/recipe';
|
|
9
|
+
import { loadCategoryRecipes, loadTypeRows, resolveRecipeRows } from './rows';
|
|
10
|
+
|
|
11
|
+
function fixture(t: TestContext, id: string) {
|
|
12
|
+
process.env.NEXT_PUBLIC_DUMP_STORAGE_URL = 'https://recipe.invalid';
|
|
13
|
+
const dataset: DatasetSnapshot = { id, version: '1', revision: 'a'.repeat(64) };
|
|
14
|
+
const root = `${id}/1/revisions/${dataset.revision}`;
|
|
15
|
+
const bucketA = 'data/r/recipes/a/craft/blocks/0.json';
|
|
16
|
+
const bucketB = 'data/r/recipes/b/craft/blocks/0.json';
|
|
17
|
+
const bucketNext = 'data/r/recipes/a/craft/blocks/1.json';
|
|
18
|
+
const makeRow = (category: string, bucket: string, recipeId = 'r:shared', order = 0): PreparedRecipeRow => ({
|
|
19
|
+
id: recipeId, category, bucket, order,
|
|
20
|
+
inputs: ['r:input{"mode":1}', '#r:tag'], outputs: ['r:output'],
|
|
21
|
+
image: 'r:image', w: 80, h: 40,
|
|
22
|
+
});
|
|
23
|
+
const a = makeRow('a:craft', bucketA);
|
|
24
|
+
const b = makeRow('b:craft', bucketB);
|
|
25
|
+
const duplicate = makeRow('a:craft', bucketNext, 'r:shared/dup_1', 1);
|
|
26
|
+
const tag = makeRow('emi:tag', 'data/r/recipes/emi/tag/blocks/0.json');
|
|
27
|
+
const types = [
|
|
28
|
+
{ id: 'a:craft', count: 2, rows: 'data/a/index/recipes/craft.json' },
|
|
29
|
+
{ id: 'b:craft', count: 1, rows: 'data/b/index/recipes/craft.json' },
|
|
30
|
+
{ id: 'emi:tag', count: 1, rows: 'data/emi/index/recipes/tag.json' },
|
|
31
|
+
];
|
|
32
|
+
const body = (category: string) => ({ category, slots: {}, properties: {} });
|
|
33
|
+
const documents: Record<string, unknown> = {
|
|
34
|
+
'manifest.json': {
|
|
35
|
+
schema: 'manifest', layout: 'v3', languages: [],
|
|
36
|
+
producer: { name: 'fixture', platform: 'test', minecraft: 'test' },
|
|
37
|
+
indexes: { quests: {}, recipes: { types }, used: [] },
|
|
38
|
+
namespaces: {
|
|
39
|
+
r: { display: { name: 'r' }, registry: ['recipes'], guides: [], languages: [], quests: false, keybinds: false },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
[types[0]!.rows]: { rows: [duplicate, a] },
|
|
43
|
+
[types[1]!.rows]: { rows: [b] },
|
|
44
|
+
[types[2]!.rows]: { rows: [tag] },
|
|
45
|
+
'registry/recipes.ndjson': { 'r:shared': [a, b, tag], 'r:shared/dup_1': [duplicate] },
|
|
46
|
+
[bucketA]: { 'r:shared': body('a:craft') },
|
|
47
|
+
[bucketB]: { 'r:shared': body('b:craft') },
|
|
48
|
+
[bucketNext]: { 'r:shared/dup_1': body('a:craft') },
|
|
49
|
+
};
|
|
50
|
+
const snapshot: SnapshotIndex = { files: {}, artifacts: {} };
|
|
51
|
+
for (const path of Object.keys(documents)) {
|
|
52
|
+
snapshot.files[path] = `${root}/${path}`;
|
|
53
|
+
snapshot.artifacts[path] = {
|
|
54
|
+
sha256: 'b'.repeat(64), bytes: 10, codec: path.endsWith('.ndjson') ? 'ndjson' : 'json', compression: 'none',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const requests: string[] = [];
|
|
58
|
+
t.mock.method(globalThis, 'fetch', async (input: string | URL | Request) => {
|
|
59
|
+
const url = String(input);
|
|
60
|
+
requests.push(url);
|
|
61
|
+
if (url.endsWith('/versions.json')) {
|
|
62
|
+
return Response.json({
|
|
63
|
+
pack: id, latest: '1', versions: ['1'],
|
|
64
|
+
snapshots: { '1': {
|
|
65
|
+
revision: dataset.revision, publishedAt: '2026-01-01T00:00:00Z',
|
|
66
|
+
index: `${root}/objects.json.gz`,
|
|
67
|
+
} },
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (url.endsWith('/objects.json.gz')) {
|
|
71
|
+
return new Response(new Uint8Array(gzipSync(JSON.stringify(snapshot))));
|
|
72
|
+
}
|
|
73
|
+
const path = url.slice(`https://recipe.invalid/${root}/`.length);
|
|
74
|
+
const document = documents[path];
|
|
75
|
+
assert.notEqual(document, undefined, `Unexpected request: ${url}`);
|
|
76
|
+
if (path.endsWith('.ndjson')) {
|
|
77
|
+
return new Response(Object.entries(document as Record<string, unknown>)
|
|
78
|
+
.map(([key, value]) => JSON.stringify({ [key]: value })).join('\n'));
|
|
79
|
+
}
|
|
80
|
+
return Response.json(document);
|
|
81
|
+
});
|
|
82
|
+
const index: RecipeCompactIndex = {
|
|
83
|
+
types: ['b:craft', 'a:craft', 'emi:tag'], items: [], names: {},
|
|
84
|
+
};
|
|
85
|
+
return { dataset, index, requests, bucketA, bucketB, bucketNext };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
test('type rows only read prepared metadata and preserve order and refs', async (t) => {
|
|
89
|
+
const { dataset, index, requests, bucketA } = fixture(t, 'recipe-type');
|
|
90
|
+
const rows = await loadTypeRows({ id: dataset.id }, index, 'a:craft');
|
|
91
|
+
assert.deepEqual(rows.map((row) => row.id), ['r:shared', 'r:shared/dup_1']);
|
|
92
|
+
assert.equal(rows[0]!.type, 1);
|
|
93
|
+
assert.equal(rows[0]!.bucket, bucketA);
|
|
94
|
+
assert.deepEqual(rows[0]!.in, ['r:input{"mode":1}', '#r:tag']);
|
|
95
|
+
assert.deepEqual(rows[0]!.d, { w: 80, h: 40 });
|
|
96
|
+
assert.ok(rows[0]!.bodyUrl?.endsWith(bucketA));
|
|
97
|
+
const reordered = await loadTypeRows(dataset, { ...index, types: ['a:craft'] }, 'a:craft');
|
|
98
|
+
assert.equal(reordered[0]!.type, 0);
|
|
99
|
+
assert.equal(requests.filter((url) => url.includes('/blocks/')).length, 0);
|
|
100
|
+
assert.equal(requests.filter((url) => url.endsWith('/registry/recipes.ndjson')).length, 0);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('selected recipe reads only its block, and calculator can load all category blocks', async (t) => {
|
|
104
|
+
const { dataset, index, requests, bucketA, bucketB, bucketNext } = fixture(t, 'recipe-body');
|
|
105
|
+
const rows = await loadTypeRows(dataset, index, 'a:craft');
|
|
106
|
+
const recipe = await loadClientRecipe(dataset, rows[0]!.id, rows[0]!.bucket);
|
|
107
|
+
assert.equal(recipe?.type, 'a:craft');
|
|
108
|
+
assert.deepEqual(requests.filter((url) => url.includes('/blocks/')).map((url) => url.split('/data/')[1]),
|
|
109
|
+
[bucketA.slice(5)]);
|
|
110
|
+
const category = await loadCategoryRecipes(dataset, index, 'a:craft');
|
|
111
|
+
assert.deepEqual(category.map((entry) => entry.id), ['r:shared', 'r:shared/dup_1']);
|
|
112
|
+
assert.ok(requests.some((url) => url.endsWith(bucketNext)));
|
|
113
|
+
assert.ok(!requests.some((url) => url.endsWith(bucketB)));
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('registry lookup preserves category-scoped bare IDs and real dup suffixes without bodies', async (t) => {
|
|
117
|
+
const { dataset, index, requests, bucketA, bucketB } = fixture(t, 'recipe-lookup');
|
|
118
|
+
const rows = await resolveRecipeRows(dataset, index, ['r:shared', 'r:shared/dup_1', 'r:shared'], { includeTagRows: false });
|
|
119
|
+
assert.deepEqual(rows.map((row) => [index.types[row.type], row.id]), [
|
|
120
|
+
['a:craft', 'r:shared'], ['b:craft', 'r:shared'], ['a:craft', 'r:shared/dup_1'],
|
|
121
|
+
]);
|
|
122
|
+
assert.deepEqual((await clientRecipeFileRels(dataset, 'r:shared')).slice(0, 2), [bucketA, bucketB]);
|
|
123
|
+
assert.equal((await resolveRecipeRows(dataset, index, ['r:shared'])).length, 3);
|
|
124
|
+
const unknown = await resolveRecipeRows(dataset, { ...index, types: [] }, ['r:shared'], { includeTagRows: false });
|
|
125
|
+
assert.deepEqual(unknown.map((row) => row.cat), ['a:craft', 'b:craft']);
|
|
126
|
+
assert.equal(requests.filter((url) => url.includes('/blocks/')).length, 0);
|
|
127
|
+
});
|