@drupflare/spool 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +263 -41
- package/dist/cdn/client.js +1 -1
- package/dist/cdn/manifest.json +7 -7
- package/dist/cdn/spool-sw.js +1 -1
- package/dist/client/entry.js +33 -1
- package/dist/client/register.d.ts +23 -1
- package/dist/client/register.js +53 -7
- package/dist/protocol/config.d.ts +16 -1
- package/dist/protocol/config.js +3 -1
- package/dist/protocol/dataset.d.ts +183 -0
- package/dist/protocol/dataset.js +206 -0
- package/dist/protocol/envelope.d.ts +1 -0
- package/dist/protocol/envelope.js +2 -1
- package/dist/protocol/errors.d.ts +1 -1
- package/dist/protocol/graph.d.ts +23 -4
- package/dist/protocol/graph.js +34 -3
- package/dist/protocol/index.d.ts +3 -0
- package/dist/protocol/index.js +3 -0
- package/dist/protocol/plan.d.ts +100 -0
- package/dist/protocol/plan.js +661 -0
- package/dist/protocol/provision.d.ts +46 -0
- package/dist/protocol/provision.js +38 -0
- package/dist/protocol/query.d.ts +66 -5
- package/dist/protocol/query.js +103 -4
- package/dist/protocol/route.d.ts +6 -2
- package/dist/protocol/route.js +31 -3
- package/dist/protocol/write.d.ts +146 -0
- package/dist/protocol/write.js +101 -0
- package/dist/report/dataset.d.ts +48 -0
- package/dist/report/dataset.js +93 -0
- package/dist/report/derive.d.ts +285 -0
- package/dist/report/derive.js +676 -1
- package/dist/report/economics.d.ts +11 -1
- package/dist/report/economics.js +19 -1
- package/dist/report/index.d.ts +2 -0
- package/dist/report/index.js +2 -0
- package/dist/report/inputs.d.ts +97 -0
- package/dist/report/inputs.js +133 -0
- package/dist/report/institution.d.ts +188 -1
- package/dist/report/institution.js +146 -0
- package/dist/report/loops.d.ts +73 -0
- package/dist/report/loops.js +101 -0
- package/dist/report/measurement.d.ts +1 -1
- package/dist/report/measurement.js +3 -1
- package/dist/report/model.d.ts +2 -0
- package/dist/report/model.js +4 -0
- package/dist/report/thirdparty.d.ts +57 -0
- package/dist/report/thirdparty.js +111 -0
- package/dist/report/trim.d.ts +56 -0
- package/dist/report/trim.js +83 -1
- package/dist/server/dataset.d.ts +48 -0
- package/dist/server/dataset.js +308 -0
- package/dist/server/embedded.d.ts +3 -3
- package/dist/server/embedded.js +3 -3
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +2 -0
- package/dist/server/spool.d.ts +20 -0
- package/dist/server/spool.js +126 -18
- package/dist/server/write.d.ts +27 -0
- package/dist/server/write.js +127 -0
- package/dist/sw/analytics.d.ts +6 -0
- package/dist/sw/analytics.js +14 -0
- package/dist/sw/dataset-sync.d.ts +76 -0
- package/dist/sw/dataset-sync.js +149 -0
- package/dist/sw/dataset.d.ts +91 -0
- package/dist/sw/dataset.js +318 -0
- package/dist/sw/graph/index.d.ts +31 -1
- package/dist/sw/graph/index.js +57 -5
- package/dist/sw/graph/invalidate.d.ts +15 -3
- package/dist/sw/graph/invalidate.js +42 -4
- package/dist/sw/idb.js +78 -9
- package/dist/sw/partition.d.ts +6 -1
- package/dist/sw/partition.js +21 -2
- package/dist/sw/principal-dataset.d.ts +64 -0
- package/dist/sw/principal-dataset.js +254 -0
- package/dist/sw/render.d.ts +7 -2
- package/dist/sw/render.js +19 -5
- package/dist/sw/replica.d.ts +12 -3
- package/dist/sw/replica.js +40 -5
- package/dist/sw/runtime.d.ts +43 -2
- package/dist/sw/runtime.js +340 -24
- package/dist/sw/seal.d.ts +13 -0
- package/dist/sw/seal.js +13 -4
- package/dist/sw/static.d.ts +18 -0
- package/dist/sw/static.js +84 -1
- package/dist/sw/storage.d.ts +51 -1
- package/dist/sw/storage.js +33 -1
- package/dist/sw/write.d.ts +107 -0
- package/dist/sw/write.js +442 -0
- package/package.json +3 -2
package/dist/protocol/graph.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProtocolError } from './errors.js';
|
|
2
|
+
import { DATASET_NAME } from './query.js';
|
|
2
3
|
/** the reference to put in a page's data for record `id` */
|
|
3
4
|
export function recordRef(id) {
|
|
4
5
|
return { $record: id };
|
|
@@ -7,6 +8,20 @@ export function recordRef(id) {
|
|
|
7
8
|
export function projectionRef(id) {
|
|
8
9
|
return { $projection: id };
|
|
9
10
|
}
|
|
11
|
+
/** the reference to put in a page's data for the row `key` of dataset `dataset` */
|
|
12
|
+
export function rowRef(dataset, key) {
|
|
13
|
+
if (!DATASET_NAME.test(dataset) || key === '') {
|
|
14
|
+
bad('a row reference needs a dataset name and a non-empty key');
|
|
15
|
+
}
|
|
16
|
+
return { $row: `${dataset}/${key}` };
|
|
17
|
+
}
|
|
18
|
+
/** splits a row id into its dataset name and key; the name never holds a `/`, so the first one splits */
|
|
19
|
+
export function splitRowId(id) {
|
|
20
|
+
const at = id.indexOf('/');
|
|
21
|
+
if (at < 1 || at === id.length - 1)
|
|
22
|
+
return null;
|
|
23
|
+
return { dataset: id.slice(0, at), key: id.slice(at + 1) };
|
|
24
|
+
}
|
|
10
25
|
function isPlain(value) {
|
|
11
26
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
12
27
|
}
|
|
@@ -18,12 +33,14 @@ export function isRef(value) {
|
|
|
18
33
|
if (keys.length !== 1)
|
|
19
34
|
return false;
|
|
20
35
|
const key = keys[0];
|
|
21
|
-
return (key === '$record' || key === '$projection'
|
|
36
|
+
return ((key === '$record' || key === '$projection' || key === '$row') &&
|
|
37
|
+
typeof value[key] === 'string');
|
|
22
38
|
}
|
|
23
|
-
/** every record and
|
|
39
|
+
/** every record, projection and row id referenced anywhere in `value`, sorted and unique */
|
|
24
40
|
export function collectRefs(value) {
|
|
25
41
|
const records = new Set();
|
|
26
42
|
const projections = new Set();
|
|
43
|
+
const rows = new Set();
|
|
27
44
|
const walk = (node) => {
|
|
28
45
|
if (Array.isArray(node))
|
|
29
46
|
return node.forEach(walk);
|
|
@@ -32,6 +49,8 @@ export function collectRefs(value) {
|
|
|
32
49
|
if (isRef(node)) {
|
|
33
50
|
if ('$record' in node)
|
|
34
51
|
records.add(node.$record);
|
|
52
|
+
else if ('$row' in node)
|
|
53
|
+
rows.add(node.$row);
|
|
35
54
|
else
|
|
36
55
|
projections.add(node.$projection);
|
|
37
56
|
return;
|
|
@@ -39,7 +58,11 @@ export function collectRefs(value) {
|
|
|
39
58
|
Object.values(node).forEach(walk);
|
|
40
59
|
};
|
|
41
60
|
walk(value);
|
|
42
|
-
return {
|
|
61
|
+
return {
|
|
62
|
+
records: [...records].sort(),
|
|
63
|
+
projections: [...projections].sort(),
|
|
64
|
+
...(rows.size > 0 ? { rows: [...rows].sort() } : {})
|
|
65
|
+
};
|
|
43
66
|
}
|
|
44
67
|
/**
|
|
45
68
|
* Replaces every reference in `value` with the record's data or the projection's resolved tree.
|
|
@@ -59,6 +82,13 @@ export function resolveRefs(value, lookup) {
|
|
|
59
82
|
throw new Error(`record ${node.$record} is not stored`);
|
|
60
83
|
return record.data;
|
|
61
84
|
}
|
|
85
|
+
if ('$row' in node) {
|
|
86
|
+
const at = splitRowId(node.$row);
|
|
87
|
+
const row = at ? lookup.row?.(at.dataset, at.key) : undefined;
|
|
88
|
+
if (row === undefined)
|
|
89
|
+
throw new Error(`row ${node.$row} is not held`);
|
|
90
|
+
return row;
|
|
91
|
+
}
|
|
62
92
|
const id = node.$projection;
|
|
63
93
|
if (path.includes(id))
|
|
64
94
|
throw new Error(`projection ${id} reaches itself`);
|
|
@@ -157,6 +187,7 @@ export function createCollector() {
|
|
|
157
187
|
projections.set(id, { data, deps, text: json });
|
|
158
188
|
return projectionRef(id);
|
|
159
189
|
},
|
|
190
|
+
row: rowRef,
|
|
160
191
|
collect(vector) {
|
|
161
192
|
const closure = (id, path) => {
|
|
162
193
|
if (path.includes(id))
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './assembly.js';
|
|
|
3
3
|
export * from './beacon.js';
|
|
4
4
|
export * from './collector.js';
|
|
5
5
|
export * from './config.js';
|
|
6
|
+
export * from './dataset.js';
|
|
6
7
|
export * from './envelope.js';
|
|
7
8
|
export * from './errors.js';
|
|
8
9
|
export * from './graph.js';
|
|
@@ -12,6 +13,7 @@ export * from './manifest.js';
|
|
|
12
13
|
export * from './navigation.js';
|
|
13
14
|
export * from './normalise.js';
|
|
14
15
|
export * from './pattern.js';
|
|
16
|
+
export * from './plan.js';
|
|
15
17
|
export * from './provision.js';
|
|
16
18
|
export * from './query.js';
|
|
17
19
|
export * from './route.js';
|
|
@@ -21,3 +23,4 @@ export * from './template/compile.js';
|
|
|
21
23
|
export * from './template/interpret.js';
|
|
22
24
|
export * from './vector.js';
|
|
23
25
|
export * from './view.js';
|
|
26
|
+
export * from './write.js';
|
package/dist/protocol/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from './assembly.js';
|
|
|
3
3
|
export * from './beacon.js';
|
|
4
4
|
export * from './collector.js';
|
|
5
5
|
export * from './config.js';
|
|
6
|
+
export * from './dataset.js';
|
|
6
7
|
export * from './envelope.js';
|
|
7
8
|
export * from './errors.js';
|
|
8
9
|
export * from './graph.js';
|
|
@@ -12,6 +13,7 @@ export * from './manifest.js';
|
|
|
12
13
|
export * from './navigation.js';
|
|
13
14
|
export * from './normalise.js';
|
|
14
15
|
export * from './pattern.js';
|
|
16
|
+
export * from './plan.js';
|
|
15
17
|
export * from './provision.js';
|
|
16
18
|
export * from './query.js';
|
|
17
19
|
export * from './route.js';
|
|
@@ -21,3 +23,4 @@ export * from './template/compile.js';
|
|
|
21
23
|
export * from './template/interpret.js';
|
|
22
24
|
export * from './vector.js';
|
|
23
25
|
export * from './view.js';
|
|
26
|
+
export * from './write.js';
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { QueryResult, Shaped } from './query.js';
|
|
2
|
+
type Plain = Record<string, unknown>;
|
|
3
|
+
export type PlanOp = 'eq' | 'in' | 'gte' | 'lte' | 'prefix';
|
|
4
|
+
/** one condition of a plan; `param` is the URL parameter that supplies its value */
|
|
5
|
+
export type PlanCondition = {
|
|
6
|
+
/** a base field, or `as.field` of a join */
|
|
7
|
+
field: string;
|
|
8
|
+
op: PlanOp;
|
|
9
|
+
param: string;
|
|
10
|
+
type: 'string' | 'number';
|
|
11
|
+
/** prefix only: ASCII-only lowercasing on both sides, as SQLite's lower() does */
|
|
12
|
+
fold?: 'ascii';
|
|
13
|
+
};
|
|
14
|
+
/** an equi-join from the base row; `on[1]` null matches the right dataset's key */
|
|
15
|
+
export type PlanJoin = {
|
|
16
|
+
dataset: string;
|
|
17
|
+
on: [string, string | null];
|
|
18
|
+
type: 'inner' | 'left';
|
|
19
|
+
/** the joined row's name in the output row */
|
|
20
|
+
as: string;
|
|
21
|
+
/** the right row's fields the plan may read */
|
|
22
|
+
fields: string[];
|
|
23
|
+
};
|
|
24
|
+
export type PlanAggregate = 'count' | {
|
|
25
|
+
count: string;
|
|
26
|
+
} | {
|
|
27
|
+
sum: string;
|
|
28
|
+
} | {
|
|
29
|
+
min: string;
|
|
30
|
+
} | {
|
|
31
|
+
max: string;
|
|
32
|
+
} | {
|
|
33
|
+
avg: string;
|
|
34
|
+
};
|
|
35
|
+
/** a read-only query over held datasets, declared on a route and written in JSON */
|
|
36
|
+
export type QueryPlan = {
|
|
37
|
+
/** base fields the plan may read; the output row carries exactly these */
|
|
38
|
+
from: string[];
|
|
39
|
+
join?: PlanJoin[];
|
|
40
|
+
/** conditions, all ANDed; a condition whose parameter is absent is skipped */
|
|
41
|
+
where?: PlanCondition[];
|
|
42
|
+
group?: {
|
|
43
|
+
by: string[];
|
|
44
|
+
aggregates: Record<string, PlanAggregate>;
|
|
45
|
+
};
|
|
46
|
+
/** fields the `sort` parameter may name; a leading minus in the URL sorts descending */
|
|
47
|
+
sort?: string[];
|
|
48
|
+
pageSize: number;
|
|
49
|
+
/** most result rows (groups or joined rows) the plan answers locally */
|
|
50
|
+
limit: number;
|
|
51
|
+
};
|
|
52
|
+
/** the held rows of one dataset in ascending key order (code point order) */
|
|
53
|
+
export type PlanTable = {
|
|
54
|
+
keys: readonly string[];
|
|
55
|
+
rows: ReadonlyMap<string, Plain>;
|
|
56
|
+
index?: TableIndex;
|
|
57
|
+
};
|
|
58
|
+
/** the base table and a way to reach each joined dataset; undefined when it is not held */
|
|
59
|
+
export type PlanTables = {
|
|
60
|
+
base: PlanTable;
|
|
61
|
+
joined(dataset: string): PlanTable | undefined;
|
|
62
|
+
};
|
|
63
|
+
/** the fewest rows a table holds before its fields are indexed; below it a scan is cheaper */
|
|
64
|
+
export declare const INDEX_MIN_ROWS = 200;
|
|
65
|
+
/** a stored value the engine compares exactly as SQLite does; anything else makes a plan not local */
|
|
66
|
+
export declare function plainValue(value: unknown): boolean;
|
|
67
|
+
/** UTF-8 byte order, which SQLite's BINARY collation uses; UTF-16 unit order differs above U+FFFF */
|
|
68
|
+
export declare function compareText(a: string, b: string): number;
|
|
69
|
+
/**
|
|
70
|
+
* Lazy per-field indexes over one table. Each index is built on first use and is only an
|
|
71
|
+
* optimisation: a plan gives the same answer with or without one.
|
|
72
|
+
*/
|
|
73
|
+
export declare class TableIndex {
|
|
74
|
+
#private;
|
|
75
|
+
constructor(keys: readonly string[], rows: ReadonlyMap<string, Plain>);
|
|
76
|
+
/** how many field indexes have been built */
|
|
77
|
+
get built(): number;
|
|
78
|
+
/** how many entries the built indexes hold, across every field */
|
|
79
|
+
get entries(): number;
|
|
80
|
+
/** whether every row's `field` holds a value {@link plainValue} accepts */
|
|
81
|
+
clean(field: string): boolean;
|
|
82
|
+
/** the keys whose `field` equals one of `values`, ascending */
|
|
83
|
+
equal(field: string, values: readonly (number | string)[]): string[];
|
|
84
|
+
/** the keys whose `field` is at least or at most `value`, within the value's type, ascending */
|
|
85
|
+
range(field: string, op: 'gte' | 'lte', value: number | string): string[];
|
|
86
|
+
/** the keys whose `field` starts with `text`, ascending */
|
|
87
|
+
prefix(field: string, fold: 'ascii' | undefined, text: string): string[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Answers a query string from held tables under `plan`, or returns null when the answer is not
|
|
91
|
+
* local: an unknown or repeated parameter, a value the plan refuses, a float or text in a sum, a
|
|
92
|
+
* table that is not held, a boolean or nested value in a declared field, or more result rows than
|
|
93
|
+
* `limit`. Equal to the SQL the plan describes, row for row.
|
|
94
|
+
*/
|
|
95
|
+
export declare function evaluatePlan(plan: QueryPlan, search: string, tables: PlanTables): QueryResult | null;
|
|
96
|
+
/** the page data for a plan route: the stored data with the rows under `list` and a `query` view */
|
|
97
|
+
export declare function shapePlan(list: string, plan: QueryPlan, data: unknown, search: string, tables: PlanTables | undefined): Shaped;
|
|
98
|
+
/** the validated copy of a plan; throws `bad-route` for a plan the engine could not answer exactly */
|
|
99
|
+
export declare function checkPlan(pattern: string, value: unknown): QueryPlan;
|
|
100
|
+
export {};
|