@kubun/protocol 0.7.1 → 0.8.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.
@@ -0,0 +1,48 @@
1
+ import type { ExecutionResult } from 'graphql';
2
+ import type { DeployGraphParams, DeployGraphResult, ExecuteGraphParams, ExecuteGraphResult, ListGraphResult, LoadGraphParams, LoadGraphResult } from './services/graph.js';
3
+ /**
4
+ * Parameters for a single GraphQL operation (query, mutation, or subscription).
5
+ * Does not include graphID or viewerDID --
6
+ * those are captured by the GraphQLSource at construction time.
7
+ */
8
+ export type GraphQLOperationParams = {
9
+ text: string;
10
+ variables?: Record<string, unknown>;
11
+ };
12
+ /**
13
+ * A bound GraphQL execution target for a specific graph (and optionally a viewer).
14
+ * Obtained from GraphQLSourceProvider.getGraphQLSource().
15
+ */
16
+ export type GraphQLSource = {
17
+ query<Data extends Record<string, unknown> = Record<string, unknown>>(params: GraphQLOperationParams): Promise<ExecutionResult<Data>>;
18
+ mutate<Data extends Record<string, unknown> = Record<string, unknown>>(params: GraphQLOperationParams): Promise<ExecutionResult<Data>>;
19
+ subscribe<Data extends Record<string, unknown> = Record<string, unknown>>(params: GraphQLOperationParams): Promise<AsyncGenerator<ExecutionResult<Data>> | ExecutionResult<Data>>;
20
+ };
21
+ /**
22
+ * Parameters for obtaining a GraphQLSource.
23
+ */
24
+ export type GraphQLSourceParams = {
25
+ graphID: string;
26
+ getViewerDID?: () => string | null;
27
+ };
28
+ /**
29
+ * Provides bound GraphQLSource instances for a given graph.
30
+ * KubunEngine and KubunClient both implement this interface.
31
+ */
32
+ export type GraphQLSourceProvider = {
33
+ getGraphQLSource(params: GraphQLSourceParams): GraphQLSource;
34
+ };
35
+ /**
36
+ * Shared interface for graph management and execution.
37
+ * Implemented by KubunEngine (local) and KubunClient (remote).
38
+ * Consumers that need graph operations (MCP, CLI, etc.) depend on this
39
+ * interface rather than a specific implementation.
40
+ */
41
+ export type GraphsProvider = GraphQLSourceProvider & {
42
+ listGraphs(): Promise<ListGraphResult>;
43
+ loadGraph(params: LoadGraphParams): Promise<LoadGraphResult>;
44
+ deployGraph(params: DeployGraphParams): Promise<DeployGraphResult>;
45
+ queryGraph<Data extends Record<string, unknown> = Record<string, unknown>>(params: ExecuteGraphParams): Promise<ExecuteGraphResult<Data>>;
46
+ mutateGraph<Data extends Record<string, unknown> = Record<string, unknown>>(params: ExecuteGraphParams): Promise<ExecuteGraphResult<Data>>;
47
+ subscribeToGraph<Data extends Record<string, unknown> = Record<string, unknown>>(params: ExecuteGraphParams): Promise<AsyncGenerator<ExecuteGraphResult<Data>> | ExecuteGraphResult<Data>>;
48
+ };
@@ -0,0 +1 @@
1
+ export{};
package/lib/index.d.ts CHANGED
@@ -1,17 +1,19 @@
1
1
  import type { AnyClientMessageOf, AnyServerMessageOf, ClientTransportOf, ServerTransportOf } from '@enkaku/protocol';
2
2
  import type { GraphProtocol } from './services/graph.js';
3
- import type { SyncProtocol } from './services/sync.js';
4
3
  export { type KubunErrorCode, KubunErrorCodes } from './errors.js';
4
+ export type { GraphQLOperationParams, GraphQLSource, GraphQLSourceParams, GraphQLSourceProvider, GraphsProvider, } from './executor.js';
5
+ export * from './models/catalog.js';
5
6
  export * from './models/cluster.js';
6
7
  export * from './models/document.js';
7
8
  export * from './models/graph.js';
8
9
  export * from './models/json-schema.js';
10
+ export * from './models/optimal-clusters.js';
11
+ export * from './models/space.js';
9
12
  export * from './models/value.js';
10
13
  export { KubunAttributeKeys, KubunSpanNames } from './semantic.js';
11
14
  export * from './services/graph.js';
12
- export * from './services/sync.js';
13
15
  export * from './types.js';
14
- export type Protocol = GraphProtocol & SyncProtocol;
16
+ export type Protocol = GraphProtocol;
15
17
  export type ClientMessage = AnyClientMessageOf<Protocol>;
16
18
  export type ServerMessage = AnyServerMessageOf<Protocol>;
17
19
  export type ClientTransport = ClientTransportOf<Protocol>;
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- export{KubunErrorCodes}from"./errors.js";export*from"./models/cluster.js";export*from"./models/document.js";export*from"./models/graph.js";export*from"./models/json-schema.js";export*from"./models/value.js";export{KubunAttributeKeys,KubunSpanNames}from"./semantic.js";export*from"./services/graph.js";export*from"./services/sync.js";export*from"./types.js";
1
+ export{KubunErrorCodes}from"./errors.js";export*from"./models/catalog.js";export*from"./models/cluster.js";export*from"./models/document.js";export*from"./models/graph.js";export*from"./models/json-schema.js";export*from"./models/optimal-clusters.js";export*from"./models/space.js";export*from"./models/value.js";export{KubunAttributeKeys,KubunSpanNames}from"./semantic.js";export*from"./services/graph.js";export*from"./types.js";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Declarative filter criteria for a catalog.
3
+ * All fields are optional — omitted fields mean "no constraint on this dimension."
4
+ * Multiple values in an array are OR'd (any match).
5
+ * Multiple fields are AND'd (all must match).
6
+ */
7
+ export type CatalogFilterCriteria = {
8
+ /** Filter by model IDs — documents must be of one of these models */
9
+ models?: Array<string>;
10
+ /** Filter by owner DIDs — documents must be owned by one of these DIDs */
11
+ owners?: Array<string>;
12
+ /** Filter by circle IDs — documents must grant access to one of these circles */
13
+ circles?: Array<string>;
14
+ };
15
+ export type CatalogRecord = {
16
+ id: string;
17
+ ownerDID: string;
18
+ name: string;
19
+ description: string;
20
+ filterCriteria: CatalogFilterCriteria;
21
+ hlc: string;
22
+ };
@@ -0,0 +1 @@
1
+ export{};
@@ -1116,6 +1116,8 @@ export declare const clusterModel: {
1116
1116
  readonly additionalProperties: false;
1117
1117
  };
1118
1118
  export type ClusterModel = FromSchema<typeof clusterModel>;
1119
+ export type ClustersRecord = Record<string, ClusterModel>;
1120
+ export declare function clusterToRecord(cluster: ClusterModel): ClustersRecord;
1119
1121
  export declare const validateClusterModel: import("@enkaku/schema").Validator<{
1120
1122
  digest: string;
1121
1123
  models: ({
@@ -1399,7 +1401,7 @@ export declare const validateClusterModel: import("@enkaku/schema").Validator<{
1399
1401
  }>;
1400
1402
  export declare function verifyCluster(cluster: ClusterModel): DocumentModelsRecord;
1401
1403
  export type ClusterBuilderParams = {
1402
- externalClusters?: Array<ClusterModel>;
1404
+ externalClusters?: ClustersRecord;
1403
1405
  logger?: Logger;
1404
1406
  };
1405
1407
  export declare class ClusterBuilder {
@@ -1 +1 @@
1
- import{toB64 as e}from"@enkaku/codec";import{assertType as t,createValidator as r}from"@enkaku/schema";import{DocumentModelID as l,digestJSON as o}from"@kubun/id";import{getKubunLogger as i}from"@kubun/logger";import{DocumentModelNormalizer as s,documentModelsCluster as n}from"./document.js";import{binaryStringValue as d}from"./value.js";export const clusterModel={$id:"urn:kubun:protocol:model:cluster",type:"object",properties:{digest:d,models:n,record:{type:"object",patternProperties:{"^k[0-9a-z]{56}$":{type:"integer",minimum:0}},additionalProperties:!1}},required:["digest","models","record"],additionalProperties:!1};export const validateClusterModel=r(clusterModel);export function verifyCluster(r){t(validateClusterModel,r);let i=o(r.models);if(r.digest!==e(i))throw Error("Invalid cluster: digest mismatch");let s=Object.entries(r.record);if(s.length!==r.models.length)throw Error("Invalid cluster: record length mismatch");let n={};for(let[e,t]of s){let o=new l(i,t).toString();if(e!==o)throw Error(`Invalid cluster: record key mismatch, expected ${o}, got ${e}`);let s=r.models[t];if(null==s)throw Error(`Invalid cluster: missing model at index ${t}`);n[e]=s}return n}export class ClusterBuilder{#e=[];#t={};#r=new Map;#l;constructor(e={}){for(let t of(this.#l=e.logger??i("protocol"),e.externalClusters??[])){let e=verifyCluster(t),r={};for(let t of Object.keys(e)){let e=l.fromString(t);r[l.local(e.index).toString()]=t}for(let[t,l]of Object.entries(e))this.#t[t]=l,this.#r.set(t,r)}}get cluster(){return this.#e}get length(){return this.#e.length}build(){let t=this.#e;if(0===t.length)throw Error("Cluster is empty");let r=o(t),i={};for(let e=0;e<t.length;e++)i[new l(r,e).toString()]=e;return{digest:e(r),models:t,record:i}}get(e){let t;if("number"==typeof e)t=e;else if("string"==typeof e&&"#"===e[0]){if(Number.isNaN(t=Number.parseInt(e.slice(1),10)))throw Error(`Invalid DocumentModelID: ${e}`)}else{let r="string"==typeof e?l.fromString(e):e;if(!r.isLocal){let t="string"==typeof e?e:e.toString(),r=this.#t[t];if(null!=r)return r;throw Error(`External model not found: ${t}`)}t=r.index}let r=this.#e[t];if(null==r)throw RangeError(`Invalid cluster index: ${t}`);return r}add(e){let t=(e.interfaces??[]).map(e=>{if(e.startsWith("#")){let t=Number.parseInt(e.slice(1),10);if(Number.isNaN(t))throw Error(`Invalid DocumentModelID: ${e}`);return l.local(t).toString()}return e}),r=new s({inputModel:e,interfaceModels:t.map(e=>{let t=this.get(e),r=this.#r.get(e);return null!=r?this.#o(t,r):t}),logger:this.#l,normalizedInterfaceIDs:t}).toDocumentModel(),o=this.#e.length;return this.#e.push(r),l.local(o)}#o(e,t){let r=e.interfaces.map(e=>t[e]??e),l={...e.fieldsMeta};for(let[e,r]of Object.entries(l))"document"===r.type&&null!=r.model&&null!=t[r.model]&&(l[e]={...r,model:t[r.model]});return{...e,interfaces:r,fieldsMeta:l}}addAll(e){return e.map(e=>this.add(e))}}
1
+ import{fromB64 as e,toB64 as t}from"@enkaku/codec";import{assertType as r,createValidator as l}from"@enkaku/schema";import{ClusterModelID as o,DocumentModelID as i,digestJSON as s}from"@kubun/id";import{getKubunLogger as n}from"@kubun/logger";import{DocumentModelNormalizer as u,documentModelsCluster as d}from"./document.js";import{binaryStringValue as a}from"./value.js";export const clusterModel={$id:"urn:kubun:protocol:model:cluster",type:"object",properties:{digest:a,models:d,record:{type:"object",patternProperties:{"^k[0-9a-z]{56}$":{type:"integer",minimum:0}},additionalProperties:!1}},required:["digest","models","record"],additionalProperties:!1};export function clusterToRecord(t){let r=e(t.digest);return{[o.fromDigest(r).toString()]:t}}export const validateClusterModel=l(clusterModel);export function verifyCluster(e){r(validateClusterModel,e);let l=s(e.models);if(e.digest!==t(l))throw Error("Invalid cluster: digest mismatch");let o=Object.entries(e.record);if(o.length!==e.models.length)throw Error("Invalid cluster: record length mismatch");let n={};for(let[t,r]of o){let o=new i(l,r).toString();if(t!==o)throw Error(`Invalid cluster: record key mismatch, expected ${o}, got ${t}`);let s=e.models[r];if(null==s)throw Error(`Invalid cluster: missing model at index ${r}`);n[t]=s}return n}export class ClusterBuilder{#e=[];#t={};#r=new Map;#l;constructor(e={}){for(let t of(this.#l=e.logger??n("protocol"),Object.values(e.externalClusters??{}))){let e=verifyCluster(t),r={};for(let t of Object.keys(e)){let e=i.fromString(t);r[i.local(e.index).toString()]=t}for(let[t,l]of Object.entries(e))this.#t[t]=l,this.#r.set(t,r)}}get cluster(){return this.#e}get length(){return this.#e.length}build(){let e=this.#e;if(0===e.length)throw Error("Cluster is empty");let r=s(e),l={};for(let t=0;t<e.length;t++)l[new i(r,t).toString()]=t;return{digest:t(r),models:e,record:l}}get(e){let t;if("number"==typeof e)t=e;else if("string"==typeof e&&"#"===e[0]){if(Number.isNaN(t=Number.parseInt(e.slice(1),10)))throw Error(`Invalid DocumentModelID: ${e}`)}else{let r="string"==typeof e?i.fromString(e):e;if(!r.isLocal){let t="string"==typeof e?e:e.toString(),r=this.#t[t];if(null!=r)return r;throw Error(`External model not found: ${t}`)}t=r.index}let r=this.#e[t];if(null==r)throw RangeError(`Invalid cluster index: ${t}`);return r}add(e){let t=(e.interfaces??[]).map(e=>{if(e.startsWith("#")){let t=Number.parseInt(e.slice(1),10);if(Number.isNaN(t))throw Error(`Invalid DocumentModelID: ${e}`);return i.local(t).toString()}return e}),r=new u({inputModel:e,interfaceModels:t.map(e=>{let t=this.get(e),r=this.#r.get(e);return null!=r?this.#o(t,r):t}),logger:this.#l,normalizedInterfaceIDs:t}).toDocumentModel(),l=this.#e.length;return this.#e.push(r),i.local(l)}#o(e,t){let r=e.interfaces.map(e=>t[e]??e),l={...e.fieldsMeta};for(let[e,r]of Object.entries(l))"document"===r.type&&null!=r.model&&null!=t[r.model]&&(l[e]={...r,model:t[r.model]});return{...e,interfaces:r,fieldsMeta:l}}addAll(e){return e.map(e=>this.add(e))}}
@@ -1,8 +1,8 @@
1
- import { type ClusterModel } from './cluster.js';
1
+ import type { ClustersRecord } from './cluster.js';
2
2
  import type { DocumentModel, DocumentModelsRecord } from './document.js';
3
3
  export type FromClustersParams = {
4
4
  aliases?: Record<string, string>;
5
- clusters: Array<ClusterModel>;
5
+ clusters: ClustersRecord;
6
6
  };
7
7
  export type GraphModelParams = {
8
8
  aliases?: Record<string, string>;
@@ -11,6 +11,7 @@ export type GraphModelParams = {
11
11
  export type GraphModelJSON = {
12
12
  aliases: Record<string, string>;
13
13
  record: DocumentModelsRecord;
14
+ extensionSDL?: string;
14
15
  };
15
16
  export declare class GraphModel {
16
17
  #private;
@@ -1 +1 @@
1
- import{verifyCluster as e}from"./cluster.js";export class GraphModel{static fromClusters(s){let r={};for(let a of s.clusters.map(e))Object.assign(r,a);return new GraphModel({aliases:s.aliases,record:r})}#e;#s;constructor(e){null!=e.aliases&&0!==Object.keys(e.aliases).length?this.#e=e.aliases:this.#e=Object.entries(e.record).reduce((e,[s,r])=>(null==e[r.name]?e[r.name]=s:console.warn(`Duplicate model name ${r.name} in GraphModel record, ignoring model ID ${s} in aliases`),e),{}),this.#s=e.record}get aliases(){return this.#e}get record(){return this.#s}getAlias(e){for(let[s,r]of Object.entries(this.#e))if(r===e)return s;return null}getModel(e){let s=this.#e[e]??e;return this.#s[s]??null}toJSON(){return{aliases:this.#e,record:this.#s}}}
1
+ import{verifyCluster as e}from"./cluster.js";export class GraphModel{static fromClusters(s){let r={};for(let a of Object.values(s.clusters).map(e))Object.assign(r,a);return new GraphModel({aliases:s.aliases,record:r})}#e;#s;constructor(e){null!=e.aliases&&0!==Object.keys(e.aliases).length?this.#e=e.aliases:this.#e=Object.entries(e.record).reduce((e,[s,r])=>(null==e[r.name]?e[r.name]=s:console.warn(`Duplicate model name ${r.name} in GraphModel record, ignoring model ID ${s} in aliases`),e),{}),this.#s=e.record}get aliases(){return this.#e}get record(){return this.#s}getAlias(e){for(let[s,r]of Object.entries(this.#e))if(r===e)return s;return null}getModel(e){let s=this.#e[e]??e;return this.#s[s]??null}toJSON(){return{aliases:this.#e,record:this.#s}}}
@@ -0,0 +1,44 @@
1
+ import { type ClustersRecord } from './cluster.js';
2
+ import type { DocumentModelInput } from './document.js';
3
+ /**
4
+ * Extract fieldsMeta document reference dependencies for each model.
5
+ * Returns directed edges only (A→B does not imply B→A).
6
+ * Used for SCC grouping — only circular fieldsMeta forces co-location.
7
+ */
8
+ export declare function extractFieldsMetaDeps(models: Array<DocumentModelInput>): Array<Set<number>>;
9
+ /**
10
+ * Extract interface implementation dependencies for each model.
11
+ * These form a DAG (no circular interfaces). Used for ordering
12
+ * within a cluster so ClusterBuilder can resolve interfaces eagerly.
13
+ */
14
+ export declare function extractInterfaceDeps(models: Array<DocumentModelInput>): Array<Set<number>>;
15
+ /**
16
+ * Find strongly connected components using Tarjan's algorithm.
17
+ * Used on fieldsMeta directed graph — only circular references (A→B→A)
18
+ * force models into the same cluster. One-way refs don't group.
19
+ * Returns arrays of model indices, one per SCC.
20
+ */
21
+ export declare function findStronglyConnectedComponents(deps: Array<Set<number>>): Array<Array<number>>;
22
+ /**
23
+ * Find cluster groups from model definitions.
24
+ * Groups are determined by strongly connected components in the
25
+ * fieldsMeta directed graph. Only circular fieldsMeta references
26
+ * force models into the same cluster.
27
+ */
28
+ export declare function findClusters(models: Array<DocumentModelInput>): Array<Array<number>>;
29
+ export type GraphBuilderParams = {
30
+ externalClusters?: ClustersRecord;
31
+ };
32
+ /**
33
+ * Higher-level builder that produces optimally-split clusters from model
34
+ * definitions. Independent models get their own cluster; cross-referencing
35
+ * models are grouped together. This maximizes content-addressed
36
+ * deduplication while keeping the ClusterBuilder as an internal detail.
37
+ */
38
+ export declare class GraphBuilder {
39
+ #private;
40
+ constructor(params?: GraphBuilderParams);
41
+ add(model: DocumentModelInput): this;
42
+ addAll(models: Array<DocumentModelInput>): this;
43
+ build(): ClustersRecord;
44
+ }
@@ -0,0 +1 @@
1
+ import{DocumentModelID as e,digestJSON as t}from"@kubun/id";import{ClusterBuilder as l,clusterToRecord as n}from"./cluster.js";function r(e){if(!e.startsWith("#"))return null;let t=Number.parseInt(e.slice(1),10);return Number.isNaN(t)?null:t}export function extractFieldsMetaDeps(e){return e.map(e=>{let t=new Set;for(let l of Object.values(e.fieldsMeta??{}))if("document"===l.type&&null!=l.model){let e=r(l.model);null!=e&&t.add(e)}return t})}export function extractInterfaceDeps(e){return e.map(e=>{let t=new Set;for(let l of e.interfaces??[]){let e=r(l);null!=e&&t.add(e)}return t})}export function findStronglyConnectedComponents(e){let t=e.length,l=Array(t).fill(-1),n=Array(t).fill(-1),r=Array(t).fill(!1),o=[],s=[],f=0;for(let i=0;i<t;i++)-1===l[i]&&function i(a){for(let s of(l[a]=f,n[a]=f,f++,o.push(a),r[a]=!0,e[a]))!(s>=t)&&(-1===l[s]?(i(s),n[a]=Math.min(n[a],n[s])):r[s]&&(n[a]=Math.min(n[a],l[s])));if(n[a]===l[a]){let e=[],t=o.pop();for(;null!=t&&(r[t]=!1,e.push(t),t!==a);)t=o.pop();s.push(e)}}(i);return s.map(e=>e.sort((e,t)=>e-t)).sort((e,t)=>e[0]-t[0])}export function findClusters(e){return findStronglyConnectedComponents(extractFieldsMetaDeps(e))}export class GraphBuilder{#e=[];#t;constructor(e={}){this.#t=e.externalClusters??{}}add(e){return this.#e.push(e),this}addAll(e){return this.#e.push(...e),this}build(){let o=Object.keys(this.#t).length>0?this.#t:void 0,s=function(o,s){if(0===o.length)return[];let f=extractFieldsMetaDeps(o),i=extractInterfaceDeps(o),a=findStronglyConnectedComponents(f),u=function(e,t,l){let n=new Map;for(let t=0;t<e.length;t++)for(let l of e[t])n.set(l,t);let r=Array.from({length:e.length},()=>new Set);for(let o=0;o<e.length;o++)for(let s of e[o]){for(let e of t[s]){let t=n.get(e);null!=t&&t!==o&&r[o].add(t)}for(let e of l[s]){let t=n.get(e);null!=t&&t!==o&&r[o].add(t)}}let o=r.map(e=>e.size),s=o.map((e,t)=>0===e?t:-1).filter(e=>e>=0),f=[];for(;s.length>0;){let e=s.shift();if(null==e)break;f.push(e);for(let t=0;t<r.length;t++)r[t].has(e)&&(o[t]--,0===o[t]&&s.push(t))}return f}(a,i,f),d=new Map,p={...s??{}},m=[];for(let s of u){let f=a[s],u=function(e,t,l,n){let o=new Set(t),s=new Map;for(let e of t){let t=new Set;for(let n of l[e])o.has(n)&&t.add(n);s.set(e,t)}let f=new Map;for(let e of t)f.set(e,s.get(e)?.size??0);let i=[],a=t.filter(e=>(f.get(e)??0)===0).map(t=>({originalIndex:t,model:e[t]})).sort((e,t)=>e.model.name.localeCompare(t.model.name));for(;a.length>0;){let t=a.shift();if(null==t)break;for(let[l,n]of(i.push(t),s))if(n.has(t.originalIndex)){let t=(f.get(l)??1)-1;if(f.set(l,t),0===t){let t={originalIndex:l,model:e[l]},n=a.findIndex(e=>e.model.name.localeCompare(t.model.name)>0);-1===n?a.push(t):a.splice(n,0,t)}}}let u=new Map;for(let e=0;e<i.length;e++)u.set(i[e].originalIndex,e);return i.map(({model:e})=>{let t={...e};if(null!=t.interfaces&&(t.interfaces=t.interfaces.map(e=>{let t=r(e);if(null==t)return e;let l=n.get(t);if(null!=l)return l;let o=u.get(t);return null!=o?`#${o}`:e})),null!=t.fieldsMeta){let e={...t.fieldsMeta};for(let[t,l]of Object.entries(e))if("document"===l.type&&null!=l.model){let o=r(l.model);if(null==o)continue;let s=n.get(o);if(null!=s){e[t]={...l,model:s};continue}let f=u.get(o);null!=f&&(e[t]={...l,model:`#${f}`})}t.fieldsMeta=e}return t})}(o,f,i,d),c=new l({externalClusters:Object.keys(p).length>0?p:void 0});c.addAll(u);let h=c.build();m.push(h);let g=t(h.models);for(let t=0;t<f.length;t++){let l=f[t],n=o[l].name,r=h.models.findIndex(e=>e.name===n);if(-1!==r){let t=new e(g,r);d.set(l,t.toString())}}Object.assign(p,n(h))}return m}(this.#e,o),f={};for(let e of s)Object.assign(f,n(e));return f}}
@@ -0,0 +1,21 @@
1
+ export type SpaceRecord = {
2
+ id: string;
3
+ name: string;
4
+ description: string;
5
+ createdBy: string;
6
+ hlc: string;
7
+ };
8
+ export type CircleRecord = {
9
+ id: string;
10
+ spaceID: string;
11
+ name: string;
12
+ description: string;
13
+ catalogIDs: Array<string>;
14
+ hlc: string;
15
+ };
16
+ export type CircleMemberRecord = {
17
+ circleID: string;
18
+ memberDID: string;
19
+ role: 'admin' | 'member';
20
+ hlc: string;
21
+ };
@@ -0,0 +1 @@
1
+ export{};
@@ -1152,6 +1152,13 @@ export declare const deployGraphParams: {
1152
1152
  readonly name: {
1153
1153
  readonly type: "string";
1154
1154
  };
1155
+ readonly plugins: {
1156
+ readonly type: "object";
1157
+ readonly additionalProperties: {
1158
+ readonly type: "object";
1159
+ readonly additionalProperties: true;
1160
+ };
1161
+ };
1155
1162
  readonly search: {
1156
1163
  readonly type: "object";
1157
1164
  readonly additionalProperties: {
@@ -3428,6 +3435,9 @@ export declare const loadGraphResult: {
3428
3435
  readonly type: "string";
3429
3436
  };
3430
3437
  };
3438
+ readonly extensionSDL: {
3439
+ readonly type: "string";
3440
+ };
3431
3441
  };
3432
3442
  readonly required: readonly ["record", "aliases"];
3433
3443
  readonly additionalProperties: false;
@@ -3445,6 +3455,9 @@ export declare const executeGraphParams: {
3445
3455
  readonly variables: {
3446
3456
  readonly type: "object";
3447
3457
  };
3458
+ readonly catalogID: {
3459
+ readonly type: "string";
3460
+ };
3448
3461
  };
3449
3462
  readonly required: readonly ["id", "text"];
3450
3463
  readonly additionalProperties: false;
@@ -3578,6 +3591,9 @@ export declare const mutateGraphParams: {
3578
3591
  readonly variables: {
3579
3592
  readonly type: "object";
3580
3593
  };
3594
+ readonly catalogID: {
3595
+ readonly type: "string";
3596
+ };
3581
3597
  };
3582
3598
  readonly required: readonly ["id", "text", "mutations"];
3583
3599
  readonly additionalProperties: false;
@@ -4755,6 +4771,13 @@ export declare const graphProtocol: {
4755
4771
  readonly name: {
4756
4772
  readonly type: "string";
4757
4773
  };
4774
+ readonly plugins: {
4775
+ readonly type: "object";
4776
+ readonly additionalProperties: {
4777
+ readonly type: "object";
4778
+ readonly additionalProperties: true;
4779
+ };
4780
+ };
4758
4781
  readonly search: {
4759
4782
  readonly type: "object";
4760
4783
  readonly additionalProperties: {
@@ -7033,6 +7056,9 @@ export declare const graphProtocol: {
7033
7056
  readonly type: "string";
7034
7057
  };
7035
7058
  };
7059
+ readonly extensionSDL: {
7060
+ readonly type: "string";
7061
+ };
7036
7062
  };
7037
7063
  readonly required: readonly ["record", "aliases"];
7038
7064
  readonly additionalProperties: false;
@@ -7075,6 +7101,9 @@ export declare const graphProtocol: {
7075
7101
  readonly variables: {
7076
7102
  readonly type: "object";
7077
7103
  };
7104
+ readonly catalogID: {
7105
+ readonly type: "string";
7106
+ };
7078
7107
  };
7079
7108
  readonly required: readonly ["id", "text", "mutations"];
7080
7109
  readonly additionalProperties: false;
@@ -7148,6 +7177,9 @@ export declare const graphProtocol: {
7148
7177
  readonly variables: {
7149
7178
  readonly type: "object";
7150
7179
  };
7180
+ readonly catalogID: {
7181
+ readonly type: "string";
7182
+ };
7151
7183
  };
7152
7184
  readonly required: readonly ["id", "text"];
7153
7185
  readonly additionalProperties: false;
@@ -7221,6 +7253,9 @@ export declare const graphProtocol: {
7221
7253
  readonly variables: {
7222
7254
  readonly type: "object";
7223
7255
  };
7256
+ readonly catalogID: {
7257
+ readonly type: "string";
7258
+ };
7224
7259
  };
7225
7260
  readonly required: readonly ["id", "text"];
7226
7261
  readonly additionalProperties: false;
@@ -1 +1 @@
1
- import{clusterModel as e}from"../models/cluster.js";import{documentModelsRecord as t}from"../models/document.js";import{binaryStringValue as r,signedJWTStringValue as a}from"../models/value.js";export const searchModelConfig={type:"object",properties:{fields:{type:"array",items:{type:"string"}}},additionalProperties:!1};export const searchConfig={type:"object",additionalProperties:searchModelConfig};export const deployGraphParams={type:"object",properties:{clusters:{type:"array",items:e},id:{type:"string"},name:{type:"string"},search:searchConfig},required:["clusters"],additionalProperties:!1};export const deployGraphResult={type:"object",properties:{id:{type:"string"},record:t,aliases:{type:"object",additionalProperties:{type:"string"}},search:searchConfig},required:["id","record","aliases"],additionalProperties:!1};export const listGraphResult={type:"object",properties:{graphs:{type:"array",items:{type:"object",properties:{id:{type:"string"},name:{type:"string"}},required:["id","name"],additionalProperties:!1}}},required:["graphs"],additionalProperties:!1};export const loadGraphParams={type:"object",properties:{id:{type:"string"}},required:["id"],additionalProperties:!1};export const loadGraphResult={type:"object",properties:{record:t,aliases:{type:"object",additionalProperties:{type:"string"}}},required:["record","aliases"],additionalProperties:!1};export const executeGraphParams={type:"object",properties:{id:{type:"string"},text:{type:"string"},variables:{type:"object"}},required:["id","text"],additionalProperties:!1};export const executeGraphError={type:"object",properties:{message:{type:"string"},locations:{type:"array",items:{type:"object",properties:{line:{type:"integer"},column:{type:"integer"}},required:["line","column"],additionalProperties:!1}},path:{type:"array",items:{type:"string"}},extensions:{type:"object"}},required:["message"],additionalProperties:!1};export const executeGraphResult={type:"object",properties:{data:{anyOf:[{type:"object"},{type:"null"}]},errors:{type:"array",items:executeGraphError},extensions:{type:"object"}},additionalProperties:!1};export const mutateGraphParams={type:"object",properties:{...executeGraphParams.properties,mutations:{anyOf:[{type:"object",additionalProperties:a},{type:"null"}]},attachments:{type:"object",additionalProperties:r},transactionID:{type:"string"}},required:[...executeGraphParams.required,"mutations"],additionalProperties:!1};export const beginTransactionParams={type:"object",properties:{id:{type:"string"}},required:["id"],additionalProperties:!1};export const beginTransactionResult={type:"object",properties:{transactionID:{type:"string"}},required:["transactionID"],additionalProperties:!1};export const transactionParams={type:"object",properties:{transactionID:{type:"string"}},required:["transactionID"],additionalProperties:!1};export const transactionResult={type:"object",properties:{success:{type:"boolean"}},required:["success"],additionalProperties:!1};export const graphProtocol={"graph/deploy":{type:"request",param:deployGraphParams,result:deployGraphResult},"graph/list":{type:"request",result:listGraphResult},"graph/load":{type:"request",param:loadGraphParams,result:loadGraphResult},"graph/mutate":{type:"request",param:mutateGraphParams,result:executeGraphResult},"graph/query":{type:"request",param:executeGraphParams,result:executeGraphResult},"graph/subscribe":{type:"stream",param:executeGraphParams,receive:executeGraphResult,result:{anyOf:[executeGraphResult,{type:"null"}]}},"graph/beginTransaction":{type:"request",param:beginTransactionParams,result:beginTransactionResult},"graph/commitTransaction":{type:"request",param:transactionParams,result:transactionResult},"graph/rollbackTransaction":{type:"request",param:transactionParams,result:transactionResult}};
1
+ import{clusterModel as e}from"../models/cluster.js";import{documentModelsRecord as t}from"../models/document.js";import{binaryStringValue as r,signedJWTStringValue as a}from"../models/value.js";export const searchModelConfig={type:"object",properties:{fields:{type:"array",items:{type:"string"}}},additionalProperties:!1};export const searchConfig={type:"object",additionalProperties:searchModelConfig};export const deployGraphParams={type:"object",properties:{clusters:{type:"array",items:e},id:{type:"string"},name:{type:"string"},plugins:{type:"object",additionalProperties:{type:"object",additionalProperties:!0}},search:searchConfig},required:["clusters"],additionalProperties:!1};export const deployGraphResult={type:"object",properties:{id:{type:"string"},record:t,aliases:{type:"object",additionalProperties:{type:"string"}},search:searchConfig},required:["id","record","aliases"],additionalProperties:!1};export const listGraphResult={type:"object",properties:{graphs:{type:"array",items:{type:"object",properties:{id:{type:"string"},name:{type:"string"}},required:["id","name"],additionalProperties:!1}}},required:["graphs"],additionalProperties:!1};export const loadGraphParams={type:"object",properties:{id:{type:"string"}},required:["id"],additionalProperties:!1};export const loadGraphResult={type:"object",properties:{record:t,aliases:{type:"object",additionalProperties:{type:"string"}},extensionSDL:{type:"string"}},required:["record","aliases"],additionalProperties:!1};export const executeGraphParams={type:"object",properties:{id:{type:"string"},text:{type:"string"},variables:{type:"object"},catalogID:{type:"string"}},required:["id","text"],additionalProperties:!1};export const executeGraphError={type:"object",properties:{message:{type:"string"},locations:{type:"array",items:{type:"object",properties:{line:{type:"integer"},column:{type:"integer"}},required:["line","column"],additionalProperties:!1}},path:{type:"array",items:{type:"string"}},extensions:{type:"object"}},required:["message"],additionalProperties:!1};export const executeGraphResult={type:"object",properties:{data:{anyOf:[{type:"object"},{type:"null"}]},errors:{type:"array",items:executeGraphError},extensions:{type:"object"}},additionalProperties:!1};export const mutateGraphParams={type:"object",properties:{...executeGraphParams.properties,mutations:{anyOf:[{type:"object",additionalProperties:a},{type:"null"}]},attachments:{type:"object",additionalProperties:r},transactionID:{type:"string"}},required:[...executeGraphParams.required,"mutations"],additionalProperties:!1};export const beginTransactionParams={type:"object",properties:{id:{type:"string"}},required:["id"],additionalProperties:!1};export const beginTransactionResult={type:"object",properties:{transactionID:{type:"string"}},required:["transactionID"],additionalProperties:!1};export const transactionParams={type:"object",properties:{transactionID:{type:"string"}},required:["transactionID"],additionalProperties:!1};export const transactionResult={type:"object",properties:{success:{type:"boolean"}},required:["success"],additionalProperties:!1};export const graphProtocol={"graph/deploy":{type:"request",param:deployGraphParams,result:deployGraphResult},"graph/list":{type:"request",result:listGraphResult},"graph/load":{type:"request",param:loadGraphParams,result:loadGraphResult},"graph/mutate":{type:"request",param:mutateGraphParams,result:executeGraphResult},"graph/query":{type:"request",param:executeGraphParams,result:executeGraphResult},"graph/subscribe":{type:"stream",param:executeGraphParams,receive:executeGraphResult,result:{anyOf:[executeGraphResult,{type:"null"}]}},"graph/beginTransaction":{type:"request",param:beginTransactionParams,result:beginTransactionResult},"graph/commitTransaction":{type:"request",param:transactionParams,result:transactionResult},"graph/rollbackTransaction":{type:"request",param:transactionParams,result:transactionResult}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/protocol",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "license": "see LICENSE.md",
5
5
  "keywords": [],
6
6
  "type": "module",
@@ -19,10 +19,11 @@
19
19
  "@enkaku/protocol": "^0.14.0",
20
20
  "@enkaku/schema": "^0.14.0",
21
21
  "change-case": "^5.4.4",
22
- "@kubun/id": "^0.7.0",
23
- "@kubun/logger": "^0.7.0"
22
+ "@kubun/logger": "^0.8.0",
23
+ "@kubun/id": "^0.8.0"
24
24
  },
25
25
  "devDependencies": {
26
+ "graphql": "^16.13.2",
26
27
  "json-schema-typed": "^8.0.2"
27
28
  },
28
29
  "scripts": {
@@ -31,7 +32,7 @@
31
32
  "build:types": "tsc --emitDeclarationOnly --skipLibCheck",
32
33
  "build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
33
34
  "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
34
- "test:types": "tsc --noEmit",
35
+ "test:types": "tsc --noEmit -p tsconfig.test.json",
35
36
  "test:unit": "vitest run",
36
37
  "test": "pnpm run test:types && pnpm run test:unit"
37
38
  }
@@ -1,153 +0,0 @@
1
- import type { FromSchema } from '@enkaku/schema';
2
- export declare const syncProtocol: {
3
- readonly 'sync/negotiate': {
4
- readonly type: "request";
5
- readonly param: {
6
- readonly type: "object";
7
- readonly properties: {
8
- readonly scopes: {
9
- readonly type: "array";
10
- readonly items: {
11
- readonly type: "object";
12
- readonly properties: {
13
- readonly modelID: {
14
- readonly type: "string";
15
- };
16
- readonly ownerDID: {
17
- readonly type: "string";
18
- };
19
- };
20
- readonly required: readonly ["modelID", "ownerDID"];
21
- readonly additionalProperties: false;
22
- };
23
- readonly description: "Requested sync scopes as (model, owner) pairs";
24
- };
25
- readonly delegationTokens: {
26
- readonly type: "array";
27
- readonly items: {
28
- readonly type: "string";
29
- };
30
- readonly description: "JWT delegation tokens for authorization";
31
- };
32
- };
33
- readonly required: readonly ["scopes", "delegationTokens"];
34
- readonly additionalProperties: false;
35
- };
36
- readonly result: {
37
- readonly type: "object";
38
- readonly properties: {
39
- readonly acceptedScopes: {
40
- readonly type: "array";
41
- readonly items: {
42
- readonly type: "object";
43
- readonly properties: {
44
- readonly modelID: {
45
- readonly type: "string";
46
- };
47
- readonly ownerDID: {
48
- readonly type: "string";
49
- };
50
- };
51
- readonly required: readonly ["modelID", "ownerDID"];
52
- readonly additionalProperties: false;
53
- };
54
- };
55
- readonly excludedDocumentIDs: {
56
- readonly type: "array";
57
- readonly items: {
58
- readonly type: "string";
59
- };
60
- };
61
- };
62
- readonly required: readonly ["acceptedScopes", "excludedDocumentIDs"];
63
- readonly additionalProperties: false;
64
- };
65
- };
66
- readonly 'sync/merkle-sync': {
67
- readonly type: "stream";
68
- readonly param: {
69
- readonly type: "object";
70
- readonly properties: {
71
- readonly scopes: {
72
- readonly type: "array";
73
- readonly items: {
74
- readonly type: "object";
75
- readonly properties: {
76
- readonly modelID: {
77
- readonly type: "string";
78
- };
79
- readonly ownerDID: {
80
- readonly type: "string";
81
- };
82
- };
83
- readonly required: readonly ["modelID", "ownerDID"];
84
- readonly additionalProperties: false;
85
- };
86
- };
87
- readonly excludedDocumentIDs: {
88
- readonly type: "array";
89
- readonly items: {
90
- readonly type: "string";
91
- };
92
- };
93
- readonly tree: {
94
- readonly type: "object";
95
- readonly description: "Merkle tree bucket hashes from requester";
96
- readonly additionalProperties: {
97
- readonly type: "string";
98
- };
99
- };
100
- };
101
- readonly required: readonly ["scopes", "excludedDocumentIDs", "tree"];
102
- readonly additionalProperties: false;
103
- };
104
- readonly receive: {
105
- readonly type: "object";
106
- readonly properties: {
107
- readonly type: {
108
- readonly type: "string";
109
- readonly enum: readonly ["mutations", "complete"];
110
- };
111
- readonly mutationJWTs: {
112
- readonly type: "array";
113
- readonly items: {
114
- readonly type: "string";
115
- };
116
- readonly description: "Signed mutation JWTs for divergent time buckets";
117
- };
118
- readonly divergentBuckets: {
119
- readonly type: "number";
120
- readonly description: "Number of divergent minute buckets found";
121
- };
122
- readonly totalMutations: {
123
- readonly type: "number";
124
- readonly description: "Total mutations sent";
125
- };
126
- };
127
- readonly required: readonly ["type"];
128
- readonly additionalProperties: false;
129
- };
130
- readonly result: {
131
- readonly type: "object";
132
- readonly properties: {
133
- readonly success: {
134
- readonly type: "boolean";
135
- };
136
- readonly divergentBuckets: {
137
- readonly type: "number";
138
- };
139
- readonly mutationsSent: {
140
- readonly type: "number";
141
- };
142
- };
143
- readonly required: readonly ["success", "divergentBuckets", "mutationsSent"];
144
- readonly additionalProperties: false;
145
- };
146
- };
147
- };
148
- export type SyncProtocol = typeof syncProtocol;
149
- export type SyncNegotiateParams = FromSchema<SyncProtocol['sync/negotiate']['param']>;
150
- export type SyncNegotiateResult = FromSchema<SyncProtocol['sync/negotiate']['result']>;
151
- export type SyncMerkleSyncParams = FromSchema<SyncProtocol['sync/merkle-sync']['param']>;
152
- export type SyncMerkleSyncReceive = FromSchema<SyncProtocol['sync/merkle-sync']['receive']>;
153
- export type SyncMerkleSyncResult = FromSchema<SyncProtocol['sync/merkle-sync']['result']>;
@@ -1 +0,0 @@
1
- export const syncProtocol={"sync/negotiate":{type:"request",param:{type:"object",properties:{scopes:{type:"array",items:{type:"object",properties:{modelID:{type:"string"},ownerDID:{type:"string"}},required:["modelID","ownerDID"],additionalProperties:!1},description:"Requested sync scopes as (model, owner) pairs"},delegationTokens:{type:"array",items:{type:"string"},description:"JWT delegation tokens for authorization"}},required:["scopes","delegationTokens"],additionalProperties:!1},result:{type:"object",properties:{acceptedScopes:{type:"array",items:{type:"object",properties:{modelID:{type:"string"},ownerDID:{type:"string"}},required:["modelID","ownerDID"],additionalProperties:!1}},excludedDocumentIDs:{type:"array",items:{type:"string"}}},required:["acceptedScopes","excludedDocumentIDs"],additionalProperties:!1}},"sync/merkle-sync":{type:"stream",param:{type:"object",properties:{scopes:{type:"array",items:{type:"object",properties:{modelID:{type:"string"},ownerDID:{type:"string"}},required:["modelID","ownerDID"],additionalProperties:!1}},excludedDocumentIDs:{type:"array",items:{type:"string"}},tree:{type:"object",description:"Merkle tree bucket hashes from requester",additionalProperties:{type:"string"}}},required:["scopes","excludedDocumentIDs","tree"],additionalProperties:!1},receive:{type:"object",properties:{type:{type:"string",enum:["mutations","complete"]},mutationJWTs:{type:"array",items:{type:"string"},description:"Signed mutation JWTs for divergent time buckets"},divergentBuckets:{type:"number",description:"Number of divergent minute buckets found"},totalMutations:{type:"number",description:"Total mutations sent"}},required:["type"],additionalProperties:!1},result:{type:"object",properties:{success:{type:"boolean"},divergentBuckets:{type:"number"},mutationsSent:{type:"number"}},required:["success","divergentBuckets","mutationsSent"],additionalProperties:!1}}};