@uniweb/core 0.19.0 → 0.20.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/package.json +4 -3
- package/src/block.js +12 -2
- package/src/datastore.js +146 -19
- package/src/detail-url.js +72 -11
- package/src/entity-store.js +145 -31
- package/src/fetch-config.js +169 -4
- package/src/fetcher-dispatcher.js +12 -0
- package/src/index.js +7 -3
- package/src/page.js +6 -0
- package/src/query-address.js +34 -1
- package/src/route-match.js +153 -18
- package/src/sort.js +116 -0
- package/src/website.js +94 -15
- package/src/request-styles/index.js +0 -59
- package/src/request-styles/json-body.js +0 -117
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* json-body — the framework's general-purpose request style.
|
|
3
|
-
*
|
|
4
|
-
* Ambient default when the site doesn't pick a style. Speaks the
|
|
5
|
-
* framework's own conventions:
|
|
6
|
-
*
|
|
7
|
-
* GET — operators travel as URL params prefixed with underscore:
|
|
8
|
-
* ?_where=<JSON.stringify(predicate)>
|
|
9
|
-
* ?_limit=N
|
|
10
|
-
* ?_sort=field:dir (comma-separated for multi-key)
|
|
11
|
-
* The leading underscore avoids collision with backend-
|
|
12
|
-
* specific query params the author may have included in `url:`.
|
|
13
|
-
*
|
|
14
|
-
* POST — operators merge as top-level keys into an object body,
|
|
15
|
-
* alongside any author-supplied body. Content-Type defaults
|
|
16
|
-
* to `application/json` unless the site set a different one.
|
|
17
|
-
* String POST bodies (rare; typically GraphQL-only) don't
|
|
18
|
-
* receive operator merge — the string is sent as-is.
|
|
19
|
-
*
|
|
20
|
-
* Operator name renames are applied from the `rename:` map passed in
|
|
21
|
-
* context. Shallow substitutions only — `rename: { limit: pageSize }`
|
|
22
|
-
* swaps the wire name `_limit` → `pageSize` on GET, or the body key
|
|
23
|
-
* `limit` → `pageSize` on POST. The operator identity (what `limit`
|
|
24
|
-
* means in the query) does not change.
|
|
25
|
-
*
|
|
26
|
-
* Internal module. Accessed by `default-fetcher.js` via the registry;
|
|
27
|
-
* never imported directly from outside `@uniweb/runtime`.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
export const jsonBody = {
|
|
31
|
-
name: 'json-body',
|
|
32
|
-
|
|
33
|
-
// Which operators this style knows how to push. The effective push set
|
|
34
|
-
// is the intersection of this and the site's `supports:` list.
|
|
35
|
-
canPush: new Set(['where', 'limit', 'sort']),
|
|
36
|
-
|
|
37
|
-
// Default response envelope. null = no wrapper (a plain JSON payload).
|
|
38
|
-
defaultEnvelope: null,
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Encode a request against the json-body conventions.
|
|
42
|
-
*
|
|
43
|
-
* @param {Object} request - The normalized fetch request.
|
|
44
|
-
* @param {Object} ctx
|
|
45
|
-
* @param {'GET'|'POST'} ctx.method - The method the fetcher chose.
|
|
46
|
-
* @param {Set<string>} ctx.pushCandidates - Operators present on the
|
|
47
|
-
* request AND listed in the site's `supports:`. Style may choose to
|
|
48
|
-
* push all, some, or none of these based on what it knows how to
|
|
49
|
-
* express on the wire.
|
|
50
|
-
* @param {Object|null} ctx.rename - Optional { operator → wireName } map.
|
|
51
|
-
* @returns {{
|
|
52
|
-
* queryParams: Array<[string, string]>,
|
|
53
|
-
* bodyMerge: Object|null,
|
|
54
|
-
* pushed: Set<string>,
|
|
55
|
-
* }}
|
|
56
|
-
* queryParams — pairs appended to the URL's query string.
|
|
57
|
-
* bodyMerge — object merged into the POST body, or null.
|
|
58
|
-
* pushed — the operators that actually rode on the wire.
|
|
59
|
-
* Feeds the fetcher's cache-key derivation and
|
|
60
|
-
* runtime-fallback skip.
|
|
61
|
-
*/
|
|
62
|
-
encode(request, { method, pushCandidates, rename }) {
|
|
63
|
-
const pushed = new Set()
|
|
64
|
-
const queryParams = []
|
|
65
|
-
let bodyMerge = null
|
|
66
|
-
|
|
67
|
-
if (method === 'GET') {
|
|
68
|
-
if (pushCandidates.has('where') && request.where !== undefined) {
|
|
69
|
-
queryParams.push([
|
|
70
|
-
wireName('where', '_where', rename),
|
|
71
|
-
JSON.stringify(request.where),
|
|
72
|
-
])
|
|
73
|
-
pushed.add('where')
|
|
74
|
-
}
|
|
75
|
-
if (pushCandidates.has('limit') && request.limit !== undefined) {
|
|
76
|
-
queryParams.push([
|
|
77
|
-
wireName('limit', '_limit', rename),
|
|
78
|
-
String(request.limit),
|
|
79
|
-
])
|
|
80
|
-
pushed.add('limit')
|
|
81
|
-
}
|
|
82
|
-
if (pushCandidates.has('sort') && request.sort !== undefined) {
|
|
83
|
-
queryParams.push([
|
|
84
|
-
wireName('sort', '_sort', rename),
|
|
85
|
-
String(request.sort),
|
|
86
|
-
])
|
|
87
|
-
pushed.add('sort')
|
|
88
|
-
}
|
|
89
|
-
} else if (method === 'POST') {
|
|
90
|
-
const merged = {}
|
|
91
|
-
if (pushCandidates.has('where') && request.where !== undefined) {
|
|
92
|
-
merged[wireName('where', 'where', rename)] = request.where
|
|
93
|
-
pushed.add('where')
|
|
94
|
-
}
|
|
95
|
-
if (pushCandidates.has('limit') && request.limit !== undefined) {
|
|
96
|
-
merged[wireName('limit', 'limit', rename)] = request.limit
|
|
97
|
-
pushed.add('limit')
|
|
98
|
-
}
|
|
99
|
-
if (pushCandidates.has('sort') && request.sort !== undefined) {
|
|
100
|
-
merged[wireName('sort', 'sort', rename)] = request.sort
|
|
101
|
-
pushed.add('sort')
|
|
102
|
-
}
|
|
103
|
-
if (Object.keys(merged).length > 0) bodyMerge = merged
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return { queryParams, bodyMerge, pushed }
|
|
107
|
-
},
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function wireName(operator, defaultWire, rename) {
|
|
111
|
-
if (rename && typeof rename[operator] === 'string' && rename[operator].length > 0) {
|
|
112
|
-
return rename[operator]
|
|
113
|
-
}
|
|
114
|
-
return defaultWire
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export default jsonBody
|