@dumbql/ssr 0.0.1

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.
@@ -0,0 +1,79 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, inject, TransferState, makeStateKey, Injectable, PLATFORM_ID } from '@angular/core';
3
+ import { isPlatformServer, isPlatformBrowser } from '@angular/common';
4
+
5
+ const SSR_STREAM_KEY = new InjectionToken('SSR_STREAM_KEY');
6
+ /**
7
+ * Service for progressive SSR transfer of GraphQL data.
8
+ * Splits large payloads into chunks for faster TTFB.
9
+ */
10
+ class SsrStreamService {
11
+ transferState = inject(TransferState, { optional: true });
12
+ config;
13
+ constructor() {
14
+ this.config = inject(SSR_STREAM_KEY, { optional: true }) ?? {};
15
+ }
16
+ /** Serialize data to TransferState in chunks */
17
+ writeChunked(key, data) {
18
+ if (!this.transferState)
19
+ return;
20
+ const stateKey = makeStateKey(`${this.config.key ?? 'gql'}_${key}`);
21
+ this.transferState.set(stateKey, data);
22
+ }
23
+ /** Read chunked data from TransferState */
24
+ readChunked(key) {
25
+ if (!this.transferState)
26
+ return undefined;
27
+ const stateKey = makeStateKey(`${this.config.key ?? 'gql'}_${key}`);
28
+ return this.transferState.get(stateKey, undefined);
29
+ }
30
+ /** Clear all GQL-related TransferState entries */
31
+ clear() {
32
+ // TransferState doesn't expose keys, so this is a no-op in Angular
33
+ }
34
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.4", ngImport: i0, type: SsrStreamService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
35
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.4", ngImport: i0, type: SsrStreamService, providedIn: 'root' });
36
+ }
37
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.4", ngImport: i0, type: SsrStreamService, decorators: [{
38
+ type: Injectable,
39
+ args: [{ providedIn: 'root' }]
40
+ }], ctorParameters: () => [] });
41
+
42
+ class TransferCacheService {
43
+ platformId = inject(PLATFORM_ID);
44
+ streamSvc = inject(SsrStreamService);
45
+ /** Save cache state for transfer to browser */
46
+ save(cache) {
47
+ if (!isPlatformServer(this.platformId))
48
+ return;
49
+ this.streamSvc.writeChunked('cache', cache.serialize());
50
+ }
51
+ /** Restore cache state from SSR transfer */
52
+ restore(cache) {
53
+ if (!isPlatformBrowser(this.platformId))
54
+ return false;
55
+ const data = this.streamSvc.readChunked('cache');
56
+ if (!data)
57
+ return false;
58
+ try {
59
+ cache.deserialize(data);
60
+ return true;
61
+ }
62
+ catch {
63
+ return false;
64
+ }
65
+ }
66
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.4", ngImport: i0, type: TransferCacheService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
67
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.4", ngImport: i0, type: TransferCacheService, providedIn: 'root' });
68
+ }
69
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.4", ngImport: i0, type: TransferCacheService, decorators: [{
70
+ type: Injectable,
71
+ args: [{ providedIn: 'root' }]
72
+ }] });
73
+
74
+ /**
75
+ * Generated bundle index. Do not edit.
76
+ */
77
+
78
+ export { SSR_STREAM_KEY, SsrStreamService, TransferCacheService };
79
+ //# sourceMappingURL=dumbql-ssr.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dumbql-ssr.mjs","sources":["../../../../projects/dumbql/ssr/src/lib/ssr-stream.ts","../../../../projects/dumbql/ssr/src/lib/transfer-cache.service.ts","../../../../projects/dumbql/ssr/src/dumbql-ssr.ts"],"sourcesContent":["import { Injectable, inject, InjectionToken, TransferState, makeStateKey } from '@angular/core';\n\nexport const SSR_STREAM_KEY = new InjectionToken<string>('SSR_STREAM_KEY');\n\nexport interface SsrStreamConfig {\n /** Key prefix for TransferState */\n key?: string;\n /** Chunk size for progressive loading (bytes) */\n chunkSize?: number;\n}\n\n/**\n * Service for progressive SSR transfer of GraphQL data.\n * Splits large payloads into chunks for faster TTFB.\n */\n@Injectable({ providedIn: 'root' })\nexport class SsrStreamService {\n private readonly transferState = inject(TransferState, { optional: true });\n private readonly config: SsrStreamConfig;\n\n constructor() {\n \tthis.config = (inject(SSR_STREAM_KEY, { optional: true }) as SsrStreamConfig) ?? {};\n }\n\n /** Serialize data to TransferState in chunks */\n writeChunked(key: string, data: unknown): void {\n \tif (!this.transferState) return;\n \tconst stateKey = makeStateKey<unknown>(`${this.config.key ?? 'gql'}_${key}`);\n \tthis.transferState.set(stateKey, data);\n }\n\n /** Read chunked data from TransferState */\n readChunked<T>(key: string): T | undefined {\n \tif (!this.transferState) return undefined;\n \tconst stateKey = makeStateKey<T | undefined>(`${this.config.key ?? 'gql'}_${key}`);\n \treturn this.transferState.get(stateKey, undefined);\n }\n\n /** Clear all GQL-related TransferState entries */\n clear(): void {\n \t// TransferState doesn't expose keys, so this is a no-op in Angular\n }\n}\n","import { Injectable, inject, PLATFORM_ID } from '@angular/core';\nimport { isPlatformServer, isPlatformBrowser } from '@angular/common';\nimport { SsrStreamService } from './ssr-stream';\nimport { type CacheService } from '@dumbql/cache';\n\n@Injectable({ providedIn: 'root' })\nexport class TransferCacheService {\n private readonly platformId = inject(PLATFORM_ID);\n private readonly streamSvc = inject(SsrStreamService);\n\n /** Save cache state for transfer to browser */\n save(cache: CacheService): void {\n \tif (!isPlatformServer(this.platformId)) return;\n \tthis.streamSvc.writeChunked('cache', cache.serialize());\n }\n\n /** Restore cache state from SSR transfer */\n restore(cache: CacheService): boolean {\n \tif (!isPlatformBrowser(this.platformId)) return false;\n \tconst data = this.streamSvc.readChunked<string>('cache');\n \tif (!data) return false;\n \ttry {\n \t\tcache.deserialize(data);\n \t\treturn true;\n \t} catch {\n \t\treturn false;\n \t}\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;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-0,0 +1,26 @@
1
+ {
2
+ "name": "@dumbql/ssr",
3
+ "version": "0.0.1",
4
+ "peerDependencies": {
5
+ "@angular/common": "^22.0.0",
6
+ "@angular/core": "^22.0.0",
7
+ "@dumbql/cache": "^0.0.1",
8
+ "rxjs": "~7.8.0"
9
+ },
10
+ "sideEffects": false,
11
+ "module": "fesm2022/dumbql-ssr.mjs",
12
+ "typings": "types/dumbql-ssr.d.ts",
13
+ "exports": {
14
+ "./package.json": {
15
+ "default": "./package.json"
16
+ },
17
+ ".": {
18
+ "types": "./types/dumbql-ssr.d.ts",
19
+ "default": "./fesm2022/dumbql-ssr.mjs"
20
+ }
21
+ },
22
+ "type": "module",
23
+ "dependencies": {
24
+ "tslib": "^2.3.0"
25
+ }
26
+ }
@@ -0,0 +1,42 @@
1
+ import { CacheService } from '@dumbql/cache';
2
+ import * as i0 from '@angular/core';
3
+ import { InjectionToken } from '@angular/core';
4
+
5
+ declare class TransferCacheService {
6
+ private readonly platformId;
7
+ private readonly streamSvc;
8
+ /** Save cache state for transfer to browser */
9
+ save(cache: CacheService): void;
10
+ /** Restore cache state from SSR transfer */
11
+ restore(cache: CacheService): boolean;
12
+ static ɵfac: i0.ɵɵFactoryDeclaration<TransferCacheService, never>;
13
+ static ɵprov: i0.ɵɵInjectableDeclaration<TransferCacheService>;
14
+ }
15
+
16
+ declare const SSR_STREAM_KEY: InjectionToken<string>;
17
+ interface SsrStreamConfig {
18
+ /** Key prefix for TransferState */
19
+ key?: string;
20
+ /** Chunk size for progressive loading (bytes) */
21
+ chunkSize?: number;
22
+ }
23
+ /**
24
+ * Service for progressive SSR transfer of GraphQL data.
25
+ * Splits large payloads into chunks for faster TTFB.
26
+ */
27
+ declare class SsrStreamService {
28
+ private readonly transferState;
29
+ private readonly config;
30
+ constructor();
31
+ /** Serialize data to TransferState in chunks */
32
+ writeChunked(key: string, data: unknown): void;
33
+ /** Read chunked data from TransferState */
34
+ readChunked<T>(key: string): T | undefined;
35
+ /** Clear all GQL-related TransferState entries */
36
+ clear(): void;
37
+ static ɵfac: i0.ɵɵFactoryDeclaration<SsrStreamService, never>;
38
+ static ɵprov: i0.ɵɵInjectableDeclaration<SsrStreamService>;
39
+ }
40
+
41
+ export { SSR_STREAM_KEY, SsrStreamService, TransferCacheService };
42
+ export type { SsrStreamConfig };