@manta-eu/client 0.3.0 → 0.5.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.
@@ -106,6 +106,7 @@ export type GQLAbortUploadResponse = {
106
106
 
107
107
  export type GQLAccessibleDatastore = {
108
108
  __typename?: "AccessibleDatastore";
109
+ datastoresInSubtree?: Maybe<Scalars["Int"]["output"]>;
109
110
  depth: Scalars["Int"]["output"];
110
111
  id: Scalars["String"]["output"];
111
112
  live?: Maybe<Scalars["Boolean"]["output"]>;
@@ -572,6 +573,13 @@ export type GQLCreateMemoryResponse = {
572
573
  memory?: Maybe<GQLMemory>;
573
574
  };
574
575
 
576
+ export type GQLCreateStripeBillingPortalSessionResponse = {
577
+ __typename?: "CreateStripeBillingPortalSessionResponse";
578
+ error?: Maybe<Scalars["String"]["output"]>;
579
+ success: Scalars["Boolean"]["output"];
580
+ url?: Maybe<Scalars["String"]["output"]>;
581
+ };
582
+
575
583
  export type GQLCreateStripeCheckoutSessionResponse = {
576
584
  __typename?: "CreateStripeCheckoutSessionResponse";
577
585
  error?: Maybe<Scalars["String"]["output"]>;
@@ -852,11 +860,13 @@ export type GQLDatastoreSubscription = {
852
860
  inGoodStanding: Scalars["Boolean"]["output"];
853
861
  interval?: Maybe<Scalars["String"]["output"]>;
854
862
  intervalCount?: Maybe<Scalars["Int"]["output"]>;
863
+ productIds: Array<Scalars["String"]["output"]>;
855
864
  status: Scalars["String"]["output"];
856
865
  };
857
866
 
858
867
  export type GQLDatastoreTreeNode = {
859
868
  __typename?: "DatastoreTreeNode";
869
+ accessibleId: Scalars["String"]["output"];
860
870
  datastoreId?: Maybe<Scalars["String"]["output"]>;
861
871
  depth: Scalars["Int"]["output"];
862
872
  id: Scalars["String"]["output"];
@@ -1187,6 +1197,7 @@ export enum GQLInferalIntegrationProvider {
1187
1197
  Linkedin = "LINKEDIN",
1188
1198
  Mailchimp = "MAILCHIMP",
1189
1199
  Meta = "META",
1200
+ Microsoftads = "MICROSOFTADS",
1190
1201
  Pinterest = "PINTEREST",
1191
1202
  Shopify = "SHOPIFY",
1192
1203
  Slack = "SLACK",
@@ -1207,10 +1218,41 @@ export enum GQLInferalLocation {
1207
1218
  }
1208
1219
 
1209
1220
  export type GQLInferalProviderInput =
1210
- | { klaviyo: GQLKlaviyoProviderInput; shopify?: never; triplewhale?: never; woocommerce?: never }
1211
- | { klaviyo?: never; shopify: GQLShopifyProviderInput; triplewhale?: never; woocommerce?: never }
1212
- | { klaviyo?: never; shopify?: never; triplewhale: GQLTriplewhaleProviderInput; woocommerce?: never }
1213
- | { klaviyo?: never; shopify?: never; triplewhale?: never; woocommerce: GQLWoocommerceProviderInput };
1221
+ | {
1222
+ klaviyo: GQLKlaviyoProviderInput;
1223
+ microsoftAds?: never;
1224
+ shopify?: never;
1225
+ triplewhale?: never;
1226
+ woocommerce?: never;
1227
+ }
1228
+ | {
1229
+ klaviyo?: never;
1230
+ microsoftAds: GQLMicrosoftAdsProviderInput;
1231
+ shopify?: never;
1232
+ triplewhale?: never;
1233
+ woocommerce?: never;
1234
+ }
1235
+ | {
1236
+ klaviyo?: never;
1237
+ microsoftAds?: never;
1238
+ shopify: GQLShopifyProviderInput;
1239
+ triplewhale?: never;
1240
+ woocommerce?: never;
1241
+ }
1242
+ | {
1243
+ klaviyo?: never;
1244
+ microsoftAds?: never;
1245
+ shopify?: never;
1246
+ triplewhale: GQLTriplewhaleProviderInput;
1247
+ woocommerce?: never;
1248
+ }
1249
+ | {
1250
+ klaviyo?: never;
1251
+ microsoftAds?: never;
1252
+ shopify?: never;
1253
+ triplewhale?: never;
1254
+ woocommerce: GQLWoocommerceProviderInput;
1255
+ };
1214
1256
 
1215
1257
  export type GQLInferalStreamInput = {
1216
1258
  location: GQLInferalLocation;
@@ -1238,6 +1280,7 @@ export enum GQLIntegration {
1238
1280
  GoogleAnalytics = "GOOGLE_ANALYTICS",
1239
1281
  Linkedin = "LINKEDIN",
1240
1282
  Meta = "META",
1283
+ MicrosoftAds = "MICROSOFT_ADS",
1241
1284
  Shopify = "SHOPIFY",
1242
1285
  Slack = "SLACK",
1243
1286
  Snapchat = "SNAPCHAT",
@@ -1600,6 +1643,26 @@ export enum GQLMetaSetupStateEnum {
1600
1643
  TimedOut = "TIMED_OUT",
1601
1644
  }
1602
1645
 
1646
+ export type GQLMicrosoftAdsAccount = {
1647
+ __typename?: "MicrosoftAdsAccount";
1648
+ connectable: Scalars["Boolean"]["output"];
1649
+ customerId?: Maybe<Scalars["String"]["output"]>;
1650
+ id: Scalars["String"]["output"];
1651
+ name?: Maybe<Scalars["String"]["output"]>;
1652
+ number?: Maybe<Scalars["String"]["output"]>;
1653
+ };
1654
+
1655
+ export type GQLMicrosoftAdsProviderInput = {
1656
+ accountId: Scalars["String"]["input"];
1657
+ };
1658
+
1659
+ export type GQLMicrosoftAdsSetupProgress = {
1660
+ __typename?: "MicrosoftAdsSetupProgress";
1661
+ accounts?: Maybe<Array<GQLMicrosoftAdsAccount>>;
1662
+ lastError?: Maybe<GQLGoogleSetupLastError>;
1663
+ state: Array<GQLGoogleSetupStateEnum>;
1664
+ };
1665
+
1603
1666
  export type GQLMutation = {
1604
1667
  __typename?: "Mutation";
1605
1668
  abortUpload: GQLAbortUploadResponse;
@@ -1618,6 +1681,7 @@ export type GQLMutation = {
1618
1681
  createDataConnection: GQLDataConnectionTestState;
1619
1682
  createInferalIntegration: GQLCreateInferalIntegrationResponse;
1620
1683
  createMemory: GQLCreateMemoryResponse;
1684
+ createStripeBillingPortalSession: GQLCreateStripeBillingPortalSessionResponse;
1621
1685
  createStripeCheckoutSession: GQLCreateStripeCheckoutSessionResponse;
1622
1686
  dashSetupConnect: GQLDashSetupProgress;
1623
1687
  deleteActionPlan: GQLDeleteActionPlanResponse;
@@ -1653,6 +1717,7 @@ export type GQLMutation = {
1653
1717
  manualActionResolve?: Maybe<GQLManualActionResolvePayload>;
1654
1718
  materializeOntologyCoverage: GQLMaterializeOntologyCoverageResponse;
1655
1719
  metaSetupConnect: GQLMetaSetupProgress;
1720
+ microsoftAdsSetupConnect: GQLMicrosoftAdsSetupProgress;
1656
1721
  pauseLDESStream: GQLLdesStreamResponse;
1657
1722
  provisionDatastore: GQLProvisionDatastoreResponse;
1658
1723
  reconfirmMemory: GQLUpdateMemoryResponse;
@@ -1764,6 +1829,11 @@ export type GQLMutationCreateMemoryArgs = {
1764
1829
  input: GQLCreateMemoryInput;
1765
1830
  };
1766
1831
 
1832
+ export type GQLMutationCreateStripeBillingPortalSessionArgs = {
1833
+ datastoreId: Scalars["String"]["input"];
1834
+ returnUrl: Scalars["String"]["input"];
1835
+ };
1836
+
1767
1837
  export type GQLMutationCreateStripeCheckoutSessionArgs = {
1768
1838
  cancelUrl: Scalars["String"]["input"];
1769
1839
  datastoreId: Scalars["String"]["input"];
@@ -1926,6 +1996,11 @@ export type GQLMutationMetaSetupConnectArgs = {
1926
1996
  accountIds: Array<Scalars["String"]["input"]>;
1927
1997
  };
1928
1998
 
1999
+ export type GQLMutationMicrosoftAdsSetupConnectArgs = {
2000
+ accountIds: Array<Scalars["String"]["input"]>;
2001
+ location: GQLInferalLocation;
2002
+ };
2003
+
1929
2004
  export type GQLMutationPauseLdesStreamArgs = {
1930
2005
  url: Scalars["String"]["input"];
1931
2006
  };
@@ -2233,6 +2308,7 @@ export type GQLQuery = {
2233
2308
  memoryReplaySeries: GQLMemoryReplaySeriesResult;
2234
2309
  memorySchemas: GQLMemorySchemasResponse;
2235
2310
  metaSetupProgress: GQLMetaSetupProgress;
2311
+ microsoftAdsSetupProgress: GQLMicrosoftAdsSetupProgress;
2236
2312
  nodeProperties: GQLNodePropertiesResponse;
2237
2313
  nodeRelationships: GQLActionPlanGraphResponse;
2238
2314
  organizationLinking?: Maybe<GQLOrganizationLinking>;
@@ -3469,6 +3545,21 @@ export type GQLCreateMemoryMutation = {
3469
3545
  };
3470
3546
  };
3471
3547
 
3548
+ export type GQLCreateStripeBillingPortalSessionMutationVariables = Exact<{
3549
+ datastoreId: Scalars["String"]["input"];
3550
+ returnUrl: Scalars["String"]["input"];
3551
+ }>;
3552
+
3553
+ export type GQLCreateStripeBillingPortalSessionMutation = {
3554
+ __typename?: "Mutation";
3555
+ createStripeBillingPortalSession: {
3556
+ __typename?: "CreateStripeBillingPortalSessionResponse";
3557
+ success: boolean;
3558
+ url?: string | null;
3559
+ error?: string | null;
3560
+ };
3561
+ };
3562
+
3472
3563
  export type GQLCreateStripeCheckoutSessionMutationVariables = Exact<{
3473
3564
  datastoreId: Scalars["String"]["input"];
3474
3565
  priceId: Scalars["String"]["input"];
@@ -3937,6 +4028,33 @@ export type GQLMetaSetupConnectMutation = {
3937
4028
  };
3938
4029
  };
3939
4030
 
4031
+ export type GQLMicrosoftAdsSetupConnectMutationVariables = Exact<{
4032
+ accountIds: Array<Scalars["String"]["input"]> | Scalars["String"]["input"];
4033
+ location: GQLInferalLocation;
4034
+ }>;
4035
+
4036
+ export type GQLMicrosoftAdsSetupConnectMutation = {
4037
+ __typename?: "Mutation";
4038
+ microsoftAdsSetupConnect: {
4039
+ __typename?: "MicrosoftAdsSetupProgress";
4040
+ state: Array<GQLGoogleSetupStateEnum>;
4041
+ accounts?: Array<{
4042
+ __typename?: "MicrosoftAdsAccount";
4043
+ id: string;
4044
+ name?: string | null;
4045
+ number?: string | null;
4046
+ customerId?: string | null;
4047
+ connectable: boolean;
4048
+ }> | null;
4049
+ lastError?: {
4050
+ __typename?: "GoogleSetupLastError";
4051
+ severity: string;
4052
+ message: string;
4053
+ title?: string | null;
4054
+ } | null;
4055
+ };
4056
+ };
4057
+
3940
4058
  export type GQLPauseLdesStreamMutationVariables = Exact<{
3941
4059
  url: Scalars["String"]["input"];
3942
4060
  }>;
@@ -5112,6 +5230,7 @@ export type GQLDatastoreSubscriptionsQuery = {
5112
5230
  currency?: string | null;
5113
5231
  interval?: string | null;
5114
5232
  intervalCount?: number | null;
5233
+ productIds: Array<string>;
5115
5234
  }>;
5116
5235
  };
5117
5236
 
@@ -5122,6 +5241,7 @@ export type GQLDatastoreTreeQuery = {
5122
5241
  datastoreTree: Array<{
5123
5242
  __typename?: "DatastoreTreeNode";
5124
5243
  id: string;
5244
+ accessibleId: string;
5125
5245
  name: string;
5126
5246
  depth: number;
5127
5247
  organizationId: string;
@@ -5496,6 +5616,30 @@ export type GQLMetaSetupProgressQuery = {
5496
5616
  };
5497
5617
  };
5498
5618
 
5619
+ export type GQLMicrosoftAdsSetupProgressQueryVariables = Exact<{ [key: string]: never }>;
5620
+
5621
+ export type GQLMicrosoftAdsSetupProgressQuery = {
5622
+ __typename?: "Query";
5623
+ microsoftAdsSetupProgress: {
5624
+ __typename?: "MicrosoftAdsSetupProgress";
5625
+ state: Array<GQLGoogleSetupStateEnum>;
5626
+ accounts?: Array<{
5627
+ __typename?: "MicrosoftAdsAccount";
5628
+ id: string;
5629
+ name?: string | null;
5630
+ number?: string | null;
5631
+ customerId?: string | null;
5632
+ connectable: boolean;
5633
+ }> | null;
5634
+ lastError?: {
5635
+ __typename?: "GoogleSetupLastError";
5636
+ severity: string;
5637
+ message: string;
5638
+ title?: string | null;
5639
+ } | null;
5640
+ };
5641
+ };
5642
+
5499
5643
  export type GQLNodePropertiesQueryVariables = Exact<{
5500
5644
  nodeIri: Scalars["String"]["input"];
5501
5645
  planGraphIri?: InputMaybe<Scalars["IRI"]["input"]>;
@@ -6510,6 +6654,47 @@ export const useCreateMemoryMutation = <TError = unknown, TContext = unknown>(
6510
6654
  });
6511
6655
  };
6512
6656
 
6657
+ export const CreateStripeBillingPortalSessionDocument = `
6658
+ mutation CreateStripeBillingPortalSession($datastoreId: String!, $returnUrl: String!) {
6659
+ createStripeBillingPortalSession(
6660
+ datastoreId: $datastoreId
6661
+ returnUrl: $returnUrl
6662
+ ) {
6663
+ success
6664
+ url
6665
+ error
6666
+ }
6667
+ }
6668
+ `;
6669
+
6670
+ export const useCreateStripeBillingPortalSessionMutation = <TError = unknown, TContext = unknown>(
6671
+ client: GraphQLClient,
6672
+ options?: UseMutationOptions<
6673
+ GQLCreateStripeBillingPortalSessionMutation,
6674
+ TError,
6675
+ GQLCreateStripeBillingPortalSessionMutationVariables,
6676
+ TContext
6677
+ >,
6678
+ headers?: RequestInit["headers"],
6679
+ ) => {
6680
+ return useMutation<
6681
+ GQLCreateStripeBillingPortalSessionMutation,
6682
+ TError,
6683
+ GQLCreateStripeBillingPortalSessionMutationVariables,
6684
+ TContext
6685
+ >({
6686
+ mutationKey: ["CreateStripeBillingPortalSession"],
6687
+ mutationFn: (variables?: GQLCreateStripeBillingPortalSessionMutationVariables) =>
6688
+ fetcher<GQLCreateStripeBillingPortalSessionMutation, GQLCreateStripeBillingPortalSessionMutationVariables>(
6689
+ client,
6690
+ CreateStripeBillingPortalSessionDocument,
6691
+ variables,
6692
+ headers,
6693
+ )(),
6694
+ ...options,
6695
+ });
6696
+ };
6697
+
6513
6698
  export const CreateStripeCheckoutSessionDocument = `
6514
6699
  mutation CreateStripeCheckoutSession($datastoreId: String!, $priceId: String!, $successUrl: String!, $cancelUrl: String!) {
6515
6700
  createStripeCheckoutSession(
@@ -7650,6 +7835,54 @@ export const useMetaSetupConnectMutation = <TError = unknown, TContext = unknown
7650
7835
  });
7651
7836
  };
7652
7837
 
7838
+ export const MicrosoftAdsSetupConnectDocument = `
7839
+ mutation MicrosoftAdsSetupConnect($accountIds: [String!]!, $location: InferalLocation!) {
7840
+ microsoftAdsSetupConnect(accountIds: $accountIds, location: $location) {
7841
+ state
7842
+ accounts {
7843
+ id
7844
+ name
7845
+ number
7846
+ customerId
7847
+ connectable
7848
+ }
7849
+ lastError {
7850
+ severity
7851
+ message
7852
+ title
7853
+ }
7854
+ }
7855
+ }
7856
+ `;
7857
+
7858
+ export const useMicrosoftAdsSetupConnectMutation = <TError = unknown, TContext = unknown>(
7859
+ client: GraphQLClient,
7860
+ options?: UseMutationOptions<
7861
+ GQLMicrosoftAdsSetupConnectMutation,
7862
+ TError,
7863
+ GQLMicrosoftAdsSetupConnectMutationVariables,
7864
+ TContext
7865
+ >,
7866
+ headers?: RequestInit["headers"],
7867
+ ) => {
7868
+ return useMutation<
7869
+ GQLMicrosoftAdsSetupConnectMutation,
7870
+ TError,
7871
+ GQLMicrosoftAdsSetupConnectMutationVariables,
7872
+ TContext
7873
+ >({
7874
+ mutationKey: ["MicrosoftAdsSetupConnect"],
7875
+ mutationFn: (variables?: GQLMicrosoftAdsSetupConnectMutationVariables) =>
7876
+ fetcher<GQLMicrosoftAdsSetupConnectMutation, GQLMicrosoftAdsSetupConnectMutationVariables>(
7877
+ client,
7878
+ MicrosoftAdsSetupConnectDocument,
7879
+ variables,
7880
+ headers,
7881
+ )(),
7882
+ ...options,
7883
+ });
7884
+ };
7885
+
7653
7886
  export const PauseLdesStreamDocument = `
7654
7887
  mutation PauseLdesStream($url: String!) {
7655
7888
  pauseLDESStream(url: $url) {
@@ -10076,6 +10309,7 @@ export const DatastoreSubscriptionsDocument = `
10076
10309
  currency
10077
10310
  interval
10078
10311
  intervalCount
10312
+ productIds
10079
10313
  }
10080
10314
  }
10081
10315
  `;
@@ -10134,6 +10368,7 @@ export const DatastoreTreeDocument = `
10134
10368
  query DatastoreTree {
10135
10369
  datastoreTree {
10136
10370
  id
10371
+ accessibleId
10137
10372
  name
10138
10373
  depth
10139
10374
  organizationId
@@ -11116,6 +11351,75 @@ export const useSuspenseMetaSetupProgressQuery = <TData = GQLMetaSetupProgressQu
11116
11351
  useSuspenseMetaSetupProgressQuery.getKey = (variables?: GQLMetaSetupProgressQueryVariables) =>
11117
11352
  variables === undefined ? ["MetaSetupProgressSuspense"] : ["MetaSetupProgressSuspense", variables];
11118
11353
 
11354
+ export const MicrosoftAdsSetupProgressDocument = `
11355
+ query MicrosoftAdsSetupProgress {
11356
+ microsoftAdsSetupProgress {
11357
+ state
11358
+ accounts {
11359
+ id
11360
+ name
11361
+ number
11362
+ customerId
11363
+ connectable
11364
+ }
11365
+ lastError {
11366
+ severity
11367
+ message
11368
+ title
11369
+ }
11370
+ }
11371
+ }
11372
+ `;
11373
+
11374
+ export const useMicrosoftAdsSetupProgressQuery = <TData = GQLMicrosoftAdsSetupProgressQuery, TError = unknown>(
11375
+ client: GraphQLClient,
11376
+ variables?: GQLMicrosoftAdsSetupProgressQueryVariables,
11377
+ options?: Omit<UseQueryOptions<GQLMicrosoftAdsSetupProgressQuery, TError, TData>, "queryKey"> & {
11378
+ queryKey?: UseQueryOptions<GQLMicrosoftAdsSetupProgressQuery, TError, TData>["queryKey"];
11379
+ },
11380
+ headers?: RequestInit["headers"],
11381
+ ) => {
11382
+ return useQuery<GQLMicrosoftAdsSetupProgressQuery, TError, TData>({
11383
+ queryKey: variables === undefined ? ["MicrosoftAdsSetupProgress"] : ["MicrosoftAdsSetupProgress", variables],
11384
+ queryFn: fetcher<GQLMicrosoftAdsSetupProgressQuery, GQLMicrosoftAdsSetupProgressQueryVariables>(
11385
+ client,
11386
+ MicrosoftAdsSetupProgressDocument,
11387
+ variables,
11388
+ headers,
11389
+ ),
11390
+ ...options,
11391
+ });
11392
+ };
11393
+
11394
+ useMicrosoftAdsSetupProgressQuery.getKey = (variables?: GQLMicrosoftAdsSetupProgressQueryVariables) =>
11395
+ variables === undefined ? ["MicrosoftAdsSetupProgress"] : ["MicrosoftAdsSetupProgress", variables];
11396
+
11397
+ export const useSuspenseMicrosoftAdsSetupProgressQuery = <TData = GQLMicrosoftAdsSetupProgressQuery, TError = unknown>(
11398
+ client: GraphQLClient,
11399
+ variables?: GQLMicrosoftAdsSetupProgressQueryVariables,
11400
+ options?: Omit<UseSuspenseQueryOptions<GQLMicrosoftAdsSetupProgressQuery, TError, TData>, "queryKey"> & {
11401
+ queryKey?: UseSuspenseQueryOptions<GQLMicrosoftAdsSetupProgressQuery, TError, TData>["queryKey"];
11402
+ },
11403
+ headers?: RequestInit["headers"],
11404
+ ) => {
11405
+ return useSuspenseQuery<GQLMicrosoftAdsSetupProgressQuery, TError, TData>({
11406
+ queryKey:
11407
+ variables === undefined
11408
+ ? ["MicrosoftAdsSetupProgressSuspense"]
11409
+ : ["MicrosoftAdsSetupProgressSuspense", variables],
11410
+ queryFn: fetcher<GQLMicrosoftAdsSetupProgressQuery, GQLMicrosoftAdsSetupProgressQueryVariables>(
11411
+ client,
11412
+ MicrosoftAdsSetupProgressDocument,
11413
+ variables,
11414
+ headers,
11415
+ ),
11416
+ ...options,
11417
+ });
11418
+ };
11419
+
11420
+ useSuspenseMicrosoftAdsSetupProgressQuery.getKey = (variables?: GQLMicrosoftAdsSetupProgressQueryVariables) =>
11421
+ variables === undefined ? ["MicrosoftAdsSetupProgressSuspense"] : ["MicrosoftAdsSetupProgressSuspense", variables];
11422
+
11119
11423
  export const NodePropertiesDocument = `
11120
11424
  query NodeProperties($nodeIri: String!, $planGraphIri: IRI) {
11121
11425
  nodeProperties(nodeIri: $nodeIri, planGraphIri: $planGraphIri) {
@@ -1,6 +1,9 @@
1
- import jsonld from "jsonld";
2
- import { encodeEntity, type Lens, type Schema } from "ldkit";
3
- import { xsd } from "ldkit/namespaces";
1
+ import { isPresent } from "@manta-eu/lib/present";
2
+ import { owlNothingIri } from "@manta-eu/rdf-lib/namespaces";
3
+ import { encodeEntity, type Identity, type Lens, type Property, type Schema, type SchemaInterface } from "ldkit";
4
+ import { rdf, xsd } from "ldkit/namespaces";
5
+ import { groupBy, uniq, uniqBy } from "ramda";
6
+ import type { GQLExecuteActionUpdateInput } from "../generated/graphql";
4
7
 
5
8
  export type DocumentTerm = { value: string; termType: string };
6
9
 
@@ -10,47 +13,97 @@ export type DocumentQuad = {
10
13
  object: DocumentTerm & { datatype?: { value: string }; language?: string };
11
14
  };
12
15
 
13
- export type InsertEntity<S extends Schema> = Parameters<Lens<S>["insert"]>[number];
16
+ type InsertEntity<S extends Schema> = Parameters<Lens<S>["insert"]>[number];
14
17
 
15
- // jsonld keeps the `_:` prefix in a blank node value
16
- function jsonldTerm(term: DocumentTerm): DocumentTerm {
17
- return { termType: term.termType, value: term.termType === "BlankNode" ? `_:${term.value}` : term.value };
18
+ export type ActionSchema = Schema & { "@type": string };
19
+
20
+ export type Writable<T> = T extends readonly (infer E)[]
21
+ ? Writable<E>[]
22
+ : T extends Record<string, unknown>
23
+ ? { [K in keyof T]?: Writable<T[K]> }
24
+ : T;
25
+
26
+ export type ActionEntity<S extends Schema> = Identity &
27
+ (string extends keyof S ? Record<string, unknown> : Writable<Omit<SchemaInterface<S>, "$id">>);
28
+
29
+ export type ActionInput = GQLExecuteActionUpdateInput;
30
+
31
+ const termKey = (term: DocumentTerm): string => (term.termType === "BlankNode" ? `_:${term.value}` : term.value);
32
+
33
+ const objectKey = ({ object }: DocumentQuad): string =>
34
+ `${termKey(object)} ${object.datatype?.value ?? ""} ${object.language ?? ""}`;
35
+
36
+ const oneOrMany = (values: readonly unknown[]): unknown => (values.length === 1 ? values[0] : values);
37
+
38
+ function literal(object: DocumentQuad["object"]): unknown {
39
+ const datatype = object.datatype?.value ?? xsd.string;
40
+
41
+ if (isPresent(object.language)) return { "@value": object.value, "@language": object.language };
42
+ if (datatype === xsd.string) return object.value;
43
+ return { "@value": object.value, "@type": datatype };
18
44
  }
19
45
 
20
- function jsonldQuad(quad: DocumentQuad) {
21
- const { subject, predicate, object } = quad;
22
-
23
- return {
24
- subject: jsonldTerm(subject),
25
- predicate: { termType: "NamedNode", value: predicate.value },
26
- object:
27
- object.termType === "Literal"
28
- ? {
29
- termType: "Literal",
30
- value: object.value,
31
- language: object.language,
32
- datatype: { value: object.datatype?.value ?? xsd.string },
33
- }
34
- : jsonldTerm(object),
35
- graph: { termType: "DefaultGraph", value: "" },
46
+ export function documentFromQuads(quads: readonly DocumentQuad[], subjectIri: string): Record<string, unknown> {
47
+ const described = quads.filter(({ subject }) => subject.value === subjectIri || subject.termType === "BlankNode");
48
+ const bySubject = groupBy((quad: DocumentQuad) => termKey(quad.subject), described);
49
+ const blankObjects = described.flatMap(({ object }) => (object.termType === "BlankNode" ? [termKey(object)] : []));
50
+ const shared = new Set(blankObjects.filter((key, index) => blankObjects.indexOf(key) !== index));
51
+ const labels = new Map<string, string>();
52
+
53
+ const label = (key: string): string => {
54
+ if (!labels.has(key)) labels.set(key, `_:b${labels.size}`);
55
+ return labels.get(key) ?? key;
36
56
  };
57
+
58
+ const value = (object: DocumentQuad["object"], path: readonly string[]): unknown => {
59
+ const key = termKey(object);
60
+
61
+ if (object.termType === "Literal") return literal(object);
62
+ if (object.termType !== "BlankNode") return { "@id": key };
63
+ if (path.includes(key)) return { "@id": label(key) };
64
+ return node(key, [...path, key]);
65
+ };
66
+
67
+ const node = (key: string, path: readonly string[]): Record<string, unknown> => {
68
+ const own = bySubject[key] ?? [];
69
+ const types = own.filter(({ predicate }) => predicate.value === rdf.type).map(({ object }) => termKey(object));
70
+ const others = own.filter(({ predicate }) => predicate.value !== rdf.type);
71
+ const byPredicate = groupBy((quad: DocumentQuad) => quad.predicate.value, others);
72
+
73
+ return {
74
+ ...(shared.has(key) && { "@id": label(key) }),
75
+ ...(isPresent(types) && { "@type": oneOrMany(uniq(types)) }),
76
+ ...Object.fromEntries(
77
+ Object.entries(byPredicate).map(([predicate, values = []]) => [
78
+ predicate,
79
+ oneOrMany(uniqBy(objectKey, values).map(({ object }) => value(object, path))),
80
+ ]),
81
+ ),
82
+ };
83
+ };
84
+
85
+ return { "@id": subjectIri, ...node(subjectIri, [subjectIri]) };
37
86
  }
38
87
 
39
- export async function documentFromQuads(
40
- quads: readonly DocumentQuad[],
41
- subjectIri: string,
42
- ): Promise<Record<string, unknown>> {
43
- const described = quads.filter(({ subject }) => subject.value === subjectIri || subject.termType === "BlankNode");
44
- const flattened = await jsonld.fromRDF(described.map(jsonldQuad));
88
+ export function entityActionDocument<S extends Schema>(schema: S, entity: ActionEntity<S>): Record<string, unknown> {
89
+ const quads = encodeEntity(schema, entity as unknown as InsertEntity<S>).filter(
90
+ (quad) => quad.object.termType !== "Variable",
91
+ );
45
92
 
46
- return jsonld.frame(flattened, { "@id": subjectIri, "@embed": "@always" });
93
+ return documentFromQuads(quads, entity.$id);
47
94
  }
48
95
 
49
- export function entityActionDocument<S extends Schema>(
96
+ const propertyIri = (definition: Property | string | readonly string[] | undefined): string =>
97
+ typeof definition === "object" && "@id" in definition ? definition["@id"] : String(definition);
98
+
99
+ export function entityActionInput<S extends ActionSchema>(
50
100
  schema: S,
51
- entity: InsertEntity<S>,
52
- ): Promise<Record<string, unknown>> {
53
- const quads = encodeEntity(schema, entity).filter((quad) => quad.object.termType !== "Variable");
101
+ actionShape: string,
102
+ entity: ActionEntity<S>,
103
+ cleared: readonly (Exclude<keyof S, "@type"> & string)[] = [],
104
+ ): ActionInput {
105
+ const document = entityActionDocument(schema, entity);
106
+ const nothing = Object.fromEntries(cleared.map((key) => [propertyIri(schema[key]), { "@id": owlNothingIri }]));
54
107
 
55
- return documentFromQuads(quads, entity.$id);
108
+ return { subjectIri: entity.$id, rdfType: schema["@type"], actionShape, properties: { ...document, ...nothing } };
56
109
  }
@@ -9,6 +9,22 @@ export const thinkChatFacetPath = "think-chat";
9
9
  export const defaultConversationName = "New chat";
10
10
  export const defaultFolderName = "New folder";
11
11
 
12
+ export const conversationModeSchema = z.enum(["datastore", "group"]);
13
+ export type ConversationMode = z.infer<typeof conversationModeSchema>;
14
+ export const chatModeQueryParam = "mode";
15
+
16
+ export function chatModeQuery(mode: ConversationMode | undefined): Record<string, string> {
17
+ return mode === "group" ? { [chatModeQueryParam]: mode } : {};
18
+ }
19
+
20
+ export function withChatModeQueryParam(href: string, mode: ConversationMode | undefined): string {
21
+ if (mode !== "group") return href;
22
+
23
+ const url = new URL(href, "http://placeholder");
24
+ url.searchParams.set(chatModeQueryParam, mode);
25
+ return `${url.pathname}${url.search}${url.hash}`;
26
+ }
27
+
12
28
  export const chatManagerScopeSchema = z.strictObject({
13
29
  version: z.literal(1),
14
30
  realm: z.string().min(1),
@@ -16,6 +32,8 @@ export const chatManagerScopeSchema = z.strictObject({
16
32
  userId: z.string().min(1),
17
33
  // Present for a custom app's token, so each app keeps its own chats; absent keeps the web app's chats where they are.
18
34
  customAppClientId: z.string().min(1).optional(),
35
+ // Present only for a group view's manager, so every other manager keeps its name.
36
+ mode: z.literal("group").optional(),
19
37
  });
20
38
 
21
39
  export type ChatManagerScope = z.infer<typeof chatManagerScopeSchema>;