@elaraai/east 1.0.97 → 1.0.99

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 (154) hide show
  1. package/README.md +0 -1
  2. package/dist/src/builtins.d.ts +1 -1
  3. package/dist/src/builtins.d.ts.map +1 -1
  4. package/dist/src/builtins.js +14 -0
  5. package/dist/src/builtins.js.map +1 -1
  6. package/dist/src/codegen/spellings.d.ts.map +1 -1
  7. package/dist/src/codegen/spellings.js +2 -0
  8. package/dist/src/codegen/spellings.js.map +1 -1
  9. package/dist/src/comparison.d.ts +6 -5
  10. package/dist/src/comparison.d.ts.map +1 -1
  11. package/dist/src/comparison.js +6 -5
  12. package/dist/src/comparison.js.map +1 -1
  13. package/dist/src/compile/builtins/array.d.ts +4 -0
  14. package/dist/src/compile/builtins/array.d.ts.map +1 -1
  15. package/dist/src/compile/builtins/array.js +15 -1
  16. package/dist/src/compile/builtins/array.js.map +1 -1
  17. package/dist/src/compile/builtins/dict.d.ts +4 -0
  18. package/dist/src/compile/builtins/dict.d.ts.map +1 -1
  19. package/dist/src/compile/builtins/dict.js +14 -1
  20. package/dist/src/compile/builtins/dict.js.map +1 -1
  21. package/dist/src/compile/builtins/tree.d.ts +13 -0
  22. package/dist/src/compile/builtins/tree.d.ts.map +1 -1
  23. package/dist/src/compile/builtins/tree.js +27 -1
  24. package/dist/src/compile/builtins/tree.js.map +1 -1
  25. package/dist/src/compile/builtins/vector.d.ts +2 -2
  26. package/dist/src/compile/constructors.d.ts +6 -1
  27. package/dist/src/compile/constructors.d.ts.map +1 -1
  28. package/dist/src/compile/constructors.js +21 -11
  29. package/dist/src/compile/constructors.js.map +1 -1
  30. package/dist/src/compile/control.d.ts +7 -1
  31. package/dist/src/compile/control.d.ts.map +1 -1
  32. package/dist/src/compile/control.js +228 -146
  33. package/dist/src/compile/control.js.map +1 -1
  34. package/dist/src/compile/flow.d.ts +138 -0
  35. package/dist/src/compile/flow.d.ts.map +1 -0
  36. package/dist/src/compile/flow.js +358 -0
  37. package/dist/src/compile/flow.js.map +1 -0
  38. package/dist/src/compile/functions.d.ts +9 -1
  39. package/dist/src/compile/functions.d.ts.map +1 -1
  40. package/dist/src/compile/functions.js +62 -69
  41. package/dist/src/compile/functions.js.map +1 -1
  42. package/dist/src/compile/ir.d.ts +12 -0
  43. package/dist/src/compile/ir.d.ts.map +1 -1
  44. package/dist/src/compile/ir.js +164 -40
  45. package/dist/src/compile/ir.js.map +1 -1
  46. package/dist/src/compile/runtime.d.ts +2 -16
  47. package/dist/src/compile/runtime.d.ts.map +1 -1
  48. package/dist/src/compile/runtime.js +5 -40
  49. package/dist/src/compile/runtime.js.map +1 -1
  50. package/dist/src/compile.control_flow.spec.d.ts +6 -0
  51. package/dist/src/compile.control_flow.spec.d.ts.map +1 -0
  52. package/dist/src/compile.control_flow.spec.js +219 -0
  53. package/dist/src/compile.control_flow.spec.js.map +1 -0
  54. package/dist/src/compile.d.ts +1 -1
  55. package/dist/src/compile.d.ts.map +1 -1
  56. package/dist/src/compile.js +1 -1
  57. package/dist/src/compile.js.map +1 -1
  58. package/dist/src/eastir.d.ts.map +1 -1
  59. package/dist/src/eastir.js +8 -30
  60. package/dist/src/eastir.js.map +1 -1
  61. package/dist/src/expr/array.d.ts +39 -0
  62. package/dist/src/expr/array.d.ts.map +1 -1
  63. package/dist/src/expr/array.js +47 -0
  64. package/dist/src/expr/array.js.map +1 -1
  65. package/dist/src/expr/dict.d.ts +44 -1
  66. package/dist/src/expr/dict.d.ts.map +1 -1
  67. package/dist/src/expr/dict.js +54 -2
  68. package/dist/src/expr/dict.js.map +1 -1
  69. package/dist/src/expr/index.d.ts +130 -0
  70. package/dist/src/expr/index.d.ts.map +1 -1
  71. package/dist/src/expr/index.js +133 -0
  72. package/dist/src/expr/index.js.map +1 -1
  73. package/dist/src/expr/named.d.ts +100 -0
  74. package/dist/src/expr/named.d.ts.map +1 -0
  75. package/dist/src/expr/named.js +182 -0
  76. package/dist/src/expr/named.js.map +1 -0
  77. package/dist/src/functions.d.ts +21 -0
  78. package/dist/src/functions.d.ts.map +1 -1
  79. package/dist/src/functions.js +22 -41
  80. package/dist/src/functions.js.map +1 -1
  81. package/dist/src/internal.d.ts +1 -0
  82. package/dist/src/internal.d.ts.map +1 -1
  83. package/dist/src/internal.js +4 -0
  84. package/dist/src/internal.js.map +1 -1
  85. package/dist/src/ir_locations.d.ts +24 -0
  86. package/dist/src/ir_locations.d.ts.map +1 -0
  87. package/dist/src/ir_locations.js +58 -0
  88. package/dist/src/ir_locations.js.map +1 -0
  89. package/dist/src/location.d.ts +10 -0
  90. package/dist/src/location.d.ts.map +1 -1
  91. package/dist/src/location.js +19 -1
  92. package/dist/src/location.js.map +1 -1
  93. package/dist/src/query/jq/catalog.js +1 -1
  94. package/dist/src/query/jq/catalog.js.map +1 -1
  95. package/dist/src/query/jq/translate-builtins.d.ts.map +1 -1
  96. package/dist/src/query/jq/translate-builtins.js +11 -2
  97. package/dist/src/query/jq/translate-builtins.js.map +1 -1
  98. package/dist/src/query/jq/translate.d.ts +12 -0
  99. package/dist/src/query/jq/translate.d.ts.map +1 -1
  100. package/dist/src/query/jq/translate.js +40 -0
  101. package/dist/src/query/jq/translate.js.map +1 -1
  102. package/dist/src/runner_exec.d.ts +4 -1
  103. package/dist/src/runner_exec.d.ts.map +1 -1
  104. package/dist/src/runner_exec.js +24 -12
  105. package/dist/src/runner_exec.js.map +1 -1
  106. package/dist/src/runner_merge.d.ts +18 -0
  107. package/dist/src/runner_merge.d.ts.map +1 -1
  108. package/dist/src/runner_merge.js +36 -2
  109. package/dist/src/runner_merge.js.map +1 -1
  110. package/dist/src/serialization/beast2/decoded-function.spec.js +7 -4
  111. package/dist/src/serialization/beast2/decoded-function.spec.js.map +1 -1
  112. package/dist/src/serialization/beast2/shared.d.ts.map +1 -1
  113. package/dist/src/serialization/beast2/shared.js +6 -21
  114. package/dist/src/serialization/beast2/shared.js.map +1 -1
  115. package/dist/src/serialization/beast2/v4/container.d.ts.map +1 -1
  116. package/dist/src/serialization/beast2/v4/container.js +3 -4
  117. package/dist/src/serialization/beast2/v4/container.js.map +1 -1
  118. package/dist/src/serialization/beast2/v4/type-table.d.ts +42 -14
  119. package/dist/src/serialization/beast2/v4/type-table.d.ts.map +1 -1
  120. package/dist/src/serialization/beast2/v4/type-table.js +139 -53
  121. package/dist/src/serialization/beast2/v4/type-table.js.map +1 -1
  122. package/dist/src/serialization/beast2/v5/codec.d.ts +29 -2
  123. package/dist/src/serialization/beast2/v5/codec.d.ts.map +1 -1
  124. package/dist/src/serialization/beast2/v5/codec.js +153 -27
  125. package/dist/src/serialization/beast2/v5/codec.js.map +1 -1
  126. package/dist/src/serialization/beast2/v5/manifest.d.ts +3 -3
  127. package/dist/src/serialization/beast2/v5/manifest.js +3 -3
  128. package/dist/src/serialization/beast2/v5/runs.d.ts.map +1 -1
  129. package/dist/src/serialization/beast2/v5/runs.js +16 -4
  130. package/dist/src/serialization/beast2/v5/runs.js.map +1 -1
  131. package/dist/src/serialization/beast2/v5/source-maps.spec.d.ts +6 -0
  132. package/dist/src/serialization/beast2/v5/source-maps.spec.d.ts.map +1 -0
  133. package/dist/src/serialization/beast2/v5/source-maps.spec.js +81 -0
  134. package/dist/src/serialization/beast2/v5/source-maps.spec.js.map +1 -0
  135. package/dist/src/serialization/beast2/v5/type-section.js +1 -1
  136. package/dist/src/serialization/beast2/v5/type-section.js.map +1 -1
  137. package/dist/src/type_of_type.d.ts +12 -33
  138. package/dist/src/type_of_type.d.ts.map +1 -1
  139. package/dist/src/type_of_type.js +46 -174
  140. package/dist/src/type_of_type.js.map +1 -1
  141. package/dist/src/type_of_type.recursive_id.spec.d.ts +6 -0
  142. package/dist/src/type_of_type.recursive_id.spec.d.ts.map +1 -0
  143. package/dist/src/type_of_type.recursive_id.spec.js +86 -0
  144. package/dist/src/type_of_type.recursive_id.spec.js.map +1 -0
  145. package/dist/src/type_of_type.to_etv.spec.js +9 -9
  146. package/dist/src/type_of_type.to_etv.spec.js.map +1 -1
  147. package/dist/src/type_value_equal.d.ts +31 -0
  148. package/dist/src/type_value_equal.d.ts.map +1 -0
  149. package/dist/src/type_value_equal.js +170 -0
  150. package/dist/src/type_value_equal.js.map +1 -0
  151. package/dist/src/types.d.ts.map +1 -1
  152. package/dist/src/types.js +3 -1
  153. package/dist/src/types.js.map +1 -1
  154. package/package.json +1 -1
@@ -28,6 +28,8 @@ import { from, equal, notEqual, less, lessEqual, print, is, greaterEqual, greate
28
28
  import { toSource } from '../codegen/index.js';
29
29
  import { importFunction, exportFunctions, encodeFunctionManifest, decodeFunctionManifest, linkImports, platformDependencies } from '../functions.js';
30
30
  import { jq } from './query.js';
31
+ import { field, fields, inCase, patchesFor, struct, withField } from './named.js';
32
+ export { type Patches } from './named.js';
31
33
  export { BlockBuilder, type AsyncPlatformDefinition, type PlatformDefinition, type GenericPlatformDefinition, type AsyncGenericPlatformDefinition, type PlatformDeclaration, PLATFORM_DECLARATION, isPlatformDeclaration, equals, eq, notEquals, ne, lessThan, lt, lessThanOrEqual, lte, le, greaterThan, gt, greaterThanOrEqual, gte, ge, diff, applyPatch, composePatch, invertPatch } from './block.js';
32
34
  export type { ToExpr as ExprFactory } from './expr.js';
33
35
  /**
@@ -662,6 +664,134 @@ export declare const East: {
662
664
  * ```
663
665
  */
664
666
  invertPatch: typeof invertPatch;
667
+ /**
668
+ * Reads a struct's field by a name held as a value — what `value.name`
669
+ * reads where the name is written — for code building East programs over
670
+ * types it is handed. A recursive value is read through to its node.
671
+ *
672
+ * @param value - A struct, or a recursive value whose node is one
673
+ * @param name - The field
674
+ * @param type - The field's type, where the caller holds it: checked, and the expression typed by it
675
+ * @returns The field's expression
676
+ * @throws {Error} When the value is not a struct, has no field of the name, or the field is not of the type given —
677
+ * as the program is built
678
+ *
679
+ * @example
680
+ * ```ts
681
+ * const Row = StructType({ name: StringType, site: StringType });
682
+ * const readOf = (name: string) => East.function([Row], StringType, ($, row) => East.field(row, name, StringType));
683
+ * const compiled = East.compile(readOf("site"), []);
684
+ * compiled({ name: "Press 1", site: "North" }); // "North"
685
+ * ```
686
+ */
687
+ field: typeof field;
688
+ /**
689
+ * A struct's fields by names held as values: each field's expression, in
690
+ * the order given, or in the struct's own — to spread into a call, or into
691
+ * {@link East.struct}. The value is read once a field: give a variable.
692
+ *
693
+ * @param value - A struct, or a recursive value whose node is one
694
+ * @param names - The fields, in the order wanted; every field, in the struct's order, where none are given
695
+ * @returns The fields' expressions
696
+ * @throws {Error} When the value is not a struct, or has no field of a name given — as the program is built
697
+ *
698
+ * @example
699
+ * ```ts
700
+ * const Row = StructType({ name: StringType, site: StringType, status: StringType });
701
+ * const Place = StructType({ site: StringType, name: StringType });
702
+ * const placeOf = East.function([Row], Place, ($, row) => East.struct(Place, East.fields(row, ["site", "name"])));
703
+ * const compiled = East.compile(placeOf, []);
704
+ * compiled({ name: "Press 1", site: "North", status: "up" }); // { site: "North", name: "Press 1" }
705
+ * ```
706
+ */
707
+ fields: typeof fields;
708
+ /**
709
+ * Builds a struct of a type held as a value from its fields, by name or in
710
+ * the type's order — what a struct literal builds where its names are
711
+ * written. A recursive type's node is built, and wrapped in it.
712
+ *
713
+ * @param type - A struct type, or a recursive type whose node is one
714
+ * @param values - Each field's value or expression: by name, every field once; or in the type's order, one a field
715
+ * @returns The struct's expression
716
+ * @throws {Error} When the type is not a struct, a name is not one of its fields, a field has no value, or a value
717
+ * is not of its field's type — as the program is built
718
+ *
719
+ * @example
720
+ * ```ts
721
+ * const Pair = StructType({ low: IntegerType, high: IntegerType });
722
+ * const ordered = East.function([IntegerType, IntegerType], Pair, ($, a, b) =>
723
+ * East.struct(Pair, [East.min(a, b), East.max(a, b)]));
724
+ * const compiled = East.compile(ordered, []);
725
+ * compiled(7n, 3n); // { low: 3n, high: 7n }
726
+ * ```
727
+ */
728
+ struct: typeof struct;
729
+ /**
730
+ * A struct with one field replaced, by a name held as a value: the same
731
+ * type, every other field as it is. A recursive value's node is rebuilt,
732
+ * and wrapped again. The value is read once a field: give a variable.
733
+ *
734
+ * @param value - A struct, or a recursive value whose node is one
735
+ * @param name - The field replaced
736
+ * @param replacement - Its new value or expression
737
+ * @returns The struct with the field replaced
738
+ * @throws {Error} When the value is not a struct, has no field of the name, or the replacement is not of its type —
739
+ * as the program is built
740
+ *
741
+ * @example
742
+ * ```ts
743
+ * const Row = StructType({ name: StringType, status: StringType });
744
+ * const stopped = East.function([Row], Row, ($, row) => East.withField(row, "status", "down"));
745
+ * const compiled = East.compile(stopped, []);
746
+ * compiled({ name: "Press 1", status: "up" }); // { name: "Press 1", status: "down" }
747
+ * ```
748
+ */
749
+ withField: typeof withField;
750
+ /**
751
+ * A variant of a type held as a value, holding a value in a case by a name
752
+ * held as a value — what `variant(name, value)` builds where the case is
753
+ * written. A recursive type's node is built, and wrapped in it.
754
+ *
755
+ * @param type - A variant type, or a recursive type whose node is one
756
+ * @param name - The case
757
+ * @param value - Its value or expression
758
+ * @returns The variant's expression
759
+ * @throws {Error} When the type is not a variant, has no case of the name, or the value is not of the case's type —
760
+ * as the program is built
761
+ *
762
+ * @example
763
+ * ```ts
764
+ * const Reading = VariantType({ load: FloatType, output: FloatType });
765
+ * const readingOf = (place: string) => East.function([FloatType], Reading, ($, x) => East.inCase(Reading, place, x));
766
+ * const compiled = East.compile(readingOf("output"), []);
767
+ * compiled(0.82); // variant("output", 0.82)
768
+ * ```
769
+ */
770
+ inCase: typeof inCase;
771
+ /**
772
+ * The patch functions of a type held as a value: diff, apply, compose and
773
+ * invert, each an East function of the type, bound and called as any other
774
+ * — what {@link East.diff}, {@link East.applyPatch},
775
+ * {@link East.composePatch} and {@link East.invertPatch} build where the
776
+ * type is written.
777
+ *
778
+ * @param type - The type patched
779
+ * @returns Its patch type, and its patch functions
780
+ *
781
+ * @example
782
+ * ```ts
783
+ * const Row = StructType({ name: StringType, status: StringType });
784
+ * const { diff, apply } = East.patchesFor(Row);
785
+ * const roundTrip = East.function([Row, Row], Row, ($, before, after) => {
786
+ * const diffFn = $.const(diff);
787
+ * const applyFn = $.const(apply);
788
+ * return applyFn(before, diffFn(before, after));
789
+ * });
790
+ * const compiled = East.compile(roundTrip, []);
791
+ * compiled({ name: "Press 1", status: "up" }, { name: "Press 1", status: "down" }); // { name: "Press 1", status: "down" }
792
+ * ```
793
+ */
794
+ patchesFor: typeof patchesFor;
665
795
  /**
666
796
  * A jq query over East values, as East code: parsed, checked against the
667
797
  * inputs' types and translated to ordinary East IR when the program is
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/expr/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;A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;;;;;;;;IAGH;;;OAGG;;;;;;;;IAGH;;;;;;;;OAQG;;;;IAGH;;;;;;;;;;;;;;OAcG;;;;CAEJ,CAAC"}
@@ -31,6 +31,8 @@ import { from, equal, notEqual, less, lessEqual, print, is, greaterEqual, greate
31
31
  import { toSource } from '../codegen/index.js';
32
32
  import { importFunction, exportFunctions, encodeFunctionManifest, decodeFunctionManifest, linkImports, platformDependencies } from '../functions.js';
33
33
  import { jq } from './query.js';
34
+ import { field, fields, inCase, patchesFor, struct, withField } from './named.js';
35
+ export {} from './named.js';
34
36
  export { BlockBuilder, PLATFORM_DECLARATION, isPlatformDeclaration, equals, eq, notEquals, ne, lessThan, lt, lessThanOrEqual, lte, le, greaterThan, gt, greaterThanOrEqual, gte, ge, diff, applyPatch, composePatch, invertPatch } from './block.js';
35
37
  // Import standard libraries
36
38
  import IntegerLib from './libs/integer.js';
@@ -704,6 +706,137 @@ export const East = {
704
706
  */
705
707
  invertPatch,
706
708
  // ============================================================================
709
+ // Names and types held as values
710
+ // ============================================================================
711
+ /**
712
+ * Reads a struct's field by a name held as a value — what `value.name`
713
+ * reads where the name is written — for code building East programs over
714
+ * types it is handed. A recursive value is read through to its node.
715
+ *
716
+ * @param value - A struct, or a recursive value whose node is one
717
+ * @param name - The field
718
+ * @param type - The field's type, where the caller holds it: checked, and the expression typed by it
719
+ * @returns The field's expression
720
+ * @throws {Error} When the value is not a struct, has no field of the name, or the field is not of the type given —
721
+ * as the program is built
722
+ *
723
+ * @example
724
+ * ```ts
725
+ * const Row = StructType({ name: StringType, site: StringType });
726
+ * const readOf = (name: string) => East.function([Row], StringType, ($, row) => East.field(row, name, StringType));
727
+ * const compiled = East.compile(readOf("site"), []);
728
+ * compiled({ name: "Press 1", site: "North" }); // "North"
729
+ * ```
730
+ */
731
+ field,
732
+ /**
733
+ * A struct's fields by names held as values: each field's expression, in
734
+ * the order given, or in the struct's own — to spread into a call, or into
735
+ * {@link East.struct}. The value is read once a field: give a variable.
736
+ *
737
+ * @param value - A struct, or a recursive value whose node is one
738
+ * @param names - The fields, in the order wanted; every field, in the struct's order, where none are given
739
+ * @returns The fields' expressions
740
+ * @throws {Error} When the value is not a struct, or has no field of a name given — as the program is built
741
+ *
742
+ * @example
743
+ * ```ts
744
+ * const Row = StructType({ name: StringType, site: StringType, status: StringType });
745
+ * const Place = StructType({ site: StringType, name: StringType });
746
+ * const placeOf = East.function([Row], Place, ($, row) => East.struct(Place, East.fields(row, ["site", "name"])));
747
+ * const compiled = East.compile(placeOf, []);
748
+ * compiled({ name: "Press 1", site: "North", status: "up" }); // { site: "North", name: "Press 1" }
749
+ * ```
750
+ */
751
+ fields,
752
+ /**
753
+ * Builds a struct of a type held as a value from its fields, by name or in
754
+ * the type's order — what a struct literal builds where its names are
755
+ * written. A recursive type's node is built, and wrapped in it.
756
+ *
757
+ * @param type - A struct type, or a recursive type whose node is one
758
+ * @param values - Each field's value or expression: by name, every field once; or in the type's order, one a field
759
+ * @returns The struct's expression
760
+ * @throws {Error} When the type is not a struct, a name is not one of its fields, a field has no value, or a value
761
+ * is not of its field's type — as the program is built
762
+ *
763
+ * @example
764
+ * ```ts
765
+ * const Pair = StructType({ low: IntegerType, high: IntegerType });
766
+ * const ordered = East.function([IntegerType, IntegerType], Pair, ($, a, b) =>
767
+ * East.struct(Pair, [East.min(a, b), East.max(a, b)]));
768
+ * const compiled = East.compile(ordered, []);
769
+ * compiled(7n, 3n); // { low: 3n, high: 7n }
770
+ * ```
771
+ */
772
+ struct,
773
+ /**
774
+ * A struct with one field replaced, by a name held as a value: the same
775
+ * type, every other field as it is. A recursive value's node is rebuilt,
776
+ * and wrapped again. The value is read once a field: give a variable.
777
+ *
778
+ * @param value - A struct, or a recursive value whose node is one
779
+ * @param name - The field replaced
780
+ * @param replacement - Its new value or expression
781
+ * @returns The struct with the field replaced
782
+ * @throws {Error} When the value is not a struct, has no field of the name, or the replacement is not of its type —
783
+ * as the program is built
784
+ *
785
+ * @example
786
+ * ```ts
787
+ * const Row = StructType({ name: StringType, status: StringType });
788
+ * const stopped = East.function([Row], Row, ($, row) => East.withField(row, "status", "down"));
789
+ * const compiled = East.compile(stopped, []);
790
+ * compiled({ name: "Press 1", status: "up" }); // { name: "Press 1", status: "down" }
791
+ * ```
792
+ */
793
+ withField,
794
+ /**
795
+ * A variant of a type held as a value, holding a value in a case by a name
796
+ * held as a value — what `variant(name, value)` builds where the case is
797
+ * written. A recursive type's node is built, and wrapped in it.
798
+ *
799
+ * @param type - A variant type, or a recursive type whose node is one
800
+ * @param name - The case
801
+ * @param value - Its value or expression
802
+ * @returns The variant's expression
803
+ * @throws {Error} When the type is not a variant, has no case of the name, or the value is not of the case's type —
804
+ * as the program is built
805
+ *
806
+ * @example
807
+ * ```ts
808
+ * const Reading = VariantType({ load: FloatType, output: FloatType });
809
+ * const readingOf = (place: string) => East.function([FloatType], Reading, ($, x) => East.inCase(Reading, place, x));
810
+ * const compiled = East.compile(readingOf("output"), []);
811
+ * compiled(0.82); // variant("output", 0.82)
812
+ * ```
813
+ */
814
+ inCase,
815
+ /**
816
+ * The patch functions of a type held as a value: diff, apply, compose and
817
+ * invert, each an East function of the type, bound and called as any other
818
+ * — what {@link East.diff}, {@link East.applyPatch},
819
+ * {@link East.composePatch} and {@link East.invertPatch} build where the
820
+ * type is written.
821
+ *
822
+ * @param type - The type patched
823
+ * @returns Its patch type, and its patch functions
824
+ *
825
+ * @example
826
+ * ```ts
827
+ * const Row = StructType({ name: StringType, status: StringType });
828
+ * const { diff, apply } = East.patchesFor(Row);
829
+ * const roundTrip = East.function([Row, Row], Row, ($, before, after) => {
830
+ * const diffFn = $.const(diff);
831
+ * const applyFn = $.const(apply);
832
+ * return applyFn(before, diffFn(before, after));
833
+ * });
834
+ * const compiled = East.compile(roundTrip, []);
835
+ * compiled({ name: "Press 1", status: "up" }, { name: "Press 1", status: "down" }); // { name: "Press 1", status: "down" }
836
+ * ```
837
+ */
838
+ patchesFor,
839
+ // ============================================================================
707
840
  // Queries
708
841
  // ============================================================================
709
842
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/expr/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sBAAsB;AACtB,cAAc,YAAY,CAAC;AAE3B,+CAA+C;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAA6B,YAAY,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAkC,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvF,gCAAgC;AAChC,OAAO,EAAE,IAA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AU;IACV,+EAA+E;IAE/E;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,EAAE;IAEF,cAAc;IAEd;;;;;;;;;;;;OAYG;IACH,GAAG,EAAE,IAAI,CAAC,GAAG;IAEb;;;;;;;;;;;;OAYG;IACH,GAAG,EAAE,IAAI,CAAC,GAAG;IAEb;;;;;;;;;;;;;;OAcG;IACH,KAAK,EAAE,IAAI,CAAC,KAAK;IAEjB,eAAe;IAEf;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,UAAU;IAEnB;;;;;;;;;;;OAWG;IACH,KAAK,EAAE,QAAQ;IAEf;;;;;;;;;;;OAWG;IACH,QAAQ,EAAE,WAAW;IAErB;;;;;;;;OAQG;IACH,MAAM,EAAE,SAAS;IAEjB;;;;;;;;OAQG;IACH,IAAI,EAAE,OAAO;IAEb;;;;;;;;;;OAUG;IACH,KAAK,EAAE,QAAQ;IAEf;;;OAGG;IACH,MAAM,EAAE,SAAS;IAEjB;;;OAGG;IACH,MAAM,EAAE,SAAS;IAEjB;;;;;;;;OAQG;IACH,GAAG,EAAE,MAAM;IAEX;;;;;;;;;;;;;;OAcG;IACH,IAAI,EAAE,OAAO;CACd,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ import { type EastType } from "../types.js";
6
+ import { Expr } from "./expr.js";
7
+ import type { ExprType } from "./types.js";
8
+ import type { FunctionExpr } from "./function.js";
9
+ /**
10
+ * Reads a struct's field by a name held as a value — what `value.name` reads
11
+ * where the name is written. A recursive value is read through to its node.
12
+ *
13
+ * @typeParam T - The field's type, where the caller holds it
14
+ * @param value - A struct, or a recursive value whose node is one
15
+ * @param name - The field
16
+ * @param type - The field's type, where the caller holds it: checked, and the expression typed by it
17
+ * @returns The field's expression
18
+ * @throws {Error} When the value is not a struct, has no field of the name, or the field is not of the type given
19
+ */
20
+ export declare function field<T extends EastType = EastType>(value: Expr, name: string, type?: T): ExprType<T>;
21
+ /**
22
+ * A struct's fields, by names held as values: each field's expression, in the
23
+ * order given, or in the struct's own order — to spread into a call, or into
24
+ * {@link struct}.
25
+ *
26
+ * @param value - A struct, or a recursive value whose node is one: give a variable, for it is read once a field
27
+ * @param names - The fields, in the order wanted; every field, in the struct's order, where none are given
28
+ * @returns The fields' expressions
29
+ * @throws {Error} When the value is not a struct, or has no field of a name given
30
+ */
31
+ export declare function fields(value: Expr, names?: readonly string[]): ExprType<EastType>[];
32
+ /**
33
+ * Builds a struct of a type held as a value from its fields, given by name or
34
+ * in the type's order — what a struct literal builds where its names are
35
+ * written. A recursive type's node is built, and wrapped in it.
36
+ *
37
+ * @typeParam T - The struct's type
38
+ * @param type - A struct type, or a recursive type whose node is one
39
+ * @param values - Each field's value or expression: by name, every field once; or in the type's order, one a field
40
+ * @returns The struct's expression
41
+ * @throws {Error} When the type is not a struct, a name is not one of its fields, a field has no value, or a value is
42
+ * not of its field's type
43
+ */
44
+ export declare function struct<T extends EastType>(type: T, values: Readonly<Record<string, unknown>> | readonly unknown[]): ExprType<T>;
45
+ /**
46
+ * A struct with one field replaced, by a name held as value: the same type,
47
+ * every other field as it is. A recursive value's node is rebuilt, and wrapped
48
+ * again.
49
+ *
50
+ * @typeParam V - The struct's expression, whose type the result keeps
51
+ * @param value - A struct, or a recursive value whose node is one: give a variable, for it is read once a field
52
+ * @param name - The field replaced
53
+ * @param replacement - Its new value or expression
54
+ * @returns The struct with the field replaced: an expression of the value's own type
55
+ * @throws {Error} When the value is not a struct, has no field of the name, or the replacement is not of its type
56
+ */
57
+ export declare function withField<V extends Expr>(value: V, name: string, replacement: unknown): V;
58
+ /**
59
+ * A variant of a type held as a value, holding a value in a case by a name
60
+ * held as a value — what `variant(name, value)` builds where the case is
61
+ * written. A recursive type's node is built, and wrapped in it.
62
+ *
63
+ * @typeParam T - The variant's type
64
+ * @param type - A variant type, or a recursive type whose node is one
65
+ * @param name - The case
66
+ * @param value - Its value or expression
67
+ * @returns The variant's expression
68
+ * @throws {Error} When the type is not a variant, has no case of the name, or the value is not of the case's type
69
+ */
70
+ export declare function inCase<T extends EastType>(type: T, name: string, value: unknown): ExprType<T>;
71
+ /**
72
+ * The patch functions of a type held as a value ({@link patchesFor}): each an
73
+ * East function of the type, bound and called as any other.
74
+ *
75
+ * @typeParam T - The type patched
76
+ */
77
+ export interface Patches<T extends EastType = EastType> {
78
+ /** The type's patches, `PatchType(T)`. */
79
+ readonly patchType: EastType;
80
+ /** `(before, after) → the patch between them` */
81
+ readonly diff: FunctionExpr<[T, T], EastType>;
82
+ /** `(value, patch) → the value patched`: an East runtime error when the patch was made against another value */
83
+ readonly apply: FunctionExpr<[T, EastType], T>;
84
+ /** `(first, second) → one patch doing both`: an East runtime error when the second does not follow the first */
85
+ readonly compose: FunctionExpr<[EastType, EastType], EastType>;
86
+ /** `(patch) → the patch undoing it` */
87
+ readonly invert: FunctionExpr<[EastType], EastType>;
88
+ }
89
+ /**
90
+ * The patch functions of a type held as a value: diff, apply, compose and
91
+ * invert, each an East function of the type — what `East.diff`,
92
+ * `East.applyPatch`, `East.composePatch` and `East.invertPatch` build where
93
+ * the type is written, and the program side of `diffFor`.
94
+ *
95
+ * @typeParam T - The type patched
96
+ * @param type - The type
97
+ * @returns Its patch type and its patch functions
98
+ */
99
+ export declare function patchesFor<T extends EastType>(type: T): Patches<T>;
100
+ //# sourceMappingURL=named.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"named.d.ts","sourceRoot":"","sources":["../../../src/expr/named.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAsBH,OAAO,EAAE,KAAK,QAAQ,EAAgC,MAAM,aAAa,CAAC;AAK1E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAsB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AAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/C,gHAAgH;IAChH,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC/D,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;CACrD;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAgBlE"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ /**
6
+ * East built from names and types held as values.
7
+ *
8
+ * East names a struct's fields, and a variant's cases, where its code is
9
+ * written: `row.jobs`, `variant("some", x)`. Code that builds East programs
10
+ * over types it is handed — a library generating a program for whatever record
11
+ * its caller declares — holds those names, and the types, as values. These
12
+ * build the same program pieces from them: a field read, a struct, a variant,
13
+ * and the patch functions of a type. Each checks its names against the type as
14
+ * the program is built, so a name the type does not have fails there, naming
15
+ * the name and the type. In TypeScript each gives an expression of the type it
16
+ * is handed, or of `EastType` where the type is known only as a value.
17
+ *
18
+ * A value read more than once — by {@link fields} or {@link withField} — is
19
+ * read from the expression given each time: give a variable (a parameter, or a
20
+ * `$.let`), not a computation.
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ import { get_location_id } from "../location.js";
25
+ import { isTypeEqual } from "../types.js";
26
+ import { printTypeValueSummary } from "../type_diff.js";
27
+ import { PatchType } from "../patch/index.js";
28
+ import { toEastTypeValue } from "../type_of_type.js";
29
+ import { variant } from "../containers/variant.js";
30
+ import { Expr } from "./expr.js";
31
+ import { builtin, from, fromAst, func, wrapRecursive } from "./block.js";
32
+ /** A type in a refusal's words: its kind, and a struct's fields or a variant's cases by name. */
33
+ function words(type) {
34
+ return printTypeValueSummary(toEastTypeValue(type), 1, 64);
35
+ }
36
+ /** A value read through a recursive wrapper: its node; any other value as it is. */
37
+ function opened(value) {
38
+ const type = Expr.type(value);
39
+ if (type.type !== "Recursive")
40
+ return value;
41
+ return fromAst({ ast_type: "UnwrapRecursive", type: type.node, loc_id: get_location_id(), value: Expr.ast(value) });
42
+ }
43
+ /** A struct type, or a recursive type's struct node; refused, naming what was asked of it, for any other type. */
44
+ function structOf(asked, type) {
45
+ const node = type.type === "Recursive" ? type.node : type;
46
+ if (node.type !== "Struct")
47
+ throw new Error(`${asked}: ${words(type)} is not a struct`);
48
+ return node;
49
+ }
50
+ /**
51
+ * Reads a struct's field by a name held as a value — what `value.name` reads
52
+ * where the name is written. A recursive value is read through to its node.
53
+ *
54
+ * @typeParam T - The field's type, where the caller holds it
55
+ * @param value - A struct, or a recursive value whose node is one
56
+ * @param name - The field
57
+ * @param type - The field's type, where the caller holds it: checked, and the expression typed by it
58
+ * @returns The field's expression
59
+ * @throws {Error} When the value is not a struct, has no field of the name, or the field is not of the type given
60
+ */
61
+ export function field(value, name, type) {
62
+ const struct = opened(value);
63
+ const node = structOf(`East.field '${name}'`, Expr.type(value));
64
+ const held = node.fields[name];
65
+ if (held === undefined)
66
+ throw new Error(`East.field: ${words(node)} has no field '${name}'`);
67
+ if (type !== undefined && !isTypeEqual(held, type)) {
68
+ throw new Error(`East.field: '${name}' of ${words(node)} is ${words(held)}, not ${words(type)}`);
69
+ }
70
+ return fromAst({ ast_type: "GetField", type: held, loc_id: get_location_id(), field: name, struct: Expr.ast(struct) });
71
+ }
72
+ /**
73
+ * A struct's fields, by names held as values: each field's expression, in the
74
+ * order given, or in the struct's own order — to spread into a call, or into
75
+ * {@link struct}.
76
+ *
77
+ * @param value - A struct, or a recursive value whose node is one: give a variable, for it is read once a field
78
+ * @param names - The fields, in the order wanted; every field, in the struct's order, where none are given
79
+ * @returns The fields' expressions
80
+ * @throws {Error} When the value is not a struct, or has no field of a name given
81
+ */
82
+ export function fields(value, names) {
83
+ const node = structOf("East.fields", Expr.type(value));
84
+ return (names ?? Object.keys(node.fields)).map((name) => field(value, name));
85
+ }
86
+ /**
87
+ * Builds a struct of a type held as a value from its fields, given by name or
88
+ * in the type's order — what a struct literal builds where its names are
89
+ * written. A recursive type's node is built, and wrapped in it.
90
+ *
91
+ * @typeParam T - The struct's type
92
+ * @param type - A struct type, or a recursive type whose node is one
93
+ * @param values - Each field's value or expression: by name, every field once; or in the type's order, one a field
94
+ * @returns The struct's expression
95
+ * @throws {Error} When the type is not a struct, a name is not one of its fields, a field has no value, or a value is
96
+ * not of its field's type
97
+ */
98
+ export function struct(type, values) {
99
+ const node = structOf("East.struct", type);
100
+ const names = Object.keys(node.fields);
101
+ let byName;
102
+ if (Array.isArray(values)) {
103
+ if (values.length !== names.length)
104
+ throw new Error(`East.struct: ${words(node)} has ${names.length} fields, given ${values.length}`);
105
+ byName = Object.fromEntries(names.map((name, at) => [name, values[at]]));
106
+ }
107
+ else {
108
+ byName = values;
109
+ const stranger = Object.keys(byName).find((name) => !names.includes(name));
110
+ if (stranger !== undefined)
111
+ throw new Error(`East.struct: ${words(node)} has no field '${stranger}'`);
112
+ const missing = names.find((name) => !(name in byName));
113
+ if (missing !== undefined)
114
+ throw new Error(`East.struct: no value for the field '${missing}' of ${words(node)}`);
115
+ }
116
+ const built = from(byName, node);
117
+ return (type.type === "Recursive" ? wrapRecursive(built, type) : built);
118
+ }
119
+ /**
120
+ * A struct with one field replaced, by a name held as value: the same type,
121
+ * every other field as it is. A recursive value's node is rebuilt, and wrapped
122
+ * again.
123
+ *
124
+ * @typeParam V - The struct's expression, whose type the result keeps
125
+ * @param value - A struct, or a recursive value whose node is one: give a variable, for it is read once a field
126
+ * @param name - The field replaced
127
+ * @param replacement - Its new value or expression
128
+ * @returns The struct with the field replaced: an expression of the value's own type
129
+ * @throws {Error} When the value is not a struct, has no field of the name, or the replacement is not of its type
130
+ */
131
+ export function withField(value, name, replacement) {
132
+ const type = Expr.type(value);
133
+ const node = structOf("East.withField", type);
134
+ if (!(name in node.fields))
135
+ throw new Error(`East.withField: ${words(node)} has no field '${name}'`);
136
+ return struct(type, Object.fromEntries(Object.keys(node.fields).map((held) => [held, held === name ? replacement : field(value, held)])));
137
+ }
138
+ /**
139
+ * A variant of a type held as a value, holding a value in a case by a name
140
+ * held as a value — what `variant(name, value)` builds where the case is
141
+ * written. A recursive type's node is built, and wrapped in it.
142
+ *
143
+ * @typeParam T - The variant's type
144
+ * @param type - A variant type, or a recursive type whose node is one
145
+ * @param name - The case
146
+ * @param value - Its value or expression
147
+ * @returns The variant's expression
148
+ * @throws {Error} When the type is not a variant, has no case of the name, or the value is not of the case's type
149
+ */
150
+ export function inCase(type, name, value) {
151
+ const node = type.type === "Recursive" ? type.node : type;
152
+ if (node.type !== "Variant")
153
+ throw new Error(`East.inCase: ${words(type)} is not a variant`);
154
+ if (!(name in node.cases))
155
+ throw new Error(`East.inCase: ${words(node)} has no case '${name}'`);
156
+ const built = from(variant(name, value), node);
157
+ return (type.type === "Recursive" ? wrapRecursive(built, type) : built);
158
+ }
159
+ /**
160
+ * The patch functions of a type held as a value: diff, apply, compose and
161
+ * invert, each an East function of the type — what `East.diff`,
162
+ * `East.applyPatch`, `East.composePatch` and `East.invertPatch` build where
163
+ * the type is written, and the program side of `diffFor`.
164
+ *
165
+ * @typeParam T - The type patched
166
+ * @param type - The type
167
+ * @returns Its patch type and its patch functions
168
+ */
169
+ export function patchesFor(type) {
170
+ // From the type's runtime form: a type known only as a value has a patch TypeScript cannot compute.
171
+ const patchType = PatchType(toEastTypeValue(type));
172
+ // Built over the type as an East type: the functions' own signatures are the ones declared.
173
+ const valueType = type;
174
+ return {
175
+ patchType,
176
+ diff: func([valueType, valueType], patchType, (_$, before, after) => builtin("Diff", [valueType, patchType], [before, after], patchType)),
177
+ apply: func([valueType, patchType], valueType, (_$, value, patch) => builtin("ApplyPatch", [valueType, patchType], [value, patch], valueType)),
178
+ compose: func([patchType, patchType], patchType, (_$, first, second) => builtin("ComposePatch", [valueType, patchType], [first, second], patchType)),
179
+ invert: func([patchType], patchType, (_$, patch) => builtin("InvertPatch", [valueType, patchType], [patch], patchType)),
180
+ };
181
+ }
182
+ //# sourceMappingURL=named.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"named.js","sourceRoot":"","sources":["../../../src/expr/named.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAkC,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEzE,iGAAiG;AACjG,SAAS,KAAK,CAAC,IAAc;IAC3B,OAAO,qBAAqB,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,oFAAoF;AACpF,SAAS,MAAM,CAAC,KAAW;IACzB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,OAAO,CAAC,EAAE,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI,CAAC,IAAgB,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,KAAK,EAA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