Skip to content

Commit 5964285

Browse files
committed
Partition custom element documents with namespace
1 parent 4a2e41a commit 5964285

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

packages/catalog-server/src/lib/firestore/firestore-repository.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ export class FirestoreRepository implements Repository {
333333
];
334334

335335
batch.create(customElementsRef.doc(), {
336+
namespace: this.namespace,
336337
package: packageName,
337338
version,
338339
distTags,
@@ -506,6 +507,7 @@ export class FirestoreRepository implements Repository {
506507
.collectionGroup('customElements')
507508
.withConverter(customElementConverter)
508509
.where('isLatest', '==', true)
510+
.where('namespace', '==', this.namespace)
509511
.limit(limit ?? 25);
510512

511513
if (query !== undefined) {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import {
8+
getModule,
9+
Version,
10+
} from '@webcomponents/custom-elements-manifest-tools';
11+
import {
12+
CustomElementDeclaration,
13+
CustomElementExport,
14+
Package,
15+
} from 'custom-elements-manifest';
16+
import {suite} from 'uvu';
17+
import * as assert from 'uvu/assert';
18+
19+
import {FirestoreRepository} from '../../../lib/firestore/firestore-repository.js';
20+
21+
const test = suite('FirestoreRepository tests');
22+
23+
test('Limits element searches to a namespace', async () => {
24+
const manifest: Package = {
25+
schemaVersion: '1.0.0',
26+
readme: 'README.md',
27+
modules: [
28+
{
29+
kind: 'javascript-module',
30+
path: 'foo.js',
31+
exports: [
32+
{
33+
kind: 'custom-element-definition',
34+
name: 'x-foo',
35+
declaration: {
36+
name: 'FooElement',
37+
},
38+
},
39+
],
40+
declarations: [
41+
{
42+
kind: 'class',
43+
customElement: true,
44+
tagName: 'x-foo',
45+
name: 'FooElement',
46+
members: [],
47+
},
48+
],
49+
},
50+
],
51+
};
52+
53+
const module = getModule(manifest, 'foo.js')!;
54+
const customElementExport = module.exports![0] as CustomElementExport;
55+
const customElementDeclaration =
56+
module.declarations![0] as CustomElementDeclaration;
57+
58+
const repo1 = new FirestoreRepository('firestore-repository-test-1');
59+
const repo2 = new FirestoreRepository('firestore-repository-test-2');
60+
61+
const writeElement = async (repo: FirestoreRepository) =>
62+
repo.writeCustomElements(
63+
{name: 'foo', version: '1.0.0', description: 'test package'} as Version,
64+
[
65+
{
66+
package: manifest,
67+
module,
68+
export: customElementExport,
69+
declaration: customElementDeclaration,
70+
declarationReference: customElementExport.declaration,
71+
},
72+
],
73+
['latest'],
74+
'joe'
75+
);
76+
77+
await Promise.all([writeElement(repo1), writeElement(repo2)]);
78+
const [result1, result2] = await Promise.all([
79+
repo1.queryElements({query: 'foo'}),
80+
repo2.queryElements({query: 'foo'}),
81+
]);
82+
assert.equal(result1.length, 1);
83+
assert.equal(result2.length, 1);
84+
});
85+
86+
test.run();

0 commit comments

Comments
 (0)