@cedarjs/realtime 9.0.0-canary.1784 → 9.0.0-canary.3124
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/graphql/plugins/useCedarRealtime.d.ts +9 -9
- package/dist/graphql/plugins/useCedarRealtime.d.ts.map +1 -1
- package/dist/graphql/plugins/useCedarRealtime.js +144 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -171
- package/package.json +24 -15
- package/LICENSE +0 -21
- package/dist/graphql/index.d.ts +0 -7
- package/dist/graphql/index.d.ts.map +0 -1
- package/dist/graphql/plugins/__fixtures__/common.d.ts +0 -9
- package/dist/graphql/plugins/__fixtures__/common.d.ts.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Plugin } from '@envelop/core';
|
|
1
|
+
import type { Plugin as EnvelopPlugin } from '@envelop/core';
|
|
2
2
|
import type { CreateRedisEventTargetArgs } from '@graphql-yoga/redis-event-target';
|
|
3
3
|
import type { PubSub } from '@graphql-yoga/subscription';
|
|
4
4
|
import { createPubSub } from '@graphql-yoga/subscription';
|
|
@@ -11,7 +11,7 @@ export { Repeater } from 'graphql-yoga';
|
|
|
11
11
|
* But not fully supported in TS
|
|
12
12
|
* {
|
|
13
13
|
* schema: DocumentNode // <-- required
|
|
14
|
-
* [string]:
|
|
14
|
+
* [string]: CedarSubscription
|
|
15
15
|
* }
|
|
16
16
|
*
|
|
17
17
|
* Note: This type is duplicated from packages/graphql-server/src/subscriptions/makeSubscriptions
|
|
@@ -47,8 +47,8 @@ export type CedarRealtimeOptions = {
|
|
|
47
47
|
enableDeferStream?: boolean;
|
|
48
48
|
liveQueries?: {
|
|
49
49
|
/**
|
|
50
|
-
* @description Cedar Realtime supports in-memory and Redis stores.
|
|
51
|
-
*
|
|
50
|
+
* @description Cedar Realtime supports in-memory and Redis stores. If no
|
|
51
|
+
* `store` is configured, live queries will be disabled.
|
|
52
52
|
*/
|
|
53
53
|
store: 'in-memory' | {
|
|
54
54
|
redis: {
|
|
@@ -64,8 +64,8 @@ export type CedarRealtimeOptions = {
|
|
|
64
64
|
};
|
|
65
65
|
subscriptions?: {
|
|
66
66
|
/**
|
|
67
|
-
* @description Cedar Realtime supports in-memory and Redis stores.
|
|
68
|
-
*
|
|
67
|
+
* @description Cedar Realtime supports in-memory and Redis stores. If no
|
|
68
|
+
* `store` is configured, subscriptions will be disabled.
|
|
69
69
|
*/
|
|
70
70
|
store: 'in-memory' | {
|
|
71
71
|
redis: {
|
|
@@ -91,13 +91,13 @@ export declare class RedisLiveQueryStore {
|
|
|
91
91
|
liveQueryStore: InMemoryLiveQueryStore;
|
|
92
92
|
constructor(pub: PublishClientType, sub: SubscribeClientType, channel: string, liveQueryStore: InMemoryLiveQueryStore);
|
|
93
93
|
invalidate(identifiers: string[] | string): Promise<void>;
|
|
94
|
-
makeExecute(execute: typeof defaultExecute): (args: import("graphql").ExecutionArgs) => AsyncIterableIterator<import("graphql").ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>> | import("@n1ru4l/graphql-live-query").LiveExecutionResult> | import("graphql").ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>> | Promise<AsyncIterableIterator<import("graphql").ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>> | import("@n1ru4l/graphql-live-query").LiveExecutionResult> | import("graphql").ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>>>;
|
|
94
|
+
makeExecute(execute: typeof defaultExecute): (args: import("graphql").ExecutionArgs) => AsyncIterableIterator<import("graphql").ExecutionResult<import("graphql/jsutils/ObjMap.js").ObjMap<unknown>, import("graphql/jsutils/ObjMap.js").ObjMap<unknown>> | import("@n1ru4l/graphql-live-query").LiveExecutionResult> | import("graphql").ExecutionResult<import("graphql/jsutils/ObjMap.js").ObjMap<unknown>, import("graphql/jsutils/ObjMap.js").ObjMap<unknown>> | Promise<AsyncIterableIterator<import("graphql").ExecutionResult<import("graphql/jsutils/ObjMap.js").ObjMap<unknown>, import("graphql/jsutils/ObjMap.js").ObjMap<unknown>> | import("@n1ru4l/graphql-live-query").LiveExecutionResult> | import("graphql").ExecutionResult<import("graphql/jsutils/ObjMap.js").ObjMap<unknown>, import("graphql/jsutils/ObjMap.js").ObjMap<unknown>>>;
|
|
95
95
|
}
|
|
96
96
|
export declare let liveQueryStore: LiveQueryStorageMechanism | undefined;
|
|
97
97
|
export declare let pubSub: ReturnType<typeof createPubSub> | undefined;
|
|
98
|
-
export declare const useCedarRealtime: (options: CedarRealtimeOptions) =>
|
|
98
|
+
export declare const useCedarRealtime: (options: CedarRealtimeOptions) => EnvelopPlugin;
|
|
99
99
|
/**
|
|
100
100
|
* @deprecated Use `useCedarRealtime` instead.
|
|
101
101
|
*/
|
|
102
|
-
export declare const useRedwoodRealtime: (options: CedarRealtimeOptions) =>
|
|
102
|
+
export declare const useRedwoodRealtime: (options: CedarRealtimeOptions) => EnvelopPlugin;
|
|
103
103
|
//# sourceMappingURL=useCedarRealtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCedarRealtime.d.ts","sourceRoot":"","sources":["../../../src/graphql/plugins/useCedarRealtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"useCedarRealtime.d.ts","sourceRoot":"","sources":["../../../src/graphql/plugins/useCedarRealtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,eAAe,CAAA;AAO5D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAA;AAClF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AAC3E,OAAO,KAAK,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,SAAS,CAAA;AAGxD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEvC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEzD,YAAY,EAAE,MAAM,EAAE,CAAA;AAEtB,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,CAAA;AAE/C,eAAO,MAAM,qBAAqB,QAEjC,CAAA;AAED,MAAM,MAAM,yBAAyB,GACnC,mBAAmB,GAAG,sBAAsB,CAAA;AAE9C,MAAM,MAAM,iBAAiB,GAAG,0BAA0B,CAAC,eAAe,CAAC,CAAA;AAC3E,MAAM,MAAM,mBAAmB,GAAG,0BAA0B,CAAC,iBAAiB,CAAC,CAAA;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,WAAW,CAAC,EAAE;QACZ;;;WAGG;QACH,KAAK,EACD,WAAW,GACX;YACE,KAAK,EAAE;gBACL;;;mBAGG;gBACH,OAAO,CAAC,EAAE,MAAM,CAAA;gBAChB,aAAa,EAAE,iBAAiB,CAAA;gBAChC,eAAe,EAAE,mBAAmB,CAAA;aACrC,CAAA;SACF,CAAA;KACN,CAAA;IACD,aAAa,CAAC,EAAE;QACd;;;WAGG;QACH,KAAK,EACD,WAAW,GACX;YACE,KAAK,EAAE;gBACL,aAAa,EAAE,iBAAiB,CAAA;gBAChC,eAAe,EAAE,mBAAmB,CAAA;aACrC,CAAA;SACF,CAAA;QACL;;;WAGG;QACH,aAAa,EAAE,uBAAuB,CAAA;KACvC,CAAA;CACF,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,oBAAoB,CAAA;AAEzD,qBAAa,mBAAmB;IAC9B,GAAG,EAAE,iBAAiB,CAAA;IACtB,GAAG,EAAE,mBAAmB,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,sBAAsB,CAAA;gBAGpC,GAAG,EAAE,iBAAiB,EACtB,GAAG,EAAE,mBAAmB,EACxB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,sBAAsB;IAoBlC,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM;IAS/C,WAAW,CAAC,OAAO,EAAE,OAAO,cAAc;CAG3C;AAID,eAAO,IAAI,cAAc,EAAE,yBAAyB,GAAG,SAAqB,CAAA;AAC5E,eAAO,IAAI,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,GAAG,SAAqB,CAAA;AAE1E,eAAO,MAAM,gBAAgB,GAC3B,SAAS,oBAAoB,KAC5B,aAoGF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,oBAAoB,KAC5B,aAEF,CAAA"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { useLiveQuery } from "@envelop/live-query";
|
|
2
|
+
import { mergeSchemas } from "@graphql-tools/schema";
|
|
3
|
+
import { astFromDirective } from "@graphql-tools/utils";
|
|
4
|
+
import { useDeferStream } from "@graphql-yoga/plugin-defer-stream";
|
|
5
|
+
import { useGraphQLSSE } from "@graphql-yoga/plugin-graphql-sse";
|
|
6
|
+
import { createRedisEventTarget } from "@graphql-yoga/redis-event-target";
|
|
7
|
+
import { createPubSub } from "@graphql-yoga/subscription";
|
|
8
|
+
import { GraphQLLiveDirective } from "@n1ru4l/graphql-live-query";
|
|
9
|
+
import { InMemoryLiveQueryStore } from "@n1ru4l/in-memory-live-query-store";
|
|
10
|
+
import { print } from "graphql";
|
|
11
|
+
import { Repeater } from "graphql-yoga";
|
|
12
|
+
const liveDirectiveTypeDefs = print(
|
|
13
|
+
astFromDirective(GraphQLLiveDirective)
|
|
14
|
+
);
|
|
15
|
+
class RedisLiveQueryStore {
|
|
16
|
+
pub;
|
|
17
|
+
sub;
|
|
18
|
+
channel;
|
|
19
|
+
liveQueryStore;
|
|
20
|
+
constructor(pub, sub, channel, liveQueryStore2) {
|
|
21
|
+
this.pub = pub;
|
|
22
|
+
this.sub = sub;
|
|
23
|
+
this.liveQueryStore = liveQueryStore2;
|
|
24
|
+
this.channel = channel;
|
|
25
|
+
this.sub.subscribe(this.channel, (err) => {
|
|
26
|
+
if (err) {
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
this.sub.on("message", (channel2, resourceIdentifier) => {
|
|
31
|
+
if (channel2 === this.channel && resourceIdentifier) {
|
|
32
|
+
this.liveQueryStore.invalidate(resourceIdentifier);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async invalidate(identifiers) {
|
|
37
|
+
if (typeof identifiers === "string") {
|
|
38
|
+
identifiers = [identifiers];
|
|
39
|
+
}
|
|
40
|
+
for (const identifier of identifiers) {
|
|
41
|
+
this.pub.publish(this.channel, identifier);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
makeExecute(execute) {
|
|
45
|
+
return this.liveQueryStore.makeExecute(execute);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
let liveQueryStore = void 0;
|
|
49
|
+
let pubSub = void 0;
|
|
50
|
+
const useCedarRealtime = (options) => {
|
|
51
|
+
let liveQueriesEnabled = false;
|
|
52
|
+
let subscriptionsEnabled = false;
|
|
53
|
+
let liveQueryPlugin;
|
|
54
|
+
const inMemoryLiveQueryStore = new InMemoryLiveQueryStore();
|
|
55
|
+
liveQueryStore = {};
|
|
56
|
+
pubSub = {};
|
|
57
|
+
const wasLiveQueryAdded = /* @__PURE__ */ Symbol.for("useCedarRealtime.wasLiveQueryAdded");
|
|
58
|
+
if (options.liveQueries?.store) {
|
|
59
|
+
if (options.liveQueries.store === "in-memory") {
|
|
60
|
+
liveQueriesEnabled = true;
|
|
61
|
+
liveQueryStore = inMemoryLiveQueryStore;
|
|
62
|
+
liveQueryPlugin = useLiveQuery({ liveQueryStore });
|
|
63
|
+
} else if (options.liveQueries.store.redis) {
|
|
64
|
+
liveQueriesEnabled = true;
|
|
65
|
+
liveQueryStore = new RedisLiveQueryStore(
|
|
66
|
+
options.liveQueries.store.redis.publishClient,
|
|
67
|
+
options.liveQueries.store.redis.subscribeClient,
|
|
68
|
+
options.liveQueries.store.redis.channel || "live-query-invalidations",
|
|
69
|
+
inMemoryLiveQueryStore
|
|
70
|
+
);
|
|
71
|
+
liveQueryPlugin = useLiveQuery({
|
|
72
|
+
liveQueryStore
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
throw new Error("Invalid live query store configuration.");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (options.subscriptions?.store) {
|
|
79
|
+
if (options.subscriptions.store === "in-memory") {
|
|
80
|
+
subscriptionsEnabled = true;
|
|
81
|
+
pubSub = createPubSub();
|
|
82
|
+
} else if (options.subscriptions.store.redis) {
|
|
83
|
+
subscriptionsEnabled = true;
|
|
84
|
+
const eventTarget = createRedisEventTarget({
|
|
85
|
+
publishClient: options.subscriptions.store.redis.publishClient,
|
|
86
|
+
subscribeClient: options.subscriptions.store.redis.subscribeClient
|
|
87
|
+
});
|
|
88
|
+
pubSub = createPubSub({ eventTarget });
|
|
89
|
+
} else {
|
|
90
|
+
throw new Error("Invalid subscriptions store configuration.");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
onSchemaChange({ replaceSchema, schema }) {
|
|
95
|
+
if (schema.extensions?.[wasLiveQueryAdded] === true) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (liveQueriesEnabled) {
|
|
99
|
+
const liveSchema = mergeSchemas({
|
|
100
|
+
schemas: [schema],
|
|
101
|
+
typeDefs: [liveDirectiveTypeDefs]
|
|
102
|
+
});
|
|
103
|
+
liveSchema.extensions = {
|
|
104
|
+
...schema.extensions,
|
|
105
|
+
[wasLiveQueryAdded]: true
|
|
106
|
+
};
|
|
107
|
+
replaceSchema(liveSchema);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
onPluginInit({ addPlugin }) {
|
|
111
|
+
if (liveQueriesEnabled && liveQueryPlugin) {
|
|
112
|
+
addPlugin(liveQueryPlugin);
|
|
113
|
+
}
|
|
114
|
+
if (subscriptionsEnabled) {
|
|
115
|
+
addPlugin(useGraphQLSSE());
|
|
116
|
+
}
|
|
117
|
+
if (options.enableDeferStream) {
|
|
118
|
+
addPlugin(useDeferStream());
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
onContextBuilding() {
|
|
122
|
+
return ({ extendContext }) => {
|
|
123
|
+
extendContext({
|
|
124
|
+
liveQueryStore: liveQueriesEnabled && liveQueryStore,
|
|
125
|
+
pubSub: subscriptionsEnabled && pubSub
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
const useRedwoodRealtime = (options) => {
|
|
132
|
+
return useCedarRealtime(options);
|
|
133
|
+
};
|
|
134
|
+
export {
|
|
135
|
+
InMemoryLiveQueryStore,
|
|
136
|
+
RedisLiveQueryStore,
|
|
137
|
+
Repeater,
|
|
138
|
+
createPubSub,
|
|
139
|
+
liveDirectiveTypeDefs,
|
|
140
|
+
liveQueryStore,
|
|
141
|
+
pubSub,
|
|
142
|
+
useCedarRealtime,
|
|
143
|
+
useRedwoodRealtime
|
|
144
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { useCedarRealtime,
|
|
2
2
|
/** @deprecated - please use useCedarRealtime instead */
|
|
3
|
-
useRedwoodRealtime, createPubSub, liveDirectiveTypeDefs, InMemoryLiveQueryStore, RedisLiveQueryStore, liveQueryStore, pubSub, Repeater, } from './graphql';
|
|
3
|
+
useRedwoodRealtime, createPubSub, liveDirectiveTypeDefs, InMemoryLiveQueryStore, RedisLiveQueryStore, liveQueryStore, pubSub, Repeater, } from './graphql/plugins/useCedarRealtime.js';
|
|
4
4
|
export type { LiveQueryStorageMechanism, PubSub, PublishClientType, SubscribeClientType, SubscriptionGlobImports, CedarRealtimeOptions,
|
|
5
5
|
/** @deprecated - please use CedarRealtimeOptions instead */
|
|
6
|
-
RedwoodRealtimeOptions, } from './graphql';
|
|
6
|
+
RedwoodRealtimeOptions, } from './graphql/plugins/useCedarRealtime.js';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB;AAChB,wDAAwD;AACxD,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,MAAM,EACN,QAAQ,GACT,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB;AAChB,wDAAwD;AACxD,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,MAAM,EACN,QAAQ,GACT,MAAM,uCAAuC,CAAA;AAE9C,YAAY,EACV,yBAAyB,EACzB,MAAM,EACN,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB;AACpB,4DAA4D;AAC5D,sBAAsB,GACvB,MAAM,uCAAuC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,173 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
InMemoryLiveQueryStore: () => import_in_memory_live_query_store.InMemoryLiveQueryStore,
|
|
24
|
-
RedisLiveQueryStore: () => RedisLiveQueryStore,
|
|
25
|
-
Repeater: () => import_graphql_yoga.Repeater,
|
|
26
|
-
createPubSub: () => import_subscription.createPubSub,
|
|
27
|
-
liveDirectiveTypeDefs: () => liveDirectiveTypeDefs,
|
|
28
|
-
liveQueryStore: () => liveQueryStore,
|
|
29
|
-
pubSub: () => pubSub,
|
|
30
|
-
useCedarRealtime: () => useCedarRealtime,
|
|
31
|
-
useRedwoodRealtime: () => useRedwoodRealtime
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(src_exports);
|
|
34
|
-
|
|
35
|
-
// src/graphql/plugins/useCedarRealtime.ts
|
|
36
|
-
var import_live_query = require("@envelop/live-query");
|
|
37
|
-
var import_schema = require("@graphql-tools/schema");
|
|
38
|
-
var import_utils = require("@graphql-tools/utils");
|
|
39
|
-
var import_plugin_defer_stream = require("@graphql-yoga/plugin-defer-stream");
|
|
40
|
-
var import_plugin_graphql_sse = require("@graphql-yoga/plugin-graphql-sse");
|
|
41
|
-
var import_redis_event_target = require("@graphql-yoga/redis-event-target");
|
|
42
|
-
var import_subscription = require("@graphql-yoga/subscription");
|
|
43
|
-
var import_graphql_live_query = require("@n1ru4l/graphql-live-query");
|
|
44
|
-
var import_in_memory_live_query_store = require("@n1ru4l/in-memory-live-query-store");
|
|
45
|
-
var import_graphql = require("graphql");
|
|
46
|
-
var import_graphql_yoga = require("graphql-yoga");
|
|
47
|
-
var liveDirectiveTypeDefs = (0, import_graphql.print)(
|
|
48
|
-
(0, import_utils.astFromDirective)(import_graphql_live_query.GraphQLLiveDirective)
|
|
49
|
-
);
|
|
50
|
-
var RedisLiveQueryStore = class {
|
|
51
|
-
pub;
|
|
52
|
-
sub;
|
|
53
|
-
channel;
|
|
54
|
-
liveQueryStore;
|
|
55
|
-
constructor(pub, sub, channel, liveQueryStore2) {
|
|
56
|
-
this.pub = pub;
|
|
57
|
-
this.sub = sub;
|
|
58
|
-
this.liveQueryStore = liveQueryStore2;
|
|
59
|
-
this.channel = channel;
|
|
60
|
-
this.sub.subscribe(this.channel, (err) => {
|
|
61
|
-
if (err) {
|
|
62
|
-
throw err;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
this.sub.on("message", (channel2, resourceIdentifier) => {
|
|
66
|
-
if (channel2 === this.channel && resourceIdentifier) {
|
|
67
|
-
this.liveQueryStore.invalidate(resourceIdentifier);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
async invalidate(identifiers) {
|
|
72
|
-
if (typeof identifiers === "string") {
|
|
73
|
-
identifiers = [identifiers];
|
|
74
|
-
}
|
|
75
|
-
for (const identifier of identifiers) {
|
|
76
|
-
this.pub.publish(this.channel, identifier);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
makeExecute(execute) {
|
|
80
|
-
return this.liveQueryStore.makeExecute(execute);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var liveQueryStore = void 0;
|
|
84
|
-
var pubSub = void 0;
|
|
85
|
-
var useCedarRealtime = (options) => {
|
|
86
|
-
let liveQueriesEnabled = false;
|
|
87
|
-
let subscriptionsEnabled = false;
|
|
88
|
-
let liveQueryPlugin = {};
|
|
89
|
-
const inMemoryLiveQueryStore = new import_in_memory_live_query_store.InMemoryLiveQueryStore();
|
|
90
|
-
liveQueryStore = {};
|
|
91
|
-
pubSub = {};
|
|
92
|
-
const wasLiveQueryAdded = Symbol.for("useCedarRealtime.wasLiveQueryAdded");
|
|
93
|
-
if (options.liveQueries?.store) {
|
|
94
|
-
if (options.liveQueries.store === "in-memory") {
|
|
95
|
-
liveQueriesEnabled = true;
|
|
96
|
-
liveQueryStore = inMemoryLiveQueryStore;
|
|
97
|
-
liveQueryPlugin = (0, import_live_query.useLiveQuery)({
|
|
98
|
-
liveQueryStore
|
|
99
|
-
});
|
|
100
|
-
} else if (options.liveQueries.store.redis) {
|
|
101
|
-
liveQueriesEnabled = true;
|
|
102
|
-
liveQueryStore = new RedisLiveQueryStore(
|
|
103
|
-
options.liveQueries.store.redis.publishClient,
|
|
104
|
-
options.liveQueries.store.redis.subscribeClient,
|
|
105
|
-
options.liveQueries.store.redis.channel || "live-query-invalidations",
|
|
106
|
-
inMemoryLiveQueryStore
|
|
107
|
-
);
|
|
108
|
-
liveQueryPlugin = (0, import_live_query.useLiveQuery)({
|
|
109
|
-
liveQueryStore
|
|
110
|
-
});
|
|
111
|
-
} else {
|
|
112
|
-
throw new Error("Invalid live query store configuration.");
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (options.subscriptions) {
|
|
116
|
-
if (options.subscriptions.store === "in-memory") {
|
|
117
|
-
subscriptionsEnabled = true;
|
|
118
|
-
pubSub = (0, import_subscription.createPubSub)();
|
|
119
|
-
} else if (options.subscriptions.store.redis) {
|
|
120
|
-
subscriptionsEnabled = true;
|
|
121
|
-
const eventTarget = (0, import_redis_event_target.createRedisEventTarget)({
|
|
122
|
-
publishClient: options.subscriptions.store.redis.publishClient,
|
|
123
|
-
subscribeClient: options.subscriptions.store.redis.subscribeClient
|
|
124
|
-
});
|
|
125
|
-
pubSub = (0, import_subscription.createPubSub)({ eventTarget });
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
onSchemaChange({ replaceSchema, schema }) {
|
|
130
|
-
if (schema.extensions?.[wasLiveQueryAdded] === true) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
if (liveQueriesEnabled) {
|
|
134
|
-
const liveSchema = (0, import_schema.mergeSchemas)({
|
|
135
|
-
schemas: [schema],
|
|
136
|
-
typeDefs: [liveDirectiveTypeDefs]
|
|
137
|
-
});
|
|
138
|
-
liveSchema.extensions = {
|
|
139
|
-
...schema.extensions,
|
|
140
|
-
[wasLiveQueryAdded]: true
|
|
141
|
-
};
|
|
142
|
-
replaceSchema(liveSchema);
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
onPluginInit({ addPlugin }) {
|
|
146
|
-
if (liveQueriesEnabled) {
|
|
147
|
-
addPlugin(liveQueryPlugin);
|
|
148
|
-
}
|
|
149
|
-
if (subscriptionsEnabled) {
|
|
150
|
-
addPlugin((0, import_plugin_graphql_sse.useGraphQLSSE)());
|
|
151
|
-
}
|
|
152
|
-
if (options.enableDeferStream) {
|
|
153
|
-
addPlugin((0, import_plugin_defer_stream.useDeferStream)());
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
onContextBuilding() {
|
|
157
|
-
return ({ extendContext }) => {
|
|
158
|
-
extendContext({
|
|
159
|
-
liveQueryStore: liveQueriesEnabled && liveQueryStore,
|
|
160
|
-
pubSub: subscriptionsEnabled && pubSub
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
var useRedwoodRealtime = (options) => {
|
|
167
|
-
return useCedarRealtime(options);
|
|
168
|
-
};
|
|
169
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
170
|
-
0 && (module.exports = {
|
|
1
|
+
import {
|
|
2
|
+
useCedarRealtime,
|
|
3
|
+
useRedwoodRealtime,
|
|
4
|
+
createPubSub,
|
|
5
|
+
liveDirectiveTypeDefs,
|
|
6
|
+
InMemoryLiveQueryStore,
|
|
7
|
+
RedisLiveQueryStore,
|
|
8
|
+
liveQueryStore,
|
|
9
|
+
pubSub,
|
|
10
|
+
Repeater
|
|
11
|
+
} from "./graphql/plugins/useCedarRealtime.js";
|
|
12
|
+
export {
|
|
171
13
|
InMemoryLiveQueryStore,
|
|
172
14
|
RedisLiveQueryStore,
|
|
173
15
|
Repeater,
|
|
@@ -177,4 +19,4 @@ var useRedwoodRealtime = (options) => {
|
|
|
177
19
|
pubSub,
|
|
178
20
|
useCedarRealtime,
|
|
179
21
|
useRedwoodRealtime
|
|
180
|
-
}
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/realtime",
|
|
3
|
-
"version": "9.0.0-canary.
|
|
3
|
+
"version": "9.0.0-canary.3124",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
7
7
|
"directory": "packages/realtime"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
11
17
|
"types": "./dist/index.d.ts",
|
|
12
18
|
"files": [
|
|
13
19
|
"dist"
|
|
14
20
|
],
|
|
15
21
|
"scripts": {
|
|
16
|
-
"build": "
|
|
22
|
+
"build": "node ./build.mts",
|
|
17
23
|
"build:pack": "yarn pack -o cedarjs-realtime.tgz",
|
|
18
|
-
"build:types": "tsc --build --verbose",
|
|
24
|
+
"build:types": "tsc --build --verbose ./tsconfig.build.json",
|
|
19
25
|
"build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build\"",
|
|
20
26
|
"prepublishOnly": "NODE_ENV=production yarn build",
|
|
21
27
|
"test": "vitest run",
|
|
@@ -23,26 +29,26 @@
|
|
|
23
29
|
},
|
|
24
30
|
"dependencies": {
|
|
25
31
|
"@envelop/live-query": "7.0.0",
|
|
26
|
-
"@graphql-tools/schema": "10.0
|
|
32
|
+
"@graphql-tools/schema": "10.1.0",
|
|
27
33
|
"@graphql-tools/utils": "10.11.0",
|
|
28
|
-
"@graphql-yoga/plugin-defer-stream": "3.
|
|
29
|
-
"@graphql-yoga/plugin-graphql-sse": "3.
|
|
34
|
+
"@graphql-yoga/plugin-defer-stream": "3.22.0",
|
|
35
|
+
"@graphql-yoga/plugin-graphql-sse": "3.22.0",
|
|
30
36
|
"@graphql-yoga/redis-event-target": "3.0.3",
|
|
31
37
|
"@graphql-yoga/subscription": "5.0.5",
|
|
32
38
|
"@n1ru4l/graphql-live-query": "0.10.0",
|
|
33
39
|
"@n1ru4l/in-memory-live-query-store": "0.10.0",
|
|
34
|
-
"graphql": "16.
|
|
40
|
+
"graphql": "16.14.2"
|
|
35
41
|
},
|
|
36
42
|
"devDependencies": {
|
|
37
|
-
"@cedarjs/framework-tools": "9.0.0-canary.
|
|
38
|
-
"@envelop/core": "5.
|
|
43
|
+
"@cedarjs/framework-tools": "9.0.0-canary.3124",
|
|
44
|
+
"@envelop/core": "5.6.0",
|
|
39
45
|
"@envelop/testing": "7.0.0",
|
|
40
46
|
"@envelop/types": "5.2.1",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
47
|
+
"graphql-yoga": "5.22.0",
|
|
48
|
+
"ioredis": "5.11.1",
|
|
49
|
+
"nodemon": "3.1.14",
|
|
44
50
|
"typescript": "5.9.3",
|
|
45
|
-
"vitest": "
|
|
51
|
+
"vitest": "4.1.11"
|
|
46
52
|
},
|
|
47
53
|
"peerDependencies": {
|
|
48
54
|
"ioredis": "^5.3.2"
|
|
@@ -52,8 +58,11 @@
|
|
|
52
58
|
"optional": true
|
|
53
59
|
}
|
|
54
60
|
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=24"
|
|
63
|
+
},
|
|
55
64
|
"publishConfig": {
|
|
56
65
|
"access": "public"
|
|
57
66
|
},
|
|
58
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
|
|
59
68
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Cedar
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/graphql/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { useCedarRealtime,
|
|
2
|
-
/** @deprecated - please use useCedarRealtime instead */
|
|
3
|
-
useRedwoodRealtime, createPubSub, liveDirectiveTypeDefs, InMemoryLiveQueryStore, RedisLiveQueryStore, liveQueryStore, pubSub, Repeater, } from './plugins/useCedarRealtime';
|
|
4
|
-
export type { LiveQueryStorageMechanism, PubSub, PublishClientType, SubscribeClientType, SubscriptionGlobImports, CedarRealtimeOptions,
|
|
5
|
-
/** @deprecated - please use CedarRealtimeOptions instead */
|
|
6
|
-
RedwoodRealtimeOptions, } from './plugins/useCedarRealtime';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graphql/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB;AAChB,wDAAwD;AACxD,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,MAAM,EACN,QAAQ,GACT,MAAM,4BAA4B,CAAA;AAEnC,YAAY,EACV,yBAAyB,EACzB,MAAM,EACN,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB;AACpB,4DAA4D;AAC5D,sBAAsB,GACvB,MAAM,4BAA4B,CAAA"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const testSchema: import("graphql").GraphQLSchema;
|
|
2
|
-
export declare const testLiveSchema: import("graphql").GraphQLSchema;
|
|
3
|
-
export declare const testQuery = "\n query meQuery {\n me {\n id\n name\n }\n }\n";
|
|
4
|
-
export declare const testFilteredQuery = "\n query FilteredQuery {\n me {\n id\n name\n }\n }\n";
|
|
5
|
-
export declare const testErrorQuery = "\n query forbiddenUserQuery {\n forbiddenUser {\n id\n name\n }\n }\n";
|
|
6
|
-
export declare const testLiveQuery = "\n query meQuery @live {\n me {\n id\n name\n }\n }\n";
|
|
7
|
-
export declare const testParseErrorQuery = "\n query ParseErrorQuery {\n me {\n id\n name\n unknown_field\n }\n }\n";
|
|
8
|
-
export declare const testValidationErrorQuery = "\n query ValidationErrorQuery(id: Int!) {\n getUser(id: 'one') {\n id\n name\n }\n }\n";
|
|
9
|
-
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/graphql/plugins/__fixtures__/common.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,iCAiCrB,CAAA;AAEF,eAAO,MAAM,cAAc,iCAgDzB,CAAA;AACF,eAAO,MAAM,SAAS,sEAOrB,CAAA;AAED,eAAO,MAAM,iBAAiB,4EAO7B,CAAA;AAED,eAAO,MAAM,cAAc,4FAO1B,CAAA;AAED,eAAO,MAAM,aAAa,4EAOzB,CAAA;AAED,eAAO,MAAM,mBAAmB,mGAQ/B,CAAA;AAED,eAAO,MAAM,wBAAwB,6GAOpC,CAAA"}
|