Skip to content

Commit a66394b

Browse files
RangerMauveMauve Signweaver
andauthored
feat: Add setting for default archive device value (#1102)
Co-authored-by: Mauve Signweaver <[email protected]>
1 parent 2e4a293 commit a66394b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/mapeo-manager.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export const DEFAULT_FALLBACK_MAP_FILE_PATH = require.resolve(
9090
export const DEFAULT_ONLINE_STYLE_URL =
9191
'https://demotiles.maplibre.org/style.json'
9292

93+
export const DEFAULT_IS_ARCHIVE_DEVICE = true
94+
9395
/**
9496
* @typedef {Omit<import('./local-peers.js').PeerInfo, 'protomux'>} PublicPeerInfo
9597
*/
@@ -123,6 +125,7 @@ export class MapeoManager extends TypedEmitter {
123125
#l
124126
#defaultConfigPath
125127
#makeWebsocket
128+
#defaultIsArchiveDevice
126129

127130
/**
128131
* @param {Object} opts
@@ -136,6 +139,7 @@ export class MapeoManager extends TypedEmitter {
136139
* @param {string} [opts.customMapPath] File path to a locally stored Styled Map Package (SMP).
137140
* @param {string} [opts.fallbackMapPath] File path to a locally stored Styled Map Package (SMP)
138141
* @param {string} [opts.defaultOnlineStyleUrl] URL for an online-hosted StyleJSON asset.
142+
* @param {boolean} [opts.defaultIsArchiveDevice] Whether the node is an archive device by default
139143
* @param {(url: string) => WebSocket} [opts.makeWebsocket]
140144
*/
141145
constructor({
@@ -149,12 +153,14 @@ export class MapeoManager extends TypedEmitter {
149153
customMapPath,
150154
fallbackMapPath = DEFAULT_FALLBACK_MAP_FILE_PATH,
151155
defaultOnlineStyleUrl = DEFAULT_ONLINE_STYLE_URL,
156+
defaultIsArchiveDevice = DEFAULT_IS_ARCHIVE_DEVICE,
152157
makeWebsocket = (url) => new WebSocket(url),
153158
}) {
154159
super()
155160
this.#keyManager = new KeyManager(rootKey)
156161
this.#deviceId = getDeviceId(this.#keyManager)
157162
this.#defaultConfigPath = defaultConfigPath
163+
this.#defaultIsArchiveDevice = defaultIsArchiveDevice
158164
this.#makeWebsocket = makeWebsocket
159165
const logger = (this.#loggerBase = new Logger({ deviceId: this.#deviceId }))
160166
this.#l = Logger.create('manager', logger)
@@ -882,7 +888,7 @@ export class MapeoManager extends TypedEmitter {
882888
if (typeof row?.isArchiveDevice === 'boolean') {
883889
return row.isArchiveDevice
884890
} else {
885-
return true
891+
return this.#defaultIsArchiveDevice
886892
}
887893
}
888894

test-e2e/manager-archive-device.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ test('Set & Get isArchiveDevice', async (t) => {
4141
)
4242
})
4343

44+
test('Default isArchiveDevice', async (t) => {
45+
const manager = createManager('seed', t, {
46+
defaultIsArchiveDevice: false,
47+
})
48+
assert.strictEqual(
49+
manager.getIsArchiveDevice(),
50+
false,
51+
'isArchiveDevice is false initially'
52+
)
53+
54+
// Ensure at least one project exists (tests internal setting on project)
55+
const projectId = await manager.createProject()
56+
const project = await manager.getProject(projectId)
57+
assert.strictEqual(
58+
project[kIsArchiveDevice],
59+
false,
60+
'Project isArchiveDevice is false initially'
61+
)
62+
})
63+
4464
test('isArchiveDevice persists', async (t) => {
4565
const custodian = new ManagerCustodian(t)
4666

0 commit comments

Comments
 (0)