@jay-framework/compiler-shared 0.6.10 → 0.8.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;
@@ -137,7 +145,8 @@ declare class JayHTMLType implements JayType {
137
145
  declare class JayImportedType implements JayType {
138
146
  readonly name: string;
139
147
  readonly type: JayType;
140
- constructor(name: string, type: JayType);
148
+ readonly isOptional: boolean;
149
+ constructor(name: string, type: JayType, isOptional?: boolean);
141
150
  readonly kind = JayTypeKind.imported;
142
151
  }
143
152
  declare class JayElementType implements JayType {
@@ -185,6 +194,20 @@ declare class JayUnionType implements JayType {
185
194
  get name(): string;
186
195
  hasType(aType: JayType): any;
187
196
  }
197
+ declare class JayPromiseType implements JayType {
198
+ readonly itemType: JayType;
199
+ constructor(itemType: JayType);
200
+ readonly kind = JayTypeKind.promise;
201
+ get name(): string;
202
+ }
203
+ declare class JayRecursiveType implements JayType {
204
+ readonly referencePath: string;
205
+ resolvedType?: JayType;
206
+ constructor(referencePath: string, resolvedType?: JayType);
207
+ readonly kind = JayTypeKind.recursive;
208
+ get name(): string;
209
+ }
210
+ declare const JayErrorType: JayObjectType;
188
211
  declare function isAtomicType(aType: JayType): aType is JayAtomicType;
189
212
  declare function isTypeAliasType(aType: JayType): aType is JayTypeAlias;
190
213
  declare function isEnumType(aType: JayType): aType is JayEnumType;
@@ -196,6 +219,10 @@ declare function isComponentType(aType: JayType): aType is JayComponentType;
196
219
  declare function isObjectType(aType: JayType): aType is JayObjectType;
197
220
  declare function isArrayType(aType: JayType): aType is JayArrayType;
198
221
  declare function isUnionType(aType: JayType): aType is JayUnionType;
222
+ declare function isPromiseType(aType: JayType): aType is JayPromiseType;
223
+ declare function isRecursiveType(aType: JayType): aType is JayRecursiveType;
224
+ declare function isCurrencyType(aType: JayType): aType is JayAtomicType;
225
+ declare function isDateWithTimezoneType(aType: JayType): aType is JayAtomicType;
199
226
  declare function equalJayTypes(a: JayType, b: JayType): any;
200
227
 
201
228
  interface JayImportName {
@@ -286,12 +313,18 @@ interface Ref {
286
313
  elementType: JayType;
287
314
  }
288
315
  declare function mkRef(ref: string, originalName: string, constName: string, repeated: boolean, autoRef: boolean, viewStateType: JayType, elementType: JayType): Ref;
316
+ interface RecursiveRegion {
317
+ refName: string;
318
+ renderedContent: string;
319
+ viewStateType: string;
320
+ }
289
321
  declare class RenderFragment {
290
322
  rendered: string;
291
323
  imports: Imports;
292
324
  validations: JayValidations;
293
325
  refs: RefsTree;
294
- constructor(rendered: string, imports?: Imports, validations?: JayValidations, refs?: RefsTree);
326
+ recursiveRegions: RecursiveRegion[];
327
+ constructor(rendered: string, imports?: Imports, validations?: JayValidations, refs?: RefsTree, recursiveRegions?: RecursiveRegion[]);
295
328
  map(f: (s: string) => string): RenderFragment;
296
329
  plusImport(imp: Imports): RenderFragment;
297
330
  static empty(): RenderFragment;
@@ -317,4 +350,4 @@ declare function prettify(code: string, options?: prettier.Options): Promise<str
317
350
  declare function prettifyHtml(html: string): string;
318
351
  declare function removeComments(code: string): string;
319
352
 
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 };
353
+ 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 {
@@ -464,10 +498,11 @@ class JayHTMLType {
464
498
  }
465
499
  }
466
500
  class JayImportedType {
467
- constructor(name, type) {
501
+ constructor(name, type, isOptional = false) {
468
502
  __publicField(this, "kind", 4);
469
503
  this.name = name;
470
504
  this.type = type;
505
+ this.isOptional = isOptional;
471
506
  }
472
507
  }
473
508
  class JayElementType {
@@ -524,6 +559,30 @@ class JayUnionType {
524
559
  return !!this.ofTypes.find((bType) => equalJayTypes(aType, bType));
525
560
  }
526
561
  }
562
+ class JayPromiseType {
563
+ constructor(itemType) {
564
+ __publicField(this, "kind", 11);
565
+ this.itemType = itemType;
566
+ }
567
+ get name() {
568
+ return `Promise<${this.itemType.name}>`;
569
+ }
570
+ }
571
+ class JayRecursiveType {
572
+ constructor(referencePath, resolvedType) {
573
+ __publicField(this, "kind", 12);
574
+ this.referencePath = referencePath;
575
+ this.resolvedType = resolvedType;
576
+ }
577
+ get name() {
578
+ return this.resolvedType?.name || `Recursive<${this.referencePath}>`;
579
+ }
580
+ }
581
+ const JayErrorType = new JayObjectType("Error", {
582
+ message: new JayAtomicType("string"),
583
+ name: new JayAtomicType("string"),
584
+ stack: new JayAtomicType("string")
585
+ });
527
586
  function isAtomicType(aType) {
528
587
  return aType.kind === 0;
529
588
  }
@@ -557,11 +616,23 @@ function isArrayType(aType) {
557
616
  function isUnionType(aType) {
558
617
  return aType.kind === 10;
559
618
  }
619
+ function isPromiseType(aType) {
620
+ return aType.kind === 11;
621
+ }
622
+ function isRecursiveType(aType) {
623
+ return aType.kind === 12;
624
+ }
625
+ function isCurrencyType(aType) {
626
+ return aType.kind === 0 && aType.name === "Currency";
627
+ }
628
+ function isDateWithTimezoneType(aType) {
629
+ return aType.kind === 0 && aType.name === "DateWithTimezone";
630
+ }
560
631
  function equalJayTypes(a, b) {
561
632
  if (a.name !== b.name)
562
633
  return false;
563
634
  if (a instanceof JayAtomicType && b instanceof JayAtomicType)
564
- return true;
635
+ return a.name === b.name;
565
636
  else if (a instanceof JayEnumType && b instanceof JayEnumType)
566
637
  return a.values.length === b.values.length && a.values.reduce(
567
638
  (res, a_val, currentIndex) => res && a_val === b.values[currentIndex],
@@ -590,6 +661,10 @@ function equalJayTypes(a, b) {
590
661
  return aProps.size === bProps.size && [...aProps].map((aProp) => bProps.has(aProp) && equalJayTypes(a[aProp], b[aProp]));
591
662
  } else if (a instanceof JayUnionType && b instanceof JayUnionType) {
592
663
  return a.ofTypes.length === b.ofTypes.length && a.ofTypes.reduce((res, aType) => res && b.hasType(aType), true);
664
+ } else if (a instanceof JayPromiseType && b instanceof JayPromiseType) {
665
+ return equalJayTypes(a.itemType, b.itemType);
666
+ } else if (a instanceof JayRecursiveType && b instanceof JayRecursiveType) {
667
+ return a.referencePath === b.referencePath;
593
668
  } else
594
669
  ;
595
670
  }
@@ -739,13 +814,16 @@ function hasRefs(refs, includingAutoRefs) {
739
814
  function nestRefs(path, renderFragment) {
740
815
  let refs = renderFragment.refs;
741
816
  for (let index = path.length - 1; index >= 0; --index) {
817
+ if (path[index] === ".")
818
+ continue;
742
819
  refs = mkRefsTree([], { [path[index]]: refs }, refs.repeated);
743
820
  }
744
821
  return new RenderFragment(
745
822
  renderFragment.rendered,
746
823
  renderFragment.imports,
747
824
  renderFragment.validations,
748
- refs
825
+ refs,
826
+ renderFragment.recursiveRegions
749
827
  );
750
828
  }
751
829
  function mkRefsTree(refs, children, repeated = false, refsTypeName, repeatedRefsTypeName) {
@@ -773,25 +851,34 @@ function mkRef(ref, originalName, constName, repeated, autoRef, viewStateType, e
773
851
  };
774
852
  }
775
853
  class RenderFragment {
776
- constructor(rendered, imports = Imports.none(), validations = [], refs = mkRefsTree([], {})) {
854
+ constructor(rendered, imports = Imports.none(), validations = [], refs = mkRefsTree([], {}), recursiveRegions = []) {
777
855
  __publicField(this, "rendered");
778
856
  __publicField(this, "imports");
779
857
  __publicField(this, "validations");
780
858
  __publicField(this, "refs");
859
+ __publicField(this, "recursiveRegions");
781
860
  this.rendered = rendered;
782
861
  this.imports = imports;
783
862
  this.validations = validations;
784
863
  this.refs = refs;
864
+ this.recursiveRegions = recursiveRegions;
785
865
  }
786
866
  map(f) {
787
- return new RenderFragment(f(this.rendered), this.imports, this.validations, this.refs);
867
+ return new RenderFragment(
868
+ f(this.rendered),
869
+ this.imports,
870
+ this.validations,
871
+ this.refs,
872
+ this.recursiveRegions
873
+ );
788
874
  }
789
875
  plusImport(imp) {
790
876
  return new RenderFragment(
791
877
  this.rendered,
792
878
  this.imports.plus(imp),
793
879
  this.validations,
794
- this.refs
880
+ this.refs,
881
+ this.recursiveRegions
795
882
  );
796
883
  }
797
884
  static empty() {
@@ -804,7 +891,8 @@ class RenderFragment {
804
891
  rendered,
805
892
  Imports.merge(fragment1.imports, fragment2.imports),
806
893
  [...fragment1.validations, ...fragment2.validations],
807
- newRefsTree
894
+ newRefsTree,
895
+ [...fragment1.recursiveRegions, ...fragment2.recursiveRegions]
808
896
  );
809
897
  }
810
898
  }
@@ -850,6 +938,14 @@ function removeComments(code) {
850
938
  (line) => !(line.includes("// @ts-expect-error ") || line.includes("// @ts-ignore") || line.includes("{/* @ts-ignore */}"))
851
939
  ).join("\n");
852
940
  }
941
+ const s = createRequire(import.meta.url), e = s("typescript"), u = e, c = new Proxy(e, {
942
+ get(t, r) {
943
+ return t[r];
944
+ }
945
+ });
946
+ function i(t) {
947
+ return e[t];
948
+ }
853
949
  export {
854
950
  CSS_EXTENSION,
855
951
  GenerateTarget,
@@ -882,10 +978,13 @@ export {
882
978
  JayElementConstructorType,
883
979
  JayElementType,
884
980
  JayEnumType,
981
+ JayErrorType,
885
982
  JayHTMLType,
886
983
  JayImportedType,
887
984
  JayNumber,
888
985
  JayObjectType,
986
+ JayPromiseType,
987
+ JayRecursiveType,
889
988
  JayString,
890
989
  JayTypeAlias,
891
990
  JayTypeKind,
@@ -907,18 +1006,23 @@ export {
907
1006
  getMode,
908
1007
  getModeFileExtension,
909
1008
  getModeFromExtension,
1009
+ i as getTs,
910
1010
  hasExtension,
911
1011
  hasJayModeExtension,
912
1012
  hasRefs,
913
1013
  isArrayType,
914
1014
  isAtomicType,
915
1015
  isComponentType,
1016
+ isCurrencyType,
1017
+ isDateWithTimezoneType,
916
1018
  isElementConstructorType,
917
1019
  isElementType,
918
1020
  isEnumType,
919
1021
  isHTMLType,
920
1022
  isImportedType,
921
1023
  isObjectType,
1024
+ isPromiseType,
1025
+ isRecursiveType,
922
1026
  isTypeAliasType,
923
1027
  isUnionType,
924
1028
  mergeRefsTrees,
@@ -929,6 +1033,8 @@ export {
929
1033
  prettifyHtml,
930
1034
  removeComments,
931
1035
  resolvePrimitiveType,
1036
+ u as ts,
1037
+ c as tsBridge,
932
1038
  withOriginalTrace,
933
1039
  withoutExtension
934
1040
  };
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.8.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.8.0",
29
+ "@jay-framework/runtime": "^0.8.0",
30
+ "@jay-framework/secure": "^0.8.0",
31
+ "@jay-framework/typescript-bridge": "^0.3.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.8.0",
44
45
  "@testing-library/jest-dom": "^6.2.0",
45
46
  "@types/js-beautify": "^1",
46
47
  "@types/node": "^20.11.5",