@absolutejs/sync 2.5.0 → 2.7.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.
@@ -1,6 +1,8 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
2
  import { Elysia } from 'elysia';
3
3
  import { type SyncEngine, type SyncEngineOptions } from './engine/syncEngine';
4
+ import type { ClusterBus } from './engine/cluster';
5
+ import type { SyncPack } from './engine/pack';
4
6
  import { type SyncSocketOptions } from './engine/socket';
5
7
  import { type SyncPluginOptions } from './plugin';
6
8
  import { type ReactiveHub } from './reactiveHub';
@@ -25,10 +27,12 @@ export declare class PlatformSyncConfigurationError extends Error {
25
27
  }
26
28
  export declare const readPlatformSyncConfiguration: (environment?: Record<string, string | undefined>) => PlatformSyncConfiguration | null;
27
29
  export type PlatformSyncRuntimeOptions = {
30
+ clusterBus?: ClusterBus;
28
31
  configuration?: PlatformSyncConfiguration;
29
32
  engineOptions?: SyncEngineOptions;
30
33
  hub?: ReactiveHub;
31
34
  onSlow?: SyncSocketOptions['onSlow'];
35
+ packs?: SyncPack[];
32
36
  resolveContext?: SyncSocketOptions['resolveContext'];
33
37
  resolveTopics?: SyncPluginOptions['resolveTopics'];
34
38
  };
@@ -59,9 +63,20 @@ export declare const createPlatformSyncRuntime: (options?: PlatformSyncRuntimeOp
59
63
  headers: unknown;
60
64
  response: {
61
65
  200: {
66
+ cluster: {
67
+ error?: string | undefined;
68
+ configured: boolean;
69
+ connected: boolean;
70
+ };
62
71
  contract: 1;
63
72
  instanceId: string;
64
- ready: true;
73
+ packs: {
74
+ name: string;
75
+ version: string;
76
+ ownsTables: string[];
77
+ readsTables: string[];
78
+ }[];
79
+ ready: boolean;
65
80
  tier: "push" | "engine" | "both";
66
81
  };
67
82
  };
@@ -90,9 +105,20 @@ export declare const createPlatformSyncRuntime: (options?: PlatformSyncRuntimeOp
90
105
  headers: unknown;
91
106
  response: {
92
107
  200: {
108
+ cluster: {
109
+ error?: string | undefined;
110
+ configured: boolean;
111
+ connected: boolean;
112
+ };
93
113
  contract: 1;
94
114
  instanceId: string;
95
- ready: true;
115
+ packs: {
116
+ name: string;
117
+ version: string;
118
+ ownsTables: string[];
119
+ readsTables: string[];
120
+ }[];
121
+ ready: boolean;
96
122
  tier: "push" | "engine" | "both";
97
123
  };
98
124
  };
@@ -133,7 +159,9 @@ export declare const createPlatformSyncRuntime: (options?: PlatformSyncRuntimeOp
133
159
  socketPath: string;
134
160
  tier: "push" | "engine" | "both";
135
161
  };
162
+ dispose: () => Promise<void>;
136
163
  engine: SyncEngine | undefined;
137
164
  hub: ReactiveHub | undefined;
138
165
  metrics: () => import("./engine").EngineMetrics | null;
166
+ ready: Promise<void>;
139
167
  };
package/dist/platform.js CHANGED
@@ -3005,7 +3005,12 @@ var sync = ({
3005
3005
  heartbeatMs = 25000
3006
3006
  }) => {
3007
3007
  const app = new Elysia2({ name: "@absolutejs/sync" }).get(path, async (context) => {
3008
+ const cookies = Object.fromEntries(Object.entries(context.cookie).map(([name, cookie]) => [
3009
+ name,
3010
+ cookie.value
3011
+ ]));
3008
3012
  const topics = await resolveTopics({
3013
+ cookies,
3009
3014
  query: context.query,
3010
3015
  request: context.request
3011
3016
  });
@@ -3123,6 +3128,36 @@ var createPlatformSyncRuntime = (options = {}) => {
3123
3128
  mutationConcurrency: configuration.mutationConcurrency,
3124
3129
  mutationQueueLimit: configuration.mutationQueueLimit
3125
3130
  }) : undefined;
3131
+ if (!engine && (options.clusterBus || options.packs?.length))
3132
+ throw new PlatformSyncConfigurationError("Platform Sync packs and cluster buses require the engine or both tier");
3133
+ for (const pack of options.packs ?? [])
3134
+ engine?.registerPack(pack);
3135
+ let clusterState = options.clusterBus ? "connecting" : "disabled";
3136
+ let clusterError;
3137
+ let disconnectCluster;
3138
+ const ready = options.clusterBus ? engine.connectCluster(options.clusterBus).then((disconnect) => {
3139
+ disconnectCluster = disconnect;
3140
+ clusterState = "connected";
3141
+ }).catch((error) => {
3142
+ clusterError = error;
3143
+ clusterState = "error";
3144
+ throw error;
3145
+ }) : Promise.resolve();
3146
+ ready.catch(() => {
3147
+ return;
3148
+ });
3149
+ let disposed = false;
3150
+ const dispose = async () => {
3151
+ if (disposed)
3152
+ return;
3153
+ disposed = true;
3154
+ try {
3155
+ await ready;
3156
+ } finally {
3157
+ await disconnectCluster?.();
3158
+ disconnectCluster = undefined;
3159
+ }
3160
+ };
3126
3161
  const app = new Elysia3({ name: "@absolutejs/sync/platform" }).use(hub ? sync({
3127
3162
  heartbeatMs: configuration.heartbeatMs,
3128
3163
  hub,
@@ -3135,18 +3170,31 @@ var createPlatformSyncRuntime = (options = {}) => {
3135
3170
  path: configuration.socketPath,
3136
3171
  ...options.onSlow ? { onSlow: options.onSlow } : {},
3137
3172
  ...options.resolveContext ? { resolveContext: options.resolveContext } : {}
3138
- }) : new Elysia3({ name: "@absolutejs/sync/platform/no-engine" })).get(PLATFORM_SYNC_HEALTH_PATH, () => ({
3139
- contract: 1,
3140
- instanceId: configuration.instanceId,
3141
- ready: true,
3142
- tier: configuration.tier
3143
- }));
3173
+ }) : new Elysia3({ name: "@absolutejs/sync/platform/no-engine" })).get(PLATFORM_SYNC_HEALTH_PATH, ({ set }) => {
3174
+ const isReady = clusterState !== "connecting" && clusterState !== "error";
3175
+ if (!isReady)
3176
+ set.status = 503;
3177
+ return {
3178
+ cluster: {
3179
+ configured: clusterState !== "disabled",
3180
+ connected: clusterState === "connected",
3181
+ ...clusterError instanceof Error ? { error: clusterError.message } : {}
3182
+ },
3183
+ contract: 1,
3184
+ instanceId: configuration.instanceId,
3185
+ packs: engine?.inspect().packs ?? [],
3186
+ ready: isReady,
3187
+ tier: configuration.tier
3188
+ };
3189
+ });
3144
3190
  return {
3145
3191
  app,
3146
3192
  configuration,
3193
+ dispose,
3147
3194
  engine,
3148
3195
  hub,
3149
- metrics: () => engine?.metrics() ?? null
3196
+ metrics: () => engine?.metrics() ?? null,
3197
+ ready
3150
3198
  };
3151
3199
  };
3152
3200
  export {
@@ -3158,5 +3206,5 @@ export {
3158
3206
  PLATFORM_SYNC_ENVIRONMENT_KEY
3159
3207
  };
3160
3208
 
3161
- //# debugId=3093A4FC38575BA364756E2164756E21
3209
+ //# debugId=794AB659205BD12164756E2164756E21
3162
3210
  //# sourceMappingURL=platform.js.map