eny-ai 1.0.0 → 2.0.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/V2_README.md +414 -0
- package/dist/chunk-2NUS77CI.js +195 -0
- package/dist/chunk-5KPALVCK.js +280 -0
- package/dist/{chunk-2WFUL4XJ.js → chunk-5PZUUNHS.js} +717 -751
- package/dist/{chunk-E4KJZEXX.js → chunk-AJH2I5ZI.js} +5 -0
- package/dist/chunk-LVJ3GJRQ.js +360 -0
- package/dist/{chunk-PNKVD2UK.js → chunk-MXA7TAAG.js} +11 -1
- package/dist/cli.js +5 -4
- package/dist/firebase.cjs +296 -0
- package/dist/firebase.d.cts +136 -0
- package/dist/firebase.d.ts +136 -0
- package/dist/firebase.js +17 -0
- package/dist/hooks.cjs +236 -0
- package/dist/hooks.d.cts +184 -0
- package/dist/hooks.d.ts +184 -0
- package/dist/hooks.js +31 -0
- package/dist/index.cjs +1622 -1092
- package/dist/index.d.cts +16 -195
- package/dist/index.d.ts +16 -195
- package/dist/index.js +68 -262
- package/dist/runtime.cjs +366 -0
- package/dist/runtime.d.cts +229 -0
- package/dist/runtime.d.ts +229 -0
- package/dist/runtime.js +25 -0
- package/dist/symbols.js +2 -2
- package/examples/app-simbolico-completo.tsx +249 -0
- package/examples/nextjs-integration.tsx +446 -0
- package/examples/v2-demo.tsx +377 -0
- package/package.json +23 -11
- package/dist/react/index.cjs +0 -342
- package/dist/react/index.d.cts +0 -751
- package/dist/react/index.d.ts +0 -751
- package/dist/react/index.js +0 -284
package/dist/index.cjs
CHANGED
|
@@ -30,7 +30,911 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
34
|
+
var init_cjs_shims = __esm({
|
|
35
|
+
"node_modules/tsup/assets/cjs_shims.js"() {
|
|
36
|
+
"use strict";
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// src/runtime.ts
|
|
41
|
+
var runtime_exports = {};
|
|
42
|
+
__export(runtime_exports, {
|
|
43
|
+
ENYRuntime: () => ENYRuntime,
|
|
44
|
+
eny: () => eny,
|
|
45
|
+
filterArray: () => filterArray,
|
|
46
|
+
func: () => func,
|
|
47
|
+
lambda: () => lambda,
|
|
48
|
+
mapArray: () => mapArray,
|
|
49
|
+
reduceArray: () => reduceArray,
|
|
50
|
+
state: () => state2,
|
|
51
|
+
substate: () => substate
|
|
52
|
+
});
|
|
53
|
+
var ENYRuntime, eny, state2, substate, func, lambda, mapArray, filterArray, reduceArray;
|
|
54
|
+
var init_runtime = __esm({
|
|
55
|
+
"src/runtime.ts"() {
|
|
56
|
+
"use strict";
|
|
57
|
+
init_cjs_shims();
|
|
58
|
+
ENYRuntime = class {
|
|
59
|
+
constructor() {
|
|
60
|
+
this.context = {};
|
|
61
|
+
this.hooks = /* @__PURE__ */ new Map();
|
|
62
|
+
this.effects = [];
|
|
63
|
+
// ════════════════════════════════════════════════════════════════
|
|
64
|
+
// SÍMBOLOS HTTP/ASYNC
|
|
65
|
+
// ════════════════════════════════════════════════════════════════
|
|
66
|
+
/**
|
|
67
|
+
* http - HTTP methods
|
|
68
|
+
* http.GET(url), http.POST(url, data), etc
|
|
69
|
+
* Alias: ⇄
|
|
70
|
+
*/
|
|
71
|
+
this.http = {
|
|
72
|
+
GET: async (url) => {
|
|
73
|
+
const res = await fetch(url);
|
|
74
|
+
return res.json();
|
|
75
|
+
},
|
|
76
|
+
POST: async (url, data) => {
|
|
77
|
+
const res = await fetch(url, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
headers: { "Content-Type": "application/json" },
|
|
80
|
+
body: JSON.stringify(data)
|
|
81
|
+
});
|
|
82
|
+
return res.json();
|
|
83
|
+
},
|
|
84
|
+
PUT: async (url, data) => {
|
|
85
|
+
const res = await fetch(url, {
|
|
86
|
+
method: "PUT",
|
|
87
|
+
headers: { "Content-Type": "application/json" },
|
|
88
|
+
body: JSON.stringify(data)
|
|
89
|
+
});
|
|
90
|
+
return res.json();
|
|
91
|
+
},
|
|
92
|
+
DELETE: async (url) => {
|
|
93
|
+
const res = await fetch(url, { method: "DELETE" });
|
|
94
|
+
return res.json();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
// ════════════════════════════════════════════════════════════════
|
|
98
|
+
// SÍMBOLOS MEMÓRIA/STORAGE
|
|
99
|
+
// ════════════════════════════════════════════════════════════════
|
|
100
|
+
/**
|
|
101
|
+
* storage - Memory/Storage access
|
|
102
|
+
* storage.get(key), storage.set(key, value)
|
|
103
|
+
* Alias: 𝓜
|
|
104
|
+
*/
|
|
105
|
+
this.storage = {
|
|
106
|
+
get: (key) => localStorage.getItem(key),
|
|
107
|
+
set: (key, value) => localStorage.setItem(key, JSON.stringify(value)),
|
|
108
|
+
remove: (key) => localStorage.removeItem(key),
|
|
109
|
+
clear: () => localStorage.clear(),
|
|
110
|
+
session: {
|
|
111
|
+
get: (key) => sessionStorage.getItem(key),
|
|
112
|
+
set: (key, value) => sessionStorage.setItem(key, JSON.stringify(value))
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
// ════════════════════════════════════════════════════════════════
|
|
116
|
+
// SÍMBOLOS SEGURANÇA
|
|
117
|
+
// ════════════════════════════════════════════════════════════════
|
|
118
|
+
/**
|
|
119
|
+
* validate - Validation helpers
|
|
120
|
+
* validate.email(str), validate.min(len)
|
|
121
|
+
* Alias: 🛡
|
|
122
|
+
*/
|
|
123
|
+
this.validate = {
|
|
124
|
+
email: (str) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(str),
|
|
125
|
+
min: (len) => (str) => str.length >= len,
|
|
126
|
+
max: (len) => (str) => str.length <= len,
|
|
127
|
+
regex: (pattern) => (str) => pattern.test(str),
|
|
128
|
+
required: (val) => val != null && val !== "",
|
|
129
|
+
equals: (expected) => (actual) => actual === expected
|
|
130
|
+
};
|
|
131
|
+
this.crypto = {
|
|
132
|
+
lock: (obj) => Object.freeze(obj),
|
|
133
|
+
unlock: (obj) => Object.assign({}, obj)
|
|
134
|
+
};
|
|
135
|
+
// ════════════════════════════════════════════════════════════════
|
|
136
|
+
// SÍMBOLOS NAVEGAÇÃO
|
|
137
|
+
// ════════════════════════════════════════════════════════════════
|
|
138
|
+
/**
|
|
139
|
+
* router - Router/Navigation
|
|
140
|
+
* router.navigate(path), router.back()
|
|
141
|
+
* Alias: 🧭
|
|
142
|
+
*/
|
|
143
|
+
this.router = {
|
|
144
|
+
navigate: (path) => window.location.href = path,
|
|
145
|
+
back: () => window.history.back(),
|
|
146
|
+
forward: () => window.history.forward(),
|
|
147
|
+
reload: () => window.location.reload(),
|
|
148
|
+
params: () => new URLSearchParams(window.location.search)
|
|
149
|
+
};
|
|
150
|
+
// ════════════════════════════════════════════════════════════════
|
|
151
|
+
// SISTEMA DE LOGS
|
|
152
|
+
// ════════════════════════════════════════════════════════════════
|
|
153
|
+
/**
|
|
154
|
+
* logger - Logging system
|
|
155
|
+
* logger.info(msg), logger.error(msg), logger.warn(msg)
|
|
156
|
+
* Alias: 📜
|
|
157
|
+
*/
|
|
158
|
+
this.logger = {
|
|
159
|
+
info: (msg, data) => console.log(`\u2139\uFE0F ${msg}`, data),
|
|
160
|
+
error: (msg, data) => console.error(`\u274C ${msg}`, data),
|
|
161
|
+
warn: (msg, data) => console.warn(`\u26A0\uFE0F ${msg}`, data),
|
|
162
|
+
log: (msg, data) => console.log(`\u{1F4DC} ${msg}`, data)
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
// ════════════════════════════════════════════════════════════════
|
|
166
|
+
// SÍMBOLOS BÁSICOS - ESTADO
|
|
167
|
+
// ════════════════════════════════════════════════════════════════
|
|
168
|
+
/**
|
|
169
|
+
* Σ - Cria estado global
|
|
170
|
+
* Σ('user', { name: 'João' })
|
|
171
|
+
*/
|
|
172
|
+
\u03A3(key, initialValue) {
|
|
173
|
+
if (!this.context[key]) {
|
|
174
|
+
this.context[key] = initialValue;
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
get: () => this.context[key],
|
|
178
|
+
set: (value) => {
|
|
179
|
+
this.context[key] = value;
|
|
180
|
+
this.notify();
|
|
181
|
+
},
|
|
182
|
+
value: this.context[key]
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* σ - Sub-estado (local)
|
|
187
|
+
* σ(parent, 'field')
|
|
188
|
+
*/
|
|
189
|
+
\u03C3(parent, field) {
|
|
190
|
+
return {
|
|
191
|
+
get: () => parent[field],
|
|
192
|
+
set: (value) => {
|
|
193
|
+
parent[field] = value;
|
|
194
|
+
},
|
|
195
|
+
value: parent[field]
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* ⊤ e ⊥ - Booleanos
|
|
200
|
+
*/
|
|
201
|
+
get TRUE() {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
get FALSE() {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
// Aliases simbólicos para compatibilidade
|
|
208
|
+
get trueValue() {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
get falseValue() {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Ø - Nulo/Vazio
|
|
216
|
+
*/
|
|
217
|
+
get \u00D8() {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
// ════════════════════════════════════════════════════════════════
|
|
221
|
+
// SÍMBOLOS FUNCIONAIS - FUNÇÕES
|
|
222
|
+
// ════════════════════════════════════════════════════════════════
|
|
223
|
+
/**
|
|
224
|
+
* func - Define função normal
|
|
225
|
+
* func('myFunc', (a, b) => a + b)
|
|
226
|
+
*/
|
|
227
|
+
func(name, fn2) {
|
|
228
|
+
const wrapped = fn2;
|
|
229
|
+
this.context[name] = wrapped;
|
|
230
|
+
return wrapped;
|
|
231
|
+
}
|
|
232
|
+
// Alias: ƒ
|
|
233
|
+
get \u0192() {
|
|
234
|
+
return this.func.bind(this);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* lambda - Arrow function/Lambda
|
|
238
|
+
* lambda(fn) - wraps e memoiza
|
|
239
|
+
*/
|
|
240
|
+
lambda(fn2) {
|
|
241
|
+
return fn2;
|
|
242
|
+
}
|
|
243
|
+
// Alias: λ
|
|
244
|
+
get \u03BB() {
|
|
245
|
+
return this.lambda.bind(this);
|
|
246
|
+
}
|
|
247
|
+
// ════════════════════════════════════════════════════════════════
|
|
248
|
+
// SÍMBOLOS DE ARRAY - ITERAÇÃO
|
|
249
|
+
// ════════════════════════════════════════════════════════════════
|
|
250
|
+
/**
|
|
251
|
+
* map - Map operator
|
|
252
|
+
* arr.map((item) => item * 2)
|
|
253
|
+
* Alias: ↦
|
|
254
|
+
*/
|
|
255
|
+
map(arr, fn2) {
|
|
256
|
+
return arr.map((item) => fn2(item));
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* filter - Filter operator
|
|
260
|
+
* arr.filter((item) => item > 5)
|
|
261
|
+
* Alias: ⊳
|
|
262
|
+
*/
|
|
263
|
+
filter(arr, predicate) {
|
|
264
|
+
return arr.filter((item) => predicate(item));
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* reduce - Reduce operator
|
|
268
|
+
* arr.reduce((acc, item) => acc + item, 0)
|
|
269
|
+
* Alias: ⊲
|
|
270
|
+
*/
|
|
271
|
+
reduce(arr, reducer, initial = 0) {
|
|
272
|
+
return arr.reduce((acc, item) => reducer(acc, item), initial);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* find - Find operator
|
|
276
|
+
* arr.find((item) => item.id === 5)
|
|
277
|
+
* Alias: ⊙
|
|
278
|
+
*/
|
|
279
|
+
find(arr, predicate) {
|
|
280
|
+
return arr.find((item) => predicate(item));
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* every - Every operator
|
|
284
|
+
* arr.every((item) => item > 0)
|
|
285
|
+
* Alias: ∀
|
|
286
|
+
*/
|
|
287
|
+
every(arr, predicate) {
|
|
288
|
+
return arr.every((item) => predicate(item));
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* some - Some operator
|
|
292
|
+
* arr.some((item) => item > 0)
|
|
293
|
+
* Alias: ∃
|
|
294
|
+
*/
|
|
295
|
+
some(arr, predicate) {
|
|
296
|
+
return arr.some((item) => predicate(item));
|
|
297
|
+
}
|
|
298
|
+
// ════════════════════════════════════════════════════════════════
|
|
299
|
+
// SÍMBOLOS OPERADORES
|
|
300
|
+
// ════════════════════════════════════════════════════════════════
|
|
301
|
+
/**
|
|
302
|
+
* assign - Assignment operator
|
|
303
|
+
* Alias: ←
|
|
304
|
+
*/
|
|
305
|
+
assign(target, value) {
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* and - AND operator
|
|
310
|
+
* Alias: ∧
|
|
311
|
+
*/
|
|
312
|
+
and(a, b) {
|
|
313
|
+
return a && b;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* or - OR operator
|
|
317
|
+
* Alias: ∨
|
|
318
|
+
*/
|
|
319
|
+
or(a, b) {
|
|
320
|
+
return a || b;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* not - NOT operator
|
|
324
|
+
* Alias: ¬
|
|
325
|
+
*/
|
|
326
|
+
not(a) {
|
|
327
|
+
return !a;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* merge - Merge/Spread operator
|
|
331
|
+
* Alias: ⊕
|
|
332
|
+
*/
|
|
333
|
+
merge(...objs) {
|
|
334
|
+
return Object.assign({}, ...objs);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* encode - Basic encoding/decoding
|
|
338
|
+
* Alias: 🔑 🔒 🔓
|
|
339
|
+
*/
|
|
340
|
+
encode(data) {
|
|
341
|
+
return btoa(data);
|
|
342
|
+
}
|
|
343
|
+
// ════════════════════════════════════════════════════════════════
|
|
344
|
+
// INTERNALS
|
|
345
|
+
// ════════════════════════════════════════════════════════════════
|
|
346
|
+
notify() {
|
|
347
|
+
this.effects.forEach((effect2) => effect2());
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* effect - Register effect function
|
|
351
|
+
* Alias: ⚡
|
|
352
|
+
*/
|
|
353
|
+
effect(fn2, deps = []) {
|
|
354
|
+
this.effects.push(() => fn2());
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Obter todo contexto
|
|
358
|
+
*/
|
|
359
|
+
getContext() {
|
|
360
|
+
return { ...this.context };
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Limpar runtime
|
|
364
|
+
*/
|
|
365
|
+
clear() {
|
|
366
|
+
this.context = {};
|
|
367
|
+
this.hooks.clear();
|
|
368
|
+
this.effects = [];
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
eny = new ENYRuntime();
|
|
372
|
+
state2 = eny.\u03A3.bind(eny);
|
|
373
|
+
substate = eny.\u03C3.bind(eny);
|
|
374
|
+
func = eny.func.bind(eny);
|
|
375
|
+
lambda = eny.lambda.bind(eny);
|
|
376
|
+
mapArray = eny.map.bind(eny);
|
|
377
|
+
filterArray = eny.filter.bind(eny);
|
|
378
|
+
reduceArray = eny.reduce.bind(eny);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// src/firebase/index.ts
|
|
383
|
+
var firebase_exports = {};
|
|
384
|
+
__export(firebase_exports, {
|
|
385
|
+
ENYFirebase: () => ENYFirebase,
|
|
386
|
+
firebase: () => firebase,
|
|
387
|
+
useAuth: () => useAuth,
|
|
388
|
+
useFirebase: () => useFirebase,
|
|
389
|
+
useRealtimeData: () => useRealtimeData
|
|
390
|
+
});
|
|
391
|
+
function useFirebase() {
|
|
392
|
+
return firebase;
|
|
393
|
+
}
|
|
394
|
+
function useAuth(callback) {
|
|
395
|
+
const [user, setUser] = import_react2.default.useState(null);
|
|
396
|
+
const [loading, setLoading] = import_react2.default.useState(true);
|
|
397
|
+
import_react2.default.useEffect(() => {
|
|
398
|
+
const unsubscribe = firebase.onAuthStateChange((u) => {
|
|
399
|
+
setUser(u);
|
|
400
|
+
setLoading(false);
|
|
401
|
+
callback?.(u);
|
|
402
|
+
});
|
|
403
|
+
return () => unsubscribe();
|
|
404
|
+
}, [callback]);
|
|
405
|
+
return { user, loading };
|
|
406
|
+
}
|
|
407
|
+
function useRealtimeData(path) {
|
|
408
|
+
const [data, setData] = import_react2.default.useState(null);
|
|
409
|
+
const [loading, setLoading] = import_react2.default.useState(true);
|
|
410
|
+
import_react2.default.useEffect(() => {
|
|
411
|
+
const unsubscribe = firebase.watch(path, (d) => {
|
|
412
|
+
setData(d);
|
|
413
|
+
setLoading(false);
|
|
414
|
+
});
|
|
415
|
+
return () => unsubscribe();
|
|
416
|
+
}, [path]);
|
|
417
|
+
return { data, loading };
|
|
418
|
+
}
|
|
419
|
+
var import_app, import_auth, import_database, import_react2, ENYFirebase, firebase;
|
|
420
|
+
var init_firebase = __esm({
|
|
421
|
+
"src/firebase/index.ts"() {
|
|
422
|
+
"use strict";
|
|
423
|
+
init_cjs_shims();
|
|
424
|
+
import_app = require("firebase/app");
|
|
425
|
+
import_auth = require("firebase/auth");
|
|
426
|
+
import_database = require("firebase/database");
|
|
427
|
+
import_react2 = __toESM(require("react"), 1);
|
|
428
|
+
ENYFirebase = class {
|
|
429
|
+
constructor() {
|
|
430
|
+
this.app = null;
|
|
431
|
+
this.auth = null;
|
|
432
|
+
this.db = null;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* ⚙️ - Inicializar Firebase
|
|
436
|
+
*/
|
|
437
|
+
initialize(config) {
|
|
438
|
+
this.app = (0, import_app.initializeApp)(config);
|
|
439
|
+
this.auth = (0, import_auth.getAuth)(this.app);
|
|
440
|
+
this.db = (0, import_database.getDatabase)(this.app);
|
|
441
|
+
console.log("\u2705 Firebase inicializado");
|
|
442
|
+
}
|
|
443
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
444
|
+
// MÉTODOS AUTENTICAÇÃO
|
|
445
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
446
|
+
/**
|
|
447
|
+
* signin - Login com email/senha
|
|
448
|
+
* signin(email, password)
|
|
449
|
+
* Alias: 🔑(email, password)
|
|
450
|
+
*/
|
|
451
|
+
async signin(email, password) {
|
|
452
|
+
if (!this.auth) throw new Error("Firebase not initialized");
|
|
453
|
+
try {
|
|
454
|
+
const credential = await (0, import_auth.signInWithEmailAndPassword)(this.auth, email, password);
|
|
455
|
+
console.log("\u2705 Login bem-sucedido:", email);
|
|
456
|
+
return {
|
|
457
|
+
user: credential.user,
|
|
458
|
+
success: true
|
|
459
|
+
};
|
|
460
|
+
} catch (error2) {
|
|
461
|
+
console.error("\u274C Erro login:", error2);
|
|
462
|
+
throw error2;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* signup - Criar conta
|
|
467
|
+
* signup(email, password)
|
|
468
|
+
* Alias: 📝(email, password)
|
|
469
|
+
*/
|
|
470
|
+
async signup(email, password) {
|
|
471
|
+
if (!this.auth) throw new Error("Firebase not initialized");
|
|
472
|
+
try {
|
|
473
|
+
const credential = await (0, import_auth.createUserWithEmailAndPassword)(this.auth, email, password);
|
|
474
|
+
console.log("\u2705 Conta criada:", email);
|
|
475
|
+
return {
|
|
476
|
+
user: credential.user,
|
|
477
|
+
success: true
|
|
478
|
+
};
|
|
479
|
+
} catch (error2) {
|
|
480
|
+
console.error("\u274C Erro criar conta:", error2);
|
|
481
|
+
throw error2;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* signout - Logout
|
|
486
|
+
* signout()
|
|
487
|
+
* Alias: 🚪()
|
|
488
|
+
*/
|
|
489
|
+
async signout() {
|
|
490
|
+
if (!this.auth) throw new Error("Firebase not initialized");
|
|
491
|
+
try {
|
|
492
|
+
await (0, import_auth.signOut)(this.auth);
|
|
493
|
+
console.log("\u{1F44B} Desconectado");
|
|
494
|
+
return { success: true };
|
|
495
|
+
} catch (error2) {
|
|
496
|
+
console.error("\u274C Erro logout:", error2);
|
|
497
|
+
throw error2;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* currentUser - Obter usuário atual
|
|
502
|
+
* Alias: 👤
|
|
503
|
+
*/
|
|
504
|
+
get currentUser() {
|
|
505
|
+
return this.auth?.currentUser || null;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* onAuthStateChange - Observar estado autenticação
|
|
509
|
+
* onAuthStateChange((user) => {...})
|
|
510
|
+
* Alias: 👁((user) => {...})
|
|
511
|
+
*/
|
|
512
|
+
onAuthStateChange(callback) {
|
|
513
|
+
if (!this.auth) throw new Error("Firebase not initialized");
|
|
514
|
+
return (0, import_auth.onAuthStateChanged)(this.auth, callback);
|
|
515
|
+
}
|
|
516
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
517
|
+
// MÉTODOS DATABASE
|
|
518
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
519
|
+
/**
|
|
520
|
+
* write - Escrever dados
|
|
521
|
+
* write('users/123', { name: 'João' })
|
|
522
|
+
* Alias: 📊(path, data)
|
|
523
|
+
*/
|
|
524
|
+
async write(path, data) {
|
|
525
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
526
|
+
try {
|
|
527
|
+
const dbRef = (0, import_database.ref)(this.db, path);
|
|
528
|
+
await (0, import_database.set)(dbRef, data);
|
|
529
|
+
console.log("\u2705 Dados salvos:", path);
|
|
530
|
+
return { success: true };
|
|
531
|
+
} catch (error2) {
|
|
532
|
+
console.error("\u274C Erro salvar:", error2);
|
|
533
|
+
throw error2;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* read - Ler dados (uma vez)
|
|
538
|
+
* read('users/123')
|
|
539
|
+
* Alias: 🔍('users/123')
|
|
540
|
+
*/
|
|
541
|
+
async read(path) {
|
|
542
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
543
|
+
try {
|
|
544
|
+
const dbRef = (0, import_database.ref)(this.db, path);
|
|
545
|
+
const snapshot = await (0, import_database.get)(dbRef);
|
|
546
|
+
console.log("\u2705 Dados lidos:", path);
|
|
547
|
+
return snapshot.val();
|
|
548
|
+
} catch (error2) {
|
|
549
|
+
console.error("\u274C Erro ler:", error2);
|
|
550
|
+
throw error2;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* watch - Observar dados em tempo real
|
|
555
|
+
* watch('users/123', (data) => {...})
|
|
556
|
+
* Alias: 📡('users/123', (data) => {...})
|
|
557
|
+
*/
|
|
558
|
+
watch(path, callback) {
|
|
559
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
560
|
+
const dbRef = (0, import_database.ref)(this.db, path);
|
|
561
|
+
return (0, import_database.onValue)(dbRef, (snapshot) => {
|
|
562
|
+
callback(snapshot.val());
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* update - Atualizar dados específicos
|
|
567
|
+
* update('users/123', { name: 'João Silva' })
|
|
568
|
+
* Alias: ✏️('users/123', { name: 'João Silva' })
|
|
569
|
+
*/
|
|
570
|
+
async updateData(path, data) {
|
|
571
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
572
|
+
try {
|
|
573
|
+
const dbRef = (0, import_database.ref)(this.db, path);
|
|
574
|
+
await (0, import_database.update)(dbRef, data);
|
|
575
|
+
console.log("\u2705 Dados atualizados:", path);
|
|
576
|
+
return { success: true };
|
|
577
|
+
} catch (error2) {
|
|
578
|
+
console.error("\u274C Erro atualizar:", error2);
|
|
579
|
+
throw error2;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* delete - Deletar dados
|
|
584
|
+
* delete('users/123')
|
|
585
|
+
* Alias: 🗑️('users/123')
|
|
586
|
+
*/
|
|
587
|
+
async delete(path) {
|
|
588
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
589
|
+
try {
|
|
590
|
+
const dbRef = (0, import_database.ref)(this.db, path);
|
|
591
|
+
await (0, import_database.remove)(dbRef);
|
|
592
|
+
console.log("\u2705 Dados deletados:", path);
|
|
593
|
+
return { success: true };
|
|
594
|
+
} catch (error2) {
|
|
595
|
+
console.error("\u274C Erro deletar:", error2);
|
|
596
|
+
throw error2;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* query - Query com ordem/limite
|
|
601
|
+
* query('users', 'age', 10)
|
|
602
|
+
* Alias: 🔗('users', 'age', 10)
|
|
603
|
+
*/
|
|
604
|
+
async queryData(path, orderBy = "", limit = 0) {
|
|
605
|
+
if (!this.db) throw new Error("Firebase not initialized");
|
|
606
|
+
try {
|
|
607
|
+
const dbRef = (0, import_database.ref)(this.db, path);
|
|
608
|
+
let q = dbRef;
|
|
609
|
+
if (orderBy) {
|
|
610
|
+
q = (0, import_database.query)(dbRef, (0, import_database.orderByChild)(orderBy));
|
|
611
|
+
}
|
|
612
|
+
if (limit) {
|
|
613
|
+
q = (0, import_database.query)(dbRef, (0, import_database.limitToFirst)(limit));
|
|
614
|
+
}
|
|
615
|
+
const snapshot = await (0, import_database.get)(q);
|
|
616
|
+
return snapshot.val();
|
|
617
|
+
} catch (error2) {
|
|
618
|
+
console.error("\u274C Erro query:", error2);
|
|
619
|
+
throw error2;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
623
|
+
// HELPERS
|
|
624
|
+
// ═════════════════════════════════════════════════════════════════════════════
|
|
625
|
+
/**
|
|
626
|
+
* 🔐 - Contexto de autenticação
|
|
627
|
+
*/
|
|
628
|
+
getAuth() {
|
|
629
|
+
return this.auth;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* 📂 - Contexto de database
|
|
633
|
+
*/
|
|
634
|
+
getDatabase() {
|
|
635
|
+
return this.db;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Verificar se está autenticado
|
|
639
|
+
*/
|
|
640
|
+
isAuthenticated() {
|
|
641
|
+
return this.currentUser !== null;
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
firebase = new ENYFirebase();
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
// src/index.ts
|
|
649
|
+
var src_exports = {};
|
|
650
|
+
__export(src_exports, {
|
|
651
|
+
ALPHABET: () => ALPHABET,
|
|
652
|
+
ENYFirebase: () => ENYFirebase,
|
|
653
|
+
ENYRuntime: () => ENYRuntime,
|
|
654
|
+
EnyContext: () => EnyContext,
|
|
655
|
+
EnyUI: () => EnyUI,
|
|
656
|
+
EnyValidate: () => EnyValidate,
|
|
657
|
+
FALSE: () => FALSE,
|
|
658
|
+
IAManager: () => IAManager,
|
|
659
|
+
LocalIA: () => LocalIA,
|
|
660
|
+
NAME: () => NAME,
|
|
661
|
+
NIL: () => NIL,
|
|
662
|
+
RemoteIA: () => RemoteIA,
|
|
663
|
+
SYMBOLS: () => SYMBOLS2,
|
|
664
|
+
SYMBOL_NAMES: () => SYMBOL_NAMES,
|
|
665
|
+
TRANSPILE_MAP: () => TRANSPILE_MAP,
|
|
666
|
+
TRUE: () => TRUE,
|
|
667
|
+
TokenType: () => TokenType,
|
|
668
|
+
VERSION: () => VERSION,
|
|
669
|
+
VOID: () => VOID,
|
|
670
|
+
applyEvolve: () => applyEvolve,
|
|
671
|
+
asyncFn: () => asyncFn,
|
|
672
|
+
component: () => component,
|
|
673
|
+
createEnySystem: () => createEnySystem,
|
|
674
|
+
defaultIAManager: () => defaultIAManager,
|
|
675
|
+
effect: () => effect,
|
|
676
|
+
error: () => error,
|
|
677
|
+
filter: () => filter,
|
|
678
|
+
find: () => find,
|
|
679
|
+
firebase: () => firebase,
|
|
680
|
+
fn: () => fn,
|
|
681
|
+
get: () => get,
|
|
682
|
+
hasWASMTarget: () => hasWASMTarget,
|
|
683
|
+
initializeEnyFirebase: () => initializeEnyFirebase,
|
|
684
|
+
log: () => log,
|
|
685
|
+
map: () => map,
|
|
686
|
+
navigate: () => navigate,
|
|
687
|
+
parse: () => parse,
|
|
688
|
+
post: () => post,
|
|
689
|
+
processIA: () => processIA,
|
|
690
|
+
reduce: () => reduce,
|
|
691
|
+
runENY: () => runENY,
|
|
692
|
+
shape: () => shape,
|
|
693
|
+
state: () => state,
|
|
694
|
+
storageGet: () => storageGet,
|
|
695
|
+
storageSet: () => storageSet,
|
|
696
|
+
toSymbolic: () => toSymbolic,
|
|
697
|
+
tokenize: () => tokenize,
|
|
698
|
+
transpileSymbols: () => transpileSymbols,
|
|
699
|
+
transpileToDTS: () => transpileToDTS,
|
|
700
|
+
transpileToJS: () => transpileToJS,
|
|
701
|
+
transpileToWAT: () => transpileToWAT,
|
|
702
|
+
useAuth: () => useAuth,
|
|
703
|
+
useCallbackWithDeps: () => useCallbackWithDeps,
|
|
704
|
+
useEnyEffect: () => useEnyEffect,
|
|
705
|
+
useEnyFetch: () => useEnyFetch,
|
|
706
|
+
useEnyState: () => useEnyState,
|
|
707
|
+
useFirebase: () => useFirebase,
|
|
708
|
+
useLogger: () => useLogger,
|
|
709
|
+
useMemoWithDeps: () => useMemoWithDeps,
|
|
710
|
+
useNavigation: () => useNavigation,
|
|
711
|
+
usePersistentState: () => usePersistentState,
|
|
712
|
+
useRealtimeData: () => useRealtimeData,
|
|
713
|
+
useReducerWithState: () => useReducerWithState,
|
|
714
|
+
useValidation: () => useValidation,
|
|
715
|
+
validate: () => validate,
|
|
716
|
+
validateSemantic: () => validateSemantic,
|
|
717
|
+
validateSemanticFull: () => validateSemanticFull
|
|
718
|
+
});
|
|
719
|
+
module.exports = __toCommonJS(src_exports);
|
|
720
|
+
init_cjs_shims();
|
|
721
|
+
|
|
722
|
+
// src/runENY.ts
|
|
723
|
+
init_cjs_shims();
|
|
724
|
+
|
|
725
|
+
// src/parser.ts
|
|
726
|
+
init_cjs_shims();
|
|
727
|
+
|
|
728
|
+
// src/parser/ebnfParser.ts
|
|
729
|
+
init_cjs_shims();
|
|
730
|
+
|
|
33
731
|
// src/lexer/tokenize.ts
|
|
732
|
+
init_cjs_shims();
|
|
733
|
+
var TokenType = /* @__PURE__ */ ((TokenType2) => {
|
|
734
|
+
TokenType2["SYMBOL"] = "SYMBOL";
|
|
735
|
+
TokenType2["IDENTIFIER"] = "IDENTIFIER";
|
|
736
|
+
TokenType2["STRING"] = "STRING";
|
|
737
|
+
TokenType2["NUMBER"] = "NUMBER";
|
|
738
|
+
TokenType2["ARROW"] = "ARROW";
|
|
739
|
+
TokenType2["LBRACE"] = "LBRACE";
|
|
740
|
+
TokenType2["RBRACE"] = "RBRACE";
|
|
741
|
+
TokenType2["COLON"] = "COLON";
|
|
742
|
+
TokenType2["COMMA"] = "COMMA";
|
|
743
|
+
TokenType2["LPAREN"] = "LPAREN";
|
|
744
|
+
TokenType2["RPAREN"] = "RPAREN";
|
|
745
|
+
TokenType2["LBRACKET"] = "LBRACKET";
|
|
746
|
+
TokenType2["RBRACKET"] = "RBRACKET";
|
|
747
|
+
TokenType2["NEWLINE"] = "NEWLINE";
|
|
748
|
+
TokenType2["COMPARATOR"] = "COMPARATOR";
|
|
749
|
+
TokenType2["OPERATOR"] = "OPERATOR";
|
|
750
|
+
TokenType2["EOF"] = "EOF";
|
|
751
|
+
return TokenType2;
|
|
752
|
+
})(TokenType || {});
|
|
753
|
+
var SYMBOLS_STATE = /* @__PURE__ */ new Set([
|
|
754
|
+
"\u03A3",
|
|
755
|
+
// STATE - Estado global
|
|
756
|
+
"\u03C3",
|
|
757
|
+
// SUBSTATE - Estado local
|
|
758
|
+
"\xD8",
|
|
759
|
+
// VOID - Não-existência
|
|
760
|
+
"\u{1F512}",
|
|
761
|
+
// LOCK - Imutável
|
|
762
|
+
"\u{1F513}"
|
|
763
|
+
// UNLOCK - Mutável
|
|
764
|
+
]);
|
|
765
|
+
var SYMBOLS_EXEC = /* @__PURE__ */ new Set([
|
|
766
|
+
"\u0394",
|
|
767
|
+
// ACTION - Ação/função
|
|
768
|
+
"\u0192",
|
|
769
|
+
// FUNCTION - Capacidade lógica
|
|
770
|
+
"\u21C9",
|
|
771
|
+
// PARALLEL - Execução paralela
|
|
772
|
+
"\u25B3",
|
|
773
|
+
// DEPEND - Dependência
|
|
774
|
+
"\u25CF",
|
|
775
|
+
// CORE - Núcleo
|
|
776
|
+
"\u23F3"
|
|
777
|
+
// DELAY - Espera temporal
|
|
778
|
+
]);
|
|
779
|
+
var SYMBOLS_STRUCT = /* @__PURE__ */ new Set([
|
|
780
|
+
"\u03A9",
|
|
781
|
+
// OBJECT - Objeto
|
|
782
|
+
"\u25A0",
|
|
783
|
+
// OBJECT ALT - Entidade concreta
|
|
784
|
+
"\u25CB",
|
|
785
|
+
// CLASS - Classe/molde
|
|
786
|
+
"\u2B12",
|
|
787
|
+
// INHERIT - Herança
|
|
788
|
+
"\u2283",
|
|
789
|
+
// CONTAINS - Composição
|
|
790
|
+
"\u2254",
|
|
791
|
+
// ASSIGN - Atribuição
|
|
792
|
+
"\u29C9"
|
|
793
|
+
// MODULE - Módulo
|
|
794
|
+
]);
|
|
795
|
+
var SYMBOLS_TIME = /* @__PURE__ */ new Set([
|
|
796
|
+
"\u26A1",
|
|
797
|
+
// CAUSE - Causa/origem
|
|
798
|
+
"\u2726",
|
|
799
|
+
// CONSEQUENCE - Resultado
|
|
800
|
+
"\u21BB",
|
|
801
|
+
// LOOP - Repetição
|
|
802
|
+
"\u25CC",
|
|
803
|
+
// EVENT - Evento
|
|
804
|
+
"\u21C4",
|
|
805
|
+
// SYNC - Sincronização
|
|
806
|
+
"\u231B"
|
|
807
|
+
// TIMEOUT - Limite temporal
|
|
808
|
+
]);
|
|
809
|
+
var SYMBOLS_ENERGY = /* @__PURE__ */ new Set([
|
|
810
|
+
"\u03A8",
|
|
811
|
+
// ENERGY - Energia vital
|
|
812
|
+
"\u23EC",
|
|
813
|
+
// THROTTLE - Limitar
|
|
814
|
+
"\u23EB",
|
|
815
|
+
// BOOST - Acelerar
|
|
816
|
+
"\u20B5"
|
|
817
|
+
// COST - Custo
|
|
818
|
+
]);
|
|
819
|
+
var SYMBOLS_MEMORY = /* @__PURE__ */ new Set([
|
|
820
|
+
"\u{1D4DC}",
|
|
821
|
+
// MEMORY - Memória
|
|
822
|
+
"\u267E",
|
|
823
|
+
// PERSIST - Persistência
|
|
824
|
+
"\u2302"
|
|
825
|
+
// ROOT - Raiz do sistema
|
|
826
|
+
]);
|
|
827
|
+
var SYMBOLS_UI = /* @__PURE__ */ new Set([
|
|
828
|
+
"\u03A6",
|
|
829
|
+
// FORM - Form/UI
|
|
830
|
+
"\u0398",
|
|
831
|
+
// ANIMATION - Animação
|
|
832
|
+
"\u2610",
|
|
833
|
+
// INTERFACE - Interface
|
|
834
|
+
"\u{1F441}",
|
|
835
|
+
// VISUAL - Percepção visual
|
|
836
|
+
"\u2328",
|
|
837
|
+
// INPUT - Entrada
|
|
838
|
+
"\u{1F9ED}"
|
|
839
|
+
// POINTER - Ponteiro/direção
|
|
840
|
+
]);
|
|
841
|
+
var SYMBOLS_SECURITY = /* @__PURE__ */ new Set([
|
|
842
|
+
"\u{1F6E1}",
|
|
843
|
+
// SECURITY - Segurança
|
|
844
|
+
"\u{1F511}",
|
|
845
|
+
// KEY - Chave/autorização
|
|
846
|
+
"\u26A0",
|
|
847
|
+
// RISK - Risco
|
|
848
|
+
"\u26D4",
|
|
849
|
+
// BLOCK - Bloqueio
|
|
850
|
+
"\u{1F9EA}"
|
|
851
|
+
// SANDBOX - Isolamento
|
|
852
|
+
]);
|
|
853
|
+
var SYMBOLS_EVOLVE = /* @__PURE__ */ new Set([
|
|
854
|
+
"\u2301",
|
|
855
|
+
// EVOLVE BLOCK - Bloco de evolução
|
|
856
|
+
"\u27F3",
|
|
857
|
+
// EVOLVE - Evoluir
|
|
858
|
+
"\u2714",
|
|
859
|
+
// VERIFY - Verificar
|
|
860
|
+
"\u2713",
|
|
861
|
+
// VALID - Válido
|
|
862
|
+
"\u2716",
|
|
863
|
+
// INVALID - Inválido
|
|
864
|
+
"\u{1F4DC}"
|
|
865
|
+
// LOG - Registro
|
|
866
|
+
]);
|
|
867
|
+
var SYMBOLS_LOGIC = /* @__PURE__ */ new Set([
|
|
868
|
+
"\u039B",
|
|
869
|
+
// LOGIC - Lógica condicional
|
|
870
|
+
"\u2297"
|
|
871
|
+
// PARALLEL BLOCK - Bloco paralelo
|
|
872
|
+
]);
|
|
873
|
+
var SYMBOLS = /* @__PURE__ */ new Set([
|
|
874
|
+
...SYMBOLS_STATE,
|
|
875
|
+
...SYMBOLS_EXEC,
|
|
876
|
+
...SYMBOLS_STRUCT,
|
|
877
|
+
...SYMBOLS_TIME,
|
|
878
|
+
...SYMBOLS_ENERGY,
|
|
879
|
+
...SYMBOLS_MEMORY,
|
|
880
|
+
...SYMBOLS_UI,
|
|
881
|
+
...SYMBOLS_SECURITY,
|
|
882
|
+
...SYMBOLS_EVOLVE,
|
|
883
|
+
...SYMBOLS_LOGIC
|
|
884
|
+
]);
|
|
885
|
+
var SYMBOL_NAMES = {
|
|
886
|
+
"\u03A3": "STATE",
|
|
887
|
+
"\u03C3": "SUBSTATE",
|
|
888
|
+
"\xD8": "VOID",
|
|
889
|
+
"\u{1F512}": "LOCK",
|
|
890
|
+
"\u{1F513}": "UNLOCK",
|
|
891
|
+
"\u0394": "ACTION",
|
|
892
|
+
"\u0192": "FUNCTION",
|
|
893
|
+
"\u21C9": "PARALLEL",
|
|
894
|
+
"\u25B3": "DEPEND",
|
|
895
|
+
"\u25CF": "CORE",
|
|
896
|
+
"\u23F3": "DELAY",
|
|
897
|
+
"\u03A9": "OBJECT",
|
|
898
|
+
"\u25A0": "OBJECT_ALT",
|
|
899
|
+
"\u25CB": "CLASS",
|
|
900
|
+
"\u2B12": "INHERIT",
|
|
901
|
+
"\u2283": "CONTAINS",
|
|
902
|
+
"\u2254": "ASSIGN",
|
|
903
|
+
"\u29C9": "MODULE",
|
|
904
|
+
"\u26A1": "CAUSE",
|
|
905
|
+
"\u2726": "CONSEQUENCE",
|
|
906
|
+
"\u21BB": "LOOP",
|
|
907
|
+
"\u25CC": "EVENT",
|
|
908
|
+
"\u21C4": "SYNC",
|
|
909
|
+
"\u231B": "TIMEOUT",
|
|
910
|
+
"\u03A8": "ENERGY",
|
|
911
|
+
"\u23EC": "THROTTLE",
|
|
912
|
+
"\u23EB": "BOOST",
|
|
913
|
+
"\u20B5": "COST",
|
|
914
|
+
"\u{1D4DC}": "MEMORY",
|
|
915
|
+
"\u267E": "PERSIST",
|
|
916
|
+
"\u2302": "ROOT",
|
|
917
|
+
"\u03A6": "FORM",
|
|
918
|
+
"\u0398": "ANIMATION",
|
|
919
|
+
"\u2610": "INTERFACE",
|
|
920
|
+
"\u{1F441}": "VISUAL",
|
|
921
|
+
"\u2328": "INPUT",
|
|
922
|
+
"\u{1F9ED}": "POINTER",
|
|
923
|
+
"\u{1F6E1}": "SECURITY",
|
|
924
|
+
"\u{1F511}": "KEY",
|
|
925
|
+
"\u26A0": "RISK",
|
|
926
|
+
"\u26D4": "BLOCK",
|
|
927
|
+
"\u{1F9EA}": "SANDBOX",
|
|
928
|
+
"\u2301": "EVOLVE_BLOCK",
|
|
929
|
+
"\u27F3": "EVOLVE",
|
|
930
|
+
"\u2714": "VERIFY",
|
|
931
|
+
"\u2713": "VALID",
|
|
932
|
+
"\u2716": "INVALID",
|
|
933
|
+
"\u{1F4DC}": "LOG",
|
|
934
|
+
"\u039B": "LOGIC",
|
|
935
|
+
"\u2297": "PARALLEL_BLOCK"
|
|
936
|
+
};
|
|
937
|
+
var OPERATORS = /* @__PURE__ */ new Set(["+", "\u2212", "-", "\u2254"]);
|
|
34
938
|
function isWhitespace(ch) {
|
|
35
939
|
return ch === " " || ch === " " || ch === "\r";
|
|
36
940
|
}
|
|
@@ -194,217 +1098,6 @@ function tokenize(input) {
|
|
|
194
1098
|
tokens.push({ type: "EOF" /* EOF */, value: "", pos: i });
|
|
195
1099
|
return tokens;
|
|
196
1100
|
}
|
|
197
|
-
var TokenType, SYMBOLS_STATE, SYMBOLS_EXEC, SYMBOLS_STRUCT, SYMBOLS_TIME, SYMBOLS_ENERGY, SYMBOLS_MEMORY, SYMBOLS_UI, SYMBOLS_SECURITY, SYMBOLS_EVOLVE, SYMBOLS_LOGIC, SYMBOLS, SYMBOL_NAMES, OPERATORS;
|
|
198
|
-
var init_tokenize = __esm({
|
|
199
|
-
"src/lexer/tokenize.ts"() {
|
|
200
|
-
"use strict";
|
|
201
|
-
TokenType = /* @__PURE__ */ ((TokenType2) => {
|
|
202
|
-
TokenType2["SYMBOL"] = "SYMBOL";
|
|
203
|
-
TokenType2["IDENTIFIER"] = "IDENTIFIER";
|
|
204
|
-
TokenType2["STRING"] = "STRING";
|
|
205
|
-
TokenType2["NUMBER"] = "NUMBER";
|
|
206
|
-
TokenType2["ARROW"] = "ARROW";
|
|
207
|
-
TokenType2["LBRACE"] = "LBRACE";
|
|
208
|
-
TokenType2["RBRACE"] = "RBRACE";
|
|
209
|
-
TokenType2["COLON"] = "COLON";
|
|
210
|
-
TokenType2["COMMA"] = "COMMA";
|
|
211
|
-
TokenType2["LPAREN"] = "LPAREN";
|
|
212
|
-
TokenType2["RPAREN"] = "RPAREN";
|
|
213
|
-
TokenType2["LBRACKET"] = "LBRACKET";
|
|
214
|
-
TokenType2["RBRACKET"] = "RBRACKET";
|
|
215
|
-
TokenType2["NEWLINE"] = "NEWLINE";
|
|
216
|
-
TokenType2["COMPARATOR"] = "COMPARATOR";
|
|
217
|
-
TokenType2["OPERATOR"] = "OPERATOR";
|
|
218
|
-
TokenType2["EOF"] = "EOF";
|
|
219
|
-
return TokenType2;
|
|
220
|
-
})(TokenType || {});
|
|
221
|
-
SYMBOLS_STATE = /* @__PURE__ */ new Set([
|
|
222
|
-
"\u03A3",
|
|
223
|
-
// STATE - Estado global
|
|
224
|
-
"\u03C3",
|
|
225
|
-
// SUBSTATE - Estado local
|
|
226
|
-
"\xD8",
|
|
227
|
-
// VOID - Não-existência
|
|
228
|
-
"\u{1F512}",
|
|
229
|
-
// LOCK - Imutável
|
|
230
|
-
"\u{1F513}"
|
|
231
|
-
// UNLOCK - Mutável
|
|
232
|
-
]);
|
|
233
|
-
SYMBOLS_EXEC = /* @__PURE__ */ new Set([
|
|
234
|
-
"\u0394",
|
|
235
|
-
// ACTION - Ação/função
|
|
236
|
-
"\u0192",
|
|
237
|
-
// FUNCTION - Capacidade lógica
|
|
238
|
-
"\u21C9",
|
|
239
|
-
// PARALLEL - Execução paralela
|
|
240
|
-
"\u25B3",
|
|
241
|
-
// DEPEND - Dependência
|
|
242
|
-
"\u25CF",
|
|
243
|
-
// CORE - Núcleo
|
|
244
|
-
"\u23F3"
|
|
245
|
-
// DELAY - Espera temporal
|
|
246
|
-
]);
|
|
247
|
-
SYMBOLS_STRUCT = /* @__PURE__ */ new Set([
|
|
248
|
-
"\u03A9",
|
|
249
|
-
// OBJECT - Objeto
|
|
250
|
-
"\u25A0",
|
|
251
|
-
// OBJECT ALT - Entidade concreta
|
|
252
|
-
"\u25CB",
|
|
253
|
-
// CLASS - Classe/molde
|
|
254
|
-
"\u2B12",
|
|
255
|
-
// INHERIT - Herança
|
|
256
|
-
"\u2283",
|
|
257
|
-
// CONTAINS - Composição
|
|
258
|
-
"\u2254",
|
|
259
|
-
// ASSIGN - Atribuição
|
|
260
|
-
"\u29C9"
|
|
261
|
-
// MODULE - Módulo
|
|
262
|
-
]);
|
|
263
|
-
SYMBOLS_TIME = /* @__PURE__ */ new Set([
|
|
264
|
-
"\u26A1",
|
|
265
|
-
// CAUSE - Causa/origem
|
|
266
|
-
"\u2726",
|
|
267
|
-
// CONSEQUENCE - Resultado
|
|
268
|
-
"\u21BB",
|
|
269
|
-
// LOOP - Repetição
|
|
270
|
-
"\u25CC",
|
|
271
|
-
// EVENT - Evento
|
|
272
|
-
"\u21C4",
|
|
273
|
-
// SYNC - Sincronização
|
|
274
|
-
"\u231B"
|
|
275
|
-
// TIMEOUT - Limite temporal
|
|
276
|
-
]);
|
|
277
|
-
SYMBOLS_ENERGY = /* @__PURE__ */ new Set([
|
|
278
|
-
"\u03A8",
|
|
279
|
-
// ENERGY - Energia vital
|
|
280
|
-
"\u23EC",
|
|
281
|
-
// THROTTLE - Limitar
|
|
282
|
-
"\u23EB",
|
|
283
|
-
// BOOST - Acelerar
|
|
284
|
-
"\u20B5"
|
|
285
|
-
// COST - Custo
|
|
286
|
-
]);
|
|
287
|
-
SYMBOLS_MEMORY = /* @__PURE__ */ new Set([
|
|
288
|
-
"\u{1D4DC}",
|
|
289
|
-
// MEMORY - Memória
|
|
290
|
-
"\u267E",
|
|
291
|
-
// PERSIST - Persistência
|
|
292
|
-
"\u2302"
|
|
293
|
-
// ROOT - Raiz do sistema
|
|
294
|
-
]);
|
|
295
|
-
SYMBOLS_UI = /* @__PURE__ */ new Set([
|
|
296
|
-
"\u03A6",
|
|
297
|
-
// FORM - Form/UI
|
|
298
|
-
"\u0398",
|
|
299
|
-
// ANIMATION - Animação
|
|
300
|
-
"\u2610",
|
|
301
|
-
// INTERFACE - Interface
|
|
302
|
-
"\u{1F441}",
|
|
303
|
-
// VISUAL - Percepção visual
|
|
304
|
-
"\u2328",
|
|
305
|
-
// INPUT - Entrada
|
|
306
|
-
"\u{1F9ED}"
|
|
307
|
-
// POINTER - Ponteiro/direção
|
|
308
|
-
]);
|
|
309
|
-
SYMBOLS_SECURITY = /* @__PURE__ */ new Set([
|
|
310
|
-
"\u{1F6E1}",
|
|
311
|
-
// SECURITY - Segurança
|
|
312
|
-
"\u{1F511}",
|
|
313
|
-
// KEY - Chave/autorização
|
|
314
|
-
"\u26A0",
|
|
315
|
-
// RISK - Risco
|
|
316
|
-
"\u26D4",
|
|
317
|
-
// BLOCK - Bloqueio
|
|
318
|
-
"\u{1F9EA}"
|
|
319
|
-
// SANDBOX - Isolamento
|
|
320
|
-
]);
|
|
321
|
-
SYMBOLS_EVOLVE = /* @__PURE__ */ new Set([
|
|
322
|
-
"\u2301",
|
|
323
|
-
// EVOLVE BLOCK - Bloco de evolução
|
|
324
|
-
"\u27F3",
|
|
325
|
-
// EVOLVE - Evoluir
|
|
326
|
-
"\u2714",
|
|
327
|
-
// VERIFY - Verificar
|
|
328
|
-
"\u2713",
|
|
329
|
-
// VALID - Válido
|
|
330
|
-
"\u2716",
|
|
331
|
-
// INVALID - Inválido
|
|
332
|
-
"\u{1F4DC}"
|
|
333
|
-
// LOG - Registro
|
|
334
|
-
]);
|
|
335
|
-
SYMBOLS_LOGIC = /* @__PURE__ */ new Set([
|
|
336
|
-
"\u039B",
|
|
337
|
-
// LOGIC - Lógica condicional
|
|
338
|
-
"\u2297"
|
|
339
|
-
// PARALLEL BLOCK - Bloco paralelo
|
|
340
|
-
]);
|
|
341
|
-
SYMBOLS = /* @__PURE__ */ new Set([
|
|
342
|
-
...SYMBOLS_STATE,
|
|
343
|
-
...SYMBOLS_EXEC,
|
|
344
|
-
...SYMBOLS_STRUCT,
|
|
345
|
-
...SYMBOLS_TIME,
|
|
346
|
-
...SYMBOLS_ENERGY,
|
|
347
|
-
...SYMBOLS_MEMORY,
|
|
348
|
-
...SYMBOLS_UI,
|
|
349
|
-
...SYMBOLS_SECURITY,
|
|
350
|
-
...SYMBOLS_EVOLVE,
|
|
351
|
-
...SYMBOLS_LOGIC
|
|
352
|
-
]);
|
|
353
|
-
SYMBOL_NAMES = {
|
|
354
|
-
"\u03A3": "STATE",
|
|
355
|
-
"\u03C3": "SUBSTATE",
|
|
356
|
-
"\xD8": "VOID",
|
|
357
|
-
"\u{1F512}": "LOCK",
|
|
358
|
-
"\u{1F513}": "UNLOCK",
|
|
359
|
-
"\u0394": "ACTION",
|
|
360
|
-
"\u0192": "FUNCTION",
|
|
361
|
-
"\u21C9": "PARALLEL",
|
|
362
|
-
"\u25B3": "DEPEND",
|
|
363
|
-
"\u25CF": "CORE",
|
|
364
|
-
"\u23F3": "DELAY",
|
|
365
|
-
"\u03A9": "OBJECT",
|
|
366
|
-
"\u25A0": "OBJECT_ALT",
|
|
367
|
-
"\u25CB": "CLASS",
|
|
368
|
-
"\u2B12": "INHERIT",
|
|
369
|
-
"\u2283": "CONTAINS",
|
|
370
|
-
"\u2254": "ASSIGN",
|
|
371
|
-
"\u29C9": "MODULE",
|
|
372
|
-
"\u26A1": "CAUSE",
|
|
373
|
-
"\u2726": "CONSEQUENCE",
|
|
374
|
-
"\u21BB": "LOOP",
|
|
375
|
-
"\u25CC": "EVENT",
|
|
376
|
-
"\u21C4": "SYNC",
|
|
377
|
-
"\u231B": "TIMEOUT",
|
|
378
|
-
"\u03A8": "ENERGY",
|
|
379
|
-
"\u23EC": "THROTTLE",
|
|
380
|
-
"\u23EB": "BOOST",
|
|
381
|
-
"\u20B5": "COST",
|
|
382
|
-
"\u{1D4DC}": "MEMORY",
|
|
383
|
-
"\u267E": "PERSIST",
|
|
384
|
-
"\u2302": "ROOT",
|
|
385
|
-
"\u03A6": "FORM",
|
|
386
|
-
"\u0398": "ANIMATION",
|
|
387
|
-
"\u2610": "INTERFACE",
|
|
388
|
-
"\u{1F441}": "VISUAL",
|
|
389
|
-
"\u2328": "INPUT",
|
|
390
|
-
"\u{1F9ED}": "POINTER",
|
|
391
|
-
"\u{1F6E1}": "SECURITY",
|
|
392
|
-
"\u{1F511}": "KEY",
|
|
393
|
-
"\u26A0": "RISK",
|
|
394
|
-
"\u26D4": "BLOCK",
|
|
395
|
-
"\u{1F9EA}": "SANDBOX",
|
|
396
|
-
"\u2301": "EVOLVE_BLOCK",
|
|
397
|
-
"\u27F3": "EVOLVE",
|
|
398
|
-
"\u2714": "VERIFY",
|
|
399
|
-
"\u2713": "VALID",
|
|
400
|
-
"\u2716": "INVALID",
|
|
401
|
-
"\u{1F4DC}": "LOG",
|
|
402
|
-
"\u039B": "LOGIC",
|
|
403
|
-
"\u2297": "PARALLEL_BLOCK"
|
|
404
|
-
};
|
|
405
|
-
OPERATORS = /* @__PURE__ */ new Set(["+", "\u2212", "-", "\u2254"]);
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
1101
|
|
|
409
1102
|
// src/parser/ebnfParser.ts
|
|
410
1103
|
function peek(cx) {
|
|
@@ -988,10 +1681,10 @@ function parseTokens(tokens, options) {
|
|
|
988
1681
|
}
|
|
989
1682
|
if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */) next(cx);
|
|
990
1683
|
}
|
|
991
|
-
const
|
|
992
|
-
ast.substates.push(
|
|
993
|
-
ast.nodes.push(
|
|
994
|
-
onLog({ level: "info", event: "parse.substate", detail:
|
|
1684
|
+
const substate2 = { type: "substate", name, props };
|
|
1685
|
+
ast.substates.push(substate2);
|
|
1686
|
+
ast.nodes.push(substate2);
|
|
1687
|
+
onLog({ level: "info", event: "parse.substate", detail: substate2 });
|
|
995
1688
|
continue;
|
|
996
1689
|
}
|
|
997
1690
|
if (sym === "\u25CB") {
|
|
@@ -1700,19 +2393,8 @@ function parseFromCode(code, options) {
|
|
|
1700
2393
|
const tokens = tokenize(code);
|
|
1701
2394
|
return parseTokens(tokens, options);
|
|
1702
2395
|
}
|
|
1703
|
-
var init_ebnfParser = __esm({
|
|
1704
|
-
"src/parser/ebnfParser.ts"() {
|
|
1705
|
-
"use strict";
|
|
1706
|
-
init_tokenize();
|
|
1707
|
-
}
|
|
1708
|
-
});
|
|
1709
2396
|
|
|
1710
2397
|
// src/parser.ts
|
|
1711
|
-
var parser_exports = {};
|
|
1712
|
-
__export(parser_exports, {
|
|
1713
|
-
parse: () => parse,
|
|
1714
|
-
writeWithRetry: () => writeWithRetry
|
|
1715
|
-
});
|
|
1716
2398
|
async function writeWithRetry(entry, filePath, attempts = 3, delay = 1e3, onLog) {
|
|
1717
2399
|
const fsPromises = await import("fs/promises");
|
|
1718
2400
|
let attempt = 0;
|
|
@@ -1744,614 +2426,151 @@ function parse(code, options) {
|
|
|
1744
2426
|
ast.logs = ast.logs || [];
|
|
1745
2427
|
return ast;
|
|
1746
2428
|
}
|
|
1747
|
-
var init_parser = __esm({
|
|
1748
|
-
"src/parser.ts"() {
|
|
1749
|
-
"use strict";
|
|
1750
|
-
init_ebnfParser();
|
|
1751
|
-
}
|
|
1752
|
-
});
|
|
1753
2429
|
|
|
1754
|
-
// src/
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
const
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
2430
|
+
// src/semantic/validate.ts
|
|
2431
|
+
init_cjs_shims();
|
|
2432
|
+
function validateSemantic(ast, options) {
|
|
2433
|
+
const result = validateSemanticFull(ast, options);
|
|
2434
|
+
return result.errors;
|
|
2435
|
+
}
|
|
2436
|
+
function validateSemanticFull(ast, options) {
|
|
2437
|
+
const errors = [];
|
|
2438
|
+
const warnings = [];
|
|
2439
|
+
const pillars = {
|
|
2440
|
+
state: false,
|
|
2441
|
+
action: false,
|
|
2442
|
+
form: false,
|
|
2443
|
+
time: false,
|
|
2444
|
+
energy: false,
|
|
2445
|
+
memory: false,
|
|
2446
|
+
interface: false,
|
|
2447
|
+
security: false,
|
|
2448
|
+
evolve: false
|
|
2449
|
+
};
|
|
2450
|
+
const onLog = (e) => {
|
|
2451
|
+
const entry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...e };
|
|
2452
|
+
if (options?.onLog) options.onLog(entry);
|
|
2453
|
+
};
|
|
2454
|
+
ast.functions = ast.functions || [];
|
|
2455
|
+
ast.modules = ast.modules || [];
|
|
2456
|
+
ast.objects = ast.objects || [];
|
|
2457
|
+
ast.events = ast.events || [];
|
|
2458
|
+
ast.securities = ast.securities || [];
|
|
2459
|
+
ast.memories = ast.memories || [];
|
|
2460
|
+
ast.interfaces = ast.interfaces || [];
|
|
1767
2461
|
if (ast.system) {
|
|
1768
|
-
|
|
1769
|
-
|
|
2462
|
+
pillars.state = true;
|
|
2463
|
+
} else {
|
|
2464
|
+
warnings.push("No \u03A3 SYSTEM declared - consider adding a system name");
|
|
1770
2465
|
}
|
|
1771
|
-
if (ast.
|
|
1772
|
-
|
|
1773
|
-
|
|
2466
|
+
if (ast.substates?.length) {
|
|
2467
|
+
for (const sub of ast.substates) {
|
|
2468
|
+
if (sub.parent && !ast.substates.some((s) => s.name === sub.parent)) {
|
|
2469
|
+
warnings.push(`Substate '${sub.name}' references unknown parent '${sub.parent}'`);
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
1774
2472
|
}
|
|
1775
|
-
if (ast.
|
|
1776
|
-
|
|
1777
|
-
module.exports.UI = UI;`);
|
|
2473
|
+
if (ast.functions.length > 0) {
|
|
2474
|
+
pillars.action = true;
|
|
1778
2475
|
}
|
|
1779
|
-
const
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
}`;
|
|
1789
|
-
parts.push(fnCode);
|
|
1790
|
-
} else {
|
|
1791
|
-
const fnCode = `function ${fn2.name}(${args}) {
|
|
1792
|
-
${bodyLines.join("\n")}
|
|
1793
|
-
}
|
|
1794
|
-
module.exports.${fn2.name} = ${fn2.name};`;
|
|
1795
|
-
parts.push(fnCode);
|
|
1796
|
-
}
|
|
2476
|
+
const fnMap = /* @__PURE__ */ new Map();
|
|
2477
|
+
for (const fn2 of ast.functions) {
|
|
2478
|
+
fnMap.set(fn2.name, (fnMap.get(fn2.name) || 0) + 1);
|
|
2479
|
+
}
|
|
2480
|
+
for (const [name, count] of fnMap.entries()) {
|
|
2481
|
+
if (count > 1) {
|
|
2482
|
+
const msg = `Duplicate function name: ${name}`;
|
|
2483
|
+
errors.push(msg);
|
|
2484
|
+
onLog({ level: "error", event: "parse.semantic.error", detail: { error: msg } });
|
|
1797
2485
|
}
|
|
1798
2486
|
}
|
|
1799
|
-
const
|
|
1800
|
-
|
|
1801
|
-
for (const
|
|
1802
|
-
const
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
const code = `export const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
|
|
1808
|
-
${body}
|
|
1809
|
-
} };`;
|
|
1810
|
-
parts.push(code);
|
|
1811
|
-
} else {
|
|
1812
|
-
const code = `const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
|
|
1813
|
-
${body}
|
|
1814
|
-
} };
|
|
1815
|
-
module.exports.${constName} = ${constName};`;
|
|
1816
|
-
parts.push(code);
|
|
2487
|
+
const knownFns = new Set(ast.functions.map((f) => f.name));
|
|
2488
|
+
for (const fn2 of ast.functions) {
|
|
2489
|
+
for (const step of fn2.steps || []) {
|
|
2490
|
+
const token = step.raw.trim();
|
|
2491
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(token) && !knownFns.has(token)) {
|
|
2492
|
+
const msg = `Undefined function reference in '${fn2.name}': '${token}'`;
|
|
2493
|
+
errors.push(msg);
|
|
2494
|
+
onLog({ level: "warn", event: "parse.semantic.error", detail: { error: msg } });
|
|
1817
2495
|
}
|
|
1818
2496
|
}
|
|
1819
2497
|
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
for (const o of ast.objects) {
|
|
1823
|
-
objectNames.push(o.name);
|
|
1824
|
-
parts.push(isESM ? `export const ${o.name} = ${JSON.stringify(o.props, null, 2)};` : `const ${o.name} = ${JSON.stringify(o.props, null, 2)};
|
|
1825
|
-
module.exports.${o.name} = ${o.name};`);
|
|
1826
|
-
}
|
|
2498
|
+
if (ast.objects?.length || ast.classes?.length) {
|
|
2499
|
+
pillars.form = true;
|
|
1827
2500
|
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
for (const
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
module.exports.${constName} = ${constName};`);
|
|
2501
|
+
if (ast.classes?.length) {
|
|
2502
|
+
const classNames = new Set(ast.classes.map((c) => c.name));
|
|
2503
|
+
for (const cls of ast.classes) {
|
|
2504
|
+
if (cls.extends && !classNames.has(cls.extends)) {
|
|
2505
|
+
warnings.push(`Class '${cls.name}' extends unknown class '${cls.extends}'`);
|
|
2506
|
+
}
|
|
1835
2507
|
}
|
|
1836
2508
|
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
2509
|
+
if (ast.inherits?.length) {
|
|
2510
|
+
const allNames = /* @__PURE__ */ new Set([
|
|
2511
|
+
...ast.classes?.map((c) => c.name) || [],
|
|
2512
|
+
...ast.objects?.map((o) => o.name) || []
|
|
2513
|
+
]);
|
|
2514
|
+
for (const inh of ast.inherits) {
|
|
2515
|
+
if (!allNames.has(inh.parent)) {
|
|
2516
|
+
warnings.push(`Inherit: '${inh.child}' extends unknown '${inh.parent}'`);
|
|
2517
|
+
}
|
|
1844
2518
|
}
|
|
1845
2519
|
}
|
|
1846
|
-
if (ast.
|
|
1847
|
-
|
|
1848
|
-
module.exports.BUILD_TARGETS = BUILD_TARGETS;`);
|
|
1849
|
-
}
|
|
1850
|
-
if (ast.evolve) {
|
|
1851
|
-
parts.push(isESM ? `export const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};` : `const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};
|
|
1852
|
-
module.exports.EVOLVE_STEPS = EVOLVE_STEPS;`);
|
|
1853
|
-
}
|
|
1854
|
-
if (ast.database) {
|
|
1855
|
-
parts.push(isESM ? `export const DATABASE = ${JSON.stringify(ast.database)};` : `const DATABASE = ${JSON.stringify(ast.database)};
|
|
1856
|
-
module.exports.DATABASE = DATABASE;`);
|
|
1857
|
-
}
|
|
1858
|
-
if (ast.kernel) {
|
|
1859
|
-
parts.push(isESM ? `export const KERNEL = ${JSON.stringify(ast.kernel)};` : `const KERNEL = ${JSON.stringify(ast.kernel)};
|
|
1860
|
-
module.exports.KERNEL = KERNEL;`);
|
|
1861
|
-
}
|
|
1862
|
-
if (ast.training) {
|
|
1863
|
-
parts.push(isESM ? `export const TRAINING = ${JSON.stringify(ast.training)};` : `const TRAINING = ${JSON.stringify(ast.training)};
|
|
1864
|
-
module.exports.TRAINING = TRAINING;`);
|
|
1865
|
-
}
|
|
1866
|
-
if (ast.substates && ast.substates.length) {
|
|
1867
|
-
parts.push(isESM ? `export const SUBSTATES = ${JSON.stringify(ast.substates, null, 2)};` : `const SUBSTATES = ${JSON.stringify(ast.substates, null, 2)};
|
|
1868
|
-
module.exports.SUBSTATES = SUBSTATES;`);
|
|
1869
|
-
}
|
|
1870
|
-
if (ast.classes && ast.classes.length) {
|
|
1871
|
-
for (const c of ast.classes) {
|
|
1872
|
-
const className = c.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
1873
|
-
parts.push(isESM ? `export class ${className} {
|
|
1874
|
-
constructor() {
|
|
1875
|
-
Object.assign(this, ${JSON.stringify(c.props)});
|
|
1876
|
-
}
|
|
1877
|
-
${(c.methods || []).map((m) => ` ${m}() {}`).join("\n")}
|
|
1878
|
-
}` : `class ${className} {
|
|
1879
|
-
constructor() {
|
|
1880
|
-
Object.assign(this, ${JSON.stringify(c.props)});
|
|
1881
|
-
}
|
|
1882
|
-
${(c.methods || []).map((m) => ` ${m}() {}`).join("\n")}
|
|
1883
|
-
}
|
|
1884
|
-
module.exports.${className} = ${className};`);
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
if (ast.loops && ast.loops.length) {
|
|
1888
|
-
parts.push(isESM ? `export const LOOPS = ${JSON.stringify(ast.loops, null, 2)};` : `const LOOPS = ${JSON.stringify(ast.loops, null, 2)};
|
|
1889
|
-
module.exports.LOOPS = LOOPS;`);
|
|
2520
|
+
if (ast.events?.length || ast.causes?.length || ast.loops?.length) {
|
|
2521
|
+
pillars.time = true;
|
|
1890
2522
|
}
|
|
1891
|
-
if (ast.events
|
|
1892
|
-
for (const
|
|
1893
|
-
const
|
|
1894
|
-
|
|
1895
|
-
|
|
2523
|
+
if (ast.events?.length) {
|
|
2524
|
+
for (const evt of ast.events) {
|
|
2525
|
+
for (const handler of evt.handler || []) {
|
|
2526
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(handler) && !knownFns.has(handler)) {
|
|
2527
|
+
warnings.push(`Event '${evt.name}' handler '${handler}' is not a known function`);
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
1896
2530
|
}
|
|
1897
2531
|
}
|
|
1898
|
-
if (ast.
|
|
1899
|
-
|
|
1900
|
-
module.exports.SYNCS = SYNCS;`);
|
|
1901
|
-
}
|
|
1902
|
-
if (ast.timeouts && ast.timeouts.length) {
|
|
1903
|
-
parts.push(isESM ? `export const TIMEOUTS = ${JSON.stringify(ast.timeouts, null, 2)};` : `const TIMEOUTS = ${JSON.stringify(ast.timeouts, null, 2)};
|
|
1904
|
-
module.exports.TIMEOUTS = TIMEOUTS;`);
|
|
1905
|
-
}
|
|
1906
|
-
if (ast.delays && ast.delays.length) {
|
|
1907
|
-
parts.push(isESM ? `export const DELAYS = ${JSON.stringify(ast.delays, null, 2)};` : `const DELAYS = ${JSON.stringify(ast.delays, null, 2)};
|
|
1908
|
-
module.exports.DELAYS = DELAYS;`);
|
|
1909
|
-
}
|
|
1910
|
-
if (ast.securities && ast.securities.length) {
|
|
1911
|
-
parts.push(isESM ? `export const SECURITY_RULES = ${JSON.stringify(ast.securities, null, 2)};` : `const SECURITY_RULES = ${JSON.stringify(ast.securities, null, 2)};
|
|
1912
|
-
module.exports.SECURITY_RULES = SECURITY_RULES;`);
|
|
1913
|
-
}
|
|
1914
|
-
if (ast.keys && ast.keys.length) {
|
|
1915
|
-
parts.push(isESM ? `export const KEYS = ${JSON.stringify(ast.keys, null, 2)};` : `const KEYS = ${JSON.stringify(ast.keys, null, 2)};
|
|
1916
|
-
module.exports.KEYS = KEYS;`);
|
|
1917
|
-
}
|
|
1918
|
-
if (ast.sandboxes && ast.sandboxes.length) {
|
|
1919
|
-
parts.push(isESM ? `export const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};` : `const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};
|
|
1920
|
-
module.exports.SANDBOXES = SANDBOXES;`);
|
|
1921
|
-
}
|
|
1922
|
-
if (ast.causes && ast.causes.length) {
|
|
1923
|
-
parts.push(isESM ? `export const CAUSES = ${JSON.stringify(ast.causes, null, 2)};` : `const CAUSES = ${JSON.stringify(ast.causes, null, 2)};
|
|
1924
|
-
module.exports.CAUSES = CAUSES;`);
|
|
1925
|
-
}
|
|
1926
|
-
if (ast.consequences && ast.consequences.length) {
|
|
1927
|
-
parts.push(isESM ? `export const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};` : `const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};
|
|
1928
|
-
module.exports.CONSEQUENCES = CONSEQUENCES;`);
|
|
1929
|
-
}
|
|
1930
|
-
if (ast.memories && ast.memories.length) {
|
|
1931
|
-
parts.push(isESM ? `export const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};` : `const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};
|
|
1932
|
-
module.exports.MEMORIES = MEMORIES;`);
|
|
1933
|
-
}
|
|
1934
|
-
if (ast.persists && ast.persists.length) {
|
|
1935
|
-
parts.push(isESM ? `export const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};` : `const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};
|
|
1936
|
-
module.exports.PERSISTS = PERSISTS;`);
|
|
1937
|
-
}
|
|
1938
|
-
if (ast.interfaces && ast.interfaces.length) {
|
|
1939
|
-
parts.push(isESM ? `export const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};` : `const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};
|
|
1940
|
-
module.exports.INTERFACES = INTERFACES;`);
|
|
1941
|
-
}
|
|
1942
|
-
if (ast.visuals && ast.visuals.length) {
|
|
1943
|
-
parts.push(isESM ? `export const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};` : `const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};
|
|
1944
|
-
module.exports.VISUALS = VISUALS;`);
|
|
1945
|
-
}
|
|
1946
|
-
if (ast.inputs && ast.inputs.length) {
|
|
1947
|
-
parts.push(isESM ? `export const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};` : `const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};
|
|
1948
|
-
module.exports.INPUTS = INPUTS;`);
|
|
1949
|
-
}
|
|
1950
|
-
if (ast.throttles && ast.throttles.length) {
|
|
1951
|
-
parts.push(isESM ? `export const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};` : `const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};
|
|
1952
|
-
module.exports.THROTTLES = THROTTLES;`);
|
|
1953
|
-
}
|
|
1954
|
-
if (ast.boosts && ast.boosts.length) {
|
|
1955
|
-
parts.push(isESM ? `export const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};` : `const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};
|
|
1956
|
-
module.exports.BOOSTS = BOOSTS;`);
|
|
1957
|
-
}
|
|
1958
|
-
if (ast.costs && ast.costs.length) {
|
|
1959
|
-
parts.push(isESM ? `export const COSTS = ${JSON.stringify(ast.costs, null, 2)};` : `const COSTS = ${JSON.stringify(ast.costs, null, 2)};
|
|
1960
|
-
module.exports.COSTS = COSTS;`);
|
|
1961
|
-
}
|
|
1962
|
-
if (ast.locks && ast.locks.length) {
|
|
1963
|
-
parts.push(isESM ? `export const LOCKS = ${JSON.stringify(ast.locks, null, 2)};` : `const LOCKS = ${JSON.stringify(ast.locks, null, 2)};
|
|
1964
|
-
module.exports.LOCKS = LOCKS;`);
|
|
1965
|
-
}
|
|
1966
|
-
if (ast.unlocks && ast.unlocks.length) {
|
|
1967
|
-
parts.push(isESM ? `export const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};` : `const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};
|
|
1968
|
-
module.exports.UNLOCKS = UNLOCKS;`);
|
|
1969
|
-
}
|
|
1970
|
-
if (ast.voids && ast.voids.length) {
|
|
1971
|
-
parts.push(isESM ? `export const VOIDS = ${JSON.stringify(ast.voids, null, 2)};` : `const VOIDS = ${JSON.stringify(ast.voids, null, 2)};
|
|
1972
|
-
module.exports.VOIDS = VOIDS;`);
|
|
1973
|
-
}
|
|
1974
|
-
if (ast.inherits && ast.inherits.length) {
|
|
1975
|
-
parts.push(isESM ? `export const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};` : `const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};
|
|
1976
|
-
module.exports.INHERITS = INHERITS;`);
|
|
1977
|
-
}
|
|
1978
|
-
if (ast.contains && ast.contains.length) {
|
|
1979
|
-
parts.push(isESM ? `export const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};` : `const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};
|
|
1980
|
-
module.exports.CONTAINS = CONTAINS;`);
|
|
1981
|
-
}
|
|
1982
|
-
if (ast.verifies && ast.verifies.length) {
|
|
1983
|
-
parts.push(isESM ? `export const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};` : `const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};
|
|
1984
|
-
module.exports.VERIFIES = VERIFIES;`);
|
|
1985
|
-
}
|
|
1986
|
-
if (ast.logNodes && ast.logNodes.length) {
|
|
1987
|
-
parts.push(isESM ? `export const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};` : `const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};
|
|
1988
|
-
module.exports.LOG_NODES = LOG_NODES;`);
|
|
1989
|
-
}
|
|
1990
|
-
if (isESM) {
|
|
1991
|
-
parts.push("\nexport default { SYSTEM, MODE, UI };");
|
|
1992
|
-
} else {
|
|
1993
|
-
parts.push("\nmodule.exports.default = { SYSTEM, MODE, UI };");
|
|
1994
|
-
}
|
|
1995
|
-
return parts.join("\n\n");
|
|
1996
|
-
}
|
|
1997
|
-
function transpileToDTS(ast) {
|
|
1998
|
-
const lines = [];
|
|
1999
|
-
lines.push("// Type declarations generated by enyosx-ai");
|
|
2000
|
-
lines.push("");
|
|
2001
|
-
if (ast.system) {
|
|
2002
|
-
lines.push(`export declare const SYSTEM: string;`);
|
|
2003
|
-
}
|
|
2004
|
-
if (ast.mode) {
|
|
2005
|
-
lines.push(`export declare const MODE: string;`);
|
|
2006
|
-
}
|
|
2007
|
-
if (ast.ui) {
|
|
2008
|
-
lines.push(`export declare const UI: string;`);
|
|
2532
|
+
if (ast.throttles?.length || ast.boosts?.length || ast.costs?.length) {
|
|
2533
|
+
pillars.energy = true;
|
|
2009
2534
|
}
|
|
2010
|
-
if (ast.
|
|
2011
|
-
for (const
|
|
2012
|
-
|
|
2013
|
-
|
|
2535
|
+
if (ast.throttles?.length) {
|
|
2536
|
+
for (const t of ast.throttles) {
|
|
2537
|
+
if (t.limit <= 0) {
|
|
2538
|
+
errors.push(`Throttle '${t.target}' has invalid limit: ${t.limit}`);
|
|
2539
|
+
}
|
|
2014
2540
|
}
|
|
2015
2541
|
}
|
|
2016
|
-
if (ast.
|
|
2017
|
-
|
|
2018
|
-
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2019
|
-
lines.push(`export declare const IA_${name}: { name: string; run: () => void };`);
|
|
2020
|
-
}
|
|
2542
|
+
if (ast.memories?.length || ast.persists?.length || ast.database) {
|
|
2543
|
+
pillars.memory = true;
|
|
2021
2544
|
}
|
|
2022
|
-
if (ast.
|
|
2023
|
-
|
|
2024
|
-
const propTypes = Object.keys(o.props).map((k) => `${k}: string | null`).join("; ");
|
|
2025
|
-
lines.push(`export declare const ${o.name}: { ${propTypes} };`);
|
|
2026
|
-
}
|
|
2545
|
+
if (ast.forms?.length || ast.inputs?.length || ast.visuals?.length || ast.interfaces?.length) {
|
|
2546
|
+
pillars.interface = true;
|
|
2027
2547
|
}
|
|
2028
|
-
if (ast.
|
|
2029
|
-
|
|
2030
|
-
lines.push(`export declare const FORM_${f.name}: Record<string, any>;`);
|
|
2031
|
-
}
|
|
2548
|
+
if (ast.securities?.length || ast.keys?.length || ast.sandboxes?.length) {
|
|
2549
|
+
pillars.security = true;
|
|
2032
2550
|
}
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2551
|
+
const validSecurityLevels = ["low", "medium", "high", "critical"];
|
|
2552
|
+
if (ast.securities?.length) {
|
|
2553
|
+
for (const sec of ast.securities) {
|
|
2554
|
+
if (sec.level && !validSecurityLevels.includes(sec.level.toLowerCase())) {
|
|
2555
|
+
warnings.push(`Security rule has unknown level '${sec.level}' (use: low, medium, high, critical)`);
|
|
2556
|
+
}
|
|
2037
2557
|
}
|
|
2038
2558
|
}
|
|
2039
|
-
if (ast.
|
|
2040
|
-
|
|
2041
|
-
}
|
|
2042
|
-
if (ast.evolve) {
|
|
2043
|
-
lines.push(`export declare const EVOLVE_STEPS: string[];`);
|
|
2559
|
+
if (ast.evolve?.steps?.length) {
|
|
2560
|
+
pillars.evolve = true;
|
|
2044
2561
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2562
|
+
const activePillars = Object.values(pillars).filter(Boolean).length;
|
|
2563
|
+
const score = Math.round(activePillars / 9 * 100);
|
|
2564
|
+
ast.errors = errors;
|
|
2565
|
+
if (errors.length > 0) console.debug("[semantic] errors", errors);
|
|
2566
|
+
return { errors, warnings, pillars, score };
|
|
2049
2567
|
}
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
lines.push(` ;; System: ${ast.system || "unnamed"}`);
|
|
2057
|
-
lines.push(` ;; Mode: ${ast.mode || "default"}`);
|
|
2058
|
-
lines.push("");
|
|
2059
|
-
lines.push(" ;; Memory declaration");
|
|
2060
|
-
lines.push(' (memory (export "memory") 1)');
|
|
2061
|
-
lines.push("");
|
|
2062
|
-
if (ast.system) {
|
|
2063
|
-
const bytes = Array.from(new TextEncoder().encode(ast.system)).join(" ");
|
|
2064
|
-
lines.push(` ;; System name data`);
|
|
2065
|
-
lines.push(` (data (i32.const 0) "${ast.system}")`);
|
|
2066
|
-
lines.push("");
|
|
2067
|
-
}
|
|
2068
|
-
if (ast.functions && ast.functions.length) {
|
|
2069
|
-
lines.push(" ;; Function stubs");
|
|
2070
|
-
for (const fn2 of ast.functions) {
|
|
2071
|
-
const params = (fn2.args || []).map((_, i) => `(param $arg${i} i32)`).join(" ");
|
|
2072
|
-
lines.push(` (func (export "${fn2.name}") ${params} (result i32)`);
|
|
2073
|
-
lines.push(` ;; Steps: ${(fn2.steps || []).map((s) => s.raw).join(" -> ")}`);
|
|
2074
|
-
lines.push(` i32.const 0 ;; placeholder return`);
|
|
2075
|
-
lines.push(` )`);
|
|
2076
|
-
lines.push("");
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
if (ast.ias && ast.ias.length) {
|
|
2080
|
-
lines.push(" ;; IA stubs (table references for future indirect calls)");
|
|
2081
|
-
for (const ia of ast.ias) {
|
|
2082
|
-
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2083
|
-
lines.push(` ;; IA: ${ia.name}`);
|
|
2084
|
-
lines.push(` (func (export "ia_${name}") (result i32)`);
|
|
2085
|
-
lines.push(` ;; Capabilities: ${ia.body.join(", ")}`);
|
|
2086
|
-
lines.push(` i32.const 1 ;; stub: IA ready`);
|
|
2087
|
-
lines.push(` )`);
|
|
2088
|
-
lines.push("");
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
lines.push(" ;; Main entry point");
|
|
2092
|
-
lines.push(' (func (export "_start")');
|
|
2093
|
-
lines.push(" ;; Initialize system");
|
|
2094
|
-
lines.push(" nop");
|
|
2095
|
-
lines.push(" )");
|
|
2096
|
-
lines.push("");
|
|
2097
|
-
if (ast.build && ast.build.targets) {
|
|
2098
|
-
lines.push(` ;; Build targets: ${ast.build.targets.join(", ")}`);
|
|
2099
|
-
}
|
|
2100
|
-
lines.push(")");
|
|
2101
|
-
lines.push("");
|
|
2102
|
-
lines.push(";; To compile this WAT to WASM:");
|
|
2103
|
-
lines.push(";; wat2wasm output.wat -o output.wasm");
|
|
2104
|
-
lines.push(";; Or use wasm-pack for Rust-based compilation");
|
|
2105
|
-
return lines.join("\n");
|
|
2106
|
-
}
|
|
2107
|
-
function hasWASMTarget(ast) {
|
|
2108
|
-
if (!ast.build || !ast.build.targets) return false;
|
|
2109
|
-
return ast.build.targets.some(
|
|
2110
|
-
(t) => t.toLowerCase() === "wasm" || t.toLowerCase() === "webassembly" || t.toLowerCase() === "wat"
|
|
2111
|
-
);
|
|
2112
|
-
}
|
|
2113
|
-
var init_transpile = __esm({
|
|
2114
|
-
"src/transpile.ts"() {
|
|
2115
|
-
"use strict";
|
|
2116
|
-
}
|
|
2117
|
-
});
|
|
2118
|
-
|
|
2119
|
-
// src/index.ts
|
|
2120
|
-
var index_exports = {};
|
|
2121
|
-
__export(index_exports, {
|
|
2122
|
-
ALPHABET: () => ALPHABET,
|
|
2123
|
-
EVOLVE: () => EVOLVE,
|
|
2124
|
-
FALSE: () => FALSE,
|
|
2125
|
-
FALSE_VAL: () => FALSE_VAL,
|
|
2126
|
-
FUNCTION: () => FUNCTION,
|
|
2127
|
-
IAManager: () => IAManager,
|
|
2128
|
-
INTERFACE: () => INTERFACE,
|
|
2129
|
-
LocalIA: () => LocalIA,
|
|
2130
|
-
NAME: () => NAME,
|
|
2131
|
-
NIL: () => NIL,
|
|
2132
|
-
OBJECT: () => OBJECT,
|
|
2133
|
-
RemoteIA: () => RemoteIA,
|
|
2134
|
-
SHIELD: () => SHIELD,
|
|
2135
|
-
STATE: () => STATE,
|
|
2136
|
-
SUBSTATE: () => SUBSTATE,
|
|
2137
|
-
SYMBOLS: () => SYMBOLS2,
|
|
2138
|
-
SYMBOL_NAMES: () => SYMBOL_NAMES,
|
|
2139
|
-
TRANSPILE_MAP: () => TRANSPILE_MAP,
|
|
2140
|
-
TRUE: () => TRUE,
|
|
2141
|
-
TRUE_VAL: () => TRUE_VAL,
|
|
2142
|
-
TokenType: () => TokenType,
|
|
2143
|
-
VERSION: () => VERSION,
|
|
2144
|
-
VOID: () => VOID,
|
|
2145
|
-
VOID_VAL: () => VOID_VAL,
|
|
2146
|
-
applyEvolve: () => applyEvolve,
|
|
2147
|
-
asyncFn: () => asyncFn,
|
|
2148
|
-
compile: () => compile,
|
|
2149
|
-
component: () => component,
|
|
2150
|
-
createBoost: () => createBoost,
|
|
2151
|
-
createClass: () => createClass,
|
|
2152
|
-
createEvent: () => createEvent,
|
|
2153
|
-
createEvolve: () => createEvolve,
|
|
2154
|
-
createFunction: () => createFunction,
|
|
2155
|
-
createInput: () => createInput,
|
|
2156
|
-
createKey: () => createKey,
|
|
2157
|
-
createLoop: () => createLoop,
|
|
2158
|
-
createMemory: () => createMemory,
|
|
2159
|
-
createObject: () => createObject,
|
|
2160
|
-
createPersist: () => createPersist,
|
|
2161
|
-
createSecurity: () => createSecurity,
|
|
2162
|
-
createSystem: () => createSystem,
|
|
2163
|
-
createThrottle: () => createThrottle,
|
|
2164
|
-
createVisual: () => createVisual,
|
|
2165
|
-
defaultIAManager: () => defaultIAManager,
|
|
2166
|
-
effect: () => effect,
|
|
2167
|
-
error: () => error,
|
|
2168
|
-
filter: () => filter,
|
|
2169
|
-
find: () => find,
|
|
2170
|
-
fn: () => fn,
|
|
2171
|
-
generateENY: () => generateENY,
|
|
2172
|
-
get: () => get,
|
|
2173
|
-
getEnergy: () => getEnergy,
|
|
2174
|
-
getEvolve: () => getEvolve,
|
|
2175
|
-
getFunctions: () => getFunctions,
|
|
2176
|
-
getInterface: () => getInterface,
|
|
2177
|
-
getMemory: () => getMemory,
|
|
2178
|
-
getSecurity: () => getSecurity,
|
|
2179
|
-
getState: () => getState,
|
|
2180
|
-
getStructures: () => getStructures,
|
|
2181
|
-
getTemporals: () => getTemporals,
|
|
2182
|
-
hasWASMTarget: () => hasWASMTarget,
|
|
2183
|
-
isValidENY: () => isValidENY,
|
|
2184
|
-
log: () => log,
|
|
2185
|
-
map: () => map,
|
|
2186
|
-
navigate: () => navigate,
|
|
2187
|
-
parse: () => parse,
|
|
2188
|
-
post: () => post,
|
|
2189
|
-
processIA: () => processIA,
|
|
2190
|
-
quickSystem: () => quickSystem,
|
|
2191
|
-
reduce: () => reduce,
|
|
2192
|
-
runENY: () => runENY,
|
|
2193
|
-
shape: () => shape,
|
|
2194
|
-
state: () => state,
|
|
2195
|
-
storageGet: () => storageGet,
|
|
2196
|
-
storageSet: () => storageSet,
|
|
2197
|
-
toSymbolic: () => toSymbolic,
|
|
2198
|
-
tokenize: () => tokenize,
|
|
2199
|
-
transpileSymbols: () => transpileSymbols,
|
|
2200
|
-
transpileToDTS: () => transpileToDTS,
|
|
2201
|
-
transpileToJS: () => transpileToJS,
|
|
2202
|
-
transpileToWAT: () => transpileToWAT,
|
|
2203
|
-
validate: () => validate,
|
|
2204
|
-
validateSemantic: () => validateSemantic,
|
|
2205
|
-
validateSemanticFull: () => validateSemanticFull
|
|
2206
|
-
});
|
|
2207
|
-
module.exports = __toCommonJS(index_exports);
|
|
2208
|
-
|
|
2209
|
-
// src/runENY.ts
|
|
2210
|
-
init_parser();
|
|
2211
|
-
init_parser();
|
|
2212
|
-
|
|
2213
|
-
// src/semantic/validate.ts
|
|
2214
|
-
function validateSemantic(ast, options) {
|
|
2215
|
-
const result = validateSemanticFull(ast, options);
|
|
2216
|
-
return result.errors;
|
|
2217
|
-
}
|
|
2218
|
-
function validateSemanticFull(ast, options) {
|
|
2219
|
-
const errors = [];
|
|
2220
|
-
const warnings = [];
|
|
2221
|
-
const pillars = {
|
|
2222
|
-
state: false,
|
|
2223
|
-
action: false,
|
|
2224
|
-
form: false,
|
|
2225
|
-
time: false,
|
|
2226
|
-
energy: false,
|
|
2227
|
-
memory: false,
|
|
2228
|
-
interface: false,
|
|
2229
|
-
security: false,
|
|
2230
|
-
evolve: false
|
|
2231
|
-
};
|
|
2232
|
-
const onLog = (e) => {
|
|
2233
|
-
const entry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...e };
|
|
2234
|
-
if (options?.onLog) options.onLog(entry);
|
|
2235
|
-
};
|
|
2236
|
-
ast.functions = ast.functions || [];
|
|
2237
|
-
ast.modules = ast.modules || [];
|
|
2238
|
-
ast.objects = ast.objects || [];
|
|
2239
|
-
ast.events = ast.events || [];
|
|
2240
|
-
ast.securities = ast.securities || [];
|
|
2241
|
-
ast.memories = ast.memories || [];
|
|
2242
|
-
ast.interfaces = ast.interfaces || [];
|
|
2243
|
-
if (ast.system) {
|
|
2244
|
-
pillars.state = true;
|
|
2245
|
-
} else {
|
|
2246
|
-
warnings.push("No \u03A3 SYSTEM declared - consider adding a system name");
|
|
2247
|
-
}
|
|
2248
|
-
if (ast.substates?.length) {
|
|
2249
|
-
for (const sub of ast.substates) {
|
|
2250
|
-
if (sub.parent && !ast.substates.some((s) => s.name === sub.parent)) {
|
|
2251
|
-
warnings.push(`Substate '${sub.name}' references unknown parent '${sub.parent}'`);
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
}
|
|
2255
|
-
if (ast.functions.length > 0) {
|
|
2256
|
-
pillars.action = true;
|
|
2257
|
-
}
|
|
2258
|
-
const fnMap = /* @__PURE__ */ new Map();
|
|
2259
|
-
for (const fn2 of ast.functions) {
|
|
2260
|
-
fnMap.set(fn2.name, (fnMap.get(fn2.name) || 0) + 1);
|
|
2261
|
-
}
|
|
2262
|
-
for (const [name, count] of fnMap.entries()) {
|
|
2263
|
-
if (count > 1) {
|
|
2264
|
-
const msg = `Duplicate function name: ${name}`;
|
|
2265
|
-
errors.push(msg);
|
|
2266
|
-
onLog({ level: "error", event: "parse.semantic.error", detail: { error: msg } });
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
const knownFns = new Set(ast.functions.map((f) => f.name));
|
|
2270
|
-
for (const fn2 of ast.functions) {
|
|
2271
|
-
for (const step of fn2.steps || []) {
|
|
2272
|
-
const token = step.raw.trim();
|
|
2273
|
-
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(token) && !knownFns.has(token)) {
|
|
2274
|
-
const msg = `Undefined function reference in '${fn2.name}': '${token}'`;
|
|
2275
|
-
errors.push(msg);
|
|
2276
|
-
onLog({ level: "warn", event: "parse.semantic.error", detail: { error: msg } });
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
if (ast.objects?.length || ast.classes?.length) {
|
|
2281
|
-
pillars.form = true;
|
|
2282
|
-
}
|
|
2283
|
-
if (ast.classes?.length) {
|
|
2284
|
-
const classNames = new Set(ast.classes.map((c) => c.name));
|
|
2285
|
-
for (const cls of ast.classes) {
|
|
2286
|
-
if (cls.extends && !classNames.has(cls.extends)) {
|
|
2287
|
-
warnings.push(`Class '${cls.name}' extends unknown class '${cls.extends}'`);
|
|
2288
|
-
}
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
if (ast.inherits?.length) {
|
|
2292
|
-
const allNames = /* @__PURE__ */ new Set([
|
|
2293
|
-
...ast.classes?.map((c) => c.name) || [],
|
|
2294
|
-
...ast.objects?.map((o) => o.name) || []
|
|
2295
|
-
]);
|
|
2296
|
-
for (const inh of ast.inherits) {
|
|
2297
|
-
if (!allNames.has(inh.parent)) {
|
|
2298
|
-
warnings.push(`Inherit: '${inh.child}' extends unknown '${inh.parent}'`);
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
if (ast.events?.length || ast.causes?.length || ast.loops?.length) {
|
|
2303
|
-
pillars.time = true;
|
|
2304
|
-
}
|
|
2305
|
-
if (ast.events?.length) {
|
|
2306
|
-
for (const evt of ast.events) {
|
|
2307
|
-
for (const handler of evt.handler || []) {
|
|
2308
|
-
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(handler) && !knownFns.has(handler)) {
|
|
2309
|
-
warnings.push(`Event '${evt.name}' handler '${handler}' is not a known function`);
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
if (ast.throttles?.length || ast.boosts?.length || ast.costs?.length) {
|
|
2315
|
-
pillars.energy = true;
|
|
2316
|
-
}
|
|
2317
|
-
if (ast.throttles?.length) {
|
|
2318
|
-
for (const t of ast.throttles) {
|
|
2319
|
-
if (t.limit <= 0) {
|
|
2320
|
-
errors.push(`Throttle '${t.target}' has invalid limit: ${t.limit}`);
|
|
2321
|
-
}
|
|
2322
|
-
}
|
|
2323
|
-
}
|
|
2324
|
-
if (ast.memories?.length || ast.persists?.length || ast.database) {
|
|
2325
|
-
pillars.memory = true;
|
|
2326
|
-
}
|
|
2327
|
-
if (ast.forms?.length || ast.inputs?.length || ast.visuals?.length || ast.interfaces?.length) {
|
|
2328
|
-
pillars.interface = true;
|
|
2329
|
-
}
|
|
2330
|
-
if (ast.securities?.length || ast.keys?.length || ast.sandboxes?.length) {
|
|
2331
|
-
pillars.security = true;
|
|
2332
|
-
}
|
|
2333
|
-
const validSecurityLevels = ["low", "medium", "high", "critical"];
|
|
2334
|
-
if (ast.securities?.length) {
|
|
2335
|
-
for (const sec of ast.securities) {
|
|
2336
|
-
if (sec.level && !validSecurityLevels.includes(sec.level.toLowerCase())) {
|
|
2337
|
-
warnings.push(`Security rule has unknown level '${sec.level}' (use: low, medium, high, critical)`);
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
}
|
|
2341
|
-
if (ast.evolve?.steps?.length) {
|
|
2342
|
-
pillars.evolve = true;
|
|
2343
|
-
}
|
|
2344
|
-
const activePillars = Object.values(pillars).filter(Boolean).length;
|
|
2345
|
-
const score = Math.round(activePillars / 9 * 100);
|
|
2346
|
-
ast.errors = errors;
|
|
2347
|
-
if (errors.length > 0) console.debug("[semantic] errors", errors);
|
|
2348
|
-
return { errors, warnings, pillars, score };
|
|
2349
|
-
}
|
|
2350
|
-
|
|
2351
|
-
// src/evolve/stub.ts
|
|
2352
|
-
function applyEvolve(ast, options) {
|
|
2353
|
-
if (!ast.evolve || !ast.evolve.steps || ast.evolve.steps.length === 0) {
|
|
2354
|
-
return { changed: false, appliedSteps: [], skippedSteps: [] };
|
|
2568
|
+
|
|
2569
|
+
// src/evolve/stub.ts
|
|
2570
|
+
init_cjs_shims();
|
|
2571
|
+
function applyEvolve(ast, options) {
|
|
2572
|
+
if (!ast.evolve || !ast.evolve.steps || ast.evolve.steps.length === 0) {
|
|
2573
|
+
return { changed: false, appliedSteps: [], skippedSteps: [] };
|
|
2355
2574
|
}
|
|
2356
2575
|
const onLog = options?.onLog;
|
|
2357
2576
|
const steps = ast.evolve.steps;
|
|
@@ -2514,72 +2733,425 @@ function applyEvolve(ast, options) {
|
|
|
2514
2733
|
}
|
|
2515
2734
|
break;
|
|
2516
2735
|
}
|
|
2517
|
-
if (applied) {
|
|
2518
|
-
changed = true;
|
|
2519
|
-
appliedSteps.push(step);
|
|
2520
|
-
} else {
|
|
2521
|
-
skippedSteps.push(step);
|
|
2736
|
+
if (applied) {
|
|
2737
|
+
changed = true;
|
|
2738
|
+
appliedSteps.push(step);
|
|
2739
|
+
} else {
|
|
2740
|
+
skippedSteps.push(step);
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
if (changed && onLog) {
|
|
2744
|
+
onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.summary", detail: { appliedSteps, skippedSteps } });
|
|
2745
|
+
}
|
|
2746
|
+
return { changed, appliedSteps, skippedSteps };
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
// src/runENY.ts
|
|
2750
|
+
function runENY(code, options) {
|
|
2751
|
+
const hasSystem = /Σ\s+SYSTEM/i.test(code);
|
|
2752
|
+
if (!hasSystem) {
|
|
2753
|
+
if (options?.onLog) {
|
|
2754
|
+
options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } });
|
|
2755
|
+
}
|
|
2756
|
+
if (options?.logFile) {
|
|
2757
|
+
const attempts = options?.logRetryAttempts ?? 3;
|
|
2758
|
+
const delay = options?.logRetryDelayMs ?? 1e3;
|
|
2759
|
+
writeWithRetry({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } }, options.logFile, attempts, delay, options?.onLog);
|
|
2760
|
+
}
|
|
2761
|
+
return { raw: code, isEny: false, logs: [] };
|
|
2762
|
+
}
|
|
2763
|
+
const userOnLog = options?.onLog;
|
|
2764
|
+
let wrappedOnLog = userOnLog;
|
|
2765
|
+
if (options?.logFile) {
|
|
2766
|
+
const attempts = options?.logRetryAttempts ?? 3;
|
|
2767
|
+
const delay = options?.logRetryDelayMs ?? 1e3;
|
|
2768
|
+
wrappedOnLog = (e) => {
|
|
2769
|
+
if (userOnLog) userOnLog(e);
|
|
2770
|
+
writeWithRetry(e, options.logFile, attempts, delay, userOnLog);
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
const ast = parse(code, { ...options, onLog: wrappedOnLog });
|
|
2774
|
+
try {
|
|
2775
|
+
const errors = validateSemantic(ast, { onLog: wrappedOnLog });
|
|
2776
|
+
if (errors && errors.length > 0) {
|
|
2777
|
+
if (options?.onLog) options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "parse.semantic.summary", detail: { count: errors.length } });
|
|
2778
|
+
}
|
|
2779
|
+
} catch (err) {
|
|
2780
|
+
if (wrappedOnLog) wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.semantic.failed", detail: { error: String(err) } });
|
|
2781
|
+
}
|
|
2782
|
+
if (ast.evolve && ast.evolve.steps && ast.evolve.steps.length > 0) {
|
|
2783
|
+
try {
|
|
2784
|
+
const evolveResult = applyEvolve(ast, { onLog: wrappedOnLog });
|
|
2785
|
+
if (evolveResult.changed && wrappedOnLog) {
|
|
2786
|
+
wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "parse.evolve.summary", detail: { changed: true, stepsApplied: ast.evolve.steps.length } });
|
|
2787
|
+
}
|
|
2788
|
+
} catch (err) {
|
|
2789
|
+
if (wrappedOnLog) wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.evolve.failed", detail: { error: String(err) } });
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
ast.isEny = true;
|
|
2793
|
+
return ast;
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
// src/types.ts
|
|
2797
|
+
init_cjs_shims();
|
|
2798
|
+
|
|
2799
|
+
// src/transpile.ts
|
|
2800
|
+
init_cjs_shims();
|
|
2801
|
+
function transpileToJS(ast, options) {
|
|
2802
|
+
const parts = [];
|
|
2803
|
+
const format = options?.moduleFormat || "esm";
|
|
2804
|
+
const isESM = format === "esm";
|
|
2805
|
+
parts.push("// Generated by enyosx-ai (transpiler)");
|
|
2806
|
+
if (ast.system) {
|
|
2807
|
+
parts.push(isESM ? `export const SYSTEM = ${JSON.stringify(ast.system)};` : `const SYSTEM = ${JSON.stringify(ast.system)};
|
|
2808
|
+
module.exports.SYSTEM = SYSTEM;`);
|
|
2809
|
+
}
|
|
2810
|
+
if (ast.mode) {
|
|
2811
|
+
parts.push(isESM ? `export const MODE = ${JSON.stringify(ast.mode)};` : `const MODE = ${JSON.stringify(ast.mode)};
|
|
2812
|
+
module.exports.MODE = MODE;`);
|
|
2813
|
+
}
|
|
2814
|
+
if (ast.ui) {
|
|
2815
|
+
parts.push(isESM ? `export const UI = ${JSON.stringify(ast.ui)};` : `const UI = ${JSON.stringify(ast.ui)};
|
|
2816
|
+
module.exports.UI = UI;`);
|
|
2817
|
+
}
|
|
2818
|
+
const functionNames = [];
|
|
2819
|
+
if (ast.functions && ast.functions.length) {
|
|
2820
|
+
for (const fn2 of ast.functions) {
|
|
2821
|
+
const args = (fn2.args || []).join(", ");
|
|
2822
|
+
const bodyLines = (fn2.steps || []).map((s) => ` // ${s.raw}`);
|
|
2823
|
+
functionNames.push(fn2.name);
|
|
2824
|
+
if (isESM) {
|
|
2825
|
+
const fnCode = `export function ${fn2.name}(${args}) {
|
|
2826
|
+
${bodyLines.join("\n")}
|
|
2827
|
+
}`;
|
|
2828
|
+
parts.push(fnCode);
|
|
2829
|
+
} else {
|
|
2830
|
+
const fnCode = `function ${fn2.name}(${args}) {
|
|
2831
|
+
${bodyLines.join("\n")}
|
|
2832
|
+
}
|
|
2833
|
+
module.exports.${fn2.name} = ${fn2.name};`;
|
|
2834
|
+
parts.push(fnCode);
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
const iaNames = [];
|
|
2839
|
+
if (ast.ias && ast.ias.length) {
|
|
2840
|
+
for (const ia of ast.ias) {
|
|
2841
|
+
const body = ia.body.map((b) => ` // ${b}`).join("\n");
|
|
2842
|
+
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2843
|
+
const constName = `IA_${name}`;
|
|
2844
|
+
iaNames.push(constName);
|
|
2845
|
+
if (isESM) {
|
|
2846
|
+
const code = `export const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
|
|
2847
|
+
${body}
|
|
2848
|
+
} };`;
|
|
2849
|
+
parts.push(code);
|
|
2850
|
+
} else {
|
|
2851
|
+
const code = `const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
|
|
2852
|
+
${body}
|
|
2853
|
+
} };
|
|
2854
|
+
module.exports.${constName} = ${constName};`;
|
|
2855
|
+
parts.push(code);
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
const objectNames = [];
|
|
2860
|
+
if (ast.objects && ast.objects.length) {
|
|
2861
|
+
for (const o of ast.objects) {
|
|
2862
|
+
objectNames.push(o.name);
|
|
2863
|
+
parts.push(isESM ? `export const ${o.name} = ${JSON.stringify(o.props, null, 2)};` : `const ${o.name} = ${JSON.stringify(o.props, null, 2)};
|
|
2864
|
+
module.exports.${o.name} = ${o.name};`);
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
const formNames = [];
|
|
2868
|
+
if (ast.forms && ast.forms.length) {
|
|
2869
|
+
for (const f of ast.forms) {
|
|
2870
|
+
const constName = `FORM_${f.name}`;
|
|
2871
|
+
formNames.push(constName);
|
|
2872
|
+
parts.push(isESM ? `export const ${constName} = ${JSON.stringify(f.props, null, 2)};` : `const ${constName} = ${JSON.stringify(f.props, null, 2)};
|
|
2873
|
+
module.exports.${constName} = ${constName};`);
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
const animNames = [];
|
|
2877
|
+
if (ast.animations && ast.animations.length) {
|
|
2878
|
+
for (const a of ast.animations) {
|
|
2879
|
+
const constName = `ANIMATION_${a.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
2880
|
+
animNames.push(constName);
|
|
2881
|
+
parts.push(isESM ? `export const ${constName} = ${JSON.stringify(a.props, null, 2)};` : `const ${constName} = ${JSON.stringify(a.props, null, 2)};
|
|
2882
|
+
module.exports.${constName} = ${constName};`);
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
if (ast.build) {
|
|
2886
|
+
parts.push(isESM ? `export const BUILD_TARGETS = ${JSON.stringify(ast.build.targets || [])};` : `const BUILD_TARGETS = ${JSON.stringify(ast.build.targets || [])};
|
|
2887
|
+
module.exports.BUILD_TARGETS = BUILD_TARGETS;`);
|
|
2888
|
+
}
|
|
2889
|
+
if (ast.evolve) {
|
|
2890
|
+
parts.push(isESM ? `export const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};` : `const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};
|
|
2891
|
+
module.exports.EVOLVE_STEPS = EVOLVE_STEPS;`);
|
|
2892
|
+
}
|
|
2893
|
+
if (ast.database) {
|
|
2894
|
+
parts.push(isESM ? `export const DATABASE = ${JSON.stringify(ast.database)};` : `const DATABASE = ${JSON.stringify(ast.database)};
|
|
2895
|
+
module.exports.DATABASE = DATABASE;`);
|
|
2896
|
+
}
|
|
2897
|
+
if (ast.kernel) {
|
|
2898
|
+
parts.push(isESM ? `export const KERNEL = ${JSON.stringify(ast.kernel)};` : `const KERNEL = ${JSON.stringify(ast.kernel)};
|
|
2899
|
+
module.exports.KERNEL = KERNEL;`);
|
|
2900
|
+
}
|
|
2901
|
+
if (ast.training) {
|
|
2902
|
+
parts.push(isESM ? `export const TRAINING = ${JSON.stringify(ast.training)};` : `const TRAINING = ${JSON.stringify(ast.training)};
|
|
2903
|
+
module.exports.TRAINING = TRAINING;`);
|
|
2904
|
+
}
|
|
2905
|
+
if (ast.substates && ast.substates.length) {
|
|
2906
|
+
parts.push(isESM ? `export const SUBSTATES = ${JSON.stringify(ast.substates, null, 2)};` : `const SUBSTATES = ${JSON.stringify(ast.substates, null, 2)};
|
|
2907
|
+
module.exports.SUBSTATES = SUBSTATES;`);
|
|
2908
|
+
}
|
|
2909
|
+
if (ast.classes && ast.classes.length) {
|
|
2910
|
+
for (const c of ast.classes) {
|
|
2911
|
+
const className = c.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
2912
|
+
parts.push(isESM ? `export class ${className} {
|
|
2913
|
+
constructor() {
|
|
2914
|
+
Object.assign(this, ${JSON.stringify(c.props)});
|
|
2915
|
+
}
|
|
2916
|
+
${(c.methods || []).map((m) => ` ${m}() {}`).join("\n")}
|
|
2917
|
+
}` : `class ${className} {
|
|
2918
|
+
constructor() {
|
|
2919
|
+
Object.assign(this, ${JSON.stringify(c.props)});
|
|
2920
|
+
}
|
|
2921
|
+
${(c.methods || []).map((m) => ` ${m}() {}`).join("\n")}
|
|
2922
|
+
}
|
|
2923
|
+
module.exports.${className} = ${className};`);
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
if (ast.loops && ast.loops.length) {
|
|
2927
|
+
parts.push(isESM ? `export const LOOPS = ${JSON.stringify(ast.loops, null, 2)};` : `const LOOPS = ${JSON.stringify(ast.loops, null, 2)};
|
|
2928
|
+
module.exports.LOOPS = LOOPS;`);
|
|
2929
|
+
}
|
|
2930
|
+
if (ast.events && ast.events.length) {
|
|
2931
|
+
for (const e of ast.events) {
|
|
2932
|
+
const eventName = `EVENT_${e.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
2933
|
+
parts.push(isESM ? `export const ${eventName} = { name: ${JSON.stringify(e.name)}, handler: ${JSON.stringify(e.handler || [])} };` : `const ${eventName} = { name: ${JSON.stringify(e.name)}, handler: ${JSON.stringify(e.handler || [])} };
|
|
2934
|
+
module.exports.${eventName} = ${eventName};`);
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
if (ast.syncs && ast.syncs.length) {
|
|
2938
|
+
parts.push(isESM ? `export const SYNCS = ${JSON.stringify(ast.syncs, null, 2)};` : `const SYNCS = ${JSON.stringify(ast.syncs, null, 2)};
|
|
2939
|
+
module.exports.SYNCS = SYNCS;`);
|
|
2940
|
+
}
|
|
2941
|
+
if (ast.timeouts && ast.timeouts.length) {
|
|
2942
|
+
parts.push(isESM ? `export const TIMEOUTS = ${JSON.stringify(ast.timeouts, null, 2)};` : `const TIMEOUTS = ${JSON.stringify(ast.timeouts, null, 2)};
|
|
2943
|
+
module.exports.TIMEOUTS = TIMEOUTS;`);
|
|
2944
|
+
}
|
|
2945
|
+
if (ast.delays && ast.delays.length) {
|
|
2946
|
+
parts.push(isESM ? `export const DELAYS = ${JSON.stringify(ast.delays, null, 2)};` : `const DELAYS = ${JSON.stringify(ast.delays, null, 2)};
|
|
2947
|
+
module.exports.DELAYS = DELAYS;`);
|
|
2948
|
+
}
|
|
2949
|
+
if (ast.securities && ast.securities.length) {
|
|
2950
|
+
parts.push(isESM ? `export const SECURITY_RULES = ${JSON.stringify(ast.securities, null, 2)};` : `const SECURITY_RULES = ${JSON.stringify(ast.securities, null, 2)};
|
|
2951
|
+
module.exports.SECURITY_RULES = SECURITY_RULES;`);
|
|
2952
|
+
}
|
|
2953
|
+
if (ast.keys && ast.keys.length) {
|
|
2954
|
+
parts.push(isESM ? `export const KEYS = ${JSON.stringify(ast.keys, null, 2)};` : `const KEYS = ${JSON.stringify(ast.keys, null, 2)};
|
|
2955
|
+
module.exports.KEYS = KEYS;`);
|
|
2956
|
+
}
|
|
2957
|
+
if (ast.sandboxes && ast.sandboxes.length) {
|
|
2958
|
+
parts.push(isESM ? `export const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};` : `const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};
|
|
2959
|
+
module.exports.SANDBOXES = SANDBOXES;`);
|
|
2960
|
+
}
|
|
2961
|
+
if (ast.causes && ast.causes.length) {
|
|
2962
|
+
parts.push(isESM ? `export const CAUSES = ${JSON.stringify(ast.causes, null, 2)};` : `const CAUSES = ${JSON.stringify(ast.causes, null, 2)};
|
|
2963
|
+
module.exports.CAUSES = CAUSES;`);
|
|
2964
|
+
}
|
|
2965
|
+
if (ast.consequences && ast.consequences.length) {
|
|
2966
|
+
parts.push(isESM ? `export const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};` : `const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};
|
|
2967
|
+
module.exports.CONSEQUENCES = CONSEQUENCES;`);
|
|
2968
|
+
}
|
|
2969
|
+
if (ast.memories && ast.memories.length) {
|
|
2970
|
+
parts.push(isESM ? `export const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};` : `const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};
|
|
2971
|
+
module.exports.MEMORIES = MEMORIES;`);
|
|
2972
|
+
}
|
|
2973
|
+
if (ast.persists && ast.persists.length) {
|
|
2974
|
+
parts.push(isESM ? `export const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};` : `const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};
|
|
2975
|
+
module.exports.PERSISTS = PERSISTS;`);
|
|
2976
|
+
}
|
|
2977
|
+
if (ast.interfaces && ast.interfaces.length) {
|
|
2978
|
+
parts.push(isESM ? `export const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};` : `const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};
|
|
2979
|
+
module.exports.INTERFACES = INTERFACES;`);
|
|
2980
|
+
}
|
|
2981
|
+
if (ast.visuals && ast.visuals.length) {
|
|
2982
|
+
parts.push(isESM ? `export const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};` : `const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};
|
|
2983
|
+
module.exports.VISUALS = VISUALS;`);
|
|
2984
|
+
}
|
|
2985
|
+
if (ast.inputs && ast.inputs.length) {
|
|
2986
|
+
parts.push(isESM ? `export const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};` : `const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};
|
|
2987
|
+
module.exports.INPUTS = INPUTS;`);
|
|
2988
|
+
}
|
|
2989
|
+
if (ast.throttles && ast.throttles.length) {
|
|
2990
|
+
parts.push(isESM ? `export const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};` : `const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};
|
|
2991
|
+
module.exports.THROTTLES = THROTTLES;`);
|
|
2992
|
+
}
|
|
2993
|
+
if (ast.boosts && ast.boosts.length) {
|
|
2994
|
+
parts.push(isESM ? `export const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};` : `const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};
|
|
2995
|
+
module.exports.BOOSTS = BOOSTS;`);
|
|
2996
|
+
}
|
|
2997
|
+
if (ast.costs && ast.costs.length) {
|
|
2998
|
+
parts.push(isESM ? `export const COSTS = ${JSON.stringify(ast.costs, null, 2)};` : `const COSTS = ${JSON.stringify(ast.costs, null, 2)};
|
|
2999
|
+
module.exports.COSTS = COSTS;`);
|
|
3000
|
+
}
|
|
3001
|
+
if (ast.locks && ast.locks.length) {
|
|
3002
|
+
parts.push(isESM ? `export const LOCKS = ${JSON.stringify(ast.locks, null, 2)};` : `const LOCKS = ${JSON.stringify(ast.locks, null, 2)};
|
|
3003
|
+
module.exports.LOCKS = LOCKS;`);
|
|
3004
|
+
}
|
|
3005
|
+
if (ast.unlocks && ast.unlocks.length) {
|
|
3006
|
+
parts.push(isESM ? `export const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};` : `const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};
|
|
3007
|
+
module.exports.UNLOCKS = UNLOCKS;`);
|
|
3008
|
+
}
|
|
3009
|
+
if (ast.voids && ast.voids.length) {
|
|
3010
|
+
parts.push(isESM ? `export const VOIDS = ${JSON.stringify(ast.voids, null, 2)};` : `const VOIDS = ${JSON.stringify(ast.voids, null, 2)};
|
|
3011
|
+
module.exports.VOIDS = VOIDS;`);
|
|
3012
|
+
}
|
|
3013
|
+
if (ast.inherits && ast.inherits.length) {
|
|
3014
|
+
parts.push(isESM ? `export const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};` : `const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};
|
|
3015
|
+
module.exports.INHERITS = INHERITS;`);
|
|
3016
|
+
}
|
|
3017
|
+
if (ast.contains && ast.contains.length) {
|
|
3018
|
+
parts.push(isESM ? `export const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};` : `const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};
|
|
3019
|
+
module.exports.CONTAINS = CONTAINS;`);
|
|
3020
|
+
}
|
|
3021
|
+
if (ast.verifies && ast.verifies.length) {
|
|
3022
|
+
parts.push(isESM ? `export const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};` : `const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};
|
|
3023
|
+
module.exports.VERIFIES = VERIFIES;`);
|
|
3024
|
+
}
|
|
3025
|
+
if (ast.logNodes && ast.logNodes.length) {
|
|
3026
|
+
parts.push(isESM ? `export const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};` : `const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};
|
|
3027
|
+
module.exports.LOG_NODES = LOG_NODES;`);
|
|
3028
|
+
}
|
|
3029
|
+
if (isESM) {
|
|
3030
|
+
parts.push("\nexport default { SYSTEM, MODE, UI };");
|
|
3031
|
+
} else {
|
|
3032
|
+
parts.push("\nmodule.exports.default = { SYSTEM, MODE, UI };");
|
|
3033
|
+
}
|
|
3034
|
+
return parts.join("\n\n");
|
|
3035
|
+
}
|
|
3036
|
+
function transpileToDTS(ast) {
|
|
3037
|
+
const lines = [];
|
|
3038
|
+
lines.push("// Type declarations generated by enyosx-ai");
|
|
3039
|
+
lines.push("");
|
|
3040
|
+
if (ast.system) {
|
|
3041
|
+
lines.push(`export declare const SYSTEM: string;`);
|
|
3042
|
+
}
|
|
3043
|
+
if (ast.mode) {
|
|
3044
|
+
lines.push(`export declare const MODE: string;`);
|
|
3045
|
+
}
|
|
3046
|
+
if (ast.ui) {
|
|
3047
|
+
lines.push(`export declare const UI: string;`);
|
|
3048
|
+
}
|
|
3049
|
+
if (ast.functions && ast.functions.length) {
|
|
3050
|
+
for (const fn2 of ast.functions) {
|
|
3051
|
+
const args = (fn2.args || []).map((a) => `${a}: any`).join(", ");
|
|
3052
|
+
lines.push(`export declare function ${fn2.name}(${args}): void;`);
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
if (ast.ias && ast.ias.length) {
|
|
3056
|
+
for (const ia of ast.ias) {
|
|
3057
|
+
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
3058
|
+
lines.push(`export declare const IA_${name}: { name: string; run: () => void };`);
|
|
2522
3059
|
}
|
|
2523
3060
|
}
|
|
2524
|
-
if (
|
|
2525
|
-
|
|
3061
|
+
if (ast.objects && ast.objects.length) {
|
|
3062
|
+
for (const o of ast.objects) {
|
|
3063
|
+
const propTypes = Object.keys(o.props).map((k) => `${k}: string | null`).join("; ");
|
|
3064
|
+
lines.push(`export declare const ${o.name}: { ${propTypes} };`);
|
|
3065
|
+
}
|
|
2526
3066
|
}
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
// src/runENY.ts
|
|
2531
|
-
function runENY(code, options) {
|
|
2532
|
-
const hasSystem = /Σ\s+SYSTEM/i.test(code);
|
|
2533
|
-
if (!hasSystem) {
|
|
2534
|
-
if (options?.onLog) {
|
|
2535
|
-
options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } });
|
|
3067
|
+
if (ast.forms && ast.forms.length) {
|
|
3068
|
+
for (const f of ast.forms) {
|
|
3069
|
+
lines.push(`export declare const FORM_${f.name}: Record<string, any>;`);
|
|
2536
3070
|
}
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
3071
|
+
}
|
|
3072
|
+
if (ast.animations && ast.animations.length) {
|
|
3073
|
+
for (const a of ast.animations) {
|
|
3074
|
+
const constName = `ANIMATION_${a.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
3075
|
+
lines.push(`export declare const ${constName}: Record<string, any>;`);
|
|
2541
3076
|
}
|
|
2542
|
-
return { raw: code, isEny: false, logs: [] };
|
|
2543
3077
|
}
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
if (options?.logFile) {
|
|
2547
|
-
const attempts = options?.logRetryAttempts ?? 3;
|
|
2548
|
-
const delay = options?.logRetryDelayMs ?? 1e3;
|
|
2549
|
-
wrappedOnLog = (e) => {
|
|
2550
|
-
if (userOnLog) userOnLog(e);
|
|
2551
|
-
writeWithRetry(e, options.logFile, attempts, delay, userOnLog);
|
|
2552
|
-
};
|
|
3078
|
+
if (ast.build) {
|
|
3079
|
+
lines.push(`export declare const BUILD_TARGETS: string[];`);
|
|
2553
3080
|
}
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
3081
|
+
if (ast.evolve) {
|
|
3082
|
+
lines.push(`export declare const EVOLVE_STEPS: string[];`);
|
|
3083
|
+
}
|
|
3084
|
+
lines.push("");
|
|
3085
|
+
lines.push("declare const _default: { SYSTEM: string; MODE: string; UI: string };");
|
|
3086
|
+
lines.push("export default _default;");
|
|
3087
|
+
return lines.join("\n");
|
|
3088
|
+
}
|
|
3089
|
+
function transpileToWAT(ast) {
|
|
3090
|
+
const lines = [];
|
|
3091
|
+
lines.push(";; WebAssembly Text Format generated by enyosx-ai");
|
|
3092
|
+
lines.push(";; This is a stub for future WASM compilation");
|
|
3093
|
+
lines.push("");
|
|
3094
|
+
lines.push("(module");
|
|
3095
|
+
lines.push(` ;; System: ${ast.system || "unnamed"}`);
|
|
3096
|
+
lines.push(` ;; Mode: ${ast.mode || "default"}`);
|
|
3097
|
+
lines.push("");
|
|
3098
|
+
lines.push(" ;; Memory declaration");
|
|
3099
|
+
lines.push(' (memory (export "memory") 1)');
|
|
3100
|
+
lines.push("");
|
|
3101
|
+
if (ast.system) {
|
|
3102
|
+
const bytes = Array.from(new TextEncoder().encode(ast.system)).join(" ");
|
|
3103
|
+
lines.push(` ;; System name data`);
|
|
3104
|
+
lines.push(` (data (i32.const 0) "${ast.system}")`);
|
|
3105
|
+
lines.push("");
|
|
3106
|
+
}
|
|
3107
|
+
if (ast.functions && ast.functions.length) {
|
|
3108
|
+
lines.push(" ;; Function stubs");
|
|
3109
|
+
for (const fn2 of ast.functions) {
|
|
3110
|
+
const params = (fn2.args || []).map((_, i) => `(param $arg${i} i32)`).join(" ");
|
|
3111
|
+
lines.push(` (func (export "${fn2.name}") ${params} (result i32)`);
|
|
3112
|
+
lines.push(` ;; Steps: ${(fn2.steps || []).map((s) => s.raw).join(" -> ")}`);
|
|
3113
|
+
lines.push(` i32.const 0 ;; placeholder return`);
|
|
3114
|
+
lines.push(` )`);
|
|
3115
|
+
lines.push("");
|
|
2559
3116
|
}
|
|
2560
|
-
} catch (err) {
|
|
2561
|
-
if (wrappedOnLog) wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.semantic.failed", detail: { error: String(err) } });
|
|
2562
3117
|
}
|
|
2563
|
-
if (ast.
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
}
|
|
2569
|
-
|
|
2570
|
-
|
|
3118
|
+
if (ast.ias && ast.ias.length) {
|
|
3119
|
+
lines.push(" ;; IA stubs (table references for future indirect calls)");
|
|
3120
|
+
for (const ia of ast.ias) {
|
|
3121
|
+
const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
3122
|
+
lines.push(` ;; IA: ${ia.name}`);
|
|
3123
|
+
lines.push(` (func (export "ia_${name}") (result i32)`);
|
|
3124
|
+
lines.push(` ;; Capabilities: ${ia.body.join(", ")}`);
|
|
3125
|
+
lines.push(` i32.const 1 ;; stub: IA ready`);
|
|
3126
|
+
lines.push(` )`);
|
|
3127
|
+
lines.push("");
|
|
2571
3128
|
}
|
|
2572
3129
|
}
|
|
2573
|
-
|
|
2574
|
-
|
|
3130
|
+
lines.push(" ;; Main entry point");
|
|
3131
|
+
lines.push(' (func (export "_start")');
|
|
3132
|
+
lines.push(" ;; Initialize system");
|
|
3133
|
+
lines.push(" nop");
|
|
3134
|
+
lines.push(" )");
|
|
3135
|
+
lines.push("");
|
|
3136
|
+
if (ast.build && ast.build.targets) {
|
|
3137
|
+
lines.push(` ;; Build targets: ${ast.build.targets.join(", ")}`);
|
|
3138
|
+
}
|
|
3139
|
+
lines.push(")");
|
|
3140
|
+
lines.push("");
|
|
3141
|
+
lines.push(";; To compile this WAT to WASM:");
|
|
3142
|
+
lines.push(";; wat2wasm output.wat -o output.wasm");
|
|
3143
|
+
lines.push(";; Or use wasm-pack for Rust-based compilation");
|
|
3144
|
+
return lines.join("\n");
|
|
3145
|
+
}
|
|
3146
|
+
function hasWASMTarget(ast) {
|
|
3147
|
+
if (!ast.build || !ast.build.targets) return false;
|
|
3148
|
+
return ast.build.targets.some(
|
|
3149
|
+
(t) => t.toLowerCase() === "wasm" || t.toLowerCase() === "webassembly" || t.toLowerCase() === "wat"
|
|
3150
|
+
);
|
|
2575
3151
|
}
|
|
2576
|
-
|
|
2577
|
-
// src/index.ts
|
|
2578
|
-
init_parser();
|
|
2579
|
-
init_tokenize();
|
|
2580
|
-
init_transpile();
|
|
2581
3152
|
|
|
2582
3153
|
// src/ia/index.ts
|
|
3154
|
+
init_cjs_shims();
|
|
2583
3155
|
var LocalIA = class {
|
|
2584
3156
|
constructor() {
|
|
2585
3157
|
this.name = "LocalIA";
|
|
@@ -2717,6 +3289,7 @@ async function processIA(ia, context, provider) {
|
|
|
2717
3289
|
}
|
|
2718
3290
|
|
|
2719
3291
|
// src/symbols.ts
|
|
3292
|
+
init_cjs_shims();
|
|
2720
3293
|
var TRUE = true;
|
|
2721
3294
|
var FALSE = false;
|
|
2722
3295
|
var VOID = null;
|
|
@@ -2931,292 +3504,236 @@ var ALPHABET = {
|
|
|
2931
3504
|
INTERVAL: { symbol: "\u21BB", js: "setInterval", desc: "Intervalo" }
|
|
2932
3505
|
};
|
|
2933
3506
|
|
|
2934
|
-
// src/
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
return lines.join("\n");
|
|
2945
|
-
}
|
|
2946
|
-
function getState(ast) {
|
|
2947
|
-
return {
|
|
2948
|
-
system: ast.system,
|
|
2949
|
-
mode: ast.mode,
|
|
2950
|
-
ui: ast.ui,
|
|
2951
|
-
version: ast.version,
|
|
2952
|
-
isEny: ast.isEny,
|
|
2953
|
-
substates: ast.substates || []
|
|
2954
|
-
};
|
|
2955
|
-
}
|
|
2956
|
-
function createFunction(name, args, steps) {
|
|
2957
|
-
const argsStr = args.length ? `(${args.join(", ")})` : "";
|
|
2958
|
-
const stepsStr = steps.map((s) => ` \u2192 ${s}`).join("\n");
|
|
2959
|
-
return `\u0394 function ${name}${argsStr}
|
|
2960
|
-
${stepsStr}`;
|
|
2961
|
-
}
|
|
2962
|
-
function getFunctions(ast) {
|
|
2963
|
-
return ast.functions || [];
|
|
2964
|
-
}
|
|
2965
|
-
function createObject(name, props) {
|
|
2966
|
-
const propsStr = Object.entries(props).map(([k, v]) => ` ${k}: ${JSON.stringify(v)}`).join("\n");
|
|
2967
|
-
return `\u03A9 ${name} {
|
|
2968
|
-
${propsStr}
|
|
2969
|
-
}`;
|
|
2970
|
-
}
|
|
2971
|
-
function createClass(name, props, methods = [], extendsClass) {
|
|
2972
|
-
const extendsStr = extendsClass ? ` \u2192 ${extendsClass}` : "";
|
|
2973
|
-
const propsStr = Object.entries(props).map(([k, v]) => ` ${k}: ${typeof v}`).join("\n");
|
|
2974
|
-
const methodsStr = methods.map((m) => ` ${m}()`).join("\n");
|
|
2975
|
-
return `\u25CB ${name}${extendsStr} {
|
|
2976
|
-
${propsStr}
|
|
2977
|
-
${methodsStr}
|
|
2978
|
-
}`;
|
|
2979
|
-
}
|
|
2980
|
-
function getStructures(ast) {
|
|
2981
|
-
return {
|
|
2982
|
-
objects: ast.objects || [],
|
|
2983
|
-
classes: ast.classes || [],
|
|
2984
|
-
modules: ast.modules || []
|
|
2985
|
-
};
|
|
2986
|
-
}
|
|
2987
|
-
function createEvent(name, handlers) {
|
|
2988
|
-
const handlersStr = handlers.map((h) => ` \u2192 ${h}`).join("\n");
|
|
2989
|
-
return `\u25CC ${name}
|
|
2990
|
-
${handlersStr}`;
|
|
2991
|
-
}
|
|
2992
|
-
function createLoop(count, body) {
|
|
2993
|
-
const bodyStr = body.map((b) => ` ${b}`).join("\n");
|
|
2994
|
-
return `\u21BB ${count} {
|
|
2995
|
-
${bodyStr}
|
|
2996
|
-
}`;
|
|
2997
|
-
}
|
|
2998
|
-
function getTemporals(ast) {
|
|
2999
|
-
return {
|
|
3000
|
-
events: ast.events || [],
|
|
3001
|
-
loops: ast.loops || [],
|
|
3002
|
-
causes: ast.causes || [],
|
|
3003
|
-
timeouts: ast.timeouts || [],
|
|
3004
|
-
delays: ast.delays || [],
|
|
3005
|
-
syncs: ast.syncs || []
|
|
3006
|
-
};
|
|
3007
|
-
}
|
|
3008
|
-
function createThrottle(target, limit) {
|
|
3009
|
-
return `\u23EC ${target} ${limit}`;
|
|
3010
|
-
}
|
|
3011
|
-
function createBoost(target, factor) {
|
|
3012
|
-
return `\u23EB ${target} ${factor}`;
|
|
3507
|
+
// src/index.ts
|
|
3508
|
+
init_runtime();
|
|
3509
|
+
|
|
3510
|
+
// src/react/hooks.tsx
|
|
3511
|
+
init_cjs_shims();
|
|
3512
|
+
var import_react = __toESM(require("react"), 1);
|
|
3513
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
3514
|
+
function useEnyState(initialValue) {
|
|
3515
|
+
const [value, setValue] = (0, import_react.useState)(initialValue);
|
|
3516
|
+
return [value, setValue];
|
|
3013
3517
|
}
|
|
3014
|
-
function
|
|
3015
|
-
|
|
3016
|
-
throttles: ast.throttles || [],
|
|
3017
|
-
boosts: ast.boosts || [],
|
|
3018
|
-
costs: ast.costs || []
|
|
3019
|
-
};
|
|
3518
|
+
function useEnyEffect(effect2, deps) {
|
|
3519
|
+
(0, import_react.useEffect)(effect2, deps);
|
|
3020
3520
|
}
|
|
3021
|
-
function
|
|
3022
|
-
|
|
3521
|
+
function useEnyFetch(url) {
|
|
3522
|
+
const [data, setData] = (0, import_react.useState)(null);
|
|
3523
|
+
const [loading, setLoading] = (0, import_react.useState)(true);
|
|
3524
|
+
const [error2, setError] = (0, import_react.useState)(null);
|
|
3525
|
+
(0, import_react.useEffect)(() => {
|
|
3526
|
+
fetch(url).then((res) => res.json()).then((data2) => {
|
|
3527
|
+
setData(data2);
|
|
3528
|
+
setLoading(false);
|
|
3529
|
+
}).catch((err) => {
|
|
3530
|
+
setError(err);
|
|
3531
|
+
setLoading(false);
|
|
3532
|
+
});
|
|
3533
|
+
}, [url]);
|
|
3534
|
+
return [data, loading, error2];
|
|
3023
3535
|
}
|
|
3024
|
-
function
|
|
3025
|
-
|
|
3536
|
+
function usePersistentState(key, initialValue) {
|
|
3537
|
+
const [value, setValue] = (0, import_react.useState)(() => {
|
|
3538
|
+
const stored = localStorage.getItem(key);
|
|
3539
|
+
return stored ? JSON.parse(stored) : initialValue;
|
|
3540
|
+
});
|
|
3541
|
+
const setPersistentValue = (0, import_react.useCallback)((newValue) => {
|
|
3542
|
+
setValue(newValue);
|
|
3543
|
+
localStorage.setItem(key, JSON.stringify(newValue));
|
|
3544
|
+
}, [key]);
|
|
3545
|
+
return [value, setPersistentValue];
|
|
3026
3546
|
}
|
|
3027
|
-
function
|
|
3028
|
-
return
|
|
3029
|
-
database: ast.database,
|
|
3030
|
-
memories: ast.memories || [],
|
|
3031
|
-
persists: ast.persists || []
|
|
3032
|
-
};
|
|
3547
|
+
function useMemoWithDeps(fn2, deps) {
|
|
3548
|
+
return (0, import_react.useMemo)(fn2, deps);
|
|
3033
3549
|
}
|
|
3034
|
-
function
|
|
3035
|
-
return
|
|
3550
|
+
function useCallbackWithDeps(fn2, deps) {
|
|
3551
|
+
return (0, import_react.useCallback)(fn2, deps);
|
|
3036
3552
|
}
|
|
3037
|
-
function
|
|
3038
|
-
|
|
3039
|
-
return `\u{1F441} ${name} {
|
|
3040
|
-
${propsStr}
|
|
3041
|
-
}`;
|
|
3553
|
+
function useReducerWithState(reducer, initialState) {
|
|
3554
|
+
return (0, import_react.useReducer)(reducer, initialState);
|
|
3042
3555
|
}
|
|
3043
|
-
function
|
|
3556
|
+
function useNavigation() {
|
|
3044
3557
|
return {
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3558
|
+
navigate: (path) => window.location.href = path,
|
|
3559
|
+
back: () => window.history.back(),
|
|
3560
|
+
forward: () => window.history.forward(),
|
|
3561
|
+
reload: () => window.location.reload()
|
|
3049
3562
|
};
|
|
3050
3563
|
}
|
|
3051
|
-
function
|
|
3052
|
-
const rulesStr = rules.map((r) => ` ${r}`).join("\n");
|
|
3053
|
-
return `\u{1F6E1} ${level} {
|
|
3054
|
-
${rulesStr}
|
|
3055
|
-
}`;
|
|
3056
|
-
}
|
|
3057
|
-
function createKey(name, permissions) {
|
|
3058
|
-
const permsStr = permissions.map((p) => ` ${p}`).join("\n");
|
|
3059
|
-
return `\u{1F511} ${name} {
|
|
3060
|
-
${permsStr}
|
|
3061
|
-
}`;
|
|
3062
|
-
}
|
|
3063
|
-
function getSecurity(ast) {
|
|
3564
|
+
function useLogger() {
|
|
3064
3565
|
return {
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
locks: ast.locks || [],
|
|
3069
|
-
unlocks: ast.unlocks || []
|
|
3566
|
+
info: (msg, data) => console.log(`\u2139\uFE0F ${msg}`, data),
|
|
3567
|
+
error: (msg, data) => console.error(`\u274C ${msg}`, data),
|
|
3568
|
+
warn: (msg, data) => console.warn(`\u26A0\uFE0F ${msg}`, data)
|
|
3070
3569
|
};
|
|
3071
3570
|
}
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
}
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3571
|
+
var EnyUI = {
|
|
3572
|
+
/**
|
|
3573
|
+
* EnyUI.card - Card component
|
|
3574
|
+
*/
|
|
3575
|
+
card: ({ children, className = "" }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `bg-white rounded-lg shadow-lg p-6 ${className}`, children }),
|
|
3576
|
+
/**
|
|
3577
|
+
* EnyUI.btn - Button component
|
|
3578
|
+
*/
|
|
3579
|
+
btn: ({
|
|
3580
|
+
children,
|
|
3581
|
+
onClick,
|
|
3582
|
+
type = "primary",
|
|
3583
|
+
className = ""
|
|
3584
|
+
}) => {
|
|
3585
|
+
const baseClass = "px-4 py-2 rounded-lg font-bold transition";
|
|
3586
|
+
const typeClass = {
|
|
3587
|
+
primary: "bg-blue-600 text-white hover:bg-blue-700",
|
|
3588
|
+
danger: "bg-red-600 text-white hover:bg-red-700",
|
|
3589
|
+
secondary: "bg-gray-300 text-black hover:bg-gray-400"
|
|
3590
|
+
}[type];
|
|
3591
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: `${baseClass} ${typeClass} ${className}`, onClick, children });
|
|
3592
|
+
},
|
|
3593
|
+
/**
|
|
3594
|
+
* EnyUI.input - Input component
|
|
3595
|
+
*/
|
|
3596
|
+
input: ({
|
|
3597
|
+
value,
|
|
3598
|
+
onChange,
|
|
3599
|
+
placeholder = "",
|
|
3600
|
+
type = "text",
|
|
3601
|
+
className = ""
|
|
3602
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3603
|
+
"input",
|
|
3604
|
+
{
|
|
3605
|
+
type,
|
|
3606
|
+
value,
|
|
3607
|
+
onChange: (e) => onChange(e.target.value),
|
|
3608
|
+
placeholder,
|
|
3609
|
+
className: `w-full px-4 py-2 border rounded-lg focus:outline-none focus:border-blue-600 ${className}`
|
|
3610
|
+
}
|
|
3611
|
+
),
|
|
3612
|
+
/**
|
|
3613
|
+
* EnyUI.grid - Grid component
|
|
3614
|
+
*/
|
|
3615
|
+
grid: ({ children, cols = 1, className = "" }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `grid grid-cols-${cols} gap-4 ${className}`, children }),
|
|
3616
|
+
/**
|
|
3617
|
+
* EnyUI.flex - Flexbox component
|
|
3618
|
+
*/
|
|
3619
|
+
flex: ({ children, className = "" }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `flex ${className}`, children }),
|
|
3620
|
+
/**
|
|
3621
|
+
* EnyUI.text - Text component
|
|
3622
|
+
*/
|
|
3623
|
+
text: ({ children, size = "base", className = "" }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: `text-${size} ${className}`, children }),
|
|
3624
|
+
/**
|
|
3625
|
+
* EnyUI.heading - Heading component
|
|
3626
|
+
*/
|
|
3627
|
+
h1: ({ children, className = "" }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { className: `text-4xl font-bold ${className}`, children }),
|
|
3628
|
+
h2: ({ children, className = "" }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: `text-3xl font-bold ${className}`, children }),
|
|
3629
|
+
h3: ({ children, className = "" }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { className: `text-2xl font-bold ${className}`, children }),
|
|
3630
|
+
/**
|
|
3631
|
+
* EnyUI.modal - Modal component
|
|
3632
|
+
*/
|
|
3633
|
+
modal: ({
|
|
3634
|
+
isOpen,
|
|
3635
|
+
onClose,
|
|
3636
|
+
children,
|
|
3637
|
+
title = ""
|
|
3638
|
+
}) => {
|
|
3639
|
+
if (!isOpen) return null;
|
|
3640
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "bg-white rounded-lg p-8 max-w-md w-full", children: [
|
|
3641
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "text-2xl font-bold mb-4", children: title }),
|
|
3642
|
+
children,
|
|
3643
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3644
|
+
"button",
|
|
3645
|
+
{
|
|
3646
|
+
onClick: onClose,
|
|
3647
|
+
className: "mt-4 w-full bg-gray-300 text-black py-2 rounded-lg hover:bg-gray-400",
|
|
3648
|
+
children: "Fechar"
|
|
3649
|
+
}
|
|
3650
|
+
)
|
|
3651
|
+
] }) });
|
|
3652
|
+
},
|
|
3653
|
+
/**
|
|
3654
|
+
* EnyUI.spinner - Loading spinner
|
|
3655
|
+
*/
|
|
3656
|
+
spinner: ({ className = "" } = {}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `animate-spin inline-block w-6 h-6 border-4 border-blue-600 border-t-transparent rounded-full ${className}` }),
|
|
3657
|
+
/**
|
|
3658
|
+
* EnyUI.badge - Badge component
|
|
3659
|
+
*/
|
|
3660
|
+
badge: ({ children, color = "blue", className = "" }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `px-3 py-1 rounded-full text-white bg-${color}-600 ${className}`, children })
|
|
3661
|
+
};
|
|
3662
|
+
var EnyContext = {
|
|
3663
|
+
create: (initialValue) => import_react.default.createContext(initialValue),
|
|
3664
|
+
use: (context) => (0, import_react.useContext)(context)
|
|
3665
|
+
};
|
|
3666
|
+
var EnyValidate = {
|
|
3667
|
+
email: (str) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(str),
|
|
3668
|
+
min: (len) => (str) => str.length >= len,
|
|
3669
|
+
max: (len) => (str) => str.length <= len,
|
|
3670
|
+
required: (val) => val != null && val !== "",
|
|
3671
|
+
pattern: (regex) => (val) => regex.test(val),
|
|
3672
|
+
equals: (expected) => (val) => val === expected
|
|
3673
|
+
};
|
|
3674
|
+
function useValidation(schema) {
|
|
3675
|
+
return (data) => {
|
|
3676
|
+
const errors = {};
|
|
3677
|
+
for (const [key, validator] of Object.entries(schema)) {
|
|
3678
|
+
if (!validator(data[key])) {
|
|
3679
|
+
errors[key] = true;
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
return errors;
|
|
3083
3683
|
};
|
|
3084
3684
|
}
|
|
3085
|
-
function generateENY(config) {
|
|
3086
|
-
const parts = [];
|
|
3087
|
-
parts.push(`\u03A3 SYSTEM "${config.system.name}"`);
|
|
3088
|
-
if (config.system.mode) parts.push(`\u03A3 MODE ${config.system.mode}`);
|
|
3089
|
-
if (config.system.ui) parts.push(`\u03A3 UI ${config.system.ui}`);
|
|
3090
|
-
parts.push("");
|
|
3091
|
-
for (const fn2 of config.functions || []) {
|
|
3092
|
-
parts.push(createFunction(fn2.name, fn2.args || [], fn2.steps));
|
|
3093
|
-
parts.push("");
|
|
3094
|
-
}
|
|
3095
|
-
for (const obj of config.objects || []) {
|
|
3096
|
-
parts.push(createObject(obj.name, obj.props));
|
|
3097
|
-
parts.push("");
|
|
3098
|
-
}
|
|
3099
|
-
for (const evt of config.events || []) {
|
|
3100
|
-
parts.push(createEvent(evt.name, evt.handlers));
|
|
3101
|
-
parts.push("");
|
|
3102
|
-
}
|
|
3103
|
-
if (config.security) {
|
|
3104
|
-
parts.push(createSecurity(config.security.level, config.security.rules));
|
|
3105
|
-
parts.push("");
|
|
3106
|
-
}
|
|
3107
|
-
if (config.evolve?.length) {
|
|
3108
|
-
parts.push(createEvolve(config.evolve));
|
|
3109
|
-
}
|
|
3110
|
-
return parts.join("\n").trim();
|
|
3111
|
-
}
|
|
3112
3685
|
|
|
3113
3686
|
// src/index.ts
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
var SUBSTATE = /* @__PURE__ */ Symbol("SUBSTATE");
|
|
3118
|
-
var VOID_VAL = null;
|
|
3119
|
-
var TRUE_VAL = true;
|
|
3120
|
-
var FALSE_VAL = false;
|
|
3121
|
-
var OBJECT = /* @__PURE__ */ Symbol("OBJECT");
|
|
3122
|
-
var FUNCTION = /* @__PURE__ */ Symbol("FUNCTION");
|
|
3123
|
-
var INTERFACE = /* @__PURE__ */ Symbol("INTERFACE");
|
|
3124
|
-
var SHIELD = /* @__PURE__ */ Symbol("SECURITY");
|
|
3125
|
-
var EVOLVE = /* @__PURE__ */ Symbol("EVOLVE");
|
|
3126
|
-
function quickSystem(name, config) {
|
|
3127
|
-
return createSystem({
|
|
3128
|
-
name,
|
|
3129
|
-
mode: config?.mode || "development",
|
|
3130
|
-
ui: config?.ui || "auto",
|
|
3131
|
-
evolve: config?.evolve || false
|
|
3132
|
-
});
|
|
3133
|
-
}
|
|
3134
|
-
function compile(enyCode) {
|
|
3135
|
-
const { transpileToJS: transpileToJS2 } = (init_transpile(), __toCommonJS(transpile_exports));
|
|
3136
|
-
const { parse: parse2 } = (init_parser(), __toCommonJS(parser_exports));
|
|
3137
|
-
const ast = parse2(enyCode);
|
|
3138
|
-
return transpileToJS2(ast);
|
|
3687
|
+
init_firebase();
|
|
3688
|
+
function createEnySystem() {
|
|
3689
|
+
return new (init_runtime(), __toCommonJS(runtime_exports)).ENYRuntime();
|
|
3139
3690
|
}
|
|
3140
|
-
function
|
|
3141
|
-
|
|
3142
|
-
const { parse: parse2 } = (init_parser(), __toCommonJS(parser_exports));
|
|
3143
|
-
const ast = parse2(code);
|
|
3144
|
-
return ast.isEny === true;
|
|
3145
|
-
} catch {
|
|
3146
|
-
return false;
|
|
3147
|
-
}
|
|
3691
|
+
function initializeEnyFirebase(config) {
|
|
3692
|
+
return new (init_firebase(), __toCommonJS(firebase_exports)).ENYFirebase().initialize(config);
|
|
3148
3693
|
}
|
|
3694
|
+
var VERSION = "2.0.0";
|
|
3695
|
+
var NAME = "eny-ai";
|
|
3149
3696
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3150
3697
|
0 && (module.exports = {
|
|
3151
3698
|
ALPHABET,
|
|
3152
|
-
|
|
3699
|
+
ENYFirebase,
|
|
3700
|
+
ENYRuntime,
|
|
3701
|
+
EnyContext,
|
|
3702
|
+
EnyUI,
|
|
3703
|
+
EnyValidate,
|
|
3153
3704
|
FALSE,
|
|
3154
|
-
FALSE_VAL,
|
|
3155
|
-
FUNCTION,
|
|
3156
3705
|
IAManager,
|
|
3157
|
-
INTERFACE,
|
|
3158
3706
|
LocalIA,
|
|
3159
3707
|
NAME,
|
|
3160
3708
|
NIL,
|
|
3161
|
-
OBJECT,
|
|
3162
3709
|
RemoteIA,
|
|
3163
|
-
SHIELD,
|
|
3164
|
-
STATE,
|
|
3165
|
-
SUBSTATE,
|
|
3166
3710
|
SYMBOLS,
|
|
3167
3711
|
SYMBOL_NAMES,
|
|
3168
3712
|
TRANSPILE_MAP,
|
|
3169
3713
|
TRUE,
|
|
3170
|
-
TRUE_VAL,
|
|
3171
3714
|
TokenType,
|
|
3172
3715
|
VERSION,
|
|
3173
3716
|
VOID,
|
|
3174
|
-
VOID_VAL,
|
|
3175
3717
|
applyEvolve,
|
|
3176
3718
|
asyncFn,
|
|
3177
|
-
compile,
|
|
3178
3719
|
component,
|
|
3179
|
-
|
|
3180
|
-
createClass,
|
|
3181
|
-
createEvent,
|
|
3182
|
-
createEvolve,
|
|
3183
|
-
createFunction,
|
|
3184
|
-
createInput,
|
|
3185
|
-
createKey,
|
|
3186
|
-
createLoop,
|
|
3187
|
-
createMemory,
|
|
3188
|
-
createObject,
|
|
3189
|
-
createPersist,
|
|
3190
|
-
createSecurity,
|
|
3191
|
-
createSystem,
|
|
3192
|
-
createThrottle,
|
|
3193
|
-
createVisual,
|
|
3720
|
+
createEnySystem,
|
|
3194
3721
|
defaultIAManager,
|
|
3195
3722
|
effect,
|
|
3196
3723
|
error,
|
|
3197
3724
|
filter,
|
|
3198
3725
|
find,
|
|
3726
|
+
firebase,
|
|
3199
3727
|
fn,
|
|
3200
|
-
generateENY,
|
|
3201
3728
|
get,
|
|
3202
|
-
getEnergy,
|
|
3203
|
-
getEvolve,
|
|
3204
|
-
getFunctions,
|
|
3205
|
-
getInterface,
|
|
3206
|
-
getMemory,
|
|
3207
|
-
getSecurity,
|
|
3208
|
-
getState,
|
|
3209
|
-
getStructures,
|
|
3210
|
-
getTemporals,
|
|
3211
3729
|
hasWASMTarget,
|
|
3212
|
-
|
|
3730
|
+
initializeEnyFirebase,
|
|
3213
3731
|
log,
|
|
3214
3732
|
map,
|
|
3215
3733
|
navigate,
|
|
3216
3734
|
parse,
|
|
3217
3735
|
post,
|
|
3218
3736
|
processIA,
|
|
3219
|
-
quickSystem,
|
|
3220
3737
|
reduce,
|
|
3221
3738
|
runENY,
|
|
3222
3739
|
shape,
|
|
@@ -3229,6 +3746,19 @@ function isValidENY(code) {
|
|
|
3229
3746
|
transpileToDTS,
|
|
3230
3747
|
transpileToJS,
|
|
3231
3748
|
transpileToWAT,
|
|
3749
|
+
useAuth,
|
|
3750
|
+
useCallbackWithDeps,
|
|
3751
|
+
useEnyEffect,
|
|
3752
|
+
useEnyFetch,
|
|
3753
|
+
useEnyState,
|
|
3754
|
+
useFirebase,
|
|
3755
|
+
useLogger,
|
|
3756
|
+
useMemoWithDeps,
|
|
3757
|
+
useNavigation,
|
|
3758
|
+
usePersistentState,
|
|
3759
|
+
useRealtimeData,
|
|
3760
|
+
useReducerWithState,
|
|
3761
|
+
useValidation,
|
|
3232
3762
|
validate,
|
|
3233
3763
|
validateSemantic,
|
|
3234
3764
|
validateSemanticFull
|