make it two properties

This commit is contained in:
Simon Knott 2025-02-04 09:57:30 +01:00
parent e9276b571d
commit 4e2aaf8049
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
5 changed files with 71 additions and 63 deletions

View file

@ -149,13 +149,15 @@ scheme.IndexedDBDatabase = tObject({
name: tString,
autoIncrement: tBoolean,
keyPath: tOptional(tString),
keyPathArray: tOptional(tType('string[]')),
records: tArray(tObject({
key: tOptional(tString),
value: tString,
})),
indexes: tArray(tObject({
name: tString,
keyPath: tString,
keyPath: tOptional(tString),
keyPathArray: tOptional(tType('string[]')),
multiEntry: tBoolean,
unique: tBoolean,
})),

View file

@ -558,7 +558,8 @@ export abstract class BrowserContext extends SdkObject {
const index = objectStore.index(indexName);
return {
name: index.name,
keyPath: JSON.stringify(index.keyPath),
keyPath: typeof index.keyPath === 'string' ? index.keyPath : undefined,
keyPathArray: Array.isArray(index.keyPath) ? index.keyPath : undefined,
multiEntry: index.multiEntry,
unique: index.unique,
};
@ -569,7 +570,8 @@ export abstract class BrowserContext extends SdkObject {
records: records.filter(Boolean),
indexes,
autoIncrement: objectStore.autoIncrement,
keyPath: objectStore.keyPath === null ? undefined : JSON.stringify(objectStore.keyPath),
keyPath: typeof objectStore.keyPath === 'string' ? objectStore.keyPath : undefined,
keyPathArray: Array.isArray(objectStore.keyPath) ? objectStore.keyPath : undefined,
};
}));
@ -690,9 +692,9 @@ export abstract class BrowserContext extends SdkObject {
openRequest.addEventListener('upgradeneeded', () => {
const db = openRequest.result;
for (const store of dbInfo.stores) {
const objectStore = db.createObjectStore(store.name, { autoIncrement: store.autoIncrement, keyPath: store.keyPath ? JSON.parse(store.keyPath) : undefined });
const objectStore = db.createObjectStore(store.name, { autoIncrement: store.autoIncrement, keyPath: store.keyPathArray ?? store.keyPath });
for (const index of store.indexes)
objectStore.createIndex(index.name, JSON.parse(index.keyPath), { unique: index.unique, multiEntry: index.multiEntry });
objectStore.createIndex(index.name, index.keyPathArray ?? index.keyPath!, { unique: index.unique, multiEntry: index.multiEntry });
}
});
openRequest.addEventListener('success', async () => {

View file

@ -278,13 +278,15 @@ export type IndexedDBDatabase = {
name: string,
autoIncrement: boolean,
keyPath?: string,
keyPathArray?: string[],
records: {
key?: string,
value: string,
}[],
indexes: {
name: string,
keyPath: string,
keyPath?: string,
keyPathArray?: string[],
multiEntry: boolean,
unique: boolean,
}[],

View file

@ -234,7 +234,8 @@ IndexedDBDatabase:
properties:
name: string
autoIncrement: boolean
keyPath: string? # JSON of string | string[]
keyPath: string?
keyPathArray: string[]?
records:
type: array
items:
@ -248,7 +249,8 @@ IndexedDBDatabase:
type: object
properties:
name: string
keyPath: string # JSON of string | string[]
keyPath: string?
keyPathArray: string[]?
multiEntry: boolean
unique: boolean

View file

@ -337,7 +337,7 @@ it('should support IndexedDB', async ({ page, contextFactory }) => {
{
name: 'toDoList',
autoIncrement: false,
keyPath: '"taskTitle"',
keyPath: 'taskTitle',
records: [
{
value: JSON.stringify({
@ -347,53 +347,53 @@ it('should support IndexedDB', async ({ page, contextFactory }) => {
day: '01',
month: 'January',
year: '2025',
notified: 'no'
})
}
notified: 'no',
}),
},
],
indexes: [
{
'name': 'day',
'keyPath': '"day"',
'multiEntry': false,
'unique': false,
name: 'day',
keyPath: 'day',
multiEntry: false,
unique: false,
},
{
'name': 'hours',
'keyPath': '"hours"',
'multiEntry': false,
'unique': false,
name: 'hours',
keyPath: 'hours',
multiEntry: false,
unique: false,
},
{
'name': 'minutes',
'keyPath': '"minutes"',
'multiEntry': false,
'unique': false,
name: 'minutes',
keyPath: 'minutes',
multiEntry: false,
unique: false,
},
{
'name': 'month',
'keyPath': '"month"',
'multiEntry': false,
'unique': false,
name: 'month',
keyPath: 'month',
multiEntry: false,
unique: false,
},
{
'name': 'notified',
'keyPath': '"notified"',
'multiEntry': false,
'unique': false,
name: 'notified',
keyPath: 'notified',
multiEntry: false,
unique: false,
},
{
'name': 'year',
'keyPath': '"year"',
'multiEntry': false,
'unique': false,
name: 'year',
keyPath: 'year',
multiEntry: false,
unique: false,
},
],
},
],
},
],
},
]
}
]
}
]
}
]);
const context = await contextFactory({ storageState });
@ -415,42 +415,42 @@ it('indexedDb firebase acceptance test', async ({ page, contextFactory }) => {
await page.close();
const storageState = await page.context().storageState();
expect(storageState).toEqual({
'cookies': [],
'origins': [
cookies: [],
origins: [
{
'indexedDB': [
indexedDB: [
{
'name': 'firebase-heartbeat-database',
'stores': [
name: 'firebase-heartbeat-database',
stores: [
{
'autoIncrement': false,
'indexes': [],
'name': 'firebase-heartbeat-store',
'records': [],
autoIncrement: false,
indexes: [],
name: 'firebase-heartbeat-store',
records: [],
},
],
'version': 1,
version: 1,
},
{
'name': 'firebaseLocalStorageDb',
'stores': [
name: 'firebaseLocalStorageDb',
stores: [
{
'autoIncrement': false,
'indexes': [],
'keyPath': '"fbase_key"',
'name': 'firebaseLocalStorage',
'records': [
autoIncrement: false,
indexes: [],
keyPath: 'fbase_key',
name: 'firebaseLocalStorage',
records: [
{
'value': expect.any(String),
value: expect.any(String),
},
],
},
],
'version': 1,
version: 1,
},
],
'localStorage': [],
'origin': 'https://fir-ui-demo-84a6c.firebaseapp.com',
localStorage: [],
origin: 'https://fir-ui-demo-84a6c.firebaseapp.com',
},
],
});