@composedb/loader
Advanced tools
Comparing version
@@ -14,6 +14,2 @@ import type { GenesisCommit } from '@ceramicnetwork/common'; | ||
/** | ||
* Create a StreamID from a GenesisCommit. | ||
*/ | ||
export declare function createGenesisID(genesis: GenesisCommit): Promise<StreamID>; | ||
/** | ||
* Create a LoadKey for a deterministic stream. | ||
@@ -20,0 +16,0 @@ */ |
import { ModelInstanceDocument } from '@ceramicnetwork/stream-model-instance'; | ||
import { StreamID } from '@ceramicnetwork/streamid'; | ||
import * as codec from '@ipld/dag-cbor'; | ||
import { CID } from 'multiformats/cid'; | ||
import { sha256 } from 'multiformats/hashes/sha2'; | ||
/** | ||
@@ -26,15 +23,8 @@ * Create a deterministic genesis commit matching the logic unsed internally by ModelInstanceDocument. | ||
/** | ||
* Create a StreamID from a GenesisCommit. | ||
*/ export async function createGenesisID(genesis) { | ||
const bytes = codec.encode(genesis); | ||
const digest = await sha256.digest(bytes); | ||
const cid = CID.createV1(codec.code, digest); | ||
return new StreamID(ModelInstanceDocument.STREAM_TYPE_ID, cid); | ||
} | ||
/** | ||
* Create a LoadKey for a deterministic stream. | ||
*/ export async function createDeterministicKey(meta) { | ||
const genesis = createDeterministicGenesis(meta); | ||
const id = await StreamID.fromGenesis(ModelInstanceDocument.STREAM_TYPE_ID, genesis); | ||
return { | ||
id: await createGenesisID(genesis), | ||
id, | ||
genesis | ||
@@ -41,0 +31,0 @@ }; |
@@ -15,3 +15,4 @@ import { type BaseQuery, type CreateOpts, type LoadOpts, type UpdateOpts } from '@ceramicnetwork/common'; | ||
}; | ||
export type DeterministicLoadOptions = CreateOptions & { | ||
export type DeterministicLoadOptions = CreateOpts & { | ||
ignoreEmpty?: boolean; | ||
onlyIndexed?: boolean; | ||
@@ -18,0 +19,0 @@ }; |
@@ -133,3 +133,3 @@ function _check_private_redeclaration(obj, privateCollection) { | ||
}); | ||
return options.onlyIndexed === false || doc.metadata.shouldIndex !== false ? doc : null; | ||
return (options.onlyIndexed === false || doc.metadata.shouldIndex !== false) && (!options.ignoreEmpty || doc.content != null) ? doc : null; | ||
} | ||
@@ -136,0 +136,0 @@ /** |
{ | ||
"name": "@composedb/loader", | ||
"version": "0.7.0-rc.2", | ||
"version": "0.7.0-rc.3", | ||
"author": "3Box Labs", | ||
@@ -33,5 +33,3 @@ "license": "(Apache-2.0 OR MIT)", | ||
"@ceramicnetwork/streamid": "^5.0.0", | ||
"@ipld/dag-cbor": "^9.2.0", | ||
"dataloader": "^2.2.2", | ||
"multiformats": "^13.1.0" | ||
"dataloader": "^2.2.2" | ||
}, | ||
@@ -41,6 +39,6 @@ "devDependencies": { | ||
"graphql-relay": "^0.10.0", | ||
"@composedb/devtools": "^0.7.0-rc.2", | ||
"@composedb/types": "^0.7.0-rc.2", | ||
"@composedb/test-schemas": "^0.7.0-rc.2", | ||
"jest-environment-composedb": "^0.7.0-rc.2" | ||
"@composedb/devtools": "^0.7.0-rc.3", | ||
"@composedb/types": "^0.7.0-rc.3", | ||
"@composedb/test-schemas": "^0.7.0-rc.3", | ||
"jest-environment-composedb": "^0.7.0-rc.3" | ||
}, | ||
@@ -47,0 +45,0 @@ "jest": { |
3
-40%21317
-2.31%520
-2.44%- Removed
- Removed