@kubun/store-graph 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.
- package/LICENSE.md +57 -0
- package/lib/api.d.ts +70 -0
- package/lib/api.js +1 -0
- package/lib/cursor.d.ts +7 -0
- package/lib/cursor.js +1 -0
- package/lib/definition.d.ts +4 -0
- package/lib/definition.js +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +1 -0
- package/lib/migrations.d.ts +3 -0
- package/lib/migrations.js +1 -0
- package/lib/query-builder.d.ts +12 -0
- package/lib/query-builder.js +1 -0
- package/lib/tables.d.ts +219 -0
- package/lib/tables.js +1 -0
- package/package.json +40 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# The Prosperity Public License 3.0.0
|
|
2
|
+
|
|
3
|
+
Contributor: Paul Le Cam
|
|
4
|
+
|
|
5
|
+
Source Code: https://github.com/PaulLeCam/kubun
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.
|
|
10
|
+
|
|
11
|
+
## Agreement
|
|
12
|
+
|
|
13
|
+
In order to receive this license, you have to agree to its rules. Those rules are both obligations under that agreement and conditions to your license. Don't do anything with this software that triggers a rule you can't or won't follow.
|
|
14
|
+
|
|
15
|
+
## Notices
|
|
16
|
+
|
|
17
|
+
Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
|
|
18
|
+
|
|
19
|
+
## Commercial Trial
|
|
20
|
+
|
|
21
|
+
Limit your use of this software for commercial purposes to a thirty-day trial period. If you use this software for work, your company gets one trial period for all personnel, not one trial per person.
|
|
22
|
+
|
|
23
|
+
## Contributions Back
|
|
24
|
+
|
|
25
|
+
Developing feedback, changes, or additions that you contribute back to the contributor on the terms of a standardized public software license such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html) doesn't count as use for a commercial purpose.
|
|
26
|
+
|
|
27
|
+
## Personal Uses
|
|
28
|
+
|
|
29
|
+
Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn't count as use for a commercial purpose.
|
|
30
|
+
|
|
31
|
+
## Noncommercial Organizations
|
|
32
|
+
|
|
33
|
+
Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution doesn't count as use for a commercial purpose regardless of the source of funding or obligations resulting from the funding.
|
|
34
|
+
|
|
35
|
+
## Defense
|
|
36
|
+
|
|
37
|
+
Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
|
|
38
|
+
|
|
39
|
+
## Copyright
|
|
40
|
+
|
|
41
|
+
The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
|
|
42
|
+
|
|
43
|
+
## Patent
|
|
44
|
+
|
|
45
|
+
The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
|
|
46
|
+
|
|
47
|
+
## Reliability
|
|
48
|
+
|
|
49
|
+
The contributor can't revoke this license.
|
|
50
|
+
|
|
51
|
+
## Excuse
|
|
52
|
+
|
|
53
|
+
You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
|
|
54
|
+
|
|
55
|
+
## No Liability
|
|
56
|
+
|
|
57
|
+
***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
|
package/lib/api.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Adapter } from '@kubun/db-adapter';
|
|
2
|
+
import { DocumentID, DocumentModelID } from '@kubun/id';
|
|
3
|
+
import type { DocumentModel, DocumentNode } from '@kubun/protocol';
|
|
4
|
+
import type { Kysely } from 'kysely';
|
|
5
|
+
import type { Catalog, ClusterDefinitionRow, ClusterModel, CountDocumentsParams, CreateDocumentParams, CreateGraphParams, GraphModel, GraphModelWithRecord, GraphTables, InsertCatalog, InsertClusterModel, InsertDocumentAttachment, InsertMutationLogEntry, ListDocumentsParams, MutationLogEntry, QueryDocumentsParams, QueryDocumentsResult, SaveDocumentParams, SearchDocumentResult, SearchDocumentsParams } from './tables.js';
|
|
6
|
+
export type GraphStoreAPI = {
|
|
7
|
+
getDocument(id: DocumentID): Promise<DocumentNode | null>;
|
|
8
|
+
getDocumentModel(id: DocumentModelID | string): Promise<DocumentModel>;
|
|
9
|
+
createDocument(params: CreateDocumentParams): Promise<DocumentNode>;
|
|
10
|
+
saveDocument(params: SaveDocumentParams): Promise<DocumentNode>;
|
|
11
|
+
queryDocuments(params: QueryDocumentsParams): Promise<QueryDocumentsResult>;
|
|
12
|
+
countDocuments(params: CountDocumentsParams): Promise<number>;
|
|
13
|
+
listDocuments(params: ListDocumentsParams): Promise<Array<DocumentNode>>;
|
|
14
|
+
listDocumentModelIDs(): Promise<Array<string>>;
|
|
15
|
+
getDistinctOwnersForModel(modelID: string): Promise<Array<string>>;
|
|
16
|
+
queryDocumentsByOwner(modelID: string, ownerDID: string): Promise<Array<DocumentNode>>;
|
|
17
|
+
insertMutationLogEntry(entry: InsertMutationLogEntry): Promise<void>;
|
|
18
|
+
hasMutationHash(hash: string): Promise<boolean>;
|
|
19
|
+
updateMutationStatus(mutationHash: string, status: string): Promise<void>;
|
|
20
|
+
getMutationLogForDocuments(documentIDs: Array<string>): Promise<Array<MutationLogEntry>>;
|
|
21
|
+
getPendingMutations(documentID: string): Promise<Array<MutationLogEntry>>;
|
|
22
|
+
getFieldHLCs(documentID: string): Promise<Record<string, string> | null>;
|
|
23
|
+
updateFieldHLCs(docID: DocumentID, fieldHLCs: Record<string, string>): Promise<void>;
|
|
24
|
+
listGraphs(): Promise<Array<GraphModel>>;
|
|
25
|
+
createGraph(params: CreateGraphParams): Promise<string>;
|
|
26
|
+
getGraph(id: string): Promise<GraphModelWithRecord | null>;
|
|
27
|
+
getClusterForModel(modelID: string): Promise<string | undefined>;
|
|
28
|
+
getClusterModels(clusterID: string): Promise<Array<ClusterModel>>;
|
|
29
|
+
saveCluster(id: string, definition: unknown): Promise<void>;
|
|
30
|
+
getCluster(id: string): Promise<ClusterDefinitionRow | undefined>;
|
|
31
|
+
getClusters(ids: Array<string>): Promise<Record<string, unknown>>;
|
|
32
|
+
addAttachments(attachments: Array<InsertDocumentAttachment>): Promise<void>;
|
|
33
|
+
createSearchIndex(modelID: string, fields: Array<string>): Promise<void>;
|
|
34
|
+
dropSearchIndex(modelID: string): Promise<void>;
|
|
35
|
+
updateSearchEntry(modelID: string, documentID: string, data: Record<string, unknown>, fields: Array<string>): Promise<void>;
|
|
36
|
+
removeSearchEntry(modelID: string, documentID: string): Promise<void>;
|
|
37
|
+
searchDocuments(params: SearchDocumentsParams): Promise<Array<SearchDocumentResult>>;
|
|
38
|
+
createCatalog(catalog: InsertCatalog): Promise<void>;
|
|
39
|
+
getCatalog(id: string): Promise<Catalog | undefined>;
|
|
40
|
+
updateCatalog(id: string, update: Partial<Pick<InsertCatalog, 'name' | 'description' | 'filter_criteria' | 'hlc'>>): Promise<void>;
|
|
41
|
+
deleteCatalog(id: string): Promise<void>;
|
|
42
|
+
listCatalogs(ownerDID: string): Promise<Array<Catalog>>;
|
|
43
|
+
resolveCatalogScope(catalogID: string): Promise<{
|
|
44
|
+
models: Array<string> | undefined;
|
|
45
|
+
owners: Array<string> | undefined;
|
|
46
|
+
}>;
|
|
47
|
+
registerClusterModels(clusterID: string, entries: Array<InsertClusterModel>): Promise<void>;
|
|
48
|
+
getUserModelAccessDefault(ownerDID: string, modelID: string, permissionType: 'read' | 'write'): Promise<{
|
|
49
|
+
level: string;
|
|
50
|
+
allowedDIDs: Array<string> | null;
|
|
51
|
+
} | null>;
|
|
52
|
+
setUserModelAccessDefault(params: {
|
|
53
|
+
ownerDID: string;
|
|
54
|
+
modelID: string;
|
|
55
|
+
permissionType: 'read' | 'write';
|
|
56
|
+
accessLevel: string;
|
|
57
|
+
allowedDIDs: Array<string> | null;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
removeUserModelAccessDefaults(ownerDID: string, modelID: string, permissionTypes: Array<string>): Promise<void>;
|
|
60
|
+
getDocumentIDsForScope(scopes: Array<{
|
|
61
|
+
modelID: string;
|
|
62
|
+
ownerDID: string;
|
|
63
|
+
}>, excludedDocumentIDs?: Array<string>): Promise<Array<string>>;
|
|
64
|
+
getDocumentMetadataForSync(modelID: string, documentIDs: Array<string>): Promise<Array<{
|
|
65
|
+
id: string;
|
|
66
|
+
model: string;
|
|
67
|
+
owner: string;
|
|
68
|
+
}>>;
|
|
69
|
+
};
|
|
70
|
+
export declare function createGraphStore(db: Kysely<GraphTables>, adapter: Adapter): GraphStoreAPI;
|
package/lib/api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DocumentID as e,DocumentModelID as t}from"@kubun/id";import{serializeCursor as n}from"./cursor.js";function l(e,t){if(!(e instanceof Error))return!1;let n=e.message;return n.includes("no such table")&&n.includes(t)||n.includes("does not exist")&&n.includes(t)}import{applyDocumentFilter as a,applyDocumentOrderBy as r,applyPagination as o}from"./query-builder.js";function i(e){let t={version:e.version,name:e.name,behavior:e.behavior,interfaces:e.interfaces,schema:e.schema,fieldsMeta:e.fields_meta};return"unique"===t.behavior&&(t.uniqueFields=e.unique_fields),t}function s(e,t){return{id:t.id,model:t.model,owner:t.owner,data:t.data,createdAt:e.decodeTimestamp(t.created_at),updatedAt:t.updated_at?e.decodeTimestamp(t.updated_at):null}}function u(e,n){let l=t.fromString(n);return l.isLocal?l.toGlobal(t.fromString(e)).toString():n}async function c(e,t,n){let{id:l,graphModelID:a,model:r}=n,o=t.types;for(let n of(await e.schema.createTable(`k_${l}`).ifNotExists().addColumn("id",o.text,e=>e.notNull().primaryKey()).addColumn("owner",o.text,e=>e.notNull()).addColumn("model",o.text,e=>e.notNull()).addColumn("data",o.json).addColumn("field_hlcs",o.json).addColumn("unique",o.binary,e=>e.notNull()).addColumn("created_at",o.timestamp,e=>e.defaultTo(t.functions.now).notNull()).addColumn("updated_at",o.timestamp).execute(),await e.insertInto("kubun_document_models").values({id:l,version:r.version,name:r.name,behavior:r.behavior,unique_fields:"unique"===r.behavior?t.encodeJSON(r.uniqueFields):null,interfaces:t.encodeJSON(r.interfaces),schema:t.encodeJSON(r.schema),fields_meta:t.encodeJSON(r.fieldsMeta)}).onConflict(e=>e.doNothing()).execute(),r.interfaces))await e.insertInto("kubun_document_model_interfaces").values({interface_id:u(l,n),implementation_id:l}).onConflict(e=>e.doNothing()).execute();await e.insertInto("kubun_graph_document_models").values({graph_model_id:a,document_model_id:l}).onConflict(e=>e.doNothing()).execute()}export function createGraphStore(t,d){let m=d.coerceFilterValue.bind(d);async function _(e,t){if(null==t)return{effectiveModelIDs:e,effectiveOwners:void 0};let{models:n,owners:l}=await w.resolveCatalogScope(t),a=e;if(null!=n){let e=new Set(n);a=a.filter(t=>e.has(t))}return{effectiveModelIDs:a,effectiveOwners:l}}let w={async getDocument(e){let n=await t.selectFrom(`k_${e.model.toString()}`).selectAll().where("id","=",e.toString()).executeTakeFirst();return n?s(d,n):null},getDocumentModel:async e=>i(await t.selectFrom("kubun_document_models").selectAll().where("id","=",e.toString()).executeTakeFirstOrThrow()),async createDocument(e){let n=e.id.toString(),l=e.id.model.toString(),a=await t.insertInto(`k_${l}`).values({id:n,owner:e.owner,model:l,data:d.encodeJSON(e.data),unique:d.encodeBinary(e.unique)}).returningAll().executeTakeFirstOrThrow(()=>Error(`createDocument failed to return row for ${n}`));return s(d,a)},async saveDocument(e){let n=e.id.toString(),l=await t.updateTable(`k_${e.id.model.toString()}`).set({data:e.data?d.encodeJSON(e.data):null,updated_at:d.encodeTimestamp(new Date)}).where("id","=",n).returningAll().executeTakeFirstOrThrow(()=>Error(`saveDocument: document not found for id=${n}`));return s(d,l)},async queryDocuments(e){let{catalogID:l,filter:i,modelIDs:u,orderBy:c,owner:w,...h}=e,f=null!=e.last,{effectiveModelIDs:g,effectiveOwners:p}=await _(u,l);if(0===g.length)return{entries:[],hasMore:!1};let[y,...k]=g,x=t.selectFrom(`k_${y}`).selectAll();for(let e of(null!=w&&(x=x.where("owner","=",w)),null!=p&&(x=x.where("owner","in",p)),null!=i&&(x=x.where(e=>a(e,i,[],m))),k))x=x.unionAll(t=>{let n=t.selectFrom(`k_${e}`).selectAll();return null!=w&&(n=n.where("owner","=",w)),null!=p&&(n=n.where("owner","in",p)),null!=i&&(n=n.where(e=>a(e,i,[],m))),n});let[b,S]=r(x,c,f),[F,D]=o(b,h,c),v=await F.execute(),C=f?v.slice(0,D).reverse():v.slice(0,D);return{entries:S?C.map(e=>{let t={};for(let n of S){let l=e.data;for(let e of n)null!=l&&(l=l[e]);null!=l&&(t[n.join(".")]=l)}return{cursor:n({id:e.id,values:t}),document:s(d,e)}}):C.map(e=>({cursor:n({id:e.id,ts:+e.created_at}),document:s(d,e)})),hasMore:v.length>D}},async countDocuments(e){let{catalogID:n,filter:l,modelIDs:r,owner:o}=e,{effectiveModelIDs:i,effectiveOwners:s}=await _(r,n);return 0===i.length?0:(await Promise.all(i.map(async e=>{let n=t.selectFrom(`k_${e}`).select(e=>e.fn.countAll().as("count"));return null!=o&&(n=n.where("owner","=",o)),null!=s&&(n=n.where("owner","in",s)),null!=l&&(n=n.where(e=>a(e,l,[],m))),Number((await n.executeTakeFirstOrThrow()).count)}))).reduce((e,t)=>e+t,0)},async listDocuments(e){let[n,...l]=e.modelIDs,a=t.selectFrom(`k_${n}`).selectAll().where("id","in",e.docIDs);for(let t of l)a=a.unionAll(n=>n.selectFrom(`k_${t}`).selectAll().where("id","in",e.docIDs));return(await a.execute()).map(e=>s(d,e))},listDocumentModelIDs:async()=>(await t.selectFrom("kubun_document_models").select("id").execute()).map(e=>e.id),async getDistinctOwnersForModel(e){try{return(await t.selectFrom(`k_${e}`).select("owner").distinct().execute()).map(e=>e.owner)}catch(t){if(l(t,`k_${e}`))return[];throw t}},queryDocumentsByOwner:async(e,n)=>(await t.selectFrom(`k_${e}`).selectAll().where("owner","=",n).execute()).map(e=>s(d,e)),async insertMutationLogEntry(e){await t.insertInto("kubun_mutation_log").values(e).onConflict(e=>e.doNothing()).execute()},hasMutationHash:async e=>null!=await t.selectFrom("kubun_mutation_log").select("mutation_hash").where("mutation_hash","=",e).executeTakeFirst(),async updateMutationStatus(e,n){await t.updateTable("kubun_mutation_log").set({status:n}).where("mutation_hash","=",e).execute()},getMutationLogForDocuments:async e=>0===e.length?[]:await t.selectFrom("kubun_mutation_log").selectAll().where("document_id","in",e).orderBy("hlc","asc").execute(),getPendingMutations:async e=>await t.selectFrom("kubun_mutation_log").selectAll().where("document_id","=",e).where("status","=","pending").orderBy("hlc","asc").execute(),async getFieldHLCs(n){let l=e.fromString(n).model.toString(),a=await t.selectFrom(`k_${l}`).select("field_hlcs").where("id","=",n).executeTakeFirst();if(a?.field_hlcs==null)return null;let r=a.field_hlcs;return"string"==typeof r?JSON.parse(r):r},async updateFieldHLCs(e,n){let l=e.model.toString();await t.updateTable(`k_${l}`).set({field_hlcs:d.encodeJSON(n)}).where("id","=",e.toString()).execute()},listGraphs:async()=>await t.selectFrom("kubun_graph_models").selectAll().execute(),async createGraph(e){let n=e.id,l=e.name??n;return await t.transaction().setIsolationLevel("read committed").execute(async t=>{await t.insertInto("kubun_graph_models").values({aliases:d.encodeJSON(e.aliases??{}),extension_sdl:e.extensionSDL??null,id:n,name:l,plugin_config:e.pluginConfig?d.encodeJSON(e.pluginConfig):null,search:e.search?d.encodeJSON(e.search):null}).onConflict(e=>e.doNothing()).execute();let a=Object.entries(e.record),r=new Set;for(;r.size<a.length;){let e=a.filter(([e,t])=>!r.has(e)&&t.interfaces.every(t=>r.has(u(e,t))));if(0===e.length)throw Error("Could not create graph: no valid model to add");await Promise.all(e.map(async([e,l])=>{await c(t,d,{id:e,graphModelID:n,model:l}),r.add(e)}))}}),n},async getGraph(e){let n=await t.selectFrom("kubun_graph_models").selectAll().where("id","=",e).executeTakeFirst();if(null==n)return null;let l={};for(let n of(await t.selectFrom("kubun_graph_document_models").innerJoin("kubun_document_models","kubun_graph_document_models.document_model_id","kubun_document_models.id").selectAll("kubun_document_models").where("kubun_graph_document_models.graph_model_id","=",e).execute()))l[n.id]=i(n);return{...n,record:l}},async getClusterForModel(e){let n=await t.selectFrom("kubun_cluster_models").select("cluster_id").where("model_id","=",e).executeTakeFirst();return n?.cluster_id},getClusterModels:async e=>await t.selectFrom("kubun_cluster_models").selectAll().where("cluster_id","=",e).orderBy("cluster_index").execute(),async saveCluster(e,n){await t.insertInto("kubun_clusters").values({id:e,definition:d.encodeJSON(n)}).onConflict(e=>e.column("id").doUpdateSet(e=>({definition:e.ref("excluded.definition")}))).execute()},getCluster:async e=>await t.selectFrom("kubun_clusters").selectAll().where("id","=",e).executeTakeFirst(),async getClusters(e){if(0===e.length)return{};let n=await t.selectFrom("kubun_clusters").selectAll().where("id","in",e).execute(),l={};for(let e of n)l[e.id]=e.definition;return l},async addAttachments(e){await t.insertInto("kubun_document_attachments").values(e).onConflict(e=>e.doNothing()).execute()},async createSearchIndex(e,n){await d.createSearchIndex(t,{modelID:e,fields:n})},async dropSearchIndex(e){await d.dropSearchIndex(t,e)},async updateSearchEntry(e,n,l,a){let r={};for(let e of a){let t=function(e,t){let n=t.split("."),l=e;for(let e of n){if(null==l||"object"!=typeof l)return null;l=l[e]}return l}(l,e);null!=t&&(r[e]=String(t))}await d.updateSearchEntry(t,e,n,r,a)},async removeSearchEntry(e,n){await d.removeSearchEntry(t,e,n)},async searchDocuments(e){let n=[];for(let l of e.modelIDs)for(let a of(await d.searchIndex(t,{query:e.query,modelID:l,limit:e.first??50})))n.push({documentID:a.documentID,modelID:l,rank:a.rank});return(n.sort((e,t)=>Math.abs(t.rank)-Math.abs(e.rank)),e.first)?n.slice(0,e.first):n},async createCatalog(e){await t.insertInto("kubun_catalogs").values({id:e.id,owner_did:e.owner_did,name:e.name,description:e.description,filter_criteria:d.encodeJSON(e.filter_criteria),hlc:e.hlc}).execute()},getCatalog:async e=>await t.selectFrom("kubun_catalogs").selectAll().where("id","=",e).executeTakeFirst(),async updateCatalog(e,n){let l={};null!=n.name&&(l.name=n.name),null!=n.description&&(l.description=n.description),null!=n.filter_criteria&&(l.filter_criteria=d.encodeJSON(n.filter_criteria)),null!=n.hlc&&(l.hlc=n.hlc),l.updated_at=d.encodeTimestamp(new Date),await t.updateTable("kubun_catalogs").set(l).where("id","=",e).execute()},async deleteCatalog(e){await t.deleteFrom("kubun_catalogs").where("id","=",e).execute()},listCatalogs:async e=>await t.selectFrom("kubun_catalogs").selectAll().where("owner_did","=",e).execute(),async resolveCatalogScope(e){let t,n=await w.getCatalog(e);if(null==n)return{models:void 0,owners:void 0};let l=n.filter_criteria,a=null!=l.models&&l.models.length>0?l.models:void 0;return null!=l.owners&&l.owners.length>0&&(t=[...l.owners]),{models:a,owners:t}},async registerClusterModels(e,n){0!==n.length&&await t.insertInto("kubun_cluster_models").values(n).onConflict(e=>e.column("model_id").doUpdateSet(e=>({cluster_id:e.ref("excluded.cluster_id"),cluster_index:e.ref("excluded.cluster_index")}))).execute()},async getUserModelAccessDefault(e,n,l){let a=await t.selectFrom("kubun_user_model_access_defaults").select(["access_level","allowed_dids"]).where("owner_did","=",e).where("model_id","=",n).where("permission_type","=",l).executeTakeFirst();return a?{level:a.access_level,allowedDIDs:a.allowed_dids}:null},async setUserModelAccessDefault(e){await t.insertInto("kubun_user_model_access_defaults").values({owner_did:e.ownerDID,model_id:e.modelID,permission_type:e.permissionType,access_level:e.accessLevel,allowed_dids:e.allowedDIDs?d.encodeJSON(e.allowedDIDs):null}).onConflict(t=>t.columns(["owner_did","model_id","permission_type"]).doUpdateSet({access_level:e.accessLevel,allowed_dids:e.allowedDIDs?d.encodeJSON(e.allowedDIDs):null,updated_at:d.encodeTimestamp(new Date)})).execute()},async removeUserModelAccessDefaults(e,n,l){await t.deleteFrom("kubun_user_model_access_defaults").where("owner_did","=",e).where("model_id","=",n).where("permission_type","in",l).execute()},async getDocumentIDsForScope(e,n=[]){let a=[];for(let n of e)try{let e=await t.selectFrom(`k_${n.modelID}`).select("id").where("owner","=",n.ownerDID).execute();a.push(...e.map(e=>e.id))}catch(e){if(!l(e,`k_${n.modelID}`))throw e}if(n.length>0){let e=new Set(n);return a.filter(t=>!e.has(t))}return a},getDocumentMetadataForSync:async(e,n)=>0===n.length?[]:(await t.selectFrom(`k_${e}`).select(["id","model","owner"]).where("id","in",n).execute()).map(e=>({id:e.id,model:e.model,owner:e.owner}))};return w}
|
package/lib/cursor.d.ts
ADDED
package/lib/cursor.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b64uFromJSON as r,b64uToJSON as e}from"@enkaku/codec";export function parseCursor(r){return e(r)}export function serializeCursor(e){return r(e)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createGraphStore as r}from"./api.js";import{getGraphMigrations as i}from"./migrations.js";export const graphStoreDefinition={name:"graph",migrations:i,createAPI:r};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StoreProvider } from '@kubun/db';
|
|
2
|
+
import type { GraphStoreAPI } from './api.js';
|
|
3
|
+
export type { GraphStoreAPI } from './api.js';
|
|
4
|
+
export { createGraphStore } from './api.js';
|
|
5
|
+
export { graphStoreDefinition } from './definition.js';
|
|
6
|
+
export declare const GRAPH_STORE: "graph";
|
|
7
|
+
export declare function getGraphStore(provider: StoreProvider): Promise<GraphStoreAPI>;
|
|
8
|
+
export type { AccessPermissions, AddDocumentModelParams, Catalog, ClusterDefinitionRow, ClusterModel, ConnectionArguments, CountDocumentsParams, CreateDocumentParams, CreateGraphParams, CursorDocument, Document, DocumentAttachment, DocumentData, DocumentModelRow, DocumentParams, GraphModel, GraphModelWithRecord, GraphTables, InsertCatalog, InsertClusterModel, InsertDocument, InsertDocumentAttachment, InsertDocumentModel, InsertDocumentModelInterface, InsertMutationLogEntry, ListDocumentsParams, MutationLogEntry, PaginatedResult, PaginationParams, QueryDocumentsParams, QueryDocumentsResult, SaveDocumentParams, SearchConfig, SearchDocumentResult, SearchDocumentsParams, UpdateDocument, UpdateDocumentModel, } from './tables.js';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{createGraphStore}from"./api.js";export{graphStoreDefinition}from"./definition.js";export const GRAPH_STORE="graph";export function getGraphStore(r){return r.getStore("graph")}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getGraphMigrations(e){let t=e.types,a=e.functions.now;return{"0-init":{async up(e){await e.schema.createTable("kubun_document_attachments").ifNotExists().addColumn("id",t.text,e=>e.notNull().primaryKey()).addColumn("data",t.binary,e=>e.notNull()).addColumn("created_at",t.timestamp,e=>e.defaultTo(a).notNull()).execute(),await e.schema.createTable("kubun_document_models").ifNotExists().addColumn("id",t.text,e=>e.notNull().primaryKey()).addColumn("version",t.text,e=>e.notNull()).addColumn("name",t.text,e=>e.notNull()).addColumn("behavior",t.text,e=>e.notNull()).addColumn("unique_fields",t.json).addColumn("interfaces",t.json,e=>e.notNull()).addColumn("schema",t.json,e=>e.notNull()).addColumn("fields_meta",t.json,e=>e.notNull()).addColumn("created_at",t.timestamp,e=>e.defaultTo(a).notNull()).execute(),await e.schema.createTable("kubun_document_model_interfaces").ifNotExists().addColumn("interface_id",t.text,e=>e.notNull().references("kubun_document_models.id")).addColumn("implementation_id",t.text,e=>e.notNull().references("kubun_document_models.id")).addUniqueConstraint("kubun_document_model_interfaces_pkey",["interface_id","implementation_id"]).execute(),await e.schema.createTable("kubun_graph_models").ifNotExists().addColumn("id",t.text,e=>e.notNull().primaryKey()).addColumn("name",t.text,e=>e.notNull()).addColumn("aliases",t.json,e=>e.defaultTo("{}").notNull()).addColumn("search",t.json).addColumn("extension_sdl",t.text).addColumn("plugin_config",t.json).addColumn("created_at",t.timestamp,e=>e.defaultTo(a).notNull()).addColumn("updated_at",t.timestamp).execute(),await e.schema.createTable("kubun_graph_document_models").ifNotExists().addColumn("graph_model_id",t.text,e=>e.notNull().references("kubun_graph_models.id")).addColumn("document_model_id",t.text,e=>e.notNull().references("kubun_document_models.id")).addUniqueConstraint("kubun_graph_document_models_pkey",["graph_model_id","document_model_id"]).execute(),await e.schema.createTable("kubun_user_model_access_defaults").ifNotExists().addColumn("owner_did",t.text,e=>e.notNull()).addColumn("model_id",t.text,e=>e.notNull()).addColumn("permission_type",t.text,e=>e.notNull()).addColumn("access_level",t.text,e=>e.notNull()).addColumn("allowed_dids",t.json).addColumn("created_at",t.timestamp,e=>e.defaultTo(a).notNull()).addColumn("updated_at",t.timestamp).addPrimaryKeyConstraint("kubun_user_model_access_defaults_pkey",["owner_did","model_id","permission_type"]).execute(),await e.schema.createIndex("idx_user_model_access_owner_model").on("kubun_user_model_access_defaults").columns(["owner_did","model_id"]).execute(),await e.schema.createTable("kubun_mutation_log").ifNotExists().addColumn("mutation_hash",t.text,e=>e.primaryKey()).addColumn("model_id",t.text,e=>e.notNull()).addColumn("document_id",t.text,e=>e.notNull()).addColumn("author_did",t.text,e=>e.notNull()).addColumn("hlc",t.text,e=>e.notNull()).addColumn("mutation_jwt",t.text,e=>e.notNull()).addColumn("status",t.text,e=>e.notNull().defaultTo("applied")).execute(),await e.schema.createIndex("idx_mutation_log_hlc").on("kubun_mutation_log").column("hlc").execute(),await e.schema.createIndex("idx_mutation_log_document").on("kubun_mutation_log").column("document_id").execute(),await e.schema.createIndex("idx_mutation_log_status").on("kubun_mutation_log").column("status").execute(),await e.schema.createTable("kubun_cluster_models").ifNotExists().addColumn("model_id",t.text,e=>e.notNull().primaryKey()).addColumn("cluster_id",t.text,e=>e.notNull()).addColumn("cluster_index","integer",e=>e.notNull()).execute(),await e.schema.createIndex("idx_cluster_models_cluster").on("kubun_cluster_models").column("cluster_id").execute(),await e.schema.createTable("kubun_clusters").ifNotExists().addColumn("id",t.text,e=>e.notNull().primaryKey()).addColumn("definition",t.json,e=>e.notNull()).execute(),await e.schema.createTable("kubun_catalogs").ifNotExists().addColumn("id",t.text,e=>e.notNull().primaryKey()).addColumn("owner_did",t.text,e=>e.notNull()).addColumn("name",t.text,e=>e.notNull()).addColumn("description",t.text,e=>e.notNull().defaultTo("")).addColumn("filter_criteria",t.json,e=>e.notNull()).addColumn("hlc",t.text,e=>e.notNull()).addColumn("created_at",t.timestamp,e=>e.defaultTo(a).notNull()).addColumn("updated_at",t.timestamp).execute(),await e.schema.createIndex("idx_catalogs_owner").ifNotExists().on("kubun_catalogs").column("owner_did").execute()},async down(e){await e.schema.dropTable("kubun_catalogs").ifExists().execute(),await e.schema.dropTable("kubun_clusters").ifExists().execute(),await e.schema.dropTable("kubun_cluster_models").ifExists().execute(),await e.schema.dropTable("kubun_mutation_log").ifExists().execute(),await e.schema.dropTable("kubun_user_model_access_defaults").ifExists().execute(),await e.schema.dropTable("kubun_graph_document_models").ifExists().execute(),await e.schema.dropTable("kubun_graph_models").ifExists().execute(),await e.schema.dropTable("kubun_document_model_interfaces").ifExists().execute(),await e.schema.dropTable("kubun_document_models").ifExists().execute(),await e.schema.dropTable("kubun_document_attachments").ifExists().execute()}}}}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AnyValueFilter, DocumentFilter, DocumentOrderBy } from '@kubun/protocol';
|
|
2
|
+
import type { ExpressionBuilder, ExpressionWrapper, SelectQueryBuilder } from 'kysely';
|
|
3
|
+
import type { ConnectionArguments, Document, GraphTables } from './tables.js';
|
|
4
|
+
export type CoerceFilterValue = (value: unknown) => unknown;
|
|
5
|
+
type DocumentExpressionBuilder = ExpressionBuilder<GraphTables, 'k_document'>;
|
|
6
|
+
type DocumentExpressionWrapper = ExpressionWrapper<GraphTables, 'k_document', any>;
|
|
7
|
+
export type DocumentQueryBuilder = SelectQueryBuilder<GraphTables, 'k_document', Document>;
|
|
8
|
+
export declare function applyPagination(query: DocumentQueryBuilder, args: ConnectionArguments, orderBy?: DocumentOrderBy): [DocumentQueryBuilder, number];
|
|
9
|
+
export declare function applyDocumentFilter(eb: DocumentExpressionBuilder, filter: DocumentFilter, path?: Array<string>, coerce?: CoerceFilterValue): DocumentExpressionWrapper;
|
|
10
|
+
export declare function applyValueFilter(eb: DocumentExpressionBuilder, keys: Array<string>, filter: AnyValueFilter, coerce?: CoerceFilterValue): DocumentExpressionWrapper;
|
|
11
|
+
export declare function applyDocumentOrderBy(queryBuilder: DocumentQueryBuilder, orderBy?: DocumentOrderBy, isReverse?: boolean): [DocumentQueryBuilder, Array<Array<string>> | null];
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseCursor as e}from"./cursor.js";function t(e=50){return Math.min(e,100)}function r(e,t){let r=e.ref("data","->>");for(let e of t)r=r.key(e);return r}function n(e){let t=[],r=e;do{let[e,n]=Object.entries(r)[0];if(t.push(e),"string"==typeof n)return{keys:t,direction:n};r=n}while(null!=r)throw Error("Could not extract field entry")}function l(e,t=!1){return t?"asc"===e?"desc":"asc":e}export function applyPagination(l,a,o=[]){let{first:i,last:u,before:c,after:d}=a;if(null!=i){let a=t(i);return[function(t,l,a,o){let i=t;if(null!=a){let{id:t,ts:l,values:u}=e(a);null!=l?i=i.where(e=>e.or([e("created_at",">",l),e("created_at","=",l).and("id",">",t)])):null!=u&&(i=i.where(e=>{let l=[];for(let a of o){let o=n(a),i=u[o.keys.join(".")];if(null==i)continue;let c=r(e,o.keys);l.push(e.or([e(c,"asc"===o.direction?">":"<",i),e(c,"=",i).and("id",">",t)]))}return e.and(l)}))}return i.orderBy("created_at","asc").limit(l)}(l,a+1,d,o),a]}if(null!=u){let a=t(u);return[function(t,l,a,o){let i=t;if(null!=a){let{id:t,ts:l,values:u}=e(a);null!=l?i=i.where(e=>e.or([e("created_at","<",l),e("created_at","=",l).and("id","<",t)])):null!=u&&(i=i.where(e=>{let l=[];for(let a of o){let o=n(a),i=u[o.keys.join(".")];if(null==i)continue;let c=r(e,o.keys);l.push(e.or([e(c,"asc"===o.direction?"<":">",i),e(c,"=",i).and("id",">",t)]))}return e.and(l)}))}return i.orderBy("created_at","desc").limit(l)}(l,a+1,c,o),a]}let s=t();return[l.orderBy("created_at","asc").limit(s+1),s]}export function applyDocumentFilter(e,t,r=[],n){let l=Object.entries(t);if(1!==l.length)throw Error("Invalid document filter");let[a,o]=l[0];switch(a){case"where":var i,u,c,d;let s;return i=e,u=o,c=r,d=n,s=Object.entries(u).map(([e,t])=>applyValueFilter(i,[...c,e],t,d)),i.and(s);case"and":return e.and(o.map(t=>applyDocumentFilter(e,t,r,n)));case"or":return e.or(o.map(t=>applyDocumentFilter(e,t,r,n)));case"not":return e.not(applyDocumentFilter(e,o,r,n));default:throw Error(`Invalid document filter type: ${a}`)}}export function applyValueFilter(e,t,n,l){let a=Object.entries(n);if(1!==a.length)throw Error("Invalid value filter");let o=r(e,t),[i,u]=a[0],c=l??(e=>e);switch(i){case"isNull":return e(o,!0===u?"is":"is not",null);case"equalTo":return e(o,"=",c(u));case"notEqualTo":return e(o,"!=",c(u));case"in":return e(o,"in",u.map(c));case"notIn":return e(o,"not in",u.map(c));case"lessThan":return e(o,"<",c(u));case"lessThanOrEqualTo":return e(o,"<=",c(u));case"greaterThan":return e(o,">",c(u));case"greaterThanOrEqualTo":return e(o,">=",c(u));default:throw Error(`Invalid value filter type: ${i}`)}}export function applyDocumentOrderBy(e,t=[],n=!1){if(0===t.length)return[e.orderBy("created_at",l("asc",n)),null];let o=e,i=[];for(let e of t){let[t,u]=function e(t,n,o,i=[]){let u=Object.entries(n);if(1!==u.length)throw Error("Invalid order by field");let[c,d]=u[0],s=[...i,c],f=a[c];return null!=f?[t.orderBy(f,l(d,o)),s]:"string"==typeof d?[t.orderBy(e=>r(e,s),l(d,o)),s]:e(t,d,o,s)}(o,e,n);o=t,i.push(u)}return[o,i]}let a={_createdAt:"created_at",_owner:"owner"};
|
package/lib/tables.d.ts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type { CreatedAtColumn, UpdatedAtColumn } from '@kubun/db-adapter';
|
|
2
|
+
import type { DocumentID } from '@kubun/id';
|
|
3
|
+
import type { CatalogFilterCriteria, DocumentFieldsMeta, DocumentFilter, DocumentModelSchema, DocumentModelsRecord, DocumentNode, DocumentOrderBy } from '@kubun/protocol';
|
|
4
|
+
import type { ColumnType, Insertable, Selectable, Updateable } from 'kysely';
|
|
5
|
+
type JSONValueColumn<T> = ColumnType<T, T, T>;
|
|
6
|
+
export type DocumentData = Record<string, unknown>;
|
|
7
|
+
export type DocumentTable<Data extends DocumentData = DocumentData> = {
|
|
8
|
+
id: string;
|
|
9
|
+
owner: string;
|
|
10
|
+
model: string;
|
|
11
|
+
data: JSONValueColumn<Data> | null;
|
|
12
|
+
field_hlcs: JSONValueColumn<Record<string, string>> | null;
|
|
13
|
+
unique: Uint8Array;
|
|
14
|
+
created_at: CreatedAtColumn;
|
|
15
|
+
updated_at: UpdatedAtColumn;
|
|
16
|
+
};
|
|
17
|
+
export type Document<Data extends DocumentData = DocumentData> = Selectable<DocumentTable<Data>>;
|
|
18
|
+
export type InsertDocument<Data extends DocumentData = DocumentData> = Insertable<DocumentTable<Data>>;
|
|
19
|
+
export type UpdateDocument<Data extends DocumentData = DocumentData> = Updateable<DocumentTable<Data>>;
|
|
20
|
+
export type DocumentAttachmentTable = {
|
|
21
|
+
id: string;
|
|
22
|
+
data: Uint8Array;
|
|
23
|
+
created_at: CreatedAtColumn;
|
|
24
|
+
};
|
|
25
|
+
export type DocumentAttachment = Selectable<DocumentAttachmentTable>;
|
|
26
|
+
export type InsertDocumentAttachment = Insertable<DocumentAttachmentTable>;
|
|
27
|
+
export type DocumentModelTable = {
|
|
28
|
+
id: string;
|
|
29
|
+
version: string;
|
|
30
|
+
name: string;
|
|
31
|
+
behavior: string;
|
|
32
|
+
unique_fields: JSONValueColumn<Array<string>> | null;
|
|
33
|
+
interfaces: JSONValueColumn<Array<string>>;
|
|
34
|
+
schema: JSONValueColumn<DocumentModelSchema>;
|
|
35
|
+
fields_meta: JSONValueColumn<DocumentFieldsMeta>;
|
|
36
|
+
created_at: CreatedAtColumn;
|
|
37
|
+
updated_at: UpdatedAtColumn;
|
|
38
|
+
};
|
|
39
|
+
export type DocumentModelRow = Selectable<DocumentModelTable>;
|
|
40
|
+
export type InsertDocumentModel = Insertable<DocumentModelTable>;
|
|
41
|
+
export type UpdateDocumentModel = Updateable<DocumentModelTable>;
|
|
42
|
+
export type DocumentModelInterfaceTable = {
|
|
43
|
+
interface_id: string;
|
|
44
|
+
implementation_id: string;
|
|
45
|
+
};
|
|
46
|
+
export type DocumentModelInterface = Selectable<DocumentModelInterfaceTable>;
|
|
47
|
+
export type InsertDocumentModelInterface = Insertable<DocumentModelInterfaceTable>;
|
|
48
|
+
export type SearchConfig = Record<string, {
|
|
49
|
+
fields?: Array<string>;
|
|
50
|
+
}>;
|
|
51
|
+
export type GraphModelTable = {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
aliases: JSONValueColumn<Record<string, string>>;
|
|
55
|
+
search: JSONValueColumn<SearchConfig> | null;
|
|
56
|
+
extension_sdl: string | null;
|
|
57
|
+
plugin_config: JSONValueColumn<Record<string, Record<string, unknown>>> | null;
|
|
58
|
+
created_at: CreatedAtColumn;
|
|
59
|
+
updated_at: UpdatedAtColumn;
|
|
60
|
+
};
|
|
61
|
+
export type GraphModel = Selectable<GraphModelTable>;
|
|
62
|
+
export type InsertGraphModel = Insertable<GraphModelTable>;
|
|
63
|
+
export type UpdateGraphModel = Updateable<GraphModelTable>;
|
|
64
|
+
export type GraphDocumentModelTable = {
|
|
65
|
+
graph_model_id: string;
|
|
66
|
+
document_model_id: string;
|
|
67
|
+
};
|
|
68
|
+
export type GraphDocumentModel = Selectable<GraphDocumentModelTable>;
|
|
69
|
+
export type InsertGraphDocumentModel = Insertable<GraphDocumentModelTable>;
|
|
70
|
+
export type MutationLogTable = {
|
|
71
|
+
mutation_hash: string;
|
|
72
|
+
model_id: string;
|
|
73
|
+
document_id: string;
|
|
74
|
+
author_did: string;
|
|
75
|
+
hlc: string;
|
|
76
|
+
mutation_jwt: string;
|
|
77
|
+
status: string;
|
|
78
|
+
};
|
|
79
|
+
export type MutationLogEntry = Selectable<MutationLogTable>;
|
|
80
|
+
export type InsertMutationLogEntry = Insertable<MutationLogTable>;
|
|
81
|
+
export type ClusterModelTable = {
|
|
82
|
+
model_id: string;
|
|
83
|
+
cluster_id: string;
|
|
84
|
+
cluster_index: number;
|
|
85
|
+
};
|
|
86
|
+
export type ClusterModel = Selectable<ClusterModelTable>;
|
|
87
|
+
export type InsertClusterModel = Insertable<ClusterModelTable>;
|
|
88
|
+
export type ClusterDefinitionTable = {
|
|
89
|
+
id: string;
|
|
90
|
+
definition: JSONValueColumn<Record<string, unknown>>;
|
|
91
|
+
};
|
|
92
|
+
export type ClusterDefinitionRow = Selectable<ClusterDefinitionTable>;
|
|
93
|
+
export type UserModelAccessDefaultTable = {
|
|
94
|
+
owner_did: string;
|
|
95
|
+
model_id: string;
|
|
96
|
+
permission_type: string;
|
|
97
|
+
access_level: string;
|
|
98
|
+
allowed_dids: JSONValueColumn<Array<string>> | null;
|
|
99
|
+
created_at: CreatedAtColumn;
|
|
100
|
+
updated_at: UpdatedAtColumn;
|
|
101
|
+
};
|
|
102
|
+
export type UserModelAccessDefault = Selectable<UserModelAccessDefaultTable>;
|
|
103
|
+
export type InsertUserModelAccessDefault = Insertable<UserModelAccessDefaultTable>;
|
|
104
|
+
export type UpdateUserModelAccessDefault = Updateable<UserModelAccessDefaultTable>;
|
|
105
|
+
export type CatalogTable = {
|
|
106
|
+
id: string;
|
|
107
|
+
owner_did: string;
|
|
108
|
+
name: string;
|
|
109
|
+
description: string;
|
|
110
|
+
filter_criteria: JSONValueColumn<CatalogFilterCriteria>;
|
|
111
|
+
hlc: string;
|
|
112
|
+
created_at: CreatedAtColumn;
|
|
113
|
+
updated_at: UpdatedAtColumn;
|
|
114
|
+
};
|
|
115
|
+
export type Catalog = Selectable<CatalogTable>;
|
|
116
|
+
export type InsertCatalog = Insertable<CatalogTable>;
|
|
117
|
+
export type UpdateCatalog = Updateable<CatalogTable>;
|
|
118
|
+
export type GraphTables = {
|
|
119
|
+
kubun_catalogs: CatalogTable;
|
|
120
|
+
kubun_cluster_models: ClusterModelTable;
|
|
121
|
+
kubun_clusters: ClusterDefinitionTable;
|
|
122
|
+
kubun_document_attachments: DocumentAttachmentTable;
|
|
123
|
+
kubun_document_models: DocumentModelTable;
|
|
124
|
+
kubun_document_model_interfaces: DocumentModelInterfaceTable;
|
|
125
|
+
kubun_graph_document_models: GraphDocumentModelTable;
|
|
126
|
+
kubun_graph_models: GraphModelTable;
|
|
127
|
+
kubun_mutation_log: MutationLogTable;
|
|
128
|
+
kubun_user_model_access_defaults: UserModelAccessDefaultTable;
|
|
129
|
+
[key: `k_${string}`]: DocumentTable;
|
|
130
|
+
};
|
|
131
|
+
export type DocumentParams = {
|
|
132
|
+
id: DocumentID;
|
|
133
|
+
data: DocumentData | null;
|
|
134
|
+
};
|
|
135
|
+
export type CreateDocumentParams = DocumentParams & {
|
|
136
|
+
owner: string;
|
|
137
|
+
unique: Uint8Array;
|
|
138
|
+
};
|
|
139
|
+
export type SaveDocumentParams = DocumentParams & {
|
|
140
|
+
existing: DocumentNode;
|
|
141
|
+
};
|
|
142
|
+
export type CreateGraphParams = {
|
|
143
|
+
aliases?: Record<string, string>;
|
|
144
|
+
extensionSDL?: string;
|
|
145
|
+
id: string;
|
|
146
|
+
name?: string;
|
|
147
|
+
pluginConfig?: Record<string, Record<string, unknown>>;
|
|
148
|
+
record: DocumentModelsRecord;
|
|
149
|
+
search?: SearchConfig;
|
|
150
|
+
};
|
|
151
|
+
export type AddDocumentModelParams = {
|
|
152
|
+
id: string;
|
|
153
|
+
graphModelID: string;
|
|
154
|
+
model: import('@kubun/protocol').DocumentModel;
|
|
155
|
+
};
|
|
156
|
+
export type GraphModelWithRecord = GraphModel & {
|
|
157
|
+
record: DocumentModelsRecord;
|
|
158
|
+
};
|
|
159
|
+
export type ConnectionArguments = {
|
|
160
|
+
before?: string | null;
|
|
161
|
+
after?: string | null;
|
|
162
|
+
first?: number | null;
|
|
163
|
+
last?: number | null;
|
|
164
|
+
};
|
|
165
|
+
export type ListDocumentsParams = {
|
|
166
|
+
modelIDs: Array<string>;
|
|
167
|
+
docIDs: Array<string>;
|
|
168
|
+
};
|
|
169
|
+
export type QueryDocumentsParams = ConnectionArguments & {
|
|
170
|
+
modelIDs: Array<string>;
|
|
171
|
+
filter?: DocumentFilter;
|
|
172
|
+
orderBy?: DocumentOrderBy;
|
|
173
|
+
owner?: string;
|
|
174
|
+
catalogID?: string;
|
|
175
|
+
};
|
|
176
|
+
export type CountDocumentsParams = {
|
|
177
|
+
modelIDs: Array<string>;
|
|
178
|
+
filter?: DocumentFilter;
|
|
179
|
+
owner?: string;
|
|
180
|
+
catalogID?: string;
|
|
181
|
+
};
|
|
182
|
+
export type CursorDocument = {
|
|
183
|
+
cursor: string;
|
|
184
|
+
document: DocumentNode;
|
|
185
|
+
};
|
|
186
|
+
export type QueryDocumentsResult = {
|
|
187
|
+
entries: Array<CursorDocument>;
|
|
188
|
+
hasMore: boolean;
|
|
189
|
+
};
|
|
190
|
+
export type PaginationParams = {
|
|
191
|
+
limit?: number;
|
|
192
|
+
offset?: number;
|
|
193
|
+
};
|
|
194
|
+
export type PaginatedResult<T> = {
|
|
195
|
+
entries: Array<T>;
|
|
196
|
+
hasMore: boolean;
|
|
197
|
+
};
|
|
198
|
+
export type SearchDocumentsParams = {
|
|
199
|
+
query: string;
|
|
200
|
+
modelIDs: Array<string>;
|
|
201
|
+
first?: number;
|
|
202
|
+
after?: string;
|
|
203
|
+
};
|
|
204
|
+
export type SearchDocumentResult = {
|
|
205
|
+
documentID: string;
|
|
206
|
+
modelID: string;
|
|
207
|
+
rank: number;
|
|
208
|
+
};
|
|
209
|
+
export type AccessPermissions = {
|
|
210
|
+
read?: {
|
|
211
|
+
level: 'only_owner' | 'anyone' | 'allowed_dids';
|
|
212
|
+
allowedDIDs?: Array<string>;
|
|
213
|
+
};
|
|
214
|
+
write?: {
|
|
215
|
+
level: 'only_owner' | 'allowed_dids';
|
|
216
|
+
allowedDIDs?: Array<string>;
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
export {};
|
package/lib/tables.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubun/store-graph",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"license": "see LICENSE.md",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"lib/*",
|
|
14
|
+
"LICENSE.md"
|
|
15
|
+
],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@enkaku/codec": "^0.14.0",
|
|
19
|
+
"kysely": "^0.28.16",
|
|
20
|
+
"@kubun/db": "^0.8.1",
|
|
21
|
+
"@kubun/db-adapter": "^0.8.1",
|
|
22
|
+
"@kubun/protocol": "^0.8.0",
|
|
23
|
+
"@kubun/id": "^0.8.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@testcontainers/postgresql": "^11.14.0",
|
|
27
|
+
"@kubun/db-better-sqlite": "^0.8.1",
|
|
28
|
+
"@kubun/db-postgres": "^0.8.1"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build:clean": "del lib",
|
|
32
|
+
"build:js": "swc src -d ./lib --config-file ../../swc.json --strip-leading-paths",
|
|
33
|
+
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
|
|
34
|
+
"build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
|
|
35
|
+
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|
|
36
|
+
"test:types": "tsc --noEmit -p tsconfig.test.json",
|
|
37
|
+
"test:unit": "vitest run",
|
|
38
|
+
"test": "pnpm run test:types && pnpm run test:unit"
|
|
39
|
+
}
|
|
40
|
+
}
|