@adeficior/data-modifier 1.0.0-rc.12 → 1.0.0-rc.14

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 (233) hide show
  1. package/dist/common/id.d.ts +1 -0
  2. package/dist/common/id.js +4 -0
  3. package/dist/common/id.js.map +1 -1
  4. package/dist/common/ingredient/filter.d.ts +6 -0
  5. package/dist/common/ingredient/filter.js +97 -0
  6. package/dist/common/ingredient/filter.js.map +1 -0
  7. package/dist/common/ingredient/index.d.ts +74 -0
  8. package/dist/common/ingredient/index.js +112 -0
  9. package/dist/common/ingredient/index.js.map +1 -0
  10. package/dist/common/ingredient/input.d.ts +3 -0
  11. package/dist/common/ingredient/input.js +1 -0
  12. package/dist/common/ingredient/input.js.map +1 -0
  13. package/dist/common/ingredient/serializer.d.ts +17 -0
  14. package/dist/common/ingredient/serializer.js +112 -0
  15. package/dist/common/ingredient/serializer.js.map +1 -0
  16. package/dist/common/predicates.d.ts +2 -1
  17. package/dist/common/predicates.js.map +1 -1
  18. package/dist/common/result/filter.d.ts +6 -0
  19. package/dist/common/result/filter.js +68 -0
  20. package/dist/common/result/filter.js.map +1 -0
  21. package/dist/common/result/index.d.ts +41 -0
  22. package/dist/common/result/index.js +59 -0
  23. package/dist/common/result/index.js.map +1 -0
  24. package/dist/common/result/input.d.ts +3 -0
  25. package/dist/common/result/input.js +1 -0
  26. package/dist/common/result/input.js.map +1 -0
  27. package/dist/common/result/serializer.d.ts +15 -0
  28. package/dist/common/result/serializer.js +81 -0
  29. package/dist/common/result/serializer.js.map +1 -0
  30. package/dist/common/serializable.d.ts +6 -0
  31. package/dist/common/serializable.js +1 -0
  32. package/dist/common/serializable.js.map +1 -0
  33. package/dist/common/units.d.ts +1 -0
  34. package/dist/common/units.js +2 -0
  35. package/dist/common/units.js.map +1 -0
  36. package/dist/emit/blacklist.d.ts +4 -6
  37. package/dist/emit/blacklist.js +19 -21
  38. package/dist/emit/blacklist.js.map +1 -1
  39. package/dist/emit/data/loot.d.ts +6 -8
  40. package/dist/emit/data/loot.js +11 -13
  41. package/dist/emit/data/loot.js.map +1 -1
  42. package/dist/emit/data/recipe.d.ts +20 -18
  43. package/dist/emit/data/recipe.js +40 -29
  44. package/dist/emit/data/recipe.js.map +1 -1
  45. package/dist/emit/data/tags.d.ts +1 -1
  46. package/dist/emit/data/tags.js.map +1 -1
  47. package/dist/emit/polytoneTabs.d.ts +1 -1
  48. package/dist/emit/polytoneTabs.js +1 -2
  49. package/dist/emit/polytoneTabs.js.map +1 -1
  50. package/dist/emit/rule/lootTable.d.ts +2 -1
  51. package/dist/emit/rule/lootTable.js +4 -2
  52. package/dist/emit/rule/lootTable.js.map +1 -1
  53. package/dist/emit/rule/recipe.d.ts +7 -5
  54. package/dist/emit/rule/recipe.js.map +1 -1
  55. package/dist/emit/ruled.d.ts +2 -1
  56. package/dist/emit/ruled.js +5 -2
  57. package/dist/emit/ruled.js.map +1 -1
  58. package/dist/index.d.ts +0 -4
  59. package/dist/index.js +0 -2
  60. package/dist/index.js.map +1 -1
  61. package/dist/loader/context.d.ts +12 -0
  62. package/dist/loader/context.js +1 -0
  63. package/dist/loader/context.js.map +1 -0
  64. package/dist/loader/pack.d.ts +13 -7
  65. package/dist/loader/pack.js +43 -25
  66. package/dist/loader/pack.js.map +1 -1
  67. package/dist/loader/recipe.d.ts +9 -5
  68. package/dist/loader/recipe.js +39 -48
  69. package/dist/loader/recipe.js.map +1 -1
  70. package/dist/loader/registry/dump.d.ts +0 -2
  71. package/dist/loader/registry/dump.js +0 -11
  72. package/dist/loader/registry/dump.js.map +1 -1
  73. package/dist/loader/registry/index.d.ts +0 -2
  74. package/dist/loader/registry/wrapped.d.ts +13 -0
  75. package/dist/loader/registry/wrapped.js +26 -0
  76. package/dist/loader/registry/wrapped.js.map +1 -0
  77. package/dist/loader/tags.d.ts +1 -1
  78. package/dist/loader/tags.js.map +1 -1
  79. package/dist/parser/adAstra.d.ts +5 -11
  80. package/dist/parser/adAstra.js +5 -5
  81. package/dist/parser/adAstra.js.map +1 -1
  82. package/dist/parser/botania.d.ts +10 -20
  83. package/dist/parser/botania.js +10 -10
  84. package/dist/parser/botania.js.map +1 -1
  85. package/dist/parser/create.d.ts +2 -4
  86. package/dist/parser/create.js +2 -2
  87. package/dist/parser/create.js.map +1 -1
  88. package/dist/parser/index.d.ts +7 -13
  89. package/dist/parser/index.js +7 -7
  90. package/dist/parser/index.js.map +1 -1
  91. package/dist/parser/lootTable.d.ts +7 -6
  92. package/dist/parser/lootTable.js +25 -23
  93. package/dist/parser/lootTable.js.map +1 -1
  94. package/dist/parser/recipe/adAstra/conversion.d.ts +15 -14
  95. package/dist/parser/recipe/adAstra/conversion.js +27 -20
  96. package/dist/parser/recipe/adAstra/conversion.js.map +1 -1
  97. package/dist/parser/recipe/adAstra/hammering.d.ts +3 -17
  98. package/dist/parser/recipe/adAstra/hammering.js +2 -25
  99. package/dist/parser/recipe/adAstra/hammering.js.map +1 -1
  100. package/dist/parser/recipe/adAstra/inputOutput.d.ts +16 -19
  101. package/dist/parser/recipe/adAstra/inputOutput.js +37 -29
  102. package/dist/parser/recipe/adAstra/inputOutput.js.map +1 -1
  103. package/dist/parser/recipe/adAstra/nasaWorkbench.d.ts +3 -19
  104. package/dist/parser/recipe/adAstra/nasaWorkbench.js +2 -28
  105. package/dist/parser/recipe/adAstra/nasaWorkbench.js.map +1 -1
  106. package/dist/parser/recipe/adAstra/spaceStation.d.ts +15 -14
  107. package/dist/parser/recipe/adAstra/spaceStation.js +33 -14
  108. package/dist/parser/recipe/adAstra/spaceStation.js.map +1 -1
  109. package/dist/parser/recipe/botania/apothecary.d.ts +17 -14
  110. package/dist/parser/recipe/botania/apothecary.js +26 -17
  111. package/dist/parser/recipe/botania/apothecary.js.map +1 -1
  112. package/dist/parser/recipe/botania/blocks.d.ts +21 -0
  113. package/dist/parser/recipe/botania/blocks.js +77 -0
  114. package/dist/parser/recipe/botania/blocks.js.map +1 -0
  115. package/dist/parser/recipe/botania/brew.d.ts +13 -12
  116. package/dist/parser/recipe/botania/brew.js +16 -11
  117. package/dist/parser/recipe/botania/brew.js.map +1 -1
  118. package/dist/parser/recipe/botania/elvenTrade.d.ts +8 -13
  119. package/dist/parser/recipe/botania/elvenTrade.js +11 -22
  120. package/dist/parser/recipe/botania/elvenTrade.js.map +1 -1
  121. package/dist/parser/recipe/botania/gogWrapper.d.ts +12 -12
  122. package/dist/parser/recipe/botania/gogWrapper.js +14 -15
  123. package/dist/parser/recipe/botania/gogWrapper.js.map +1 -1
  124. package/dist/parser/recipe/botania/manaInfusion.d.ts +18 -15
  125. package/dist/parser/recipe/botania/manaInfusion.js +29 -21
  126. package/dist/parser/recipe/botania/manaInfusion.js.map +1 -1
  127. package/dist/parser/recipe/botania/nbtWrapper.d.ts +12 -12
  128. package/dist/parser/recipe/botania/nbtWrapper.js +12 -13
  129. package/dist/parser/recipe/botania/nbtWrapper.js.map +1 -1
  130. package/dist/parser/recipe/botania/orechid.d.ts +3 -30
  131. package/dist/parser/recipe/botania/orechid.js +2 -72
  132. package/dist/parser/recipe/botania/orechid.js.map +1 -1
  133. package/dist/parser/recipe/botania/pureDaisy.d.ts +3 -18
  134. package/dist/parser/recipe/botania/pureDaisy.js +2 -28
  135. package/dist/parser/recipe/botania/pureDaisy.js.map +1 -1
  136. package/dist/parser/recipe/botania/runicAltar.d.ts +8 -13
  137. package/dist/parser/recipe/botania/runicAltar.js +11 -22
  138. package/dist/parser/recipe/botania/runicAltar.js.map +1 -1
  139. package/dist/parser/recipe/botania/terraPlate.d.ts +4 -16
  140. package/dist/parser/recipe/botania/terraPlate.js +2 -25
  141. package/dist/parser/recipe/botania/terraPlate.js.map +1 -1
  142. package/dist/parser/recipe/create/assembly.d.ts +18 -17
  143. package/dist/parser/recipe/create/assembly.js +28 -28
  144. package/dist/parser/recipe/create/assembly.js.map +1 -1
  145. package/dist/parser/recipe/create/processing.d.ts +4 -16
  146. package/dist/parser/recipe/create/processing.js +2 -25
  147. package/dist/parser/recipe/create/processing.js.map +1 -1
  148. package/dist/parser/recipe/farmersdelight/cooking.d.ts +16 -12
  149. package/dist/parser/recipe/farmersdelight/cooking.js +27 -15
  150. package/dist/parser/recipe/farmersdelight/cooking.js.map +1 -1
  151. package/dist/parser/recipe/farmersdelight/cutting.d.ts +14 -15
  152. package/dist/parser/recipe/farmersdelight/cutting.js +32 -29
  153. package/dist/parser/recipe/farmersdelight/cutting.js.map +1 -1
  154. package/dist/parser/recipe/forge/conditional.d.ts +11 -11
  155. package/dist/parser/recipe/forge/conditional.js +17 -21
  156. package/dist/parser/recipe/forge/conditional.js.map +1 -1
  157. package/dist/parser/recipe/index.d.ts +36 -13
  158. package/dist/parser/recipe/index.js +38 -5
  159. package/dist/parser/recipe/index.js.map +1 -1
  160. package/dist/parser/recipe/ingredientMap.d.ts +12 -0
  161. package/dist/parser/recipe/ingredientMap.js +17 -0
  162. package/dist/parser/recipe/ingredientMap.js.map +1 -0
  163. package/dist/parser/recipe/manyToMany.d.ts +20 -0
  164. package/dist/parser/recipe/manyToMany.js +33 -0
  165. package/dist/parser/recipe/manyToMany.js.map +1 -0
  166. package/dist/parser/recipe/manyToOne.d.ts +20 -0
  167. package/dist/parser/recipe/manyToOne.js +33 -0
  168. package/dist/parser/recipe/manyToOne.js.map +1 -0
  169. package/dist/parser/recipe/oneToOne.d.ts +20 -0
  170. package/dist/parser/recipe/oneToOne.js +33 -0
  171. package/dist/parser/recipe/oneToOne.js.map +1 -0
  172. package/dist/parser/recipe/roots/component.d.ts +13 -12
  173. package/dist/parser/recipe/roots/component.js +16 -11
  174. package/dist/parser/recipe/roots/component.js.map +1 -1
  175. package/dist/parser/recipe/roots/ritual.d.ts +14 -16
  176. package/dist/parser/recipe/roots/ritual.js +18 -25
  177. package/dist/parser/recipe/roots/ritual.js.map +1 -1
  178. package/dist/parser/recipe/sullys/polishing.d.ts +4 -16
  179. package/dist/parser/recipe/sullys/polishing.js +2 -25
  180. package/dist/parser/recipe/sullys/polishing.js.map +1 -1
  181. package/dist/parser/recipe/thermal/catalyst.d.ts +13 -12
  182. package/dist/parser/recipe/thermal/catalyst.js +16 -11
  183. package/dist/parser/recipe/thermal/catalyst.js.map +1 -1
  184. package/dist/parser/recipe/thermal/fuel.d.ts +13 -12
  185. package/dist/parser/recipe/thermal/fuel.js +17 -11
  186. package/dist/parser/recipe/thermal/fuel.js.map +1 -1
  187. package/dist/parser/recipe/thermal/index.d.ts +16 -14
  188. package/dist/parser/recipe/thermal/index.js +35 -24
  189. package/dist/parser/recipe/thermal/index.js.map +1 -1
  190. package/dist/parser/recipe/thermal/ingredient.d.ts +4 -21
  191. package/dist/parser/recipe/thermal/ingredient.js +40 -33
  192. package/dist/parser/recipe/thermal/ingredient.js.map +1 -1
  193. package/dist/parser/recipe/thermal/treeExtraction.d.ts +17 -17
  194. package/dist/parser/recipe/thermal/treeExtraction.js +30 -31
  195. package/dist/parser/recipe/thermal/treeExtraction.js.map +1 -1
  196. package/dist/parser/recipe/vanilla/shaped.d.ts +17 -13
  197. package/dist/parser/recipe/vanilla/shaped.js +21 -16
  198. package/dist/parser/recipe/vanilla/shaped.js.map +1 -1
  199. package/dist/parser/recipe/vanilla/shapeless.d.ts +3 -17
  200. package/dist/parser/recipe/vanilla/shapeless.js +2 -25
  201. package/dist/parser/recipe/vanilla/shapeless.js.map +1 -1
  202. package/dist/parser/recipe/vanilla/smelting.d.ts +16 -13
  203. package/dist/parser/recipe/vanilla/smelting.js +21 -15
  204. package/dist/parser/recipe/vanilla/smelting.js.map +1 -1
  205. package/dist/parser/recipe/vanilla/smithing.d.ts +18 -14
  206. package/dist/parser/recipe/vanilla/smithing.js +25 -16
  207. package/dist/parser/recipe/vanilla/smithing.js.map +1 -1
  208. package/dist/parser/recipe/vanilla/stonecutting.d.ts +15 -13
  209. package/dist/parser/recipe/vanilla/stonecutting.js +22 -24
  210. package/dist/parser/recipe/vanilla/stonecutting.js.map +1 -1
  211. package/dist/parser/roots.d.ts +2 -4
  212. package/dist/parser/roots.js +2 -2
  213. package/dist/parser/roots.js.map +1 -1
  214. package/dist/parser/thermal.d.ts +4 -10
  215. package/dist/parser/thermal.js +4 -5
  216. package/dist/parser/thermal.js.map +1 -1
  217. package/dist/schema/data/recipe.d.ts +2 -1
  218. package/package.json +2 -1
  219. package/dist/common/ingredient.d.ts +0 -49
  220. package/dist/common/ingredient.js +0 -108
  221. package/dist/common/ingredient.js.map +0 -1
  222. package/dist/common/result.d.ts +0 -48
  223. package/dist/common/result.js +0 -37
  224. package/dist/common/result.js.map +0 -1
  225. package/dist/parser/recipe/adAstra/index.d.ts +0 -5
  226. package/dist/parser/recipe/adAstra/index.js +0 -1
  227. package/dist/parser/recipe/adAstra/index.js.map +0 -1
  228. package/dist/parser/recipe/ignored.d.ts +0 -10
  229. package/dist/parser/recipe/ignored.js +0 -16
  230. package/dist/parser/recipe/ignored.js.map +0 -1
  231. package/dist/parser/recipe/quark/exclusion.d.ts +0 -20
  232. package/dist/parser/recipe/quark/exclusion.js +0 -32
  233. package/dist/parser/recipe/quark/exclusion.js.map +0 -1
@@ -1,29 +1,41 @@
1
1
  import { exists } from "@adeficior/pack-resolver";
2
2
  import RecipeParser, { Recipe } from "../index.js";
3
3
  export class CookingRecipe extends Recipe {
4
+ ingredients;
5
+ result;
6
+ container;
7
+ constructor(ingredients, result, container) {
8
+ super();
9
+ this.ingredients = ingredients;
10
+ this.result = result;
11
+ this.container = container;
12
+ }
4
13
  getIngredients() {
5
- return [this.definition.container, ...this.definition.ingredients].filter(exists);
14
+ return [this.container, ...this.ingredients].filter(exists);
6
15
  }
7
16
  getResults() {
8
- return [this.definition.result];
17
+ return [this.result];
9
18
  }
10
- replaceIngredient(replace) {
11
- return new CookingRecipe({
12
- ...this.definition,
13
- container: this.definition.container && replace(this.definition.container),
14
- ingredients: this.definition.ingredients.map(replace),
15
- });
19
+ replace(ingredientReplacer, resultReplacer) {
20
+ return new CookingRecipe(this.ingredients.map(ingredientReplacer), resultReplacer(this.result), this.container && ingredientReplacer(this.container));
16
21
  }
17
- replaceResult(replace) {
18
- return new CookingRecipe({
19
- ...this.definition,
20
- result: replace(this.definition.result),
21
- });
22
+ serialize(context) {
23
+ return {
24
+ ingredients: context.ingredients.serializeList(this.ingredients),
25
+ result: context.results.serialize(this.result),
26
+ container: this.container && context.ingredients.serialize(this.container),
27
+ };
22
28
  }
23
29
  }
24
30
  export default class CookingRecipeParser extends RecipeParser {
25
- create(definition) {
26
- return new CookingRecipe(definition);
31
+ deserialize(definition, context) {
32
+ const ingredients = context.ingredients.createList(definition.ingredients);
33
+ const result = context.results.create(definition.result);
34
+ // TODO optional serialize & deserialize?
35
+ const container = definition.container === undefined
36
+ ? undefined
37
+ : context.ingredients.create(definition.container);
38
+ return new CookingRecipe(ingredients, result, container);
27
39
  }
28
40
  }
29
41
  //# sourceMappingURL=cooking.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cooking.js","sourceRoot":"","sources":["../../../../src/parser/recipe/farmersdelight/cooking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAQlD,OAAO,YAAY,EAAE,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAYnD,MAAM,OAAO,aAAc,SAAQ,MAA+B;IAChE,cAAc;QACZ,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,MAAM,CACvE,MAAM,CACP,CAAC;IACJ,CAAC;IAED,UAAU;QACR,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAED,iBAAiB,CAAC,OAA6B;QAC7C,OAAO,IAAI,aAAa,CAAC;YACvB,GAAG,IAAI,CAAC,UAAU;YAClB,SAAS,EACP,IAAI,CAAC,UAAU,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;YACjE,WAAW,EAAE,IAAI,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AI,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CACrD,CAAC;IACJ,CAAC;IAEQ,SAAS,CAChB,OAA2B;QAE3B,OAAO;YACL,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC;YAChE,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;YAC9C,SAAS,EACP,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;SAClE,CAAC;IACJ,CAAC;CACF;AAED,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,YAGhD;IACC,WAAW,CACT,UAAmC,EACnC,OAA2B;QAE3B,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3E,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACzD,yCAAyC;QACzC,MAAM,SAAS,GACb,UAAU,CAAC,SAAS,KAAK,SAAS;YAChC,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QACvD,OAAO,IAAI,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAC3D,CAAC;CACF"}
@@ -1,23 +1,22 @@
1
- import type { Replacer } from "../index.js";
2
- import RecipeParser, { Recipe } from "../index.js";
3
- import type { Ingredient, IngredientInput } from "../../../common/ingredient.js";
4
- import type { RecipeDefinition } from "../../../schema/data/recipe.js";
5
- import type { Result, ResultInput } from "../../../common/result.js";
1
+ import type { Ingredient } from "../../../common/ingredient/index.js";
2
+ import type { Result } from "../../../common/result/index.js";
3
+ import RecipeParser, { type RecipeParseContext, type Replacer } from "../index.js";
4
+ import { ManyToManyRecipe, type ManyToManyRecipeDefinition } from "../manyToMany.js";
6
5
  export type ToolInput = Readonly<{
7
6
  type: "farmersdelight:tool_action";
8
7
  action: string;
9
8
  }>;
10
- export type CuttingRecipeDefinition = RecipeDefinition & Readonly<{
11
- ingredients: Ingredient[];
12
- result: Result[];
13
- tool: Ingredient | ToolInput;
9
+ export type CuttingRecipeDefinition = Omit<ManyToManyRecipeDefinition, "results"> & Readonly<{
10
+ tool: unknown;
11
+ result: ManyToManyRecipeDefinition["results"];
14
12
  }>;
15
- export declare class CuttingRecipe extends Recipe<CuttingRecipeDefinition> {
16
- getIngredients(): IngredientInput[];
17
- getResults(): ResultInput[];
18
- replaceIngredient(replace: Replacer<Ingredient>): Recipe;
19
- replaceResult(replace: Replacer<Result>): Recipe;
13
+ export declare class CuttingRecipe extends ManyToManyRecipe {
14
+ private readonly tool;
15
+ constructor(ingredients: Ingredient[], results: Result[], tool: Ingredient);
16
+ getIngredients(): Ingredient[];
17
+ replace(ingredientReplacer: Replacer<Ingredient>, resultReplacer: Replacer<Result>): CuttingRecipe;
18
+ serialize(context: RecipeParseContext): Partial<CuttingRecipeDefinition>;
20
19
  }
21
20
  export default class CuttingRecipeParser extends RecipeParser<CuttingRecipeDefinition, CuttingRecipe> {
22
- create(definition: CuttingRecipeDefinition): CuttingRecipe;
21
+ deserialize(definition: CuttingRecipeDefinition, context: RecipeParseContext): CuttingRecipe;
23
22
  }
@@ -1,38 +1,41 @@
1
- import RecipeParser, { Recipe } from "../index.js";
2
- function isToolInput(input) {
3
- return (!!input &&
4
- typeof input === "object" &&
5
- "type" in input &&
6
- input.type === "farmersdelight:tool_action");
7
- }
8
- export class CuttingRecipe extends Recipe {
9
- getIngredients() {
10
- if (isToolInput(this.definition.tool))
11
- return this.definition.ingredients;
12
- return [...this.definition.ingredients, this.definition.tool];
1
+ import RecipeParser, {} from "../index.js";
2
+ import { ManyToManyRecipe, } from "../manyToMany.js";
3
+ // TODO create actual input
4
+ // function isToolInput<T>(input: T | ToolInput): input is ToolInput {
5
+ // return (
6
+ // !!input &&
7
+ // typeof input === "object" &&
8
+ // "type" in input &&
9
+ // input.type === "farmersdelight:tool_action"
10
+ // );
11
+ // }
12
+ export class CuttingRecipe extends ManyToManyRecipe {
13
+ tool;
14
+ constructor(ingredients, results, tool) {
15
+ super(ingredients, results);
16
+ this.tool = tool;
13
17
  }
14
- getResults() {
15
- return this.definition.result;
18
+ getIngredients() {
19
+ return [...super.getIngredients(), this.tool];
16
20
  }
17
- replaceIngredient(replace) {
18
- return new CuttingRecipe({
19
- ...this.definition,
20
- ingredients: this.definition.ingredients.map(replace),
21
- tool: isToolInput(this.definition.tool)
22
- ? this.definition.tool
23
- : replace(this.definition.tool),
24
- });
21
+ replace(ingredientReplacer, resultReplacer) {
22
+ return new CuttingRecipe(this.ingredients.map(ingredientReplacer), this.results.map(resultReplacer), ingredientReplacer(this.tool));
25
23
  }
26
- replaceResult(replace) {
27
- return new CuttingRecipe({
28
- ...this.definition,
29
- result: this.definition.result.map(replace),
30
- });
24
+ serialize(context) {
25
+ const { results, ...rest } = super.serialize(context);
26
+ return {
27
+ ...rest,
28
+ result: results,
29
+ tool: context.ingredients.serialize(this.tool),
30
+ };
31
31
  }
32
32
  }
33
33
  export default class CuttingRecipeParser extends RecipeParser {
34
- create(definition) {
35
- return new CuttingRecipe(definition);
34
+ deserialize(definition, context) {
35
+ const ingredients = context.ingredients.createList(definition.ingredients);
36
+ const result = context.results.createList(definition.result);
37
+ const tool = context.ingredients.create(definition.tool);
38
+ return new CuttingRecipe(ingredients, result, tool);
36
39
  }
37
40
  }
38
41
  //# sourceMappingURL=cutting.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cutting.js","sourceRoot":"","sources":["../../../../src/parser/recipe/farmersdelight/cutting.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,EAAE,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAoBnD,SAAS,WAAW,CAAI,KAAoB;IAC1C,OAAO,CACL,CA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AC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3E,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC7D,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACzD,OAAO,IAAI,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;CACF"}
@@ -1,7 +1,7 @@
1
- import type { Ingredient, IngredientInput } from "../../../common/ingredient.js";
2
- import type { Result, ResultInput } from "../../../common/result.js";
1
+ import type { Ingredient } from "../../../common/ingredient/index.js";
2
+ import type { Result } from "../../../common/result/index.js";
3
3
  import type { RecipeDefinition } from "../../../schema/data/recipe.js";
4
- import type { InlineRecipeParser, Replacer } from "../index.js";
4
+ import type { RecipeHolder, RecipeParseContext, Replacer } from "../index.js";
5
5
  import RecipeParser, { Recipe } from "../index.js";
6
6
  type WithConditions<T> = {
7
7
  conditions: unknown[];
@@ -10,16 +10,16 @@ type WithConditions<T> = {
10
10
  export type ForgeConditionalRecipeDefinition = RecipeDefinition & Readonly<{
11
11
  recipes: WithConditions<RecipeDefinition>[];
12
12
  }>;
13
- export declare class ForgeConditionalRecipe extends Recipe<ForgeConditionalRecipeDefinition> {
13
+ export declare class ForgeConditionalRecipe extends Recipe {
14
14
  private readonly recipes;
15
- constructor(definition: Omit<ForgeConditionalRecipeDefinition, "recipes">, recipes: WithConditions<Recipe>[]);
16
- getIngredients(): IngredientInput[];
17
- getResults(): ResultInput[];
18
- replaceIngredient(replace: Replacer<Ingredient>): Recipe;
19
- replaceResult(replace: Replacer<Result>): Recipe;
20
- getTypes(): string[];
15
+ constructor(recipes: WithConditions<RecipeHolder>[]);
16
+ getIngredients(): Ingredient[];
17
+ getResults(): Result[];
18
+ replace(ingredientReplacer: Replacer<Ingredient>, resultReplacer: Replacer<Result>): ForgeConditionalRecipe;
19
+ serialize(context: RecipeParseContext): Partial<ForgeConditionalRecipeDefinition>;
20
+ additionalTypes(): `${string}:${string}`[];
21
21
  }
22
22
  export default class ForgeConditionalRecipeParser extends RecipeParser<ForgeConditionalRecipeDefinition, ForgeConditionalRecipe> {
23
- create(definition: ForgeConditionalRecipeDefinition, parser: InlineRecipeParser): ForgeConditionalRecipe;
23
+ deserialize(definition: ForgeConditionalRecipeDefinition, context: RecipeParseContext): ForgeConditionalRecipe;
24
24
  }
25
25
  export {};
@@ -1,14 +1,8 @@
1
1
  import RecipeParser, { Recipe } from "../index.js";
2
2
  export class ForgeConditionalRecipe extends Recipe {
3
3
  recipes;
4
- constructor(definition, recipes) {
5
- super({
6
- ...definition,
7
- recipes: recipes.map((it) => ({
8
- conditions: it.conditions,
9
- recipe: it.recipe.toJSON(),
10
- })),
11
- });
4
+ constructor(recipes) {
5
+ super();
12
6
  this.recipes = recipes;
13
7
  }
14
8
  getIngredients() {
@@ -17,29 +11,31 @@ export class ForgeConditionalRecipe extends Recipe {
17
11
  getResults() {
18
12
  return this.recipes.flatMap((it) => it.recipe.getResults());
19
13
  }
20
- replaceIngredient(replace) {
21
- return new ForgeConditionalRecipe(this.definition, this.recipes.map((it) => ({
14
+ replace(ingredientReplacer, resultReplacer) {
15
+ return new ForgeConditionalRecipe(this.recipes.map((it) => ({
22
16
  ...it,
23
- recipe: it.recipe.replaceIngredient(replace),
17
+ recipe: it.recipe.replace(ingredientReplacer, resultReplacer),
24
18
  })));
25
19
  }
26
- replaceResult(replace) {
27
- return new ForgeConditionalRecipe(this.definition, this.recipes.map((it) => ({
28
- ...it,
29
- recipe: it.recipe.replaceResult(replace),
30
- })));
20
+ serialize(context) {
21
+ return {
22
+ recipes: this.recipes.map((it) => ({
23
+ ...it,
24
+ recipe: context.recipes.serialize(it.recipe),
25
+ })),
26
+ };
31
27
  }
32
- getTypes() {
33
- return this.definition.recipes.map((it) => it.recipe.type);
28
+ additionalTypes() {
29
+ return this.recipes.flatMap((it) => it.recipe.getTypes());
34
30
  }
35
31
  }
36
32
  export default class ForgeConditionalRecipeParser extends RecipeParser {
37
- create(definition, parser) {
33
+ deserialize(definition, context) {
38
34
  const recipes = definition.recipes.map((it) => ({
39
35
  conditions: it.conditions,
40
- recipe: parser(it.recipe),
36
+ recipe: context.recipes.deserialize(it.recipe),
41
37
  }));
42
- return new ForgeConditionalRecipe(definition, recipes);
38
+ return new ForgeConditionalRecipe(recipes);
43
39
  }
44
40
  }
45
41
  //# sourceMappingURL=conditional.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"conditional.js","sourceRoot":"","sources":["../../../../src/parser/recipe/forge/conditional.ts"],"names":[],"mappings":"AAOA,OAAO,YAAY,EAAE,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAYnD,MAAM,OAAO,sBAAuB,SAAQ,MAAwC;IAG/D;IAFnB,YACE,UAA6D,EAC5C,OAAiC;QAElD,KAAK,CAAC;YACJ,GAAG,UAAU;YACb,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC5B,UAAU,EAAE,EAAE,CAAC,UAAU;gBACzB,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE;aAC3B,CAAC,CAAC;SACJ,CAAC,CAAC;QARc,YAAO,GAAP,OAAO,CAA0B;IASpD,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,iBAAiB,CAAC,OAA6B;QAC7C,OAAO,IAAI,sBAAsB,CAC/B,IAAI,CAAC,UAAU,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AC,GAAG,CACpC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YACP,UAAU,EAAE,EAAE,CAAC,UAAU;YACzB,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,MAAM,CAAC;SAC/C,CAAC,CACH,CAAC;QAEF,OAAO,IAAI,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;CACF"}
@@ -1,19 +1,42 @@
1
- import type { Ingredient, IngredientInput, Predicate } from "../../common/ingredient.js";
2
- import type { Result, ResultInput } from "../../common/result.js";
1
+ import { type NormalizedId } from "../../common/id.js";
2
+ import type { Ingredient } from "../../common/ingredient/index.js";
3
+ import type { Predicate } from "../../common/predicates.js";
4
+ import type { Result } from "../../common/result/index.js";
5
+ import type { PackContext } from "../../loader/context.js";
3
6
  import type { RecipeDefinition } from "../../schema/data/recipe.js";
4
7
  export type Replacer<T> = (value: T) => T;
5
8
  export declare function createReplacer<T>(from: Predicate<T>, to: T): Replacer<T>;
6
- export declare abstract class Recipe<TDefinition extends RecipeDefinition = RecipeDefinition> {
7
- protected readonly definition: TDefinition;
8
- constructor(definition: TDefinition);
9
- abstract getIngredients(): IngredientInput[];
10
- abstract replaceIngredient(replace: Replacer<Ingredient>): Recipe;
11
- abstract getResults(): ResultInput[];
12
- abstract replaceResult(replace: Replacer<Result>): Recipe;
13
- toJSON(): TDefinition;
14
- getTypes(): string[];
9
+ export declare class RecipeHolder {
10
+ private readonly definition;
11
+ private readonly recipe;
12
+ private readonly type;
13
+ constructor(definition: RecipeDefinition, recipe: Recipe);
14
+ serialize(context: RecipeParseContext): {
15
+ type: import("@adeficior/data-modifier/generated").RecipeSerializerId;
16
+ conditions?: import("../../index.js").ForgeCondition[];
17
+ "fabric:load_conditions"?: import("../../index.js").FabricCondition[];
18
+ };
19
+ getIngredients(): Ingredient[];
20
+ getResults(): Result[];
21
+ replace(ingredientReplacer: Replacer<Ingredient>, resultReplacer: Replacer<Result>): RecipeHolder;
22
+ replaceIngredient(replace: Replacer<Ingredient>): RecipeHolder;
23
+ replaceResult(replace: Replacer<Result>): RecipeHolder;
24
+ getTypes(): NormalizedId[];
15
25
  }
16
- export type InlineRecipeParser = <TDefinition extends RecipeDefinition>(definition: TDefinition) => Recipe<TDefinition>;
26
+ export declare abstract class Recipe {
27
+ abstract getIngredients(): Ingredient[];
28
+ abstract getResults(): Result[];
29
+ abstract replace(ingredientReplacer: Replacer<Ingredient>, resultReplacer: Replacer<Result>): Recipe;
30
+ additionalTypes(): NormalizedId[];
31
+ abstract serialize(context: RecipeParseContext): Partial<RecipeDefinition>;
32
+ }
33
+ export type RecipeSerializer = {
34
+ deserialize(definition: RecipeDefinition): RecipeHolder;
35
+ serialize(recipe: RecipeHolder): RecipeDefinition;
36
+ };
37
+ export type RecipeParseContext = Pick<PackContext, "ingredients" | "results"> & {
38
+ recipes: RecipeSerializer;
39
+ };
17
40
  export default abstract class RecipeParser<TDefinition extends RecipeDefinition, TRecipe extends Recipe> {
18
- abstract create(definition: TDefinition, parse: InlineRecipeParser): TRecipe;
41
+ abstract deserialize(definition: TDefinition, context: RecipeParseContext): TRecipe;
19
42
  }
@@ -1,3 +1,4 @@
1
+ import { encodeId } from "../../common/id.js";
1
2
  export function createReplacer(from, to) {
2
3
  return (it) => {
3
4
  if (from(it))
@@ -5,16 +6,48 @@ export function createReplacer(from, to) {
5
6
  return it;
6
7
  };
7
8
  }
8
- export class Recipe {
9
+ function keep() {
10
+ return (t) => t;
11
+ }
12
+ export class RecipeHolder {
9
13
  definition;
10
- constructor(definition) {
14
+ recipe;
15
+ type;
16
+ constructor(definition, recipe) {
11
17
  this.definition = definition;
18
+ this.recipe = recipe;
19
+ this.type = encodeId(definition.type);
20
+ }
21
+ serialize(context) {
22
+ return {
23
+ ...this.definition,
24
+ ...this.recipe.serialize(context),
25
+ };
26
+ }
27
+ getIngredients() {
28
+ return this.recipe.getIngredients();
29
+ }
30
+ getResults() {
31
+ return this.recipe.getResults();
12
32
  }
13
- toJSON() {
14
- return this.definition;
33
+ // TODO rename modifiy & add modifier object
34
+ replace(ingredientReplacer, resultReplacer) {
35
+ const modified = this.recipe.replace(ingredientReplacer, resultReplacer);
36
+ return new RecipeHolder(this.definition, modified);
37
+ }
38
+ replaceIngredient(replace) {
39
+ return this.replace(replace, keep());
40
+ }
41
+ replaceResult(replace) {
42
+ return this.replace(keep(), replace);
15
43
  }
16
44
  getTypes() {
17
- return [this.toJSON().type];
45
+ return [this.type, ...this.recipe.additionalTypes()];
46
+ }
47
+ }
48
+ export class Recipe {
49
+ additionalTypes() {
50
+ return [];
18
51
  }
19
52
  }
20
53
  export default class RecipeParser {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/parser/recipe/index.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,cAAc,CAAI,IAAkB,EAAE,EAAK;IACzD,OAAO,CAAC,EAAK,EAAE,EAAE;QACf,IAAI,IAAI,CAAC,EAAE,CAAC;YAAE,OAAO,EAAE,CAAC;QACxB,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,OAAgB,MAAM;IAGK;IAA/B,YAA+B,UAAuB;QAAvB,eAAU,GAAV,UAAU,CAAa;IAAG,CAAC;IAU1D,MAAM;QACJ,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,QAAQ;QACN,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;CACF;AAMD,MAAM,CAAC,OAAO,OAAgB,YAAY;CAKzC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/parser/recipe/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAqB,MAAM,oBAAoB,CAAC;AASjE,MAAM,UAAU,cAAc,CAAI,IAAkB,EAAE,EAAK;IACzD,OAAO,CAAC,EAAK,EAAE,EAAE;QACf,IAAI,IAAI,CAAC,EAAE,CAA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AAC,eAAe,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAED,MAAM,OAAgB,MAAM;IAU1B,eAAe;QACb,OAAO,EAAE,CAAC;IACZ,CAAC;CAGF;AAcD,MAAM,CAAC,OAAO,OAAgB,YAAY;CAQzC"}
@@ -0,0 +1,12 @@
1
+ import type { RecipeParseContext, Replacer } from ".";
2
+ import type { Ingredient } from "../../common/ingredient";
3
+ export type IngredientMapInput = Record<string, unknown>;
4
+ export declare class IngredientMap {
5
+ private readonly ingredients;
6
+ constructor(ingredients: Record<string, Ingredient>);
7
+ list(): Ingredient[];
8
+ replace(replace: Replacer<Ingredient>): IngredientMap;
9
+ serialize(context: RecipeParseContext): {
10
+ [x: string]: unknown;
11
+ };
12
+ }
@@ -0,0 +1,17 @@
1
+ import { mapValues } from "lodash-es";
2
+ export class IngredientMap {
3
+ ingredients;
4
+ constructor(ingredients) {
5
+ this.ingredients = ingredients;
6
+ }
7
+ list() {
8
+ return Object.values(this.ingredients);
9
+ }
10
+ replace(replace) {
11
+ return new IngredientMap(mapValues(this.ingredients, replace));
12
+ }
13
+ serialize(context) {
14
+ return mapValues(this.ingredients, (it) => context.ingredients.serialize(it));
15
+ }
16
+ }
17
+ //# sourceMappingURL=ingredientMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingredientMap.js","sourceRoot":"","sources":["../../../src/parser/recipe/ingredientMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAMtC,MAAM,OAAO,aAAa;IACK;IAA7B,YAA6B,WAAuC;QAAvC,gBAAW,GAAX,WAAW,CAA4B;IAAG,CAAC;IAExE,IAAI;QACF,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,OAA6B;QACnC,OAAO,IAAI,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,SAAS,CAAC,OAA2B;QACnC,OAAO,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,CACxC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAClC,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import type { Ingredient } from "../../common/ingredient/index.js";
2
+ import type { Result } from "../../common/result/index.js";
3
+ import type { RecipeDefinition } from "../../schema/data/recipe.js";
4
+ import RecipeParser, { Recipe, type RecipeParseContext, type Replacer } from "./index.js";
5
+ export type ManyToManyRecipeDefinition = RecipeDefinition & Readonly<{
6
+ ingredients: unknown[];
7
+ results: unknown[];
8
+ }>;
9
+ export declare class ManyToManyRecipe extends Recipe {
10
+ protected readonly ingredients: Ingredient[];
11
+ protected readonly results: Result[];
12
+ constructor(ingredients: Ingredient[], results: Result[]);
13
+ getIngredients(): Ingredient[];
14
+ getResults(): Result[];
15
+ replace(ingredientReplacer: Replacer<Ingredient>, resultReplacer: Replacer<Result>): ManyToManyRecipe;
16
+ serialize(context: RecipeParseContext): Partial<ManyToManyRecipeDefinition>;
17
+ }
18
+ export declare class ManyToManyRecipeParser<TDefinition extends ManyToManyRecipeDefinition> extends RecipeParser<TDefinition, ManyToManyRecipe> {
19
+ deserialize(definition: TDefinition, context: RecipeParseContext): ManyToManyRecipe;
20
+ }
@@ -0,0 +1,33 @@
1
+ import RecipeParser, { Recipe, } from "./index.js";
2
+ export class ManyToManyRecipe extends Recipe {
3
+ ingredients;
4
+ results;
5
+ constructor(ingredients, results) {
6
+ super();
7
+ this.ingredients = ingredients;
8
+ this.results = results;
9
+ }
10
+ getIngredients() {
11
+ return this.ingredients;
12
+ }
13
+ getResults() {
14
+ return this.results;
15
+ }
16
+ replace(ingredientReplacer, resultReplacer) {
17
+ return new ManyToManyRecipe(this.ingredients.map(ingredientReplacer), this.results.map(resultReplacer));
18
+ }
19
+ serialize(context) {
20
+ return {
21
+ results: context.results.serializeList(this.results),
22
+ ingredients: context.ingredients.serializeList(this.ingredients),
23
+ };
24
+ }
25
+ }
26
+ export class ManyToManyRecipeParser extends RecipeParser {
27
+ deserialize(definition, context) {
28
+ const ingredients = context.ingredients.createList(definition.ingredients);
29
+ const results = context.results.createList(definition.results);
30
+ return new ManyToManyRecipe(ingredients, results);
31
+ }
32
+ }
33
+ //# sourceMappingURL=manyToMany.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manyToMany.js","sourceRoot":"","sources":["../../../src/parser/recipe/manyToMany.ts"],"names":[],"mappings":"AAGA,OAAO,YAAY,EAAE,EACnB,MAAM,GAGP,MAAM,YAAY,CAAC;AAQpB,MAAM,OAAO,gBAAiB,SAAQ,MAAM;IAErB;IACA;IAFrB,YACqB,WAAyB,EACzB,OAAiB;QAEpC,KAAK,EAAE,CAAC;QAHW,gBAAW,GAAX,WAAW,CAAc;QACzB,YAAO,GAAP,OAAO,CAAU;IAGtC,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEQ,OAAO,CACd,kBAAwC,EACxC,cAAgC;QAEhC,OAAO,IAAI,gBAAgB,CACzB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,kBAAkB,CAAC,EACxC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CACjC,CAAC;IACJ,CAAC;IAEQ,SAAS,CAChB,OAA2B;QAE3B,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;YACpD,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC;SACjE,CAAC;IACJ,CAAC;CACF;AAED,MAAM,OAAO,sBAEX,SAAQ,YAA2C;IACnD,WAAW,CACT,UAAuB,EACvB,OAA2B;QAE3B,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3E,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC/D,OAAO,IAAI,gBAAgB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import type { Ingredient } from "../../common/ingredient/index.js";
2
+ import type { Result } from "../../common/result/index.js";
3
+ import type { RecipeDefinition } from "../../schema/data/recipe.js";
4
+ import RecipeParser, { Recipe, type RecipeParseContext, type Replacer } from "./index.js";
5
+ export type ManyToOneRecipeDefinition = RecipeDefinition & Readonly<{
6
+ ingredients: unknown[];
7
+ result: unknown;
8
+ }>;
9
+ export declare class ManyToOneRecipe extends Recipe {
10
+ protected readonly ingredients: Ingredient[];
11
+ protected readonly result: Result;
12
+ constructor(ingredients: Ingredient[], result: Result);
13
+ getIngredients(): Ingredient[];
14
+ getResults(): Result[];
15
+ replace(ingredientReplacer: Replacer<Ingredient>, resultReplacer: Replacer<Result>): ManyToOneRecipe;
16
+ serialize(context: RecipeParseContext): Partial<ManyToOneRecipeDefinition>;
17
+ }
18
+ export declare class ManyToOneRecipeParser<TDefinition extends ManyToOneRecipeDefinition> extends RecipeParser<TDefinition, ManyToOneRecipe> {
19
+ deserialize(definition: TDefinition, context: RecipeParseContext): ManyToOneRecipe;
20
+ }
@@ -0,0 +1,33 @@
1
+ import RecipeParser, { Recipe, } from "./index.js";
2
+ export class ManyToOneRecipe extends Recipe {
3
+ ingredients;
4
+ result;
5
+ constructor(ingredients, result) {
6
+ super();
7
+ this.ingredients = ingredients;
8
+ this.result = result;
9
+ }
10
+ getIngredients() {
11
+ return this.ingredients;
12
+ }
13
+ getResults() {
14
+ return [this.result];
15
+ }
16
+ replace(ingredientReplacer, resultReplacer) {
17
+ return new ManyToOneRecipe(this.ingredients.map(ingredientReplacer), resultReplacer(this.result));
18
+ }
19
+ serialize(context) {
20
+ return {
21
+ result: context.results.serialize(this.result),
22
+ ingredients: context.ingredients.serializeList(this.ingredients),
23
+ };
24
+ }
25
+ }
26
+ export class ManyToOneRecipeParser extends RecipeParser {
27
+ deserialize(definition, context) {
28
+ const ingredients = context.ingredients.createList(definition.ingredients);
29
+ const result = context.results.create(definition.result);
30
+ return new ManyToOneRecipe(ingredients, result);
31
+ }
32
+ }
33
+ //# sourceMappingURL=manyToOne.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manyToOne.js","sourceRoot":"","sources":["../../../src/parser/recipe/manyToOne.ts"],"names":[],"mappings":"AAGA,OAAO,YAAY,EAAE,EACnB,MAAM,GAGP,MAAM,YAAY,CAAC;AAQpB,MAAM,OAAO,eAAgB,SAAQ,MAAM;IAEpB;IACA;IAFrB,YACqB,WAAyB,EACzB,MAAc;QAEjC,KAAK,EAAE,CAAC;QAHW,gBAAW,GAAX,WAAW,CAAc;QACzB,WAAM,GAAN,MAAM,CAAQ;IAGnC,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,UAAU;QACR,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAEQ,OAAO,CACd,kBAAwC,EACxC,cAAgC;QAEhC,OAAO,IAAI,eAAe,CACxB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,kBAAkB,CAAC,EACxC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAC5B,CAAC;IACJ,CAAC;IAEQ,SAAS,CAChB,OAA2B;QAE3B,OAAO;YACL,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;YAC9C,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC;SACjE,CAAC;IACJ,CAAC;CACF;AAED,MAAM,OAAO,qBAEX,SAAQ,YAA0C;IAClD,WAAW,CACT,UAAuB,EACvB,OAA2B;QAE3B,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3E,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACzD,OAAO,IAAI,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import type { Ingredient } from "../../common/ingredient/index.js";
2
+ import type { Result } from "../../common/result/index.js";
3
+ import type { RecipeDefinition } from "../../schema/data/recipe.js";
4
+ import RecipeParser, { Recipe, type RecipeParseContext, type Replacer } from "./index.js";
5
+ export type OneToOneRecipeDefinition = RecipeDefinition & Readonly<{
6
+ ingredient: unknown;
7
+ result: unknown;
8
+ }>;
9
+ export declare class OneToOneRecipe extends Recipe {
10
+ protected readonly ingredient: Ingredient;
11
+ protected readonly result: Result;
12
+ constructor(ingredient: Ingredient, result: Result);
13
+ getIngredients(): Ingredient[];
14
+ getResults(): Result[];
15
+ replace(ingredientReplacer: Replacer<Ingredient>, resultReplacer: Replacer<Result>): OneToOneRecipe;
16
+ serialize(context: RecipeParseContext): Partial<OneToOneRecipeDefinition>;
17
+ }
18
+ export declare class OneToOneRecipeParser<TDefinition extends OneToOneRecipeDefinition> extends RecipeParser<TDefinition, OneToOneRecipe> {
19
+ deserialize(definition: TDefinition, context: RecipeParseContext): OneToOneRecipe;
20
+ }