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, name: tString,
autoIncrement: tBoolean, autoIncrement: tBoolean,
keyPath: tOptional(tString), keyPath: tOptional(tString),
keyPathArray: tOptional(tType('string[]')),
records: tArray(tObject({ records: tArray(tObject({
key: tOptional(tString), key: tOptional(tString),
value: tString, value: tString,
})), })),
indexes: tArray(tObject({ indexes: tArray(tObject({
name: tString, name: tString,
keyPath: tString, keyPath: tOptional(tString),
keyPathArray: tOptional(tType('string[]')),
multiEntry: tBoolean, multiEntry: tBoolean,
unique: tBoolean, unique: tBoolean,
})), })),

View file

@ -558,7 +558,8 @@ export abstract class BrowserContext extends SdkObject {
const index = objectStore.index(indexName); const index = objectStore.index(indexName);
return { return {
name: index.name, 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, multiEntry: index.multiEntry,
unique: index.unique, unique: index.unique,
}; };
@ -569,7 +570,8 @@ export abstract class BrowserContext extends SdkObject {
records: records.filter(Boolean), records: records.filter(Boolean),
indexes, indexes,
autoIncrement: objectStore.autoIncrement, 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', () => { openRequest.addEventListener('upgradeneeded', () => {
const db = openRequest.result; const db = openRequest.result;
for (const store of dbInfo.stores) { 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) 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 () => { openRequest.addEventListener('success', async () => {

View file

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

View file

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

View file

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