@jay-framework/compiler-shared 0.6.10 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as prettier from 'prettier';
2
+ export * from '@jay-framework/typescript-bridge';
2
3
 
3
4
  declare enum ImportsFor {
4
5
  definition = 0,
@@ -12,6 +13,7 @@ interface ImportName {
12
13
  usage: ImportsFor[];
13
14
  }
14
15
  declare const Import: {
16
+ baseJayElement: ImportName;
15
17
  jayElement: ImportName;
16
18
  element: ImportName;
17
19
  svgElement: ImportName;
@@ -24,10 +26,14 @@ declare const Import: {
24
26
  ReferencesManager: ImportName;
25
27
  SecureReferencesManager: ImportName;
26
28
  conditional: ImportName;
29
+ withData: ImportName;
27
30
  dynamicElement: ImportName;
28
31
  svgDynamicElement: ImportName;
29
32
  mathMLDynamicElement: ImportName;
30
33
  forEach: ImportName;
34
+ resolved: ImportName;
35
+ pending: ImportName;
36
+ rejected: ImportName;
31
37
  ConstructContext: ImportName;
32
38
  HTMLElementCollectionProxy: ImportName;
33
39
  HTMLElementProxy: ImportName;
@@ -101,7 +107,9 @@ declare enum JayTypeKind {
101
107
  component = 7,
102
108
  object = 8,
103
109
  array = 9,
104
- union = 10
110
+ union = 10,
111
+ promise = 11,
112
+ recursive = 12
105
113
  }
106
114
  interface JayType {
107
115
  name: string;
@@ -185,6 +193,20 @@ declare class JayUnionType implements JayType {
185
193
  get name(): string;
186
194
  hasType(aType: JayType): any;
187
195
  }
196
+ declare class JayPromiseType implements JayType {
197
+ readonly itemType: JayType;
198
+ constructor(itemType: JayType);
199
+ readonly kind = JayTypeKind.promise;
200
+ get name(): string;
201
+ }
202
+ declare class JayRecursiveType implements JayType {
203
+ readonly referencePath: string;
204
+ resolvedType?: JayType;
205
+ constructor(referencePath: string, resolvedType?: JayType);
206
+ readonly kind = JayTypeKind.recursive;
207
+ get name(): string;
208
+ }
209
+ declare const JayErrorType: JayObjectType;
188
210
  declare function isAtomicType(aType: JayType): aType is JayAtomicType;
189
211
  declare function isTypeAliasType(aType: JayType): aType is JayTypeAlias;
190
212
  declare function isEnumType(aType: JayType): aType is JayEnumType;
@@ -196,6 +218,10 @@ declare function isComponentType(aType: JayType): aType is JayComponentType;
196
218
  declare function isObjectType(aType: JayType): aType is JayObjectType;
197
219
  declare function isArrayType(aType: JayType): aType is JayArrayType;
198
220
  declare function isUnionType(aType: JayType): aType is JayUnionType;
221
+ declare function isPromiseType(aType: JayType): aType is JayPromiseType;
222
+ declare function isRecursiveType(aType: JayType): aType is JayRecursiveType;
223
+ declare function isCurrencyType(aType: JayType): aType is JayAtomicType;
224
+ declare function isDateWithTimezoneType(aType: JayType): aType is JayAtomicType;
199
225
  declare function equalJayTypes(a: JayType, b: JayType): any;
200
226
 
201
227
  interface JayImportName {
@@ -286,12 +312,18 @@ interface Ref {
286
312
  elementType: JayType;
287
313
  }
288
314
  declare function mkRef(ref: string, originalName: string, constName: string, repeated: boolean, autoRef: boolean, viewStateType: JayType, elementType: JayType): Ref;
315
+ interface RecursiveRegion {
316
+ refName: string;
317
+ renderedContent: string;
318
+ viewStateType: string;
319
+ }
289
320
  declare class RenderFragment {
290
321
  rendered: string;
291
322
  imports: Imports;
292
323
  validations: JayValidations;
293
324
  refs: RefsTree;
294
- constructor(rendered: string, imports?: Imports, validations?: JayValidations, refs?: RefsTree);
325
+ recursiveRegions: RecursiveRegion[];
326
+ constructor(rendered: string, imports?: Imports, validations?: JayValidations, refs?: RefsTree, recursiveRegions?: RecursiveRegion[]);
295
327
  map(f: (s: string) => string): RenderFragment;
296
328
  plusImport(imp: Imports): RenderFragment;
297
329
  static empty(): RenderFragment;
@@ -317,4 +349,4 @@ declare function prettify(code: string, options?: prettier.Options): Promise<str
317
349
  declare function prettifyHtml(html: string): string;
318
350
  declare function removeComments(code: string): string;
319
351
 
320
- export { CSS_EXTENSION, type CompilerSourceFile, GenerateTarget, type GenericTypescriptSourceFile, Import, type ImportName, type ImportedRefsTree, Imports, ImportsFor, JAY_4_REACT, JAY_COMPONENT, JAY_CONTRACT_DTS_EXTENSION, JAY_CONTRACT_EXTENSION, JAY_DTS_EXTENSION, JAY_EXTENSION, JAY_FULLSTACK_COMPONENTS, JAY_QUERY_MAIN_SANDBOX, JAY_QUERY_MAIN_SANDBOX_TS, JAY_QUERY_PREFIX, JAY_QUERY_WORKER_SANDBOX, JAY_QUERY_WORKER_SANDBOX_TS, JAY_QUERY_WORKER_TRUSTED, JAY_QUERY_WORKER_TRUSTED_TS, JAY_RUNTIME, JAY_SECURE, JAY_TS_EXTENSION, JayArrayType, JayAtomicType, JayBoolean, JayComponentApiMember, JayComponentType, JayDate, JayElementConstructorType, JayElementType, JayEnumType, JayHTMLType, type JayImportLink, type JayImportName, JayImportedType, JayNumber, JayObjectType, JayString, type JayType, JayTypeAlias, JayTypeKind, JayUnionType, JayUnknown, type JayValidations, MAKE_JAY_4_REACT_COMPONENT, MAKE_JAY_COMPONENT, MAKE_JAY_TSX_COMPONENT, type MainRuntimeModes, REACT, type Ref, type RefsTree, RenderFragment, RuntimeMode, SourceFileFormat, TSX_EXTENSION, TS_EXTENSION, WithValidations, checkValidationErrors, equalJayTypes, getJayTsFileSourcePath, getMode, getModeFileExtension, getModeFromExtension, hasExtension, hasJayModeExtension, hasRefs, isArrayType, isAtomicType, isComponentType, isElementConstructorType, isElementType, isEnumType, isHTMLType, isImportedType, isObjectType, isTypeAliasType, isUnionType, mergeRefsTrees, mkRef, mkRefsTree, nestRefs, prettify, prettifyHtml, removeComments, resolvePrimitiveType, withOriginalTrace, withoutExtension };
352
+ export { CSS_EXTENSION, type CompilerSourceFile, GenerateTarget, type GenericTypescriptSourceFile, Import, type ImportName, type ImportedRefsTree, Imports, ImportsFor, JAY_4_REACT, JAY_COMPONENT, JAY_CONTRACT_DTS_EXTENSION, JAY_CONTRACT_EXTENSION, JAY_DTS_EXTENSION, JAY_EXTENSION, JAY_FULLSTACK_COMPONENTS, JAY_QUERY_MAIN_SANDBOX, JAY_QUERY_MAIN_SANDBOX_TS, JAY_QUERY_PREFIX, JAY_QUERY_WORKER_SANDBOX, JAY_QUERY_WORKER_SANDBOX_TS, JAY_QUERY_WORKER_TRUSTED, JAY_QUERY_WORKER_TRUSTED_TS, JAY_RUNTIME, JAY_SECURE, JAY_TS_EXTENSION, JayArrayType, JayAtomicType, JayBoolean, JayComponentApiMember, JayComponentType, JayDate, JayElementConstructorType, JayElementType, JayEnumType, JayErrorType, JayHTMLType, type JayImportLink, type JayImportName, JayImportedType, JayNumber, JayObjectType, JayPromiseType, JayRecursiveType, JayString, type JayType, JayTypeAlias, JayTypeKind, JayUnionType, JayUnknown, type JayValidations, MAKE_JAY_4_REACT_COMPONENT, MAKE_JAY_COMPONENT, MAKE_JAY_TSX_COMPONENT, type MainRuntimeModes, REACT, type RecursiveRegion, type Ref, type RefsTree, RenderFragment, RuntimeMode, SourceFileFormat, TSX_EXTENSION, TS_EXTENSION, WithValidations, checkValidationErrors, equalJayTypes, getJayTsFileSourcePath, getMode, getModeFileExtension, getModeFromExtension, hasExtension, hasJayModeExtension, hasRefs, isArrayType, isAtomicType, isComponentType, isCurrencyType, isDateWithTimezoneType, isElementConstructorType, isElementType, isEnumType, isHTMLType, isImportedType, isObjectType, isPromiseType, isRecursiveType, isTypeAliasType, isUnionType, mergeRefsTrees, mkRef, mkRefsTree, nestRefs, prettify, prettifyHtml, removeComments, resolvePrimitiveType, withOriginalTrace, withoutExtension };
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  import * as prettier from "prettier";
8
8
  import jsBeautify from "js-beautify";
9
+ import { createRequire } from "module";
9
10
  const JAY_EXTENSION = ".jay-html";
10
11
  const CSS_EXTENSION = ".css";
11
12
  const JAY_CONTRACT_EXTENSION = ".jay-contract";
@@ -38,6 +39,13 @@ const importsOrder = {
38
39
  JAY_4_REACT: 4
39
40
  };
40
41
  const Import = {
42
+ baseJayElement: importStatementFragment(
43
+ JAY_RUNTIME,
44
+ "BaseJayElement",
45
+ 1,
46
+ 2
47
+ /* elementSandbox */
48
+ ),
41
49
  jayElement: importStatementFragment(
42
50
  JAY_RUNTIME,
43
51
  "JayElement",
@@ -114,6 +122,12 @@ const Import = {
114
122
  1
115
123
  /* implementation */
116
124
  ),
125
+ withData: importStatementFragment(
126
+ JAY_RUNTIME,
127
+ "withData",
128
+ 1
129
+ /* implementation */
130
+ ),
117
131
  dynamicElement: importStatementFragment(
118
132
  JAY_RUNTIME,
119
133
  "dynamicElement as de",
@@ -138,6 +152,24 @@ const Import = {
138
152
  1
139
153
  /* implementation */
140
154
  ),
155
+ resolved: importStatementFragment(
156
+ JAY_RUNTIME,
157
+ "resolved",
158
+ 1
159
+ /* implementation */
160
+ ),
161
+ pending: importStatementFragment(
162
+ JAY_RUNTIME,
163
+ "pending",
164
+ 1
165
+ /* implementation */
166
+ ),
167
+ rejected: importStatementFragment(
168
+ JAY_RUNTIME,
169
+ "rejected",
170
+ 1
171
+ /* implementation */
172
+ ),
141
173
  ConstructContext: importStatementFragment(
142
174
  JAY_RUNTIME,
143
175
  "ConstructContext",
@@ -405,8 +437,8 @@ class Imports {
405
437
  }
406
438
  static merge(imports1, imports2) {
407
439
  let merged = [];
408
- for (let i = 0; i < Math.max(imports1.imports.length, imports2.imports.length); i++)
409
- merged[i] = imports1.imports[i] || imports2.imports[i];
440
+ for (let i2 = 0; i2 < Math.max(imports1.imports.length, imports2.imports.length); i2++)
441
+ merged[i2] = imports1.imports[i2] || imports2.imports[i2];
410
442
  return new Imports(merged);
411
443
  }
412
444
  }
@@ -422,6 +454,8 @@ var JayTypeKind = /* @__PURE__ */ ((JayTypeKind2) => {
422
454
  JayTypeKind2[JayTypeKind2["object"] = 8] = "object";
423
455
  JayTypeKind2[JayTypeKind2["array"] = 9] = "array";
424
456
  JayTypeKind2[JayTypeKind2["union"] = 10] = "union";
457
+ JayTypeKind2[JayTypeKind2["promise"] = 11] = "promise";
458
+ JayTypeKind2[JayTypeKind2["recursive"] = 12] = "recursive";
425
459
  return JayTypeKind2;
426
460
  })(JayTypeKind || {});
427
461
  class JayAtomicType {
@@ -524,6 +558,30 @@ class JayUnionType {
524
558
  return !!this.ofTypes.find((bType) => equalJayTypes(aType, bType));
525
559
  }
526
560
  }
561
+ class JayPromiseType {
562
+ constructor(itemType) {
563
+ __publicField(this, "kind", 11);
564
+ this.itemType = itemType;
565
+ }
566
+ get name() {
567
+ return `Promise<${this.itemType.name}>`;
568
+ }
569
+ }
570
+ class JayRecursiveType {
571
+ constructor(referencePath, resolvedType) {
572
+ __publicField(this, "kind", 12);
573
+ this.referencePath = referencePath;
574
+ this.resolvedType = resolvedType;
575
+ }
576
+ get name() {
577
+ return this.resolvedType?.name || `Recursive<${this.referencePath}>`;
578
+ }
579
+ }
580
+ const JayErrorType = new JayObjectType("Error", {
581
+ message: new JayAtomicType("string"),
582
+ name: new JayAtomicType("string"),
583
+ stack: new JayAtomicType("string")
584
+ });
527
585
  function isAtomicType(aType) {
528
586
  return aType.kind === 0;
529
587
  }
@@ -557,11 +615,23 @@ function isArrayType(aType) {
557
615
  function isUnionType(aType) {
558
616
  return aType.kind === 10;
559
617
  }
618
+ function isPromiseType(aType) {
619
+ return aType.kind === 11;
620
+ }
621
+ function isRecursiveType(aType) {
622
+ return aType.kind === 12;
623
+ }
624
+ function isCurrencyType(aType) {
625
+ return aType.kind === 0 && aType.name === "Currency";
626
+ }
627
+ function isDateWithTimezoneType(aType) {
628
+ return aType.kind === 0 && aType.name === "DateWithTimezone";
629
+ }
560
630
  function equalJayTypes(a, b) {
561
631
  if (a.name !== b.name)
562
632
  return false;
563
633
  if (a instanceof JayAtomicType && b instanceof JayAtomicType)
564
- return true;
634
+ return a.name === b.name;
565
635
  else if (a instanceof JayEnumType && b instanceof JayEnumType)
566
636
  return a.values.length === b.values.length && a.values.reduce(
567
637
  (res, a_val, currentIndex) => res && a_val === b.values[currentIndex],
@@ -590,6 +660,10 @@ function equalJayTypes(a, b) {
590
660
  return aProps.size === bProps.size && [...aProps].map((aProp) => bProps.has(aProp) && equalJayTypes(a[aProp], b[aProp]));
591
661
  } else if (a instanceof JayUnionType && b instanceof JayUnionType) {
592
662
  return a.ofTypes.length === b.ofTypes.length && a.ofTypes.reduce((res, aType) => res && b.hasType(aType), true);
663
+ } else if (a instanceof JayPromiseType && b instanceof JayPromiseType) {
664
+ return equalJayTypes(a.itemType, b.itemType);
665
+ } else if (a instanceof JayRecursiveType && b instanceof JayRecursiveType) {
666
+ return a.referencePath === b.referencePath;
593
667
  } else
594
668
  ;
595
669
  }
@@ -739,6 +813,8 @@ function hasRefs(refs, includingAutoRefs) {
739
813
  function nestRefs(path, renderFragment) {
740
814
  let refs = renderFragment.refs;
741
815
  for (let index = path.length - 1; index >= 0; --index) {
816
+ if (path[index] === ".")
817
+ continue;
742
818
  refs = mkRefsTree([], { [path[index]]: refs }, refs.repeated);
743
819
  }
744
820
  return new RenderFragment(
@@ -773,25 +849,34 @@ function mkRef(ref, originalName, constName, repeated, autoRef, viewStateType, e
773
849
  };
774
850
  }
775
851
  class RenderFragment {
776
- constructor(rendered, imports = Imports.none(), validations = [], refs = mkRefsTree([], {})) {
852
+ constructor(rendered, imports = Imports.none(), validations = [], refs = mkRefsTree([], {}), recursiveRegions = []) {
777
853
  __publicField(this, "rendered");
778
854
  __publicField(this, "imports");
779
855
  __publicField(this, "validations");
780
856
  __publicField(this, "refs");
857
+ __publicField(this, "recursiveRegions");
781
858
  this.rendered = rendered;
782
859
  this.imports = imports;
783
860
  this.validations = validations;
784
861
  this.refs = refs;
862
+ this.recursiveRegions = recursiveRegions;
785
863
  }
786
864
  map(f) {
787
- return new RenderFragment(f(this.rendered), this.imports, this.validations, this.refs);
865
+ return new RenderFragment(
866
+ f(this.rendered),
867
+ this.imports,
868
+ this.validations,
869
+ this.refs,
870
+ this.recursiveRegions
871
+ );
788
872
  }
789
873
  plusImport(imp) {
790
874
  return new RenderFragment(
791
875
  this.rendered,
792
876
  this.imports.plus(imp),
793
877
  this.validations,
794
- this.refs
878
+ this.refs,
879
+ this.recursiveRegions
795
880
  );
796
881
  }
797
882
  static empty() {
@@ -804,7 +889,8 @@ class RenderFragment {
804
889
  rendered,
805
890
  Imports.merge(fragment1.imports, fragment2.imports),
806
891
  [...fragment1.validations, ...fragment2.validations],
807
- newRefsTree
892
+ newRefsTree,
893
+ [...fragment1.recursiveRegions, ...fragment2.recursiveRegions]
808
894
  );
809
895
  }
810
896
  }
@@ -850,6 +936,14 @@ function removeComments(code) {
850
936
  (line) => !(line.includes("// @ts-expect-error ") || line.includes("// @ts-ignore") || line.includes("{/* @ts-ignore */}"))
851
937
  ).join("\n");
852
938
  }
939
+ const s = createRequire(import.meta.url), e = s("typescript"), u = e, c = new Proxy(e, {
940
+ get(t, r) {
941
+ return t[r];
942
+ }
943
+ });
944
+ function i(t) {
945
+ return e[t];
946
+ }
853
947
  export {
854
948
  CSS_EXTENSION,
855
949
  GenerateTarget,
@@ -882,10 +976,13 @@ export {
882
976
  JayElementConstructorType,
883
977
  JayElementType,
884
978
  JayEnumType,
979
+ JayErrorType,
885
980
  JayHTMLType,
886
981
  JayImportedType,
887
982
  JayNumber,
888
983
  JayObjectType,
984
+ JayPromiseType,
985
+ JayRecursiveType,
889
986
  JayString,
890
987
  JayTypeAlias,
891
988
  JayTypeKind,
@@ -907,18 +1004,23 @@ export {
907
1004
  getMode,
908
1005
  getModeFileExtension,
909
1006
  getModeFromExtension,
1007
+ i as getTs,
910
1008
  hasExtension,
911
1009
  hasJayModeExtension,
912
1010
  hasRefs,
913
1011
  isArrayType,
914
1012
  isAtomicType,
915
1013
  isComponentType,
1014
+ isCurrencyType,
1015
+ isDateWithTimezoneType,
916
1016
  isElementConstructorType,
917
1017
  isElementType,
918
1018
  isEnumType,
919
1019
  isHTMLType,
920
1020
  isImportedType,
921
1021
  isObjectType,
1022
+ isPromiseType,
1023
+ isRecursiveType,
922
1024
  isTypeAliasType,
923
1025
  isUnionType,
924
1026
  mergeRefsTrees,
@@ -929,6 +1031,8 @@ export {
929
1031
  prettifyHtml,
930
1032
  removeComments,
931
1033
  resolvePrimitiveType,
1034
+ u as ts,
1035
+ c as tsBridge,
932
1036
  withOriginalTrace,
933
1037
  withoutExtension
934
1038
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/compiler-shared",
3
- "version": "0.6.10",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "license": "Apache-2.0",
@@ -25,9 +25,10 @@
25
25
  },
26
26
  "author": "",
27
27
  "dependencies": {
28
- "@jay-framework/component": "^0.6.10",
29
- "@jay-framework/runtime": "^0.6.10",
30
- "@jay-framework/secure": "^0.6.10",
28
+ "@jay-framework/component": "^0.7.0",
29
+ "@jay-framework/runtime": "^0.7.0",
30
+ "@jay-framework/secure": "^0.7.0",
31
+ "@jay-framework/typescript-bridge": "^0.2.0",
31
32
  "@types/js-yaml": "^4.0.9",
32
33
  "change-case": "^4.1.2",
33
34
  "js-beautify": "^1.14.11",
@@ -40,7 +41,7 @@
40
41
  },
41
42
  "devDependencies": {
42
43
  "@caiogondim/strip-margin": "^1.0.0",
43
- "@jay-framework/dev-environment": "^0.6.10",
44
+ "@jay-framework/dev-environment": "^0.7.0",
44
45
  "@testing-library/jest-dom": "^6.2.0",
45
46
  "@types/js-beautify": "^1",
46
47
  "@types/node": "^20.11.5",