@wishknish/knishio-client-ts 0.8.1 → 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/dist/index.cjs CHANGED
@@ -3812,7 +3812,8 @@ zod.z.object({
3812
3812
  client: zod.z.unknown().optional(),
3813
3813
  socket: zod.z.unknown().optional(),
3814
3814
  serverSdkVersion: zod.z.number().int().min(1).optional(),
3815
- logging: zod.z.boolean().optional()
3815
+ logging: zod.z.boolean().optional(),
3816
+ defaultRequestPolicy: zod.z.enum(["cache-first", "cache-only", "network-only", "cache-and-network"]).nullable().optional()
3816
3817
  }).strict();
3817
3818
  zod.z.object({
3818
3819
  token: zod.z.string().min(1, "Auth token cannot be empty"),
@@ -5826,14 +5827,14 @@ var GraphQLClient = class {
5826
5827
  });
5827
5828
  }
5828
5829
  async query(request) {
5829
- const { query, variables } = request;
5830
- const result = await this.$__client.query(query, variables || {}).toPromise();
5830
+ const { query, variables, context } = request;
5831
+ const result = await this.$__client.query(query, variables || {}, context).toPromise();
5831
5832
  return this.formatResponse(result);
5832
5833
  }
5833
5834
  async mutation(request) {
5834
- const { query, variables } = request;
5835
+ const { query, variables, context } = request;
5835
5836
  const mutationString = request.mutation || query;
5836
- const result = await this.$__client.mutation(mutationString, variables || {}).toPromise();
5837
+ const result = await this.$__client.mutation(mutationString, variables || {}, context).toPromise();
5837
5838
  return this.formatResponse(result);
5838
5839
  }
5839
5840
  // Alias for mutation() to match JS SDK interface
@@ -6342,7 +6343,11 @@ var KnishIOClientConfigSchema2 = zod.z.object({
6342
6343
  client: zod.z.unknown().optional(),
6343
6344
  socket: zod.z.unknown().optional(),
6344
6345
  serverSdkVersion: zod.z.number().int().min(1).max(10).default(4),
6345
- logging: zod.z.boolean().default(false)
6346
+ logging: zod.z.boolean().default(false),
6347
+ // Optional default urql request policy for reads (server/sync clients pass
6348
+ // 'network-only'). Permitted by the strict schema so the constructor option
6349
+ // isn't rejected.
6350
+ defaultRequestPolicy: zod.z.enum(["cache-first", "cache-only", "network-only", "cache-and-network"]).nullable().optional()
6346
6351
  }).strict();
6347
6352
  var EnvironmentConfigSchema = zod.z.object({
6348
6353
  NODE_ENV: zod.z.enum(["development", "production", "test"]).default("development"),
@@ -10070,6 +10075,10 @@ var KnishIOClient = class {
10070
10075
  $__client;
10071
10076
  $__serverSdkVersion = 3;
10072
10077
  $__logging = false;
10078
+ // Default urql request policy applied to reads when the caller doesn't pass
10079
+ // one. null = urql's default (cache-first). Server/sync clients set this to
10080
+ // 'network-only' so a long-lived client never serves a stale cached read.
10081
+ $__defaultRequestPolicy = null;
10073
10082
  $__authTokenObjects = {};
10074
10083
  $__authToken = null;
10075
10084
  $__authInProcess = false;
@@ -10109,13 +10118,15 @@ var KnishIOClient = class {
10109
10118
  serverSdkVersion = 3,
10110
10119
  logging = false
10111
10120
  } = validatedConfig;
10121
+ const defaultRequestPolicy = config.defaultRequestPolicy ?? null;
10112
10122
  this.initialize({
10113
10123
  uri,
10114
10124
  cellSlug,
10115
10125
  socket,
10116
10126
  client,
10117
10127
  serverSdkVersion,
10118
- logging
10128
+ logging,
10129
+ defaultRequestPolicy
10119
10130
  });
10120
10131
  }
10121
10132
  /**
@@ -10127,7 +10138,8 @@ var KnishIOClient = class {
10127
10138
  socket = null,
10128
10139
  client = null,
10129
10140
  serverSdkVersion = 3,
10130
- logging = false
10141
+ logging = false,
10142
+ defaultRequestPolicy = null
10131
10143
  }) {
10132
10144
  this.reset();
10133
10145
  this.$__logging = logging;
@@ -10149,6 +10161,7 @@ var KnishIOClient = class {
10149
10161
  encrypt: this.$__encrypt
10150
10162
  });
10151
10163
  this.$__serverSdkVersion = serverSdkVersion;
10164
+ this.$__defaultRequestPolicy = defaultRequestPolicy;
10152
10165
  }
10153
10166
  /**
10154
10167
  * Get random uri from specified this.$__uris
@@ -10196,6 +10209,20 @@ var KnishIOClient = class {
10196
10209
  getServerSdkVersion() {
10197
10210
  return this.$__serverSdkVersion;
10198
10211
  }
10212
+ /**
10213
+ * Gets the client's default urql request policy (null = urql default).
10214
+ */
10215
+ getDefaultRequestPolicy() {
10216
+ return this.$__defaultRequestPolicy;
10217
+ }
10218
+ /**
10219
+ * Sets the default urql request policy applied to reads that don't specify
10220
+ * one. Pass 'network-only' on a long-lived server/sync client so it never
10221
+ * serves a stale cached read; null restores urql's default (cache-first).
10222
+ */
10223
+ setDefaultRequestPolicy(policy) {
10224
+ this.$__defaultRequestPolicy = policy;
10225
+ }
10199
10226
  /**
10200
10227
  * Reset common properties
10201
10228
  */
@@ -10384,7 +10411,7 @@ var KnishIOClient = class {
10384
10411
  /**
10385
10412
  * Executes a query or mutation
10386
10413
  */
10387
- async executeQuery(query, variables = null) {
10414
+ async executeQuery(query, variables = null, context = {}) {
10388
10415
  if (this.$__authToken && this.$__authToken.isExpired() && !this.$__authInProcess) {
10389
10416
  this.log("info", "KnishIOClient::executeQuery() - Access token is expired. Getting new one...");
10390
10417
  await this.requestAuthToken({
@@ -10400,7 +10427,8 @@ var KnishIOClient = class {
10400
10427
  return response;
10401
10428
  });
10402
10429
  }
10403
- return await query.execute({ variables: variables || {} });
10430
+ const effectiveContext = this.$__defaultRequestPolicy && !context.requestPolicy ? { requestPolicy: this.$__defaultRequestPolicy, ...context } : context;
10431
+ return await query.execute({ variables: variables || {}, context: effectiveContext });
10404
10432
  }
10405
10433
  /**
10406
10434
  * When a ProposeMolecule submission is rejected for a position-related
@@ -10733,7 +10761,8 @@ var KnishIOClient = class {
10733
10761
  throughMolecule = false,
10734
10762
  values = null,
10735
10763
  keys = null,
10736
- atomValues = null
10764
+ atomValues = null,
10765
+ requestPolicy = null
10737
10766
  }) {
10738
10767
  this.log("info", `KnishIOClient::queryMeta() - Querying metaType: ${metaType}, metaId: ${metaId}...`);
10739
10768
  let query;
@@ -10785,7 +10814,8 @@ var KnishIOClient = class {
10785
10814
  cellSlug: this.getCellSlug()
10786
10815
  });
10787
10816
  }
10788
- return this.executeQuery(query, variables);
10817
+ const context = requestPolicy ? { requestPolicy } : {};
10818
+ return this.executeQuery(query, variables, context);
10789
10819
  }
10790
10820
  /**
10791
10821
  * Queries meta assets and verifies cryptographic integrity of associated molecules.