Skip to content

Commit

Permalink
Merge branch 'main' of github.com:digidem/comapeo-core into feat/addR…
Browse files Browse the repository at this point in the history
…emoteDetectionAlertDataType
  • Loading branch information
Tomás Ciccola committed Sep 26, 2024
2 parents a7a3ecd + ab66b21 commit b1fad02
Show file tree
Hide file tree
Showing 525 changed files with 112 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ proto/build
!/drizzle/**/*.sql
.eslintcache
docs/api/html/*
tests/fixtures/config/*.zip
test/fixtures/config/*.zip
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/dist/
/drizzle/*/meta/
/src/generated/
/tests/fixtures/
/test/fixtures/
/docs/
/coverage/
/proto/build/
2 changes: 1 addition & 1 deletion benchmarks/datastore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import benchmark from 'nanobench'
import { createDataStore } from '../tests/helpers/datastore.js'
import { createDataStore } from '../test/helpers/datastore.js'

const datastore = await createDataStore({
dataTypes: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "npm-run-all lint test:prettier build:types type test:buildConfigs test:unit test:e2e test:types",
"test:prettier": "prettier --check .",
"test:buildConfigs": "node scripts/build-config-fixtures.js",
"test:unit": "node --test tests/*.js tests/**/*.js",
"test:unit": "node --test",
"test:e2e": "node --test test-e2e/*.js test-e2e/**/*.js",
"test:types": "tsc -p test-types/tsconfig.json",
"build:types": "tsc -p tsconfig.npm.json && cpy 'src/**/*.d.ts' dist",
Expand Down
6 changes: 2 additions & 4 deletions scripts/build-config-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import * as fs from 'node:fs/promises'
import { createWriteStream } from 'node:fs'
import { join, relative } from 'node:path'

const CONFIG_FIXTURES_PATH = new URL(
'../tests/fixtures/config',
import.meta.url
).pathname
const CONFIG_FIXTURES_PATH = new URL('../test/fixtures/config', import.meta.url)
.pathname
const dir = await fs.readdir(CONFIG_FIXTURES_PATH, { withFileTypes: true })
console.log('zipping config fixtures')
for (const fileOrFolder of dir) {
Expand Down
4 changes: 2 additions & 2 deletions src/datastore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The `DataStore` class is an API over a CoreManager namespace, responsible for re

The `DataStore` class is used internally by the [`DataType`](../datatype/) class.

An example of `DataStore` usage taken from the [datastore tests](../../tests/datastore.js):
An example of `DataStore` usage taken from the [datastore tests](../../test/datastore.js):

```js
const datastore = new DataStore({
Expand Down Expand Up @@ -43,4 +43,4 @@ TODO!

## Tests

Tests for this module are in [tests/datastore.js](../../tests/datastore.js)
Tests for this module are in [test/datastore.js](../../test/datastore.js)
2 changes: 1 addition & 1 deletion src/datatype/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ TODO!

## Tests

Tests for this module are in [tests/datatype.js](../../tests/datatype.js)
Tests for this module are in [test/datatype.js](../../test/datatype.js)
24 changes: 24 additions & 0 deletions src/lib/key-by.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Like [`Map.groupBy`][0], but the result's values aren't arrays.
*
* If multiple values resolve to the same key, an error is thrown.
*
* [0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy
*
* @template T
* @template K
* @param {Iterable<T>} items
* @param {(item: T) => K} callbackFn
* @returns {Map<K, T>}
*/
export function keyBy(items, callbackFn) {
/** @type {Map<K, T>} */ const result = new Map()
for (const item of items) {
const key = callbackFn(item)
if (result.has(key)) {
throw new Error(`keyBy found duplicate key ${JSON.stringify(key)}`)
}
result.set(key, item)
}
return result
}
7 changes: 4 additions & 3 deletions src/member-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
projectKeyToId,
projectKeyToProjectInviteId,
} from './utils.js'
import { keyBy } from './lib/key-by.js'
import { abortSignalAny } from './lib/ponyfills.js'
import timingSafeEqual from './lib/timing-safe-equal.js'
import { ROLES, isRoleIdForNewInvite } from './roles.js'
Expand Down Expand Up @@ -279,6 +280,8 @@ export class MemberApi extends TypedEmitter {
this.#dataTypes.deviceInfo.getMany(),
])

const deviceInfoByConfigCoreId = keyBy(allDeviceInfo, ({ docId }) => docId)

return Promise.all(
[...allRoles.entries()].map(async ([deviceId, role]) => {
/** @type {MemberInfo} */
Expand All @@ -290,9 +293,7 @@ export class MemberApi extends TypedEmitter {
'config'
)

const deviceInfo = allDeviceInfo.find(
({ docId }) => docId === configCoreId
)
const deviceInfo = deviceInfoByConfigCoreId.get(configCoreId)

memberInfo.name = deviceInfo?.name
memberInfo.deviceType = deviceInfo?.deviceType
Expand Down
4 changes: 2 additions & 2 deletions test-e2e/config-import.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { createManager } from './utils.js'
import { defaultConfigPath } from '../tests/helpers/default-config.js'
import { defaultConfigPath } from '../test/helpers/default-config.js'

test(' config import - load default config when passed a path to `createProject`', async (t) => {
const manager = createManager('device0', t)
Expand Down Expand Up @@ -78,7 +78,7 @@ test('deletion of data before loading a new config', async (t) => {

// load another config
await project.importConfig({
configPath: './tests/fixtures/config/validConfig.zip',
configPath: './test/fixtures/config/validConfig.zip',
})

// load default config again
Expand Down
8 changes: 4 additions & 4 deletions test-e2e/manager-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import RAM from 'random-access-memory'
import { MapeoManager } from '../src/mapeo-manager.js'
import Fastify from 'fastify'
import { getExpectedConfig } from './utils.js'
import { defaultConfigPath } from '../tests/helpers/default-config.js'
import { defaultConfigPath } from '../test/helpers/default-config.js'
import { kDataTypes } from '../src/mapeo-project.js'
import { hashObject } from '../src/utils.js'

Expand Down Expand Up @@ -133,7 +133,7 @@ test('Consistent loading of config', async (t) => {

const expectedDefault = await getExpectedConfig(defaultConfigPath)
const expectedMinimal = await getExpectedConfig(
'tests/fixtures/config/completeConfig.zip'
'test/fixtures/config/completeConfig.zip'
)
const projectId = await manager.createProject()
const project = await manager.getProject(projectId)
Expand Down Expand Up @@ -173,7 +173,7 @@ test('Consistent loading of config', async (t) => {
)

await t.test('loading non-default config when creating project', async () => {
const configPath = 'tests/fixtures/config/completeConfig.zip'
const configPath = 'test/fixtures/config/completeConfig.zip'
const projectId = await manager.createProject({ configPath })

const project = await manager.getProject(projectId)
Expand Down Expand Up @@ -210,7 +210,7 @@ test('Consistent loading of config', async (t) => {
await t.test(
'load different config and check if correctly loaded',
async () => {
const configPath = 'tests/fixtures/config/completeConfig.zip'
const configPath = 'test/fixtures/config/completeConfig.zip'
await project.importConfig({ configPath })
const projectPresets = await project.preset.getMany()
assert.deepEqual(
Expand Down
6 changes: 3 additions & 3 deletions test-e2e/manager-fastify-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { FastifyController } from '../src/fastify-controller.js'
import { plugin as StaticMapsPlugin } from '../src/fastify-plugins/maps/static-maps.js'
import { plugin as MapServerPlugin } from '../src/fastify-plugins/maps/index.js'
import { plugin as OfflineFallbackMapPlugin } from '../src/fastify-plugins/maps/offline-fallback-map.js'
import { blobMetadata } from '../tests/helpers/blob-store.js'
import { blobMetadata } from '../test/helpers/blob-store.js'

const BLOB_FIXTURES_DIR = fileURLToPath(
new URL('../tests/fixtures/blob-api/', import.meta.url)
new URL('../test/fixtures/blob-api/', import.meta.url)
)

const MAP_FIXTURES_PATH = new URL('../tests/fixtures/maps', import.meta.url)
const MAP_FIXTURES_PATH = new URL('../test/fixtures/maps', import.meta.url)
.pathname

const MAPEO_FALLBACK_MAP_PATH = new URL(
Expand Down
8 changes: 4 additions & 4 deletions test-e2e/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import {
waitForSync,
} from './utils.js'
import { kCoreManager } from '../src/mapeo-project.js'
import { getKeys } from '../tests/helpers/core-manager.js'
import { getKeys } from '../test/helpers/core-manager.js'
import { NAMESPACES, PRESYNC_NAMESPACES } from '../src/constants.js'
import { FastifyController } from '../src/fastify-controller.js'
import { generate } from '@mapeo/mock-data'
import { valueOf } from '../src/utils.js'
import pTimeout from 'p-timeout'
import { BLOCKED_ROLE_ID, COORDINATOR_ROLE_ID } from '../src/roles.js'
import { kSyncState } from '../src/sync/sync-api.js'
import { blobMetadata } from '../tests/helpers/blob-store.js'
import { blobMetadata } from '../test/helpers/blob-store.js'
/** @import { State } from '../src/sync/sync-api.js' */

const SCHEMAS_INITIAL_SYNC = ['preset', 'field']
Expand Down Expand Up @@ -138,7 +138,7 @@ test('syncing blobs', async (t) => {
const [invitorProject, inviteeProject] = projects

const fixturePath = new URL(
'../tests/fixtures/images/02-digidem-logo.jpg',
'../test/fixtures/images/02-digidem-logo.jpg',
import.meta.url
).pathname

Expand Down Expand Up @@ -347,7 +347,7 @@ test('auto-stop', async (t) => {
await clock.tickAsync(9000)

const fixturePath = new URL(
'../tests/fixtures/images/02-digidem-logo.jpg',
'../test/fixtures/images/02-digidem-logo.jpg',
import.meta.url
).pathname
const blob = await invitorProject.$blobs.create(
Expand Down
2 changes: 1 addition & 1 deletion test-e2e/translation-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'node:test'
import assert from 'node:assert/strict'
import { isDefined } from '../src/utils.js'
import { createManagers, ManagerCustodian } from './utils.js'
import { defaultConfigPath } from '../tests/helpers/default-config.js'
import { defaultConfigPath } from '../test/helpers/default-config.js'
import {
fieldsTranslationMap,
fieldTranslations,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b1fad02

Please sign in to comment.