toiljs 0.0.84 → 0.0.86

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 (36) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/build/cli/.tsbuildinfo +1 -1
  3. package/build/compiler/.tsbuildinfo +1 -1
  4. package/build/compiler/config.d.ts +2 -0
  5. package/build/compiler/config.js +1 -0
  6. package/build/compiler/generate.js +3 -2
  7. package/build/compiler/index.d.ts +1 -1
  8. package/build/compiler/index.js +44 -5
  9. package/build/compiler/toil-docs.generated.js +6 -1
  10. package/build/devserver/.tsbuildinfo +1 -1
  11. package/build/devserver/analytics/index.js +113 -33
  12. package/build/devserver/runtime/module.js +1 -0
  13. package/docs/auth/configuration.md +94 -0
  14. package/docs/auth/extending.md +170 -0
  15. package/docs/auth/how-it-works.md +138 -0
  16. package/docs/auth/index.md +102 -0
  17. package/docs/auth/usage.md +188 -0
  18. package/docs/auth.md +6 -0
  19. package/examples/basic/client/routes/analytics.tsx +164 -26
  20. package/examples/basic/server/models/SiteAnalytics.ts +139 -11
  21. package/examples/basic/server/routes/Analytics.ts +89 -13
  22. package/examples/basic/server/routes/UserId.ts +22 -0
  23. package/package.json +5 -1
  24. package/scripts/gen-toil-docs.mjs +15 -6
  25. package/server/auth/AuthController.ts +335 -0
  26. package/server/auth/AuthUser.ts +49 -0
  27. package/server/auth/index.ts +16 -0
  28. package/server/globals/auth.ts +31 -0
  29. package/server/globals/userid.ts +107 -0
  30. package/src/compiler/config.ts +13 -0
  31. package/src/compiler/generate.ts +3 -2
  32. package/src/compiler/index.ts +74 -5
  33. package/src/compiler/toil-docs.generated.ts +6 -1
  34. package/src/devserver/analytics/index.ts +139 -38
  35. package/src/devserver/runtime/module.ts +1 -0
  36. package/test/analytics-dev.test.ts +76 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Dev-server analytics stub parity: the `env.analytics_read` / `env.analytics_series` dev imports must
3
+ * encode the v2 frames BYTE-FOR-BYTE like the edge (`analytics.rs`), so a guest's toilscript `Analytics`
4
+ * decode is identical in dev and prod. We decode the stashed frame positionally, exactly as the guest.
5
+ */
6
+ import { describe, expect, it } from 'vitest';
7
+
8
+ import { buildAnalyticsImports } from '../src/devserver/analytics/index.js';
9
+
10
+ // Minimal fakes: domainLen 0 needs no memory; the stub stashes the frame into db.lastResult.
11
+ function harness() {
12
+ const ref = { memory: null } as unknown as Parameters<typeof buildAnalyticsImports>[0];
13
+ const db = { lastResult: null as Buffer | null, lastResultVersion: 0 } as unknown as Parameters<
14
+ typeof buildAnalyticsImports
15
+ >[1];
16
+ return { imports: buildAnalyticsImports(ref, db), db };
17
+ }
18
+
19
+ describe('dev analytics stub v2 frame parity', () => {
20
+ it('analytics_read encodes the fixed-layout snapshot frame', () => {
21
+ const { imports, db } = harness();
22
+ const n = imports.analytics_read(0, 0);
23
+ const buf = db.lastResult as unknown as Buffer;
24
+ expect(n).toBe(buf.length);
25
+
26
+ let p = 0;
27
+ const u16 = () => { const v = buf.readUInt16LE(p); p += 2; return v; };
28
+ const u32 = () => { const v = buf.readUInt32LE(p); p += 4; return v; };
29
+ const i64 = () => { const v = buf.readBigInt64LE(p); p += 8; return v; };
30
+ const u64 = () => { const v = buf.readBigUInt64LE(p); p += 8; return v; };
31
+
32
+ expect(u16()).toBe(2); // FRAME_VERSION
33
+ u64(); // now_ms
34
+ const count = u32();
35
+ expect(count).toBe(43); // METRIC_COUNTERS
36
+ const life: bigint[] = [];
37
+ for (let i = 0; i < count; i++) life.push(i64());
38
+ expect(life[0]).toBe(42n); // Requests
39
+ expect(life[1]).toBe(12345n); // BytesOutL1
40
+ expect(life[12]).toBe(1_000_000n); // GasUsed
41
+ expect(life[41]).toBe(900n); // CacheHits
42
+ expect(i64()).toBe(3n); // connectedStreams
43
+ expect(i64()).toBe(65536n); // committedMemory
44
+ expect(i64()).toBe(5n); // reqMinuteUsed
45
+ expect(u64()).toBe(100n); // reqMinuteCap
46
+ expect(i64()).toBe(42n); // reqDayUsed
47
+ expect(u64()).toBe(5000n); // reqDayCap
48
+ expect(p).toBe(buf.length); // no trailing bytes
49
+ });
50
+
51
+ it('analytics_series encodes the series frame with the right shape per range', () => {
52
+ const { imports, db } = harness();
53
+ // metric 0 (Requests), range 3 (H24) -> hour ring, 24 buckets, bucketSecs 3600.
54
+ const n = imports.analytics_series(0, 0, 0, 3);
55
+ const buf = db.lastResult as unknown as Buffer;
56
+ expect(n).toBe(buf.length);
57
+ let p = 0;
58
+ expect(buf.readUInt16LE(p)).toBe(2); p += 2; // version
59
+ expect(buf.readUInt16LE(p)).toBe(0); p += 2; // metric id
60
+ expect(buf.readUInt32LE(p)).toBe(3600); p += 4; // bucketSecs
61
+ p += 8; // headMs
62
+ const count = buf.readUInt32LE(p); p += 4;
63
+ expect(count).toBe(24);
64
+ expect(buf.length).toBe(p + count * 8);
65
+
66
+ // range 0 (1h) -> minute ring: 60 buckets, bucketSecs 60.
67
+ imports.analytics_series(0, 0, 0, 0);
68
+ const b2 = db.lastResult as unknown as Buffer;
69
+ expect(b2.readUInt32LE(4)).toBe(60); // bucketSecs
70
+ expect(b2.readUInt32LE(16)).toBe(60); // count
71
+
72
+ // A bad metric / range -> ABSENT (negative), no frame.
73
+ expect(imports.analytics_series(0, 0, 999, 3)).toBeLessThan(0);
74
+ expect(imports.analytics_series(0, 0, 0, 99)).toBeLessThan(0);
75
+ });
76
+ });