keyPath string/array matters
This commit is contained in:
parent
625273c2c0
commit
e9276b571d
|
|
@ -148,14 +148,14 @@ scheme.IndexedDBDatabase = tObject({
|
||||||
stores: tArray(tObject({
|
stores: tArray(tObject({
|
||||||
name: tString,
|
name: tString,
|
||||||
autoIncrement: tBoolean,
|
autoIncrement: tBoolean,
|
||||||
keyPath: tOptional(tArray(tString)),
|
keyPath: tOptional(tString),
|
||||||
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: tArray(tString),
|
keyPath: tString,
|
||||||
multiEntry: tBoolean,
|
multiEntry: tBoolean,
|
||||||
unique: tBoolean,
|
unique: tBoolean,
|
||||||
})),
|
})),
|
||||||
|
|
|
||||||
|
|
@ -558,7 +558,7 @@ 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: Array.isArray(index.keyPath) ? index.keyPath : [index.keyPath],
|
keyPath: JSON.stringify(index.keyPath),
|
||||||
multiEntry: index.multiEntry,
|
multiEntry: index.multiEntry,
|
||||||
unique: index.unique,
|
unique: index.unique,
|
||||||
};
|
};
|
||||||
|
|
@ -569,7 +569,7 @@ 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 : (Array.isArray(objectStore.keyPath) ? objectStore.keyPath : [objectStore.keyPath]),
|
keyPath: objectStore.keyPath === null ? undefined : JSON.stringify(objectStore.keyPath),
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
@ -690,9 +690,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 });
|
const objectStore = db.createObjectStore(store.name, { autoIncrement: store.autoIncrement, keyPath: store.keyPath ? JSON.parse(store.keyPath) : undefined });
|
||||||
for (const index of store.indexes)
|
for (const index of store.indexes)
|
||||||
objectStore.createIndex(index.name, index.keyPath, { unique: index.unique, multiEntry: index.multiEntry });
|
objectStore.createIndex(index.name, JSON.parse(index.keyPath), { unique: index.unique, multiEntry: index.multiEntry });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
openRequest.addEventListener('success', async () => {
|
openRequest.addEventListener('success', async () => {
|
||||||
|
|
@ -709,7 +709,6 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
request.addEventListener('error', reject);
|
request.addEventListener('error', reject);
|
||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
transaction.commit();
|
|
||||||
transaction.addEventListener('complete', () => resolve());
|
transaction.addEventListener('complete', () => resolve());
|
||||||
transaction.addEventListener('error', () => reject(transaction.error));
|
transaction.addEventListener('error', () => reject(transaction.error));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
4
packages/protocol/src/channels.d.ts
vendored
4
packages/protocol/src/channels.d.ts
vendored
|
|
@ -277,14 +277,14 @@ export type IndexedDBDatabase = {
|
||||||
stores: {
|
stores: {
|
||||||
name: string,
|
name: string,
|
||||||
autoIncrement: boolean,
|
autoIncrement: boolean,
|
||||||
keyPath?: string[],
|
keyPath?: string,
|
||||||
records: {
|
records: {
|
||||||
key?: string,
|
key?: string,
|
||||||
value: string,
|
value: string,
|
||||||
}[],
|
}[],
|
||||||
indexes: {
|
indexes: {
|
||||||
name: string,
|
name: string,
|
||||||
keyPath: string[],
|
keyPath: string,
|
||||||
multiEntry: boolean,
|
multiEntry: boolean,
|
||||||
unique: boolean,
|
unique: boolean,
|
||||||
}[],
|
}[],
|
||||||
|
|
|
||||||
|
|
@ -234,9 +234,7 @@ IndexedDBDatabase:
|
||||||
properties:
|
properties:
|
||||||
name: string
|
name: string
|
||||||
autoIncrement: boolean
|
autoIncrement: boolean
|
||||||
keyPath:
|
keyPath: string? # JSON of string | string[]
|
||||||
type: array?
|
|
||||||
items: string
|
|
||||||
records:
|
records:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
|
|
@ -250,9 +248,7 @@ IndexedDBDatabase:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
name: string
|
name: string
|
||||||
keyPath:
|
keyPath: string # JSON of string | string[]
|
||||||
type: array
|
|
||||||
items: string
|
|
||||||
multiEntry: boolean
|
multiEntry: boolean
|
||||||
unique: boolean
|
unique: boolean
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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({
|
||||||
|
|
@ -354,37 +354,37 @@ it('should support IndexedDB', async ({ page, contextFactory }) => {
|
||||||
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,
|
||||||
},
|
},
|
||||||
|
|
@ -411,9 +411,7 @@ it('should support IndexedDB', async ({ page, contextFactory }) => {
|
||||||
it('indexedDb firebase acceptance test', async ({ page, contextFactory }) => {
|
it('indexedDb firebase acceptance test', async ({ page, contextFactory }) => {
|
||||||
await page.goto('https://fir-ui-demo-84a6c.firebaseapp.com/');
|
await page.goto('https://fir-ui-demo-84a6c.firebaseapp.com/');
|
||||||
await page.getByText('Continue as guest').click();
|
await page.getByText('Continue as guest').click();
|
||||||
await expect(page.locator('#user-info')).toMatchAriaSnapshot(`
|
await expect(page.getByRole('button', { name: 'Sign Out' })).toBeVisible();
|
||||||
- text: New User
|
|
||||||
`);
|
|
||||||
await page.close();
|
await page.close();
|
||||||
const storageState = await page.context().storageState();
|
const storageState = await page.context().storageState();
|
||||||
expect(storageState).toEqual({
|
expect(storageState).toEqual({
|
||||||
|
|
@ -439,9 +437,7 @@ it('indexedDb firebase acceptance test', async ({ page, contextFactory }) => {
|
||||||
{
|
{
|
||||||
'autoIncrement': false,
|
'autoIncrement': false,
|
||||||
'indexes': [],
|
'indexes': [],
|
||||||
'keyPath': [
|
'keyPath': '"fbase_key"',
|
||||||
'fbase_key',
|
|
||||||
],
|
|
||||||
'name': 'firebaseLocalStorage',
|
'name': 'firebaseLocalStorage',
|
||||||
'records': [
|
'records': [
|
||||||
{
|
{
|
||||||
|
|
@ -462,8 +458,6 @@ it('indexedDb firebase acceptance test', async ({ page, contextFactory }) => {
|
||||||
const recreatedContext = await contextFactory({ storageState });
|
const recreatedContext = await contextFactory({ storageState });
|
||||||
const recreatedPage = await recreatedContext.newPage();
|
const recreatedPage = await recreatedContext.newPage();
|
||||||
await recreatedPage.goto('https://fir-ui-demo-84a6c.firebaseapp.com/');
|
await recreatedPage.goto('https://fir-ui-demo-84a6c.firebaseapp.com/');
|
||||||
|
await expect(recreatedPage.getByRole('button', { name: 'Sign Out' })).toBeVisible();
|
||||||
expect(await recreatedContext.storageState()).toEqual(storageState);
|
expect(await recreatedContext.storageState()).toEqual(storageState);
|
||||||
await expect(recreatedPage.locator('body')).toMatchAriaSnapshot(`
|
|
||||||
- text: New User
|
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue