@crowdedkingdoms/crowdyjs 14.0.0 → 14.2.0-dev.1
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/MIGRATION.md +6 -4
- package/README.md +43 -0
- package/dist/client.d.ts +27 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +69 -2
- package/dist/crowdy-client.d.ts.map +1 -1
- package/dist/crowdy-client.js +25 -0
- package/dist/datacenter-redirect.d.ts +49 -0
- package/dist/datacenter-redirect.d.ts.map +1 -0
- package/dist/datacenter-redirect.js +62 -0
- package/dist/domains/apps.d.ts +32 -4
- package/dist/domains/apps.d.ts.map +1 -1
- package/dist/domains/apps.js +35 -4
- package/dist/domains/controlPlane.d.ts +1 -1
- package/dist/domains/controlPlane.js +1 -1
- package/dist/domains/gameModel.d.ts +9 -1
- package/dist/domains/gameModel.d.ts.map +1 -1
- package/dist/domains/usage.d.ts +1 -1
- package/dist/domains/usage.js +1 -1
- package/dist/errors.d.ts +143 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +168 -0
- package/dist/generated/graphql.d.ts +354 -9
- package/dist/generated/graphql.d.ts.map +1 -1
- package/dist/generated/graphql.js +107 -3
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/kit/npcs.d.ts.map +1 -1
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +5 -0
- package/dist/kit/social.d.ts.map +1 -1
- package/dist/realtime.d.ts +26 -0
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +83 -0
- package/package.json +1 -1
package/dist/realtime.d.ts
CHANGED
|
@@ -455,6 +455,32 @@ export declare class RealtimeClient {
|
|
|
455
455
|
* discovery round trip and no reason to consult the rediscover callback. The
|
|
456
456
|
* binary relay has already refused any target outside this estate.
|
|
457
457
|
*/
|
|
458
|
+
/**
|
|
459
|
+
* Follow an HTTP redirect that has already happened.
|
|
460
|
+
*
|
|
461
|
+
* Called when a GraphQL call was refused with `WRONG_DATACENTER` and the
|
|
462
|
+
* transport moved itself. The websocket has to follow in the same step or the
|
|
463
|
+
* session is split across two DATACENTERS rather than merely two instances —
|
|
464
|
+
* strictly worse than the split this file already guards against, because the
|
|
465
|
+
* subscription would be talking to a datacenter that holds none of the app's
|
|
466
|
+
* shards and will refuse it too.
|
|
467
|
+
*
|
|
468
|
+
* Idempotent: moving to the URL already in use returns without touching the
|
|
469
|
+
* connection, so a burst of refused calls produces one move rather than one
|
|
470
|
+
* reconnect each.
|
|
471
|
+
*/
|
|
472
|
+
/**
|
|
473
|
+
* Act on a `WRONG_DATACENTER` carried in a websocket `errors[]`.
|
|
474
|
+
*
|
|
475
|
+
* @returns true when the connection was moved, so the caller can skip
|
|
476
|
+
* reporting the error as an ordinary failure.
|
|
477
|
+
*/
|
|
478
|
+
private applyDatacenterRedirect;
|
|
479
|
+
moveToDatacenter(target: {
|
|
480
|
+
httpUrl: string;
|
|
481
|
+
wsUrl?: string | null;
|
|
482
|
+
datacenter?: string;
|
|
483
|
+
}): void;
|
|
458
484
|
private moveToDirectedEndpoint;
|
|
459
485
|
/** Drop the relay so the next subscribe builds one against the new URL. */
|
|
460
486
|
/**
|
package/dist/realtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../src/realtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../src/realtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MA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GG;IACG,iBAAiB,CAAC,SAAS,SAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAwB3D,OAAO,CAAC,kBAAkB;YA0CZ,gBAAgB;IAwI9B,OAAO,CAAC,wBAAwB;IAmDhC,OAAO,CAAC,OAAO;IAaf;;;;;;;;;;OAUG;YACW,kBAAkB;IAoChC;;;;;;;OAOG;IACH;;;;;;;;;;;;;OAaG;IACH;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IAgB/B,gBAAgB,CAAC,MAAM,EAAE;QACvB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,IAAI;IAYR,OAAO,CAAC,sBAAsB;IAkB9B,2EAA2E;IAC3E;;;;;;;;;;;;OAYG;YACW,4BAA4B;IAoC1C,OAAO,CAAC,kBAAkB;IAa1B,OAAO,CAAC,QAAQ;IAiFhB,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,SAAS;CAOlB;AAuBD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,oBAAoB,CAAC"}
|
package/dist/realtime.js
CHANGED
|
@@ -2,6 +2,7 @@ import { print } from 'graphql';
|
|
|
2
2
|
import { createClient } from 'graphql-ws';
|
|
3
3
|
import { silentLogger } from './logger.js';
|
|
4
4
|
import { CrowdyRealtimeError } from './errors.js';
|
|
5
|
+
import { moveFromErrors } from './datacenter-redirect.js';
|
|
5
6
|
import { payloadBytesOf } from './metrics.js';
|
|
6
7
|
import { UdpNotificationsDocument, } from './generated/graphql.js';
|
|
7
8
|
import { BinaryRelayTransport } from './binary-relay.js';
|
|
@@ -226,6 +227,13 @@ export class RealtimeClient {
|
|
|
226
227
|
settled = true;
|
|
227
228
|
dispose();
|
|
228
229
|
if (message.errors?.length) {
|
|
230
|
+
// Move the connection, then reject. The caller still sees this
|
|
231
|
+
// mutation fail -- a websocket mutation cannot be transparently
|
|
232
|
+
// replayed the way an HTTP POST can, because the reply is
|
|
233
|
+
// correlated to a subscription that is about to be torn down -- but
|
|
234
|
+
// the NEXT one lands in the right datacenter instead of repeating
|
|
235
|
+
// the refusal until something gives up.
|
|
236
|
+
this.applyDatacenterRedirect(message.errors);
|
|
229
237
|
reject(new CrowdyRealtimeError(message.errors[0]?.message ?? 'GraphQL mutation failed', {
|
|
230
238
|
code: 'WS_MUTATION_ERROR',
|
|
231
239
|
retryable: true,
|
|
@@ -465,6 +473,15 @@ export class RealtimeClient {
|
|
|
465
473
|
if (notification)
|
|
466
474
|
this.dispatch(notification);
|
|
467
475
|
if (message.errors?.length) {
|
|
476
|
+
// A redirect arriving over the subscription is acted on immediately
|
|
477
|
+
// rather than counted as a failure. The generic path waits for
|
|
478
|
+
// `rediscoverAfterFailures` consecutive connect failures before it
|
|
479
|
+
// moves, which is right when the SDK is guessing that something is
|
|
480
|
+
// wrong -- and wrong here, because the server has just said exactly
|
|
481
|
+
// what is wrong and exactly where to go. Waiting would cost three
|
|
482
|
+
// reconnects to a datacenter that has already refused us once.
|
|
483
|
+
if (this.applyDatacenterRedirect(message.errors))
|
|
484
|
+
return;
|
|
468
485
|
this.dispatchError(new CrowdyRealtimeError(message.errors[0]?.message ?? 'Subscription error', {
|
|
469
486
|
code: 'SUBSCRIPTION_ERROR',
|
|
470
487
|
retryable: true,
|
|
@@ -594,6 +611,50 @@ export class RealtimeClient {
|
|
|
594
611
|
* discovery round trip and no reason to consult the rediscover callback. The
|
|
595
612
|
* binary relay has already refused any target outside this estate.
|
|
596
613
|
*/
|
|
614
|
+
/**
|
|
615
|
+
* Follow an HTTP redirect that has already happened.
|
|
616
|
+
*
|
|
617
|
+
* Called when a GraphQL call was refused with `WRONG_DATACENTER` and the
|
|
618
|
+
* transport moved itself. The websocket has to follow in the same step or the
|
|
619
|
+
* session is split across two DATACENTERS rather than merely two instances —
|
|
620
|
+
* strictly worse than the split this file already guards against, because the
|
|
621
|
+
* subscription would be talking to a datacenter that holds none of the app's
|
|
622
|
+
* shards and will refuse it too.
|
|
623
|
+
*
|
|
624
|
+
* Idempotent: moving to the URL already in use returns without touching the
|
|
625
|
+
* connection, so a burst of refused calls produces one move rather than one
|
|
626
|
+
* reconnect each.
|
|
627
|
+
*/
|
|
628
|
+
/**
|
|
629
|
+
* Act on a `WRONG_DATACENTER` carried in a websocket `errors[]`.
|
|
630
|
+
*
|
|
631
|
+
* @returns true when the connection was moved, so the caller can skip
|
|
632
|
+
* reporting the error as an ordinary failure.
|
|
633
|
+
*/
|
|
634
|
+
applyDatacenterRedirect(errors) {
|
|
635
|
+
const move = moveFromErrors(errors);
|
|
636
|
+
if (!move)
|
|
637
|
+
return false;
|
|
638
|
+
const before = this.wsUrl;
|
|
639
|
+
this.moveToDatacenter({
|
|
640
|
+
httpUrl: move.gameApiUrl,
|
|
641
|
+
wsUrl: move.gameApiWsUrl ?? null,
|
|
642
|
+
datacenter: move.appDatacenter,
|
|
643
|
+
});
|
|
644
|
+
return this.wsUrl !== before;
|
|
645
|
+
}
|
|
646
|
+
moveToDatacenter(target) {
|
|
647
|
+
const wsUrl = target.wsUrl || httpToWebsocketUrl(target.httpUrl);
|
|
648
|
+
if (!wsUrl)
|
|
649
|
+
return;
|
|
650
|
+
this.moveToDirectedEndpoint({
|
|
651
|
+
httpUrl: target.httpUrl,
|
|
652
|
+
wsUrl,
|
|
653
|
+
reason: target.datacenter
|
|
654
|
+
? `app is served from '${target.datacenter}'`
|
|
655
|
+
: 'app is served from another datacenter',
|
|
656
|
+
});
|
|
657
|
+
}
|
|
597
658
|
moveToDirectedEndpoint(target) {
|
|
598
659
|
if (target.wsUrl === this.wsUrl)
|
|
599
660
|
return;
|
|
@@ -809,6 +870,28 @@ function notificationKind(typename) {
|
|
|
809
870
|
* off before it stops, instead of dropping them and letting them find out.
|
|
810
871
|
*/
|
|
811
872
|
export const SERVER_DRAINING_CODE = 'SERVER_DRAINING';
|
|
873
|
+
/**
|
|
874
|
+
* The websocket form of an http(s) URL, keeping its path.
|
|
875
|
+
*
|
|
876
|
+
* A fallback only. `WRONG_DATACENTER` names `gameApiWsUrl` alongside
|
|
877
|
+
* `gameApiUrl`, and the server's answer is the one to prefer — it knows about
|
|
878
|
+
* ports and paths this cannot see. This exists so a server that someday omits it
|
|
879
|
+
* degrades to a reasonable guess instead of leaving the websocket in the old
|
|
880
|
+
* datacenter, which is the one outcome worse than guessing.
|
|
881
|
+
*/
|
|
882
|
+
function httpToWebsocketUrl(httpUrl) {
|
|
883
|
+
const trimmed = httpUrl?.trim();
|
|
884
|
+
if (!trimmed)
|
|
885
|
+
return null;
|
|
886
|
+
if (trimmed.startsWith('wss://') || trimmed.startsWith('ws://')) {
|
|
887
|
+
return trimmed;
|
|
888
|
+
}
|
|
889
|
+
if (trimmed.startsWith('https://'))
|
|
890
|
+
return `wss://${trimmed.slice(8)}`;
|
|
891
|
+
if (trimmed.startsWith('http://'))
|
|
892
|
+
return `ws://${trimmed.slice(7)}`;
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
812
895
|
/** Default relay endpoint: the realtime wsUrl with its path set to /realtime. */
|
|
813
896
|
function deriveBinaryRelayUrl(wsUrl) {
|
|
814
897
|
try {
|
package/package.json
CHANGED