-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add project settings functionality to MapeoProject #187
Conversation
6ce5568
to
d701a61
Compare
running into a couple of implementation questions that I probably need some help with:
class MapeoManager {
async createProject(value) {
const project = new MapeoProject(...)
await project.$create(value)
return project
}
} Does that seem reasonable, or do I need to approach the design of this a little differently? Or maybe I'm missing an important detail... |
After discussion with Gregor:
|
b5e3aac
to
4288d76
Compare
src/mapeo-project.js
Outdated
// TODO: Use simplified decode export from @mapeo/schema when available | ||
const schemaName = decode(entry.block, { | ||
index: entry.index, | ||
coreKey: entry.key, | ||
}).schemaName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
highlighting that this ideally would be using a more optimal variant of decode, which hasn't been implemented yet at time of writing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed via c6259d2
src/mapeo-project.js
Outdated
await Promise.all([ | ||
indexWriter.batch(otherEntries), | ||
projectSettingsConfig.indexWriter.batch(projectSettingsEntries), | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do i need to do any error catching/handling here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the decode()
function will throw if it encounters a block that it does not know how to decode. These errors should just be ignored for now.
For errors in the indexWriter batch, I think it's ok to not catch them and let them bubble up to the dataStore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed via 6763de9
src/mapeo-project.js
Outdated
|
||
/** | ||
* @param {import('./types.js').ProjectSettings} settings | ||
* @param {string} [versionId] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be string | string[]
? Thought it would be, but then how would that get passed to dataType.getByVersionId
? (which accepts string
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should have a second parameter here. Using this method should always just update the latest e.g.
async $setProjectSettings(settings) {
const { project } = this.#dataTypes
const existing = project.getByDocId(this.#projectId)
if (existing) {
return project.update([ existing.versionId, ...existing.forks ], {
...getValueOf(existing),
...settings
})
} else {
return project[kCreateWithDocId](this.#projectId, {
...settings,
schemaName: 'project'
})
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed via 2cc9d44
src/mapeo-project.js
Outdated
} | ||
|
||
/** | ||
* @returns {Promise<import('@mapeo/schema').Project>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have this returning the entire project document for now, but guessing we'd want less information to surface in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think return Omit<ProjectValue, 'schemaName'>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed via 82563b4
src/mapeo-project.js
Outdated
@@ -124,4 +166,34 @@ export class MapeoProject { | |||
get field() { | |||
return this.#dataTypes.field | |||
} | |||
|
|||
/** | |||
* @param {Omit<import('@mapeo/schema').ProjectValue, 'schemaName'>} settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kind of forgot what defaultPresets
represents - should it also be omitted here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be Partial<Omit<ProjectValue, 'schemaName'>>
default presets is configuration for which presets are shown to the user to select from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think we should modify the schema and consider all properties on projectSettings to be optional, and implement defaults in code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to modify the schema given https://github.com/digidem/mapeo-schema/issues/104?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we allow fields to be undefined
. We just don't allow them to be null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue created: https://github.com/digidem/mapeo-schema/issues/132
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be Partial<Omit<ProjectValue, 'schemaName'>>
addressed via 2cc9d44
const NAMESPACE_SCHEMAS = /** @type {const} */ ({ | ||
data: ['observation'], | ||
config: ['preset', 'field'], | ||
config: ['preset', 'field', 'project'], | ||
auth: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be a comment here explaining what this is used for. took me a bit to figure out I needed to update it to add the project schema
// TODO: Update to use @mapeo/crypto when ready (https://github.com/digidem/mapeo-core-next/issues/171) | ||
this.#projectId = coreManagerOpts.projectKey.toString('hex') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just highlighting this as something that will eventually be updated
* main: (25 commits) add initial implementation of MemberApi (#232) feat: $blobs.getUrl and $blobs.create methods (#184) chore: update manager e2e tests (#237) feat: add capabilities (#231) feat: coreOwnership integration [3/3] (#230) feat: CoreOwnership class w getOwner & getCoreKey [2/3] (#229) feat: handle `coreOwnership` records in `IndexWriter` [1/3] (#214) fix: adjust storage options for MapeoManager and MapeoProject (#235) implement addProject method for MapeoManager class (#215) implement listProjects method for MapeoManager class (#208) feat: expose blobStore.writerDriveId (#219) implement wrapper client containing createProject and getProject methods (#199) add project settings functionality to MapeoProject (#187) feat: Add encode/decode for project keys [3/3] (#203) feat: update protobuf for RPC [2/3] (#202) chore: move protobuf messages into src/generated [1/3] (#201) feat: Add internal `dataType.createWithDocId()` (#192) chore: explicitly set "mode" opt for encryptionKeys column creation (#186) chore: fix linting and type checking (#183) chore: consolidate encryption key columns in projectKeys table (#181) ...
Closes #167
Notes:
$setProjectSettings
and$getProjectSettings
methods (which also make it easier to test the indexing)TODO:
@mapeo/schema
https://github.com/digidem/mapeo-schema/issues/121@mapeo/schema
https://github.com/digidem/mapeo-schema/issues/132@mapeo/crypto
GenerateprojectId
with @mapeo/crypto? #171