fusee-framework 1.7.0 → 1.9.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.
Files changed (77) hide show
  1. package/README.md +206 -139
  2. package/app/benchmark/benchmark.js +2 -2
  3. package/app/benchmark/vite.config.js +23 -0
  4. package/app/main.js +24 -3
  5. package/app/main.ts +7 -1
  6. package/app/pages/_layout.js +27 -0
  7. package/app/pages/async-work.js +65 -0
  8. package/app/pages/index.js +25 -5
  9. package/app/pages/index.ts +9 -0
  10. package/app/pages/router-example.js +24 -1
  11. package/app/pages/scroll-demo.ts +102 -0
  12. package/app/providers/ChildComponent.js +8 -2
  13. package/app/providers/ChildComponent.ts +47 -47
  14. package/app/providers/GrandchildComponent.js +19 -0
  15. package/app/providers/ParentComponent.js +5 -1
  16. package/app/routes/RouterExample.js +23 -1
  17. package/app/routes/TestResource.js +47 -0
  18. package/app/services.js +15 -0
  19. package/auto-imports.d.ts +12 -0
  20. package/framework/auto-import-preset.js +15 -9
  21. package/framework/core/async-context.js +27 -0
  22. package/framework/core/compiler/ast.js +167 -0
  23. package/framework/core/compiler/errors-list.js +47 -0
  24. package/framework/core/compiler/errors.js +107 -0
  25. package/framework/core/compiler/generator.js +363 -0
  26. package/framework/core/compiler/lexer.js +347 -0
  27. package/framework/core/compiler/main-compiler.js +115 -0
  28. package/framework/core/compiler/parser.js +414 -0
  29. package/framework/core/compiler/plugins/actions-plugin.js +263 -0
  30. package/framework/core/compiler/plugins/compiler-plugin.d.ts +5 -0
  31. package/framework/core/compiler/plugins/compiler-plugin.js +45 -0
  32. package/framework/core/compiler/plugins/file-router-plugin.js +301 -0
  33. package/framework/core/compiler/plugins/router-plugin.js +196 -0
  34. package/framework/core/compiler/transformer.js +398 -0
  35. package/framework/core/component.js +61 -23
  36. package/framework/core/di.js +187 -0
  37. package/framework/core/directives.js +40 -96
  38. package/framework/core/evaluator.js +1 -1
  39. package/framework/core/h.js +430 -0
  40. package/framework/core/hydration.js +83 -0
  41. package/framework/core/reconcile.js +151 -0
  42. package/framework/core/signal.js +269 -0
  43. package/framework/core/store.js +322 -81
  44. package/framework/index.js +5 -3
  45. package/framework/router/file-router.js +1 -1
  46. package/framework/router/router.js +113 -21
  47. package/framework/server/actions.js +173 -0
  48. package/framework/server/actions.server.js +88 -0
  49. package/framework/server/index.js +18 -0
  50. package/framework/types/actions.d.ts +50 -0
  51. package/framework/types/actions.server.d.ts +36 -0
  52. package/framework/types/compiler/ast.d.ts +166 -0
  53. package/framework/types/compiler/errors-codes.d.ts +23 -0
  54. package/framework/types/compiler/errors.d.ts +43 -0
  55. package/framework/types/compiler/generator.d.ts +8 -0
  56. package/framework/types/compiler/h.d.ts +46 -0
  57. package/framework/types/compiler/lexer.d.ts +27 -0
  58. package/framework/types/compiler/main-compiler.d.ts +60 -0
  59. package/framework/types/compiler/parser.d.ts +4 -0
  60. package/framework/types/compiler/plugins/actions.d.ts +30 -0
  61. package/framework/types/compiler/plugins/compiler-plugin.d.ts +5 -0
  62. package/framework/types/compiler/plugins/file-router-plugins.d.ts +32 -0
  63. package/framework/types/compiler/plugins/router-plugin.d.ts +24 -0
  64. package/framework/types/compiler/transformer.d.ts +28 -0
  65. package/framework/types/component.d.ts +89 -88
  66. package/framework/types/di.d.ts +43 -0
  67. package/framework/types/hydration.d.ts +30 -0
  68. package/framework/types/index.d.ts +38 -22
  69. package/framework/types/reconcile.d.ts +7 -0
  70. package/framework/types/router.d.ts +11 -1
  71. package/framework/types/server.d.ts +11 -0
  72. package/framework/types/signal.d.ts +142 -79
  73. package/framework/types/store.d.ts +66 -8
  74. package/ghid_go_fusee_integrat_go1_26.txt +276 -0
  75. package/ghid_rust_fusee_rust_1_95_0.txt +1118 -0
  76. package/package.json +44 -36
  77. package/vite.config.js +65 -47
@@ -1,8 +1,66 @@
1
- export function defineStore<T>(id: string, setup: () => T): () => T;
2
- export function resetStore(id: string): void;
3
- export function clearStores(): void;
4
- export function registerStorePlugin(plugin: (store: any, id: string) => void): void;
5
-
6
- declare global {
7
- function defineStore<T>(id: string, setup: () => T): () => T;
8
- }
1
+ export type MutationType = 'direct' | 'patch object' | 'patch function';
2
+
3
+ export const MutationType: {
4
+ readonly DIRECT: 'direct';
5
+ readonly PATCH_OBJECT: 'patch object';
6
+ readonly PATCH_FUNCTION: 'patch function';
7
+ };
8
+
9
+ export interface StoreMutation {
10
+ type: MutationType;
11
+ storeId: string;
12
+ payload?: Record<string, any>;
13
+ }
14
+
15
+ export interface SubscribeOptions {
16
+ flush?: 'pre' | 'post' | 'sync';
17
+ detached?: boolean;
18
+ }
19
+
20
+ export type SubscribeCallback = (mutation: StoreMutation, state: any) => void;
21
+ export type UnsubscribeFunction = () => void;
22
+
23
+ export interface Store<T> {
24
+ readonly id: string;
25
+ readonly type: 'store';
26
+ patch(partial: Partial<{ [K in keyof T]: T[K] extends (...args: any[]) => any ? ReturnType<T[K]> : T[K] }> | ((state: T) => void)): void;
27
+ subscribe(callback: SubscribeCallback, options?: SubscribeOptions): UnsubscribeFunction;
28
+ }
29
+
30
+ export type StoreHook<T> = (() => T & Store<T>) & { $id: string };
31
+
32
+ export function defineStore<T>(id: string, setup: () => T): StoreHook<T>;
33
+ export function resetStore(id: string): void;
34
+ export function clearStores(): void;
35
+ export function registerStorePlugin(plugin: (store: any, id: string) => void): void;
36
+ export function useNestedStore<T>(useStoreFn: StoreHook<T>): T & Store<T>;
37
+
38
+ export type StoreToRefs<T> = {
39
+ [K in keyof T]: T[K] extends (...args: any[]) => infer R ? import('./signal').SignalAccessor<R> : never
40
+ }
41
+
42
+ export type StoreToState<T> = {
43
+ [K in keyof T]: T[K] extends (...args: any[]) => infer R
44
+ ? import('./signal').SignalAccessor<R> extends { readonly: true }
45
+ ? never
46
+ : import('./signal').SignalAccessor<R>
47
+ : never
48
+ }
49
+
50
+ export type StoreToGetters<T> = {
51
+ [K in keyof T]: T[K] extends (...args: any[]) => infer R
52
+ ? import('./signal').SignalAccessor<R> extends { readonly: true }
53
+ ? import('./signal').SignalAccessor<R>
54
+ : never
55
+ : never
56
+ }
57
+
58
+ export function storeToRefs<T>(store: T & Store<T>): StoreToRefs<T>;
59
+ export function storeToState<T>(store: T & Store<T>): StoreToState<T>;
60
+ export function storeToGetters<T>(store: T & Store<T>): StoreToGetters<T>;
61
+
62
+ declare global {
63
+ function defineStore<T>(id: string, setup: () => T): import('./store').StoreHook<T>;
64
+ function useNestedStore<T>(useStoreFn: import('./store').StoreHook<T>): T & Store<T>;
65
+ type MutationType = import('./store').MutationType;
66
+ }
@@ -0,0 +1,276 @@
1
+ Ghid integrat: Construirea serverului Fusee în Go 1.26 — ghid tehnic detaliat și bune practici
2
+
3
+ Scopul acestui fișier
4
+ - Un ghid tehnic complet, în limba română, pentru construirea serverului Fusee în Go (versiunea 1.26). Integrează cele două ghiduri anterioare: un ghid general pentru server Fusee în Go și un ghid tehnic actualizat specific Go 1.26.
5
+ - Public țintă: student CS care dezvoltă Fusee (framework JS cu reactivitate fină) și are nevoie de un backend scalabil în Go pentru orchestrare compilare, servire artefacte, build pipeline, caching, multi-tenant, observabilitate și securitate.
6
+
7
+ Sumar rapid
8
+ 1. Motivație pentru Go
9
+ 2. Ce e nou în Go 1.26 și implicații practice
10
+ 3. Reguli explicite pentru editorul AI / echipă
11
+ 4. Setup și toolchain (Go 1.26)
12
+ 5. Arhitectură recomandată proiect
13
+ 6. Concurență în Go: modele, pattern-uri și scenarii Fusee
14
+ 7. Implementări concrete: worker pool, errgroup, rate limiting, backpressure
15
+ 8. HTTP server design și API pentru Fusee
16
+ 9. Job orchestration: sync vs async, cache, deduplicare, multi-tenant
17
+ 10. Securitate, izolare runner, sandboxing
18
+ 11. Observabilitate, tracing și profilare (incl. goroutine leak profile 1.26)
19
+ 12. Testing: unit, integration, golden, differential, leak tests
20
+ 13. CI/CD, Dockerfile, producție
21
+ 14. Performanță și optimizări practice
22
+ 15. Anti-patterns și greșeli comune
23
+ 16. Checklist de migrare JS → Go
24
+ 17. Plan de învățare și implementare 90+ zile
25
+ 18. Resurse și linkuri utile
26
+
27
+ 1) De ce Go pentru serverul Fusee
28
+ - Simplitate, viteza de dezvoltare și ecosistem pentru servere networked.
29
+ - Model de concurență ușor de folosit (goroutines + channels) ideal pentru orchestration.
30
+ - Toolchain stabil, cross-compilation simplă, suport bun pentru containerizare și cloud native.
31
+ - Go 1.26 aduce optimizări GC și instrumente utile (goroutine leak profile) care ajută la construirea unui server robust.
32
+
33
+ 2) Ce e nou în Go 1.26 (rezumat relevant)
34
+ - Green Tea garbage collector activ implicit (reduce overhead GC pentru alocări mici și concu- intensive).
35
+ - `errors.AsType[E error](err)` — verificări tip-sigure pentru erori.
36
+ - `new(expr)` — permite `new` cu expresii (utile pentru pointere inițializate inline în DTO-uri).
37
+ - Experimental: `simd/archsimd`, `runtime/secret`, `goroutineleak` profile.
38
+ - `go fix` modernizat — automatizări pentru modernizarea codului.
39
+ Referințe oficiale: https://go.dev/doc/go1.26 și https://go.dev/blog/go1.26
40
+
41
+ 3) Reguli explicite pentru editorul AI / echipă
42
+ - Propagă `context.Context` în toate apelurile I/O, job-run și comunicare între componente.
43
+ - Nu lansa goroutine fără mecanism de oprire: folosește `context`, `WaitGroup`, canale, `errgroup`.
44
+ - Nu inventa API extern: folosește API-uri documentate; întreabă dacă nu e sigur.
45
+ - Evită variabile globale mutabile; folosește injecție de dependență (constructori de tip NewXxx).
46
+ - Error handling explicit: returnează erori, folosește `errors.Is`/`errors.AsType`.
47
+ - Nu folosi panic pentru control-flow; folosește recover centralizat la boundary-uri HTTP.
48
+ - Aplică backpressure — canale cu buffer limitat, rate-limiter (token bucket), cozi finite.
49
+ - Testează tot: unit tests, integration tests, benchmark-uri și leak tests (goroutineleak profile).
50
+
51
+ 4) Setup & toolchain pentru Go 1.26
52
+ - Instalează Go 1.26 de pe https://go.dev/dl/ (sau managerul preferat). Setează `GOPATH` doar dacă ai nevoie; folosește `go mod`.
53
+ - Inițializează modul:
54
+ - `go mod init github.com/yourorg/fusee-server`
55
+ - Asigură `go 1.26` în `go.mod` (editează manual dacă `go mod init` a creat o versiune inferioară)
56
+ - Instrumente recomandate:
57
+ - `gofmt` (format), `go vet`, `golangci-lint`, `staticcheck`
58
+ - `go test` + `-race` pentru detecție race conditions
59
+ - `pprof` (profilare CPU/memorie) și `GOEXPERIMENT=goroutineleakprofile` pentru leak detection în CI/dev
60
+ - `minio` pentru test local S3, `redis` pentru cache/metadate
61
+ - `docker` / `kind` / `testcontainers` pentru e2e
62
+
63
+ 5) Structura recomandată proiect
64
+ - cmd/fusee-server/main.go
65
+ - internal/server (HTTP server, middleware)
66
+ - internal/api (handlers, DTO, validation)
67
+ - internal/compile (orchestrare job-uri, queue)
68
+ - internal/worker (worker pool, runners)
69
+ - pkg/storage (S3 adapter), pkg/cache (in-memory + Redis)
70
+ - pkg/observability (metrics/tracing wrappers)
71
+ - test/ (fixtures, golden)
72
+
73
+ 6) Concurența în Go — concepte și pattern-uri esențiale
74
+ - Goroutine: `go fn()` — unitate ușoară de execuție. Nu sunt gratuite.
75
+ - Channel: comunicare sincronă/asincronă între goroutine. Folosește canale buffered pentru backpressure.
76
+ - select: multiplexare pe canale + context.Done() pentru cancel.
77
+ - sync.WaitGroup: sincronizare pentru grupuri de goroutine.
78
+ - sync.Mutex / RWMutex / atomic: folosirea cu atenție când state partajat.
79
+ - errgroup: colectare erori din mai multe goroutine, propagare cancel.
80
+
81
+ Pattern-uri utile:
82
+ - Worker pool — pentru job-uri compilare.
83
+ - Fan-out/fan-in — paralelizare taskuri independente.
84
+ - Owner-per-shard — pentru a evita lock contention.
85
+ - Circuit breaker + retry with backoff — pentru dependențe instabile.
86
+
87
+ 7) Exemple concrete (cod schematic) — worker pool și orchestration
88
+ - Exemplar worker pool (robust, cu ctx, timeout și wg):
89
+
90
+ ```
91
+ package worker
92
+
93
+ import (
94
+ "context"
95
+ "sync"
96
+ "time"
97
+ )
98
+
99
+ type Job struct {
100
+ ID string
101
+ Input []byte
102
+ }
103
+
104
+ type Result struct {
105
+ JobID string
106
+ Err error
107
+ }
108
+
109
+ func StartWorkers(ctx context.Context, n int, jobs <-chan Job, results chan<- Result, wg *sync.WaitGroup) {
110
+ for i := 0; i < n; i++ {
111
+ wg.Add(1)
112
+ go func(workerID int) {
113
+ defer wg.Done()
114
+ for {
115
+ select {
116
+ case <-ctx.Done():
117
+ return
118
+ case job, ok := <-jobs:
119
+ if !ok { return }
120
+ jobCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
121
+ resErr := processJob(jobCtx, job)
122
+ cancel()
123
+ select {
124
+ case results <- Result{JobID: job.ID, Err: resErr}:
125
+ case <-ctx.Done():
126
+ return
127
+ }
128
+ }
129
+ }
130
+ }(i)
131
+ }
132
+ }
133
+
134
+ // processJob este funcția de lucru care trebuie să respecte contextul
135
+ func processJob(ctx context.Context, j Job) error {
136
+ // implementare: build, write artifact to S3, update DB
137
+ return nil
138
+ }
139
+ ```
140
+
141
+ Observații:
142
+ - Folosește `jobCtx` cu timeout specific pentru fiecare job.
143
+ - Rezultatele pot fi stocate în DB sau trimise pe canal `results`.
144
+ - `wg` este așteptat la shutdown pentru a evita goroutine leaks.
145
+
146
+ 8) HTTP server design & endpoint-uri recomandate
147
+ - Endpoints cheie:
148
+ - POST /compile → acceptă request, validează, calculează hash input, verifică cache, enquează job asincron și returnează 202 + job_id (sau 200 + artifact dacă e cache hit)
149
+ - GET /compile/{id}/status → starea jobului
150
+ - GET /assets/{hash} → serve artifact (WASM/JS) cu headers CDN
151
+ - /metrics, /debug/pprof/*, /healthz, /readyz
152
+ - Principii handler:
153
+ - Handlers mici: parse, validate, convert DTO, call service layer, write response
154
+ - Middleware pentru logging, tracing, recover (panic->500), rate-limit
155
+
156
+ Exemplu handler schematic:
157
+
158
+ ```
159
+ func (s *Server) compileHandler(w http.ResponseWriter, r *http.Request) {
160
+ ctx := r.Context()
161
+ var req CompileRequest
162
+ if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
163
+ http.Error(w, "invalid JSON", http.StatusBadRequest)
164
+ return
165
+ }
166
+ if !s.limiter.Allow() {
167
+ http.Error(w, "rate limit", http.StatusTooManyRequests)
168
+ return
169
+ }
170
+ key := s.computeHash(req)
171
+ if art, ok := s.cache.Get(key); ok {
172
+ w.Header().Set("Content-Type", "application/wasm")
173
+ w.Write(art)
174
+ return
175
+ }
176
+ jobID, err := s.queue.Enqueue(ctx, req)
177
+ if err != nil {
178
+ http.Error(w, "internal", http.StatusInternalServerError)
179
+ return
180
+ }
181
+ w.WriteHeader(http.StatusAccepted)
182
+ json.NewEncoder(w).Encode(map[string]string{"job_id": jobID})
183
+ }
184
+ ```
185
+
186
+ 9) Job orchestration: sync vs async, cache & deduplicare
187
+ - Dev: permită compilare sync cu timeout curat (feedback rapid).
188
+ - Prod: async cu job queue și worker pool; returnează 202. Stochează artefactele în object store.
189
+ - Deduplicare: folosește hash funcțional (deterministic) din input (source + flags) pentru a evita recompilări.
190
+ - Stochează metadate în Redis/DB (status, retrier count, last error, artifact URL).
191
+
192
+ 10) Securitate și izolare
193
+ - Rulează build-runner în containere sandbox (firecracker, gVisor, k8s Jobs) sau procese izolate.
194
+ - Limitările resurselor: cgroup limits, ulimit pentru procese runner.
195
+ - Validare input: never trust client input — sanitize, size limits, timeouts.
196
+ - TLS & auth pentru API, rate-limit per tenant.
197
+
198
+ 11) Observabilitate, tracing și profilare
199
+ - Logging: zap/zerolog (structured logs). Include trace_id, job_id, tenant_id în log fields.
200
+ - Metrics: Prometheus client — counters, histograms (compile_duration_seconds), gauges (job_queue_length).
201
+ - Tracing: OpenTelemetry — trace request flow: HTTP -> queue -> worker -> storage.
202
+ - Profilare: pprof endpoints. Go 1.26 pprof UI default la flamegraph. Activează `goroutineleakprofile` în test/CI pentru leak detection.
203
+
204
+ 12) Testare recomandată
205
+ - Unit tests (table-driven) pentru serviciile pure.
206
+ - Mocks pentru dependințe I/O (storage, redis) cu `github.com/golang/mock` sau `testify/mock`.
207
+ - Integration tests cu MinIO/Redis în container (testcontainers).
208
+ - Golden tests pentru output codgen (compare generated JS/WASM bytes).
209
+ - Differential tests: compară comportamentul JS-based compiler cu runner (Rust/WASM) dacă există.
210
+ - Leak tests: rulează workload mic + colectează goroutineleak profile și asigură că nu apar goroutine leaked.
211
+
212
+ 13) CI/CD și Docker
213
+ - Docker multistage build; folosește `CGO_ENABLED=0` pentru binare statice (dacă nu folosești cgo).
214
+ - GitHub Actions / GitLab CI: lint -> unit tests -> build -> container -> smoke tests (integration), optional: run goroutine leak profile in CI smoke stage.
215
+ - Exemple Dockerfile (multistage):
216
+
217
+ ```
218
+ FROM golang:1.26 AS builder
219
+ WORKDIR /src
220
+ COPY go.mod go.sum ./
221
+ RUN go mod download
222
+ COPY . .
223
+ RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -o /app/cmd/fusee-server ./cmd/fusee-server
224
+
225
+ FROM gcr.io/distroless/static-debian11
226
+ COPY --from=builder /app/cmd/fusee-server /usr/local/bin/fusee-server
227
+ EXPOSE 8080
228
+ ENTRYPOINT ["/usr/local/bin/fusee-server"]
229
+ ```
230
+
231
+ 14) Performanță & optimizări
232
+ - Măsoară cu pprof înainte de optimizare.
233
+ - Evită alocările repetate: folosește `sync.Pool` pentru buffers mari.
234
+ - Sharding pentru a reduce lock contention.
235
+ - Folosește canale pentru coordonare când se potrivește, dar evită blocking pe canale necontrolate.
236
+ - Dacă e nevoie de operații vectorizate, poți explora `simd/archsimd` (experimental) sau implementări native în Rust pentru codgen.
237
+
238
+ 15) Anti-patterns de evitat
239
+ - Goroutine leaks (pornite fără mecanism de oprire).
240
+ - Folosirea `panic` pentru flow control.
241
+ - Variabile globale mutabile pentru state aplicație.
242
+ - Blocking pe canale nebuffered în contexte fără timeout.
243
+ - Ignorarea contextului în apeluri externe.
244
+
245
+ 16) Checklist migrare JS -> Go (server)
246
+ - Definește API contract (OpenAPI)
247
+ - Generare DTO în Go
248
+ - Implementare handlers pure și service layer
249
+ - Job queue + worker pool + cache/dedup
250
+ - Storage artifacts (S3) + CDN headers
251
+ - Observability (metrics, tracing) și health endpoints
252
+ - Security review + sandboxing runner
253
+ - Tests: unit/integration/golden/leak
254
+
255
+ 17) Plan 90 zile (orientativ)
256
+ - Săptămâna 1-2: setup proiect, basic HTTP + middleware, DTO
257
+ - Săptămâna 3-4: implementare job queue simplu, worker pool, sync compile dev mode
258
+ - Săptămâna 5-6: integrate storage (MinIO), cache (Redis), dedup
259
+ - Săptămâna 7-8: add rate limiter, multi-tenant basics, health & metrics
260
+ - Săptămâna 9-10: tracing OTel, pprof, goroutine leak tests în CI
261
+ - Săptămâna 11-12: CI/CD, Docker image, smoke e2e, performance tuning
262
+
263
+ 18) Resurse și linkuri utile
264
+ - Go 1.26 Release Notes: https://go.dev/doc/go1.26
265
+ - Go blog: https://go.dev/blog/go1.26
266
+ - Effective Go: https://go.dev/doc/effective_go
267
+ - golang.org/x/sync/errgroup: https://pkg.go.dev/golang.org/x/sync/errgroup
268
+ - golang.org/x/time/rate: https://pkg.go.dev/golang.org/x/time/rate
269
+ - Prometheus client: https://github.com/prometheus/client_golang
270
+ - OpenTelemetry Go: https://opentelemetry.io/docs/instrumentation/go/
271
+
272
+ Concluzie
273
+ - Construirea serverului Fusee în Go 1.26 aduce beneficii de performanță, scalabilitate și o experiență solidă de dezvoltare. Folosește `context` pe scară largă, gestionează cu grijă goroutine-urile, instrumentează observabilitatea și asigură izolare pentru runner.
274
+ - Go 1.26 oferă instrumente adiționale (goroutine leak profile, `errors.AsType`, Green Tea GC) care, folosite corect, îți vor ușura munca și îmbunătăți fiabilitatea.
275
+
276
+ Dacă dorești, pot salva acest fișier ca `ghid_go_fusee_integrat_go1_26.txt` și ți-l pot pune la dispoziție pentru descărcare. De asemenea pot genera o versiune v2 care include un repo template complet (fișiere `main.go`, `server` package, worker example), workflow GitHub Actions și setări `golangci-lint`.