@kubun/standalone 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/graphql.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Context } from '@kubun/graphql';
2
- import { type MutationContext } from '@kubun/mutation';
2
+ import { type HLC, type MutationContext } from '@kubun/mutation';
3
3
  export type ExecutionContext = MutationContext & {
4
4
  did: string;
5
+ hlc: HLC;
5
6
  };
6
7
  export declare function createContext(ctx: ExecutionContext): Context;
package/lib/graphql.js CHANGED
@@ -1 +1 @@
1
- import{createReadContext as e}from"@kubun/graphql";import{applyChangeMutation as t,applySetMutation as o,createChangeMutation as a,createRemoveMutation as r,createSetMutation as n}from"@kubun/mutation";export function createContext(s){return{...e({db:s.db,viewerDID:s.did}),async executeCreateMutation(e,t){let a=globalThis.crypto.getRandomValues(new Uint8Array(12)),r=await n({issuer:s.did,modelID:e,data:t,unique:a});return await o(s,r)},async executeSetMutation(e,t,a){let r=await n({issuer:s.did,modelID:e,data:a,unique:t});return await o(s,r)},async executeUpdateMutation(e){let o=await a({issuer:s.did,loadState:async e=>await s.db.getDocumentState(e),docID:e.id,patch:e.patch.map(e=>{let[t,o]=Object.entries(e)[0];return{...o,op:t}}),from:e.from});return await t(s,o)},async executeRemoveMutation(e){let o=r({docID:e,issuer:s.did});await t(s,o)},async executeSetModelAccessDefaults(){throw Error("Access control mutations are not supported in standalone mode")},async executeRemoveModelAccessDefaults(){throw Error("Access control mutations are not supported in standalone mode")},async executeSetDocumentAccessOverride(){throw Error("Access control mutations are not supported in standalone mode")},async executeRemoveDocumentAccessOverride(){throw Error("Access control mutations are not supported in standalone mode")}}}
1
+ import{createReadContext as e}from"@kubun/graphql";import{applyChangeMutation as t,applySetMutation as o,convertPatchInput as n,createMutationOperations as c}from"@kubun/mutation";export function createContext(a){let r=c({issuer:a.did,hlc:a.hlc,processSetMutation:e=>o(a,e),processChangeMutation:e=>t(a,e)});return{...e({db:a.db,viewerDID:a.did}),executeCreateMutation:async(e,t)=>await r.createDocument(e,t),executeSetMutation:async(e,t,o)=>await r.setDocument(e,t,o),executeUpdateMutation:async e=>await r.updateDocument(e.id,n(e.patch)),async executeRemoveMutation(e){await r.removeDocument(e)},async executeSetModelAccessDefaults(){throw Error("Access control mutations are not supported in standalone mode")},async executeRemoveModelAccessDefaults(){throw Error("Access control mutations are not supported in standalone mode")},async executeSetDocumentAccessOverride(){throw Error("Access control mutations are not supported in standalone mode")},async executeRemoveDocumentAccessOverride(){throw Error("Access control mutations are not supported in standalone mode")}}}
package/lib/standalone.js CHANGED
@@ -1 +1 @@
1
- import{createSchema as e}from"@kubun/graphql";import{getKubunLogger as t}from"@kubun/logger";import{GraphModel as r}from"@kubun/protocol";import{execute as a,parse as s,subscribe as o}from"graphql";import{createContext as i}from"./graphql.js";export class KubunStandalone{#e;#t;#r={};#a;#s={};constructor(e){this.#e=i({db:e.db,did:e.did,validators:{}}),this.#t=e.db,this.#a=e.logger??t("standalone")}async getGraphModel(e){return null==this.#r[e]&&(this.#r[e]=this.#t.getGraph(e).then(t=>{if(null==t)throw this.#a.warn("graph {id} not found",{id:e}),delete this.#r[e],Error(`Graph not found: ${e}`);return this.#a.debug("cached model for graph {id}",{id:e}),{aliases:t.aliases,record:t.record}})),await this.#r[e]}async getGraphQLSchema(t){return null==this.#s[t]&&(this.#s[t]=this.getGraphModel(t).then(r=>{let a=e(r);return this.#a.debug("cached schema for graph {id}",{id:t}),a}).catch(e=>{throw delete this.#s[t],e})),await this.#s[t]}async #o(e){let t=s(e.text);if(null==t.definitions[0])throw Error("Missing GraphQL document definition");return{schema:await this.getGraphQLSchema(e.graphID),document:t,contextValue:this.#e,variableValues:e.variables}}async deploy(e){let t=r.fromClusters({clusters:e.clusters}),a=await this.#t.createGraph({id:e.id,name:e.name,record:t.record}),s=t.toJSON();return this.#r[a]=Promise.resolve(s),delete this.#s[a],this.#a.info("deployed graph {id}",{id:a}),{id:a,...s}}async execute(e){let t=await this.#o(e);return await a(t)}async subscribe(e){let t=await this.#o(e);return await o(t)}}export function standalone(e){return new KubunStandalone(e)}
1
+ import{createSchema as e}from"@kubun/graphql";import{getKubunLogger as t}from"@kubun/logger";import{HLC as r}from"@kubun/mutation";import{GraphModel as a}from"@kubun/protocol";import{execute as s,parse as o,subscribe as i}from"graphql";import{createContext as h}from"./graphql.js";export class KubunStandalone{#e;#t;#r={};#a;#s={};constructor(e){this.#e=h({db:e.db,did:e.did,hlc:new r({nodeID:e.did}),validators:{}}),this.#t=e.db,this.#a=e.logger??t("standalone")}async getGraphModel(e){return null==this.#r[e]&&(this.#r[e]=this.#t.getGraph(e).then(t=>{if(null==t)throw this.#a.warn("graph {id} not found",{id:e}),delete this.#r[e],Error(`Graph not found: ${e}`);return this.#a.debug("cached model for graph {id}",{id:e}),{aliases:t.aliases,record:t.record}})),await this.#r[e]}async getGraphQLSchema(t){return null==this.#s[t]&&(this.#s[t]=this.getGraphModel(t).then(r=>{let a=e(r);return this.#a.debug("cached schema for graph {id}",{id:t}),a}).catch(e=>{throw delete this.#s[t],e})),await this.#s[t]}async #o(e){let t=o(e.text);if(null==t.definitions[0])throw Error("Missing GraphQL document definition");return{schema:await this.getGraphQLSchema(e.graphID),document:t,contextValue:this.#e,variableValues:e.variables}}async deploy(e){let t=a.fromClusters({clusters:e.clusters}),r=await this.#t.createGraph({id:e.id,name:e.name,record:t.record}),s=t.toJSON();return this.#r[r]=Promise.resolve(s),delete this.#s[r],this.#a.info("deployed graph {id}",{id:r}),{id:r,...s}}async execute(e){let t=await this.#o(e);return await s(t)}async subscribe(e){let t=await this.#o(e);return await i(t)}}export function standalone(e){return new KubunStandalone(e)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/standalone",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "license": "see LICENSE.md",
5
5
  "keywords": [],
6
6
  "type": "module",
@@ -16,14 +16,14 @@
16
16
  "sideEffects": false,
17
17
  "dependencies": {
18
18
  "graphql": "^16.12.0",
19
- "@kubun/graphql": "^0.5.0",
20
- "@kubun/logger": "^0.5.0",
21
- "@kubun/protocol": "^0.5.0",
22
- "@kubun/mutation": "^0.5.0"
19
+ "@kubun/logger": "^0.6.0",
20
+ "@kubun/mutation": "^0.6.0",
21
+ "@kubun/protocol": "^0.6.0",
22
+ "@kubun/graphql": "^0.6.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@kubun/db": "^0.5.0",
26
- "@kubun/test-utils": "^0.5.0"
25
+ "@kubun/db": "^0.6.0",
26
+ "@kubun/test-utils": "^0.6.0"
27
27
  },
28
28
  "scripts": {
29
29
  "build:clean": "del lib",