@coasys/ad4m 0.12.0-rc1-dev.5 → 0.12.0
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/lib/index.cjs +4968 -4805
- package/lib/index.js +4936 -4801
- package/lib/src/agent/AgentClient.d.ts +4 -0
- package/lib/src/agent/AgentClient.js +34 -0
- package/lib/src/index.d.ts +2 -3
- package/lib/src/index.js +2 -3
- package/lib/src/model/Ad4mModel.d.ts +8 -812
- package/lib/src/model/Ad4mModel.js +78 -2390
- package/lib/src/model/ModelQueryBuilder.d.ts +370 -0
- package/lib/src/model/ModelQueryBuilder.js +556 -0
- package/lib/src/model/decorators.d.ts +2 -20
- package/lib/src/model/decorators.js +5 -410
- package/lib/src/model/hydration.d.ts +102 -0
- package/lib/src/model/hydration.js +709 -0
- package/lib/src/model/index.d.ts +20 -0
- package/lib/src/model/index.js +20 -0
- package/lib/src/model/{schema/fromJSONSchema.d.ts → json-schema.d.ts} +45 -12
- package/lib/src/model/json-schema.js +326 -0
- package/lib/src/model/prolog-facts.d.ts +37 -0
- package/lib/src/model/{prolog/generatePrologFacts.js → prolog-facts.js} +47 -52
- package/lib/src/model/query-common.d.ts +14 -0
- package/lib/src/model/query-common.js +36 -0
- package/lib/src/model/query-prolog.d.ts +15 -0
- package/lib/src/model/query-prolog.js +140 -0
- package/lib/src/model/query-surreal.d.ts +44 -0
- package/lib/src/model/query-surreal.js +249 -0
- package/lib/src/model/sdna.d.ts +14 -0
- package/lib/src/model/sdna.js +141 -0
- package/lib/src/model/shacl-gen.d.ts +31 -0
- package/lib/src/model/shacl-gen.js +246 -0
- package/lib/src/model/surreal-utils.d.ts +1 -1
- package/lib/src/model/types.d.ts +75 -96
- package/lib/src/model/types.js +4 -4
- package/lib/src/model/util.d.ts +4 -5
- package/lib/src/model/util.js +12 -32
- package/lib/src/perspectives/PerspectiveClient.d.ts +1 -1
- package/lib/src/perspectives/PerspectiveProxy.d.ts +1 -1
- package/lib/src/perspectives/WakerSubscriptionManager.d.ts +79 -0
- package/lib/src/perspectives/WakerSubscriptionManager.js +196 -0
- package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
- package/lib/src/runtime/RuntimeResolver.js +73 -0
- package/lib/src/schema.gql +14 -0
- package/lib/src/typeDefs.js +14 -0
- package/package.json +13 -8
- package/src/agent/AgentClient.ts +45 -0
- package/src/index.ts +2 -3
- package/src/model/Ad4mModel.ts +1084 -3818
- package/src/model/ModelQueryBuilder.ts +617 -0
- package/src/model/Subject.ts +1 -1
- package/src/model/decorators.ts +17 -475
- package/src/model/hydration.ts +796 -0
- package/src/model/index.ts +21 -0
- package/src/model/json-schema.ts +424 -0
- package/src/model/prolog-facts.ts +145 -0
- package/src/model/query-common.ts +48 -0
- package/src/model/query-prolog.ts +148 -0
- package/src/model/query-surreal.ts +280 -0
- package/src/model/relation-filtering.test.ts +0 -1
- package/src/model/sdna.ts +170 -0
- package/src/model/shacl-gen.ts +292 -0
- package/src/model/surreal-utils.ts +1 -1
- package/src/model/types.ts +182 -0
- package/src/model/util.ts +13 -36
- package/src/perspectives/PerspectiveClient.ts +1 -1
- package/src/perspectives/PerspectiveProxy.ts +1 -1
- package/src/perspectives/WakerSubscriptionManager.ts +292 -0
- package/src/runtime/RuntimeResolver.ts +53 -0
- package/lib/src/Ad4mClient.test.d.ts +0 -1
- package/lib/src/Ad4mClient.test.js +0 -1204
- package/lib/src/Literal.test.d.ts +0 -1
- package/lib/src/Literal.test.js +0 -41
- package/lib/src/model/mutation.d.ts +0 -81
- package/lib/src/model/mutation.js +0 -317
- package/lib/src/model/parentUtils.d.ts +0 -32
- package/lib/src/model/parentUtils.js +0 -64
- package/lib/src/model/prolog/generatePrologFacts.d.ts +0 -36
- package/lib/src/model/prolog/index.d.ts +0 -1
- package/lib/src/model/prolog/index.js +0 -1
- package/lib/src/model/query/ModelQueryBuilder.d.ts +0 -82
- package/lib/src/model/query/ModelQueryBuilder.js +0 -115
- package/lib/src/model/query/QueryBuilder.d.ts +0 -101
- package/lib/src/model/query/QueryBuilder.js +0 -193
- package/lib/src/model/query/SurrealQueryBuilder.d.ts +0 -48
- package/lib/src/model/query/SurrealQueryBuilder.js +0 -371
- package/lib/src/model/query/fetchInstance.d.ts +0 -24
- package/lib/src/model/query/fetchInstance.js +0 -144
- package/lib/src/model/query/hydration.d.ts +0 -54
- package/lib/src/model/query/hydration.js +0 -214
- package/lib/src/model/query/operations.d.ts +0 -59
- package/lib/src/model/query/operations.js +0 -384
- package/lib/src/model/query/snapshot.d.ts +0 -59
- package/lib/src/model/query/snapshot.js +0 -106
- package/lib/src/model/query/surrealCompiler.d.ts +0 -42
- package/lib/src/model/query/surrealCompiler.js +0 -304
- package/lib/src/model/schema/fromJSONSchema.js +0 -264
- package/lib/src/model/schema/metadata.d.ts +0 -15
- package/lib/src/model/schema/metadata.js +0 -112
- package/lib/src/model/subscription.d.ts +0 -47
- package/lib/src/model/subscription.js +0 -231
- package/lib/src/model/transaction.d.ts +0 -27
- package/lib/src/model/transaction.js +0 -32
- package/lib/src/shims/reflect-metadata.d.ts +0 -0
- package/lib/src/shims/type-graphql.d.ts +0 -32
- package/lib/src/src/Ad4mClient.d.ts +0 -28
- package/lib/src/src/Address.d.ts +0 -1
- package/lib/src/src/DID.d.ts +0 -1
- package/lib/src/src/Exception.d.ts +0 -7
- package/lib/src/src/Literal.d.ts +0 -7
- package/lib/src/src/PubSub.d.ts +0 -17
- package/lib/src/src/SmartLiteral.d.ts +0 -12
- package/lib/src/src/agent/Agent.d.ts +0 -110
- package/lib/src/src/agent/AgentClient.d.ts +0 -62
- package/lib/src/src/agent/AgentResolver.d.ts +0 -30
- package/lib/src/src/agent/AgentStatus.d.ts +0 -8
- package/lib/src/src/ai/AIClient.d.ts +0 -32
- package/lib/src/src/ai/AIResolver.d.ts +0 -75
- package/lib/src/src/ai/Tasks.d.ts +0 -37
- package/lib/src/src/buildSchema.d.ts +0 -1
- package/lib/src/src/expression/Expression.d.ts +0 -28
- package/lib/src/src/expression/ExpressionClient.d.ts +0 -13
- package/lib/src/src/expression/ExpressionRef.d.ts +0 -9
- package/lib/src/src/expression/ExpressionResolver.d.ts +0 -10
- package/lib/src/src/index.d.ts +0 -35
- package/lib/src/src/jestSetup.d.ts +0 -1
- package/lib/src/src/language/Icon.d.ts +0 -4
- package/lib/src/src/language/Language.d.ts +0 -206
- package/lib/src/src/language/LanguageClient.d.ts +0 -17
- package/lib/src/src/language/LanguageContext.d.ts +0 -37
- package/lib/src/src/language/LanguageHandle.d.ts +0 -9
- package/lib/src/src/language/LanguageMeta.d.ts +0 -35
- package/lib/src/src/language/LanguageRef.d.ts +0 -6
- package/lib/src/src/language/LanguageResolver.d.ts +0 -19
- package/lib/src/src/links/Links.d.ts +0 -39
- package/lib/src/src/links/Links.test.d.ts +0 -1
- package/lib/src/src/model/Ad4mModel.d.ts +0 -1438
- package/lib/src/src/model/Ad4mModel.test.d.ts +0 -1
- package/lib/src/src/model/Subject.d.ts +0 -25
- package/lib/src/src/model/decorators.d.ts +0 -545
- package/lib/src/src/model/util.d.ts +0 -12
- package/lib/src/src/neighbourhood/Neighbourhood.d.ts +0 -10
- package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +0 -25
- package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +0 -19
- package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +0 -1
- package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +0 -24
- package/lib/src/src/perspectives/LinkQuery.d.ts +0 -11
- package/lib/src/src/perspectives/Perspective.d.ts +0 -38
- package/lib/src/src/perspectives/Perspective.test.d.ts +0 -1
- package/lib/src/src/perspectives/PerspectiveClient.d.ts +0 -97
- package/lib/src/src/perspectives/PerspectiveDiff.d.ts +0 -9
- package/lib/src/src/perspectives/PerspectiveHandle.d.ts +0 -18
- package/lib/src/src/perspectives/PerspectiveProxy.d.ts +0 -865
- package/lib/src/src/perspectives/PerspectiveResolver.d.ts +0 -57
- package/lib/src/src/runtime/RuntimeClient.d.ts +0 -56
- package/lib/src/src/runtime/RuntimeResolver.d.ts +0 -132
- package/lib/src/src/shacl/SHACLFlow.d.ts +0 -171
- package/lib/src/src/shacl/SHACLFlow.test.d.ts +0 -1
- package/lib/src/src/shacl/SHACLShape.d.ts +0 -117
- package/lib/src/src/shacl/SHACLShape.test.d.ts +0 -1
- package/lib/src/src/typeDefs.d.ts +0 -1
- package/lib/src/src/unwrapApolloResult.d.ts +0 -2
- package/lib/src/src/utils.d.ts +0 -25
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WakerSubscriptionManager — manages live SurrealDB subscriptions for the waker.
|
|
3
|
+
*
|
|
4
|
+
* Lives in core so it can be imported by both the plugin and integration tests
|
|
5
|
+
* without ESM/CJS import issues.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: keep in sync with plugins/ad4m/wakerSubscriptionManager.ts
|
|
8
|
+
*/
|
|
9
|
+
export interface WakerSubscription {
|
|
10
|
+
id: string;
|
|
11
|
+
type: "mention" | "channel-messages";
|
|
12
|
+
perspective: string;
|
|
13
|
+
channel: string;
|
|
14
|
+
query: string;
|
|
15
|
+
neighbourhood?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Per-message parent resolution result for mention subscriptions. */
|
|
18
|
+
export interface MentionMessage {
|
|
19
|
+
/** The message's expression address (source of the body link). */
|
|
20
|
+
address: string;
|
|
21
|
+
/** All parent addresses this message belongs to (channels, conversations, etc.). */
|
|
22
|
+
parents: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface WakerLogger {
|
|
25
|
+
info(msg: string): void;
|
|
26
|
+
warn(msg: string): void;
|
|
27
|
+
error(msg: string): void;
|
|
28
|
+
debug(msg: string): void;
|
|
29
|
+
}
|
|
30
|
+
export interface WakerSubscriptionManagerOptions {
|
|
31
|
+
/** PerspectiveClient from Ad4mClient (provides perspectiveSubscribeSurrealQuery etc.) */
|
|
32
|
+
perspectiveClient: any;
|
|
33
|
+
/** Logger instance */
|
|
34
|
+
logger: WakerLogger;
|
|
35
|
+
/** Debounce interval in ms before firing the wake callback (default 2000) */
|
|
36
|
+
debounceMs?: number;
|
|
37
|
+
/** Called when a subscription fires (after debounce). Return value is ignored.
|
|
38
|
+
* For mention subs, `mentions` contains per-message parent info. */
|
|
39
|
+
onWake: (sub: WakerSubscription, result: any, mentions?: MentionMessage[]) => void;
|
|
40
|
+
/** Called when the active subscription list changes (for persistence). */
|
|
41
|
+
onPersist?: (subscriptions: WakerSubscription[], seenMessages: Record<string, string[]>) => void;
|
|
42
|
+
/** Previously persisted seen message IDs per subscription. Seeds seenMessages on resubscribe to avoid duplicate wakes. */
|
|
43
|
+
previousSeenMessages?: Record<string, string[]>;
|
|
44
|
+
/** Optional: provide QuerySubscriptionProxy class directly (avoids require("@coasys/ad4m") at runtime). */
|
|
45
|
+
QuerySubscriptionProxy?: any;
|
|
46
|
+
}
|
|
47
|
+
export declare class WakerSubscriptionManager {
|
|
48
|
+
private perspectiveClient;
|
|
49
|
+
private logger;
|
|
50
|
+
private debounceMs;
|
|
51
|
+
private onWake;
|
|
52
|
+
private onPersist?;
|
|
53
|
+
private QuerySubscriptionProxyCtor;
|
|
54
|
+
private previousSeenMessages;
|
|
55
|
+
private proxies;
|
|
56
|
+
private activeSubscriptions;
|
|
57
|
+
private debounceTimers;
|
|
58
|
+
/** Per-subscription set of already-processed message addresses (for mention subs)
|
|
59
|
+
* or serialized result hash (for channel-messages subs). */
|
|
60
|
+
private seenMessages;
|
|
61
|
+
constructor(options: WakerSubscriptionManagerOptions);
|
|
62
|
+
/**
|
|
63
|
+
* Create a live SurrealDB subscription.
|
|
64
|
+
* If a subscription with the same id already exists, it is disposed first.
|
|
65
|
+
*/
|
|
66
|
+
subscribe(sub: WakerSubscription): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Dispose a single subscription.
|
|
69
|
+
* @param persist — if false, skip calling onPersist (used during batch cleanup).
|
|
70
|
+
*/
|
|
71
|
+
dispose(id: string, persist?: boolean): void;
|
|
72
|
+
/** Dispose all active subscriptions. */
|
|
73
|
+
disposeAll(): void;
|
|
74
|
+
/** Get all active subscriptions. */
|
|
75
|
+
getActive(): WakerSubscription[];
|
|
76
|
+
/** Check if a subscription exists. */
|
|
77
|
+
has(id: string): boolean;
|
|
78
|
+
private persist;
|
|
79
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WakerSubscriptionManager — manages live SurrealDB subscriptions for the waker.
|
|
3
|
+
*
|
|
4
|
+
* Lives in core so it can be imported by both the plugin and integration tests
|
|
5
|
+
* without ESM/CJS import issues.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: keep in sync with plugins/ad4m/wakerSubscriptionManager.ts
|
|
8
|
+
*/
|
|
9
|
+
export class WakerSubscriptionManager {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.proxies = new Map();
|
|
12
|
+
this.activeSubscriptions = new Map();
|
|
13
|
+
this.debounceTimers = new Map();
|
|
14
|
+
/** Per-subscription set of already-processed message addresses (for mention subs)
|
|
15
|
+
* or serialized result hash (for channel-messages subs). */
|
|
16
|
+
this.seenMessages = new Map();
|
|
17
|
+
this.perspectiveClient = options.perspectiveClient;
|
|
18
|
+
this.logger = options.logger;
|
|
19
|
+
this.debounceMs = options.debounceMs ?? 2000;
|
|
20
|
+
this.onWake = options.onWake;
|
|
21
|
+
this.onPersist = options.onPersist;
|
|
22
|
+
this.QuerySubscriptionProxyCtor = options.QuerySubscriptionProxy ?? null;
|
|
23
|
+
this.previousSeenMessages = options.previousSeenMessages ?? {};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create a live SurrealDB subscription.
|
|
27
|
+
* If a subscription with the same id already exists, it is disposed first.
|
|
28
|
+
*/
|
|
29
|
+
async subscribe(sub) {
|
|
30
|
+
// Dispose existing subscription with same id if any
|
|
31
|
+
this.dispose(sub.id, false);
|
|
32
|
+
if (!this.QuerySubscriptionProxyCtor) {
|
|
33
|
+
throw new Error("WakerSubscriptionManager: QuerySubscriptionProxy must be provided via constructor options");
|
|
34
|
+
}
|
|
35
|
+
const QuerySubscriptionProxy = this.QuerySubscriptionProxyCtor;
|
|
36
|
+
this.logger.info(`[waker] ${sub.id}: creating subscription (perspective=${sub.perspective}, type=${sub.type})`);
|
|
37
|
+
this.logger.info(`[waker] ${sub.id}: SurrealQL query:\n${sub.query}`);
|
|
38
|
+
const proxy = new QuerySubscriptionProxy(sub.perspective, sub.query, this.perspectiveClient);
|
|
39
|
+
proxy.isSurrealDB = true;
|
|
40
|
+
// Suppress unhandled rejection from proxy.initialized — QuerySubscriptionProxy
|
|
41
|
+
// rejects this promise internally when subscribe() fails, and if nobody catches
|
|
42
|
+
// it before the next microtask it crashes the process.
|
|
43
|
+
if (proxy.initialized && typeof proxy.initialized.catch === "function") {
|
|
44
|
+
proxy.initialized.catch(() => { });
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await proxy.subscribe();
|
|
48
|
+
await proxy.initialized;
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
const msg = err?.message ?? String(err);
|
|
52
|
+
this.logger.warn(`[waker] ${sub.id}: subscription failed — ${msg}`);
|
|
53
|
+
try {
|
|
54
|
+
proxy.dispose();
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
// Remove from active state so it doesn't get persisted/retried
|
|
58
|
+
this.activeSubscriptions.delete(sub.id);
|
|
59
|
+
this.seenMessages.delete(sub.id);
|
|
60
|
+
this.persist();
|
|
61
|
+
return; // Don't throw — caller should not crash
|
|
62
|
+
}
|
|
63
|
+
this.logger.info(`[waker] ${sub.id}: subscription initialized successfully`);
|
|
64
|
+
// Seed from persisted seen messages so we don't re-wake after restart
|
|
65
|
+
const seen = new Set(this.previousSeenMessages[sub.id] ?? []);
|
|
66
|
+
this.seenMessages.set(sub.id, seen);
|
|
67
|
+
if (seen.size > 0) {
|
|
68
|
+
this.logger.info(`[waker] ${sub.id}: seeded ${seen.size} seen message(s) from persisted state`);
|
|
69
|
+
}
|
|
70
|
+
proxy.onResult(async (result) => {
|
|
71
|
+
this.logger.info(`[waker] ${sub.id}: onResult fired — type=${typeof result}, isArray=${Array.isArray(result)}, value=${String(JSON.stringify(result)).substring(0, 500)}`);
|
|
72
|
+
// SurrealDB can deliver non-array values (e.g. false) on disconnect/reconnect — ignore them
|
|
73
|
+
if (!Array.isArray(result)) {
|
|
74
|
+
this.logger.warn(`[waker] ${sub.id}: ignoring non-array result: ${JSON.stringify(result)}`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (sub.type === "mention") {
|
|
78
|
+
// For mention subscriptions: track seen message addresses.
|
|
79
|
+
// Only wake for messages we haven't seen before.
|
|
80
|
+
const currentSeen = this.seenMessages.get(sub.id) ?? new Set();
|
|
81
|
+
const newMessages = [];
|
|
82
|
+
for (const item of result) {
|
|
83
|
+
if (item && item.source && !currentSeen.has(item.source)) {
|
|
84
|
+
newMessages.push(item.source);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (newMessages.length === 0) {
|
|
88
|
+
this.logger.info(`[waker] ${sub.id}: all ${result.length} items already seen, skipping`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this.logger.info(`[waker] ${sub.id}: ${newMessages.length} new message(s) out of ${result.length} total`);
|
|
92
|
+
// Resolve parents per new message
|
|
93
|
+
const mentions = [];
|
|
94
|
+
for (const msgAddr of newMessages) {
|
|
95
|
+
const parents = [];
|
|
96
|
+
try {
|
|
97
|
+
const escaped = msgAddr.replace(/'/g, "\\'");
|
|
98
|
+
const parentQuery = `SELECT * FROM link WHERE predicate = 'ad4m://has_child' AND target = '${escaped}'`;
|
|
99
|
+
this.logger.info(`[waker] ${sub.id}: resolving parents for ${msgAddr}`);
|
|
100
|
+
const parentResult = await this.perspectiveClient.querySurrealDB(sub.perspective, parentQuery);
|
|
101
|
+
if (Array.isArray(parentResult)) {
|
|
102
|
+
for (const link of parentResult) {
|
|
103
|
+
if (link && link.source) {
|
|
104
|
+
parents.push(link.source);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
this.logger.warn(`[waker] ${sub.id}: parent resolution failed for ${msgAddr} — ${err?.message ?? err}`);
|
|
111
|
+
}
|
|
112
|
+
this.logger.info(`[waker] ${sub.id}: message ${msgAddr} has ${parents.length} parent(s): ${parents.join(", ")}`);
|
|
113
|
+
mentions.push({ address: msgAddr, parents });
|
|
114
|
+
}
|
|
115
|
+
// Mark all new messages as seen
|
|
116
|
+
for (const addr of newMessages) {
|
|
117
|
+
currentSeen.add(addr);
|
|
118
|
+
}
|
|
119
|
+
this.seenMessages.set(sub.id, currentSeen);
|
|
120
|
+
// Debounce the wake callback
|
|
121
|
+
const existing = this.debounceTimers.get(sub.id);
|
|
122
|
+
if (existing)
|
|
123
|
+
clearTimeout(existing);
|
|
124
|
+
this.debounceTimers.set(sub.id, setTimeout(() => {
|
|
125
|
+
this.onWake(sub, result, mentions);
|
|
126
|
+
this.debounceTimers.delete(sub.id);
|
|
127
|
+
this.persist();
|
|
128
|
+
}, this.debounceMs));
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// For channel-messages: always notify the agent on every subscription push.
|
|
132
|
+
// No deduplication — the agent reads recent messages itself.
|
|
133
|
+
this.logger.info(`[waker] ${sub.id}: channel update (${result.length} items)`);
|
|
134
|
+
const existing = this.debounceTimers.get(sub.id);
|
|
135
|
+
if (existing)
|
|
136
|
+
clearTimeout(existing);
|
|
137
|
+
this.debounceTimers.set(sub.id, setTimeout(() => {
|
|
138
|
+
this.onWake(sub, result);
|
|
139
|
+
this.debounceTimers.delete(sub.id);
|
|
140
|
+
}, this.debounceMs));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
this.proxies.set(sub.id, proxy);
|
|
144
|
+
this.activeSubscriptions.set(sub.id, sub);
|
|
145
|
+
this.persist();
|
|
146
|
+
this.logger.info(`[waker] Subscription ${sub.id} active (type=${sub.type}, perspective=${sub.perspective})`);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Dispose a single subscription.
|
|
150
|
+
* @param persist — if false, skip calling onPersist (used during batch cleanup).
|
|
151
|
+
*/
|
|
152
|
+
dispose(id, persist = true) {
|
|
153
|
+
const proxy = this.proxies.get(id);
|
|
154
|
+
if (proxy) {
|
|
155
|
+
try {
|
|
156
|
+
proxy.dispose();
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
/* ignore */
|
|
160
|
+
}
|
|
161
|
+
this.proxies.delete(id);
|
|
162
|
+
}
|
|
163
|
+
const timer = this.debounceTimers.get(id);
|
|
164
|
+
if (timer) {
|
|
165
|
+
clearTimeout(timer);
|
|
166
|
+
this.debounceTimers.delete(id);
|
|
167
|
+
}
|
|
168
|
+
this.activeSubscriptions.delete(id);
|
|
169
|
+
this.seenMessages.delete(id);
|
|
170
|
+
if (persist)
|
|
171
|
+
this.persist();
|
|
172
|
+
}
|
|
173
|
+
/** Dispose all active subscriptions. */
|
|
174
|
+
disposeAll() {
|
|
175
|
+
for (const [id] of this.proxies) {
|
|
176
|
+
this.dispose(id, false);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** Get all active subscriptions. */
|
|
180
|
+
getActive() {
|
|
181
|
+
return Array.from(this.activeSubscriptions.values());
|
|
182
|
+
}
|
|
183
|
+
/** Check if a subscription exists. */
|
|
184
|
+
has(id) {
|
|
185
|
+
return this.activeSubscriptions.has(id);
|
|
186
|
+
}
|
|
187
|
+
persist() {
|
|
188
|
+
if (this.onPersist) {
|
|
189
|
+
const seen = {};
|
|
190
|
+
for (const [id, set] of this.seenMessages) {
|
|
191
|
+
seen[id] = Array.from(set);
|
|
192
|
+
}
|
|
193
|
+
this.onPersist(this.getActive(), seen);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -75,6 +75,17 @@ export declare class VerificationRequestResult {
|
|
|
75
75
|
requiresPassword: boolean;
|
|
76
76
|
isExistingUser: boolean;
|
|
77
77
|
}
|
|
78
|
+
export declare class HostingUserInfo {
|
|
79
|
+
email: string;
|
|
80
|
+
remainingCredits: string;
|
|
81
|
+
hotWalletAddress?: string;
|
|
82
|
+
constructor(email: string, remainingCredits: string, hotWalletAddress?: string);
|
|
83
|
+
}
|
|
84
|
+
export declare class PaymentRequestResult {
|
|
85
|
+
success: boolean;
|
|
86
|
+
message: string;
|
|
87
|
+
constructor(success: boolean, message: string);
|
|
88
|
+
}
|
|
78
89
|
/**
|
|
79
90
|
* Resolver classes are used here to define the GraphQL schema
|
|
80
91
|
* (through the type-graphql annotations)
|
|
@@ -129,4 +140,7 @@ export default class RuntimeResolver {
|
|
|
129
140
|
runtimeEmailTestGetCode(email: string): string | null;
|
|
130
141
|
runtimeEmailTestClearCodes(): boolean;
|
|
131
142
|
runtimeEmailTestSetExpiry(email: string, verificationType: string, expiresAt: number): boolean;
|
|
143
|
+
runtimeHostingUserInfo(): HostingUserInfo;
|
|
144
|
+
runtimeSetHotWalletAddress(address: string): boolean;
|
|
145
|
+
runtimeRequestPayment(amountHOT: string): PaymentRequestResult;
|
|
132
146
|
}
|
|
@@ -315,6 +315,49 @@ VerificationRequestResult = __decorate([
|
|
|
315
315
|
ObjectType()
|
|
316
316
|
], VerificationRequestResult);
|
|
317
317
|
export { VerificationRequestResult };
|
|
318
|
+
let HostingUserInfo = class HostingUserInfo {
|
|
319
|
+
constructor(email, remainingCredits, hotWalletAddress) {
|
|
320
|
+
this.email = email;
|
|
321
|
+
this.remainingCredits = remainingCredits;
|
|
322
|
+
this.hotWalletAddress = hotWalletAddress;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
__decorate([
|
|
326
|
+
Field(),
|
|
327
|
+
__metadata("design:type", String)
|
|
328
|
+
], HostingUserInfo.prototype, "email", void 0);
|
|
329
|
+
__decorate([
|
|
330
|
+
Field(),
|
|
331
|
+
__metadata("design:type", String)
|
|
332
|
+
], HostingUserInfo.prototype, "remainingCredits", void 0);
|
|
333
|
+
__decorate([
|
|
334
|
+
Field({ nullable: true }),
|
|
335
|
+
__metadata("design:type", String)
|
|
336
|
+
], HostingUserInfo.prototype, "hotWalletAddress", void 0);
|
|
337
|
+
HostingUserInfo = __decorate([
|
|
338
|
+
ObjectType(),
|
|
339
|
+
__metadata("design:paramtypes", [String, String, String])
|
|
340
|
+
], HostingUserInfo);
|
|
341
|
+
export { HostingUserInfo };
|
|
342
|
+
let PaymentRequestResult = class PaymentRequestResult {
|
|
343
|
+
constructor(success, message) {
|
|
344
|
+
this.success = success;
|
|
345
|
+
this.message = message;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
__decorate([
|
|
349
|
+
Field(),
|
|
350
|
+
__metadata("design:type", Boolean)
|
|
351
|
+
], PaymentRequestResult.prototype, "success", void 0);
|
|
352
|
+
__decorate([
|
|
353
|
+
Field(),
|
|
354
|
+
__metadata("design:type", String)
|
|
355
|
+
], PaymentRequestResult.prototype, "message", void 0);
|
|
356
|
+
PaymentRequestResult = __decorate([
|
|
357
|
+
ObjectType(),
|
|
358
|
+
__metadata("design:paramtypes", [Boolean, String])
|
|
359
|
+
], PaymentRequestResult);
|
|
360
|
+
export { PaymentRequestResult };
|
|
318
361
|
/**
|
|
319
362
|
* Resolver classes are used here to define the GraphQL schema
|
|
320
363
|
* (through the type-graphql annotations)
|
|
@@ -523,6 +566,16 @@ let RuntimeResolver = class RuntimeResolver {
|
|
|
523
566
|
// For testing: simulate setting expiry (no-op in mock)
|
|
524
567
|
return true;
|
|
525
568
|
}
|
|
569
|
+
// Hosting mutations & queries
|
|
570
|
+
runtimeHostingUserInfo() {
|
|
571
|
+
return new HostingUserInfo("test@example.com", "100000000", null);
|
|
572
|
+
}
|
|
573
|
+
runtimeSetHotWalletAddress(address) {
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
runtimeRequestPayment(amountHOT) {
|
|
577
|
+
return new PaymentRequestResult(true, "Mock payment of " + amountHOT + " base units credited");
|
|
578
|
+
}
|
|
526
579
|
};
|
|
527
580
|
__decorate([
|
|
528
581
|
Mutation(returns => Boolean),
|
|
@@ -850,6 +903,26 @@ __decorate([
|
|
|
850
903
|
__metadata("design:paramtypes", [String, String, Number]),
|
|
851
904
|
__metadata("design:returntype", Boolean)
|
|
852
905
|
], RuntimeResolver.prototype, "runtimeEmailTestSetExpiry", null);
|
|
906
|
+
__decorate([
|
|
907
|
+
Query(returns => HostingUserInfo),
|
|
908
|
+
__metadata("design:type", Function),
|
|
909
|
+
__metadata("design:paramtypes", []),
|
|
910
|
+
__metadata("design:returntype", HostingUserInfo)
|
|
911
|
+
], RuntimeResolver.prototype, "runtimeHostingUserInfo", null);
|
|
912
|
+
__decorate([
|
|
913
|
+
Mutation(returns => Boolean),
|
|
914
|
+
__param(0, Arg("address")),
|
|
915
|
+
__metadata("design:type", Function),
|
|
916
|
+
__metadata("design:paramtypes", [String]),
|
|
917
|
+
__metadata("design:returntype", Boolean)
|
|
918
|
+
], RuntimeResolver.prototype, "runtimeSetHotWalletAddress", null);
|
|
919
|
+
__decorate([
|
|
920
|
+
Mutation(returns => PaymentRequestResult),
|
|
921
|
+
__param(0, Arg("amountHOT")),
|
|
922
|
+
__metadata("design:type", Function),
|
|
923
|
+
__metadata("design:paramtypes", [String]),
|
|
924
|
+
__metadata("design:returntype", PaymentRequestResult)
|
|
925
|
+
], RuntimeResolver.prototype, "runtimeRequestPayment", null);
|
|
853
926
|
RuntimeResolver = __decorate([
|
|
854
927
|
Resolver()
|
|
855
928
|
], RuntimeResolver);
|
package/lib/src/schema.gql
CHANGED
|
@@ -144,6 +144,12 @@ type ExpressionRendered {
|
|
|
144
144
|
timestamp: String!
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
type HostingUserInfo {
|
|
148
|
+
email: String!
|
|
149
|
+
hotWalletAddress: String
|
|
150
|
+
remainingCredits: String!
|
|
151
|
+
}
|
|
152
|
+
|
|
147
153
|
type Icon {
|
|
148
154
|
code: String!
|
|
149
155
|
}
|
|
@@ -379,7 +385,9 @@ type Mutation {
|
|
|
379
385
|
runtimeRemoveNotification(id: String!): Boolean!
|
|
380
386
|
runtimeRequestInstallNotification(notification: NotificationInput!): String!
|
|
381
387
|
runtimeRequestLoginVerification(appInfo: AuthInfoInput, email: String!): VerificationRequestResult!
|
|
388
|
+
runtimeRequestPayment(amountHOT: String!): PaymentRequestResult!
|
|
382
389
|
runtimeRestartHolochain: Boolean!
|
|
390
|
+
runtimeSetHotWalletAddress(address: String!): Boolean!
|
|
383
391
|
runtimeSetMultiUserEnabled(enabled: Boolean!): Boolean!
|
|
384
392
|
runtimeSetStatus(status: PerspectiveInput!): Boolean!
|
|
385
393
|
runtimeTestEmail(to: String!): Boolean!
|
|
@@ -428,6 +436,11 @@ type OnlineAgent {
|
|
|
428
436
|
status: PerspectiveExpression!
|
|
429
437
|
}
|
|
430
438
|
|
|
439
|
+
type PaymentRequestResult {
|
|
440
|
+
message: String!
|
|
441
|
+
success: Boolean!
|
|
442
|
+
}
|
|
443
|
+
|
|
431
444
|
type Perspective {
|
|
432
445
|
links: [LinkExpression!]!
|
|
433
446
|
}
|
|
@@ -489,6 +502,7 @@ type Query {
|
|
|
489
502
|
runtimeFriends: [String!]!
|
|
490
503
|
runtimeGetNetworkMetrics: String!
|
|
491
504
|
runtimeHcAgentInfos: String!
|
|
505
|
+
runtimeHostingUserInfo: HostingUserInfo!
|
|
492
506
|
runtimeInfo: RuntimeInfo!
|
|
493
507
|
runtimeKnownLinkLanguageTemplates: [String!]!
|
|
494
508
|
runtimeListUsers: [UserStatistics!]!
|
package/lib/src/typeDefs.js
CHANGED
|
@@ -140,6 +140,12 @@ type ExpressionRendered {
|
|
|
140
140
|
timestamp: String!
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
type HostingUserInfo {
|
|
144
|
+
email: String!
|
|
145
|
+
hotWalletAddress: String
|
|
146
|
+
remainingCredits: String!
|
|
147
|
+
}
|
|
148
|
+
|
|
143
149
|
type Icon {
|
|
144
150
|
code: String!
|
|
145
151
|
}
|
|
@@ -375,7 +381,9 @@ type Mutation {
|
|
|
375
381
|
runtimeRemoveNotification(id: String!): Boolean!
|
|
376
382
|
runtimeRequestInstallNotification(notification: NotificationInput!): String!
|
|
377
383
|
runtimeRequestLoginVerification(appInfo: AuthInfoInput, email: String!): VerificationRequestResult!
|
|
384
|
+
runtimeRequestPayment(amountHOT: String!): PaymentRequestResult!
|
|
378
385
|
runtimeRestartHolochain: Boolean!
|
|
386
|
+
runtimeSetHotWalletAddress(address: String!): Boolean!
|
|
379
387
|
runtimeSetMultiUserEnabled(enabled: Boolean!): Boolean!
|
|
380
388
|
runtimeSetStatus(status: PerspectiveInput!): Boolean!
|
|
381
389
|
runtimeTestEmail(to: String!): Boolean!
|
|
@@ -424,6 +432,11 @@ type OnlineAgent {
|
|
|
424
432
|
status: PerspectiveExpression!
|
|
425
433
|
}
|
|
426
434
|
|
|
435
|
+
type PaymentRequestResult {
|
|
436
|
+
message: String!
|
|
437
|
+
success: Boolean!
|
|
438
|
+
}
|
|
439
|
+
|
|
427
440
|
type Perspective {
|
|
428
441
|
links: [LinkExpression!]!
|
|
429
442
|
}
|
|
@@ -485,6 +498,7 @@ type Query {
|
|
|
485
498
|
runtimeFriends: [String!]!
|
|
486
499
|
runtimeGetNetworkMetrics: String!
|
|
487
500
|
runtimeHcAgentInfos: String!
|
|
501
|
+
runtimeHostingUserInfo: HostingUserInfo!
|
|
488
502
|
runtimeInfo: RuntimeInfo!
|
|
489
503
|
runtimeKnownLinkLanguageTemplates: [String!]!
|
|
490
504
|
runtimeListUsers: [UserStatistics!]!
|
package/package.json
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "patch-package && tsc && pnpm run buildSchema && pnpm run bundle",
|
|
10
|
+
"buildSchema": "tsx lib/src/buildSchema.js",
|
|
11
|
+
"bundle": "rollup -c rollup.config.js",
|
|
12
|
+
"test": "jest --forceExit"
|
|
13
|
+
},
|
|
8
14
|
"repository": {
|
|
9
15
|
"type": "git",
|
|
10
16
|
"url": "git+https://github.com/coasys/ad4m.git"
|
|
@@ -58,11 +64,10 @@
|
|
|
58
64
|
"ws": "8.13.0"
|
|
59
65
|
},
|
|
60
66
|
"patchedDependencies": {},
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
67
|
+
"pnpm": {
|
|
68
|
+
"patchedDependencies": {
|
|
69
|
+
"graphql@15.7.2": "patches/graphql@15.7.2.patch"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"version": "0.12.0"
|
|
73
|
+
}
|
package/src/agent/AgentClient.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
EntanglementProofInput,
|
|
11
11
|
UserCreationResult,
|
|
12
12
|
} from "./Agent";
|
|
13
|
+
import { HostingUserInfo, PaymentRequestResult } from "../runtime/RuntimeResolver";
|
|
13
14
|
import { AgentStatus } from "./AgentStatus";
|
|
14
15
|
import { LinkMutations } from "../links/Links";
|
|
15
16
|
import { PerspectiveClient } from "../perspectives/PerspectiveClient";
|
|
@@ -588,4 +589,48 @@ export class AgentClient {
|
|
|
588
589
|
);
|
|
589
590
|
return runtimeVerifyEmailCode;
|
|
590
591
|
}
|
|
592
|
+
|
|
593
|
+
// Hosting methods
|
|
594
|
+
|
|
595
|
+
async hostingUserInfo(): Promise<HostingUserInfo> {
|
|
596
|
+
const { runtimeHostingUserInfo } = unwrapApolloResult(
|
|
597
|
+
await this.#apolloClient.query({
|
|
598
|
+
query: gql`query runtimeHostingUserInfo {
|
|
599
|
+
runtimeHostingUserInfo {
|
|
600
|
+
email
|
|
601
|
+
remainingCredits
|
|
602
|
+
hotWalletAddress
|
|
603
|
+
}
|
|
604
|
+
}`,
|
|
605
|
+
})
|
|
606
|
+
);
|
|
607
|
+
return runtimeHostingUserInfo;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
async setHotWalletAddress(address: string): Promise<boolean> {
|
|
611
|
+
const { runtimeSetHotWalletAddress } = unwrapApolloResult(
|
|
612
|
+
await this.#apolloClient.mutate({
|
|
613
|
+
mutation: gql`mutation runtimeSetHotWalletAddress($address: String!) {
|
|
614
|
+
runtimeSetHotWalletAddress(address: $address)
|
|
615
|
+
}`,
|
|
616
|
+
variables: { address },
|
|
617
|
+
})
|
|
618
|
+
);
|
|
619
|
+
return runtimeSetHotWalletAddress;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
async requestPayment(amountHOT: string): Promise<PaymentRequestResult> {
|
|
623
|
+
const { runtimeRequestPayment } = unwrapApolloResult(
|
|
624
|
+
await this.#apolloClient.mutate({
|
|
625
|
+
mutation: gql`mutation runtimeRequestPayment($amountHOT: String!) {
|
|
626
|
+
runtimeRequestPayment(amountHOT: $amountHOT) {
|
|
627
|
+
success
|
|
628
|
+
message
|
|
629
|
+
}
|
|
630
|
+
}`,
|
|
631
|
+
variables: { amountHOT },
|
|
632
|
+
})
|
|
633
|
+
);
|
|
634
|
+
return runtimeRequestPayment;
|
|
635
|
+
}
|
|
591
636
|
}
|
package/src/index.ts
CHANGED
|
@@ -16,11 +16,11 @@ export * from "./Literal";
|
|
|
16
16
|
export * from "./perspectives/Perspective";
|
|
17
17
|
export * from "./perspectives/PerspectiveHandle";
|
|
18
18
|
export * from "./perspectives/PerspectiveProxy";
|
|
19
|
+
export * from "./perspectives/WakerSubscriptionManager";
|
|
19
20
|
export * from "./perspectives/PerspectiveDiff";
|
|
20
21
|
export * from "./perspectives/LinkQuery";
|
|
21
22
|
export * from "./SmartLiteral";
|
|
22
|
-
export * from "./model
|
|
23
|
-
export * from "./model/Subject";
|
|
23
|
+
export * from "./model";
|
|
24
24
|
export * from "./neighbourhood/Neighbourhood";
|
|
25
25
|
export * from "./neighbourhood/NeighbourhoodProxy";
|
|
26
26
|
export * from "./typeDefs";
|
|
@@ -30,6 +30,5 @@ export * from "./agent/AgentClient";
|
|
|
30
30
|
export * from "./ai/AIClient"
|
|
31
31
|
export * from "./ai/Tasks"
|
|
32
32
|
export * from "./runtime/RuntimeResolver"
|
|
33
|
-
export * from './model/Ad4mModel'
|
|
34
33
|
export * from './shacl/SHACLShape'
|
|
35
34
|
export { SHACLFlow, FlowState, FlowTransition, LinkPattern, FlowableCondition } from './shacl/SHACLFlow'
|