@orkestrel/server 0.0.1 → 0.0.2
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/dist/src/core/index.cjs +1665 -0
- package/dist/src/core/index.cjs.map +1 -0
- package/dist/src/core/{helpers.d.ts → index.d.cts} +1512 -890
- package/dist/src/core/index.d.ts +1512 -6
- package/dist/src/core/index.js +1 -117
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +19 -959
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/{types.d.ts → index.d.cts} +307 -163
- package/dist/src/server/index.d.ts +307 -4
- package/dist/src/server/index.js +386 -0
- package/dist/src/server/index.js.map +1 -0
- package/package.json +24 -12
- package/dist/src/core/Negotiator.d.ts +0 -32
- package/dist/src/core/constants.d.ts +0 -68
- package/dist/src/core/errors.d.ts +0 -73
- package/dist/src/core/factories.d.ts +0 -21
- package/dist/src/core/types.d.ts +0 -362
- package/dist/src/server/Server.d.ts +0 -63
- package/dist/src/server/factories.d.ts +0 -26
- package/dist/src/server/helpers.d.ts +0 -45
package/dist/src/core/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRecord, isString, parseJSON } from "@orkestrel/contract";
|
|
1
2
|
//#region src/core/constants.ts
|
|
2
3
|
/** Default graceful-stop deadline (ms) the server gives in-flight requests on `stop()`. */
|
|
3
4
|
var DEFAULT_DRAIN_MS = 1e4;
|
|
@@ -169,123 +170,6 @@ var ContentTooLargeError = class extends HTTPError {
|
|
|
169
170
|
function isHTTPError(value) {
|
|
170
171
|
return value instanceof HTTPError;
|
|
171
172
|
}
|
|
172
|
-
Object.freeze([
|
|
173
|
-
"null",
|
|
174
|
-
"boolean",
|
|
175
|
-
"object",
|
|
176
|
-
"array",
|
|
177
|
-
"number",
|
|
178
|
-
"integer",
|
|
179
|
-
"string"
|
|
180
|
-
]);
|
|
181
|
-
/** Determine whether a value is a string. */
|
|
182
|
-
function isString(value) {
|
|
183
|
-
return typeof value === "string";
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Determine whether a value is a non-null object.
|
|
187
|
-
*
|
|
188
|
-
* @remarks
|
|
189
|
-
* `true` for arrays, class instances, plain objects, `Map`, `Set`, etc. — use
|
|
190
|
-
* {@link isRecord} when you need a plain-record check.
|
|
191
|
-
*/
|
|
192
|
-
function isObject(value) {
|
|
193
|
-
return typeof value === "object" && value !== null;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Determine whether a value is a plain record (object literal or null-prototype),
|
|
197
|
-
* not an array or class instance.
|
|
198
|
-
*
|
|
199
|
-
* @remarks
|
|
200
|
-
* Use instead of {@link isObject} to distinguish a plain `{}` /
|
|
201
|
-
* `Object.create(null)` from arrays, `Date`, `Map`, etc. The prototype-chain
|
|
202
|
-
* test is realm-agnostic: rather than comparing against the current realm's
|
|
203
|
-
* `Object.prototype` (which a plain object from another `vm.Context`, iframe,
|
|
204
|
-
* or worker would fail), it accepts any value whose prototype is `null`, OR
|
|
205
|
-
* whose prototype's own prototype is `null` — the shape every plain object
|
|
206
|
-
* has in every realm, since `Object.prototype` itself always sits one step
|
|
207
|
-
* above `null`. Arrays and class instances are still rejected: an array's
|
|
208
|
-
* prototype chain runs through `Array.prototype` before `null`, and a class
|
|
209
|
-
* instance's runs through the class's own prototype. The whole body runs
|
|
210
|
-
* inside `attempt` (AGENTS §14) so a revoked `Proxy` or a hostile
|
|
211
|
-
* `getPrototypeOf` trap cannot escape as a thrown error.
|
|
212
|
-
*/
|
|
213
|
-
function isRecord(value) {
|
|
214
|
-
const outcome = attempt(() => {
|
|
215
|
-
if (!isObject(value) || isArray(value)) return false;
|
|
216
|
-
const prototype = Object.getPrototypeOf(value);
|
|
217
|
-
return prototype === null || Object.getPrototypeOf(prototype) === null;
|
|
218
|
-
});
|
|
219
|
-
return outcome.success && outcome.value;
|
|
220
|
-
}
|
|
221
|
-
/** Determine whether a value is an array. */
|
|
222
|
-
function isArray(value) {
|
|
223
|
-
return Array.isArray(value);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Invoke a callback and capture its outcome as a {@link Result}, never letting
|
|
227
|
-
* a throw escape.
|
|
228
|
-
*
|
|
229
|
-
* @remarks
|
|
230
|
-
* The single sanctioned never-throw boundary for the guards (AGENTS §14). The
|
|
231
|
-
* `whereOf`, `lazyOf`, and `transformOf` combinators invoke caller-supplied
|
|
232
|
-
* callbacks *inside* a guard body, yet a guard must NEVER throw — it returns a
|
|
233
|
-
* `boolean`. This converts a throwing callback into a `Failure` so the
|
|
234
|
-
* surrounding guard can treat it as a non-match instead of propagating the
|
|
235
|
-
* exception, written once and shared rather than copy-pasted as ad-hoc
|
|
236
|
-
* `try`/`catch`.
|
|
237
|
-
*
|
|
238
|
-
* @param callback - The callback to invoke with no arguments
|
|
239
|
-
* @returns A `Success` carrying the return value, or a `Failure` carrying the
|
|
240
|
-
* thrown reason normalised to an `Error`
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* ```ts
|
|
244
|
-
* const outcome = attempt(() => predicate(value))
|
|
245
|
-
* return outcome.success && outcome.value
|
|
246
|
-
* ```
|
|
247
|
-
*/
|
|
248
|
-
function attempt(callback) {
|
|
249
|
-
try {
|
|
250
|
-
return {
|
|
251
|
-
success: true,
|
|
252
|
-
value: callback()
|
|
253
|
-
};
|
|
254
|
-
} catch (reason) {
|
|
255
|
-
if (reason instanceof Error) return {
|
|
256
|
-
success: false,
|
|
257
|
-
error: reason
|
|
258
|
-
};
|
|
259
|
-
let message = "Unknown thrown value";
|
|
260
|
-
try {
|
|
261
|
-
message = String(reason);
|
|
262
|
-
} catch {}
|
|
263
|
-
return {
|
|
264
|
-
success: false,
|
|
265
|
-
error: new Error(message)
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Parse a JSON string, returning `undefined` instead of throwing.
|
|
271
|
-
*
|
|
272
|
-
* @remarks
|
|
273
|
-
* The safe boundary for untrusted JSON text: a malformed string yields
|
|
274
|
-
* `undefined`, never an exception. Returns `unknown` — a successful parse proves
|
|
275
|
-
* nothing about shape, so narrow the result with a guard (or use
|
|
276
|
-
* {@link parseJSONAs}). A large document is not walked here; parsing is shallow
|
|
277
|
-
* and lazy validation is the caller's to compose.
|
|
278
|
-
*
|
|
279
|
-
* @param value - The JSON string to parse
|
|
280
|
-
* @returns The parsed value, or `undefined` when `value` is not valid JSON
|
|
281
|
-
*/
|
|
282
|
-
function parseJSON(value) {
|
|
283
|
-
try {
|
|
284
|
-
return JSON.parse(value);
|
|
285
|
-
} catch {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
173
|
//#endregion
|
|
290
174
|
//#region src/core/helpers.ts
|
|
291
175
|
/**
|