@undefineds.co/xpod 0.3.6 → 0.3.14
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/config/cli.json +1 -1
- package/config/cloud.json +54 -22
- package/config/local.json +56 -12
- package/config/resolver.json +10 -2
- package/config/xpod.base.json +50 -0
- package/config/xpod.json +8 -8
- package/dist/agents/config/resolve.js +10 -10
- package/dist/agents/config/resolve.js.map +1 -1
- package/dist/api/chatkit/index.d.ts +1 -1
- package/dist/api/chatkit/index.js.map +1 -1
- package/dist/api/chatkit/pod-store.d.ts +14 -11
- package/dist/api/chatkit/pod-store.js +114 -78
- package/dist/api/chatkit/pod-store.js.map +1 -1
- package/dist/api/chatkit/runtime/AcpAgentRuntime.js +1 -1
- package/dist/api/chatkit/runtime/AcpAgentRuntime.js.map +1 -1
- package/dist/api/chatkit/service.js +1 -1
- package/dist/api/chatkit/service.js.map +1 -1
- package/dist/api/chatkit/types.d.ts +11 -11
- package/dist/api/chatkit/types.js +3 -3
- package/dist/api/chatkit/types.js.map +1 -1
- package/dist/api/container/cloud.js +0 -8
- package/dist/api/container/cloud.js.map +1 -1
- package/dist/api/container/index.js +2 -1
- package/dist/api/container/index.js.map +1 -1
- package/dist/api/container/local.js +0 -7
- package/dist/api/container/local.js.map +1 -1
- package/dist/api/container/routes.js +3 -17
- package/dist/api/container/routes.js.map +1 -1
- package/dist/api/container/types.d.ts +0 -2
- package/dist/api/container/types.js.map +1 -1
- package/dist/api/handlers/PodManagementHandler.d.ts +3 -0
- package/dist/api/handlers/PodManagementHandler.js +71 -1
- package/dist/api/handlers/PodManagementHandler.js.map +1 -1
- package/dist/api/handlers/RunHandler.js +5 -5
- package/dist/api/handlers/RunHandler.js.map +1 -1
- package/dist/api/runs/AgentRuntimeTypes.d.ts +7 -8
- package/dist/api/runs/AgentRuntimeTypes.js.map +1 -1
- package/dist/api/runs/InngestRunExecutionBackend.d.ts +2 -2
- package/dist/api/runs/ManagedRunWorker.d.ts +1 -1
- package/dist/api/runs/ManagedRunWorker.js +6 -6
- package/dist/api/runs/ManagedRunWorker.js.map +1 -1
- package/dist/api/runs/PiAgentRuntimeDriver.d.ts +16 -1
- package/dist/api/runs/PiAgentRuntimeDriver.js +182 -23
- package/dist/api/runs/PiAgentRuntimeDriver.js.map +1 -1
- package/dist/api/runs/RunStateCenter.d.ts +3 -3
- package/dist/api/runs/RunStateCenter.js +13 -13
- package/dist/api/runs/RunStateCenter.js.map +1 -1
- package/dist/api/runs/store.d.ts +4 -4
- package/dist/api/runs/store.js +2 -2
- package/dist/api/runs/store.js.map +1 -1
- package/dist/api/service/VectorStoreService.d.ts +1 -1
- package/dist/api/service/VectorStoreService.js +16 -16
- package/dist/api/service/VectorStoreService.js.map +1 -1
- package/dist/api/tasks/InngestTaskScheduler.d.ts +4 -4
- package/dist/api/tasks/TaskMaterializer.d.ts +3 -3
- package/dist/api/tasks/TaskMaterializer.js +11 -11
- package/dist/api/tasks/TaskMaterializer.js.map +1 -1
- package/dist/api/tasks/TaskService.d.ts +3 -3
- package/dist/api/tasks/TaskService.js +11 -7
- package/dist/api/tasks/TaskService.js.map +1 -1
- package/dist/api/tasks/store.d.ts +10 -4
- package/dist/api/tasks/store.js +14 -4
- package/dist/api/tasks/store.js.map +1 -1
- package/dist/api/workspace/types.d.ts +3 -3
- package/dist/api/workspace/types.js +6 -6
- package/dist/api/workspace/types.js.map +1 -1
- package/dist/cli/commands/config.js +2 -2
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/start.js +9 -3
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/components/components.jsonld +8 -2
- package/dist/components/context.jsonld +302 -51
- package/dist/http/search/SearchHttpHandler.js +8 -8
- package/dist/http/search/SearchHttpHandler.js.map +1 -1
- package/dist/identity/drizzle/PodLookupRepository.d.ts +11 -1
- package/dist/identity/drizzle/PodLookupRepository.js +95 -4
- package/dist/identity/drizzle/PodLookupRepository.js.map +1 -1
- package/dist/identity/drizzle/db.js +4 -43
- package/dist/identity/drizzle/db.js.map +1 -1
- package/dist/identity/drizzle/schema.pg.d.ts +0 -5
- package/dist/identity/drizzle/schema.pg.js +2 -16
- package/dist/identity/drizzle/schema.pg.js.map +1 -1
- package/dist/identity/drizzle/schema.sqlite.d.ts +19 -176
- package/dist/identity/drizzle/schema.sqlite.js +2 -16
- package/dist/identity/drizzle/schema.sqlite.js.map +1 -1
- package/dist/identity/oidc/AutoDetectIdentityProviderHandler.d.ts +4 -4
- package/dist/identity/oidc/AutoDetectIdentityProviderHandler.js +7 -7
- package/dist/identity/oidc/AutoDetectIdentityProviderHandler.js.map +1 -1
- package/dist/identity/oidc/AutoDetectIdentityProviderHandler.jsonld +6 -6
- package/dist/identity/oidc/AutoDetectOidcHandler.d.ts +4 -4
- package/dist/identity/oidc/AutoDetectOidcHandler.js +6 -6
- package/dist/identity/oidc/AutoDetectOidcHandler.js.map +1 -1
- package/dist/identity/oidc/AutoDetectOidcHandler.jsonld +6 -6
- package/dist/identity/oidc/ScopedPickWebIdHandler.d.ts +37 -0
- package/dist/identity/oidc/ScopedPickWebIdHandler.js +211 -0
- package/dist/identity/oidc/ScopedPickWebIdHandler.js.map +1 -0
- package/dist/identity/oidc/ScopedPickWebIdHandler.jsonld +158 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/main.js +8 -2
- package/dist/main.js.map +1 -1
- package/dist/provision/ProvisionPodCreator.d.ts +3 -4
- package/dist/provision/ProvisionPodCreator.js +8 -13
- package/dist/provision/ProvisionPodCreator.js.map +1 -1
- package/dist/provision/ProvisionPodCreator.jsonld +7 -7
- package/dist/runtime/Proxy.d.ts +0 -1
- package/dist/runtime/Proxy.js +0 -9
- package/dist/runtime/Proxy.js.map +1 -1
- package/dist/runtime/bootstrap.d.ts +1 -0
- package/dist/runtime/bootstrap.js +5 -2
- package/dist/runtime/bootstrap.js.map +1 -1
- package/dist/runtime/css-process.d.ts +12 -4
- package/dist/runtime/css-process.js +61 -14
- package/dist/runtime/css-process.js.map +1 -1
- package/dist/runtime/oidc-issuer.d.ts +3 -2
- package/dist/runtime/oidc-issuer.js +3 -2
- package/dist/runtime/oidc-issuer.js.map +1 -1
- package/dist/runtime/runtime-types.d.ts +1 -0
- package/dist/runtime/runtime-types.js.map +1 -1
- package/dist/solidfs/LocalFirstRdfRepresentationResolver.d.ts +21 -0
- package/dist/solidfs/LocalFirstRdfRepresentationResolver.js +38 -0
- package/dist/solidfs/LocalFirstRdfRepresentationResolver.js.map +1 -0
- package/dist/solidfs/LocalSolidFS.d.ts +18 -0
- package/dist/solidfs/LocalSolidFS.js +539 -0
- package/dist/solidfs/LocalSolidFS.js.map +1 -0
- package/dist/solidfs/PodSolidFsHttpClient.d.ts +16 -0
- package/dist/solidfs/PodSolidFsHttpClient.js +93 -0
- package/dist/solidfs/PodSolidFsHttpClient.js.map +1 -0
- package/dist/solidfs/PodSolidFsHydrator.d.ts +27 -0
- package/dist/solidfs/PodSolidFsHydrator.js +127 -0
- package/dist/solidfs/PodSolidFsHydrator.js.map +1 -0
- package/dist/solidfs/PodSolidFsSyncer.d.ts +21 -0
- package/dist/solidfs/PodSolidFsSyncer.js +78 -0
- package/dist/solidfs/PodSolidFsSyncer.js.map +1 -0
- package/dist/solidfs/RdfIndexSolidFsSyncer.d.ts +22 -0
- package/dist/solidfs/RdfIndexSolidFsSyncer.js +131 -0
- package/dist/solidfs/RdfIndexSolidFsSyncer.js.map +1 -0
- package/dist/solidfs/index.d.ts +7 -0
- package/dist/solidfs/index.js +24 -0
- package/dist/solidfs/index.js.map +1 -0
- package/dist/solidfs/types.d.ts +131 -0
- package/dist/solidfs/types.js +19 -0
- package/dist/solidfs/types.js.map +1 -0
- package/dist/storage/RepresentationPartialConvertingStore.js +6 -13
- package/dist/storage/RepresentationPartialConvertingStore.js.map +1 -1
- package/dist/storage/SparqlUpdateResourceStore.d.ts +4 -0
- package/dist/storage/SparqlUpdateResourceStore.js +13 -0
- package/dist/storage/SparqlUpdateResourceStore.js.map +1 -1
- package/dist/storage/SparqlUpdateResourceStore.jsonld +26 -0
- package/dist/storage/accessors/MixDataAccessor.d.ts +85 -4
- package/dist/storage/accessors/MixDataAccessor.js +511 -16
- package/dist/storage/accessors/MixDataAccessor.js.map +1 -1
- package/dist/storage/accessors/MixDataAccessor.jsonld +176 -1
- package/dist/storage/accessors/QuintStoreSparqlDataAccessor.d.ts +7 -0
- package/dist/storage/accessors/QuintStoreSparqlDataAccessor.js +72 -4
- package/dist/storage/accessors/QuintStoreSparqlDataAccessor.js.map +1 -1
- package/dist/storage/accessors/QuintStoreSparqlDataAccessor.jsonld +24 -0
- package/dist/storage/quint/BaseQuintStore.d.ts +3 -0
- package/dist/storage/quint/BaseQuintStore.js +51 -27
- package/dist/storage/quint/BaseQuintStore.js.map +1 -1
- package/dist/storage/quint/PgQuintStore.d.ts +1 -0
- package/dist/storage/quint/PgQuintStore.js +50 -32
- package/dist/storage/quint/PgQuintStore.js.map +1 -1
- package/dist/storage/quint/PgQuintStore.jsonld +4 -3
- package/dist/storage/quint/SqliteQuintStore.d.ts +5 -0
- package/dist/storage/quint/SqliteQuintStore.js +100 -0
- package/dist/storage/quint/SqliteQuintStore.js.map +1 -1
- package/dist/storage/quint/SqliteQuintStore.jsonld +20 -0
- package/dist/storage/quint/types.d.ts +16 -0
- package/dist/storage/quint/types.js.map +1 -1
- package/dist/storage/rdf/Rdf3xTripleIndex.d.ts +55 -0
- package/dist/storage/rdf/Rdf3xTripleIndex.js +1235 -0
- package/dist/storage/rdf/Rdf3xTripleIndex.js.map +1 -0
- package/dist/storage/rdf/RdfContentTypes.d.ts +9 -0
- package/dist/storage/rdf/RdfContentTypes.js +79 -0
- package/dist/storage/rdf/RdfContentTypes.js.map +1 -0
- package/dist/storage/rdf/RdfLocalQueryEngine.d.ts +76 -0
- package/dist/storage/rdf/RdfLocalQueryEngine.js +2636 -0
- package/dist/storage/rdf/RdfLocalQueryEngine.js.map +1 -0
- package/dist/storage/rdf/RdfQuadIndex.d.ts +98 -0
- package/dist/storage/rdf/RdfQuadIndex.js +1840 -0
- package/dist/storage/rdf/RdfQuadIndex.js.map +1 -0
- package/dist/storage/rdf/RdfQuadIndex.jsonld +416 -0
- package/dist/storage/rdf/RdfShadowComparator.d.ts +12 -0
- package/dist/storage/rdf/RdfShadowComparator.js +47 -0
- package/dist/storage/rdf/RdfShadowComparator.js.map +1 -0
- package/dist/storage/rdf/RdfSparqlAdapter.d.ts +147 -0
- package/dist/storage/rdf/RdfSparqlAdapter.js +2420 -0
- package/dist/storage/rdf/RdfSparqlAdapter.js.map +1 -0
- package/dist/storage/rdf/RdfSparqlAdapter.jsonld +414 -0
- package/dist/storage/rdf/RdfTermDictionary.d.ts +27 -0
- package/dist/storage/rdf/RdfTermDictionary.js +352 -0
- package/dist/storage/rdf/RdfTermDictionary.js.map +1 -0
- package/dist/storage/rdf/RdfTermDictionary.jsonld +114 -0
- package/dist/storage/rdf/RdfTermSemantics.d.ts +6 -0
- package/dist/storage/rdf/RdfTermSemantics.js +40 -0
- package/dist/storage/rdf/RdfTermSemantics.js.map +1 -0
- package/dist/storage/rdf/RdfTextIndex.d.ts +23 -0
- package/dist/storage/rdf/RdfTextIndex.js +569 -0
- package/dist/storage/rdf/RdfTextIndex.js.map +1 -0
- package/dist/storage/rdf/RdfVectorIndex.d.ts +22 -0
- package/dist/storage/rdf/RdfVectorIndex.js +631 -0
- package/dist/storage/rdf/RdfVectorIndex.js.map +1 -0
- package/dist/storage/rdf/RdfXmlSerializer.d.ts +2 -0
- package/dist/storage/rdf/RdfXmlSerializer.js +123 -0
- package/dist/storage/rdf/RdfXmlSerializer.js.map +1 -0
- package/dist/storage/rdf/ShadowRdfQuintStore.d.ts +58 -0
- package/dist/storage/rdf/ShadowRdfQuintStore.js +202 -0
- package/dist/storage/rdf/ShadowRdfQuintStore.js.map +1 -0
- package/dist/storage/rdf/ShadowRdfQuintStore.jsonld +308 -0
- package/dist/storage/rdf/SolidRdfEngine.d.ts +51 -0
- package/dist/storage/rdf/SolidRdfEngine.js +264 -0
- package/dist/storage/rdf/SolidRdfEngine.js.map +1 -0
- package/dist/storage/rdf/SolidRdfEngine.jsonld +338 -0
- package/dist/storage/rdf/SolidRdfSparqlEngine.d.ts +92 -0
- package/dist/storage/rdf/SolidRdfSparqlEngine.js +477 -0
- package/dist/storage/rdf/SolidRdfSparqlEngine.js.map +1 -0
- package/dist/storage/rdf/SolidRdfSparqlEngine.jsonld +257 -0
- package/dist/storage/rdf/index.d.ts +15 -0
- package/dist/storage/rdf/index.js +61 -0
- package/dist/storage/rdf/index.js.map +1 -0
- package/dist/storage/rdf/models-benchmark.d.ts +260 -0
- package/dist/storage/rdf/models-benchmark.js +1405 -0
- package/dist/storage/rdf/models-benchmark.js.map +1 -0
- package/dist/storage/rdf/types.d.ts +726 -0
- package/dist/storage/rdf/types.js +3 -0
- package/dist/storage/rdf/types.js.map +1 -0
- package/dist/storage/rdf/types.jsonld +316 -0
- package/dist/storage/vector/VectorIndexingListener.d.ts +5 -5
- package/dist/storage/vector/VectorIndexingListener.js +19 -19
- package/dist/storage/vector/VectorIndexingListener.js.map +1 -1
- package/package.json +3 -2
- package/templates/pod/acp/.acr.hbs +39 -0
- package/templates/pod/acp/README.acr +18 -0
- package/templates/pod/acp/profile/card.acr +22 -0
- package/templates/pod/base/README$.md.hbs +27 -0
- package/templates/pod/base/profile/card$.ttl.hbs +13 -0
- package/templates/pod/wac/.acl.hbs +26 -0
- package/templates/pod/wac/README.acl.hbs +14 -0
- package/templates/pod/wac/profile/card.acl.hbs +19 -0
- package/dist/api/handlers/WebIdProfileHandler.d.ts +0 -16
- package/dist/api/handlers/WebIdProfileHandler.js +0 -423
- package/dist/api/handlers/WebIdProfileHandler.js.map +0 -1
- package/dist/identity/drizzle/WebIdProfileRepository.d.ts +0 -63
- package/dist/identity/drizzle/WebIdProfileRepository.js +0 -168
- package/dist/identity/drizzle/WebIdProfileRepository.js.map +0 -1
- package/dist/identity/drizzle/WebIdProfileRepository.jsonld +0 -112
- package/dist/storage/quint/BaseQuintStore.jsonld +0 -257
|
@@ -3,6 +3,7 @@ export interface PodLookupResult {
|
|
|
3
3
|
podId: string;
|
|
4
4
|
accountId: string;
|
|
5
5
|
baseUrl: string;
|
|
6
|
+
storageUrl?: string;
|
|
6
7
|
webId?: string;
|
|
7
8
|
webIds?: string[];
|
|
8
9
|
nodeId?: string;
|
|
@@ -29,7 +30,7 @@ export declare class PodLookupRepository {
|
|
|
29
30
|
private readonly usageTableName;
|
|
30
31
|
constructor(db: IdentityDatabase, kvTableName?: string);
|
|
31
32
|
/**
|
|
32
|
-
* Find Pod by resource path (matches longest
|
|
33
|
+
* Find Pod by resource path (matches longest canonical storage/base URL prefix).
|
|
33
34
|
*/
|
|
34
35
|
findByResourceIdentifier(resourcePath: string): Promise<PodLookupResult | undefined>;
|
|
35
36
|
/**
|
|
@@ -44,10 +45,18 @@ export declare class PodLookupRepository {
|
|
|
44
45
|
* not have to match the storage base URL.
|
|
45
46
|
*/
|
|
46
47
|
findByWebId(webId: string): Promise<PodLookupResult | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Find Pods by linked WebID URLs in one scan.
|
|
50
|
+
*/
|
|
51
|
+
findByWebIds(webIds: string[]): Promise<PodLookupResult[]>;
|
|
47
52
|
/**
|
|
48
53
|
* List Pods for a specific account.
|
|
49
54
|
*/
|
|
50
55
|
listByAccountId(accountId: string): Promise<PodLookupResult[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Set the canonical storage URL for a Pod in identity_pod_usage.
|
|
58
|
+
*/
|
|
59
|
+
setStorageUrl(podId: string, accountId: string, storageUrl: string): Promise<void>;
|
|
51
60
|
/**
|
|
52
61
|
* Get migration status for a Pod from identity_pod_usage table.
|
|
53
62
|
*/
|
|
@@ -71,6 +80,7 @@ export declare class PodLookupRepository {
|
|
|
71
80
|
* id/account_id/base_url columns (used by some unit tests and older schemas).
|
|
72
81
|
*/
|
|
73
82
|
private getAllPods;
|
|
83
|
+
private getUsageByPodId;
|
|
74
84
|
/**
|
|
75
85
|
* Fast path for CSS WrappedIndexedStorage. WebID indexes point to the root
|
|
76
86
|
* account id, so a single indexed key plus account data row can resolve the
|
|
@@ -18,16 +18,17 @@ class PodLookupRepository {
|
|
|
18
18
|
this.usageTableName = 'identity_pod_usage';
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Find Pod by resource path (matches longest
|
|
21
|
+
* Find Pod by resource path (matches longest canonical storage/base URL prefix).
|
|
22
22
|
*/
|
|
23
23
|
async findByResourceIdentifier(resourcePath) {
|
|
24
24
|
const pods = await this.getAllPods();
|
|
25
25
|
let bestMatch;
|
|
26
26
|
let bestLength = 0;
|
|
27
27
|
for (const pod of pods) {
|
|
28
|
-
|
|
28
|
+
const candidateBase = pod.storageUrl ?? pod.baseUrl;
|
|
29
|
+
if (resourcePath.startsWith(candidateBase) && candidateBase.length > bestLength) {
|
|
29
30
|
bestMatch = pod;
|
|
30
|
-
bestLength =
|
|
31
|
+
bestLength = candidateBase.length;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
return bestMatch;
|
|
@@ -61,7 +62,56 @@ class PodLookupRepository {
|
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
+
const indexed = await this.findByWebIdIndex(normalized);
|
|
66
|
+
if (!indexed) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const usage = await this.getUsageByPodId();
|
|
70
|
+
return {
|
|
71
|
+
...indexed,
|
|
72
|
+
storageUrl: indexed.storageUrl ?? usage.get(indexed.podId)?.storageUrl,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Find Pods by linked WebID URLs in one scan.
|
|
77
|
+
*/
|
|
78
|
+
async findByWebIds(webIds) {
|
|
79
|
+
const normalizedTargets = new Set(webIds.map(normalizeWebId).filter((value) => Boolean(value)));
|
|
80
|
+
if (normalizedTargets.size === 0) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
const results = [];
|
|
84
|
+
const pods = await this.getAllPods();
|
|
85
|
+
for (const pod of pods) {
|
|
86
|
+
const matchedWebId = getPodWebIds(pod).find((candidate) => {
|
|
87
|
+
const normalized = normalizeWebId(candidate);
|
|
88
|
+
return normalized ? normalizedTargets.has(normalized) : false;
|
|
89
|
+
});
|
|
90
|
+
if (!matchedWebId) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
results.push({
|
|
94
|
+
...pod,
|
|
95
|
+
webId: matchedWebId,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (results.length < normalizedTargets.size) {
|
|
99
|
+
const seen = new Set(results.map((result) => normalizeWebId(result.webId)).filter(Boolean));
|
|
100
|
+
for (const normalized of normalizedTargets) {
|
|
101
|
+
if (seen.has(normalized)) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const indexed = await this.findByWebIdIndex(normalized);
|
|
105
|
+
if (indexed) {
|
|
106
|
+
const usage = await this.getUsageByPodId();
|
|
107
|
+
results.push({
|
|
108
|
+
...indexed,
|
|
109
|
+
storageUrl: indexed.storageUrl ?? usage.get(indexed.podId)?.storageUrl,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return results;
|
|
65
115
|
}
|
|
66
116
|
/**
|
|
67
117
|
* List Pods for a specific account.
|
|
@@ -70,6 +120,19 @@ class PodLookupRepository {
|
|
|
70
120
|
const pods = await this.getAllPods();
|
|
71
121
|
return pods.filter((pod) => pod.accountId === accountId);
|
|
72
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Set the canonical storage URL for a Pod in identity_pod_usage.
|
|
125
|
+
*/
|
|
126
|
+
async setStorageUrl(podId, accountId, storageUrl) {
|
|
127
|
+
const tableId = drizzle_orm_1.sql.identifier([this.usageTableName]);
|
|
128
|
+
await (0, db_1.executeStatement)(this.db, (0, drizzle_orm_1.sql) `
|
|
129
|
+
INSERT INTO ${tableId} (pod_id, account_id, storage_url)
|
|
130
|
+
VALUES (${podId}, ${accountId}, ${storageUrl})
|
|
131
|
+
ON CONFLICT (pod_id) DO UPDATE SET
|
|
132
|
+
account_id = ${accountId},
|
|
133
|
+
storage_url = ${storageUrl}
|
|
134
|
+
`);
|
|
135
|
+
}
|
|
73
136
|
/**
|
|
74
137
|
* Get migration status for a Pod from identity_pod_usage table.
|
|
75
138
|
*/
|
|
@@ -143,6 +206,7 @@ class PodLookupRepository {
|
|
|
143
206
|
WHERE key LIKE 'accounts/data/%'
|
|
144
207
|
OR key LIKE '/.internal/accounts/data/%'
|
|
145
208
|
`);
|
|
209
|
+
const usageByPodId = await this.getUsageByPodId();
|
|
146
210
|
const pods = [];
|
|
147
211
|
for (const row of result?.rows ?? []) {
|
|
148
212
|
if (row.id && row.account_id && row.base_url) {
|
|
@@ -150,6 +214,7 @@ class PodLookupRepository {
|
|
|
150
214
|
podId: String(row.id),
|
|
151
215
|
accountId: String(row.account_id),
|
|
152
216
|
baseUrl: String(row.base_url),
|
|
217
|
+
storageUrl: row.storage_url ? String(row.storage_url) : undefined,
|
|
153
218
|
nodeId: row.node_id ? String(row.node_id) : undefined,
|
|
154
219
|
edgeNodeId: row.edge_node_id ? String(row.edge_node_id) : undefined,
|
|
155
220
|
});
|
|
@@ -169,6 +234,7 @@ class PodLookupRepository {
|
|
|
169
234
|
for (const [podId, podData] of Object.entries(podMap)) {
|
|
170
235
|
const pod = podData;
|
|
171
236
|
if (pod.baseUrl && typeof pod.baseUrl === 'string') {
|
|
237
|
+
const usage = usageByPodId.get(podId);
|
|
172
238
|
const podWebIds = [
|
|
173
239
|
typeof pod.webId === 'string' ? pod.webId : undefined,
|
|
174
240
|
...extractPodOwnerWebIds(pod),
|
|
@@ -178,6 +244,7 @@ class PodLookupRepository {
|
|
|
178
244
|
podId,
|
|
179
245
|
accountId,
|
|
180
246
|
baseUrl: pod.baseUrl,
|
|
247
|
+
storageUrl: stringValue(pod.storageUrl) ?? usage?.storageUrl,
|
|
181
248
|
webId: dedupeStrings(podWebIds)[0],
|
|
182
249
|
...webIdsProperty(podWebIds),
|
|
183
250
|
nodeId: typeof pod.nodeId === 'string' ? pod.nodeId : undefined,
|
|
@@ -195,6 +262,27 @@ class PodLookupRepository {
|
|
|
195
262
|
...await this.getPodsFromIndexedStore(),
|
|
196
263
|
]);
|
|
197
264
|
}
|
|
265
|
+
async getUsageByPodId() {
|
|
266
|
+
const tableId = drizzle_orm_1.sql.identifier([this.usageTableName]);
|
|
267
|
+
try {
|
|
268
|
+
const result = await (0, db_1.executeQuery)(this.db, (0, drizzle_orm_1.sql) `
|
|
269
|
+
SELECT pod_id, storage_url FROM ${tableId}
|
|
270
|
+
`);
|
|
271
|
+
const byPodId = new Map();
|
|
272
|
+
for (const row of result.rows) {
|
|
273
|
+
if (!row.pod_id) {
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
byPodId.set(row.pod_id, {
|
|
277
|
+
storageUrl: row.storage_url ?? undefined,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return byPodId;
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
return new Map();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
198
286
|
/**
|
|
199
287
|
* Fast path for CSS WrappedIndexedStorage. WebID indexes point to the root
|
|
200
288
|
* account id, so a single indexed key plus account data row can resolve the
|
|
@@ -272,6 +360,7 @@ class PodLookupRepository {
|
|
|
272
360
|
podId,
|
|
273
361
|
accountId,
|
|
274
362
|
baseUrl: pod.baseUrl,
|
|
363
|
+
storageUrl: stringValue(pod.storageUrl),
|
|
275
364
|
webId: dedupeStrings(podWebIds)[0],
|
|
276
365
|
...webIdsProperty(podWebIds),
|
|
277
366
|
nodeId: typeof pod.nodeId === 'string' ? pod.nodeId : undefined,
|
|
@@ -346,6 +435,7 @@ class PodLookupRepository {
|
|
|
346
435
|
podId,
|
|
347
436
|
accountId,
|
|
348
437
|
baseUrl,
|
|
438
|
+
storageUrl: stringValue(pod.storageUrl),
|
|
349
439
|
webId: podWebIds[0],
|
|
350
440
|
...webIdsProperty(podWebIds),
|
|
351
441
|
nodeId: stringValue(pod.nodeId),
|
|
@@ -438,6 +528,7 @@ function mergePodLookupResults(values) {
|
|
|
438
528
|
byPodId.set(value.podId, {
|
|
439
529
|
...existing,
|
|
440
530
|
baseUrl: existing.baseUrl || value.baseUrl,
|
|
531
|
+
storageUrl: existing.storageUrl ?? value.storageUrl,
|
|
441
532
|
accountId: existing.accountId || value.accountId,
|
|
442
533
|
webId: webIds[0],
|
|
443
534
|
...webIdsProperty(webIds),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PodLookupRepository.js","sourceRoot":"","sources":["../../../src/identity/drizzle/PodLookupRepository.ts"],"names":[],"mappings":";;;AAAA,6CAAkC;AAClC,6BAA6E;AA8B7E;;;;;;GAMG;AACH,MAAa,mBAAmB;IAK9B,YACmB,EAAoB,EACrC,WAAoB;QADH,OAAE,GAAF,EAAE,CAAkB;QAGrC,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,aAAa,CAAC;QAChD,IAAI,CAAC,qBAAqB,GAAG,gBAAgB,CAAC;QAC9C,IAAI,CAAC,cAAc,GAAG,oBAAoB,CAAC;IAC7C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,wBAAwB,CAAC,YAAoB;QACxD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAErC,IAAI,SAAsC,CAAC;QAC3C,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;gBAC5E,SAAS,GAAG,GAAG,CAAC;gBAChB,UAAU,GAAG,GAAG,C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,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,OAAO,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QAC/E,OAAQ,KAAiC,CAAC,OAAO,CAAC;IACpD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC;AAED,SAAS,cAAc,CAAC,GAA0B,EAAE,GAAW,EAAE,KAAa;IAC5E,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAClC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { sql } from 'drizzle-orm';\nimport { type IdentityDatabase, executeQuery, executeStatement } from './db';\n\nexport interface PodLookupResult {\n podId: string;\n accountId: string;\n baseUrl: string;\n webId?: string;\n webIds?: string[];\n nodeId?: string;\n edgeNodeId?: string;\n}\n\nexport interface PodMigrationStatus {\n podId: string;\n nodeId?: string;\n migrationStatus?: 'syncing' | 'done' | null;\n migrationTargetNode?: string;\n migrationProgress?: number;\n}\n\ninterface InternalKvRow {\n key?: string;\n value?: string;\n id?: string;\n account_id?: string;\n base_url?: string;\n node_id?: string;\n edge_node_id?: string;\n}\n\n/**\n * Repository for Pod lookup operations.\n *\n * Reads Pod data from CSS's internal_kv table where account data is stored.\n * CSS stores account data at key \"accounts/data/{accountId}\" with Pod info\n * nested in the \"**pod**\" field.\n */\nexport class PodLookupRepository {\n private readonly kvTableName: string;\n private readonly indexedStoreTableName: string;\n private readonly usageTableName: string;\n\n public constructor(\n private readonly db: IdentityDatabase,\n kvTableName?: string,\n ) {\n this.kvTableName = kvTableName ?? 'internal_kv';\n this.indexedStoreTableName = 'identity_store';\n this.usageTableName = 'identity_pod_usage';\n }\n\n /**\n * Find Pod by resource path (matches longest baseUrl prefix).\n */\n public async findByResourceIdentifier(resourcePath: string): Promise<PodLookupResult | undefined> {\n const pods = await this.getAllPods();\n\n let bestMatch: PodLookupResult | undefined;\n let bestLength = 0;\n\n for (const pod of pods) {\n if (resourcePath.startsWith(pod.baseUrl) && pod.baseUrl.length > bestLength) {\n bestMatch = pod;\n bestLength = pod.baseUrl.length;\n }\n }\n\n return bestMatch;\n }\n\n /**\n * Get Pod by ID.\n */\n public async findById(podId: string): Promise<PodLookupResult | undefined> {\n const pods = await this.getAllPods();\n return pods.find((p) => p.podId === podId);\n }\n\n /**\n * Find Pod by a linked WebID URL.\n *\n * CSS account data stores WebID links separately from Pod base URLs. This is\n * the precise lookup for IdP/SP split deployments where the WebID path does\n * not have to match the storage base URL.\n */\n public async findByWebId(webId: string): Promise<PodLookupResult | undefined> {\n const normalized = normalizeWebId(webId);\n if (!normalized) {\n return undefined;\n }\n\n const pods = await this.getAllPods();\n for (const pod of pods) {\n const matchedWebId = getPodWebIds(pod).find((candidate) => normalizeWebId(candidate) === normalized);\n if (matchedWebId) {\n return {\n ...pod,\n webId: matchedWebId,\n };\n }\n }\n return await this.findByWebIdIndex(normalized);\n }\n\n /**\n * List Pods for a specific account.\n */\n public async listByAccountId(accountId: string): Promise<PodLookupResult[]> {\n const pods = await this.getAllPods();\n return pods.filter((pod) => pod.accountId === accountId);\n }\n\n /**\n * Get migration status for a Pod from identity_pod_usage table.\n */\n public async getMigrationStatus(podId: string): Promise<PodMigrationStatus | undefined> {\n try {\n const tableId = sql.identifier([this.usageTableName]);\n const result = await executeQuery<{\n pod_id?: string;\n id?: string;\n node_id?: string | null;\n migration_status?: string | null;\n migration_target_node?: string | null;\n migration_progress?: number | null;\n }>(this.db, sql`\n SELECT pod_id, node_id, migration_status, migration_target_node, migration_progress\n FROM ${tableId}\n WHERE pod_id = ${podId}\n LIMIT 1\n `);\n\n if (result.rows.length === 0) {\n return undefined;\n }\n const row = result.rows[0];\n return {\n podId: row.pod_id ?? row.id ?? podId,\n nodeId: row.node_id ?? undefined,\n migrationStatus: row.migration_status as 'syncing' | 'done' | null | undefined,\n migrationTargetNode: row.migration_target_node ?? undefined,\n migrationProgress: row.migration_progress ?? undefined,\n };\n } catch {\n // Table might not exist.\n return undefined;\n }\n }\n\n /**\n * Set the nodeId for a Pod in identity_pod_usage table.\n */\n public async setNodeId(podId: string, nodeId: string): Promise<void> {\n const tableId = sql.identifier([this.usageTableName]);\n await executeStatement(this.db, sql`\n INSERT INTO ${tableId} (pod_id, account_id, node_id)\n VALUES (${podId}, '', ${nodeId})\n ON CONFLICT (pod_id) DO UPDATE SET node_id = ${nodeId}\n `);\n }\n\n /**\n * Update migration status for a Pod in identity_pod_usage table.\n */\n public async setMigrationStatus(\n podId: string,\n status: 'syncing' | 'done' | null,\n targetNode?: string | null,\n progress?: number | null,\n ): Promise<void> {\n const tableId = sql.identifier([this.usageTableName]);\n await executeStatement(this.db, sql`\n INSERT INTO ${tableId} (pod_id, account_id, migration_status, migration_target_node, migration_progress)\n VALUES (${podId}, '', ${status}, ${targetNode ?? null}, ${progress ?? 0})\n ON CONFLICT (pod_id) DO UPDATE SET\n migration_status = ${status},\n migration_target_node = ${targetNode ?? null},\n migration_progress = ${progress ?? 0}\n `);\n }\n\n /**\n * List all pods.\n */\n public async listAllPods(): Promise<PodLookupResult[]> {\n return this.getAllPods();\n }\n\n /**\n * Extract all pods from CSS's internal_kv storage.\n *\n * It keeps backward compatibility with legacy rows that already expose\n * id/account_id/base_url columns (used by some unit tests and older schemas).\n */\n private async getAllPods(): Promise<PodLookupResult[]> {\n const kvTableId = sql.identifier([this.kvTableName]);\n\n const result = await executeQuery<InternalKvRow>(this.db, sql`\n SELECT key, value FROM ${kvTableId}\n WHERE key LIKE 'accounts/data/%'\n OR key LIKE '/.internal/accounts/data/%'\n `);\n\n const pods: PodLookupResult[] = [];\n\n for (const row of result?.rows ?? []) {\n if (row.id && row.account_id && row.base_url) {\n pods.push({\n podId: String(row.id),\n accountId: String(row.account_id),\n baseUrl: String(row.base_url),\n nodeId: row.node_id ? String(row.node_id) : undefined,\n edgeNodeId: row.edge_node_id ? String(row.edge_node_id) : undefined,\n });\n continue;\n }\n\n if (!row.key || row.value === undefined) {\n continue;\n }\n\n try {\n const accountId = extractAccountIdFromAccountDataKey(row.key);\n if (!accountId) {\n continue;\n }\n const data = unwrapStoredValue(typeof row.value === 'string' ? JSON.parse(row.value) : row.value);\n\n const podMap = (data as any)['**pod**'] || (data as any).pod || {};\n const webIds = extractAccountWebIds(data);\n\n for (const [podId, podData] of Object.entries(podMap)) {\n const pod = podData as Record<string, unknown>;\n if (pod.baseUrl && typeof pod.baseUrl === 'string') {\n const podWebIds = [\n typeof pod.webId === 'string' ? pod.webId : undefined,\n ...extractPodOwnerWebIds(pod),\n ...webIds,\n ].filter((value): value is string => typeof value === 'string');\n pods.push({\n podId,\n accountId,\n baseUrl: pod.baseUrl,\n webId: dedupeStrings(podWebIds)[0],\n ...webIdsProperty(podWebIds),\n nodeId: typeof pod.nodeId === 'string' ? pod.nodeId : undefined,\n edgeNodeId: typeof pod.edgeNodeId === 'string' ? pod.edgeNodeId : undefined,\n });\n }\n }\n } catch {\n // Skip malformed entries.\n }\n }\n\n return mergePodLookupResults([\n ...pods,\n ...await this.getPodsFromIndexedStore(),\n ]);\n }\n\n /**\n * Fast path for CSS WrappedIndexedStorage. WebID indexes point to the root\n * account id, so a single indexed key plus account data row can resolve the\n * profile without scanning all account records.\n */\n private async findByWebIdIndex(webId: string): Promise<PodLookupResult | undefined> {\n const accountIds = await this.readStringArrayFromKv(`accounts/index/webIdLink/webId/${encodeURIComponent(webId)}`);\n for (const accountId of accountIds) {\n const account = await this.readAccountData(accountId);\n if (!account) {\n continue;\n }\n const pods = this.extractPodsFromAccountData(accountId, account);\n const match = pods.find((pod) => getPodWebIds(pod).some((candidate) => normalizeWebId(candidate) === webId));\n if (match) {\n return {\n ...match,\n webId,\n };\n }\n if (pods.length === 1) {\n return {\n ...pods[0],\n webId,\n ...webIdsProperty([webId, ...getPodWebIds(pods[0])]),\n };\n }\n }\n return undefined;\n }\n\n private async readAccountData(accountId: string): Promise<Record<string, unknown> | undefined> {\n for (const key of [`accounts/data/${accountId}`, `/.internal/accounts/data/${accountId}`]) {\n const value = await this.readKvValue(key);\n const record = parsePayloadRecord(value);\n if (record) {\n return record;\n }\n }\n return undefined;\n }\n\n private async readStringArrayFromKv(key: string): Promise<string[]> {\n const value = await this.readKvValue(key);\n return Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : [];\n }\n\n private async readKvValue(key: string): Promise<unknown> {\n const tableId = sql.identifier([this.kvTableName]);\n try {\n const result = await executeQuery<{ value?: unknown }>(this.db, sql`\n SELECT value FROM ${tableId}\n WHERE key = ${key}\n LIMIT 1\n `);\n if (result.rows.length === 0) {\n return undefined;\n }\n return parseStoredValue(result.rows[0].value);\n } catch {\n return undefined;\n }\n }\n\n private extractPodsFromAccountData(accountId: string, data: Record<string, unknown>): PodLookupResult[] {\n const podMap = (data as any)['**pod**'] || (data as any).pod || {};\n const webIds = extractAccountWebIds(data);\n const pods: PodLookupResult[] = [];\n\n for (const [podId, podData] of Object.entries(podMap)) {\n const pod = podData as Record<string, unknown>;\n if (pod.baseUrl && typeof pod.baseUrl === 'string') {\n const podWebIds = [\n typeof pod.webId === 'string' ? pod.webId : undefined,\n ...extractPodOwnerWebIds(pod),\n ...webIds,\n ].filter((value): value is string => typeof value === 'string');\n pods.push({\n podId,\n accountId,\n baseUrl: pod.baseUrl,\n webId: dedupeStrings(podWebIds)[0],\n ...webIdsProperty(podWebIds),\n nodeId: typeof pod.nodeId === 'string' ? pod.nodeId : undefined,\n edgeNodeId: typeof pod.edgeNodeId === 'string' ? pod.edgeNodeId : undefined,\n });\n }\n }\n\n return pods;\n }\n\n /**\n * Older Xpod/CSS deployments may have used the IndexedStorage-compatible\n * identity_store table instead of CSS's WrappedIndexedStorage JSON tree in\n * internal_kv. Keep this as a read-only compatibility source so hosted WebID\n * profile lookup still works after storage implementation changes.\n */\n private async getPodsFromIndexedStore(): Promise<PodLookupResult[]> {\n const storeTableId = sql.identifier([this.indexedStoreTableName]);\n let result: { rows?: Array<{ container?: string; id?: string; payload?: unknown }> } | undefined;\n try {\n result = await executeQuery(this.db, sql`\n SELECT container, id, payload FROM ${storeTableId}\n WHERE container IN ('pod', 'owner', 'webIdLink')\n `);\n } catch {\n return [];\n }\n\n const podPayloads = new Map<string, Record<string, unknown>>();\n const ownerWebIdsByPodId = new Map<string, string[]>();\n const webIdsByAccountId = new Map<string, string[]>();\n\n for (const row of result?.rows ?? []) {\n if (!row.id || !row.container) {\n continue;\n }\n const payload = parsePayloadRecord(row.payload);\n if (!payload) {\n continue;\n }\n\n if (row.container === 'pod') {\n podPayloads.set(row.id, payload);\n continue;\n }\n\n if (row.container === 'owner') {\n const podId = stringValue(payload.podId);\n const webId = stringValue(payload.webId);\n if (podId && webId) {\n appendMapValue(ownerWebIdsByPodId, podId, webId);\n }\n continue;\n }\n\n if (row.container === 'webIdLink') {\n const accountId = stringValue(payload.accountId);\n const webId = stringValue(payload.webId);\n if (accountId && webId) {\n appendMapValue(webIdsByAccountId, accountId, webId);\n }\n }\n }\n\n const pods: PodLookupResult[] = [];\n for (const [podId, pod] of podPayloads) {\n const baseUrl = stringValue(pod.baseUrl);\n const accountId = stringValue(pod.accountId);\n if (!baseUrl || !accountId) {\n continue;\n }\n const podWebIds = dedupeStrings([\n stringValue(pod.webId),\n ...(ownerWebIdsByPodId.get(podId) ?? []),\n ...(webIdsByAccountId.get(accountId) ?? []),\n ].filter((value): value is string => typeof value === 'string'));\n\n pods.push({\n podId,\n accountId,\n baseUrl,\n webId: podWebIds[0],\n ...webIdsProperty(podWebIds),\n nodeId: stringValue(pod.nodeId),\n edgeNodeId: stringValue(pod.edgeNodeId),\n });\n }\n\n return pods;\n }\n}\n\nfunction extractAccountIdFromAccountDataKey(key: string): string | undefined {\n const marker = 'accounts/data/';\n const index = key.indexOf(marker);\n if (index < 0) {\n return undefined;\n }\n const accountId = key.slice(index + marker.length).replace(/\\.json$/u, '');\n return accountId || undefined;\n}\n\nfunction extractAccountWebIds(data: unknown): string[] {\n if (!data || typeof data !== 'object') {\n return [];\n }\n\n const record = data as Record<string, unknown>;\n const linkMap = record['**webIdLink**'] || record.webIdLink || {};\n if (!linkMap || typeof linkMap !== 'object') {\n return [];\n }\n\n return Object.values(linkMap as Record<string, unknown>)\n .map((value) => {\n if (!value || typeof value !== 'object') {\n return undefined;\n }\n const webId = (value as Record<string, unknown>).webId;\n return typeof webId === 'string' ? webId : undefined;\n })\n .filter((value): value is string => typeof value === 'string');\n}\n\nfunction extractPodOwnerWebIds(pod: Record<string, unknown>): string[] {\n const ownerMap = pod['**owner**'] || pod.owner || {};\n if (!ownerMap || typeof ownerMap !== 'object') {\n return [];\n }\n\n return Object.values(ownerMap as Record<string, unknown>)\n .map((value) => {\n if (!value || typeof value !== 'object') {\n return undefined;\n }\n const webId = (value as Record<string, unknown>).webId;\n return typeof webId === 'string' ? webId : undefined;\n })\n .filter((value): value is string => typeof value === 'string');\n}\n\nfunction normalizeWebId(webId: string | undefined): string | undefined {\n if (!webId) {\n return undefined;\n }\n try {\n return new URL(webId).toString();\n } catch {\n return webId;\n }\n}\n\nfunction dedupeStrings(values: string[]): string[] {\n return [...new Set(values)];\n}\n\nfunction getPodWebIds(pod: PodLookupResult): string[] {\n return dedupeStrings([\n pod.webId,\n ...(pod.webIds ?? []),\n ].filter((value): value is string => typeof value === 'string' && value.length > 0));\n}\n\nfunction webIdsProperty(values: string[]): Pick<PodLookupResult, 'webIds'> {\n const webIds = dedupeStrings(values);\n return webIds.length > 1 ? { webIds } : {};\n}\n\nfunction mergePodLookupResults(values: PodLookupResult[]): PodLookupResult[] {\n const byPodId = new Map<string, PodLookupResult>();\n for (const value of values) {\n const existing = byPodId.get(value.podId);\n if (!existing) {\n byPodId.set(value.podId, value);\n continue;\n }\n\n const webIds = dedupeStrings([\n ...getPodWebIds(existing),\n ...getPodWebIds(value),\n ]);\n byPodId.set(value.podId, {\n ...existing,\n baseUrl: existing.baseUrl || value.baseUrl,\n accountId: existing.accountId || value.accountId,\n webId: webIds[0],\n ...webIdsProperty(webIds),\n nodeId: existing.nodeId ?? value.nodeId,\n edgeNodeId: existing.edgeNodeId ?? value.edgeNodeId,\n });\n }\n return [...byPodId.values()];\n}\n\nfunction parsePayloadRecord(value: unknown): Record<string, unknown> | undefined {\n if (!value) {\n return undefined;\n }\n if (typeof value === 'string') {\n try {\n const parsed = JSON.parse(value) as unknown;\n const unwrapped = unwrapStoredValue(parsed);\n return unwrapped && typeof unwrapped === 'object' ? unwrapped as Record<string, unknown> : undefined;\n } catch {\n return undefined;\n }\n }\n const unwrapped = unwrapStoredValue(value);\n return typeof unwrapped === 'object' ? unwrapped as Record<string, unknown> : undefined;\n}\n\nfunction parseStoredValue(value: unknown): unknown {\n if (typeof value === 'string') {\n try {\n return unwrapStoredValue(JSON.parse(value));\n } catch {\n return undefined;\n }\n }\n return unwrapStoredValue(value);\n}\n\nfunction unwrapStoredValue(value: unknown): unknown {\n if (value && typeof value === 'object' && 'key' in value && 'payload' in value) {\n return (value as Record<string, unknown>).payload;\n }\n return value;\n}\n\nfunction stringValue(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\nfunction appendMapValue(map: Map<string, string[]>, key: string, value: string): void {\n const values = map.get(key) ?? [];\n values.push(value);\n map.set(key, values);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PodLookupRepository.js","sourceRoot":"","sources":["../../../src/identity/drizzle/PodLookupRepository.ts"],"names":[],"mappings":";;;AAAA,6CAAkC;AAClC,6BAA6E;AAqC7E;;;;;;GAMG;AACH,MAAa,mBAAmB;IAK9B,YACmB,EAAoB,EACrC,WAAoB;QADH,OAAE,GAAF,EAAE,CAAkB;QAGrC,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,aAAa,CAAC;QAChD,IAAI,CAAC,qBAAqB,GAAG,gBAAgB,CAAC;QAC9C,IAAI,CAAC,cAAc,GAAG,oBAAoB,CAAC;IAC7C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,wBAAwB,CAAC,YAAoB;QACxD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAErC,IAAI,SAAsC,CAAC;QAC3C,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,aAAa,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,OAAO,CAAC;YACpD,IAAI,YAAY,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;gBAChF,SAAS,GAAG,GAAG,CAAC;gBAChB,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC;YACpC,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ,CAAC,KAAa;QACjC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK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C;IACpD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC;AAED,SAAS,cAAc,CAAC,GAA0B,EAAE,GAAW,EAAE,KAAa;IAC5E,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAClC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { sql } from 'drizzle-orm';\nimport { type IdentityDatabase, executeQuery, executeStatement } from './db';\n\nexport interface PodLookupResult {\n podId: string;\n accountId: string;\n baseUrl: string;\n storageUrl?: string;\n webId?: string;\n webIds?: string[];\n nodeId?: string;\n edgeNodeId?: string;\n}\n\nexport interface PodMigrationStatus {\n podId: string;\n nodeId?: string;\n migrationStatus?: 'syncing' | 'done' | null;\n migrationTargetNode?: string;\n migrationProgress?: number;\n}\n\ninterface InternalKvRow {\n key?: string;\n value?: string;\n id?: string;\n account_id?: string;\n base_url?: string;\n storage_url?: string;\n node_id?: string;\n edge_node_id?: string;\n}\n\ninterface PodUsageRow {\n pod_id?: string;\n storage_url?: string | null;\n}\n\n/**\n * Repository for Pod lookup operations.\n *\n * Reads Pod data from CSS's internal_kv table where account data is stored.\n * CSS stores account data at key \"accounts/data/{accountId}\" with Pod info\n * nested in the \"**pod**\" field.\n */\nexport class PodLookupRepository {\n private readonly kvTableName: string;\n private readonly indexedStoreTableName: string;\n private readonly usageTableName: string;\n\n public constructor(\n private readonly db: IdentityDatabase,\n kvTableName?: string,\n ) {\n this.kvTableName = kvTableName ?? 'internal_kv';\n this.indexedStoreTableName = 'identity_store';\n this.usageTableName = 'identity_pod_usage';\n }\n\n /**\n * Find Pod by resource path (matches longest canonical storage/base URL prefix).\n */\n public async findByResourceIdentifier(resourcePath: string): Promise<PodLookupResult | undefined> {\n const pods = await this.getAllPods();\n\n let bestMatch: PodLookupResult | undefined;\n let bestLength = 0;\n\n for (const pod of pods) {\n const candidateBase = pod.storageUrl ?? pod.baseUrl;\n if (resourcePath.startsWith(candidateBase) && candidateBase.length > bestLength) {\n bestMatch = pod;\n bestLength = candidateBase.length;\n }\n }\n\n return bestMatch;\n }\n\n /**\n * Get Pod by ID.\n */\n public async findById(podId: string): Promise<PodLookupResult | undefined> {\n const pods = await this.getAllPods();\n return pods.find((p) => p.podId === podId);\n }\n\n /**\n * Find Pod by a linked WebID URL.\n *\n * CSS account data stores WebID links separately from Pod base URLs. This is\n * the precise lookup for IdP/SP split deployments where the WebID path does\n * not have to match the storage base URL.\n */\n public async findByWebId(webId: string): Promise<PodLookupResult | undefined> {\n const normalized = normalizeWebId(webId);\n if (!normalized) {\n return undefined;\n }\n\n const pods = await this.getAllPods();\n for (const pod of pods) {\n const matchedWebId = getPodWebIds(pod).find((candidate) => normalizeWebId(candidate) === normalized);\n if (matchedWebId) {\n return {\n ...pod,\n webId: matchedWebId,\n };\n }\n }\n const indexed = await this.findByWebIdIndex(normalized);\n if (!indexed) {\n return undefined;\n }\n const usage = await this.getUsageByPodId();\n return {\n ...indexed,\n storageUrl: indexed.storageUrl ?? usage.get(indexed.podId)?.storageUrl,\n };\n }\n\n /**\n * Find Pods by linked WebID URLs in one scan.\n */\n public async findByWebIds(webIds: string[]): Promise<PodLookupResult[]> {\n const normalizedTargets = new Set(webIds.map(normalizeWebId).filter((value): value is string => Boolean(value)));\n if (normalizedTargets.size === 0) {\n return [];\n }\n\n const results: PodLookupResult[] = [];\n const pods = await this.getAllPods();\n for (const pod of pods) {\n const matchedWebId = getPodWebIds(pod).find((candidate) => {\n const normalized = normalizeWebId(candidate);\n return normalized ? normalizedTargets.has(normalized) : false;\n });\n if (!matchedWebId) {\n continue;\n }\n results.push({\n ...pod,\n webId: matchedWebId,\n });\n }\n if (results.length < normalizedTargets.size) {\n const seen = new Set(results.map((result) => normalizeWebId(result.webId)).filter(Boolean));\n for (const normalized of normalizedTargets) {\n if (seen.has(normalized)) {\n continue;\n }\n const indexed = await this.findByWebIdIndex(normalized);\n if (indexed) {\n const usage = await this.getUsageByPodId();\n results.push({\n ...indexed,\n storageUrl: indexed.storageUrl ?? usage.get(indexed.podId)?.storageUrl,\n });\n }\n }\n }\n return results;\n }\n\n /**\n * List Pods for a specific account.\n */\n public async listByAccountId(accountId: string): Promise<PodLookupResult[]> {\n const pods = await this.getAllPods();\n return pods.filter((pod) => pod.accountId === accountId);\n }\n\n /**\n * Set the canonical storage URL for a Pod in identity_pod_usage.\n */\n public async setStorageUrl(podId: string, accountId: string, storageUrl: string): Promise<void> {\n const tableId = sql.identifier([this.usageTableName]);\n await executeStatement(this.db, sql`\n INSERT INTO ${tableId} (pod_id, account_id, storage_url)\n VALUES (${podId}, ${accountId}, ${storageUrl})\n ON CONFLICT (pod_id) DO UPDATE SET\n account_id = ${accountId},\n storage_url = ${storageUrl}\n `);\n }\n\n /**\n * Get migration status for a Pod from identity_pod_usage table.\n */\n public async getMigrationStatus(podId: string): Promise<PodMigrationStatus | undefined> {\n try {\n const tableId = sql.identifier([this.usageTableName]);\n const result = await executeQuery<{\n pod_id?: string;\n id?: string;\n node_id?: string | null;\n migration_status?: string | null;\n migration_target_node?: string | null;\n migration_progress?: number | null;\n }>(this.db, sql`\n SELECT pod_id, node_id, migration_status, migration_target_node, migration_progress\n FROM ${tableId}\n WHERE pod_id = ${podId}\n LIMIT 1\n `);\n\n if (result.rows.length === 0) {\n return undefined;\n }\n const row = result.rows[0];\n return {\n podId: row.pod_id ?? row.id ?? podId,\n nodeId: row.node_id ?? undefined,\n migrationStatus: row.migration_status as 'syncing' | 'done' | null | undefined,\n migrationTargetNode: row.migration_target_node ?? undefined,\n migrationProgress: row.migration_progress ?? undefined,\n };\n } catch {\n // Table might not exist.\n return undefined;\n }\n }\n\n /**\n * Set the nodeId for a Pod in identity_pod_usage table.\n */\n public async setNodeId(podId: string, nodeId: string): Promise<void> {\n const tableId = sql.identifier([this.usageTableName]);\n await executeStatement(this.db, sql`\n INSERT INTO ${tableId} (pod_id, account_id, node_id)\n VALUES (${podId}, '', ${nodeId})\n ON CONFLICT (pod_id) DO UPDATE SET node_id = ${nodeId}\n `);\n }\n\n /**\n * Update migration status for a Pod in identity_pod_usage table.\n */\n public async setMigrationStatus(\n podId: string,\n status: 'syncing' | 'done' | null,\n targetNode?: string | null,\n progress?: number | null,\n ): Promise<void> {\n const tableId = sql.identifier([this.usageTableName]);\n await executeStatement(this.db, sql`\n INSERT INTO ${tableId} (pod_id, account_id, migration_status, migration_target_node, migration_progress)\n VALUES (${podId}, '', ${status}, ${targetNode ?? null}, ${progress ?? 0})\n ON CONFLICT (pod_id) DO UPDATE SET\n migration_status = ${status},\n migration_target_node = ${targetNode ?? null},\n migration_progress = ${progress ?? 0}\n `);\n }\n\n /**\n * List all pods.\n */\n public async listAllPods(): Promise<PodLookupResult[]> {\n return this.getAllPods();\n }\n\n /**\n * Extract all pods from CSS's internal_kv storage.\n *\n * It keeps backward compatibility with legacy rows that already expose\n * id/account_id/base_url columns (used by some unit tests and older schemas).\n */\n private async getAllPods(): Promise<PodLookupResult[]> {\n const kvTableId = sql.identifier([this.kvTableName]);\n\n const result = await executeQuery<InternalKvRow>(this.db, sql`\n SELECT key, value FROM ${kvTableId}\n WHERE key LIKE 'accounts/data/%'\n OR key LIKE '/.internal/accounts/data/%'\n `);\n const usageByPodId = await this.getUsageByPodId();\n\n const pods: PodLookupResult[] = [];\n\n for (const row of result?.rows ?? []) {\n if (row.id && row.account_id && row.base_url) {\n pods.push({\n podId: String(row.id),\n accountId: String(row.account_id),\n baseUrl: String(row.base_url),\n storageUrl: row.storage_url ? String(row.storage_url) : undefined,\n nodeId: row.node_id ? String(row.node_id) : undefined,\n edgeNodeId: row.edge_node_id ? String(row.edge_node_id) : undefined,\n });\n continue;\n }\n\n if (!row.key || row.value === undefined) {\n continue;\n }\n\n try {\n const accountId = extractAccountIdFromAccountDataKey(row.key);\n if (!accountId) {\n continue;\n }\n const data = unwrapStoredValue(typeof row.value === 'string' ? JSON.parse(row.value) : row.value);\n\n const podMap = (data as any)['**pod**'] || (data as any).pod || {};\n const webIds = extractAccountWebIds(data);\n\n for (const [podId, podData] of Object.entries(podMap)) {\n const pod = podData as Record<string, unknown>;\n if (pod.baseUrl && typeof pod.baseUrl === 'string') {\n const usage = usageByPodId.get(podId);\n const podWebIds = [\n typeof pod.webId === 'string' ? pod.webId : undefined,\n ...extractPodOwnerWebIds(pod),\n ...webIds,\n ].filter((value): value is string => typeof value === 'string');\n pods.push({\n podId,\n accountId,\n baseUrl: pod.baseUrl,\n storageUrl: stringValue(pod.storageUrl) ?? usage?.storageUrl,\n webId: dedupeStrings(podWebIds)[0],\n ...webIdsProperty(podWebIds),\n nodeId: typeof pod.nodeId === 'string' ? pod.nodeId : undefined,\n edgeNodeId: typeof pod.edgeNodeId === 'string' ? pod.edgeNodeId : undefined,\n });\n }\n }\n } catch {\n // Skip malformed entries.\n }\n }\n\n return mergePodLookupResults([\n ...pods,\n ...await this.getPodsFromIndexedStore(),\n ]);\n }\n\n private async getUsageByPodId(): Promise<Map<string, { storageUrl?: string }>> {\n const tableId = sql.identifier([this.usageTableName]);\n try {\n const result = await executeQuery<PodUsageRow>(this.db, sql`\n SELECT pod_id, storage_url FROM ${tableId}\n `);\n const byPodId = new Map<string, { storageUrl?: string }>();\n for (const row of result.rows) {\n if (!row.pod_id) {\n continue;\n }\n byPodId.set(row.pod_id, {\n storageUrl: row.storage_url ?? undefined,\n });\n }\n return byPodId;\n } catch {\n return new Map();\n }\n }\n\n /**\n * Fast path for CSS WrappedIndexedStorage. WebID indexes point to the root\n * account id, so a single indexed key plus account data row can resolve the\n * profile without scanning all account records.\n */\n private async findByWebIdIndex(webId: string): Promise<PodLookupResult | undefined> {\n const accountIds = await this.readStringArrayFromKv(`accounts/index/webIdLink/webId/${encodeURIComponent(webId)}`);\n for (const accountId of accountIds) {\n const account = await this.readAccountData(accountId);\n if (!account) {\n continue;\n }\n const pods = this.extractPodsFromAccountData(accountId, account);\n const match = pods.find((pod) => getPodWebIds(pod).some((candidate) => normalizeWebId(candidate) === webId));\n if (match) {\n return {\n ...match,\n webId,\n };\n }\n if (pods.length === 1) {\n return {\n ...pods[0],\n webId,\n ...webIdsProperty([webId, ...getPodWebIds(pods[0])]),\n };\n }\n }\n return undefined;\n }\n\n private async readAccountData(accountId: string): Promise<Record<string, unknown> | undefined> {\n for (const key of [`accounts/data/${accountId}`, `/.internal/accounts/data/${accountId}`]) {\n const value = await this.readKvValue(key);\n const record = parsePayloadRecord(value);\n if (record) {\n return record;\n }\n }\n return undefined;\n }\n\n private async readStringArrayFromKv(key: string): Promise<string[]> {\n const value = await this.readKvValue(key);\n return Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : [];\n }\n\n private async readKvValue(key: string): Promise<unknown> {\n const tableId = sql.identifier([this.kvTableName]);\n try {\n const result = await executeQuery<{ value?: unknown }>(this.db, sql`\n SELECT value FROM ${tableId}\n WHERE key = ${key}\n LIMIT 1\n `);\n if (result.rows.length === 0) {\n return undefined;\n }\n return parseStoredValue(result.rows[0].value);\n } catch {\n return undefined;\n }\n }\n\n private extractPodsFromAccountData(accountId: string, data: Record<string, unknown>): PodLookupResult[] {\n const podMap = (data as any)['**pod**'] || (data as any).pod || {};\n const webIds = extractAccountWebIds(data);\n const pods: PodLookupResult[] = [];\n\n for (const [podId, podData] of Object.entries(podMap)) {\n const pod = podData as Record<string, unknown>;\n if (pod.baseUrl && typeof pod.baseUrl === 'string') {\n const podWebIds = [\n typeof pod.webId === 'string' ? pod.webId : undefined,\n ...extractPodOwnerWebIds(pod),\n ...webIds,\n ].filter((value): value is string => typeof value === 'string');\n pods.push({\n podId,\n accountId,\n baseUrl: pod.baseUrl,\n storageUrl: stringValue(pod.storageUrl),\n webId: dedupeStrings(podWebIds)[0],\n ...webIdsProperty(podWebIds),\n nodeId: typeof pod.nodeId === 'string' ? pod.nodeId : undefined,\n edgeNodeId: typeof pod.edgeNodeId === 'string' ? pod.edgeNodeId : undefined,\n });\n }\n }\n\n return pods;\n }\n\n /**\n * Older Xpod/CSS deployments may have used the IndexedStorage-compatible\n * identity_store table instead of CSS's WrappedIndexedStorage JSON tree in\n * internal_kv. Keep this as a read-only compatibility source so hosted WebID\n * profile lookup still works after storage implementation changes.\n */\n private async getPodsFromIndexedStore(): Promise<PodLookupResult[]> {\n const storeTableId = sql.identifier([this.indexedStoreTableName]);\n let result: { rows?: Array<{ container?: string; id?: string; payload?: unknown }> } | undefined;\n try {\n result = await executeQuery(this.db, sql`\n SELECT container, id, payload FROM ${storeTableId}\n WHERE container IN ('pod', 'owner', 'webIdLink')\n `);\n } catch {\n return [];\n }\n\n const podPayloads = new Map<string, Record<string, unknown>>();\n const ownerWebIdsByPodId = new Map<string, string[]>();\n const webIdsByAccountId = new Map<string, string[]>();\n\n for (const row of result?.rows ?? []) {\n if (!row.id || !row.container) {\n continue;\n }\n const payload = parsePayloadRecord(row.payload);\n if (!payload) {\n continue;\n }\n\n if (row.container === 'pod') {\n podPayloads.set(row.id, payload);\n continue;\n }\n\n if (row.container === 'owner') {\n const podId = stringValue(payload.podId);\n const webId = stringValue(payload.webId);\n if (podId && webId) {\n appendMapValue(ownerWebIdsByPodId, podId, webId);\n }\n continue;\n }\n\n if (row.container === 'webIdLink') {\n const accountId = stringValue(payload.accountId);\n const webId = stringValue(payload.webId);\n if (accountId && webId) {\n appendMapValue(webIdsByAccountId, accountId, webId);\n }\n }\n }\n\n const pods: PodLookupResult[] = [];\n for (const [podId, pod] of podPayloads) {\n const baseUrl = stringValue(pod.baseUrl);\n const accountId = stringValue(pod.accountId);\n if (!baseUrl || !accountId) {\n continue;\n }\n const podWebIds = dedupeStrings([\n stringValue(pod.webId),\n ...(ownerWebIdsByPodId.get(podId) ?? []),\n ...(webIdsByAccountId.get(accountId) ?? []),\n ].filter((value): value is string => typeof value === 'string'));\n\n pods.push({\n podId,\n accountId,\n baseUrl,\n storageUrl: stringValue(pod.storageUrl),\n webId: podWebIds[0],\n ...webIdsProperty(podWebIds),\n nodeId: stringValue(pod.nodeId),\n edgeNodeId: stringValue(pod.edgeNodeId),\n });\n }\n\n return pods;\n }\n}\n\nfunction extractAccountIdFromAccountDataKey(key: string): string | undefined {\n const marker = 'accounts/data/';\n const index = key.indexOf(marker);\n if (index < 0) {\n return undefined;\n }\n const accountId = key.slice(index + marker.length).replace(/\\.json$/u, '');\n return accountId || undefined;\n}\n\nfunction extractAccountWebIds(data: unknown): string[] {\n if (!data || typeof data !== 'object') {\n return [];\n }\n\n const record = data as Record<string, unknown>;\n const linkMap = record['**webIdLink**'] || record.webIdLink || {};\n if (!linkMap || typeof linkMap !== 'object') {\n return [];\n }\n\n return Object.values(linkMap as Record<string, unknown>)\n .map((value) => {\n if (!value || typeof value !== 'object') {\n return undefined;\n }\n const webId = (value as Record<string, unknown>).webId;\n return typeof webId === 'string' ? webId : undefined;\n })\n .filter((value): value is string => typeof value === 'string');\n}\n\nfunction extractPodOwnerWebIds(pod: Record<string, unknown>): string[] {\n const ownerMap = pod['**owner**'] || pod.owner || {};\n if (!ownerMap || typeof ownerMap !== 'object') {\n return [];\n }\n\n return Object.values(ownerMap as Record<string, unknown>)\n .map((value) => {\n if (!value || typeof value !== 'object') {\n return undefined;\n }\n const webId = (value as Record<string, unknown>).webId;\n return typeof webId === 'string' ? webId : undefined;\n })\n .filter((value): value is string => typeof value === 'string');\n}\n\nfunction normalizeWebId(webId: string | undefined): string | undefined {\n if (!webId) {\n return undefined;\n }\n try {\n return new URL(webId).toString();\n } catch {\n return webId;\n }\n}\n\nfunction dedupeStrings(values: string[]): string[] {\n return [...new Set(values)];\n}\n\nfunction getPodWebIds(pod: PodLookupResult): string[] {\n return dedupeStrings([\n pod.webId,\n ...(pod.webIds ?? []),\n ].filter((value): value is string => typeof value === 'string' && value.length > 0));\n}\n\nfunction webIdsProperty(values: string[]): Pick<PodLookupResult, 'webIds'> {\n const webIds = dedupeStrings(values);\n return webIds.length > 1 ? { webIds } : {};\n}\n\nfunction mergePodLookupResults(values: PodLookupResult[]): PodLookupResult[] {\n const byPodId = new Map<string, PodLookupResult>();\n for (const value of values) {\n const existing = byPodId.get(value.podId);\n if (!existing) {\n byPodId.set(value.podId, value);\n continue;\n }\n\n const webIds = dedupeStrings([\n ...getPodWebIds(existing),\n ...getPodWebIds(value),\n ]);\n byPodId.set(value.podId, {\n ...existing,\n baseUrl: existing.baseUrl || value.baseUrl,\n storageUrl: existing.storageUrl ?? value.storageUrl,\n accountId: existing.accountId || value.accountId,\n webId: webIds[0],\n ...webIdsProperty(webIds),\n nodeId: existing.nodeId ?? value.nodeId,\n edgeNodeId: existing.edgeNodeId ?? value.edgeNodeId,\n });\n }\n return [...byPodId.values()];\n}\n\nfunction parsePayloadRecord(value: unknown): Record<string, unknown> | undefined {\n if (!value) {\n return undefined;\n }\n if (typeof value === 'string') {\n try {\n const parsed = JSON.parse(value) as unknown;\n const unwrapped = unwrapStoredValue(parsed);\n return unwrapped && typeof unwrapped === 'object' ? unwrapped as Record<string, unknown> : undefined;\n } catch {\n return undefined;\n }\n }\n const unwrapped = unwrapStoredValue(value);\n return typeof unwrapped === 'object' ? unwrapped as Record<string, unknown> : undefined;\n}\n\nfunction parseStoredValue(value: unknown): unknown {\n if (typeof value === 'string') {\n try {\n return unwrapStoredValue(JSON.parse(value));\n } catch {\n return undefined;\n }\n }\n return unwrapStoredValue(value);\n}\n\nfunction unwrapStoredValue(value: unknown): unknown {\n if (value && typeof value === 'object' && 'key' in value && 'payload' in value) {\n return (value as Record<string, unknown>).payload;\n }\n return value;\n}\n\nfunction stringValue(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\nfunction appendMapValue(map: Map<string, string[]>, key: string, value: string): void {\n const values = map.get(key) ?? [];\n values.push(value);\n map.set(key, values);\n}\n"]}
|
|
@@ -243,6 +243,7 @@ function ensureSqliteTables(sqlite) {
|
|
|
243
243
|
CREATE TABLE IF NOT EXISTS identity_pod_usage (
|
|
244
244
|
pod_id TEXT PRIMARY KEY,
|
|
245
245
|
account_id TEXT NOT NULL,
|
|
246
|
+
storage_url TEXT,
|
|
246
247
|
storage_bytes INTEGER NOT NULL DEFAULT 0,
|
|
247
248
|
ingress_bytes INTEGER NOT NULL DEFAULT 0,
|
|
248
249
|
egress_bytes INTEGER NOT NULL DEFAULT 0,
|
|
@@ -256,18 +257,6 @@ function ensureSqliteTables(sqlite) {
|
|
|
256
257
|
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
|
|
257
258
|
);
|
|
258
259
|
|
|
259
|
-
CREATE TABLE IF NOT EXISTS identity_webid_profile (
|
|
260
|
-
username TEXT PRIMARY KEY,
|
|
261
|
-
webid_url TEXT NOT NULL,
|
|
262
|
-
storage_url TEXT,
|
|
263
|
-
storage_mode TEXT DEFAULT 'cloud',
|
|
264
|
-
oidc_issuer TEXT,
|
|
265
|
-
profile_data TEXT,
|
|
266
|
-
account_id TEXT,
|
|
267
|
-
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
268
|
-
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
|
|
269
|
-
);
|
|
270
|
-
|
|
271
260
|
CREATE TABLE IF NOT EXISTS identity_edge_node (
|
|
272
261
|
id TEXT PRIMARY KEY,
|
|
273
262
|
display_name TEXT,
|
|
@@ -400,6 +389,7 @@ function migrateSqliteColumns(sqlite) {
|
|
|
400
389
|
addColumn('identity_pod_usage', 'compute_limit_seconds', 'INTEGER');
|
|
401
390
|
addColumn('identity_pod_usage', 'token_limit_monthly', 'INTEGER');
|
|
402
391
|
addColumn('identity_pod_usage', 'period_start', 'INTEGER');
|
|
392
|
+
addColumn('identity_pod_usage', 'storage_url', 'TEXT');
|
|
403
393
|
}
|
|
404
394
|
function sqliteColumnExists(sqlite, table, column) {
|
|
405
395
|
const rows = sqlite.prepare(`PRAGMA table_info(${table})`).all();
|
|
@@ -436,25 +426,7 @@ async function migratePgColumns(pool) {
|
|
|
436
426
|
await addColumn('identity_pod_usage', 'compute_limit_seconds', 'BIGINT');
|
|
437
427
|
await addColumn('identity_pod_usage', 'token_limit_monthly', 'BIGINT');
|
|
438
428
|
await addColumn('identity_pod_usage', 'period_start', 'TIMESTAMP WITH TIME ZONE');
|
|
439
|
-
|
|
440
|
-
try {
|
|
441
|
-
await pool.query(`
|
|
442
|
-
CREATE TABLE IF NOT EXISTS identity_webid_profile (
|
|
443
|
-
username TEXT PRIMARY KEY,
|
|
444
|
-
webid_url TEXT NOT NULL,
|
|
445
|
-
storage_url TEXT,
|
|
446
|
-
storage_mode TEXT DEFAULT 'cloud',
|
|
447
|
-
oidc_issuer TEXT,
|
|
448
|
-
profile_data TEXT,
|
|
449
|
-
account_id TEXT,
|
|
450
|
-
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
|
451
|
-
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
|
|
452
|
-
);
|
|
453
|
-
`);
|
|
454
|
-
}
|
|
455
|
-
catch {
|
|
456
|
-
// Ignore if identity profile storage is unavailable.
|
|
457
|
-
}
|
|
429
|
+
await addColumn('identity_pod_usage', 'storage_url', 'TEXT');
|
|
458
430
|
// Service token table
|
|
459
431
|
try {
|
|
460
432
|
await pool.query(`
|
|
@@ -488,6 +460,7 @@ async function ensurePostgresTables(pool) {
|
|
|
488
460
|
CREATE TABLE IF NOT EXISTS identity_pod_usage (
|
|
489
461
|
pod_id TEXT PRIMARY KEY,
|
|
490
462
|
account_id TEXT NOT NULL,
|
|
463
|
+
storage_url TEXT,
|
|
491
464
|
storage_bytes BIGINT NOT NULL DEFAULT 0,
|
|
492
465
|
ingress_bytes BIGINT NOT NULL DEFAULT 0,
|
|
493
466
|
egress_bytes BIGINT NOT NULL DEFAULT 0,
|
|
@@ -496,18 +469,6 @@ async function ensurePostgresTables(pool) {
|
|
|
496
469
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
497
470
|
);
|
|
498
471
|
|
|
499
|
-
CREATE TABLE IF NOT EXISTS identity_webid_profile (
|
|
500
|
-
username TEXT PRIMARY KEY,
|
|
501
|
-
webid_url TEXT NOT NULL,
|
|
502
|
-
storage_url TEXT,
|
|
503
|
-
storage_mode TEXT DEFAULT 'cloud',
|
|
504
|
-
oidc_issuer TEXT,
|
|
505
|
-
profile_data TEXT,
|
|
506
|
-
account_id TEXT,
|
|
507
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
508
|
-
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
509
|
-
);
|
|
510
|
-
|
|
511
472
|
CREATE TABLE IF NOT EXISTS identity_edge_node (
|
|
512
473
|
id TEXT PRIMARY KEY,
|
|
513
474
|
display_name TEXT,
|