@dreamboard-games/workspace-codegen 0.1.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 (73) hide show
  1. package/LICENSE +89 -0
  2. package/NOTICE +1 -0
  3. package/dist/hex-geometry.d.ts +2 -0
  4. package/dist/hex-geometry.js +49 -0
  5. package/dist/index.d.ts +13 -0
  6. package/dist/index.js +22 -0
  7. package/dist/manifest-contract.d.ts +14 -0
  8. package/dist/manifest-contract.js +4897 -0
  9. package/dist/manifest-validation.d.ts +6 -0
  10. package/dist/manifest-validation.js +506 -0
  11. package/dist/ownership.d.ts +31 -0
  12. package/dist/ownership.js +86 -0
  13. package/dist/preset-card-sets.d.ts +5 -0
  14. package/dist/preset-card-sets.js +135 -0
  15. package/dist/seeds.d.ts +6 -0
  16. package/dist/seeds.js +766 -0
  17. package/ownership.json +51 -0
  18. package/package.json +46 -0
  19. package/src/__fixtures__/sdk-types/invalid-card-properties-extra-key.ts +62 -0
  20. package/src/__fixtures__/sdk-types/invalid-card-properties-missing-required.ts +60 -0
  21. package/src/__fixtures__/sdk-types/invalid-card-properties-wrong-enum.ts +61 -0
  22. package/src/__fixtures__/sdk-types/invalid-card-properties-wrong-nested.ts +61 -0
  23. package/src/__fixtures__/sdk-types/invalid-card-properties-wrong-scalar.ts +61 -0
  24. package/src/__fixtures__/sdk-types/invalid-card-visibility.ts +40 -0
  25. package/src/__fixtures__/sdk-types/invalid-container-card-set-manifest.ts +62 -0
  26. package/src/__fixtures__/sdk-types/invalid-die-fields-wrong-array-item.ts +43 -0
  27. package/src/__fixtures__/sdk-types/invalid-die-fields-wrong-player-id.ts +43 -0
  28. package/src/__fixtures__/sdk-types/invalid-die-fields-wrong-resource-id.ts +43 -0
  29. package/src/__fixtures__/sdk-types/invalid-die-home-per-player-zone-no-owner.ts +35 -0
  30. package/src/__fixtures__/sdk-types/invalid-die-seed-type-id.ts +31 -0
  31. package/src/__fixtures__/sdk-types/invalid-die-visibility.ts +28 -0
  32. package/src/__fixtures__/sdk-types/invalid-generic-board-edge-id.ts +38 -0
  33. package/src/__fixtures__/sdk-types/invalid-generic-board-nested-field.ts +45 -0
  34. package/src/__fixtures__/sdk-types/invalid-hex-edge-field-edge-id.ts +47 -0
  35. package/src/__fixtures__/sdk-types/invalid-hex-vertex-field-vertex-id.ts +47 -0
  36. package/src/__fixtures__/sdk-types/invalid-manifest.ts +143 -0
  37. package/src/__fixtures__/sdk-types/invalid-piece-fields-extra-key.ts +62 -0
  38. package/src/__fixtures__/sdk-types/invalid-piece-fields-wrong-card-id.ts +61 -0
  39. package/src/__fixtures__/sdk-types/invalid-piece-fields-wrong-enum.ts +61 -0
  40. package/src/__fixtures__/sdk-types/invalid-piece-fields-wrong-scalar.ts +61 -0
  41. package/src/__fixtures__/sdk-types/invalid-piece-fields-wrong-zone-id.ts +61 -0
  42. package/src/__fixtures__/sdk-types/invalid-piece-home-per-player-container-no-owner.ts +48 -0
  43. package/src/__fixtures__/sdk-types/invalid-piece-home-per-player-edge-no-owner.ts +47 -0
  44. package/src/__fixtures__/sdk-types/invalid-piece-home-per-player-space-no-owner.ts +42 -0
  45. package/src/__fixtures__/sdk-types/invalid-piece-home-per-player-vertex-no-owner.ts +49 -0
  46. package/src/__fixtures__/sdk-types/invalid-piece-seed-type-id.ts +30 -0
  47. package/src/__fixtures__/sdk-types/invalid-piece-visibility.ts +28 -0
  48. package/src/__fixtures__/sdk-types/invalid-slot-host-manifest.ts +47 -0
  49. package/src/__fixtures__/sdk-types/invalid-slot-id-manifest.ts +49 -0
  50. package/src/__fixtures__/sdk-types/invalid-square-board-edge-id.ts +47 -0
  51. package/src/__fixtures__/sdk-types/invalid-square-board-space-id.ts +47 -0
  52. package/src/__fixtures__/sdk-types/invalid-square-board-vertex-id.ts +49 -0
  53. package/src/__fixtures__/sdk-types/invalid-square-container-field-space-id.ts +59 -0
  54. package/src/__fixtures__/sdk-types/invalid-square-container-host-space-id.ts +49 -0
  55. package/src/__fixtures__/sdk-types/invalid-square-relation-field-scalar.ts +48 -0
  56. package/src/__fixtures__/sdk-types/invalid-square-relation-space-id.ts +48 -0
  57. package/src/__fixtures__/sdk-types/invalid-square-space-fields-enum.ts +44 -0
  58. package/src/__fixtures__/sdk-types/invalid-square-space-fields-extra-key.ts +45 -0
  59. package/src/__fixtures__/sdk-types/valid-die-type-omits-sides.ts +29 -0
  60. package/src/__fixtures__/sdk-types/valid-manifest-omits-board-templates.ts +19 -0
  61. package/src/__fixtures__/sdk-types/valid-manifest.ts +612 -0
  62. package/src/__fixtures__/sdk-types/valid-player-scoped-seed-homes.ts +59 -0
  63. package/src/authoring-benchmark.test.ts +362 -0
  64. package/src/hex-geometry.ts +69 -0
  65. package/src/index.ts +64 -0
  66. package/src/manifest-contract.test.ts +1764 -0
  67. package/src/manifest-contract.ts +6581 -0
  68. package/src/manifest-validation.test.ts +393 -0
  69. package/src/manifest-validation.ts +795 -0
  70. package/src/ownership.ts +127 -0
  71. package/src/preset-card-sets.ts +169 -0
  72. package/src/sdk-types-authoring.test.ts +361 -0
  73. package/src/seeds.ts +800 -0
@@ -0,0 +1,6 @@
1
+ import type { GameTopologyManifest } from "@dreamboard/sdk-types";
2
+ export type ManifestAuthoringValidationResult = {
3
+ errors: string[];
4
+ warnings: string[];
5
+ };
6
+ export declare function validateManifestAuthoring(manifest: GameTopologyManifest): ManifestAuthoringValidationResult;
@@ -0,0 +1,506 @@
1
+ import { resolveHexVertexGeometryKey } from "./hex-geometry.js";
2
+ function isHexBoardTemplateSpec(boardTemplate) {
3
+ return boardTemplate.layout === "hex";
4
+ }
5
+ function isHexBoardSpec(board) {
6
+ return board.layout === "hex";
7
+ }
8
+ function collectDuplicateIdIssues(options) {
9
+ const issues = [];
10
+ const pathsById = new Map();
11
+ for (const entry of options.entries) {
12
+ const id = entry.id?.trim();
13
+ if (!id) {
14
+ continue;
15
+ }
16
+ const paths = pathsById.get(id) ?? [];
17
+ paths.push(entry.path);
18
+ pathsById.set(id, paths);
19
+ }
20
+ for (const [id, paths] of pathsById.entries()) {
21
+ if (paths.length > 1) {
22
+ issues.push(`${paths.join(", ")}: Duplicate ${options.label} '${id}'.`);
23
+ }
24
+ }
25
+ return issues;
26
+ }
27
+ function renderCardInstanceIds(card) {
28
+ return card.count > 1
29
+ ? Array.from({ length: card.count }, (_, index) => `${card.type}-${index + 1}`)
30
+ : [card.type];
31
+ }
32
+ function expandSeedIds(seeds) {
33
+ return seeds.flatMap((seed) => {
34
+ const count = seed.count ?? 1;
35
+ const baseId = seed.id ?? seed.typeId;
36
+ return count > 1
37
+ ? Array.from({ length: count }, (_, index) => `${baseId}-${index + 1}`)
38
+ : [baseId];
39
+ });
40
+ }
41
+ function validateTypeSlotDuplicates(options) {
42
+ const issues = [];
43
+ for (const [index, pieceType] of options.pieceTypes.entries()) {
44
+ issues.push(...collectDuplicateIdIssues({
45
+ entries: (pieceType.slots ?? []).map((slot, slotIndex) => ({
46
+ id: slot.id,
47
+ path: `manifest.pieceTypes[${index}].slots[${slotIndex}].id`,
48
+ })),
49
+ label: "piece slot id",
50
+ }));
51
+ }
52
+ for (const [index, dieType] of options.dieTypes.entries()) {
53
+ issues.push(...collectDuplicateIdIssues({
54
+ entries: (dieType.slots ?? []).map((slot, slotIndex) => ({
55
+ id: slot.id,
56
+ path: `manifest.dieTypes[${index}].slots[${slotIndex}].id`,
57
+ })),
58
+ label: "die slot id",
59
+ }));
60
+ }
61
+ return issues;
62
+ }
63
+ function validateSlotHostsAndHomes(manifest) {
64
+ const issues = [];
65
+ const pieceTypesById = new Map((manifest.pieceTypes ?? []).map((pieceType) => [pieceType.id, pieceType]));
66
+ const dieTypesById = new Map((manifest.dieTypes ?? []).map((dieType) => [dieType.id, dieType]));
67
+ const slotIdsByHostKey = new Map();
68
+ for (const [index, seed] of (manifest.pieceSeeds ?? []).entries()) {
69
+ const pieceType = pieceTypesById.get(seed.typeId);
70
+ const slotIds = (pieceType?.slots ?? []).map((slot) => slot.id);
71
+ if (slotIds.length === 0) {
72
+ continue;
73
+ }
74
+ if (typeof seed.id !== "string" || seed.id.length === 0) {
75
+ issues.push(`manifest.pieceSeeds[${index}].id: Piece seed for slot-bearing type '${seed.typeId}' must declare an explicit id.`);
76
+ continue;
77
+ }
78
+ if ((seed.count ?? 1) !== 1) {
79
+ issues.push(`manifest.pieceSeeds[${index}].count: Piece seed '${seed.id}' for slot-bearing type '${seed.typeId}' must omit count or set it to 1.`);
80
+ continue;
81
+ }
82
+ slotIdsByHostKey.set(`piece:${seed.id}`, new Set(slotIds));
83
+ }
84
+ for (const [index, seed] of (manifest.dieSeeds ?? []).entries()) {
85
+ const dieType = dieTypesById.get(seed.typeId);
86
+ const slotIds = (dieType?.slots ?? []).map((slot) => slot.id);
87
+ if (slotIds.length === 0) {
88
+ continue;
89
+ }
90
+ if (typeof seed.id !== "string" || seed.id.length === 0) {
91
+ issues.push(`manifest.dieSeeds[${index}].id: Die seed for slot-bearing type '${seed.typeId}' must declare an explicit id.`);
92
+ continue;
93
+ }
94
+ if ((seed.count ?? 1) !== 1) {
95
+ issues.push(`manifest.dieSeeds[${index}].count: Die seed '${seed.id}' for slot-bearing type '${seed.typeId}' must omit count or set it to 1.`);
96
+ continue;
97
+ }
98
+ slotIdsByHostKey.set(`die:${seed.id}`, new Set(slotIds));
99
+ }
100
+ const validateHome = (home, path) => {
101
+ if (home?.type !== "slot") {
102
+ return;
103
+ }
104
+ const hostKey = `${home.host.kind}:${home.host.id}`;
105
+ const slotIds = slotIdsByHostKey.get(hostKey);
106
+ if (!slotIds) {
107
+ issues.push(`${path}.host: Unknown strict slot host '${home.host.kind}:${home.host.id}'. Hosts must be singleton piece/die seeds whose type declares slots.`);
108
+ return;
109
+ }
110
+ if (!slotIds.has(home.slotId)) {
111
+ issues.push(`${path}.slotId: Unknown slot '${home.slotId}' for host '${home.host.kind}:${home.host.id}'.`);
112
+ }
113
+ };
114
+ for (const [cardSetIndex, cardSet] of manifest.cardSets.entries()) {
115
+ if (cardSet.type !== "manual") {
116
+ continue;
117
+ }
118
+ for (const [cardIndex, card] of cardSet.cards.entries()) {
119
+ validateHome(card.home, `manifest.cardSets[${cardSetIndex}].cards[${cardIndex}].home`);
120
+ }
121
+ }
122
+ for (const [index, seed] of (manifest.pieceSeeds ?? []).entries()) {
123
+ validateHome(seed.home, `manifest.pieceSeeds[${index}].home`);
124
+ }
125
+ for (const [index, seed] of (manifest.dieSeeds ?? []).entries()) {
126
+ validateHome(seed.home, `manifest.dieSeeds[${index}].home`);
127
+ }
128
+ return issues;
129
+ }
130
+ function validateSetupProfileReferences(manifest) {
131
+ const issues = [];
132
+ const optionChoiceIdsByOptionId = new Map((manifest.setupOptions ?? []).map((option, optionIndex) => {
133
+ const choiceIds = new Set();
134
+ for (const choice of option.choices ?? []) {
135
+ choiceIds.add(choice.id);
136
+ }
137
+ if (!option.id) {
138
+ issues.push(`manifest.setupOptions[${optionIndex}].id: Missing option id.`);
139
+ }
140
+ return [option.id, choiceIds];
141
+ }));
142
+ for (const [profileIndex, profile] of (manifest.setupProfiles ?? []).entries()) {
143
+ const optionValues = profile.optionValues ?? {};
144
+ for (const [optionId, choiceId] of Object.entries(optionValues)) {
145
+ const allowedChoices = optionChoiceIdsByOptionId.get(optionId);
146
+ if (!allowedChoices) {
147
+ issues.push(`manifest.setupProfiles[${profileIndex}].optionValues.${optionId}: Unknown setup option '${optionId}'.`);
148
+ continue;
149
+ }
150
+ if (!allowedChoices.has(choiceId)) {
151
+ issues.push(`manifest.setupProfiles[${profileIndex}].optionValues.${optionId}: Unknown choice '${choiceId}' for setup option '${optionId}'.`);
152
+ }
153
+ }
154
+ }
155
+ return issues;
156
+ }
157
+ function validatePlayerScopedSeedHomes(manifest) {
158
+ const issues = [];
159
+ const boardScopeById = new Map((manifest.boards ?? []).map((board) => [board.id, board.scope]));
160
+ const zoneScopeById = new Map((manifest.zones ?? []).map((zone) => [zone.id, zone.scope]));
161
+ const validateSeedHome = (seed, path, label) => {
162
+ const authoredId = seed.id ?? seed.typeId;
163
+ if (seed.ownerId) {
164
+ return;
165
+ }
166
+ if (homeTargetsBoard(seed.home) &&
167
+ boardScopeById.get(seed.home.boardId) === "perPlayer") {
168
+ issues.push(`${path}.boardId: ${label} '${authoredId}' requires ownerId because board '${seed.home.boardId}' has scope 'perPlayer'. Add ownerId to resolve the player-scoped destination.`);
169
+ return;
170
+ }
171
+ if (seed.home?.type === "zone" &&
172
+ zoneScopeById.get(seed.home.zoneId) === "perPlayer") {
173
+ issues.push(`${path}.zoneId: ${label} '${authoredId}' requires ownerId because zone '${seed.home.zoneId}' has scope 'perPlayer'. Add ownerId to resolve the player-scoped destination.`);
174
+ }
175
+ };
176
+ for (const [index, seed] of (manifest.pieceSeeds ?? []).entries()) {
177
+ validateSeedHome(seed, `manifest.pieceSeeds[${index}].home`, "Piece seed");
178
+ }
179
+ for (const [index, seed] of (manifest.dieSeeds ?? []).entries()) {
180
+ validateSeedHome(seed, `manifest.dieSeeds[${index}].home`, "Die seed");
181
+ }
182
+ return issues;
183
+ }
184
+ function homeTargetsBoard(home) {
185
+ return (home?.type === "space" ||
186
+ home?.type === "container" ||
187
+ home?.type === "edge" ||
188
+ home?.type === "vertex");
189
+ }
190
+ function validateBoardTemplateDuplicates(boardTemplates) {
191
+ const issues = [];
192
+ for (const [index, boardTemplate] of boardTemplates.entries()) {
193
+ if (isHexBoardTemplateSpec(boardTemplate)) {
194
+ issues.push(...collectDuplicateIdIssues({
195
+ entries: (boardTemplate.spaces ?? []).map((space, spaceIndex) => ({
196
+ id: space.id,
197
+ path: `manifest.boardTemplates[${index}].spaces[${spaceIndex}].id`,
198
+ })),
199
+ label: "space id",
200
+ }));
201
+ continue;
202
+ }
203
+ issues.push(...collectDuplicateIdIssues({
204
+ entries: (boardTemplate.spaces ?? []).map((space, spaceIndex) => ({
205
+ id: space.id,
206
+ path: `manifest.boardTemplates[${index}].spaces[${spaceIndex}].id`,
207
+ })),
208
+ label: "space id",
209
+ }));
210
+ issues.push(...collectDuplicateIdIssues({
211
+ entries: (boardTemplate.containers ?? []).map((container, containerIndex) => ({
212
+ id: container.id,
213
+ path: `manifest.boardTemplates[${index}].containers[${containerIndex}].id`,
214
+ })),
215
+ label: "container id",
216
+ }));
217
+ issues.push(...collectDuplicateIdIssues({
218
+ entries: (boardTemplate.relations ?? []).map((relation, relationIndex) => ({
219
+ id: relation.id,
220
+ path: `manifest.boardTemplates[${index}].relations[${relationIndex}].id`,
221
+ })),
222
+ label: "relation id",
223
+ }));
224
+ }
225
+ return issues;
226
+ }
227
+ function validateBoardDuplicates(boards) {
228
+ const issues = [];
229
+ for (const [index, board] of boards.entries()) {
230
+ if (isHexBoardSpec(board)) {
231
+ issues.push(...collectDuplicateIdIssues({
232
+ entries: (board.spaces ?? []).map((space, spaceIndex) => ({
233
+ id: space.id,
234
+ path: `manifest.boards[${index}].spaces[${spaceIndex}].id`,
235
+ })),
236
+ label: "space id",
237
+ }));
238
+ continue;
239
+ }
240
+ issues.push(...collectDuplicateIdIssues({
241
+ entries: (board.spaces ?? []).map((space, spaceIndex) => ({
242
+ id: space.id,
243
+ path: `manifest.boards[${index}].spaces[${spaceIndex}].id`,
244
+ })),
245
+ label: "space id",
246
+ }));
247
+ issues.push(...collectDuplicateIdIssues({
248
+ entries: (board.containers ?? []).map((container, containerIndex) => ({
249
+ id: container.id,
250
+ path: `manifest.boards[${index}].containers[${containerIndex}].id`,
251
+ })),
252
+ label: "container id",
253
+ }));
254
+ issues.push(...collectDuplicateIdIssues({
255
+ entries: (board.relations ?? []).map((relation, relationIndex) => ({
256
+ id: relation.id,
257
+ path: `manifest.boards[${index}].relations[${relationIndex}].id`,
258
+ })),
259
+ label: "relation id",
260
+ }));
261
+ }
262
+ return issues;
263
+ }
264
+ function validateSetupOptionChoiceDuplicates(options) {
265
+ const issues = [];
266
+ for (const [optionIndex, option] of options.entries()) {
267
+ issues.push(...collectDuplicateIdIssues({
268
+ entries: (option.choices ?? []).map((choice, choiceIndex) => ({
269
+ id: choice.id,
270
+ path: `manifest.setupOptions[${optionIndex}].choices[${choiceIndex}].id`,
271
+ })),
272
+ label: "setup option choice id",
273
+ }));
274
+ }
275
+ return issues;
276
+ }
277
+ function resolveHexSpaces(board, template) {
278
+ if (!template) {
279
+ return [...(board.spaces ?? [])].sort((left, right) => left.id.localeCompare(right.id));
280
+ }
281
+ const templateSpacesById = new Map((template.spaces ?? []).map((space) => [space.id, space]));
282
+ const overridesById = new Map((board.spaces ?? []).map((space) => [space.id, space]));
283
+ for (const overrideId of overridesById.keys()) {
284
+ if (!templateSpacesById.has(overrideId)) {
285
+ continue;
286
+ }
287
+ }
288
+ return (template.spaces ?? [])
289
+ .map((templateSpace) => {
290
+ const override = overridesById.get(templateSpace.id);
291
+ if (!override) {
292
+ return templateSpace;
293
+ }
294
+ return {
295
+ ...templateSpace,
296
+ ...override,
297
+ id: templateSpace.id,
298
+ q: templateSpace.q,
299
+ r: templateSpace.r,
300
+ };
301
+ })
302
+ .sort((left, right) => left.id.localeCompare(right.id));
303
+ }
304
+ function validateHexVertexRefs(options) {
305
+ const issues = [];
306
+ const spacesById = new Map(options.spaces.map((space) => [space.id, space]));
307
+ for (const [vertexIndex, vertex] of options.vertices.entries()) {
308
+ try {
309
+ resolveHexVertexGeometryKey(vertex.ref, spacesById);
310
+ }
311
+ catch (error) {
312
+ const message = error instanceof Error ? error.message : "Unknown hex vertex error.";
313
+ issues.push(`${options.ownerPath}.vertices[${vertexIndex}].ref: ${options.ownerLabel} with spaces '${vertex.ref.spaces.join(", ")}' failed validation. ${message}`);
314
+ }
315
+ }
316
+ return issues;
317
+ }
318
+ function validateHexBoardVertexRefs(manifest) {
319
+ const issues = [];
320
+ const hexTemplatesById = new Map((manifest.boardTemplates ?? [])
321
+ .filter(isHexBoardTemplateSpec)
322
+ .map((boardTemplate) => [boardTemplate.id, boardTemplate]));
323
+ for (const [templateIndex, template] of (manifest.boardTemplates ?? []).entries()) {
324
+ if (!isHexBoardTemplateSpec(template)) {
325
+ continue;
326
+ }
327
+ issues.push(...validateHexVertexRefs({
328
+ ownerPath: `manifest.boardTemplates[${templateIndex}]`,
329
+ ownerLabel: `Hex board template '${template.id}'`,
330
+ spaces: template.spaces ?? [],
331
+ vertices: template.vertices ?? [],
332
+ }));
333
+ }
334
+ for (const [boardIndex, board] of (manifest.boards ?? []).entries()) {
335
+ if (!isHexBoardSpec(board)) {
336
+ continue;
337
+ }
338
+ issues.push(...validateHexVertexRefs({
339
+ ownerPath: `manifest.boards[${boardIndex}]`,
340
+ ownerLabel: `Hex board '${board.id}'`,
341
+ spaces: resolveHexSpaces(board, hexTemplatesById.get(board.templateId ?? "")),
342
+ vertices: board.vertices ?? [],
343
+ }));
344
+ }
345
+ return issues;
346
+ }
347
+ function collectAmbiguousBoardTypeWarnings(manifest) {
348
+ const warnings = [];
349
+ const boardTemplatesById = new Map((manifest.boardTemplates ?? []).map((template) => [template.id, template]));
350
+ const boardsBySpaceType = new Map();
351
+ const boardsByEdgeType = new Map();
352
+ const boardsByVertexType = new Map();
353
+ const addBoardUsage = (target, typeId, boardId) => {
354
+ if (!typeId) {
355
+ return;
356
+ }
357
+ const boardIds = target.get(typeId) ?? new Set();
358
+ boardIds.add(boardId);
359
+ target.set(typeId, boardIds);
360
+ };
361
+ for (const board of manifest.boards ?? []) {
362
+ const template = board.templateId
363
+ ? boardTemplatesById.get(board.templateId)
364
+ : undefined;
365
+ for (const space of [
366
+ ...((template?.layout === board.layout ? template.spaces : undefined) ??
367
+ []),
368
+ ...(board.spaces ?? []),
369
+ ]) {
370
+ addBoardUsage(boardsBySpaceType, space.typeId, board.id);
371
+ }
372
+ if (board.layout === "hex" || board.layout === "square") {
373
+ for (const edge of [
374
+ ...((template?.layout === board.layout ? template.edges : undefined) ??
375
+ []),
376
+ ...(board.edges ?? []),
377
+ ]) {
378
+ addBoardUsage(boardsByEdgeType, edge.typeId, board.id);
379
+ }
380
+ for (const vertex of [
381
+ ...((template?.layout === board.layout
382
+ ? template.vertices
383
+ : undefined) ?? []),
384
+ ...(board.vertices ?? []),
385
+ ]) {
386
+ addBoardUsage(boardsByVertexType, vertex.typeId, board.id);
387
+ }
388
+ }
389
+ }
390
+ const pushWarnings = (kind, boardsByType, helperName) => {
391
+ for (const [typeId, boardIds] of boardsByType.entries()) {
392
+ if (boardIds.size < 2) {
393
+ continue;
394
+ }
395
+ warnings.push(`Ambiguous ${kind}.typeId '${typeId}' is authored on multiple boards (${Array.from(boardIds).sort().join(", ")}). Prefer ${helperName} for board-scoped lookups.`);
396
+ }
397
+ };
398
+ pushWarnings("space", boardsBySpaceType, "boardHelpers.spaceIdsByBoardId / boardHelpers.spaceTypeIdByBoardId");
399
+ pushWarnings("edge", boardsByEdgeType, "boardHelpers.edgeIdsByBoardIdAndTypeId");
400
+ pushWarnings("vertex", boardsByVertexType, "boardHelpers.vertexIdsByBoardIdAndTypeId");
401
+ return warnings;
402
+ }
403
+ export function validateManifestAuthoring(manifest) {
404
+ const errors = [];
405
+ errors.push(...collectDuplicateIdIssues({
406
+ entries: manifest.cardSets.map((cardSet, index) => ({
407
+ id: cardSet.id,
408
+ path: `manifest.cardSets[${index}].id`,
409
+ })),
410
+ label: "card set id",
411
+ }));
412
+ errors.push(...collectDuplicateIdIssues({
413
+ entries: manifest.cardSets.flatMap((cardSet, cardSetIndex) => cardSet.type === "manual"
414
+ ? cardSet.cards.flatMap((card, cardIndex) => renderCardInstanceIds(card).map((cardId) => ({
415
+ id: cardId,
416
+ path: `manifest.cardSets[${cardSetIndex}].cards[${cardIndex}].type`,
417
+ })))
418
+ : []),
419
+ label: "card runtime id",
420
+ }));
421
+ errors.push(...collectDuplicateIdIssues({
422
+ entries: (manifest.zones ?? []).map((zone, index) => ({
423
+ id: zone.id,
424
+ path: `manifest.zones[${index}].id`,
425
+ })),
426
+ label: "zone id",
427
+ }));
428
+ errors.push(...collectDuplicateIdIssues({
429
+ entries: (manifest.boardTemplates ?? []).map((boardTemplate, index) => ({
430
+ id: boardTemplate.id,
431
+ path: `manifest.boardTemplates[${index}].id`,
432
+ })),
433
+ label: "board template id",
434
+ }));
435
+ errors.push(...validateBoardTemplateDuplicates(manifest.boardTemplates ?? []));
436
+ errors.push(...collectDuplicateIdIssues({
437
+ entries: (manifest.boards ?? []).map((board, index) => ({
438
+ id: board.id,
439
+ path: `manifest.boards[${index}].id`,
440
+ })),
441
+ label: "board id",
442
+ }));
443
+ errors.push(...validateBoardDuplicates(manifest.boards ?? []));
444
+ errors.push(...validateTypeSlotDuplicates({
445
+ pieceTypes: manifest.pieceTypes ?? [],
446
+ dieTypes: manifest.dieTypes ?? [],
447
+ }));
448
+ errors.push(...collectDuplicateIdIssues({
449
+ entries: (manifest.pieceTypes ?? []).map((pieceType, index) => ({
450
+ id: pieceType.id,
451
+ path: `manifest.pieceTypes[${index}].id`,
452
+ })),
453
+ label: "piece type id",
454
+ }));
455
+ errors.push(...collectDuplicateIdIssues({
456
+ entries: expandSeedIds(manifest.pieceSeeds ?? []).map((pieceId, index) => ({
457
+ id: pieceId,
458
+ path: `manifest.pieceSeeds[*][${index}]`,
459
+ })),
460
+ label: "piece runtime id",
461
+ }));
462
+ errors.push(...collectDuplicateIdIssues({
463
+ entries: (manifest.dieTypes ?? []).map((dieType, index) => ({
464
+ id: dieType.id,
465
+ path: `manifest.dieTypes[${index}].id`,
466
+ })),
467
+ label: "die type id",
468
+ }));
469
+ errors.push(...collectDuplicateIdIssues({
470
+ entries: expandSeedIds(manifest.dieSeeds ?? []).map((dieId, index) => ({
471
+ id: dieId,
472
+ path: `manifest.dieSeeds[*][${index}]`,
473
+ })),
474
+ label: "die runtime id",
475
+ }));
476
+ errors.push(...collectDuplicateIdIssues({
477
+ entries: (manifest.resources ?? []).map((resource, index) => ({
478
+ id: resource.id,
479
+ path: `manifest.resources[${index}].id`,
480
+ })),
481
+ label: "resource id",
482
+ }));
483
+ errors.push(...collectDuplicateIdIssues({
484
+ entries: (manifest.setupOptions ?? []).map((option, index) => ({
485
+ id: option.id,
486
+ path: `manifest.setupOptions[${index}].id`,
487
+ })),
488
+ label: "setup option id",
489
+ }));
490
+ errors.push(...validateSetupOptionChoiceDuplicates(manifest.setupOptions ?? []));
491
+ errors.push(...collectDuplicateIdIssues({
492
+ entries: (manifest.setupProfiles ?? []).map((profile, index) => ({
493
+ id: profile.id,
494
+ path: `manifest.setupProfiles[${index}].id`,
495
+ })),
496
+ label: "setup profile id",
497
+ }));
498
+ errors.push(...validateSlotHostsAndHomes(manifest));
499
+ errors.push(...validatePlayerScopedSeedHomes(manifest));
500
+ errors.push(...validateSetupProfileReferences(manifest));
501
+ errors.push(...validateHexBoardVertexRefs(manifest));
502
+ return {
503
+ errors,
504
+ warnings: collectAmbiguousBoardTypeWarnings(manifest),
505
+ };
506
+ }
@@ -0,0 +1,31 @@
1
+ export type OwnershipPattern = {
2
+ prefix: string;
3
+ suffix: string;
4
+ };
5
+ export type ScaffoldingOwnership = {
6
+ version: number;
7
+ allowedPaths: {
8
+ rootFiles: string[];
9
+ directoryPrefixes: string[];
10
+ };
11
+ dynamic: {
12
+ generatedFiles: string[];
13
+ seedFiles: string[];
14
+ seedFilePatterns: OwnershipPattern[];
15
+ };
16
+ cliStatic: {
17
+ exactFiles: string[];
18
+ directoryPrefixes: string[];
19
+ };
20
+ preservedUserFiles: string[];
21
+ };
22
+ export declare const WORKSPACE_CODEGEN_OWNERSHIP: ScaffoldingOwnership;
23
+ export declare const AUTHORITATIVE_GENERATED_FILES: string[];
24
+ export declare const SEED_FILES: string[];
25
+ export declare const SEED_FILE_PATTERNS: OwnershipPattern[];
26
+ export declare const PRESERVED_USER_FILES: Set<string>;
27
+ export declare function isAllowedGamePath(filePath: string): boolean;
28
+ export declare function isAuthoritativeGeneratedPath(filePath: string): boolean;
29
+ export declare function isDynamicSeedPath(filePath: string): boolean;
30
+ export declare function isCliStaticPath(filePath: string): boolean;
31
+ export declare function isLibraryPath(filePath: string): boolean;
@@ -0,0 +1,86 @@
1
+ export const WORKSPACE_CODEGEN_OWNERSHIP = {
2
+ version: 26,
3
+ allowedPaths: {
4
+ rootFiles: [
5
+ ".npmrc",
6
+ "package.json",
7
+ "pnpm-lock.yaml",
8
+ "package-lock.json",
9
+ "manifest.ts",
10
+ "manifest.tsconfig.json",
11
+ "rule.md",
12
+ ],
13
+ directoryPrefixes: ["app/", "ui/", "shared/", "test/"],
14
+ },
15
+ dynamic: {
16
+ generatedFiles: [
17
+ "shared/manifest-literals.ts",
18
+ "shared/manifest-types.ts",
19
+ "shared/manifest-runtime.ts",
20
+ "shared/manifest-contract.ts",
21
+ "shared/generated/ui-contract.ts",
22
+ "app/index.ts",
23
+ "app/tsconfig.framework.json",
24
+ "ui/tsconfig.framework.json",
25
+ ],
26
+ seedFiles: [
27
+ "app/README.md",
28
+ "ui/App.tsx",
29
+ "app/game-contract.ts",
30
+ "app/game.ts",
31
+ "app/setup-profiles.ts",
32
+ "app/reducer-support.ts",
33
+ "app/derived.ts",
34
+ ],
35
+ seedFilePatterns: [{ prefix: "app/phases/", suffix: ".ts" }],
36
+ },
37
+ cliStatic: {
38
+ exactFiles: [
39
+ ".npmrc",
40
+ "package.json",
41
+ "app/tsconfig.json",
42
+ "ui/index.tsx",
43
+ "ui/package.json",
44
+ "ui/style.css",
45
+ "ui/tsconfig.json",
46
+ ],
47
+ directoryPrefixes: [],
48
+ },
49
+ preservedUserFiles: [],
50
+ };
51
+ export const AUTHORITATIVE_GENERATED_FILES = WORKSPACE_CODEGEN_OWNERSHIP.dynamic.generatedFiles;
52
+ export const SEED_FILES = WORKSPACE_CODEGEN_OWNERSHIP.dynamic.seedFiles;
53
+ export const SEED_FILE_PATTERNS = WORKSPACE_CODEGEN_OWNERSHIP.dynamic.seedFilePatterns;
54
+ export const PRESERVED_USER_FILES = new Set(WORKSPACE_CODEGEN_OWNERSHIP.preservedUserFiles);
55
+ function normalizeProjectPath(filePath) {
56
+ return filePath.replace(/^\.\//, "").replace(/^\/+/, "").replace(/\\/g, "/");
57
+ }
58
+ export function isAllowedGamePath(filePath) {
59
+ const path = normalizeProjectPath(filePath);
60
+ if (WORKSPACE_CODEGEN_OWNERSHIP.allowedPaths.rootFiles.includes(path)) {
61
+ return true;
62
+ }
63
+ return WORKSPACE_CODEGEN_OWNERSHIP.allowedPaths.directoryPrefixes.some((prefix) => path.startsWith(prefix));
64
+ }
65
+ export function isAuthoritativeGeneratedPath(filePath) {
66
+ const path = normalizeProjectPath(filePath);
67
+ return WORKSPACE_CODEGEN_OWNERSHIP.dynamic.generatedFiles.includes(path);
68
+ }
69
+ export function isDynamicSeedPath(filePath) {
70
+ const path = normalizeProjectPath(filePath);
71
+ if (WORKSPACE_CODEGEN_OWNERSHIP.dynamic.seedFiles.includes(path)) {
72
+ return true;
73
+ }
74
+ return WORKSPACE_CODEGEN_OWNERSHIP.dynamic.seedFilePatterns.some((pattern) => path.startsWith(pattern.prefix) && path.endsWith(pattern.suffix));
75
+ }
76
+ export function isCliStaticPath(filePath) {
77
+ const path = normalizeProjectPath(filePath);
78
+ if (WORKSPACE_CODEGEN_OWNERSHIP.cliStatic.exactFiles.includes(path)) {
79
+ return true;
80
+ }
81
+ return WORKSPACE_CODEGEN_OWNERSHIP.cliStatic.directoryPrefixes.some((prefix) => path.startsWith(prefix));
82
+ }
83
+ export function isLibraryPath(filePath) {
84
+ const path = normalizeProjectPath(filePath);
85
+ return isAuthoritativeGeneratedPath(path);
86
+ }
@@ -0,0 +1,5 @@
1
+ import type { GameTopologyManifest, ManualCardSetDefinition, PresetCardSetDefinition } from "@dreamboard/sdk-types";
2
+ export declare function createStandard52CardDeck(): ManualCardSetDefinition;
3
+ export declare function addStandardDecksIfNeeded(manifest: GameTopologyManifest): GameTopologyManifest;
4
+ export declare function materializePresetCardSet(presetCardSet: PresetCardSetDefinition): ManualCardSetDefinition;
5
+ export declare function materializeCardSet(cardSet: GameTopologyManifest["cardSets"][number]): ManualCardSetDefinition;