@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 +42 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.iife.js +42 -12
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +42 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/KnishIOClient.ts +65 -9
- package/src/libraries/GraphQLClient.ts +7 -4
- package/src/schemas/index.ts +2 -1
- package/src/types/index.ts +13 -0
- package/src/validation/schemas.ts +5 -1
package/dist/index.d.cts
CHANGED
|
@@ -274,10 +274,12 @@ interface ValidationResult$1 {
|
|
|
274
274
|
expected?: string;
|
|
275
275
|
actual?: unknown;
|
|
276
276
|
}
|
|
277
|
+
type RequestPolicy = 'cache-first' | 'cache-only' | 'network-only' | 'cache-and-network';
|
|
277
278
|
interface GraphQLRequest {
|
|
278
279
|
query: string;
|
|
279
280
|
variables?: Record<string, unknown>;
|
|
280
281
|
operationName?: string | null;
|
|
282
|
+
context?: Record<string, unknown>;
|
|
281
283
|
}
|
|
282
284
|
interface GraphQLResponse<T = unknown> {
|
|
283
285
|
data?: T | null;
|
|
@@ -1118,6 +1120,7 @@ declare class KnishIOClient {
|
|
|
1118
1120
|
private $__client;
|
|
1119
1121
|
private $__serverSdkVersion;
|
|
1120
1122
|
private $__logging;
|
|
1123
|
+
private $__defaultRequestPolicy;
|
|
1121
1124
|
private $__authTokenObjects;
|
|
1122
1125
|
private $__authToken;
|
|
1123
1126
|
private $__authInProcess;
|
|
@@ -1136,8 +1139,9 @@ declare class KnishIOClient {
|
|
|
1136
1139
|
} | null;
|
|
1137
1140
|
serverSdkVersion?: number;
|
|
1138
1141
|
logging?: boolean;
|
|
1142
|
+
defaultRequestPolicy?: RequestPolicy | null;
|
|
1139
1143
|
});
|
|
1140
|
-
initialize({ uri, cellSlug, socket, client, serverSdkVersion, logging }: {
|
|
1144
|
+
initialize({ uri, cellSlug, socket, client, serverSdkVersion, logging, defaultRequestPolicy }: {
|
|
1141
1145
|
uri: string | string[];
|
|
1142
1146
|
cellSlug?: string | null;
|
|
1143
1147
|
socket?: {
|
|
@@ -1147,12 +1151,15 @@ declare class KnishIOClient {
|
|
|
1147
1151
|
client?: GraphQLClient | null;
|
|
1148
1152
|
serverSdkVersion?: number;
|
|
1149
1153
|
logging?: boolean;
|
|
1154
|
+
defaultRequestPolicy?: RequestPolicy | null;
|
|
1150
1155
|
}): void;
|
|
1151
1156
|
getRandomUri(): string;
|
|
1152
1157
|
switchEncryption(encrypt: boolean): boolean;
|
|
1153
1158
|
deinitialize(): void;
|
|
1154
1159
|
subscribe(): GraphQLClient;
|
|
1155
1160
|
getServerSdkVersion(): number;
|
|
1161
|
+
getDefaultRequestPolicy(): RequestPolicy | null;
|
|
1162
|
+
setDefaultRequestPolicy(policy: RequestPolicy | null): void;
|
|
1156
1163
|
reset(): void;
|
|
1157
1164
|
client(): GraphQLClient;
|
|
1158
1165
|
setUri(uri: string | string[]): void;
|
|
@@ -1177,7 +1184,7 @@ declare class KnishIOClient {
|
|
|
1177
1184
|
molecule?: Molecule | null;
|
|
1178
1185
|
}): Promise<T>;
|
|
1179
1186
|
private withMoleculeLock;
|
|
1180
|
-
executeQuery(query: Query | Mutation, variables?: Record<string, any> | null): Promise<Response | null>;
|
|
1187
|
+
executeQuery(query: Query | Mutation, variables?: Record<string, any> | null, context?: Record<string, any>): Promise<Response | null>;
|
|
1181
1188
|
private handlePositionDrift;
|
|
1182
1189
|
setSecret(secret: string): void;
|
|
1183
1190
|
setAuthToken(authToken: AuthToken): void;
|
|
@@ -1226,7 +1233,7 @@ declare class KnishIOClient {
|
|
|
1226
1233
|
queryContinuId({ bundle }: {
|
|
1227
1234
|
bundle: BundleHash | string;
|
|
1228
1235
|
}): Promise<Response>;
|
|
1229
|
-
queryMeta({ metaType, metaId, key, value, latest, fields: _fields, filter, queryArgs, count, countBy, throughAtom, throughMolecule, values, keys, atomValues }: {
|
|
1236
|
+
queryMeta({ metaType, metaId, key, value, latest, fields: _fields, filter, queryArgs, count, countBy, throughAtom, throughMolecule, values, keys, atomValues, requestPolicy }: {
|
|
1230
1237
|
metaType: MetaType | string;
|
|
1231
1238
|
metaId?: MetaId | string | null;
|
|
1232
1239
|
key?: string | null;
|
|
@@ -1242,6 +1249,7 @@ declare class KnishIOClient {
|
|
|
1242
1249
|
values?: any[] | null;
|
|
1243
1250
|
keys?: string[] | null;
|
|
1244
1251
|
atomValues?: any[] | null;
|
|
1252
|
+
requestPolicy?: 'cache-first' | 'cache-only' | 'network-only' | 'cache-and-network' | null;
|
|
1245
1253
|
}): Promise<Response>;
|
|
1246
1254
|
queryMetaVerified(params: {
|
|
1247
1255
|
metaType: MetaType | string;
|
package/dist/index.d.ts
CHANGED
|
@@ -274,10 +274,12 @@ interface ValidationResult$1 {
|
|
|
274
274
|
expected?: string;
|
|
275
275
|
actual?: unknown;
|
|
276
276
|
}
|
|
277
|
+
type RequestPolicy = 'cache-first' | 'cache-only' | 'network-only' | 'cache-and-network';
|
|
277
278
|
interface GraphQLRequest {
|
|
278
279
|
query: string;
|
|
279
280
|
variables?: Record<string, unknown>;
|
|
280
281
|
operationName?: string | null;
|
|
282
|
+
context?: Record<string, unknown>;
|
|
281
283
|
}
|
|
282
284
|
interface GraphQLResponse<T = unknown> {
|
|
283
285
|
data?: T | null;
|
|
@@ -1118,6 +1120,7 @@ declare class KnishIOClient {
|
|
|
1118
1120
|
private $__client;
|
|
1119
1121
|
private $__serverSdkVersion;
|
|
1120
1122
|
private $__logging;
|
|
1123
|
+
private $__defaultRequestPolicy;
|
|
1121
1124
|
private $__authTokenObjects;
|
|
1122
1125
|
private $__authToken;
|
|
1123
1126
|
private $__authInProcess;
|
|
@@ -1136,8 +1139,9 @@ declare class KnishIOClient {
|
|
|
1136
1139
|
} | null;
|
|
1137
1140
|
serverSdkVersion?: number;
|
|
1138
1141
|
logging?: boolean;
|
|
1142
|
+
defaultRequestPolicy?: RequestPolicy | null;
|
|
1139
1143
|
});
|
|
1140
|
-
initialize({ uri, cellSlug, socket, client, serverSdkVersion, logging }: {
|
|
1144
|
+
initialize({ uri, cellSlug, socket, client, serverSdkVersion, logging, defaultRequestPolicy }: {
|
|
1141
1145
|
uri: string | string[];
|
|
1142
1146
|
cellSlug?: string | null;
|
|
1143
1147
|
socket?: {
|
|
@@ -1147,12 +1151,15 @@ declare class KnishIOClient {
|
|
|
1147
1151
|
client?: GraphQLClient | null;
|
|
1148
1152
|
serverSdkVersion?: number;
|
|
1149
1153
|
logging?: boolean;
|
|
1154
|
+
defaultRequestPolicy?: RequestPolicy | null;
|
|
1150
1155
|
}): void;
|
|
1151
1156
|
getRandomUri(): string;
|
|
1152
1157
|
switchEncryption(encrypt: boolean): boolean;
|
|
1153
1158
|
deinitialize(): void;
|
|
1154
1159
|
subscribe(): GraphQLClient;
|
|
1155
1160
|
getServerSdkVersion(): number;
|
|
1161
|
+
getDefaultRequestPolicy(): RequestPolicy | null;
|
|
1162
|
+
setDefaultRequestPolicy(policy: RequestPolicy | null): void;
|
|
1156
1163
|
reset(): void;
|
|
1157
1164
|
client(): GraphQLClient;
|
|
1158
1165
|
setUri(uri: string | string[]): void;
|
|
@@ -1177,7 +1184,7 @@ declare class KnishIOClient {
|
|
|
1177
1184
|
molecule?: Molecule | null;
|
|
1178
1185
|
}): Promise<T>;
|
|
1179
1186
|
private withMoleculeLock;
|
|
1180
|
-
executeQuery(query: Query | Mutation, variables?: Record<string, any> | null): Promise<Response | null>;
|
|
1187
|
+
executeQuery(query: Query | Mutation, variables?: Record<string, any> | null, context?: Record<string, any>): Promise<Response | null>;
|
|
1181
1188
|
private handlePositionDrift;
|
|
1182
1189
|
setSecret(secret: string): void;
|
|
1183
1190
|
setAuthToken(authToken: AuthToken): void;
|
|
@@ -1226,7 +1233,7 @@ declare class KnishIOClient {
|
|
|
1226
1233
|
queryContinuId({ bundle }: {
|
|
1227
1234
|
bundle: BundleHash | string;
|
|
1228
1235
|
}): Promise<Response>;
|
|
1229
|
-
queryMeta({ metaType, metaId, key, value, latest, fields: _fields, filter, queryArgs, count, countBy, throughAtom, throughMolecule, values, keys, atomValues }: {
|
|
1236
|
+
queryMeta({ metaType, metaId, key, value, latest, fields: _fields, filter, queryArgs, count, countBy, throughAtom, throughMolecule, values, keys, atomValues, requestPolicy }: {
|
|
1230
1237
|
metaType: MetaType | string;
|
|
1231
1238
|
metaId?: MetaId | string | null;
|
|
1232
1239
|
key?: string | null;
|
|
@@ -1242,6 +1249,7 @@ declare class KnishIOClient {
|
|
|
1242
1249
|
values?: any[] | null;
|
|
1243
1250
|
keys?: string[] | null;
|
|
1244
1251
|
atomValues?: any[] | null;
|
|
1252
|
+
requestPolicy?: 'cache-first' | 'cache-only' | 'network-only' | 'cache-and-network' | null;
|
|
1245
1253
|
}): Promise<Response>;
|
|
1246
1254
|
queryMetaVerified(params: {
|
|
1247
1255
|
metaType: MetaType | string;
|
package/dist/index.iife.js
CHANGED
|
@@ -24045,7 +24045,8 @@ ${operationTypes.join("\n")}
|
|
|
24045
24045
|
client: external_exports.unknown().optional(),
|
|
24046
24046
|
socket: external_exports.unknown().optional(),
|
|
24047
24047
|
serverSdkVersion: external_exports.number().int().min(1).optional(),
|
|
24048
|
-
logging: external_exports.boolean().optional()
|
|
24048
|
+
logging: external_exports.boolean().optional(),
|
|
24049
|
+
defaultRequestPolicy: external_exports.enum(["cache-first", "cache-only", "network-only", "cache-and-network"]).nullable().optional()
|
|
24049
24050
|
}).strict();
|
|
24050
24051
|
external_exports.object({
|
|
24051
24052
|
token: external_exports.string().min(1, "Auth token cannot be empty"),
|
|
@@ -28486,14 +28487,14 @@ ${operationTypes.join("\n")}
|
|
|
28486
28487
|
});
|
|
28487
28488
|
}
|
|
28488
28489
|
async query(request) {
|
|
28489
|
-
const { query, variables } = request;
|
|
28490
|
-
const result = await this.$__client.query(query, variables || {}).toPromise();
|
|
28490
|
+
const { query, variables, context } = request;
|
|
28491
|
+
const result = await this.$__client.query(query, variables || {}, context).toPromise();
|
|
28491
28492
|
return this.formatResponse(result);
|
|
28492
28493
|
}
|
|
28493
28494
|
async mutation(request) {
|
|
28494
|
-
const { query, variables } = request;
|
|
28495
|
+
const { query, variables, context } = request;
|
|
28495
28496
|
const mutationString = request.mutation || query;
|
|
28496
|
-
const result = await this.$__client.mutation(mutationString, variables || {}).toPromise();
|
|
28497
|
+
const result = await this.$__client.mutation(mutationString, variables || {}, context).toPromise();
|
|
28497
28498
|
return this.formatResponse(result);
|
|
28498
28499
|
}
|
|
28499
28500
|
// Alias for mutation() to match JS SDK interface
|
|
@@ -29005,7 +29006,11 @@ ${operationTypes.join("\n")}
|
|
|
29005
29006
|
client: external_exports.unknown().optional(),
|
|
29006
29007
|
socket: external_exports.unknown().optional(),
|
|
29007
29008
|
serverSdkVersion: external_exports.number().int().min(1).max(10).default(4),
|
|
29008
|
-
logging: external_exports.boolean().default(false)
|
|
29009
|
+
logging: external_exports.boolean().default(false),
|
|
29010
|
+
// Optional default urql request policy for reads (server/sync clients pass
|
|
29011
|
+
// 'network-only'). Permitted by the strict schema so the constructor option
|
|
29012
|
+
// isn't rejected.
|
|
29013
|
+
defaultRequestPolicy: external_exports.enum(["cache-first", "cache-only", "network-only", "cache-and-network"]).nullable().optional()
|
|
29009
29014
|
}).strict();
|
|
29010
29015
|
var EnvironmentConfigSchema = external_exports.object({
|
|
29011
29016
|
NODE_ENV: external_exports.enum(["development", "production", "test"]).default("development"),
|
|
@@ -32773,6 +32778,10 @@ ${operationTypes.join("\n")}
|
|
|
32773
32778
|
$__client;
|
|
32774
32779
|
$__serverSdkVersion = 3;
|
|
32775
32780
|
$__logging = false;
|
|
32781
|
+
// Default urql request policy applied to reads when the caller doesn't pass
|
|
32782
|
+
// one. null = urql's default (cache-first). Server/sync clients set this to
|
|
32783
|
+
// 'network-only' so a long-lived client never serves a stale cached read.
|
|
32784
|
+
$__defaultRequestPolicy = null;
|
|
32776
32785
|
$__authTokenObjects = {};
|
|
32777
32786
|
$__authToken = null;
|
|
32778
32787
|
$__authInProcess = false;
|
|
@@ -32812,13 +32821,15 @@ ${operationTypes.join("\n")}
|
|
|
32812
32821
|
serverSdkVersion = 3,
|
|
32813
32822
|
logging = false
|
|
32814
32823
|
} = validatedConfig;
|
|
32824
|
+
const defaultRequestPolicy = config.defaultRequestPolicy ?? null;
|
|
32815
32825
|
this.initialize({
|
|
32816
32826
|
uri,
|
|
32817
32827
|
cellSlug,
|
|
32818
32828
|
socket,
|
|
32819
32829
|
client,
|
|
32820
32830
|
serverSdkVersion,
|
|
32821
|
-
logging
|
|
32831
|
+
logging,
|
|
32832
|
+
defaultRequestPolicy
|
|
32822
32833
|
});
|
|
32823
32834
|
}
|
|
32824
32835
|
/**
|
|
@@ -32830,7 +32841,8 @@ ${operationTypes.join("\n")}
|
|
|
32830
32841
|
socket = null,
|
|
32831
32842
|
client = null,
|
|
32832
32843
|
serverSdkVersion = 3,
|
|
32833
|
-
logging = false
|
|
32844
|
+
logging = false,
|
|
32845
|
+
defaultRequestPolicy = null
|
|
32834
32846
|
}) {
|
|
32835
32847
|
this.reset();
|
|
32836
32848
|
this.$__logging = logging;
|
|
@@ -32852,6 +32864,7 @@ ${operationTypes.join("\n")}
|
|
|
32852
32864
|
encrypt: this.$__encrypt
|
|
32853
32865
|
});
|
|
32854
32866
|
this.$__serverSdkVersion = serverSdkVersion;
|
|
32867
|
+
this.$__defaultRequestPolicy = defaultRequestPolicy;
|
|
32855
32868
|
}
|
|
32856
32869
|
/**
|
|
32857
32870
|
* Get random uri from specified this.$__uris
|
|
@@ -32899,6 +32912,20 @@ ${operationTypes.join("\n")}
|
|
|
32899
32912
|
getServerSdkVersion() {
|
|
32900
32913
|
return this.$__serverSdkVersion;
|
|
32901
32914
|
}
|
|
32915
|
+
/**
|
|
32916
|
+
* Gets the client's default urql request policy (null = urql default).
|
|
32917
|
+
*/
|
|
32918
|
+
getDefaultRequestPolicy() {
|
|
32919
|
+
return this.$__defaultRequestPolicy;
|
|
32920
|
+
}
|
|
32921
|
+
/**
|
|
32922
|
+
* Sets the default urql request policy applied to reads that don't specify
|
|
32923
|
+
* one. Pass 'network-only' on a long-lived server/sync client so it never
|
|
32924
|
+
* serves a stale cached read; null restores urql's default (cache-first).
|
|
32925
|
+
*/
|
|
32926
|
+
setDefaultRequestPolicy(policy) {
|
|
32927
|
+
this.$__defaultRequestPolicy = policy;
|
|
32928
|
+
}
|
|
32902
32929
|
/**
|
|
32903
32930
|
* Reset common properties
|
|
32904
32931
|
*/
|
|
@@ -33087,7 +33114,7 @@ ${operationTypes.join("\n")}
|
|
|
33087
33114
|
/**
|
|
33088
33115
|
* Executes a query or mutation
|
|
33089
33116
|
*/
|
|
33090
|
-
async executeQuery(query, variables = null) {
|
|
33117
|
+
async executeQuery(query, variables = null, context = {}) {
|
|
33091
33118
|
if (this.$__authToken && this.$__authToken.isExpired() && !this.$__authInProcess) {
|
|
33092
33119
|
this.log("info", "KnishIOClient::executeQuery() - Access token is expired. Getting new one...");
|
|
33093
33120
|
await this.requestAuthToken({
|
|
@@ -33103,7 +33130,8 @@ ${operationTypes.join("\n")}
|
|
|
33103
33130
|
return response;
|
|
33104
33131
|
});
|
|
33105
33132
|
}
|
|
33106
|
-
|
|
33133
|
+
const effectiveContext = this.$__defaultRequestPolicy && !context.requestPolicy ? { requestPolicy: this.$__defaultRequestPolicy, ...context } : context;
|
|
33134
|
+
return await query.execute({ variables: variables || {}, context: effectiveContext });
|
|
33107
33135
|
}
|
|
33108
33136
|
/**
|
|
33109
33137
|
* When a ProposeMolecule submission is rejected for a position-related
|
|
@@ -33436,7 +33464,8 @@ ${operationTypes.join("\n")}
|
|
|
33436
33464
|
throughMolecule = false,
|
|
33437
33465
|
values = null,
|
|
33438
33466
|
keys = null,
|
|
33439
|
-
atomValues = null
|
|
33467
|
+
atomValues = null,
|
|
33468
|
+
requestPolicy = null
|
|
33440
33469
|
}) {
|
|
33441
33470
|
this.log("info", `KnishIOClient::queryMeta() - Querying metaType: ${metaType}, metaId: ${metaId}...`);
|
|
33442
33471
|
let query;
|
|
@@ -33488,7 +33517,8 @@ ${operationTypes.join("\n")}
|
|
|
33488
33517
|
cellSlug: this.getCellSlug()
|
|
33489
33518
|
});
|
|
33490
33519
|
}
|
|
33491
|
-
|
|
33520
|
+
const context = requestPolicy ? { requestPolicy } : {};
|
|
33521
|
+
return this.executeQuery(query, variables, context);
|
|
33492
33522
|
}
|
|
33493
33523
|
/**
|
|
33494
33524
|
* Queries meta assets and verifies cryptographic integrity of associated molecules.
|