@kubun/client 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.d.ts CHANGED
@@ -34,6 +34,8 @@ export declare class KubunReadClient {
34
34
  constructor(params: ReadClientParams);
35
35
  /** @internal */
36
36
  get client(): Client<Protocol>;
37
+ /** @internal */
38
+ protected get logger(): Logger;
37
39
  listGraphs(signal?: AbortSignal): RequestCall<ListGraphResult>;
38
40
  loadGraph(param: LoadGraphParams, signal?: AbortSignal): RequestCall<LoadGraphResult>;
39
41
  queryGraph<Data extends Record<string, unknown> = Record<string, unknown>>(param: ExecuteGraphParams, signal?: AbortSignal): RequestCall<ExecuteGraphResult<Data>>;
package/lib/client.js CHANGED
@@ -1 +1 @@
1
- import{Client as t}from"@enkaku/client";import{getKubunLogger as e}from"@kubun/logger";import{HLC as r}from"@kubun/mutation";import{GraphQLExecutionError as a,MutationsRunner as n}from"./graphql.js";export class KubunReadClient{#t;constructor(r){let a=r.getRandomID??(()=>globalThis.crypto.randomUUID()),n=r.logger??e("client",{clientID:a()});this.#t=new t({...r,logger:n})}get client(){return this.#t}listGraphs(t){return this.#t.request("graph/list",{signal:t})}loadGraph(t,e){return this.#t.request("graph/load",{param:t,signal:e})}queryGraph(t,e){return this.#t.request("graph/query",{param:t,signal:e})}subscribeToGraph(t,e){return this.#t.createStream("graph/subscribe",{param:t,signal:e})}}export class KubunLightClient extends KubunReadClient{deployGraph(t,e){return this.client.request("graph/deploy",{param:t,signal:e})}mutateGraph(t,e){return this.client.request("graph/mutate",{param:{...t,mutations:null},signal:e})}beginTransaction(t){return this.client.request("graph/beginTransaction",{param:t})}commitTransaction(t){return this.client.request("graph/commitTransaction",{param:t})}rollbackTransaction(t){return this.client.request("graph/rollbackTransaction",{param:t})}}export class KubunClient extends KubunReadClient{#e;#r;#a;#n;constructor(t){super(t),this.#e=t.getRandomID??(()=>globalThis.crypto.randomUUID()),this.#r=t.getRandomValues??(t=>globalThis.crypto.getRandomValues(t)),this.#a=Promise.resolve(t.identity),this.#n=new n}deployGraph(t,e){let r=this.client.request("graph/deploy",{param:t,signal:e});return Object.assign(r.then(t=>(this.#n.setSchema(t.id,t),t)),{abort:r.abort,id:r.id,procedure:r.procedure,type:r.type,signal:r.signal})}loadGraph(t,e){let r=super.loadGraph(t,e);return Object.assign(r.then(e=>(this.#n.setSchema(t.id,e),e)),{abort:r.abort,id:r.id,procedure:r.procedure,type:r.type,signal:r.signal})}async #i(t,e,n){let{id:i,...s}=e;if(this.#n.hasSchema(i)||await this.loadGraph({id:i},n),n.aborted)throw n.reason??new DOMException("The operation was aborted.","AbortError");let o=await this.#a,u={getRandomValues:this.#r,hlc:new r({nodeID:o.id}),identity:o,mutations:{}},{errors:l}=await this.#n.execute({context:u,schemaID:i,source:e.text,variables:e.variables});if(null!=l&&0!==l.length)throw new a(l);return await this.client.request("graph/mutate",{id:t,param:{id:i,mutations:u.mutations,...s},signal:n})}mutateGraph(t,e){let r=this.#e(),a=new AbortController,n=e?AbortSignal.any([a.signal,e]):a.signal;return Object.assign(this.#i(r,t,n),{id:r,abort:()=>a.abort(),signal:n})}beginTransaction(t){return this.client.request("graph/beginTransaction",{param:t})}commitTransaction(t){return this.client.request("graph/commitTransaction",{param:t})}rollbackTransaction(t){return this.client.request("graph/rollbackTransaction",{param:t})}}
1
+ import{Client as e,RequestError as r}from"@enkaku/client";import{getKubunLogger as t}from"@kubun/logger";import{HLC as a}from"@kubun/mutation";import{GraphQLExecutionError as n,MutationsRunner as i}from"./graphql.js";export class KubunReadClient{#e;#r;constructor(r){let a=r.getRandomID??(()=>globalThis.crypto.randomUUID()),n=r.logger??t("client",{clientID:a()});this.#e=new e({...r,logger:n}),this.#r=n}get client(){return this.#e}get logger(){return this.#r}listGraphs(e){return this.#e.request("graph/list",{signal:e})}loadGraph(e,r){return this.#e.request("graph/load",{param:e,signal:r})}queryGraph(e,r){this.#r.debug("queryGraph graph={id} query={text}",{id:e.id,text:e.text.slice(0,200)});let t=performance.now(),a=this.#e.request("graph/query",{param:e,signal:r});return Object.assign(a.then(e=>{let r=Math.round((performance.now()-t)*100)/100;return this.#r.debug("queryGraph completed duration={duration}ms errors={hasErrors}",{duration:String(r),hasErrors:String(null!=e.errors&&e.errors.length>0)}),e},e=>{throw this.#r.error("queryGraph failed: {error}",{error:String(e)}),e}),{abort:a.abort,id:a.id,procedure:a.procedure,type:a.type,signal:a.signal})}subscribeToGraph(e,r){return this.#r.debug("subscribeToGraph graph={id} query={text}",{id:e.id,text:e.text.slice(0,200)}),this.#e.createStream("graph/subscribe",{param:e,signal:r})}}export class KubunLightClient extends KubunReadClient{deployGraph(e,r){return this.client.request("graph/deploy",{param:e,signal:r})}mutateGraph(e,t){this.logger.debug("mutateGraph graph={id} query={text}",{id:e.id,text:e.text.slice(0,200)});let a=performance.now(),n=this.client.request("graph/mutate",{param:{...e,mutations:null},signal:t});return Object.assign(n.then(e=>{let r=Math.round((performance.now()-a)*100)/100;return this.logger.debug("mutateGraph completed duration={duration}ms errors={hasErrors}",{duration:String(r),hasErrors:String(null!=e.errors&&e.errors.length>0)}),e},e=>{throw e instanceof r?this.logger.error("mutateGraph failed: code={code} message={message} data={data}",{code:e.code,message:e.message,data:e.data}):this.logger.error("mutateGraph failed: {error}",{error:String(e)}),e}),{abort:n.abort,id:n.id,procedure:n.procedure,type:n.type,signal:n.signal})}beginTransaction(e){return this.client.request("graph/beginTransaction",{param:e})}commitTransaction(e){return this.client.request("graph/commitTransaction",{param:e})}rollbackTransaction(e){return this.client.request("graph/rollbackTransaction",{param:e})}}export class KubunClient extends KubunReadClient{#t;#a;#n;#i;constructor(e){super(e),this.#t=e.getRandomID??(()=>globalThis.crypto.randomUUID()),this.#a=e.getRandomValues??(e=>globalThis.crypto.getRandomValues(e)),this.#n=Promise.resolve(e.identity),this.#i=new i}deployGraph(e,r){let t=this.client.request("graph/deploy",{param:e,signal:r});return Object.assign(t.then(e=>(this.#i.setSchema(e.id,e),e)),{abort:t.abort,id:t.id,procedure:t.procedure,type:t.type,signal:t.signal})}loadGraph(e,r){let t=super.loadGraph(e,r);return Object.assign(t.then(r=>(this.#i.setSchema(e.id,r),r)),{abort:t.abort,id:t.id,procedure:t.procedure,type:t.type,signal:t.signal})}async #o(e,t,i){this.logger.debug("mutateGraph graph={id} query={text}",{id:t.id,text:t.text.slice(0,200)});let o=performance.now();try{let{id:r,...s}=t;if(this.#i.hasSchema(r)||await this.loadGraph({id:r},i),i.aborted)throw i.reason??new DOMException("The operation was aborted.","AbortError");let l=await this.#n,u={getRandomValues:this.#a,hlc:new a({nodeID:l.id}),identity:l,mutations:{}},{errors:g}=await this.#i.execute({context:u,schemaID:r,source:t.text,variables:t.variables});if(null!=g&&0!==g.length)throw new n(g);let h=await this.client.request("graph/mutate",{id:e,param:{id:r,mutations:u.mutations,...s},signal:i}),d=Math.round((performance.now()-o)*100)/100;return this.logger.debug("mutateGraph completed duration={duration}ms errors={hasErrors}",{duration:String(d),hasErrors:String(null!=h.errors&&h.errors.length>0)}),h}catch(e){throw e instanceof r?this.logger.error("mutateGraph failed: code={code} message={message} data={data}",{code:e.code,message:e.message,data:e.data}):this.logger.error("mutateGraph failed: {error}",{error:String(e)}),e}}mutateGraph(e,r){let t=this.#t(),a=new AbortController,n=r?AbortSignal.any([a.signal,r]):a.signal;return Object.assign(this.#o(t,e,n),{id:t,abort:()=>a.abort(),signal:n})}beginTransaction(e){return this.client.request("graph/beginTransaction",{param:e})}commitTransaction(e){return this.client.request("graph/commitTransaction",{param:e})}rollbackTransaction(e){return this.client.request("graph/rollbackTransaction",{param:e})}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/client",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "license": "see LICENSE.md",
5
5
  "keywords": [],
6
6
  "type": "module",
@@ -15,18 +15,18 @@
15
15
  ],
16
16
  "sideEffects": false,
17
17
  "dependencies": {
18
- "@enkaku/client": "^0.13.1",
19
- "@enkaku/codec": "^0.13.0",
20
- "@enkaku/token": "0.13.0",
18
+ "@enkaku/client": "^0.14.1",
19
+ "@enkaku/codec": "^0.14.0",
20
+ "@enkaku/token": "0.14.0",
21
21
  "graphql": "^16.13.1",
22
22
  "multiformats": "^13.4.2",
23
- "@kubun/id": "^0.6.0",
24
- "@kubun/logger": "^0.6.1",
25
- "@kubun/mutation": "^0.6.0"
23
+ "@kubun/id": "^0.7.0",
24
+ "@kubun/mutation": "^0.7.0",
25
+ "@kubun/logger": "^0.7.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@kubun/protocol": "^0.6.0",
29
- "@kubun/graphql": "^0.6.1"
28
+ "@kubun/protocol": "^0.7.1",
29
+ "@kubun/graphql": "^0.7.1"
30
30
  },
31
31
  "scripts": {
32
32
  "build:clean": "del lib",