@garrix82/reactgenie-dsl 1.0.0 → 1.0.2

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 (105) hide show
  1. package/.env +10 -0
  2. package/.env.example +17 -0
  3. package/.github/workflows/publish.yml +20 -0
  4. package/README.md +5 -1
  5. package/package.json +1 -5
  6. package/dist/__test__/dsl-descriptor.test.d.ts +0 -1
  7. package/dist/__test__/dsl-descriptor.test.js +0 -27
  8. package/dist/__test__/dsl-descriptor.test.js.map +0 -1
  9. package/dist/__test__/example_descriptor.d.ts +0 -125
  10. package/dist/__test__/example_descriptor.js +0 -607
  11. package/dist/__test__/example_descriptor.js.map +0 -1
  12. package/dist/__test__/food_descriptor.state.json +0 -1
  13. package/dist/__test__/food_descriptor.test.d.ts +0 -74
  14. package/dist/__test__/food_descriptor.test.js +0 -205
  15. package/dist/__test__/food_descriptor.test.js.map +0 -1
  16. package/dist/__test__/nl-interpreter-provider-selection.test.d.ts +0 -1
  17. package/dist/__test__/nl-interpreter-provider-selection.test.js +0 -73
  18. package/dist/__test__/nl-interpreter-provider-selection.test.js.map +0 -1
  19. package/dist/__test__/nl-interpreter.test.d.ts +0 -1
  20. package/dist/__test__/nl-interpreter.test.js +0 -86
  21. package/dist/__test__/nl-interpreter.test.js.map +0 -1
  22. package/dist/decorators/__test__/decorators.test.d.ts +0 -1
  23. package/dist/decorators/__test__/decorators.test.js +0 -182
  24. package/dist/decorators/__test__/decorators.test.js.map +0 -1
  25. package/dist/decorators/__test__/inheritance-descriptor.test.d.ts +0 -1
  26. package/dist/decorators/__test__/inheritance-descriptor.test.js +0 -107
  27. package/dist/decorators/__test__/inheritance-descriptor.test.js.map +0 -1
  28. package/dist/dsl/__test__/dsl-interpreter.test.d.ts +0 -1
  29. package/dist/dsl/__test__/dsl-interpreter.test.js +0 -334
  30. package/dist/dsl/__test__/dsl-interpreter.test.js.map +0 -1
  31. package/dist/dsl/__test__/parser.gen.test.d.ts +0 -1
  32. package/dist/dsl/__test__/parser.gen.test.js +0 -283
  33. package/dist/dsl/__test__/parser.gen.test.js.map +0 -1
  34. package/dist/nl/__test__/context-aware-prompt.test.d.ts +0 -1
  35. package/dist/nl/__test__/context-aware-prompt.test.js +0 -247
  36. package/dist/nl/__test__/context-aware-prompt.test.js.map +0 -1
  37. package/dist/nl/__test__/context-selector.test.d.ts +0 -1
  38. package/dist/nl/__test__/context-selector.test.js +0 -20
  39. package/dist/nl/__test__/context-selector.test.js.map +0 -1
  40. package/dist/nl/__test__/nl-parser-groq-transport.test.d.ts +0 -1
  41. package/dist/nl/__test__/nl-parser-groq-transport.test.js +0 -87
  42. package/dist/nl/__test__/nl-parser-groq-transport.test.js.map +0 -1
  43. package/dist/nl/__test__/nl-parser-openai-parity.test.d.ts +0 -1
  44. package/dist/nl/__test__/nl-parser-openai-parity.test.js +0 -206
  45. package/dist/nl/__test__/nl-parser-openai-parity.test.js.map +0 -1
  46. package/dist/nl/__test__/nl-parser-openai-sampling.test.d.ts +0 -1
  47. package/dist/nl/__test__/nl-parser-openai-sampling.test.js +0 -44
  48. package/dist/nl/__test__/nl-parser-openai-sampling.test.js.map +0 -1
  49. package/dist/nl/__test__/nl-parser-openai-transport.test.d.ts +0 -1
  50. package/dist/nl/__test__/nl-parser-openai-transport.test.js +0 -55
  51. package/dist/nl/__test__/nl-parser-openai-transport.test.js.map +0 -1
  52. package/dist/nl/__test__/nl-parser-utils.test.d.ts +0 -1
  53. package/dist/nl/__test__/nl-parser-utils.test.js +0 -70
  54. package/dist/nl/__test__/nl-parser-utils.test.js.map +0 -1
  55. package/dist/nl/__test__/nl-parser.test.d.ts +0 -1
  56. package/dist/nl/__test__/nl-parser.test.js +0 -64
  57. package/dist/nl/__test__/nl-parser.test.js.map +0 -1
  58. package/dist/nl/__test__/parameter-tuning.test.d.ts +0 -1
  59. package/dist/nl/__test__/parameter-tuning.test.js +0 -95
  60. package/dist/nl/__test__/parameter-tuning.test.js.map +0 -1
  61. package/dist/nl/__test__/semantic-parsing-experiment.test.d.ts +0 -1
  62. package/dist/nl/__test__/semantic-parsing-experiment.test.js +0 -178
  63. package/dist/nl/__test__/semantic-parsing-experiment.test.js.map +0 -1
  64. package/dist/nl/llm-monitoring.test.d.ts +0 -5
  65. package/dist/nl/llm-monitoring.test.js +0 -101
  66. package/dist/nl/llm-monitoring.test.js.map +0 -1
  67. package/lib/__test__/dsl-descriptor.test.ts +0 -27
  68. package/lib/__test__/example_descriptor.ts +0 -762
  69. package/lib/__test__/food_descriptor.state.json +0 -1
  70. package/lib/__test__/food_descriptor.test.ts +0 -331
  71. package/lib/__test__/nl-interpreter-provider-selection.test.ts +0 -126
  72. package/lib/__test__/nl-interpreter.test.ts +0 -129
  73. package/lib/decorators/__test__/decorators.test.ts +0 -177
  74. package/lib/decorators/__test__/inheritance-descriptor.test.ts +0 -92
  75. package/lib/decorators/decorators.ts +0 -754
  76. package/lib/decorators/index.ts +0 -2
  77. package/lib/decorators/store.ts +0 -47
  78. package/lib/dsl/__test__/dsl-interpreter.test.ts +0 -453
  79. package/lib/dsl/__test__/parser.gen.test.ts +0 -296
  80. package/lib/dsl/dsl-interpreter.ts +0 -974
  81. package/lib/dsl/index.ts +0 -1
  82. package/lib/dsl/parser.gen.js +0 -1479
  83. package/lib/dsl/parser.pegjs +0 -130
  84. package/lib/dsl-descriptor.ts +0 -241
  85. package/lib/index.ts +0 -5
  86. package/lib/nl/__test__/context-aware-prompt.test.ts +0 -372
  87. package/lib/nl/__test__/context-selector.test.ts +0 -27
  88. package/lib/nl/__test__/nl-parser-groq-transport.test.ts +0 -139
  89. package/lib/nl/__test__/nl-parser-openai-parity.test.ts +0 -381
  90. package/lib/nl/__test__/nl-parser-openai-sampling.test.ts +0 -73
  91. package/lib/nl/__test__/nl-parser-openai-transport.test.ts +0 -79
  92. package/lib/nl/__test__/nl-parser-utils.test.ts +0 -98
  93. package/lib/nl/__test__/nl-parser.test.ts +0 -119
  94. package/lib/nl/__test__/parameter-tuning.test.ts +0 -137
  95. package/lib/nl/__test__/semantic-parsing-experiment.test.ts +0 -260
  96. package/lib/nl/context-selector.ts +0 -123
  97. package/lib/nl/index.ts +0 -19
  98. package/lib/nl/llm-monitoring.test.ts +0 -136
  99. package/lib/nl/llm-monitoring.ts +0 -339
  100. package/lib/nl/nl-parser-groq.ts +0 -510
  101. package/lib/nl/nl-parser-utils.ts +0 -310
  102. package/lib/nl/nl-parser.ts +0 -616
  103. package/lib/nl/prompt-gen.ts +0 -607
  104. package/lib/nl/prompt-res.ts +0 -207
  105. package/lib/nl-interpreter.ts +0 -262
@@ -1,177 +0,0 @@
1
- import "../decorators";
2
- import * as assert from "assert";
3
- import {
4
- ClassDescriptor,
5
- FieldDescriptor,
6
- FuncDescriptor,
7
- DataClass, HelperClass, GenieObject
8
- } from "../../dsl-descriptor";
9
- import {GenieClass, GenieKey, GenieProperty, initGenie} from "../decorators";
10
- import {
11
- DateTime,
12
- Food,
13
- Order,
14
- Restaurant,
15
- } from "../../__test__/example_descriptor";
16
- import {genieDispatch} from "../store";
17
-
18
- initGenie();
19
-
20
- function essentialFuncDescriptor(original: FuncDescriptor) {
21
- return {
22
- name: original.func_name,
23
- // comment: original.comment, // don't compare comments
24
- params: original.parameters,
25
- returnType: original.returnType,
26
- isStatic: original.isStatic,
27
- };
28
- }
29
-
30
- function essentialFieldDescriptor(original: FieldDescriptor) {
31
- return {
32
- name: original.field,
33
- // comment: original.comment, // don't compare comments
34
- type: original.fieldType,
35
- isStatic: original.isStatic,
36
- };
37
- }
38
-
39
- function sortDescriptor(a: { name: string }, b: { name: string }) {
40
- return a.name.localeCompare(b.name);
41
- }
42
-
43
- function compareClassDescriptor(
44
- a: ClassDescriptor<GenieObject>,
45
- b: ClassDescriptor<GenieObject>
46
- ) {
47
- assert.equal(a.className, b.className);
48
- assert.equal(a.classConstructor, b.classConstructor);
49
- assert.equal(a.functions.size, b.functions.size);
50
- assert.equal(a.fields.size, b.fields.size);
51
- expect(
52
- Array.from(a.functions).map(essentialFuncDescriptor).sort(sortDescriptor)
53
- ).toEqual(
54
- Array.from(b.functions).map(essentialFuncDescriptor).sort(sortDescriptor)
55
- );
56
- expect(
57
- Array.from(a.fields).map(essentialFieldDescriptor).sort(sortDescriptor)
58
- ).toEqual(
59
- Array.from(b.fields).map(essentialFieldDescriptor).sort(sortDescriptor)
60
- );
61
- }
62
- test("Restaurant Descriptor", async () => {
63
- compareClassDescriptor(
64
- Restaurant.ClassDescriptor,
65
- Restaurant._ClassDescriptor
66
- );
67
- Restaurant.all();
68
- const restaurant1 = Restaurant.GetObject({ name: "McDonald's" });
69
- const restaurant2 = Restaurant.GetObject({ name: "McDonald's" });
70
- restaurant2.rating = 5;
71
- assert.equal(restaurant1.rating, 5);
72
- restaurant2.rating = 3;
73
- assert.equal(restaurant1.rating, 3);
74
- });
75
-
76
- test("Food Descriptor", async () => {
77
- console.log("Food descriptor", Food.ClassDescriptor);
78
- console.log("Food descriptor", Food._ClassDescriptor);
79
- compareClassDescriptor(Food.ClassDescriptor, Food._ClassDescriptor);
80
- Restaurant.all();
81
- Food.all();
82
- const foodItem1 = Food.GetObject({ name: "Hamburger" });
83
- const foodItem2 = Food.GetObject({ name: "Hamburger" });
84
- foodItem2.price = 6.99;
85
- assert.equal(foodItem1.price, 6.99);
86
- foodItem2.price = 5.99;
87
- assert.equal(foodItem1.price, 5.99);
88
- });
89
-
90
- test("Order Descriptor", async () => {
91
- compareClassDescriptor(Order.ClassDescriptor, Order._ClassDescriptor);
92
- Restaurant.all();
93
- Order.all();
94
- const order1 = Order.GetObject({ orderId: 1 });
95
- const order2 = Order.GetObject({ orderId: 1 });
96
- order2.dateTime = DateTime.CreateObject({
97
- year: 2023,
98
- month: 1,
99
- day: 1,
100
- hour: 13,
101
- minute: 0,
102
- });
103
- assert.equal(
104
- order1.dateTime.toString(),
105
- new DateTime({
106
- year: 2023,
107
- month: 1,
108
- day: 1,
109
- hour: 13,
110
- minute: 0,
111
- }).toString()
112
- );
113
- order2.dateTime = DateTime.CreateObject({
114
- year: 2023,
115
- month: 1,
116
- day: 2,
117
- hour: 13,
118
- minute: 0,
119
- });
120
- assert.equal(
121
- order1.dateTime.toString(),
122
- new DateTime({
123
- year: 2023,
124
- month: 1,
125
- day: 2,
126
- hour: 13,
127
- minute: 0,
128
- }).toString()
129
- );
130
- });
131
-
132
- @GenieClass("To-do list item")
133
- class TodoListItem extends HelperClass {
134
- @GenieProperty("Name of the item")
135
- name: string;
136
- @GenieProperty("Whether the item is done")
137
- done: boolean;
138
-
139
- constructor({name, done}: {name: string, done: boolean}) {
140
- super({});
141
- this.name = name;
142
- this.done = done;
143
- }
144
- }
145
-
146
- @GenieClass("To-do list")
147
- class TodoList extends DataClass {
148
- @GenieKey
149
- @GenieProperty("Name of the list")
150
- name: string;
151
- @GenieProperty("Items in the list")
152
- items: TodoListItem[];
153
-
154
- constructor({name, items}: {name: string, items: TodoListItem[]}) {
155
- super({});
156
- this.name = name;
157
- this.items = items;
158
- }
159
-
160
- static setup() {
161
- TodoList.CreateObject({name: "Groceries", items: [
162
- TodoListItem.CreateObject({name: "Milk", done: false}),
163
- TodoListItem.CreateObject({name: "Eggs", done: false}),
164
- TodoListItem.CreateObject({name: "Bread", done: false}),
165
- ]});
166
- }
167
- }
168
-
169
- test("Change TodoList", async () => {
170
- genieDispatch(() => {
171
- const groceriesList = TodoList.GetObject({ name: "Groceries" });
172
- const item = groceriesList.items[0];
173
- item.done = true;
174
- const groceriesListItems = groceriesList.items;
175
- groceriesListItems.push(TodoListItem.CreateObject({name: "Butter", done: false}));
176
- });
177
- });
@@ -1,92 +0,0 @@
1
- import "..";
2
- import { GenieClass, GenieFunction, GenieProperty } from "..";
3
- import { HelperClass } from "../../dsl-descriptor";
4
-
5
- @GenieClass("Parent helper")
6
- class ParentHelper extends HelperClass {
7
- @GenieProperty("Parent field")
8
- parentField: string;
9
-
10
- constructor({ parentField = "parent" }: { parentField?: string } = {}) {
11
- super({});
12
- this.parentField = parentField;
13
- }
14
-
15
- @GenieFunction("Parent instance method")
16
- parentInstance(): ParentHelper {
17
- return this;
18
- }
19
-
20
- @GenieFunction("Parent static method")
21
- static parentStatic(): ParentHelper {
22
- return ParentHelper.CreateObject({ parentField: "from-parent-static" });
23
- }
24
- }
25
-
26
- @GenieClass("Child helper")
27
- class ChildHelper extends ParentHelper {
28
- @GenieProperty("Child field")
29
- childField: string;
30
-
31
- constructor({
32
- parentField = "parent",
33
- childField = "child",
34
- }: {
35
- parentField?: string;
36
- childField?: string;
37
- } = {}) {
38
- super({ parentField });
39
- this.childField = childField;
40
- }
41
-
42
- @GenieFunction("Child instance method")
43
- childInstance(): ChildHelper {
44
- return this;
45
- }
46
-
47
- @GenieFunction("Child static method")
48
- static childStatic(): ChildHelper {
49
- return ChildHelper.CreateObject({
50
- parentField: "from-child-static",
51
- childField: "from-child-static",
52
- });
53
- }
54
- }
55
-
56
- describe("Genie descriptor inheritance isolation", () => {
57
- test("creates an own ClassDescriptor for subclass and keeps parent descriptor clean", () => {
58
- expect(Object.prototype.hasOwnProperty.call(ParentHelper, "ClassDescriptor")).toBe(true);
59
- expect(Object.prototype.hasOwnProperty.call(ChildHelper, "ClassDescriptor")).toBe(true);
60
-
61
- expect(ParentHelper.ClassDescriptor.className).toBe("ParentHelper");
62
- expect(ChildHelper.ClassDescriptor.className).toBe("ChildHelper");
63
-
64
- const parentFunctions = Array.from(ParentHelper.ClassDescriptor.functions).map(
65
- (func: any) => func.func_name
66
- );
67
- expect(parentFunctions).toContain("parentInstance");
68
- expect(parentFunctions).toContain("parentStatic");
69
- expect(parentFunctions).not.toContain("childInstance");
70
- expect(parentFunctions).not.toContain("childStatic");
71
-
72
- const childFunctions = Array.from(ChildHelper.ClassDescriptor.functions).map(
73
- (func: any) => func.func_name
74
- );
75
- expect(childFunctions).toContain("parentInstance");
76
- expect(childFunctions).toContain("parentStatic");
77
- expect(childFunctions).toContain("childInstance");
78
- expect(childFunctions).toContain("childStatic");
79
-
80
- const parentFields = Array.from(ParentHelper.ClassDescriptor.fields).map(
81
- (field: any) => field.field
82
- );
83
- expect(parentFields).toContain("parentField");
84
- expect(parentFields).not.toContain("childField");
85
-
86
- const childFields = Array.from(ChildHelper.ClassDescriptor.fields).map(
87
- (field: any) => field.field
88
- );
89
- expect(childFields).toContain("parentField");
90
- expect(childFields).toContain("childField");
91
- });
92
- });