Skip to content

Commit

Permalink
Add project, preset, field schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Aug 2, 2023
1 parent ad186ae commit 537ff7a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/schema/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// These schemas are all in a "client" database. There is only one client
// database and it contains information that is shared across all projects on a
// device
import { sqliteTable } from 'drizzle-orm/sqlite-core'
import { dereferencedDocSchemas as schemas } from '@mapeo/schema'
import { jsonSchemaToDrizzleColumns as toColumns } from './schema-to-drizzle.js'

export const projectTable = sqliteTable('project', toColumns(schemas.project))
4 changes: 4 additions & 0 deletions lib/schema/schema.js → lib/schema/project.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// These schemas are all in a "project" database. Each project in Mapeo has an
// independent "project" database.
import { sqliteTable } from 'drizzle-orm/sqlite-core'
import { dereferencedDocSchemas as schemas } from '@mapeo/schema'
import { jsonSchemaToDrizzleColumns as toColumns } from './schema-to-drizzle.js'
Expand All @@ -6,3 +8,5 @@ export const observationTable = sqliteTable(
'observation',
toColumns(schemas.observation)
)
export const presetTable = sqliteTable('preset', toColumns(schemas.preset))
export const fieldTable = sqliteTable('field', toColumns(schemas.field))
1 change: 1 addition & 0 deletions lib/schema/schema-to-drizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Convert a JSONSchema definition to a Drizzle Columns Map (the parameter for
the return type _should_ be correct when using this function. TODO: tests for
the return type of this function.
@template {JSONSchema7WithProps} TSchema
NB: The inline typescript checker often marks this next line as an error, but this seems to be a bug with JSDoc parsing - running `tsc` does not show this as an error.
@template {TSchema extends { properties: { schemaName: { enum: readonly string[] }}} ? TSchema['properties']['schemaName']['enum'][0] extends MapeoDoc['schemaName'] ? TSchema['properties']['schemaName']['enum'][0] : never : never} TSchemaName
@template {Extract<MapeoDoc, TSchemaName>} TObjectType
@param {TSchema} schema
Expand Down

0 comments on commit 537ff7a

Please sign in to comment.