@kubun/client 0.4.1 → 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.
- package/lib/attachments.d.ts +0 -1
- package/lib/attachments.js +1 -15
- package/lib/client.d.ts +4 -5
- package/lib/client.js +1 -156
- package/lib/graphql.d.ts +2 -3
- package/lib/graphql.js +1 -113
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -2
- package/lib/mutations.d.ts +6 -10
- package/lib/mutations.js +1 -25
- package/package.json +9 -9
- package/lib/attachments.d.ts.map +0 -1
- package/lib/client.d.ts.map +0 -1
- package/lib/graphql.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/mutations.d.ts.map +0 -1
package/lib/attachments.d.ts
CHANGED
|
@@ -7,4 +7,3 @@ export type Attachment = {
|
|
|
7
7
|
export declare function createAttachment(bytes: Uint8Array, mimeType?: string): Attachment;
|
|
8
8
|
/** @internal */
|
|
9
9
|
export declare function toAttachmentsRecord(attachments?: Array<Attachment>): Record<string, string>;
|
|
10
|
-
//# sourceMappingURL=attachments.d.ts.map
|
package/lib/attachments.js
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AttachmentID } from '@kubun/id';
|
|
3
|
-
/** @internal */ export function createAttachment(bytes, mimeType) {
|
|
4
|
-
return {
|
|
5
|
-
data: toB64(bytes),
|
|
6
|
-
id: AttachmentID.create(bytes, mimeType).toString()
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
/** @internal */ export function toAttachmentsRecord(attachments = []) {
|
|
10
|
-
const record = {};
|
|
11
|
-
for (const attachment of attachments){
|
|
12
|
-
record[attachment.id] = attachment.data;
|
|
13
|
-
}
|
|
14
|
-
return record;
|
|
15
|
-
}
|
|
1
|
+
import{toB64 as t}from"@enkaku/codec";import{AttachmentID as e}from"@kubun/id";export function createAttachment(r,o){return{data:t(r),id:e.create(r,o).toString()}}export function toAttachmentsRecord(t=[]){let e={};for(let r of t)e[r.id]=r.data;return e}
|
package/lib/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client, type RequestCall, type StreamCall } from '@enkaku/client';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Identity, SigningIdentity } from '@enkaku/token';
|
|
3
3
|
import { type Logger } from '@kubun/logger';
|
|
4
4
|
import type { ClientTransport, DeployGraphParams, DeployGraphResult, ExecuteGraphParams, ExecuteGraphResult, ListGraphResult, LoadGraphParams, LoadGraphResult, Protocol } from '@kubun/protocol';
|
|
5
5
|
export type MutateGraphParams = ExecuteGraphParams & {
|
|
@@ -15,13 +15,13 @@ export type KubunClientType = {
|
|
|
15
15
|
};
|
|
16
16
|
export type ReadClientParams = {
|
|
17
17
|
getRandomID?: () => string;
|
|
18
|
+
identity?: Identity | Promise<Identity>;
|
|
18
19
|
logger?: Logger;
|
|
19
20
|
serverID?: string;
|
|
20
|
-
signer?: TokenSigner | Promise<TokenSigner>;
|
|
21
21
|
transport: ClientTransport;
|
|
22
22
|
};
|
|
23
|
-
export type ClientParams = Omit<ReadClientParams, '
|
|
24
|
-
|
|
23
|
+
export type ClientParams = Omit<ReadClientParams, 'identity'> & {
|
|
24
|
+
identity: SigningIdentity | Promise<SigningIdentity>;
|
|
25
25
|
};
|
|
26
26
|
export declare class KubunReadClient {
|
|
27
27
|
#private;
|
|
@@ -44,4 +44,3 @@ export declare class KubunClient extends KubunReadClient implements KubunClientT
|
|
|
44
44
|
loadGraph(param: LoadGraphParams, signal?: AbortSignal): RequestCall<LoadGraphResult>;
|
|
45
45
|
mutateGraph<Data extends Record<string, unknown> = Record<string, unknown>>(param: MutateGraphParams, signal?: AbortSignal): RequestCall<ExecuteGraphResult<Data>>;
|
|
46
46
|
}
|
|
47
|
-
//# sourceMappingURL=client.d.ts.map
|
package/lib/client.js
CHANGED
|
@@ -1,156 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fromB64 } from '@enkaku/codec';
|
|
3
|
-
import { getKubunLogger } from '@kubun/logger';
|
|
4
|
-
import { GraphQLExecutionError, MutationsRunner } from './graphql.js';
|
|
5
|
-
export class KubunReadClient {
|
|
6
|
-
#client;
|
|
7
|
-
constructor(params){
|
|
8
|
-
const logger = params.logger ?? getKubunLogger('client', {
|
|
9
|
-
clientID: params.getRandomID?.() ?? crypto.randomUUID()
|
|
10
|
-
});
|
|
11
|
-
this.#client = new Client({
|
|
12
|
-
...params,
|
|
13
|
-
logger
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
/** @internal */ get client() {
|
|
17
|
-
return this.#client;
|
|
18
|
-
}
|
|
19
|
-
listGraphs(signal) {
|
|
20
|
-
return this.#client.request('graph/list', {
|
|
21
|
-
signal
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
loadGraph(param, signal) {
|
|
25
|
-
return this.#client.request('graph/load', {
|
|
26
|
-
param,
|
|
27
|
-
signal
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
queryGraph(param, signal) {
|
|
31
|
-
return this.#client.request('graph/query', {
|
|
32
|
-
param,
|
|
33
|
-
signal
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
subscribeToGraph(param, signal) {
|
|
37
|
-
return this.#client.createStream('graph/subscribe', {
|
|
38
|
-
param,
|
|
39
|
-
signal
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export class KubunLightClient extends KubunReadClient {
|
|
44
|
-
deployGraph(param, signal) {
|
|
45
|
-
return this.client.request('graph/deploy', {
|
|
46
|
-
param,
|
|
47
|
-
signal
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
mutateGraph(param, signal) {
|
|
51
|
-
return this.client.request('graph/mutate', {
|
|
52
|
-
param: {
|
|
53
|
-
...param,
|
|
54
|
-
mutations: {}
|
|
55
|
-
},
|
|
56
|
-
signal
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export class KubunClient extends KubunReadClient {
|
|
61
|
-
#mutationsRunner;
|
|
62
|
-
#signerPromise;
|
|
63
|
-
constructor(params){
|
|
64
|
-
super(params);
|
|
65
|
-
this.#mutationsRunner = new MutationsRunner();
|
|
66
|
-
this.#signerPromise = Promise.resolve(params.signer);
|
|
67
|
-
}
|
|
68
|
-
deployGraph(param, signal) {
|
|
69
|
-
const request = this.client.request('graph/deploy', {
|
|
70
|
-
param,
|
|
71
|
-
signal
|
|
72
|
-
});
|
|
73
|
-
const call = request.then((result)=>{
|
|
74
|
-
this.#mutationsRunner.setSchema(result.id, result);
|
|
75
|
-
return result;
|
|
76
|
-
});
|
|
77
|
-
return Object.assign(call, {
|
|
78
|
-
abort: request.abort,
|
|
79
|
-
id: request.id,
|
|
80
|
-
procedure: request.procedure,
|
|
81
|
-
type: request.type,
|
|
82
|
-
signal: request.signal
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
loadGraph(param, signal) {
|
|
86
|
-
const request = super.loadGraph(param, signal);
|
|
87
|
-
const call = request.then((result)=>{
|
|
88
|
-
this.#mutationsRunner.setSchema(param.id, result);
|
|
89
|
-
return result;
|
|
90
|
-
});
|
|
91
|
-
return Object.assign(call, {
|
|
92
|
-
abort: request.abort,
|
|
93
|
-
id: request.id,
|
|
94
|
-
procedure: request.procedure,
|
|
95
|
-
type: request.type,
|
|
96
|
-
signal: request.signal
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
async #mutateGraph(requestID, param, signal) {
|
|
100
|
-
const { id, ...rest } = param;
|
|
101
|
-
if (!this.#mutationsRunner.hasSchema(id)) {
|
|
102
|
-
await this.loadGraph({
|
|
103
|
-
id
|
|
104
|
-
}, signal);
|
|
105
|
-
}
|
|
106
|
-
signal.throwIfAborted();
|
|
107
|
-
const context = {
|
|
108
|
-
// TODO: local cache for documents state, ideally updated after successful mutations
|
|
109
|
-
loadState: async (docID)=>{
|
|
110
|
-
const res = await this.client.request('document/sync', {
|
|
111
|
-
param: {
|
|
112
|
-
documents: {
|
|
113
|
-
[docID]: null
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
const state = res.states[docID];
|
|
118
|
-
return state ? fromB64(state) : null;
|
|
119
|
-
},
|
|
120
|
-
mutations: {},
|
|
121
|
-
signer: await this.#signerPromise
|
|
122
|
-
};
|
|
123
|
-
const { errors } = await this.#mutationsRunner.execute({
|
|
124
|
-
context,
|
|
125
|
-
schemaID: id,
|
|
126
|
-
source: param.text,
|
|
127
|
-
variables: param.variables
|
|
128
|
-
});
|
|
129
|
-
if (errors != null && errors.length !== 0) {
|
|
130
|
-
throw new GraphQLExecutionError(errors);
|
|
131
|
-
}
|
|
132
|
-
return await this.client.request('graph/mutate', {
|
|
133
|
-
id: requestID,
|
|
134
|
-
param: {
|
|
135
|
-
id,
|
|
136
|
-
mutations: context.mutations,
|
|
137
|
-
...rest
|
|
138
|
-
},
|
|
139
|
-
signal
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
mutateGraph(param, signal) {
|
|
143
|
-
const id = globalThis.crypto.randomUUID();
|
|
144
|
-
const controller = new AbortController();
|
|
145
|
-
const anySignal = signal ? AbortSignal.any([
|
|
146
|
-
controller.signal,
|
|
147
|
-
signal
|
|
148
|
-
]) : controller.signal;
|
|
149
|
-
const promise = this.#mutateGraph(id, param, anySignal);
|
|
150
|
-
return Object.assign(promise, {
|
|
151
|
-
id,
|
|
152
|
-
abort: ()=>controller.abort(),
|
|
153
|
-
signal: anySignal
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
1
|
+
import{Client as t}from"@enkaku/client";import{fromB64 as e}from"@enkaku/codec";import{getKubunLogger as r}from"@kubun/logger";import{GraphQLExecutionError as a,MutationsRunner as n}from"./graphql.js";export class KubunReadClient{#t;constructor(e){let a=e.logger??r("client",{clientID:e.getRandomID?.()??crypto.randomUUID()});this.#t=new t({...e,logger:a})}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:{}},signal:e})}}export class KubunClient extends KubunReadClient{#e;#r;constructor(t){super(t),this.#e=Promise.resolve(t.identity),this.#r=new n}deployGraph(t,e){let r=this.client.request("graph/deploy",{param:t,signal:e});return Object.assign(r.then(t=>(this.#r.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.#r.setSchema(t.id,e),e)),{abort:r.abort,id:r.id,procedure:r.procedure,type:r.type,signal:r.signal})}async #a(t,r,n){let{id:i,...s}=r;this.#r.hasSchema(i)||await this.loadGraph({id:i},n),n.throwIfAborted();let u={identity:await this.#e,loadState:async t=>{let r=(await this.client.request("document/sync",{param:{documents:{[t]:null}}})).states[t];return r?e(r):null},mutations:{}},{errors:o}=await this.#r.execute({context:u,schemaID:i,source:r.text,variables:r.variables});if(null!=o&&0!==o.length)throw new a(o);return await this.client.request("graph/mutate",{id:t,param:{id:i,mutations:u.mutations,...s},signal:n})}mutateGraph(t,e){let r=globalThis.crypto.randomUUID(),a=new AbortController,n=e?AbortSignal.any([a.signal,e]):a.signal;return Object.assign(this.#a(r,t,n),{id:r,abort:()=>a.abort(),signal:n})}}
|
package/lib/graphql.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type SigningIdentity } from '@enkaku/token';
|
|
2
2
|
import type { Context } from '@kubun/graphql';
|
|
3
3
|
import type { GraphModelJSON } from '@kubun/protocol';
|
|
4
4
|
import type { ExecutionResult, GraphQLError, GraphQLSchema } from 'graphql';
|
|
@@ -8,9 +8,9 @@ export declare class GraphQLExecutionError extends Error {
|
|
|
8
8
|
get errors(): ReadonlyArray<GraphQLError>;
|
|
9
9
|
}
|
|
10
10
|
export type ExecutionContext = {
|
|
11
|
+
identity: SigningIdentity;
|
|
11
12
|
loadState: (id: string) => Promise<Uint8Array | null>;
|
|
12
13
|
mutations: Record<string, string>;
|
|
13
|
-
signer: TokenSigner;
|
|
14
14
|
};
|
|
15
15
|
export declare function createContext(client: ExecutionContext): Context;
|
|
16
16
|
type SchemasRecord = Record<string, GraphQLSchema | Promise<GraphQLSchema>>;
|
|
@@ -31,4 +31,3 @@ export declare class MutationsRunner {
|
|
|
31
31
|
execute(params: ExecuteMutationParams): Promise<ExecutionResult>;
|
|
32
32
|
}
|
|
33
33
|
export {};
|
|
34
|
-
//# sourceMappingURL=graphql.d.ts.map
|
package/lib/graphql.js
CHANGED
|
@@ -1,113 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createSchema } from '@kubun/graphql';
|
|
3
|
-
import { graphql } from 'graphql';
|
|
4
|
-
import { signChangeMutation, signRemoveMutation, signSetMutation } from './mutations.js';
|
|
5
|
-
export class GraphQLExecutionError extends Error {
|
|
6
|
-
#errors;
|
|
7
|
-
constructor(errors, message = 'GraphQL execution failed'){
|
|
8
|
-
super(message);
|
|
9
|
-
this.name = GraphQLExecutionError.name;
|
|
10
|
-
this.#errors = errors;
|
|
11
|
-
}
|
|
12
|
-
get errors() {
|
|
13
|
-
return this.#errors;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const noDocument = null;
|
|
17
|
-
export function createContext(client) {
|
|
18
|
-
const context = {
|
|
19
|
-
async executeCreateMutation (modelID, data, info) {
|
|
20
|
-
// Create the mutation token
|
|
21
|
-
const unique = globalThis.crypto.getRandomValues(new Uint8Array(12));
|
|
22
|
-
const mutation = await signSetMutation({
|
|
23
|
-
signer: client.signer,
|
|
24
|
-
modelID,
|
|
25
|
-
data,
|
|
26
|
-
unique
|
|
27
|
-
});
|
|
28
|
-
// Add the signed mutation to context so it can be retrieved by the client
|
|
29
|
-
client.mutations[info.path.key] = stringifyToken(mutation);
|
|
30
|
-
// Need to return the mutation result for execution to work
|
|
31
|
-
return noDocument;
|
|
32
|
-
},
|
|
33
|
-
async executeSetMutation (modelID, unique, data, info) {
|
|
34
|
-
// Create the mutation
|
|
35
|
-
const mutation = await signSetMutation({
|
|
36
|
-
signer: client.signer,
|
|
37
|
-
modelID,
|
|
38
|
-
data,
|
|
39
|
-
unique
|
|
40
|
-
});
|
|
41
|
-
// Add the signed mutation to context so it can be retrieved by the client
|
|
42
|
-
client.mutations[info.path.key] = stringifyToken(mutation);
|
|
43
|
-
// Need to return the mutation result for execution to work
|
|
44
|
-
return noDocument;
|
|
45
|
-
},
|
|
46
|
-
async executeUpdateMutation (input, info) {
|
|
47
|
-
const mutation = await signChangeMutation({
|
|
48
|
-
loadState: client.loadState,
|
|
49
|
-
signer: client.signer,
|
|
50
|
-
docID: input.id,
|
|
51
|
-
patch: input.patch.map((patch)=>{
|
|
52
|
-
// convert GraphQL patch input types to PatchOperation
|
|
53
|
-
const entries = Object.entries(patch);
|
|
54
|
-
const [op, rest] = entries[0];
|
|
55
|
-
return {
|
|
56
|
-
...rest,
|
|
57
|
-
op
|
|
58
|
-
};
|
|
59
|
-
}),
|
|
60
|
-
from: input.from
|
|
61
|
-
});
|
|
62
|
-
// Add the signed mutation to context so it can be retrieved by the client
|
|
63
|
-
client.mutations[info.path.key] = stringifyToken(mutation);
|
|
64
|
-
// Need to return the mutation result for execution to work
|
|
65
|
-
return noDocument;
|
|
66
|
-
},
|
|
67
|
-
async executeRemoveMutation (id, info) {
|
|
68
|
-
const mutation = await signRemoveMutation({
|
|
69
|
-
docID: id,
|
|
70
|
-
signer: client.signer
|
|
71
|
-
});
|
|
72
|
-
// Add the signed mutation to context so it can be retrieved by the client
|
|
73
|
-
client.mutations[info.path.key] = stringifyToken(mutation);
|
|
74
|
-
},
|
|
75
|
-
async executeSetModelAccessDefaults () {
|
|
76
|
-
// No-op: Access control mutations execute on server only
|
|
77
|
-
},
|
|
78
|
-
async executeRemoveModelAccessDefaults () {
|
|
79
|
-
// No-op: Access control mutations execute on server only
|
|
80
|
-
},
|
|
81
|
-
async executeSetDocumentAccessOverride () {
|
|
82
|
-
// No-op: Access control mutations execute on server only
|
|
83
|
-
},
|
|
84
|
-
async executeRemoveDocumentAccessOverride () {
|
|
85
|
-
// No-op: Access control mutations execute on server only
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
return context;
|
|
89
|
-
}
|
|
90
|
-
export class MutationsRunner {
|
|
91
|
-
#schemas;
|
|
92
|
-
constructor(params = {}){
|
|
93
|
-
this.#schemas = params.schemas ?? {};
|
|
94
|
-
}
|
|
95
|
-
hasSchema(id) {
|
|
96
|
-
return this.#schemas[id] != null;
|
|
97
|
-
}
|
|
98
|
-
setSchema(id, modelOrPromise) {
|
|
99
|
-
this.#schemas[id] = Promise.resolve(modelOrPromise).then(createSchema);
|
|
100
|
-
}
|
|
101
|
-
async execute(params) {
|
|
102
|
-
const schemaPromise = this.#schemas[params.schemaID];
|
|
103
|
-
if (schemaPromise == null) {
|
|
104
|
-
throw new Error(`Schema ${params.schemaID} not found`);
|
|
105
|
-
}
|
|
106
|
-
return await graphql({
|
|
107
|
-
contextValue: createContext(params.context),
|
|
108
|
-
schema: await schemaPromise,
|
|
109
|
-
source: params.source,
|
|
110
|
-
variableValues: params.variables
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
1
|
+
import{stringifyToken as e}from"@enkaku/token";import{createSchema as t}from"@kubun/graphql";import{graphql as a}from"graphql";import{signChangeMutation as r,signRemoveMutation as s,signSetMutation as n}from"./mutations.js";export class GraphQLExecutionError extends Error{#e;constructor(e,t="GraphQL execution failed"){super(t),this.name=GraphQLExecutionError.name,this.#e=e}get errors(){return this.#e}}export function createContext(t){return{async executeCreateMutation(a,r,s){let o=globalThis.crypto.getRandomValues(new Uint8Array(12)),c=await n({identity:t.identity,modelID:a,data:r,unique:o});return t.mutations[s.path.key]=e(c),null},async executeSetMutation(a,r,s,o){let c=await n({identity:t.identity,modelID:a,data:s,unique:r});return t.mutations[o.path.key]=e(c),null},async executeUpdateMutation(a,s){let n=await r({loadState:t.loadState,identity:t.identity,docID:a.id,patch:a.patch.map(e=>{let[t,a]=Object.entries(e)[0];return{...a,op:t}}),from:a.from});return t.mutations[s.path.key]=e(n),null},async executeRemoveMutation(a,r){let n=await s({docID:a,identity:t.identity});t.mutations[r.path.key]=e(n)},executeSetModelAccessDefaults:async()=>null,async executeRemoveModelAccessDefaults(){},executeSetDocumentAccessOverride:async()=>null,async executeRemoveDocumentAccessOverride(){}}}export class MutationsRunner{#t;constructor(e={}){this.#t=e.schemas??{}}hasSchema(e){return null!=this.#t[e]}setSchema(e,a){this.#t[e]=Promise.resolve(a).then(t)}async execute(e){let t=this.#t[e.schemaID];if(null==t)throw Error(`Schema ${e.schemaID} not found`);return await a({contextValue:createContext(e.context),schema:await t,source:e.source,variableValues:e.variables})}}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export { type Attachment, createAttachment, toAttachmentsRecord } from './attachments.js';
|
|
2
2
|
export { type ClientParams, KubunClient, type KubunClientType, KubunLightClient, KubunReadClient, type MutateGraphParams, type ReadClientParams, } from './client.js';
|
|
3
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { KubunClient, KubunLightClient, KubunReadClient } from './client.js';
|
|
1
|
+
export{createAttachment,toAttachmentsRecord}from"./attachments.js";export{KubunClient,KubunLightClient,KubunReadClient}from"./client.js";
|
package/lib/mutations.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import type { SignedToken,
|
|
1
|
+
import type { SignedToken, SigningIdentity } from '@enkaku/token';
|
|
2
2
|
import type { CreateChangeMutationParams, CreateRemoveMutationParams, CreateSetMutationParams } from '@kubun/mutation';
|
|
3
3
|
import type { ChangeDocumentMutation, DocumentData, SetDocumentMutation } from '@kubun/protocol';
|
|
4
|
-
export type
|
|
5
|
-
|
|
4
|
+
export type IdentityParams = {
|
|
5
|
+
identity: SigningIdentity;
|
|
6
6
|
};
|
|
7
|
+
export type SetMutationParams<Data extends DocumentData = DocumentData> = Omit<CreateSetMutationParams<Data>, 'issuer'> & IdentityParams;
|
|
7
8
|
export declare function signSetMutation<Data extends DocumentData = DocumentData>(params: SetMutationParams<Data>): Promise<SignedToken<SetDocumentMutation>>;
|
|
8
|
-
export type ChangeMutationParams<Data extends DocumentData = DocumentData> = Omit<CreateChangeMutationParams<Data>, 'issuer'> &
|
|
9
|
-
signer: TokenSigner;
|
|
10
|
-
};
|
|
9
|
+
export type ChangeMutationParams<Data extends DocumentData = DocumentData> = Omit<CreateChangeMutationParams<Data>, 'issuer'> & IdentityParams;
|
|
11
10
|
export declare function signChangeMutation<Data extends DocumentData = DocumentData>(params: ChangeMutationParams<Data>): Promise<SignedToken<ChangeDocumentMutation>>;
|
|
12
|
-
export type RemoveMutationParams = Omit<CreateRemoveMutationParams, 'issuer'> &
|
|
13
|
-
signer: TokenSigner;
|
|
14
|
-
};
|
|
11
|
+
export type RemoveMutationParams = Omit<CreateRemoveMutationParams, 'issuer'> & IdentityParams;
|
|
15
12
|
export declare function signRemoveMutation(params: RemoveMutationParams): Promise<SignedToken<ChangeDocumentMutation>>;
|
|
16
|
-
//# sourceMappingURL=mutations.d.ts.map
|
package/lib/mutations.js
CHANGED
|
@@ -1,25 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export async function signSetMutation(params) {
|
|
3
|
-
const { signer, ...rest } = params;
|
|
4
|
-
const mutation = await createSetMutation({
|
|
5
|
-
...rest,
|
|
6
|
-
issuer: signer.id
|
|
7
|
-
});
|
|
8
|
-
return await signer.createToken(mutation);
|
|
9
|
-
}
|
|
10
|
-
export async function signChangeMutation(params) {
|
|
11
|
-
const { signer, ...rest } = params;
|
|
12
|
-
const mutation = await createChangeMutation({
|
|
13
|
-
...rest,
|
|
14
|
-
issuer: signer.id
|
|
15
|
-
});
|
|
16
|
-
return await signer.createToken(mutation);
|
|
17
|
-
}
|
|
18
|
-
export async function signRemoveMutation(params) {
|
|
19
|
-
const { signer, ...rest } = params;
|
|
20
|
-
const mutation = createRemoveMutation({
|
|
21
|
-
...rest,
|
|
22
|
-
issuer: signer.id
|
|
23
|
-
});
|
|
24
|
-
return await signer.createToken(mutation);
|
|
25
|
-
}
|
|
1
|
+
import{createChangeMutation as n,createRemoveMutation as t,createSetMutation as i}from"@kubun/mutation";export async function signSetMutation(n){let{identity:t,...e}=n,a=await i({...e,issuer:t.id});return await t.signToken(a)}export async function signChangeMutation(t){let{identity:i,...e}=t,a=await n({...e,issuer:i.id});return await i.signToken(a)}export async function signRemoveMutation(n){let{identity:i,...e}=n,a=t({...e,issuer:i.id});return await i.signToken(a)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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.
|
|
19
|
-
"@enkaku/codec": "^0.
|
|
20
|
-
"@enkaku/token": "0.
|
|
18
|
+
"@enkaku/client": "^0.13.0",
|
|
19
|
+
"@enkaku/codec": "^0.13.0",
|
|
20
|
+
"@enkaku/token": "0.13.0",
|
|
21
21
|
"graphql": "^16.12.0",
|
|
22
22
|
"multiformats": "^13.4.2",
|
|
23
|
-
"@kubun/id": "^0.
|
|
24
|
-
"@kubun/logger": "^0.
|
|
25
|
-
"@kubun/mutation": "^0.
|
|
23
|
+
"@kubun/id": "^0.5.0",
|
|
24
|
+
"@kubun/logger": "^0.5.0",
|
|
25
|
+
"@kubun/mutation": "^0.5.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@kubun/graphql": "^0.
|
|
29
|
-
"@kubun/protocol": "^0.
|
|
28
|
+
"@kubun/graphql": "^0.5.0",
|
|
29
|
+
"@kubun/protocol": "^0.5.0"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build:clean": "del lib",
|
package/lib/attachments.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachments.d.ts","sourceRoot":"","sources":["../src/attachments.ts"],"names":[],"mappings":"AAGA,gBAAgB;AAChB,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAEjF;AAED,gBAAgB;AAChB,wBAAgB,mBAAmB,CAAC,WAAW,GAAE,KAAK,CAAC,UAAU,CAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAM/F"}
|
package/lib/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAkB,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,eAAe,EAC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AAC,UAAU,GAAG,IAAI,CAAC,CAAA;IACrD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,MAAM,EAAE,WAAW,CAAA;CACpB,CAAA;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAoE/D;AAED,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAA;AAE3E,KAAK,oBAAoB,GAAG;IAC1B,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AAED,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,gBAAgB,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC,CAAA;AAED,qBAAa,eAAe;;gBAGd,MAAM,GAAE,oBAAyB;IAI7C,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI9B,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;IAI/E,OAAO,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;CAavE"}
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACzF,OAAO,EACL,KAAK,YAAY,EACjB,WAAW,EACX,KAAK,eAAe,EACpB,gBAAgB,EAChB,eAAe,EACf,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAA"}
|
package/lib/mutations.d.ts.map
DELETED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