aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--background/indexeddb_files_server.js4
-rw-r--r--background/patterns_query_manager.js4
-rw-r--r--html/install.js10
-rw-r--r--html/item_preview.js8
-rw-r--r--test/unit/test_indexeddb_files_server.py4
-rw-r--r--test/unit/test_item_list.py2
-rw-r--r--test/unit/test_item_preview.py4
-rw-r--r--test/unit/utils.py2
-rw-r--r--test/world_wide_library.py4
9 files changed, 23 insertions, 19 deletions
diff --git a/background/indexeddb_files_server.js b/background/indexeddb_files_server.js
index 0c3f7d8..24fa700 100644
--- a/background/indexeddb_files_server.js
+++ b/background/indexeddb_files_server.js
@@ -62,7 +62,7 @@ async function get_resource_files(getting, id) {
.map(s => haketilodb.idb_get(getting.tx, "files", s.sha256));
const deps_proms = (definition.dependencies || [])
- .map(dep_id => get_resource_files(getting, dep_id));
+ .map(res_ref => get_resource_files(getting, res_ref.identifier));
const files = (await Promise.all(file_proms)).map(f => f.contents);
getting.files_by_res_id.set(id, files);
@@ -93,7 +93,7 @@ function get_files_list(defs_by_res_id, files_by_res_id, root_id) {
processed.add(id);
const ds = (defs_by_res_id.get(id).dependencies || []).reverse();
- ds.forEach(dep_id => to_process.push(["start", dep_id]));
+ ds.forEach(res_ref => to_process.push(["start", res_ref.identifier]));
}
return files;
diff --git a/background/patterns_query_manager.js b/background/patterns_query_manager.js
index 9de9d35..3e2953f 100644
--- a/background/patterns_query_manager.js
+++ b/background/patterns_query_manager.js
@@ -99,7 +99,7 @@ if (this.haketilo_content_script_main)
function register(kind, object) {
if (kind === "mappings") {
- for (const [pattern, resource] of Object.entries(object.payloads))
+ for (const [pattern, resource] of Object.entries(object.payloads || {}))
pqt.register(tree, pattern, object.identifier, resource);
} else /* if (kind === "blocking") */ {
/*
@@ -120,7 +120,7 @@ function changed(kind, change) {
const old_version = currently_registered.get(change.key);
if (old_version !== undefined) {
if (kind === "mappings") {
- for (const pattern in old_version.payloads)
+ for (const pattern in old_version.payloads || {})
pqt.deregister(tree, pattern, change.key);
} else /* if (kind === "blocking") */ {
pqt.deregister(tree, change.key, "~allow");
diff --git a/html/install.js b/html/install.js
index 68033bc..df63626 100644
--- a/html/install.js
+++ b/html/install.js
@@ -211,15 +211,15 @@ function InstallView(tab_id, on_view_show, on_view_hide) {
delete response.json.api_schema_version;
delete response.json.api_schema_revision;
- const files = response.json.source_copyright
- .concat(item_type === "resource" ? response.json.scripts : []);
+ const scripts = item_type === "resource" && response.json.scripts;
+ const files = response.json.source_copyright.concat(scripts || []);
if (item_type === "mapping") {
- for (const res_ref of Object.values(response.json.payloads))
+ for (const res_ref of Object.values(response.json.payloads || {}))
process_item(work, "resource", res_ref.identifier);
} else {
- for (const res_id of (response.json.dependencies || []))
- process_item(work, "resource", res_id);
+ for (const res_ref of (response.json.dependencies || []))
+ process_item(work, "resource", res_ref.identifier);
}
/*
diff --git a/html/item_preview.js b/html/item_preview.js
index bd4fd68..1da9492 100644
--- a/html/item_preview.js
+++ b/html/item_preview.js
@@ -82,7 +82,10 @@ function resource_preview(resource, preview_object, link_cb=make_file_link) {
preview_object.source_name.innerText = resource.source_name;
[...preview_object.dependencies.childNodes].forEach(n => n.remove());
- populate_list(preview_object.dependencies, resource.dependencies);
+
+ const deps_refs = resource.dependencies || [];
+ populate_list(preview_object.dependencies,
+ deps_refs.map(res_ref => res_ref.identifier));
const link_maker = file_ref => link_cb(preview_object, file_ref);
@@ -109,7 +112,8 @@ function mapping_preview(mapping, preview_object, link_cb=make_file_link) {
preview_object.source_name.innerText = mapping.source_name;
[...preview_object.payloads.childNodes].forEach(n => n.remove());
- for (const [pattern, payload] of Object.entries(mapping.payloads).sort()) {
+ const payload_entries = Object.entries(mapping.payloads || {}).sort();
+ for (const [pattern, payload] of payload_entries) {
/* We use a non-breaking space because normal space would be ignored. */
const [nbsp, rarrow] = [160, 0x2192].map(n => String.fromCodePoint(n));
const texts = [`${pattern}${nbsp}`, `${rarrow} ${payload.identifier}`];
diff --git a/test/unit/test_indexeddb_files_server.py b/test/unit/test_indexeddb_files_server.py
index 390bbe7..d320eba 100644
--- a/test/unit/test_indexeddb_files_server.py
+++ b/test/unit/test_indexeddb_files_server.py
@@ -41,7 +41,7 @@ def make_sample_resource_with_deps(n):
resource = make_sample_resource(with_files=False)
resource['identifier'] = f'res-{n}'
- resource['dependencies'] = [f'res-{m}'
+ resource['dependencies'] = [{'identifier': f'res-{m}'}
for m in range(max(n - 4, 0), n)]
resource['scripts'] = [sample_file_ref(f'file_{n}_{i}', sample_files)
for i in range(2)]
@@ -141,7 +141,7 @@ def test_indexeddb_files_server_errors(driver, execute_in_page, error):
del sample_data_copy['resources']['res-3']
elif error == 'circular':
res3_defs = sample_data_copy['resources']['res-3'].values()
- next(iter(res3_defs))['dependencies'].append('res-8')
+ next(iter(res3_defs))['dependencies'].append({'identifier': 'res-8'})
prepare_test_page(sample_data_copy, execute_in_page)
diff --git a/test/unit/test_item_list.py b/test/unit/test_item_list.py
index 46691c3..189646e 100644
--- a/test/unit/test_item_list.py
+++ b/test/unit/test_item_list.py
@@ -38,7 +38,7 @@ def make_sample_resource(identifier, long_name):
'version': [2021, 11, 10],
'revision': 1,
'description': 'greets an apple',
- 'dependencies': ['hello-message'],
+ 'dependencies': [{'identifier': 'hello-message'}],
'scripts': [
sample_file_ref('hello.js'),
sample_file_ref('bye.js')
diff --git a/test/unit/test_item_preview.py b/test/unit/test_item_preview.py
index 8787d5d..c715d75 100644
--- a/test/unit/test_item_preview.py
+++ b/test/unit/test_item_preview.py
@@ -51,7 +51,7 @@ def test_resource_preview(driver, execute_in_page):
for string in [
*filter(lambda v: type(v) is str, sample_resource.values()),
- *sample_resource['dependencies'],
+ *[rr['identifier'] for rr in sample_resource['dependencies']],
*[c['file'] for k in ('source_copyright', 'scripts')
for c in sample_resource[k]],
item_version_string(sample_resource, True)
@@ -61,7 +61,7 @@ def test_resource_preview(driver, execute_in_page):
sample_resource['identifier'] = 'hellopear'
sample_resource['long_name'] = 'Hello Pear'
sample_resource['description'] = 'greets a pear'
- sample_resource['dependencies'] = ['hello-msg'],
+ sample_resource['dependencies'] = [{'identifier': 'hello-msg'}]
for key in ('scripts', 'source_copyright'):
for file_ref in sample_resource[key]:
file_ref['file'] = file_ref['file'].replace('.', '_')
diff --git a/test/unit/utils.py b/test/unit/utils.py
index 85dee63..04a4d97 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -118,7 +118,7 @@ def make_sample_resource(with_files=True):
'version': [2021, 11, 10],
'revision': 1,
'description': 'greets an apple',
- 'dependencies': ['hello-message'],
+ 'dependencies': [{'identifier': 'hello-message'}],
'scripts': [
sample_file_ref('hello.js'),
sample_file_ref('bye.js')
diff --git a/test/world_wide_library.py b/test/world_wide_library.py
index 04f5e8b..56af35f 100644
--- a/test/world_wide_library.py
+++ b/test/world_wide_library.py
@@ -127,14 +127,14 @@ for deps in [(0, 1, 2, 3), (3, 4, 5, 6), (6, 7, 8, 9)]:
sample_resource_templates.append({
'id_suffix': ''.join(letters),
'files_count': deps[0],
- 'dependencies': [f'resource_{l}' for l in letters]
+ 'dependencies': [{'identifier': f'resource_{l}'} for l in letters]
})
suffixes = [srt['id_suffix'] for srt in sample_resource_templates]
sample_resource_templates.append({
'id_suffix': '-'.join(suffixes),
'files_count': 2,
- 'dependencies': [f'resource_{suffix}' for suffix in suffixes]
+ 'dependencies': [{'identifier': f'resource_{suf}'} for suf in suffixes]
})
for i in range(10):