grafserv 0.0.1-0.6 → 0.0.1-0.7

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +206 -0
  3. package/dist/accept.d.ts +8 -0
  4. package/dist/accept.d.ts.map +1 -0
  5. package/dist/accept.js +419 -0
  6. package/dist/accept.js.map +1 -0
  7. package/dist/core/base.d.ts +35 -0
  8. package/dist/core/base.d.ts.map +1 -0
  9. package/dist/core/base.js +381 -0
  10. package/dist/core/base.js.map +1 -0
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +3 -3
  14. package/dist/index.js.map +1 -1
  15. package/dist/interfaces.d.ts +137 -9
  16. package/dist/interfaces.d.ts.map +1 -1
  17. package/dist/interfaces.js +2 -0
  18. package/dist/interfaces.js.map +1 -1
  19. package/dist/mapIterator.d.ts +2 -0
  20. package/dist/mapIterator.d.ts.map +1 -0
  21. package/dist/mapIterator.js +65 -0
  22. package/dist/mapIterator.js.map +1 -0
  23. package/dist/middleware/graphiql.d.ts +3 -3
  24. package/dist/middleware/graphiql.d.ts.map +1 -1
  25. package/dist/middleware/graphiql.js +5 -3
  26. package/dist/middleware/graphiql.js.map +1 -1
  27. package/dist/middleware/graphql.d.ts +8 -3
  28. package/dist/middleware/graphql.d.ts.map +1 -1
  29. package/dist/middleware/graphql.js +317 -21
  30. package/dist/middleware/graphql.js.map +1 -1
  31. package/dist/options.d.ts +13 -0
  32. package/dist/options.d.ts.map +1 -0
  33. package/dist/options.js +21 -0
  34. package/dist/options.js.map +1 -0
  35. package/dist/servers/express/v4/index.d.ts +20 -0
  36. package/dist/servers/express/v4/index.d.ts.map +1 -0
  37. package/dist/servers/express/v4/index.js +43 -0
  38. package/dist/servers/express/v4/index.js.map +1 -0
  39. package/dist/servers/fastify/v4/index.d.ts +21 -0
  40. package/dist/servers/fastify/v4/index.d.ts.map +1 -0
  41. package/dist/servers/fastify/v4/index.js +179 -0
  42. package/dist/servers/fastify/v4/index.js.map +1 -0
  43. package/dist/servers/koa/v2/index.d.ts +21 -0
  44. package/dist/servers/koa/v2/index.d.ts.map +1 -0
  45. package/dist/servers/koa/v2/index.js +110 -0
  46. package/dist/servers/koa/v2/index.js.map +1 -0
  47. package/dist/servers/node/index.d.ts +22 -0
  48. package/dist/servers/node/index.d.ts.map +1 -0
  49. package/dist/servers/node/index.js +173 -0
  50. package/dist/servers/node/index.js.map +1 -0
  51. package/dist/utils.d.ts +16 -0
  52. package/dist/utils.d.ts.map +1 -0
  53. package/dist/utils.js +121 -0
  54. package/dist/utils.js.map +1 -0
  55. package/package.json +28 -5
  56. package/dist/middleware/index.d.ts +0 -12
  57. package/dist/middleware/index.d.ts.map +0 -1
  58. package/dist/middleware/index.js +0 -431
  59. package/dist/middleware/index.js.map +0 -1
  60. package/dist/middleware/interfaces.d.ts +0 -40
  61. package/dist/middleware/interfaces.d.ts.map +0 -1
  62. package/dist/middleware/interfaces.js +0 -3
  63. package/dist/middleware/interfaces.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # grafserv
2
2
 
3
+ ## 0.0.1-0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`9b296ba54`](undefined) - More secure, more compatible, and lots of fixes
8
+ across the monorepo
9
+
10
+ - Updated dependencies [[`9b296ba54`](undefined)]:
11
+ - grafast@0.0.1-0.6
12
+ - ruru@2.0.0-0.5
13
+ - graphile-config@0.0.1-0.2
14
+
3
15
  ## 0.0.1-0.6
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -40,3 +40,209 @@ And please give some love to our featured sponsors 🤩:
40
40
  <em>\* Sponsors the entire Graphile suite</em>
41
41
 
42
42
  <!-- SPONSORS_END -->
43
+
44
+ ## Usage
45
+
46
+ Grafserv supports many different servers, and because each server is different
47
+ each has their own entrypoint, e.g. `grafserv/node` for the Node.js HTTP server
48
+ or `grafserv/express/v4` for Express v4. Generally you import the `grafserv`
49
+ function from the relevant entrypoint for your server of choice and then create
50
+ an instance:
51
+
52
+ ```js
53
+ const instance = grafserv({ schema, preset });
54
+ ```
55
+
56
+ `grafserv` is passed the GraphQL schema to use (if it's available, otherwise
57
+ passing either null or a promise is also acceptable) and a `graphql-config`
58
+ preset - i.e. your configuration.
59
+
60
+ Calling `grafserv` will return an instance; this instance will have a number of
61
+ helpers on it, including helpers specific to integrating it with your framework
62
+ of choice. For servers that operate on a middleware basis this is typically
63
+ `instance.addTo(app)` (which allows registering multiple route handlers), though
64
+ different servers may have different APIs, such as `instance.createHandler()`
65
+ for Node and `instance.createGraphQLHandler()` for Lambda and Next.js.
66
+
67
+ Note: There is little value in Grafserv reimplementing every non-GraphQL concern
68
+ your server may have, so instead it leans on the ecosystem of your chosen server
69
+ to handle things like compression, rate limits, sessions, cookies, etc. For
70
+ example, to compress your responses you'd need to use a module like
71
+ [`compression`](https://expressjs.com/en/resources/middleware/compression.html)
72
+ for Express, [`koa-compress`](https://www.npmjs.com/package/koa-compress) for
73
+ Koa, or [`@fastify/compress`](https://www.npmjs.com/package/@fastify/compress)
74
+ for Fastify.
75
+
76
+ ### instance.release()
77
+
78
+ Releases any resources created by the instance; no further requests should be
79
+ handled (though currently active requests will be allowed to complete).
80
+
81
+ // TODO: consider terminating subscriptions or other long-lived things.
82
+
83
+ ### instance.onRelease(cb)
84
+
85
+ Adds `cb` to the list of callbacks to be called when the server is released;
86
+ useful for releasing resources you created only for the server. Callbacks will
87
+ be called in reverse order that they were added.
88
+
89
+ ### instance.setSchema(newSchema)
90
+
91
+ Replaces the schema to use for future requests (currently active requests are
92
+ unaffected) - this is primarily used for "watch" mode.
93
+
94
+ ### instance.setPreset(newPreset)
95
+
96
+ Replaces the config to use for future requests (currently active requests are
97
+ unaffected) - this is primarily used for "watch" mode. Note that certain
98
+ configuration changes might not be reflected by certain servers until a restart.
99
+
100
+ ### instance.getSchema()
101
+
102
+ Returns either the GraphQL schema that is currently in use, or a promise to the
103
+ same.
104
+
105
+ ### instance.getPreset()
106
+
107
+ Returns the resolved `graphile-config` preset that is currently in use.
108
+
109
+ ## Servers
110
+
111
+ ### Node HTTP server
112
+
113
+ ```js
114
+ import { createServer } from "node:http";
115
+ import { grafserv } from "grafserv/node";
116
+ import preset from "./graphile.config.mjs";
117
+ import schema from "./schema.mjs";
118
+
119
+ // Create a Grafserv instance
120
+ const instance = grafserv({ schema, preset });
121
+
122
+ // Mount the request handler into a new HTTP server
123
+ const server = createServer(instance.createHandler());
124
+
125
+ // Start the Node server
126
+ server.listen(preset.server.port ?? 5678);
127
+ ```
128
+
129
+ ### Express V4
130
+
131
+ ```js
132
+ import express from "express";
133
+ import { grafserv } from "grafserv/express/v4";
134
+ import preset from "./graphile.config.mjs";
135
+ import schema from "./schema.mjs";
136
+
137
+ // Create an express app
138
+ const app = express();
139
+ // (Add any Express middleware you want here.)
140
+
141
+ // Create a Grafserv instance
142
+ const instance = grafserv({ schema, preset });
143
+
144
+ // Add the Grafserv instance's route handlers to the Express app
145
+ instance.addTo(app);
146
+
147
+ // Start the Express server
148
+ app.listen(preset.server.port ?? 5678);
149
+ ```
150
+
151
+ ### Koa V2
152
+
153
+ ```js
154
+ import Koa from "koa";
155
+ import { grafserv } from "grafserv/koa/v2";
156
+ import preset from "./graphile.config.mjs";
157
+ import schema from "./schema.mjs";
158
+
159
+ // Create a Koa app
160
+ const app = new Koa();
161
+ // (Add any Koa middleware you want here.)
162
+
163
+ // Create a Grafserv instance
164
+ const instance = grafserv({ schema, preset });
165
+
166
+ // Add the Grafserv instance's route handlers to the Koa app
167
+ instance.addTo(app);
168
+
169
+ // Start the Koa server
170
+ app.listen(preset.server.port ?? 5678);
171
+ ```
172
+
173
+ ### Fastify V4
174
+
175
+ ```js
176
+ import Fastify from "fastify";
177
+ import { grafserv } from "grafserv/fastify/v4";
178
+ import preset from "./graphile.config.mjs";
179
+ import schema from "./schema.mjs";
180
+
181
+ // Create a Koa app
182
+ const app = Fastify({
183
+ logger: true,
184
+ });
185
+ // (Add any Fastify middleware you want here.)
186
+
187
+ // Create a Grafserv instance
188
+ const instance = grafserv({ schema, preset });
189
+
190
+ // Add the Grafserv instance's route handlers to the Fastify app
191
+ instance.addTo(app);
192
+
193
+ // Start the Fastify server
194
+ app.listen({ port: preset.server.port ?? 5678 }, (err, address) => {
195
+ if (err) throw err;
196
+ console.log(`Server is now listening on ${address}`);
197
+ });
198
+ ```
199
+
200
+ ### Next.js API route
201
+
202
+ Grafserv handles a number of API routes, so you should define one for each of
203
+ the things you care about. It's critical that you ensure that the paths line up
204
+ with those used in the Graphile config, otherwise the assets will not correctly
205
+ be served/referenced, this may cause issues when communicating between [Ruru][]
206
+ and GraphQL.
207
+
208
+ ```js
209
+ // utils/grafserv.mjs
210
+ import { grafserv } from "grafserv/next/v13";
211
+ import preset from "./graphile.config.mjs";
212
+ import schema from "./schema.mjs";
213
+
214
+ // Create a shared Grafserv instance
215
+ export const instance = grafserv({ schema, preset });
216
+ ```
217
+
218
+ ```js
219
+ // pages/api/graphql.mjs
220
+ import { instance } from "../../utils/grafserv.mjs";
221
+
222
+ // Create and export the `/graphql` route handler
223
+ const handler = instance.createGraphQLHandler();
224
+ export default handler;
225
+ ```
226
+
227
+ ```js
228
+ // pages/api/ruru.mjs
229
+ import { instance } from "../../utils/grafserv.mjs";
230
+
231
+ // Create and export the `/ruru` route handler
232
+ const handler = instance.createRuruHandler();
233
+ export default handler;
234
+ ```
235
+
236
+ ### Lambda
237
+
238
+ ```js
239
+ import { grafserv } from "grafserv/lambda";
240
+ import preset from "./graphile.config.mjs";
241
+ import schema from "./schema.mjs";
242
+
243
+ // Create a Grafserv instance
244
+ const instance = grafserv({ schema, preset });
245
+
246
+ // Export a lambda handler for GraphQL
247
+ export const handler = instance.createGraphQLHandler();
248
+ ```
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns a function that returns the (first, if multiple equal matches) type
3
+ * from mediaTypes that best matches the accept query specified by the given
4
+ * `acceptHeader`. If no Accept header is present then the first mediaType will
5
+ * be returned. If no match is possible, `null` will be returned.
6
+ */
7
+ export declare function makeAcceptMatcher(mediaTypes: string[]): (acceptHeader: string | undefined) => string | null;
8
+ //# sourceMappingURL=accept.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accept.d.ts","sourceRoot":"","sources":["../src/accept.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,kBAwBpC,MAAM,GAAG,SAAS,KAC/B,MAAM,GAAG,IAAI,CAmCjB"}
package/dist/accept.js ADDED
@@ -0,0 +1,419 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeAcceptMatcher = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const lru_1 = tslib_1.__importDefault(require("@graphile/lru"));
6
+ /**
7
+ * Returns a function that returns the (first, if multiple equal matches) type
8
+ * from mediaTypes that best matches the accept query specified by the given
9
+ * `acceptHeader`. If no Accept header is present then the first mediaType will
10
+ * be returned. If no match is possible, `null` will be returned.
11
+ */
12
+ function makeAcceptMatcher(mediaTypes) {
13
+ const typeDigests = mediaTypes.map((t) => {
14
+ // TODO: this parsing is super lazy and isn't 100% reliable; e.g. it could
15
+ // be broken by `foo/bar;baz="\\";frog"`. We're only handling values passed
16
+ // by our own code though, and we ain't passing this kind of nonsense.
17
+ const [spec, ...params] = t.split(";");
18
+ const parameters = Object.create(null);
19
+ for (const param of params) {
20
+ const [key, val] = param.split("=");
21
+ parameters[key] = val;
22
+ }
23
+ const [type, subtype] = spec.split("/");
24
+ return {
25
+ type,
26
+ subtype,
27
+ parameters,
28
+ q: 1,
29
+ originalType: t,
30
+ noParams: Object.keys(parameters).length === 0,
31
+ };
32
+ });
33
+ const lru = new lru_1.default({ maxLength: 50 });
34
+ return function preferredAccept(acceptHeader) {
35
+ if (acceptHeader === undefined) {
36
+ return mediaTypes[0];
37
+ }
38
+ const existing = lru.get(acceptHeader);
39
+ if (existing !== undefined) {
40
+ return existing;
41
+ }
42
+ else {
43
+ const specs = parseAccepts(acceptHeader);
44
+ // Find the first spec that matches each, then pick the one with the
45
+ // highest q.
46
+ let bestQ = 0;
47
+ let bestMediaType = null;
48
+ for (const digest of typeDigests) {
49
+ const highestPrecedenceSpecMatch = specs.find((spec) => {
50
+ return ((spec.type === "*" ||
51
+ (spec.type === digest.type &&
52
+ (spec.subtype === "*" || spec.subtype === digest.subtype))) &&
53
+ (spec.noParams ||
54
+ (!digest.noParams &&
55
+ matchesParameters(spec.parameters, digest.parameters))));
56
+ });
57
+ if (highestPrecedenceSpecMatch) {
58
+ if (bestMediaType === null || highestPrecedenceSpecMatch.q > bestQ) {
59
+ bestQ = highestPrecedenceSpecMatch.q;
60
+ bestMediaType = digest.originalType;
61
+ }
62
+ }
63
+ }
64
+ lru.set(acceptHeader, bestMediaType);
65
+ return bestMediaType;
66
+ }
67
+ };
68
+ }
69
+ exports.makeAcceptMatcher = makeAcceptMatcher;
70
+ function matchesParameters(required, given) {
71
+ for (const key in required) {
72
+ if (given[key] !== required[key]) {
73
+ return false;
74
+ }
75
+ }
76
+ return true;
77
+ }
78
+ const SPACE = " ".charCodeAt(0);
79
+ const HORIZONTAL_TAB = "\t".charCodeAt(0);
80
+ const ASTERISK = "*".charCodeAt(0);
81
+ const SLASH = "/".charCodeAt(0);
82
+ const COMMA = ",".charCodeAt(0);
83
+ const SEMICOLON = ";".charCodeAt(0);
84
+ const EQUALS = "=".charCodeAt(0);
85
+ const DOUBLE_QUOTE = '"'.charCodeAt(0);
86
+ const BACKSLASH = "\\".charCodeAt(0);
87
+ /*
88
+ * Whitespace:
89
+ * 9 (tab)
90
+ * 10 (line feed)
91
+ * 11 (vertical tab)
92
+ * 12 (form feed)
93
+ * 13 (carriage return)
94
+ * 32 (space)
95
+ */
96
+ const WHITESPACE_START = 9;
97
+ const WHITESPACE_END = 13;
98
+ /** We're more forgiving in whitespace in most cases */
99
+ function isWhitespace(charCode) {
100
+ return (charCode === SPACE ||
101
+ (charCode >= WHITESPACE_START && charCode <= WHITESPACE_END));
102
+ }
103
+ /** is Optional White Space */
104
+ function isOWS(charCode) {
105
+ return charCode === SPACE || charCode === HORIZONTAL_TAB;
106
+ }
107
+ /*
108
+ "!" / "#" / "$" / "%" / "&" / "'" / "*"
109
+ / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
110
+ / DIGIT / ALPHA
111
+
112
+ 33|35-39|42|43|45-57|65-90|94-122|124|126
113
+
114
+ >=33 && <= 126 && !34|40|41|44|58-64|91-93|123|125
115
+ */
116
+ // Matches ordered from most likely to least likely for content types.
117
+ function isToken(charCode) {
118
+ return (
119
+ // ^_`a-z
120
+ (charCode >= 94 && charCode <= 122) ||
121
+ // symbols and numbers
122
+ (charCode >= 35 &&
123
+ charCode <= 57 &&
124
+ charCode !== 40 &&
125
+ charCode !== 41 &&
126
+ charCode !== 44) ||
127
+ // A-Z
128
+ (charCode >= 65 && charCode <= 90) ||
129
+ // !
130
+ charCode === 33 ||
131
+ // |
132
+ charCode === 124 ||
133
+ // ~
134
+ charCode === 126);
135
+ }
136
+ var State;
137
+ (function (State) {
138
+ State[State["EXPECT_TYPE"] = 0] = "EXPECT_TYPE";
139
+ State[State["CONTINUE_TYPE"] = 1] = "CONTINUE_TYPE";
140
+ State[State["EXPECT_SUBTYPE"] = 2] = "EXPECT_SUBTYPE";
141
+ State[State["CONTINUE_SUBTYPE"] = 3] = "CONTINUE_SUBTYPE";
142
+ State[State["EXPECT_COMMA_OR_SEMICOLON"] = 4] = "EXPECT_COMMA_OR_SEMICOLON";
143
+ State[State["EXPECT_PARAMETER_NAME"] = 5] = "EXPECT_PARAMETER_NAME";
144
+ State[State["CONTINUE_PARAMETER_NAME"] = 6] = "CONTINUE_PARAMETER_NAME";
145
+ State[State["EXPECT_PARAMETER_VALUE"] = 7] = "EXPECT_PARAMETER_VALUE";
146
+ State[State["CONTINUE_PARAMETER_VALUE"] = 8] = "CONTINUE_PARAMETER_VALUE";
147
+ State[State["CONTINUE_QUOTED_PARAMETER_VALUE"] = 9] = "CONTINUE_QUOTED_PARAMETER_VALUE";
148
+ })(State || (State = {}));
149
+ // PERF: we could increase the speed of this significantly by checking the
150
+ // type/subtype against the supported types/subtypes, and if a match is not
151
+ // found then skip `i` right up to the next `,` without adding the entry to
152
+ // `accepts`
153
+ /**
154
+ * Parser based on https://httpwg.org/specs/rfc9110.html#rfc.section.12.5.1
155
+ *
156
+ * @remarks
157
+ *
158
+ * Why must you always write your own parsers, Benjie?
159
+ */
160
+ function parseAccepts(acceptHeader) {
161
+ const accepts = [];
162
+ let state = State.EXPECT_TYPE;
163
+ let currentAccept = null;
164
+ let currentParameterName = "";
165
+ let currentParameterValue = "";
166
+ function next() {
167
+ if (currentAccept.parameters.q) {
168
+ const q = parseFloat(currentAccept.parameters.q);
169
+ if (Number.isNaN(q) || q < 0 || q > 1) {
170
+ throw new Error("q out of range");
171
+ }
172
+ delete currentAccept.parameters.q;
173
+ currentAccept.q = q;
174
+ }
175
+ accepts.push(currentAccept);
176
+ currentAccept = null;
177
+ state = State.EXPECT_TYPE;
178
+ }
179
+ for (let i = 0, l = acceptHeader.length; i < l; i++) {
180
+ const charCode = acceptHeader.charCodeAt(i);
181
+ switch (state) {
182
+ case State.EXPECT_TYPE: {
183
+ if ( /*@__INLINE__*/isWhitespace(charCode)) {
184
+ continue;
185
+ }
186
+ else if (charCode === ASTERISK) {
187
+ // `*/*`
188
+ currentAccept = {
189
+ type: "*",
190
+ subtype: "*",
191
+ q: 1,
192
+ parameters: Object.create(null),
193
+ noParams: true,
194
+ };
195
+ const nextCharCode = acceptHeader.charCodeAt(++i);
196
+ if (nextCharCode !== SLASH) {
197
+ throw new Error("Expected '/' after '*'");
198
+ }
199
+ const nextNextCharCode = acceptHeader.charCodeAt(++i);
200
+ if (nextNextCharCode !== ASTERISK) {
201
+ throw new Error("Expected '*' after '*/'");
202
+ }
203
+ state = State.EXPECT_COMMA_OR_SEMICOLON;
204
+ }
205
+ else if ( /*@__INLINE__*/isToken(charCode)) {
206
+ currentAccept = {
207
+ type: acceptHeader[i],
208
+ subtype: "",
209
+ q: 1,
210
+ parameters: Object.create(null),
211
+ noParams: true,
212
+ };
213
+ state = State.CONTINUE_TYPE;
214
+ }
215
+ else {
216
+ throw new Error(`Unexpected character '${acceptHeader[i]}'`);
217
+ }
218
+ break;
219
+ }
220
+ case State.CONTINUE_TYPE: {
221
+ if (charCode === SLASH) {
222
+ state = State.EXPECT_SUBTYPE;
223
+ }
224
+ else if ( /*@__INLINE__*/isToken(charCode)) {
225
+ currentAccept.type += acceptHeader[i];
226
+ }
227
+ else {
228
+ throw new Error(`Unexpected character '${acceptHeader[i]}'`);
229
+ }
230
+ break;
231
+ }
232
+ case State.EXPECT_SUBTYPE: {
233
+ if (charCode === ASTERISK) {
234
+ currentAccept.subtype = "*";
235
+ state = State.EXPECT_COMMA_OR_SEMICOLON;
236
+ }
237
+ else if ( /*@__INLINE__*/isToken(charCode)) {
238
+ currentAccept.subtype = acceptHeader[i];
239
+ state = State.CONTINUE_SUBTYPE;
240
+ }
241
+ else {
242
+ throw new Error(`Unexpected character '${acceptHeader[i]}'`);
243
+ }
244
+ break;
245
+ }
246
+ case State.CONTINUE_SUBTYPE: {
247
+ if (charCode === SEMICOLON) {
248
+ // Parameters
249
+ state = State.EXPECT_PARAMETER_NAME;
250
+ }
251
+ else if (charCode === COMMA) {
252
+ /*@__INLINE__*/ next();
253
+ }
254
+ else if ( /*@__INLINE__*/isToken(charCode)) {
255
+ currentAccept.subtype += acceptHeader[i];
256
+ }
257
+ else if ( /*@__INLINE__*/isWhitespace(charCode)) {
258
+ state = State.EXPECT_COMMA_OR_SEMICOLON;
259
+ }
260
+ else {
261
+ throw new Error(`Unexpected character '${acceptHeader[i]}'`);
262
+ }
263
+ break;
264
+ }
265
+ case State.EXPECT_COMMA_OR_SEMICOLON: {
266
+ if ( /*@__INLINE__*/isWhitespace(charCode)) {
267
+ continue;
268
+ }
269
+ else if (charCode === SEMICOLON) {
270
+ state = State.EXPECT_PARAMETER_NAME;
271
+ }
272
+ else if (charCode === COMMA) {
273
+ /*@__INLINE__*/ next();
274
+ }
275
+ else {
276
+ throw new Error(`Unexpected character '${acceptHeader[i]}'`);
277
+ }
278
+ break;
279
+ }
280
+ case State.EXPECT_PARAMETER_NAME: {
281
+ if (charCode === SEMICOLON) {
282
+ continue;
283
+ }
284
+ else if (charCode === COMMA) {
285
+ /*@__INLINE__*/ next();
286
+ continue;
287
+ }
288
+ else if ( /*@__INLINE__*/isOWS(charCode)) {
289
+ continue;
290
+ }
291
+ else if ( /*@__INLINE__*/isToken(charCode)) {
292
+ currentParameterName = acceptHeader[i];
293
+ currentParameterValue = "";
294
+ state = State.CONTINUE_PARAMETER_NAME;
295
+ }
296
+ else {
297
+ throw new Error(`Unexpected character '${acceptHeader[i]}'`);
298
+ }
299
+ break;
300
+ }
301
+ case State.CONTINUE_PARAMETER_NAME: {
302
+ if (charCode === EQUALS) {
303
+ state = State.EXPECT_PARAMETER_VALUE;
304
+ /*
305
+ if (currentAccept?.parameters[currentParameterName]) {
306
+ throw new Error("Overriding parameter!");
307
+ }
308
+ */
309
+ // "q" is not a valid parameter name; it's just used for weighting.
310
+ if (currentParameterName !== "q") {
311
+ currentAccept.noParams = false;
312
+ }
313
+ }
314
+ else if ( /*@__INLINE__*/isToken(charCode)) {
315
+ currentParameterName += acceptHeader[i];
316
+ }
317
+ else {
318
+ throw new Error(`Unexpected character '${acceptHeader[i]}'`);
319
+ }
320
+ break;
321
+ }
322
+ case State.EXPECT_PARAMETER_VALUE: {
323
+ if (charCode === DOUBLE_QUOTE) {
324
+ state = State.CONTINUE_QUOTED_PARAMETER_VALUE;
325
+ }
326
+ else if ( /*@__INLINE__*/isToken(charCode)) {
327
+ state = State.CONTINUE_PARAMETER_VALUE;
328
+ currentParameterValue += acceptHeader[i];
329
+ }
330
+ else {
331
+ throw new Error(`Unexpected character '${acceptHeader[i]}'`);
332
+ }
333
+ break;
334
+ }
335
+ case State.CONTINUE_QUOTED_PARAMETER_VALUE: {
336
+ if (charCode === DOUBLE_QUOTE) {
337
+ currentAccept.parameters[currentParameterName] =
338
+ currentParameterValue;
339
+ state = State.EXPECT_COMMA_OR_SEMICOLON;
340
+ }
341
+ else if (charCode === BACKSLASH) {
342
+ const char = acceptHeader[++i];
343
+ if (char === undefined) {
344
+ throw new Error(`Unexpected terminating backslash`);
345
+ }
346
+ // From the spec:
347
+ //
348
+ // > A sender SHOULD NOT generate a quoted-pair in a quoted-string
349
+ // > except where necessary to quote DQUOTE and backslash octets
350
+ // > occurring within that string. A sender SHOULD NOT generate a
351
+ // > quoted-pair in a comment except where necessary to quote
352
+ // > parentheses ["(" and ")"] and backslash octets occurring within
353
+ // > that comment.
354
+ //
355
+ // i.e. this isn't for `\n` and `\t` and similar, those would just
356
+ // come out as "n" and "t" in the output. This is specifically for
357
+ // escaping quote marks, parenthesis, backslashes.
358
+ // TODO: Technically we should respect `quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )`
359
+ currentParameterValue += char;
360
+ }
361
+ else {
362
+ // TODO: Technically we should respect `qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text`
363
+ currentParameterValue += acceptHeader[i];
364
+ }
365
+ break;
366
+ }
367
+ case State.CONTINUE_PARAMETER_VALUE: {
368
+ if (charCode === SEMICOLON) {
369
+ currentAccept.parameters[currentParameterName] =
370
+ currentParameterValue;
371
+ // Parameters
372
+ state = State.EXPECT_PARAMETER_NAME;
373
+ }
374
+ else if (charCode === COMMA) {
375
+ currentAccept.parameters[currentParameterName] =
376
+ currentParameterValue;
377
+ /*@__INLINE__*/ next();
378
+ }
379
+ else if ( /*@__INLINE__*/isToken(charCode)) {
380
+ currentParameterValue += acceptHeader[i];
381
+ }
382
+ else {
383
+ throw new Error(`Unexpected character '${acceptHeader[i]}'`);
384
+ }
385
+ break;
386
+ }
387
+ default: {
388
+ const never = state;
389
+ throw new Error(`Unhandled state '${never}'`);
390
+ }
391
+ }
392
+ }
393
+ if (state !== State.EXPECT_TYPE) {
394
+ /*@__INLINE__*/ next();
395
+ }
396
+ // Sort `accepts` by precedence. Precedence is how accurate the match is:
397
+ // a/b;c=d
398
+ // a/b
399
+ // a/*
400
+ // */*
401
+ const score = (accept) => {
402
+ let val = 0;
403
+ if (accept.type !== "*") {
404
+ val += 1_000;
405
+ }
406
+ if (accept.subtype !== "*") {
407
+ val += 1_000_000;
408
+ }
409
+ val += Object.keys(accept.parameters).length;
410
+ return val;
411
+ };
412
+ accepts.sort((a, z) => {
413
+ const scoreA = score(a);
414
+ const scoreZ = score(z);
415
+ return scoreZ - scoreA;
416
+ });
417
+ return accepts;
418
+ }
419
+ //# sourceMappingURL=accept.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accept.js","sourceRoot":"","sources":["../src/accept.ts"],"names":[],"mappings":";;;;AAAA,gEAAgC;AAEhC;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,UAAoB;IACpD,MAAM,WAAW,GAAiB,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACrD,0EAA0E;QAC1E,2EAA2E;QAC3E,sEAAsE;QACtE,MAAM,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACpC,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;SACvB;QACD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAExC,OAAO;YACL,IAAI;YACJ,OAAO;YAC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