@wishknish/knishio-client-ts 0.8.2 → 0.8.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wishknish/knishio-client-ts",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "productName": "Knish.IO TypeScript SDK Client",
5
5
  "description": "TypeScript implementation of the Knish.IO SDK to consume Knish.IO GraphQL APIs with enhanced type safety.",
6
6
  "license": "GPL-3.0-or-later",
@@ -136,7 +136,8 @@ import type {
136
136
  MetaType,
137
137
  MetaId,
138
138
  BatchId,
139
- MetaFilter
139
+ MetaFilter,
140
+ RequestPolicy
140
141
  } from '@/types'
141
142
 
142
143
  /**
@@ -152,6 +153,10 @@ export default class KnishIOClient {
152
153
  private $__client!: GraphQLClient
153
154
  private $__serverSdkVersion: number = 3
154
155
  private $__logging: boolean = false
156
+ // Default urql request policy applied to reads when the caller doesn't pass
157
+ // one. null = urql's default (cache-first). Server/sync clients set this to
158
+ // 'network-only' so a long-lived client never serves a stale cached read.
159
+ private $__defaultRequestPolicy: RequestPolicy | null = null
155
160
  private $__authTokenObjects: Record<string, AuthToken | null> = {}
156
161
  private $__authToken: AuthToken | null = null
157
162
  private $__authInProcess: boolean = false
@@ -176,6 +181,7 @@ export default class KnishIOClient {
176
181
  socket?: { socketUri: string | null; appKey?: string } | null
177
182
  serverSdkVersion?: number
178
183
  logging?: boolean
184
+ defaultRequestPolicy?: RequestPolicy | null
179
185
  }) {
180
186
  // Phase 2 Enhancement: Use standardized configuration validation
181
187
  const standardValidationResult = ConfigValidator.validateClientConfig(config)
@@ -213,14 +219,19 @@ export default class KnishIOClient {
213
219
  serverSdkVersion = 3,
214
220
  logging = false
215
221
  } = validatedConfig
216
-
222
+ // Read from the RAW config: defaultRequestPolicy is an optional add-on the
223
+ // strict schema now permits, but the validated/inferred shape may not carry
224
+ // it depending on the parser, so take it straight from the caller's config.
225
+ const defaultRequestPolicy = (config.defaultRequestPolicy ?? null) as RequestPolicy | null
226
+
217
227
  this.initialize({
218
228
  uri: uri as string | string[],
219
229
  cellSlug: cellSlug as string | null,
220
230
  socket: socket as { socketUri: string | null; appKey?: string } | null,
221
231
  client: client as GraphQLClient | null,
222
232
  serverSdkVersion,
223
- logging
233
+ logging,
234
+ defaultRequestPolicy
224
235
  })
225
236
  }
226
237
 
@@ -233,7 +244,8 @@ export default class KnishIOClient {
233
244
  socket = null,
234
245
  client = null,
235
246
  serverSdkVersion = 3,
236
- logging = false
247
+ logging = false,
248
+ defaultRequestPolicy = null
237
249
  }: {
238
250
  uri: string | string[]
239
251
  cellSlug?: string | null
@@ -241,6 +253,7 @@ export default class KnishIOClient {
241
253
  client?: GraphQLClient | null
242
254
  serverSdkVersion?: number
243
255
  logging?: boolean
256
+ defaultRequestPolicy?: RequestPolicy | null
244
257
  }): void {
245
258
  this.reset()
246
259
 
@@ -269,6 +282,9 @@ export default class KnishIOClient {
269
282
  })
270
283
 
271
284
  this.$__serverSdkVersion = serverSdkVersion
285
+ // Config (not session state) — set here, NOT cleared in reset(), mirroring
286
+ // serverSdkVersion. A re-initialize updates it.
287
+ this.$__defaultRequestPolicy = defaultRequestPolicy
272
288
  }
273
289
 
274
290
  /**
@@ -324,6 +340,22 @@ export default class KnishIOClient {
324
340
  return this.$__serverSdkVersion
325
341
  }
326
342
 
343
+ /**
344
+ * Gets the client's default urql request policy (null = urql default).
345
+ */
346
+ getDefaultRequestPolicy(): RequestPolicy | null {
347
+ return this.$__defaultRequestPolicy
348
+ }
349
+
350
+ /**
351
+ * Sets the default urql request policy applied to reads that don't specify
352
+ * one. Pass 'network-only' on a long-lived server/sync client so it never
353
+ * serves a stale cached read; null restores urql's default (cache-first).
354
+ */
355
+ setDefaultRequestPolicy(policy: RequestPolicy | null): void {
356
+ this.$__defaultRequestPolicy = policy
357
+ }
358
+
327
359
  /**
328
360
  * Reset common properties
329
361
  */
@@ -596,7 +628,16 @@ export default class KnishIOClient {
596
628
 
597
629
  // Execute the query/mutation, forwarding any urql context (e.g.
598
630
  // requestPolicy) assembled by the caller (queryMeta) / createQueryContext().
599
- return await query.execute({ variables: variables || {}, context })
631
+ // When the caller did NOT specify a request policy, fall back to this
632
+ // client's defaultRequestPolicy (e.g. a long-lived server/sync client set
633
+ // to 'network-only' so it never serves a stale read from the urql cache —
634
+ // removing the footgun of having to pass network-only on every call).
635
+ // Precedence: per-call context.requestPolicy > client default > a query's
636
+ // own createQueryContext() (e.g. ContinuId) > urql default.
637
+ const effectiveContext = (this.$__defaultRequestPolicy && !(context as Record<string, any>).requestPolicy)
638
+ ? { requestPolicy: this.$__defaultRequestPolicy, ...context }
639
+ : context
640
+ return await query.execute({ variables: variables || {}, context: effectiveContext })
600
641
  }
601
642
 
602
643
  /**
@@ -191,7 +191,8 @@ export const KnishIOClientConfigSchema = z.object({
191
191
  client: z.unknown().optional(),
192
192
  socket: z.unknown().optional(),
193
193
  serverSdkVersion: z.number().int().min(1).optional(),
194
- logging: z.boolean().optional()
194
+ logging: z.boolean().optional(),
195
+ defaultRequestPolicy: z.enum(['cache-first', 'cache-only', 'network-only', 'cache-and-network']).nullable().optional()
195
196
  }).strict()
196
197
 
197
198
  // =============================================================================
@@ -371,6 +371,12 @@ export interface SignatureResult {
371
371
  // GRAPHQL OPERATION TYPES
372
372
  // =============================================================================
373
373
 
374
+ /**
375
+ * urql request policy (mirrors @urql/core's RequestPolicy). Controls whether a
376
+ * read hits the client's in-memory cache. 'network-only' bypasses it entirely.
377
+ */
378
+ export type RequestPolicy = 'cache-first' | 'cache-only' | 'network-only' | 'cache-and-network'
379
+
374
380
  export interface GraphQLRequest {
375
381
  query: string
376
382
  variables?: Record<string, unknown>
@@ -206,7 +206,11 @@ export const KnishIOClientConfigSchema = z.object({
206
206
  client: z.unknown().optional(),
207
207
  socket: z.unknown().optional(),
208
208
  serverSdkVersion: z.number().int().min(1).max(10).default(4),
209
- logging: z.boolean().default(false)
209
+ logging: z.boolean().default(false),
210
+ // Optional default urql request policy for reads (server/sync clients pass
211
+ // 'network-only'). Permitted by the strict schema so the constructor option
212
+ // isn't rejected.
213
+ defaultRequestPolicy: z.enum(['cache-first', 'cache-only', 'network-only', 'cache-and-network']).nullable().optional()
210
214
  }).strict()
211
215
 
212
216
  // Environment configuration with validation