Skip to content

Commit

Permalink
chore!: update to latest schema version
Browse files Browse the repository at this point in the history
This updates `@mapeo/schema` to 3.0.0-next.27. I expect this to be the
final version before `@comapeo/[email protected]`.

This update required several changes:

- Updating dev dependencies of `@mapeo/schema`: `@mapeo/mock-data` and
  `@mapeo/default-config`.

- Removing unused `isInitialProject` from project settings.

- Allowing translation `regionCode`s to be undefined (but not `null`).

- Requiring `deviceType` on device info.
  • Loading branch information
EvanHahn committed Sep 16, 2024
1 parent 745604a commit 042bd46
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ CREATE TABLE `projectSettings` (
`name` text,
`defaultPresets` text,
`configMetadata` text,
`isInitialProject` integer NOT NULL,
`forks` text NOT NULL
);
--> statement-breakpoint
Expand Down
9 changes: 1 addition & 8 deletions drizzle/client/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "5",
"dialect": "sqlite",
"id": "41e23fc3-463e-432a-9a5f-7c20366d6294",
"id": "e75103ab-bbcb-4ca9-a0c4-2d9095b63add",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"localDeviceInfo": {
Expand Down Expand Up @@ -176,13 +176,6 @@
"notNull": false,
"autoincrement": false
},
"isInitialProject": {
"name": "isInitialProject",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"forks": {
"name": "forks",
"type": "text",
Expand Down
4 changes: 2 additions & 2 deletions drizzle/client/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "5",
"when": 1725381616476,
"tag": "0000_chemical_star_brand",
"when": 1726514276007,
"tag": "0000_bumpy_carnage",
"breakpoints": true
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CREATE TABLE `deviceInfo` (
`links` text NOT NULL,
`deleted` integer NOT NULL,
`name` text NOT NULL,
`deviceType` text,
`deviceType` text NOT NULL,
`forks` text NOT NULL
);
--> statement-breakpoint
Expand Down Expand Up @@ -128,7 +128,7 @@ CREATE TABLE `preset` (
`fieldRefs` text NOT NULL,
`iconRef` text,
`terms` text NOT NULL,
`color` text NOT NULL,
`color` text,
`forks` text NOT NULL
);
--> statement-breakpoint
Expand Down Expand Up @@ -186,7 +186,7 @@ CREATE TABLE `translation` (
`docRefType` text NOT NULL,
`propertyRef` text NOT NULL,
`languageCode` text NOT NULL,
`regionCode` text NOT NULL,
`regionCode` text,
`message` text NOT NULL,
`forks` text NOT NULL
);
8 changes: 4 additions & 4 deletions drizzle/project/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "5",
"dialect": "sqlite",
"id": "b06de2c5-6a4c-4578-a8f0-d15f9f20e902",
"id": "597b1fb1-5fe9-4601-abab-9cd02b6a77fe",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"coreOwnership_backlink": {
Expand Down Expand Up @@ -236,7 +236,7 @@
"name": "deviceType",
"type": "text",
"primaryKey": false,
"notNull": false,
"notNull": true,
"autoincrement": false
},
"forks": {
Expand Down Expand Up @@ -770,7 +770,7 @@
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"autoincrement": false
},
"forks": {
Expand Down Expand Up @@ -1104,7 +1104,7 @@
"name": "regionCode",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"autoincrement": false
},
"message": {
Expand Down
4 changes: 2 additions & 2 deletions drizzle/project/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "5",
"when": 1725381611574,
"tag": "0000_tan_glorian",
"when": 1726514275142,
"tag": "0000_spooky_lady_ursula",
"breakpoints": true
}
]
Expand Down
52 changes: 39 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
"homepage": "https://github.com/digidem/mapeo-core#readme",
"devDependencies": {
"@bufbuild/buf": "^1.26.1",
"@mapeo/default-config": "4.0.0-alpha.8",
"@mapeo/mock-data": "^1.0.3-alpha.5",
"@mapeo/default-config": "4.0.1-alpha.0",
"@mapeo/mock-data": "1.0.3-alpha.6",
"@sinonjs/fake-timers": "^10.0.2",
"@types/b4a": "^1.6.0",
"@types/bogon": "^1.0.2",
Expand Down Expand Up @@ -158,7 +158,7 @@
"@fastify/type-provider-typebox": "^4.0.0",
"@hyperswarm/secret-stream": "^6.1.2",
"@mapeo/crypto": "1.0.0-alpha.10",
"@mapeo/schema": "^3.0.0-next.26",
"@mapeo/schema": "3.0.0-next.27",
"@mapeo/sqlite-indexer": "1.0.0-alpha.9",
"@sinclair/typebox": "^0.29.6",
"b4a": "^1.6.3",
Expand Down
13 changes: 8 additions & 5 deletions src/config-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,14 @@ function translationsForLanguage(warnings) {
*
*/
return function* (lang, languageTranslations) {
const { language: languageCode, region: regionCode } = parseBCP47(lang)
const parsed = parseBCP47(lang)
const { language: languageCode } = parsed
if (!languageCode) {
warnings.push(new Error(`invalid translation language ${lang}`))
return
}
let { region: regionCode } = parsed
regionCode ||= undefined
for (const [
schemaNamePlural,
languageTranslationsForDocType,
Expand Down Expand Up @@ -378,7 +381,7 @@ function schemaNamePluralToDocRefType(schemaNamePlural) {
function translationsForDocType(warnings) {
/** @param {Object} opts
* @param {string} opts.languageCode
* @param {string | null | undefined} opts.regionCode
* @param {string | undefined} opts.regionCode
* @param {import('@mapeo/schema').TranslationValue['docRefType']} opts.docRefType
* @param {Record<ValidDocTypes, unknown>} opts.languageTranslationsForDocType
*/
Expand Down Expand Up @@ -413,7 +416,7 @@ function translationForValue(warnings) {
/**
* @param {Object} opts
* @param {string} opts.languageCode
* @param {string | null | undefined} opts.regionCode
* @param {string | undefined} opts.regionCode
* @param {import('@mapeo/schema').TranslationValue['docRefType']} opts.docRefType
* @param {string} opts.docName
* @param {Record<string,unknown>} opts.fieldsToTranslate
Expand All @@ -430,7 +433,7 @@ function translationForValue(warnings) {
/** @type {'translation'} */
schemaName: 'translation',
languageCode,
regionCode: regionCode || '',
regionCode,
docRefType,
propertyRef: '',
message: '',
Expand Down Expand Up @@ -475,7 +478,7 @@ function translateMessageObject(warnings) {
if (
!validate('translation', {
...value,
docRef: { docId: '', versionId: '' },
docRef: { docId: 'placeholder', versionId: 'placeholder' },
})
) {
warnings.push(new Error(`Invalid translation ${value.message}`))
Expand Down
24 changes: 15 additions & 9 deletions src/mapeo-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
/** @import { ProjectSettingsValue as ProjectValue } from '@mapeo/schema' */
/** @import { SetNonNullable } from 'type-fest' */
/** @import { CoreStorage, Namespace } from './types.js' */
/** @import { DeviceInfoParam } from './schema/client.js' */
/** @import { OpenedNoiseStream } from './lib/noise-secret-stream-helpers.js' */

/** @typedef {SetNonNullable<ProjectKeys, 'encryptionKeys'>} ValidatedProjectKeys */
Expand Down Expand Up @@ -351,17 +352,13 @@ export class MapeoManager extends TypedEmitter {
* Create a new project.
* @param {(
* import('type-fest').Simplify<(
* Partial<Pick<ProjectValue, 'name' | 'isInitialProject'>> &
* Partial<Pick<ProjectValue, 'name'>> &
* { configPath?: string }
* )>
* )} [options]
* @returns {Promise<string>} Project public id
*/
async createProject({
name,
configPath = this.#defaultConfigPath,
isInitialProject = false,
} = {}) {
async createProject({ name, configPath = this.#defaultConfigPath } = {}) {
// 1. Create project keypair
const projectKeypair = KeyManager.generateProjectKeypair()

Expand Down Expand Up @@ -406,7 +403,7 @@ export class MapeoManager extends TypedEmitter {
})

// 5. Write project settings to project instance
await project.$setProjectSettings({ name, isInitialProject })
await project.$setProjectSettings({ name })

// 6. Write device info into project
const deviceInfo = this.getDeviceInfo()
Expand Down Expand Up @@ -741,15 +738,24 @@ export class MapeoManager extends TypedEmitter {
}

/**
* @returns {{ deviceId: string } & Partial<import('./schema/client.js').DeviceInfoParam>}
* @returns {(
* {
* deviceId: string;
* deviceType: DeviceInfoParam['deviceType']
* } & Partial<DeviceInfoParam>
* )}
*/
getDeviceInfo() {
const row = this.#db
.select()
.from(localDeviceInfoTable)
.where(eq(localDeviceInfoTable.deviceId, this.#deviceId))
.get()
return { deviceId: this.#deviceId, ...row?.deviceInfo }
return {
deviceId: this.#deviceId,
deviceType: 'device_type_unspecified',
...row?.deviceInfo,
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/mapeo-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ export class MapeoProject extends TypedEmitter {
await projectSettings[kCreateWithDocId](this.#projectId, {
...settings,
schemaName: 'projectSettings',
isInitialProject: Boolean(settings.isInitialProject),
})
)
}
Expand Down
8 changes: 6 additions & 2 deletions test-e2e/device-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ test('write and read deviceInfo', async () => {
deviceId: manager.deviceId,
})

await manager.setDeviceInfo({ name: 'new name' })
await manager.setDeviceInfo({ name: 'new name', deviceType: 'mobile' })
assert.deepEqual(manager.getDeviceInfo(), {
name: 'new name',
deviceType: 'mobile',
deviceId: manager.deviceId,
})
})
Expand Down Expand Up @@ -174,7 +175,10 @@ test('device info sent to peers', async (t) => {
})
)

await managerThatChangesName.setDeviceInfo({ name: 'new name' })
await managerThatChangesName.setDeviceInfo({
name: 'new name',
deviceType: 'mobile',
})

await otherManagersReceivedNameChangePromise
})
Loading

0 comments on commit 042bd46

Please sign in to comment.