@gencow/core 0.1.15 → 0.1.16

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.
@@ -48,7 +48,7 @@ export interface AIResult {
48
48
  model: string;
49
49
  }
50
50
  export interface AIContext {
51
- /** AI 텍스트 생성 — ctx.ai.chat({ model, messages }) */
51
+ /** AI 텍스트 생성 */
52
52
  chat: (opts: {
53
53
  model?: string;
54
54
  messages: AIMessage[];
@@ -61,9 +61,9 @@ export interface AIContext {
61
61
  type: string;
62
62
  };
63
63
  }) => Promise<AIResult>;
64
- /** 텍스트 임베딩 (단일) — ctx.ai.embed("검색 텍스트") */
64
+ /** 텍스트 임베딩 (단일) */
65
65
  embed: (text: string) => Promise<number[]>;
66
- /** 배치 임베딩 — ctx.ai.embedMany(["텍스트1", "텍스트2"]) */
66
+ /** 배치 임베딩 */
67
67
  embedMany: (texts: string[]) => Promise<number[][]>;
68
68
  }
69
69
  export interface GencowCtx {
@@ -81,7 +81,7 @@ export interface GencowCtx {
81
81
  realtime: RealtimeCtx;
82
82
  /** 재시도 — ctx.retry(fn, opts) — exponential backoff + jitter */
83
83
  retry: <T>(fn: () => Promise<T>, options?: import("./retry").RetryOptions) => Promise<T>;
84
- /** AI 헬퍼 — ctx.ai.chat({ model, messages }) — 로컬: 직접 호출, BaaS: Control Plane 프록시 */
84
+ /** AI 헬퍼 */
85
85
  ai?: AIContext;
86
86
  }
87
87
  type QueryHandler<TArgs = any, TReturn = any> = (ctx: GencowCtx, args: TArgs) => Promise<TReturn>;
@@ -248,8 +248,18 @@ export declare function deregisterClient(ws: WSContext): void;
248
248
  * 마지막 데이터만 push하여 불필요한 전송을 방지합니다.
249
249
  *
250
250
  * ⚠️ 매 mutation 호출마다 새로 생성해야 합니다 (debounce timer가 mutation scope에 격리).
251
+ *
252
+ * @param options.httpCallback BaaS 모드: Platform WS Gateway에 HTTP로 emit 전달.
253
+ * 설정되면 WS 직접 push 대신 이 콜백을 호출.
254
+ * 로컬 dev에서는 미설정 → 기존 WS 직접 push 유지.
251
255
  */
252
- export declare function buildRealtimeCtx(): RealtimeCtx;
256
+ export declare function buildRealtimeCtx(options?: {
257
+ httpCallback?: (event: {
258
+ type: "emit";
259
+ queryKey: string;
260
+ data: unknown;
261
+ }) => void;
262
+ }): RealtimeCtx;
253
263
  /**
254
264
  * mutation이 끝난 후 호출되는 legacy fallback.
255
265
  * `ctx.realtime.emit()`을 사용하는 새 mutation에서는 빈 배열([])을 전달하면 됩니다.
@@ -258,8 +268,9 @@ export declare function buildRealtimeCtx(): RealtimeCtx;
258
268
  * (서버에서 쿼리를 재실행하지 않으므로 DB 부하 없음)
259
269
  *
260
270
  * @deprecated ctx.realtime.emit() 사용 권장
271
+ * @param httpInvalidateCallback BaaS 모드: Platform WS Gateway에 HTTP로 invalidation 전달.
261
272
  */
262
- export declare function invalidateQueries(queryKeys: string[], ctx: GencowCtx): Promise<void>;
273
+ export declare function invalidateQueries(queryKeys: string[], ctx: GencowCtx, httpInvalidateCallback?: (queryKeys: string[]) => void): Promise<void>;
263
274
  export declare function handleWsMessage(ws: WSContext, raw: string | ArrayBuffer): void;
264
275
  export declare function getQueryHandler(key: string): QueryHandler | undefined;
265
276
  export declare function getQueryDef(key: string): QueryDef | undefined;
package/dist/reactive.js CHANGED
@@ -181,8 +181,12 @@ export function deregisterClient(ws) {
181
181
  * 마지막 데이터만 push하여 불필요한 전송을 방지합니다.
182
182
  *
183
183
  * ⚠️ 매 mutation 호출마다 새로 생성해야 합니다 (debounce timer가 mutation scope에 격리).
184
+ *
185
+ * @param options.httpCallback BaaS 모드: Platform WS Gateway에 HTTP로 emit 전달.
186
+ * 설정되면 WS 직접 push 대신 이 콜백을 호출.
187
+ * 로컬 dev에서는 미설정 → 기존 WS 직접 push 유지.
184
188
  */
185
- export function buildRealtimeCtx() {
189
+ export function buildRealtimeCtx(options) {
186
190
  const pendingEmits = new Map();
187
191
  return {
188
192
  emit(queryKey, data) {
@@ -192,6 +196,12 @@ export function buildRealtimeCtx() {
192
196
  clearTimeout(existing.timer);
193
197
  const timer = setTimeout(() => {
194
198
  pendingEmits.delete(queryKey);
199
+ // BaaS 모드: Platform WS Gateway에 HTTP callback
200
+ if (options?.httpCallback) {
201
+ options.httpCallback({ type: "emit", queryKey, data });
202
+ return;
203
+ }
204
+ // 로컬 dev: WS 직접 push (기존 동작)
195
205
  const clients = subscribers.get(queryKey);
196
206
  if (!clients || clients.size === 0)
197
207
  return;
@@ -221,11 +231,17 @@ export function buildRealtimeCtx() {
221
231
  * (서버에서 쿼리를 재실행하지 않으므로 DB 부하 없음)
222
232
  *
223
233
  * @deprecated ctx.realtime.emit() 사용 권장
234
+ * @param httpInvalidateCallback BaaS 모드: Platform WS Gateway에 HTTP로 invalidation 전달.
224
235
  */
225
- export async function invalidateQueries(queryKeys, ctx) {
236
+ export async function invalidateQueries(queryKeys, ctx, httpInvalidateCallback) {
226
237
  if (queryKeys.length === 0)
227
238
  return; // emit() 방식에서는 no-op
228
- // invalidate 신호만 broadcast (re-fetch는 클라이언트 결정에 맡김)
239
+ // BaaS 모드: Platform WS Gateway에 HTTP callback
240
+ if (httpInvalidateCallback) {
241
+ httpInvalidateCallback(queryKeys);
242
+ return;
243
+ }
244
+ // 로컬 dev: WS 직접 broadcast (기존 동작)
229
245
  const invalidateMsg = JSON.stringify({ type: "invalidate", queries: queryKeys });
230
246
  for (const ws of connectedClients) {
231
247
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gencow/core",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Gencow core library — defineQuery, defineMutation, reactive subscriptions",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/reactive.ts CHANGED
@@ -54,7 +54,7 @@ export interface AIResult {
54
54
  }
55
55
 
56
56
  export interface AIContext {
57
- /** AI 텍스트 생성 — ctx.ai.chat({ model, messages }) */
57
+ /** AI 텍스트 생성 */
58
58
  chat: (opts: {
59
59
  model?: string;
60
60
  messages: AIMessage[];
@@ -65,9 +65,9 @@ export interface AIContext {
65
65
  /** Response format — e.g. { type: "json_object" } for JSON mode */
66
66
  responseFormat?: { type: string };
67
67
  }) => Promise<AIResult>;
68
- /** 텍스트 임베딩 (단일) — ctx.ai.embed("검색 텍스트") */
68
+ /** 텍스트 임베딩 (단일) */
69
69
  embed: (text: string) => Promise<number[]>;
70
- /** 배치 임베딩 — ctx.ai.embedMany(["텍스트1", "텍스트2"]) */
70
+ /** 배치 임베딩 */
71
71
  embedMany: (texts: string[]) => Promise<number[][]>;
72
72
  }
73
73
 
@@ -86,7 +86,7 @@ export interface GencowCtx {
86
86
  realtime: RealtimeCtx;
87
87
  /** 재시도 — ctx.retry(fn, opts) — exponential backoff + jitter */
88
88
  retry: <T>(fn: () => Promise<T>, options?: import("./retry").RetryOptions) => Promise<T>;
89
- /** AI 헬퍼 — ctx.ai.chat({ model, messages }) — 로컬: 직접 호출, BaaS: Control Plane 프록시 */
89
+ /** AI 헬퍼 */
90
90
  ai?: AIContext;
91
91
  }
92
92
 
@@ -392,8 +392,14 @@ export function deregisterClient(ws: WSContext) {
392
392
  * 마지막 데이터만 push하여 불필요한 전송을 방지합니다.
393
393
  *
394
394
  * ⚠️ 매 mutation 호출마다 새로 생성해야 합니다 (debounce timer가 mutation scope에 격리).
395
+ *
396
+ * @param options.httpCallback BaaS 모드: Platform WS Gateway에 HTTP로 emit 전달.
397
+ * 설정되면 WS 직접 push 대신 이 콜백을 호출.
398
+ * 로컬 dev에서는 미설정 → 기존 WS 직접 push 유지.
395
399
  */
396
- export function buildRealtimeCtx(): RealtimeCtx {
400
+ export function buildRealtimeCtx(options?: {
401
+ httpCallback?: (event: { type: "emit"; queryKey: string; data: unknown }) => void;
402
+ }): RealtimeCtx {
397
403
  const pendingEmits = new Map<string, { data: unknown; timer: ReturnType<typeof setTimeout> }>();
398
404
 
399
405
  return {
@@ -404,6 +410,14 @@ export function buildRealtimeCtx(): RealtimeCtx {
404
410
 
405
411
  const timer = setTimeout(() => {
406
412
  pendingEmits.delete(queryKey);
413
+
414
+ // BaaS 모드: Platform WS Gateway에 HTTP callback
415
+ if (options?.httpCallback) {
416
+ options.httpCallback({ type: "emit", queryKey, data });
417
+ return;
418
+ }
419
+
420
+ // 로컬 dev: WS 직접 push (기존 동작)
407
421
  const clients = subscribers.get(queryKey);
408
422
  if (!clients || clients.size === 0) return;
409
423
 
@@ -430,14 +444,22 @@ export function buildRealtimeCtx(): RealtimeCtx {
430
444
  * (서버에서 쿼리를 재실행하지 않으므로 DB 부하 없음)
431
445
  *
432
446
  * @deprecated ctx.realtime.emit() 사용 권장
447
+ * @param httpInvalidateCallback BaaS 모드: Platform WS Gateway에 HTTP로 invalidation 전달.
433
448
  */
434
449
  export async function invalidateQueries(
435
450
  queryKeys: string[],
436
- ctx: GencowCtx
451
+ ctx: GencowCtx,
452
+ httpInvalidateCallback?: (queryKeys: string[]) => void,
437
453
  ): Promise<void> {
438
454
  if (queryKeys.length === 0) return; // emit() 방식에서는 no-op
439
455
 
440
- // invalidate 신호만 broadcast (re-fetch는 클라이언트 결정에 맡김)
456
+ // BaaS 모드: Platform WS Gateway에 HTTP callback
457
+ if (httpInvalidateCallback) {
458
+ httpInvalidateCallback(queryKeys);
459
+ return;
460
+ }
461
+
462
+ // 로컬 dev: WS 직접 broadcast (기존 동작)
441
463
  const invalidateMsg = JSON.stringify({ type: "invalidate", queries: queryKeys });
442
464
  for (const ws of connectedClients) {
443
465
  try { ws.send(invalidateMsg); } catch { connectedClients.delete(ws); }