Project

General

Profile

« Previous | Next » 

Revision 3d6ffa57

Added by koszko over 1 year ago

make resource dependency specifier an object

View differences:

background/indexeddb_files_server.js
62 62
	  .map(s => haketilodb.idb_get(getting.tx, "files", s.sha256));
63 63

  
64 64
    const deps_proms = (definition.dependencies || [])
65
	  .map(dep_id => get_resource_files(getting, dep_id));
65
	  .map(res_ref => get_resource_files(getting, res_ref.identifier));
66 66

  
67 67
    const files = (await Promise.all(file_proms)).map(f => f.contents);
68 68
    getting.files_by_res_id.set(id, files);
......
93 93
	processed.add(id);
94 94

  
95 95
	const ds = (defs_by_res_id.get(id).dependencies || []).reverse();
96
	ds.forEach(dep_id => to_process.push(["start", dep_id]));
96
	ds.forEach(res_ref => to_process.push(["start", res_ref.identifier]));
97 97
    }
98 98

  
99 99
    return files;
background/patterns_query_manager.js
99 99

  
100 100
function register(kind, object) {
101 101
    if (kind === "mappings") {
102
	for (const [pattern, resource] of Object.entries(object.payloads))
102
	for (const [pattern, resource] of Object.entries(object.payloads || {}))
103 103
	    pqt.register(tree, pattern, object.identifier, resource);
104 104
    } else /* if (kind === "blocking") */ {
105 105
	/*
......
120 120
    const old_version = currently_registered.get(change.key);
121 121
    if (old_version !== undefined) {
122 122
	if (kind === "mappings") {
123
	    for (const pattern in old_version.payloads)
123
	    for (const pattern in old_version.payloads || {})
124 124
		pqt.deregister(tree, pattern, change.key);
125 125
	} else /* if (kind === "blocking") */ {
126 126
	    pqt.deregister(tree, change.key, "~allow");
html/install.js
211 211
	delete response.json.api_schema_version;
212 212
	delete response.json.api_schema_revision;
213 213

  
214
	const files = response.json.source_copyright
215
	      .concat(item_type === "resource" ? response.json.scripts : []);
214
	const scripts = item_type === "resource" && response.json.scripts;
215
	const files = response.json.source_copyright.concat(scripts || []);
216 216

  
217 217
	if (item_type === "mapping") {
218
	    for (const res_ref of Object.values(response.json.payloads))
218
	    for (const res_ref of Object.values(response.json.payloads || {}))
219 219
		process_item(work, "resource", res_ref.identifier);
220 220
	} else {
221
	    for (const res_id of (response.json.dependencies || []))
222
		process_item(work, "resource", res_id);
221
	    for (const res_ref of (response.json.dependencies || []))
222
		process_item(work, "resource", res_ref.identifier);
223 223
	}
224 224

  
225 225
	/*
html/item_preview.js
82 82
    preview_object.source_name.innerText = resource.source_name;
83 83

  
84 84
    [...preview_object.dependencies.childNodes].forEach(n => n.remove());
85
    populate_list(preview_object.dependencies, resource.dependencies);
85

  
86
    const deps_refs = resource.dependencies || [];
87
    populate_list(preview_object.dependencies,
88
		  deps_refs.map(res_ref => res_ref.identifier));
86 89

  
87 90
    const link_maker = file_ref => link_cb(preview_object, file_ref);
88 91

  
......
109 112
    preview_object.source_name.innerText = mapping.source_name;
110 113

  
111 114
    [...preview_object.payloads.childNodes].forEach(n => n.remove());
112
    for (const [pattern, payload] of Object.entries(mapping.payloads).sort()) {
115
    const payload_entries = Object.entries(mapping.payloads || {}).sort();
116
    for (const [pattern, payload] of payload_entries) {
113 117
	/* We use a non-breaking space because normal space would be ignored. */
114 118
	const [nbsp, rarrow] = [160, 0x2192].map(n => String.fromCodePoint(n));
115 119
	const texts = [`${pattern}${nbsp}`, `${rarrow}  ${payload.identifier}`];
test/unit/test_indexeddb_files_server.py
41 41
    resource = make_sample_resource(with_files=False)
42 42

  
43 43
    resource['identifier'] = f'res-{n}'
44
    resource['dependencies'] = [f'res-{m}'
44
    resource['dependencies'] = [{'identifier': f'res-{m}'}
45 45
                                for m in range(max(n - 4, 0), n)]
46 46
    resource['scripts'] = [sample_file_ref(f'file_{n}_{i}', sample_files)
47 47
                           for i in range(2)]
......
141 141
        del sample_data_copy['resources']['res-3']
142 142
    elif error == 'circular':
143 143
        res3_defs = sample_data_copy['resources']['res-3'].values()
144
        next(iter(res3_defs))['dependencies'].append('res-8')
144
        next(iter(res3_defs))['dependencies'].append({'identifier': 'res-8'})
145 145

  
146 146
    prepare_test_page(sample_data_copy, execute_in_page)
147 147

  
test/unit/test_item_list.py
38 38
        'version': [2021, 11, 10],
39 39
        'revision': 1,
40 40
        'description': 'greets an apple',
41
        'dependencies': ['hello-message'],
41
        'dependencies': [{'identifier': 'hello-message'}],
42 42
        'scripts': [
43 43
            sample_file_ref('hello.js'),
44 44
            sample_file_ref('bye.js')
test/unit/test_item_preview.py
51 51

  
52 52
    for string in [
53 53
            *filter(lambda v: type(v) is str, sample_resource.values()),
54
            *sample_resource['dependencies'],
54
            *[rr['identifier'] for rr in sample_resource['dependencies']],
55 55
            *[c['file'] for k in ('source_copyright', 'scripts')
56 56
              for c in sample_resource[k]],
57 57
            item_version_string(sample_resource, True)
......
61 61
    sample_resource['identifier'] = 'hellopear'
62 62
    sample_resource['long_name'] = 'Hello Pear'
63 63
    sample_resource['description'] = 'greets a pear'
64
    sample_resource['dependencies'] = ['hello-msg'],
64
    sample_resource['dependencies'] = [{'identifier': 'hello-msg'}]
65 65
    for key in ('scripts', 'source_copyright'):
66 66
        for file_ref in sample_resource[key]:
67 67
            file_ref['file'] = file_ref['file'].replace('.', '_')
test/unit/utils.py
118 118
        'version': [2021, 11, 10],
119 119
        'revision': 1,
120 120
        'description': 'greets an apple',
121
        'dependencies': ['hello-message'],
121
        'dependencies': [{'identifier': 'hello-message'}],
122 122
        'scripts': [
123 123
            sample_file_ref('hello.js'),
124 124
            sample_file_ref('bye.js')
test/world_wide_library.py
127 127
    sample_resource_templates.append({
128 128
        'id_suffix':    ''.join(letters),
129 129
        'files_count':  deps[0],
130
        'dependencies': [f'resource_{l}' for l in letters]
130
        'dependencies': [{'identifier': f'resource_{l}'} for l in letters]
131 131
    })
132 132

  
133 133
suffixes = [srt['id_suffix'] for srt in sample_resource_templates]
134 134
sample_resource_templates.append({
135 135
    'id_suffix':    '-'.join(suffixes),
136 136
    'files_count':  2,
137
    'dependencies': [f'resource_{suffix}' for suffix in suffixes]
137
    'dependencies': [{'identifier': f'resource_{suf}'} for suf in suffixes]
138 138
})
139 139

  
140 140
for i in range(10):

Also available in: Unified diff