oc 0.50.57-beta.2 → 0.50.57
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/.turbo/turbo-build.log +18 -16
- package/.turbo/turbo-test-silent.log +30 -28
- package/CHANGELOG.md +0 -6
- package/dist/cli/facade/dev.d.ts +140 -2
- package/dist/components/oc-client/_package/package.json +38 -1
- package/dist/components/oc-client/_package/src/oc-client.js +19 -14
- package/dist/components/oc-client/_package/src/oc-client.min.js +1 -1
- package/dist/components/oc-client/_package/src/oc-client.min.map +1 -1
- package/dist/components/oc-client/src/oc-client.js +19 -14
- package/dist/components/oc-client/src/oc-client.min.js +1 -1
- package/dist/components/oc-client/src/oc-client.min.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/registry/domain/extract-package.d.ts +2 -3
- package/dist/registry/domain/options-sanitiser.d.ts +2 -3
- package/dist/registry/domain/options-sanitiser.js +0 -13
- package/dist/registry/domain/validators/uploaded-package.d.ts +4 -5
- package/dist/registry/index.d.ts +68 -10
- package/dist/registry/index.js +16 -14
- package/dist/registry/middleware/base-url-handler.d.ts +2 -3
- package/dist/registry/middleware/base-url-handler.js +4 -3
- package/dist/registry/middleware/compression.d.ts +2 -2
- package/dist/registry/middleware/compression.js +1 -1
- package/dist/registry/middleware/cors.d.ts +2 -3
- package/dist/registry/middleware/cors.js +8 -7
- package/dist/registry/middleware/discovery-handler.d.ts +2 -3
- package/dist/registry/middleware/discovery-handler.js +4 -3
- package/dist/registry/middleware/file-uploads.d.ts +2 -0
- package/dist/registry/middleware/file-uploads.js +23 -0
- package/dist/registry/middleware/index.d.ts +2 -2
- package/dist/registry/middleware/index.js +36 -39
- package/dist/registry/middleware/request-handler.d.ts +2 -0
- package/dist/registry/middleware/request-handler.js +30 -0
- package/dist/registry/router.d.ts +2 -2
- package/dist/registry/router.js +27 -33
- package/dist/registry/routes/component-info.d.ts +2 -2
- package/dist/registry/routes/component-info.js +1 -1
- package/dist/registry/routes/component-preview.d.ts +2 -2
- package/dist/registry/routes/component.d.ts +2 -2
- package/dist/registry/routes/component.js +5 -3
- package/dist/registry/routes/components.d.ts +2 -2
- package/dist/registry/routes/components.js +1 -3
- package/dist/registry/routes/dependencies.d.ts +2 -2
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +3 -3
- package/dist/registry/routes/helpers/get-component.d.ts +1 -1
- package/dist/registry/routes/history.d.ts +2 -2
- package/dist/registry/routes/history.js +1 -1
- package/dist/registry/routes/index.d.ts +2 -2
- package/dist/registry/routes/plugins.d.ts +2 -2
- package/dist/registry/routes/publish.d.ts +2 -2
- package/dist/registry/routes/static-redirector.d.ts +2 -3
- package/dist/registry/routes/static-redirector.js +12 -8
- package/dist/registry/routes/validate.d.ts +2 -2
- package/dist/types.d.ts +1 -9
- package/package.json +5 -5
- package/dist/registry/domain/http-server/express-adapter.d.ts +0 -3
- package/dist/registry/domain/http-server/express-adapter.js +0 -196
- package/dist/registry/domain/http-server/types.d.ts +0 -108
- package/dist/registry/domain/http-server/types.js +0 -2
- package/dist/registry/domain/server-adapter.d.ts +0 -4
- package/dist/registry/domain/server-adapter.js +0 -20
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = createExpressAdapter;
|
|
7
|
-
const node_http_1 = __importDefault(require("node:http"));
|
|
8
|
-
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
9
|
-
const errorhandler_1 = __importDefault(require("errorhandler"));
|
|
10
|
-
const express_1 = __importDefault(require("express"));
|
|
11
|
-
const morgan_1 = __importDefault(require("morgan"));
|
|
12
|
-
const multer_1 = __importDefault(require("multer"));
|
|
13
|
-
const response_time_1 = __importDefault(require("response-time"));
|
|
14
|
-
const expressMiddleware = Symbol('expressMiddleware');
|
|
15
|
-
const ocResponseSym = Symbol('ocResponse');
|
|
16
|
-
const ocParamsSym = Symbol('ocParams');
|
|
17
|
-
function stream(readable) {
|
|
18
|
-
readable.pipe(this.raw);
|
|
19
|
-
}
|
|
20
|
-
function normaliseParams(raw) {
|
|
21
|
-
const params = { ...raw };
|
|
22
|
-
const splat = raw['splat'];
|
|
23
|
-
if (Array.isArray(splat)) {
|
|
24
|
-
params['splat'] = splat.join('/');
|
|
25
|
-
}
|
|
26
|
-
return params;
|
|
27
|
-
}
|
|
28
|
-
function createExpressAdapter(options) {
|
|
29
|
-
const adapterOptions = options;
|
|
30
|
-
return new ExpressHttpServerAdapter(typeof adapterOptions === 'object' ? adapterOptions.port : adapterOptions);
|
|
31
|
-
}
|
|
32
|
-
class ExpressHttpServerAdapter {
|
|
33
|
-
name = 'express';
|
|
34
|
-
app;
|
|
35
|
-
server;
|
|
36
|
-
serverErrorHandlers = [];
|
|
37
|
-
constructor(port) {
|
|
38
|
-
this.app = (0, express_1.default)();
|
|
39
|
-
if (typeof port !== 'undefined') {
|
|
40
|
-
this.app.set('port', port);
|
|
41
|
-
}
|
|
42
|
-
this.app.set('json spaces', 0);
|
|
43
|
-
this.app.set('etag', 'strong');
|
|
44
|
-
}
|
|
45
|
-
enableBodyParser(opts) {
|
|
46
|
-
this.app.use(express_1.default.json({
|
|
47
|
-
inflate: true,
|
|
48
|
-
limit: opts.limit
|
|
49
|
-
}));
|
|
50
|
-
this.app.use(express_1.default.urlencoded({
|
|
51
|
-
extended: true,
|
|
52
|
-
limit: opts.limit
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
enableCookies() {
|
|
56
|
-
this.app.use((0, cookie_parser_1.default)());
|
|
57
|
-
}
|
|
58
|
-
enableFileUploads(opts) {
|
|
59
|
-
const upload = (0, multer_1.default)({
|
|
60
|
-
limits: {
|
|
61
|
-
fieldSize: 10
|
|
62
|
-
},
|
|
63
|
-
storage: multer_1.default.diskStorage({
|
|
64
|
-
destination: opts.tempDir,
|
|
65
|
-
filename: (_req, file, cb) => cb(null, opts.filename(file.originalname))
|
|
66
|
-
})
|
|
67
|
-
});
|
|
68
|
-
this.app.use(upload.any());
|
|
69
|
-
}
|
|
70
|
-
enableRequestTiming(onDone) {
|
|
71
|
-
this.app.use((0, response_time_1.default)((req, res, time) => {
|
|
72
|
-
onDone(this.toOcRequest(req), this.toOcResponse(res), time);
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
enableLogging(opts) {
|
|
76
|
-
this.app.use((0, morgan_1.default)('dev', {
|
|
77
|
-
skip: (req, res) => opts.skip(this.toOcRequest(req), this.toOcResponse(res))
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
enableErrorHandler() {
|
|
81
|
-
this.app.use((0, errorhandler_1.default)());
|
|
82
|
-
}
|
|
83
|
-
use(handler) {
|
|
84
|
-
this.app.use(this.toExpressHandler(handler, true));
|
|
85
|
-
}
|
|
86
|
-
route(method, path, id, handlers) {
|
|
87
|
-
const setRouteId = (req, _res, next) => {
|
|
88
|
-
req.routeId = id;
|
|
89
|
-
next();
|
|
90
|
-
};
|
|
91
|
-
this.app[method](path, setRouteId, ...handlers.map((handler) => this.toExpressHandler(handler)));
|
|
92
|
-
}
|
|
93
|
-
fromConnect(handler) {
|
|
94
|
-
const wrapped = (req, res) => new Promise((resolve, reject) => {
|
|
95
|
-
handler(req.raw ?? req, res.raw ?? res, (err) => {
|
|
96
|
-
if (err) {
|
|
97
|
-
reject(err);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
resolve();
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
wrapped[expressMiddleware] = handler;
|
|
105
|
-
return wrapped;
|
|
106
|
-
}
|
|
107
|
-
listen(opts, cb) {
|
|
108
|
-
this.server = node_http_1.default.createServer(this.app);
|
|
109
|
-
this.server.timeout = opts.timeout;
|
|
110
|
-
if (opts.keepAliveTimeout) {
|
|
111
|
-
this.server.keepAliveTimeout = opts.keepAliveTimeout;
|
|
112
|
-
}
|
|
113
|
-
for (const handler of this.serverErrorHandlers) {
|
|
114
|
-
this.server.on('error', handler);
|
|
115
|
-
}
|
|
116
|
-
this.server.listen(opts.port, cb);
|
|
117
|
-
}
|
|
118
|
-
onServerError(cb) {
|
|
119
|
-
this.serverErrorHandlers.push(cb);
|
|
120
|
-
this.server?.on('error', cb);
|
|
121
|
-
}
|
|
122
|
-
close(cb) {
|
|
123
|
-
this.server?.close(cb);
|
|
124
|
-
}
|
|
125
|
-
isListening() {
|
|
126
|
-
return !!this.server?.listening;
|
|
127
|
-
}
|
|
128
|
-
native() {
|
|
129
|
-
return this.app;
|
|
130
|
-
}
|
|
131
|
-
httpServer() {
|
|
132
|
-
if (!this.server) {
|
|
133
|
-
throw new Error('HTTP server has not been started');
|
|
134
|
-
}
|
|
135
|
-
return this.server;
|
|
136
|
-
}
|
|
137
|
-
toExpressHandler(handler, continueWhenNotSent = false) {
|
|
138
|
-
const native = handler[expressMiddleware];
|
|
139
|
-
if (native) {
|
|
140
|
-
return native;
|
|
141
|
-
}
|
|
142
|
-
return (req, res, next) => {
|
|
143
|
-
let result;
|
|
144
|
-
try {
|
|
145
|
-
result = handler(this.toOcRequest(req), this.toOcResponse(res));
|
|
146
|
-
}
|
|
147
|
-
catch (err) {
|
|
148
|
-
next(err);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
if (result && typeof result.then === 'function') {
|
|
152
|
-
result
|
|
153
|
-
.then(() => {
|
|
154
|
-
if (continueWhenNotSent && !res.headersSent) {
|
|
155
|
-
next();
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
|
-
.catch(next);
|
|
159
|
-
}
|
|
160
|
-
else if (continueWhenNotSent && !res.headersSent) {
|
|
161
|
-
next();
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
toOcRequest(req) {
|
|
166
|
-
const memo = req[ocParamsSym];
|
|
167
|
-
const current = (req.params ?? {});
|
|
168
|
-
if (memo && memo.source === current) {
|
|
169
|
-
return req;
|
|
170
|
-
}
|
|
171
|
-
if (!memo) {
|
|
172
|
-
Object.assign(req, {
|
|
173
|
-
raw: req,
|
|
174
|
-
routeId: req.routeId ?? ''
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
const normalized = normaliseParams(current);
|
|
178
|
-
Object.assign(req, { params: normalized });
|
|
179
|
-
req[ocParamsSym] = {
|
|
180
|
-
source: normalized
|
|
181
|
-
};
|
|
182
|
-
return req;
|
|
183
|
-
}
|
|
184
|
-
toOcResponse(res) {
|
|
185
|
-
const cached = res[ocResponseSym];
|
|
186
|
-
if (cached) {
|
|
187
|
-
return cached;
|
|
188
|
-
}
|
|
189
|
-
const ocRes = Object.assign(res, {
|
|
190
|
-
raw: res,
|
|
191
|
-
stream
|
|
192
|
-
});
|
|
193
|
-
res[ocResponseSym] = ocRes;
|
|
194
|
-
return ocRes;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type http from 'node:http';
|
|
2
|
-
import type { IncomingHttpHeaders } from 'node:http';
|
|
3
|
-
import type express from 'express';
|
|
4
|
-
import type { Config } from '../../../types';
|
|
5
|
-
export interface CookieOptions {
|
|
6
|
-
domain?: string;
|
|
7
|
-
encode?: (value: string) => string;
|
|
8
|
-
expires?: Date;
|
|
9
|
-
httpOnly?: boolean;
|
|
10
|
-
maxAge?: number;
|
|
11
|
-
partitioned?: boolean;
|
|
12
|
-
path?: string;
|
|
13
|
-
priority?: 'low' | 'medium' | 'high';
|
|
14
|
-
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
15
|
-
secure?: boolean;
|
|
16
|
-
signed?: boolean;
|
|
17
|
-
}
|
|
18
|
-
export type Method = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
|
|
19
|
-
export interface UploadedFile {
|
|
20
|
-
fieldname: string;
|
|
21
|
-
originalname: string;
|
|
22
|
-
encoding: string;
|
|
23
|
-
mimetype: string;
|
|
24
|
-
size: number;
|
|
25
|
-
destination: string;
|
|
26
|
-
filename: string;
|
|
27
|
-
path: string;
|
|
28
|
-
buffer?: Buffer;
|
|
29
|
-
stream?: NodeJS.ReadableStream;
|
|
30
|
-
truncated?: boolean;
|
|
31
|
-
}
|
|
32
|
-
export interface OcRequest {
|
|
33
|
-
method: string;
|
|
34
|
-
url: string;
|
|
35
|
-
path: string;
|
|
36
|
-
originalUrl: string;
|
|
37
|
-
protocol: string;
|
|
38
|
-
secure: boolean;
|
|
39
|
-
ip: string;
|
|
40
|
-
headers: IncomingHttpHeaders;
|
|
41
|
-
params: Record<string, string>;
|
|
42
|
-
query: Record<string, unknown>;
|
|
43
|
-
body: any;
|
|
44
|
-
cookies: Record<string, string>;
|
|
45
|
-
files?: UploadedFile[] | Record<string, UploadedFile[]>;
|
|
46
|
-
user?: string;
|
|
47
|
-
routeId: string;
|
|
48
|
-
get(header: string): string | undefined;
|
|
49
|
-
raw: http.IncomingMessage;
|
|
50
|
-
}
|
|
51
|
-
export interface OcResponse {
|
|
52
|
-
conf: Config;
|
|
53
|
-
errorCode?: string;
|
|
54
|
-
errorDetails?: string;
|
|
55
|
-
statusCode: number;
|
|
56
|
-
status(code: number): this;
|
|
57
|
-
json(body: unknown): void;
|
|
58
|
-
send(body: unknown): void;
|
|
59
|
-
set(field: string | Record<string, string>, value?: string): this;
|
|
60
|
-
header(name: string, value: string): this;
|
|
61
|
-
setHeader(name: string, value: string): this;
|
|
62
|
-
removeHeader(name: string): this;
|
|
63
|
-
type(mime: string): this;
|
|
64
|
-
cookie(name: string, value: string, opts?: CookieOptions): this;
|
|
65
|
-
redirect(url: string): void;
|
|
66
|
-
end(chunk?: unknown): void;
|
|
67
|
-
stream(readable: NodeJS.ReadableStream): void;
|
|
68
|
-
raw: http.ServerResponse;
|
|
69
|
-
}
|
|
70
|
-
export type OcHandler = (req: OcRequest, res: OcResponse) => void | Promise<void>;
|
|
71
|
-
export type ExpressMiddleware = (req: any, res: any, next: (err?: unknown) => void) => void;
|
|
72
|
-
export type HttpServerAdapterFactory<TOptions = unknown, TNative = unknown> = {
|
|
73
|
-
(options?: unknown): HttpServerAdapter<TNative>;
|
|
74
|
-
readonly __serverAdapterOptions?: TOptions;
|
|
75
|
-
};
|
|
76
|
-
export type HttpServerAdapterOptions<TAdapter> = TAdapter extends {
|
|
77
|
-
readonly __serverAdapterOptions?: infer TOptions;
|
|
78
|
-
} ? TOptions : TAdapter extends (options?: infer TOptions) => HttpServerAdapter ? TOptions : unknown;
|
|
79
|
-
export type NativeApp<TAdapter> = TAdapter extends (...args: any[]) => HttpServerAdapter<infer TNative> ? unknown extends TNative ? express.Express : TNative : TAdapter extends HttpServerAdapter<infer TNative> ? unknown extends TNative ? express.Express : TNative : express.Express;
|
|
80
|
-
export interface HttpServerAdapter<TNative = unknown> {
|
|
81
|
-
name: string;
|
|
82
|
-
enableBodyParser(opts: {
|
|
83
|
-
limit?: number | string;
|
|
84
|
-
}): void;
|
|
85
|
-
enableCookies(): void;
|
|
86
|
-
enableFileUploads(opts: {
|
|
87
|
-
tempDir: string;
|
|
88
|
-
filename: (originalName: string) => string;
|
|
89
|
-
}): void;
|
|
90
|
-
enableRequestTiming(onDone: (req: OcRequest, res: OcResponse, ms: number) => void): void;
|
|
91
|
-
enableLogging(opts: {
|
|
92
|
-
skip: (req: OcRequest, res: OcResponse) => boolean;
|
|
93
|
-
}): void;
|
|
94
|
-
enableErrorHandler(): void;
|
|
95
|
-
use(handler: OcHandler): void;
|
|
96
|
-
route(method: Method, path: string, id: string, handlers: OcHandler[]): void;
|
|
97
|
-
fromConnect(handler: ExpressMiddleware): OcHandler;
|
|
98
|
-
listen(opts: {
|
|
99
|
-
port: number | string;
|
|
100
|
-
timeout: number;
|
|
101
|
-
keepAliveTimeout?: number;
|
|
102
|
-
}, cb: (err?: Error) => void): void;
|
|
103
|
-
onServerError(cb: (err: Error) => void): void;
|
|
104
|
-
close(cb: (err?: Error) => void): void;
|
|
105
|
-
isListening(): boolean;
|
|
106
|
-
native(): TNative;
|
|
107
|
-
httpServer(): http.Server;
|
|
108
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { HttpServerAdapter } from './http-server/types';
|
|
2
|
-
type HttpServerAdapterFactory<T = unknown> = (options?: T) => HttpServerAdapter;
|
|
3
|
-
export default function getHttpServerAdapter<T = unknown>(adapter: HttpServerAdapter | HttpServerAdapterFactory<T>, options?: T): HttpServerAdapter;
|
|
4
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = getHttpServerAdapter;
|
|
4
|
-
function isHttpServerAdapter(adapter) {
|
|
5
|
-
return (!!adapter &&
|
|
6
|
-
typeof adapter === 'object' &&
|
|
7
|
-
typeof adapter.native === 'function' &&
|
|
8
|
-
typeof adapter.listen === 'function' &&
|
|
9
|
-
typeof adapter.httpServer === 'function');
|
|
10
|
-
}
|
|
11
|
-
function getHttpServerAdapter(adapter, options) {
|
|
12
|
-
if (isHttpServerAdapter(adapter)) {
|
|
13
|
-
return adapter;
|
|
14
|
-
}
|
|
15
|
-
const instance = adapter(options);
|
|
16
|
-
if (!isHttpServerAdapter(instance)) {
|
|
17
|
-
throw new Error('Invalid HTTP server adapter');
|
|
18
|
-
}
|
|
19
|
-
return instance;
|
|
20
|
-
}
|