@palbase/backend 3.0.0 → 4.0.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/dist/{chunk-B7EUJP5W.js → chunk-EG7TTYHY.js} +113 -3
- package/dist/chunk-EG7TTYHY.js.map +1 -0
- package/dist/{chunk-PHAFZGHN.js → chunk-WUQO76NW.js} +26 -19
- package/dist/chunk-WUQO76NW.js.map +1 -0
- package/dist/db/index.cjs +117 -2
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.d.cts +2 -2
- package/dist/db/index.d.ts +2 -2
- package/dist/db/index.js +11 -1
- package/dist/{endpoint-DJ98tQd6.d.cts → endpoint-2d_DpASt.d.cts} +92 -56
- package/dist/{endpoint-DJ98tQd6.d.ts → endpoint-2d_DpASt.d.ts} +92 -56
- package/dist/{index-CXUs9iTQ.d.ts → index-DZW9CjiY.d.ts} +210 -41
- package/dist/{index-CZAwpQE1.d.cts → index-DzRFS3Tl.d.cts} +210 -41
- package/dist/index.cjs +371 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -215
- package/dist/index.d.ts +88 -215
- package/dist/index.js +217 -21
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +34 -19
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.d.cts +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.js +10 -2
- package/dist/test/index.js.map +1 -1
- package/docs/README.md +11 -11
- package/docs/database.md +40 -0
- package/docs/endpoints.md +98 -92
- package/docs/errors.md +37 -30
- package/docs/getting-started.md +24 -20
- package/docs/llms-full.txt +401 -235
- package/docs/routing.md +39 -45
- package/docs/schema.md +134 -23
- package/docs/services.md +14 -10
- package/package.json +2 -2
- package/dist/chunk-B7EUJP5W.js.map +0 -1
- package/dist/chunk-PHAFZGHN.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -11,18 +11,23 @@ import {
|
|
|
11
11
|
__requestALS,
|
|
12
12
|
__runWithRuntime,
|
|
13
13
|
__setRuntime
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-WUQO76NW.js";
|
|
15
15
|
import {
|
|
16
|
+
EXTENSION_DEPENDENCIES,
|
|
17
|
+
PALBASE_EXTENSIONS,
|
|
18
|
+
PolicyBuilder,
|
|
16
19
|
boolean,
|
|
17
20
|
defineSchema,
|
|
18
21
|
enumType,
|
|
19
22
|
integer,
|
|
23
|
+
isPalbaseExtension,
|
|
20
24
|
jsonb,
|
|
21
25
|
makeTypedDB,
|
|
26
|
+
policy,
|
|
22
27
|
text,
|
|
23
28
|
timestamp,
|
|
24
29
|
uuid
|
|
25
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-EG7TTYHY.js";
|
|
26
31
|
|
|
27
32
|
// src/db/env-gen.ts
|
|
28
33
|
function baseTsType(def) {
|
|
@@ -93,26 +98,145 @@ export {};
|
|
|
93
98
|
`;
|
|
94
99
|
}
|
|
95
100
|
|
|
96
|
-
// src/
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
// src/decorators/controller.ts
|
|
102
|
+
var CONTROLLER_META = /* @__PURE__ */ Symbol.for("palbase.backend.controllerMeta");
|
|
103
|
+
function Controller(basePath, options = {}) {
|
|
104
|
+
return function(ctor) {
|
|
105
|
+
const carrier = ctor;
|
|
106
|
+
const meta = {
|
|
107
|
+
__palbase: "controller",
|
|
108
|
+
basePath,
|
|
109
|
+
...options.auth !== void 0 ? { defaultAuth: options.auth } : {}
|
|
110
|
+
};
|
|
111
|
+
Object.defineProperty(carrier, CONTROLLER_META, {
|
|
112
|
+
value: meta,
|
|
113
|
+
enumerable: false,
|
|
114
|
+
configurable: true,
|
|
115
|
+
writable: false
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(carrier, "__palbase", {
|
|
118
|
+
value: "controller",
|
|
119
|
+
enumerable: false,
|
|
120
|
+
configurable: true,
|
|
121
|
+
writable: false
|
|
122
|
+
});
|
|
123
|
+
return ctor;
|
|
124
|
+
};
|
|
99
125
|
}
|
|
100
126
|
|
|
101
|
-
// src/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
127
|
+
// src/decorators/registry.ts
|
|
128
|
+
var ROUTES = /* @__PURE__ */ Symbol.for("palbase.backend.routes");
|
|
129
|
+
var PARAM_BUFFER = /* @__PURE__ */ Symbol.for("palbase.backend.paramBuffer");
|
|
130
|
+
function carrierOf(target) {
|
|
131
|
+
const ctor = typeof target === "function" ? target : target.constructor ?? target;
|
|
132
|
+
return ctor;
|
|
133
|
+
}
|
|
134
|
+
function ownRoutes(carrier) {
|
|
135
|
+
if (!Object.prototype.hasOwnProperty.call(carrier, ROUTES)) {
|
|
136
|
+
carrier[ROUTES] = [];
|
|
137
|
+
}
|
|
138
|
+
return carrier[ROUTES];
|
|
139
|
+
}
|
|
140
|
+
function ownParamBuffer(carrier) {
|
|
141
|
+
if (!Object.prototype.hasOwnProperty.call(carrier, PARAM_BUFFER)) {
|
|
142
|
+
carrier[PARAM_BUFFER] = {};
|
|
143
|
+
}
|
|
144
|
+
return carrier[PARAM_BUFFER];
|
|
145
|
+
}
|
|
146
|
+
function recordRoute(target, fnName, method, subpath, options) {
|
|
147
|
+
const carrier = carrierOf(target);
|
|
148
|
+
const routes = ownRoutes(carrier);
|
|
149
|
+
const buffer = ownParamBuffer(carrier);
|
|
150
|
+
const params = (buffer[fnName] ?? []).slice().sort((a, b) => a.index - b.index);
|
|
151
|
+
routes.push({ method, subpath, fnName, options, params });
|
|
152
|
+
}
|
|
153
|
+
function recordParam(target, fnName, meta) {
|
|
154
|
+
const carrier = carrierOf(target);
|
|
155
|
+
const buffer = ownParamBuffer(carrier);
|
|
156
|
+
(buffer[fnName] ??= []).push(meta);
|
|
157
|
+
const routes = carrier[ROUTES];
|
|
158
|
+
if (routes) {
|
|
159
|
+
const route = routes.find((r) => r.fnName === fnName);
|
|
160
|
+
if (route) {
|
|
161
|
+
route.params.push(meta);
|
|
162
|
+
route.params.sort((a, b) => a.index - b.index);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
var RETURN_BUFFER = /* @__PURE__ */ Symbol.for("palbase.backend.returnBuffer");
|
|
167
|
+
function recordReturn(target, fnName, schema) {
|
|
168
|
+
const carrier = carrierOf(target);
|
|
169
|
+
const routes = carrier[ROUTES];
|
|
170
|
+
const route = routes?.find((r) => r.fnName === fnName);
|
|
171
|
+
if (route) {
|
|
172
|
+
route.returnSchema = schema;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (!Object.prototype.hasOwnProperty.call(carrier, RETURN_BUFFER)) {
|
|
176
|
+
carrier[RETURN_BUFFER] = {};
|
|
177
|
+
}
|
|
178
|
+
carrier[RETURN_BUFFER][fnName] = schema;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/decorators/methods.ts
|
|
182
|
+
function makeMethodDecorator(method) {
|
|
183
|
+
return function(subpath, options = {}) {
|
|
184
|
+
return function(target, propertyKey) {
|
|
185
|
+
recordRoute(target, String(propertyKey), method, subpath, options);
|
|
186
|
+
};
|
|
105
187
|
};
|
|
106
188
|
}
|
|
107
|
-
var
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
189
|
+
var Get = makeMethodDecorator("GET");
|
|
190
|
+
var Post = makeMethodDecorator("POST");
|
|
191
|
+
var Put = makeMethodDecorator("PUT");
|
|
192
|
+
var Patch = makeMethodDecorator("PATCH");
|
|
193
|
+
var Delete = makeMethodDecorator("DELETE");
|
|
194
|
+
function Returns(schema) {
|
|
195
|
+
return function(target, propertyKey) {
|
|
196
|
+
recordReturn(target, String(propertyKey), schema);
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/decorators/params.ts
|
|
201
|
+
function makeParamDecorator(kind, extra) {
|
|
202
|
+
return function(target, propertyKey, parameterIndex) {
|
|
203
|
+
recordParam(target, String(propertyKey), {
|
|
204
|
+
index: parameterIndex,
|
|
205
|
+
kind,
|
|
206
|
+
...extra?.schema !== void 0 ? { schema: extra.schema } : {},
|
|
207
|
+
...extra?.name !== void 0 ? { name: extra.name } : {}
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function Body(schema) {
|
|
212
|
+
return makeParamDecorator("body", { schema });
|
|
213
|
+
}
|
|
214
|
+
function Query(schema) {
|
|
215
|
+
return makeParamDecorator("query", { schema });
|
|
216
|
+
}
|
|
217
|
+
function Headers(schema) {
|
|
218
|
+
return makeParamDecorator("headers", schema !== void 0 ? { schema } : void 0);
|
|
219
|
+
}
|
|
220
|
+
function Param(name) {
|
|
221
|
+
return makeParamDecorator("param", { name });
|
|
222
|
+
}
|
|
223
|
+
function User() {
|
|
224
|
+
return makeParamDecorator("user");
|
|
225
|
+
}
|
|
226
|
+
function OptionalUser() {
|
|
227
|
+
return makeParamDecorator("optionalUser");
|
|
228
|
+
}
|
|
229
|
+
function Client() {
|
|
230
|
+
return makeParamDecorator("client");
|
|
231
|
+
}
|
|
232
|
+
function RequestId() {
|
|
233
|
+
return makeParamDecorator("requestId");
|
|
234
|
+
}
|
|
235
|
+
function TraceId() {
|
|
236
|
+
return makeParamDecorator("traceId");
|
|
237
|
+
}
|
|
238
|
+
function Req() {
|
|
239
|
+
return makeParamDecorator("req");
|
|
116
240
|
}
|
|
117
241
|
|
|
118
242
|
// src/middleware.ts
|
|
@@ -157,6 +281,52 @@ var HttpError = class extends Error {
|
|
|
157
281
|
return result;
|
|
158
282
|
}
|
|
159
283
|
};
|
|
284
|
+
var PalError = class extends HttpError {
|
|
285
|
+
constructor(status, code, description, data) {
|
|
286
|
+
super(status, code, description, data);
|
|
287
|
+
this.name = "PalError";
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
var NamedHttpError = class extends HttpError {
|
|
291
|
+
constructor(status, defaultCode, name, message, code, data) {
|
|
292
|
+
super(status, code ?? defaultCode, message ?? defaultMessage(name), data);
|
|
293
|
+
this.name = name;
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
function defaultMessage(name) {
|
|
297
|
+
const spaced = name.replace(/([a-z0-9])([A-Z])/g, "$1 $2");
|
|
298
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1).toLowerCase();
|
|
299
|
+
}
|
|
300
|
+
var BadRequest = class extends NamedHttpError {
|
|
301
|
+
constructor(message, code, data) {
|
|
302
|
+
super(400, "bad_request", "BadRequest", message, code, data);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
var Unauthorized = class extends NamedHttpError {
|
|
306
|
+
constructor(message, code, data) {
|
|
307
|
+
super(401, "unauthorized", "Unauthorized", message, code, data);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
var Forbidden = class extends NamedHttpError {
|
|
311
|
+
constructor(message, code, data) {
|
|
312
|
+
super(403, "forbidden", "Forbidden", message, code, data);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
var NotFound = class extends NamedHttpError {
|
|
316
|
+
constructor(message, code, data) {
|
|
317
|
+
super(404, "not_found", "NotFound", message, code, data);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
var Conflict = class extends NamedHttpError {
|
|
321
|
+
constructor(message, code, data) {
|
|
322
|
+
super(409, "conflict", "Conflict", message, code, data);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
var TooManyRequests = class extends NamedHttpError {
|
|
326
|
+
constructor(message, code, data) {
|
|
327
|
+
super(429, "too_many_requests", "TooManyRequests", message, code, data);
|
|
328
|
+
}
|
|
329
|
+
};
|
|
160
330
|
|
|
161
331
|
// src/worker.ts
|
|
162
332
|
var VALID_WORKER_NAME = /^[a-zA-Z0-9_-]+$/;
|
|
@@ -458,16 +628,43 @@ var documents = {
|
|
|
458
628
|
// src/index.ts
|
|
459
629
|
import { z } from "zod";
|
|
460
630
|
export {
|
|
631
|
+
BadRequest,
|
|
632
|
+
Body,
|
|
461
633
|
Cache,
|
|
634
|
+
Client,
|
|
635
|
+
Conflict,
|
|
636
|
+
Controller,
|
|
462
637
|
Database,
|
|
638
|
+
Delete,
|
|
463
639
|
Documents,
|
|
640
|
+
EXTENSION_DEPENDENCIES,
|
|
464
641
|
Flags,
|
|
642
|
+
Forbidden,
|
|
643
|
+
Get,
|
|
644
|
+
Headers,
|
|
465
645
|
HttpError,
|
|
466
646
|
Log,
|
|
647
|
+
NotFound,
|
|
467
648
|
Notifications,
|
|
649
|
+
OptionalUser,
|
|
650
|
+
PALBASE_EXTENSIONS,
|
|
651
|
+
PalError,
|
|
652
|
+
Param,
|
|
653
|
+
Patch,
|
|
654
|
+
PolicyBuilder,
|
|
655
|
+
Post,
|
|
656
|
+
Put,
|
|
657
|
+
Query,
|
|
468
658
|
Queue,
|
|
659
|
+
Req,
|
|
660
|
+
RequestId,
|
|
469
661
|
Resource,
|
|
662
|
+
Returns,
|
|
470
663
|
Storage,
|
|
664
|
+
TooManyRequests,
|
|
665
|
+
TraceId,
|
|
666
|
+
Unauthorized,
|
|
667
|
+
User,
|
|
471
668
|
__getRuntime,
|
|
472
669
|
__registerResource,
|
|
473
670
|
__requestALS,
|
|
@@ -477,8 +674,6 @@ export {
|
|
|
477
674
|
__shutdownResources,
|
|
478
675
|
auth,
|
|
479
676
|
boolean,
|
|
480
|
-
defineController,
|
|
481
|
-
defineHandler,
|
|
482
677
|
defineJob,
|
|
483
678
|
defineMiddleware,
|
|
484
679
|
defineSchema,
|
|
@@ -487,10 +682,11 @@ export {
|
|
|
487
682
|
documents,
|
|
488
683
|
enumType,
|
|
489
684
|
integer,
|
|
685
|
+
isPalbaseExtension,
|
|
490
686
|
jsonb,
|
|
491
687
|
makeEnvDts,
|
|
492
688
|
makeTypedDB,
|
|
493
|
-
|
|
689
|
+
policy,
|
|
494
690
|
storage,
|
|
495
691
|
text,
|
|
496
692
|
timestamp,
|