@rebasepro/server-core 0.7.0 → 0.9.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/README.md +2 -2
- package/dist/api/ast-schema-editor.d.ts +21 -0
- package/dist/api/collections_for_test/callbacks_test_collection.d.ts +2 -0
- package/dist/api/errors.d.ts +53 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/logs-routes.d.ts +37 -0
- package/dist/api/openapi-generator.d.ts +16 -0
- package/dist/api/rest/api-generator.d.ts +68 -0
- package/{src/api/rest/index.ts → dist/api/rest/index.d.ts} +0 -1
- package/dist/api/rest/query-parser.d.ts +6 -0
- package/dist/api/schema-editor-routes.d.ts +3 -0
- package/dist/api/types.d.ts +56 -0
- package/dist/auth/adapter-middleware.d.ts +43 -0
- package/dist/auth/admin-roles-route.d.ts +18 -0
- package/dist/auth/admin-user-ops.d.ts +79 -0
- package/dist/auth/admin-users-route.d.ts +28 -0
- package/dist/auth/api-keys/api-key-middleware.d.ts +39 -0
- package/{src/auth/api-keys/api-key-permission-guard.ts → dist/auth/api-keys/api-key-permission-guard.d.ts} +2 -34
- package/dist/auth/api-keys/api-key-routes.d.ts +20 -0
- package/dist/auth/api-keys/api-key-store.d.ts +35 -0
- package/{src/auth/api-keys/api-key-types.ts → dist/auth/api-keys/api-key-types.d.ts} +0 -6
- package/{src/auth/api-keys/index.ts → dist/auth/api-keys/index.d.ts} +2 -22
- package/dist/auth/apple-oauth.d.ts +30 -0
- package/{src/auth/auth-hooks.ts → dist/auth/auth-hooks.d.ts} +15 -73
- package/dist/auth/bitbucket-oauth.d.ts +11 -0
- package/dist/auth/builtin-auth-adapter.d.ts +55 -0
- package/dist/auth/cookie-utils.d.ts +32 -0
- package/{src/auth/crypto-utils.ts → dist/auth/crypto-utils.d.ts} +1 -16
- package/dist/auth/custom-auth-adapter.d.ts +39 -0
- package/dist/auth/discord-oauth.d.ts +14 -0
- package/dist/auth/facebook-oauth.d.ts +14 -0
- package/dist/auth/github-oauth.d.ts +15 -0
- package/dist/auth/gitlab-oauth.d.ts +13 -0
- package/dist/auth/google-oauth.d.ts +47 -0
- package/{src/auth/index.ts → dist/auth/index.d.ts} +4 -22
- package/{src/auth/interfaces.ts → dist/auth/interfaces.d.ts} +20 -89
- package/dist/auth/jwt.d.ts +67 -0
- package/dist/auth/linkedin-oauth.d.ts +18 -0
- package/dist/auth/magic-link-routes.d.ts +32 -0
- package/dist/auth/mfa-crypto.d.ts +23 -0
- package/dist/auth/mfa-routes.d.ts +7 -0
- package/dist/auth/mfa.d.ts +49 -0
- package/dist/auth/microsoft-oauth.d.ts +16 -0
- package/dist/auth/middleware.d.ts +158 -0
- package/dist/auth/password.d.ts +22 -0
- package/dist/auth/rate-limiter.d.ts +50 -0
- package/dist/auth/reset-password-admin.d.ts +29 -0
- package/dist/auth/rls-scope.d.ts +31 -0
- package/dist/auth/routes.d.ts +66 -0
- package/dist/auth/session-routes.d.ts +29 -0
- package/dist/auth/slack-oauth.d.ts +12 -0
- package/dist/auth/spotify-oauth.d.ts +12 -0
- package/dist/auth/twitter-oauth.d.ts +18 -0
- package/dist/collections/BackendCollectionRegistry.d.ts +13 -0
- package/dist/collections/loader.d.ts +5 -0
- package/dist/cron/cron-loader.d.ts +18 -0
- package/dist/cron/cron-routes.d.ts +14 -0
- package/dist/cron/cron-scheduler.d.ts +106 -0
- package/dist/cron/cron-store.d.ts +32 -0
- package/dist/cron/define-cron.d.ts +28 -0
- package/{src/cron/index.ts → dist/cron/index.d.ts} +1 -0
- package/dist/db/interfaces.d.ts +18 -0
- package/dist/dynamic-import-Dvh-K5fl.js +22 -0
- package/dist/dynamic-import-Dvh-K5fl.js.map +1 -0
- package/dist/email/index.d.ts +6 -0
- package/dist/email/smtp-email-service.d.ts +30 -0
- package/dist/email/templates.d.ts +50 -0
- package/{src/email/types.ts → dist/email/types.d.ts} +40 -36
- package/dist/env.d.ts +102 -0
- package/dist/functions/define-function.d.ts +55 -0
- package/dist/functions/function-loader.d.ts +18 -0
- package/dist/functions/function-routes.d.ts +10 -0
- package/{src/functions/index.ts → dist/functions/index.d.ts} +2 -0
- package/dist/history/history-routes.d.ts +23 -0
- package/{src/history/index.ts → dist/history/index.d.ts} +0 -1
- package/dist/index.d.ts +35 -0
- package/dist/index.es.js +18184 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +48629 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/init/docs.d.ts +4 -0
- package/dist/init/health.d.ts +2 -0
- package/dist/init/middlewares.d.ts +10 -0
- package/dist/init/shutdown.d.ts +65 -0
- package/dist/init/storage.d.ts +5 -0
- package/dist/init.d.ts +344 -0
- package/dist/jwt-BwIn8xmk.js +4200 -0
- package/dist/jwt-BwIn8xmk.js.map +1 -0
- package/dist/logger-BYU66ENZ.js +94 -0
- package/dist/logger-BYU66ENZ.js.map +1 -0
- package/dist/ms-DnYXB-Wd.js +162 -0
- package/dist/ms-DnYXB-Wd.js.map +1 -0
- package/dist/openapi-generator-Z9oYWLf_.js +586 -0
- package/dist/openapi-generator-Z9oYWLf_.js.map +1 -0
- package/dist/schema-editor-routes-D3ef8zu1.js +219 -0
- package/dist/schema-editor-routes-D3ef8zu1.js.map +1 -0
- package/dist/serve-spa.d.ts +36 -0
- package/dist/services/driver-registry.d.ts +78 -0
- package/dist/services/routed-realtime-service.d.ts +43 -0
- package/dist/services/webhook-service.d.ts +29 -0
- package/dist/singleton.d.ts +51 -0
- package/dist/src-B4OLmNVa.js +437 -0
- package/dist/src-B4OLmNVa.js.map +1 -0
- package/dist/src-B5WkP1Rv.js +24778 -0
- package/dist/src-B5WkP1Rv.js.map +1 -0
- package/dist/storage/GCSStorageController.d.ts +43 -0
- package/dist/storage/LocalStorageController.d.ts +46 -0
- package/dist/storage/S3StorageController.d.ts +40 -0
- package/dist/storage/image-transform.d.ts +50 -0
- package/{src/storage/index.ts → dist/storage/index.d.ts} +6 -21
- package/dist/storage/routes.d.ts +70 -0
- package/dist/storage/storage-registry.d.ts +78 -0
- package/dist/storage/tus-handler.d.ts +53 -0
- package/{src/storage/types.ts → dist/storage/types.d.ts} +32 -38
- package/dist/types/index.d.ts +11 -0
- package/dist/utils/dev-port.d.ts +45 -0
- package/dist/utils/dynamic-import.d.ts +25 -0
- package/dist/utils/logger.d.ts +31 -0
- package/dist/utils/logging.d.ts +9 -0
- package/dist/utils/request-id.d.ts +4 -0
- package/dist/utils/request-logger.d.ts +19 -0
- package/{src/utils/sql.ts → dist/utils/sql.d.ts} +5 -16
- package/package.json +49 -22
- package/coverage/clover.xml +0 -3739
- package/coverage/coverage-final.json +0 -31
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -266
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/api/ast-schema-editor.ts.html +0 -952
- package/coverage/lcov-report/src/api/errors.ts.html +0 -472
- package/coverage/lcov-report/src/api/graphql/graphql-schema-generator.ts.html +0 -1069
- package/coverage/lcov-report/src/api/graphql/index.html +0 -116
- package/coverage/lcov-report/src/api/index.html +0 -176
- package/coverage/lcov-report/src/api/openapi-generator.ts.html +0 -565
- package/coverage/lcov-report/src/api/rest/api-generator.ts.html +0 -994
- package/coverage/lcov-report/src/api/rest/index.html +0 -131
- package/coverage/lcov-report/src/api/rest/query-parser.ts.html +0 -550
- package/coverage/lcov-report/src/api/schema-editor-routes.ts.html +0 -202
- package/coverage/lcov-report/src/api/server.ts.html +0 -823
- package/coverage/lcov-report/src/auth/admin-routes.ts.html +0 -973
- package/coverage/lcov-report/src/auth/index.html +0 -176
- package/coverage/lcov-report/src/auth/jwt.ts.html +0 -574
- package/coverage/lcov-report/src/auth/middleware.ts.html +0 -745
- package/coverage/lcov-report/src/auth/password.ts.html +0 -310
- package/coverage/lcov-report/src/auth/services.ts.html +0 -2074
- package/coverage/lcov-report/src/collections/index.html +0 -116
- package/coverage/lcov-report/src/collections/loader.ts.html +0 -232
- package/coverage/lcov-report/src/db/auth-schema.ts.html +0 -523
- package/coverage/lcov-report/src/db/data-transformer.ts.html +0 -1753
- package/coverage/lcov-report/src/db/entityService.ts.html +0 -700
- package/coverage/lcov-report/src/db/index.html +0 -146
- package/coverage/lcov-report/src/db/services/EntityFetchService.ts.html +0 -4048
- package/coverage/lcov-report/src/db/services/EntityPersistService.ts.html +0 -883
- package/coverage/lcov-report/src/db/services/RelationService.ts.html +0 -3121
- package/coverage/lcov-report/src/db/services/entity-helpers.ts.html +0 -442
- package/coverage/lcov-report/src/db/services/index.html +0 -176
- package/coverage/lcov-report/src/db/services/index.ts.html +0 -124
- package/coverage/lcov-report/src/generate-drizzle-schema-logic.ts.html +0 -1960
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/services/driver-registry.ts.html +0 -631
- package/coverage/lcov-report/src/services/index.html +0 -131
- package/coverage/lcov-report/src/services/postgresDataDriver.ts.html +0 -3025
- package/coverage/lcov-report/src/storage/LocalStorageController.ts.html +0 -1189
- package/coverage/lcov-report/src/storage/S3StorageController.ts.html +0 -970
- package/coverage/lcov-report/src/storage/index.html +0 -161
- package/coverage/lcov-report/src/storage/storage-registry.ts.html +0 -646
- package/coverage/lcov-report/src/storage/types.ts.html +0 -451
- package/coverage/lcov-report/src/utils/drizzle-conditions.ts.html +0 -3082
- package/coverage/lcov-report/src/utils/index.html +0 -116
- package/coverage/lcov.info +0 -7179
- package/jest.config.cjs +0 -19
- package/src/api/ast-schema-editor.ts +0 -289
- package/src/api/collections_for_test/callbacks_test_collection.ts +0 -61
- package/src/api/errors.ts +0 -278
- package/src/api/graphql/graphql-schema-generator.ts +0 -383
- package/src/api/graphql/index.ts +0 -2
- package/src/api/index.ts +0 -11
- package/src/api/logs-routes.ts +0 -132
- package/src/api/openapi-generator.ts +0 -727
- package/src/api/rest/api-generator-count.test.ts +0 -126
- package/src/api/rest/api-generator.ts +0 -747
- package/src/api/rest/query-parser.ts +0 -300
- package/src/api/schema-editor-routes.ts +0 -41
- package/src/api/server.ts +0 -271
- package/src/api/types.ts +0 -104
- package/src/auth/adapter-middleware.ts +0 -114
- package/src/auth/admin-roles-route.ts +0 -36
- package/src/auth/admin-user-ops.ts +0 -236
- package/src/auth/admin-users-route.ts +0 -302
- package/src/auth/api-keys/api-key-middleware.ts +0 -133
- package/src/auth/api-keys/api-key-routes.ts +0 -193
- package/src/auth/api-keys/api-key-store.ts +0 -340
- package/src/auth/apple-oauth.ts +0 -122
- package/src/auth/bitbucket-oauth.ts +0 -84
- package/src/auth/builtin-auth-adapter.ts +0 -380
- package/src/auth/custom-auth-adapter.ts +0 -86
- package/src/auth/discord-oauth.ts +0 -85
- package/src/auth/facebook-oauth.ts +0 -74
- package/src/auth/github-oauth.ts +0 -112
- package/src/auth/gitlab-oauth.ts +0 -72
- package/src/auth/google-oauth.ts +0 -223
- package/src/auth/jwt.ts +0 -208
- package/src/auth/linkedin-oauth.ts +0 -83
- package/src/auth/magic-link-routes.ts +0 -167
- package/src/auth/mfa-crypto.ts +0 -91
- package/src/auth/mfa-routes.ts +0 -323
- package/src/auth/mfa.ts +0 -161
- package/src/auth/microsoft-oauth.ts +0 -90
- package/src/auth/middleware.ts +0 -369
- package/src/auth/password.ts +0 -77
- package/src/auth/rate-limiter.ts +0 -225
- package/src/auth/reset-password-admin.ts +0 -160
- package/src/auth/rls-scope.ts +0 -58
- package/src/auth/routes.ts +0 -802
- package/src/auth/session-routes.ts +0 -353
- package/src/auth/slack-oauth.ts +0 -73
- package/src/auth/spotify-oauth.ts +0 -69
- package/src/auth/twitter-oauth.ts +0 -128
- package/src/collections/BackendCollectionRegistry.ts +0 -20
- package/src/collections/loader.ts +0 -50
- package/src/cron/cron-loader.ts +0 -84
- package/src/cron/cron-routes.test.ts +0 -265
- package/src/cron/cron-routes.ts +0 -85
- package/src/cron/cron-scheduler.test.ts +0 -559
- package/src/cron/cron-scheduler.ts +0 -581
- package/src/cron/cron-store.ts +0 -166
- package/src/db/interfaces.ts +0 -60
- package/src/email/index.ts +0 -19
- package/src/email/smtp-email-service.ts +0 -123
- package/src/email/templates.ts +0 -470
- package/src/env.ts +0 -227
- package/src/functions/function-loader.ts +0 -116
- package/src/functions/function-routes.ts +0 -31
- package/src/history/history-routes.ts +0 -129
- package/src/index.ts +0 -70
- package/src/init/docs.ts +0 -47
- package/src/init/health.ts +0 -37
- package/src/init/middlewares.ts +0 -61
- package/src/init/shutdown.ts +0 -56
- package/src/init/storage.ts +0 -57
- package/src/init.ts +0 -1041
- package/src/serve-spa.ts +0 -89
- package/src/services/driver-registry.ts +0 -183
- package/src/services/routed-realtime-service.ts +0 -113
- package/src/services/webhook-service.ts +0 -155
- package/src/singleton.ts +0 -70
- package/src/storage/LocalStorageController.ts +0 -389
- package/src/storage/S3StorageController.ts +0 -300
- package/src/storage/image-transform.ts +0 -218
- package/src/storage/routes.ts +0 -368
- package/src/storage/storage-registry.ts +0 -188
- package/src/storage/tus-handler.ts +0 -315
- package/src/types/index.ts +0 -27
- package/src/utils/dev-port.ts +0 -196
- package/src/utils/logger.ts +0 -143
- package/src/utils/logging.ts +0 -40
- package/src/utils/request-id.ts +0 -40
- package/src/utils/request-logger.ts +0 -72
- package/test/api-generator.test.ts +0 -588
- package/test/api-key-permission-guard.test.ts +0 -144
- package/test/ast-schema-editor.test.ts +0 -89
- package/test/auth-middleware-hono.test.ts +0 -556
- package/test/auth-routes.test.ts +0 -1098
- package/test/backend-hooks-data.test.ts +0 -477
- package/test/custom-auth-adapter.test.ts +0 -189
- package/test/driver-registry.test.ts +0 -282
- package/test/email-templates.test.ts +0 -174
- package/test/env.test.ts +0 -128
- package/test/error-propagation.test.ts +0 -226
- package/test/errors-hono.test.ts +0 -133
- package/test/errors.test.ts +0 -155
- package/test/function-loader.test.ts +0 -127
- package/test/graphql-schema-generator.test.ts +0 -554
- package/test/jwt-security.test.ts +0 -182
- package/test/jwt.test.ts +0 -326
- package/test/mfa.test.ts +0 -197
- package/test/middleware.test.ts +0 -305
- package/test/multi-datasource-routing.test.ts +0 -113
- package/test/password.test.ts +0 -165
- package/test/query-parser.test.ts +0 -233
- package/test/rate-limiter.test.ts +0 -102
- package/test/reset-password-admin.test.ts +0 -113
- package/test/routed-realtime-service.test.ts +0 -86
- package/test/safe-compare.test.ts +0 -66
- package/test/singleton.test.ts +0 -59
- package/test/smtp-email-service.test.ts +0 -169
- package/test/storage-local.test.ts +0 -271
- package/test/storage-registry.test.ts +0 -282
- package/test/storage-routes.test.ts +0 -222
- package/test/storage-s3.test.ts +0 -304
- package/test/transform-auth-response.test.ts +0 -305
- package/test/webhook-service.test.ts +0 -260
- package/tsconfig.json +0 -54
- package/tsconfig.prod.json +0 -23
- package/vite.config.ts +0 -86
|
@@ -1,727 +0,0 @@
|
|
|
1
|
-
import { EntityCollection, Property, StringProperty, NumberProperty, ArrayProperty, MapProperty, Relation, VectorProperty } from "@rebasepro/types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* OpenAPI 3.0.3 specification generator.
|
|
5
|
-
*
|
|
6
|
-
* Produces a spec that exactly mirrors the REST API consumed by the
|
|
7
|
-
* Rebase SDK client (`@rebasepro/client`).
|
|
8
|
-
*
|
|
9
|
-
* Routes are mounted at `{basePath}/data/{slug}` by `initializeRebaseBackend`.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export interface OpenApiGeneratorOptions {
|
|
13
|
-
/** Base path for the API (e.g. "/api"). Defaults to "/api". */
|
|
14
|
-
basePath?: string;
|
|
15
|
-
/** Whether auth is enabled on data routes. Defaults to true. */
|
|
16
|
-
requireAuth?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function generateOpenApiSpec(
|
|
20
|
-
collections: EntityCollection[],
|
|
21
|
-
options: OpenApiGeneratorOptions = {}
|
|
22
|
-
): Record<string, unknown> {
|
|
23
|
-
const basePath = options.basePath ?? "/api";
|
|
24
|
-
const requireAuth = options.requireAuth ?? true;
|
|
25
|
-
|
|
26
|
-
const spec: Record<string, unknown> = {
|
|
27
|
-
openapi: "3.0.3",
|
|
28
|
-
info: {
|
|
29
|
-
title: "Rebase API",
|
|
30
|
-
version: "1.0.0",
|
|
31
|
-
description:
|
|
32
|
-
"Auto-generated REST API from Rebase collection definitions. " +
|
|
33
|
-
"This is the same API consumed by the `@rebasepro/client` SDK."
|
|
34
|
-
},
|
|
35
|
-
servers: [
|
|
36
|
-
{
|
|
37
|
-
url: basePath,
|
|
38
|
-
description: "API Server"
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
paths: {} as Record<string, unknown>,
|
|
42
|
-
components: {
|
|
43
|
-
schemas: {
|
|
44
|
-
ErrorResponse: {
|
|
45
|
-
type: "object",
|
|
46
|
-
properties: {
|
|
47
|
-
error: {
|
|
48
|
-
type: "object",
|
|
49
|
-
required: ["message", "code"],
|
|
50
|
-
properties: {
|
|
51
|
-
message: { type: "string" },
|
|
52
|
-
code: { type: "string" },
|
|
53
|
-
details: {}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
PaginationMeta: {
|
|
59
|
-
type: "object",
|
|
60
|
-
properties: {
|
|
61
|
-
total: { type: "integer",
|
|
62
|
-
description: "Total number of matching records" },
|
|
63
|
-
limit: { type: "integer",
|
|
64
|
-
description: "Page size used for this query" },
|
|
65
|
-
offset: { type: "integer",
|
|
66
|
-
description: "Number of records skipped" },
|
|
67
|
-
hasMore: { type: "boolean",
|
|
68
|
-
description: "Whether more records exist beyond this page" }
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} as Record<string, unknown>,
|
|
72
|
-
securitySchemes: {} as Record<string, unknown>
|
|
73
|
-
},
|
|
74
|
-
tags: [] as Array<{ name: string; description?: string }>
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// ── Security Schemes ─────────────────────────────────────────────────
|
|
78
|
-
if (requireAuth) {
|
|
79
|
-
(spec.components as Record<string, unknown>).securitySchemes = {
|
|
80
|
-
bearerAuth: {
|
|
81
|
-
type: "http",
|
|
82
|
-
scheme: "bearer",
|
|
83
|
-
bearerFormat: "JWT",
|
|
84
|
-
description:
|
|
85
|
-
"JWT access token obtained from `POST /auth/login` or `POST /auth/register`. " +
|
|
86
|
-
"Can also be a static service key for server-to-server authentication."
|
|
87
|
-
},
|
|
88
|
-
queryToken: {
|
|
89
|
-
type: "apiKey",
|
|
90
|
-
in: "query",
|
|
91
|
-
name: "token",
|
|
92
|
-
description: "Alternative: pass the JWT or service key as a `token` query parameter."
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
(spec as Record<string, unknown>).security = [
|
|
96
|
-
{ bearerAuth: [] },
|
|
97
|
-
{ queryToken: [] }
|
|
98
|
-
];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const paths = spec.paths as Record<string, unknown>;
|
|
102
|
-
const schemas = (spec.components as Record<string, unknown>).schemas as Record<string, unknown>;
|
|
103
|
-
const tags = spec.tags as Array<{ name: string; description?: string }>;
|
|
104
|
-
|
|
105
|
-
// ── Collection routes ────────────────────────────────────────────────
|
|
106
|
-
for (const collection of (collections || [])) {
|
|
107
|
-
const schemaName = toPascalCase(collection.singularName || collection.name);
|
|
108
|
-
const slug = collection.slug;
|
|
109
|
-
|
|
110
|
-
tags.push({
|
|
111
|
-
name: collection.name,
|
|
112
|
-
description: collection.description || `CRUD operations for ${collection.name}`
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// Build component schema for this collection
|
|
116
|
-
schemas[schemaName] = buildCollectionSchema(collection);
|
|
117
|
-
|
|
118
|
-
// Build an "input" schema (no read-only/auto fields like autoValue dates)
|
|
119
|
-
schemas[`${schemaName}Input`] = buildCollectionInputSchema(collection);
|
|
120
|
-
|
|
121
|
-
const dataPath = `/data/${slug}`;
|
|
122
|
-
|
|
123
|
-
// ── GET /data/{slug} — List entities ──────────────────────────
|
|
124
|
-
paths[dataPath] = {
|
|
125
|
-
get: {
|
|
126
|
-
tags: [collection.name],
|
|
127
|
-
summary: `List ${collection.name}`,
|
|
128
|
-
operationId: `list${schemaName}`,
|
|
129
|
-
parameters: [
|
|
130
|
-
{ name: "limit",
|
|
131
|
-
in: "query",
|
|
132
|
-
schema: { type: "integer",
|
|
133
|
-
default: 20,
|
|
134
|
-
maximum: 100 },
|
|
135
|
-
description: "Maximum number of records to return" },
|
|
136
|
-
{ name: "offset",
|
|
137
|
-
in: "query",
|
|
138
|
-
schema: { type: "integer",
|
|
139
|
-
default: 0 },
|
|
140
|
-
description: "Number of records to skip" },
|
|
141
|
-
{ name: "page",
|
|
142
|
-
in: "query",
|
|
143
|
-
schema: { type: "integer",
|
|
144
|
-
minimum: 1 },
|
|
145
|
-
description: "Page number (alternative to offset). Calculates offset as (page-1)*limit" },
|
|
146
|
-
{
|
|
147
|
-
name: "orderBy",
|
|
148
|
-
in: "query",
|
|
149
|
-
schema: { type: "string" },
|
|
150
|
-
description: "Sort field and direction. Accepts `field:asc` or `field:desc`, or a JSON array `[{\"field\":\"name\",\"direction\":\"asc\"}]`",
|
|
151
|
-
example: "created_at:desc"
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
name: "where",
|
|
155
|
-
in: "query",
|
|
156
|
-
schema: { type: "string" },
|
|
157
|
-
description: "JSON object filter. Example: `{\"status\":[\"==\",\"active\"]}`"
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
name: "include",
|
|
161
|
-
in: "query",
|
|
162
|
-
schema: { type: "string" },
|
|
163
|
-
description: "Comma-separated list of relations to include (eager-load). Use `*` for all relations.",
|
|
164
|
-
example: "author,tags"
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
name: "fields",
|
|
168
|
-
in: "query",
|
|
169
|
-
schema: { type: "string" },
|
|
170
|
-
description: "Comma-separated list of fields to return (field selection)",
|
|
171
|
-
example: "id,name,created_at"
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
name: "searchString",
|
|
175
|
-
in: "query",
|
|
176
|
-
schema: { type: "string" },
|
|
177
|
-
description: "Full-text search query"
|
|
178
|
-
},
|
|
179
|
-
...buildFilterParameters(collection)
|
|
180
|
-
],
|
|
181
|
-
responses: {
|
|
182
|
-
200: {
|
|
183
|
-
description: "Paginated list of entities",
|
|
184
|
-
content: {
|
|
185
|
-
"application/json": {
|
|
186
|
-
schema: {
|
|
187
|
-
type: "object",
|
|
188
|
-
properties: {
|
|
189
|
-
data: {
|
|
190
|
-
type: "array",
|
|
191
|
-
items: { $ref: `#/components/schemas/${schemaName}` }
|
|
192
|
-
},
|
|
193
|
-
meta: { $ref: "#/components/schemas/PaginationMeta" }
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
...errorResponses(requireAuth)
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
post: {
|
|
203
|
-
tags: [collection.name],
|
|
204
|
-
summary: `Create ${collection.singularName || collection.name}`,
|
|
205
|
-
operationId: `create${schemaName}`,
|
|
206
|
-
requestBody: {
|
|
207
|
-
required: true,
|
|
208
|
-
content: {
|
|
209
|
-
"application/json": {
|
|
210
|
-
schema: { $ref: `#/components/schemas/${schemaName}Input` }
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
responses: {
|
|
215
|
-
201: {
|
|
216
|
-
description: "Created entity",
|
|
217
|
-
content: {
|
|
218
|
-
"application/json": {
|
|
219
|
-
schema: { $ref: `#/components/schemas/${schemaName}` }
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
...errorResponses(requireAuth)
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
// ── GET/PUT/DELETE /data/{slug}/{id} ──────────────────────────
|
|
229
|
-
const entityPath = `/data/${slug}/{id}`;
|
|
230
|
-
paths[entityPath] = {
|
|
231
|
-
get: {
|
|
232
|
-
tags: [collection.name],
|
|
233
|
-
summary: `Get ${collection.singularName || collection.name} by ID`,
|
|
234
|
-
operationId: `get${schemaName}ById`,
|
|
235
|
-
parameters: [
|
|
236
|
-
{ name: "id",
|
|
237
|
-
in: "path",
|
|
238
|
-
required: true,
|
|
239
|
-
schema: { type: "string" },
|
|
240
|
-
description: "Entity ID" },
|
|
241
|
-
{
|
|
242
|
-
name: "include",
|
|
243
|
-
in: "query",
|
|
244
|
-
schema: { type: "string" },
|
|
245
|
-
description: "Comma-separated list of relations to include",
|
|
246
|
-
example: "author,tags"
|
|
247
|
-
}
|
|
248
|
-
],
|
|
249
|
-
responses: {
|
|
250
|
-
200: {
|
|
251
|
-
description: "Entity found",
|
|
252
|
-
content: {
|
|
253
|
-
"application/json": {
|
|
254
|
-
schema: { $ref: `#/components/schemas/${schemaName}` }
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
404: { description: "Entity not found",
|
|
259
|
-
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } } },
|
|
260
|
-
...errorResponses(requireAuth)
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
put: {
|
|
264
|
-
tags: [collection.name],
|
|
265
|
-
summary: `Update ${collection.singularName || collection.name}`,
|
|
266
|
-
operationId: `update${schemaName}`,
|
|
267
|
-
parameters: [
|
|
268
|
-
{ name: "id",
|
|
269
|
-
in: "path",
|
|
270
|
-
required: true,
|
|
271
|
-
schema: { type: "string" },
|
|
272
|
-
description: "Entity ID" }
|
|
273
|
-
],
|
|
274
|
-
requestBody: {
|
|
275
|
-
required: true,
|
|
276
|
-
content: {
|
|
277
|
-
"application/json": {
|
|
278
|
-
schema: { $ref: `#/components/schemas/${schemaName}Input` }
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
},
|
|
282
|
-
responses: {
|
|
283
|
-
200: {
|
|
284
|
-
description: "Updated entity",
|
|
285
|
-
content: {
|
|
286
|
-
"application/json": {
|
|
287
|
-
schema: { $ref: `#/components/schemas/${schemaName}` }
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
},
|
|
291
|
-
404: { description: "Entity not found",
|
|
292
|
-
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } } },
|
|
293
|
-
...errorResponses(requireAuth)
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
delete: {
|
|
297
|
-
tags: [collection.name],
|
|
298
|
-
summary: `Delete ${collection.singularName || collection.name}`,
|
|
299
|
-
operationId: `delete${schemaName}`,
|
|
300
|
-
parameters: [
|
|
301
|
-
{ name: "id",
|
|
302
|
-
in: "path",
|
|
303
|
-
required: true,
|
|
304
|
-
schema: { type: "string" },
|
|
305
|
-
description: "Entity ID" }
|
|
306
|
-
],
|
|
307
|
-
responses: {
|
|
308
|
-
204: { description: "Deleted successfully" },
|
|
309
|
-
404: { description: "Entity not found",
|
|
310
|
-
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } } },
|
|
311
|
-
...errorResponses(requireAuth)
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
// ── Subcollection routes ──────────────────────────────────────
|
|
317
|
-
const relations = collection.relations;
|
|
318
|
-
if (relations && relations.length > 0) {
|
|
319
|
-
for (const relation of relations) {
|
|
320
|
-
const relationName = relation.relationName;
|
|
321
|
-
if (!relationName) continue;
|
|
322
|
-
|
|
323
|
-
let targetName: string;
|
|
324
|
-
try {
|
|
325
|
-
const targetCollection = relation.target();
|
|
326
|
-
targetName = targetCollection.singularName || targetCollection.name;
|
|
327
|
-
} catch {
|
|
328
|
-
targetName = relationName;
|
|
329
|
-
}
|
|
330
|
-
const targetSchema = toPascalCase(targetName);
|
|
331
|
-
|
|
332
|
-
const subPath = `/data/${slug}/{parentId}/${relationName}`;
|
|
333
|
-
|
|
334
|
-
// Only add if the schema exists (target collection is also registered)
|
|
335
|
-
paths[subPath] = {
|
|
336
|
-
get: {
|
|
337
|
-
tags: [collection.name],
|
|
338
|
-
summary: `List ${relationName} for a ${collection.singularName || collection.name}`,
|
|
339
|
-
operationId: `list${schemaName}${toPascalCase(relationName)}`,
|
|
340
|
-
parameters: [
|
|
341
|
-
{ name: "parentId",
|
|
342
|
-
in: "path",
|
|
343
|
-
required: true,
|
|
344
|
-
schema: { type: "string" },
|
|
345
|
-
description: `${collection.singularName || collection.name} ID` },
|
|
346
|
-
{ name: "limit",
|
|
347
|
-
in: "query",
|
|
348
|
-
schema: { type: "integer",
|
|
349
|
-
default: 20 } },
|
|
350
|
-
{ name: "offset",
|
|
351
|
-
in: "query",
|
|
352
|
-
schema: { type: "integer",
|
|
353
|
-
default: 0 } },
|
|
354
|
-
{ name: "orderBy",
|
|
355
|
-
in: "query",
|
|
356
|
-
schema: { type: "string" } },
|
|
357
|
-
{ name: "searchString",
|
|
358
|
-
in: "query",
|
|
359
|
-
schema: { type: "string" } }
|
|
360
|
-
],
|
|
361
|
-
responses: {
|
|
362
|
-
200: {
|
|
363
|
-
description: `List of related ${relationName}`,
|
|
364
|
-
content: {
|
|
365
|
-
"application/json": {
|
|
366
|
-
schema: {
|
|
367
|
-
type: "object",
|
|
368
|
-
properties: {
|
|
369
|
-
data: {
|
|
370
|
-
type: "array",
|
|
371
|
-
items: schemas[targetSchema]
|
|
372
|
-
? { $ref: `#/components/schemas/${targetSchema}` }
|
|
373
|
-
: { type: "object" }
|
|
374
|
-
},
|
|
375
|
-
meta: { $ref: "#/components/schemas/PaginationMeta" }
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
...errorResponses(requireAuth)
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
return spec;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// ── Helpers ──────────────────────────────────────────────────────────────
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Build the component schema for a collection (output / read shape).
|
|
396
|
-
* All fields are included (including relation foreign keys).
|
|
397
|
-
*/
|
|
398
|
-
function buildCollectionSchema(collection: EntityCollection): Record<string, unknown> {
|
|
399
|
-
const properties: Record<string, unknown> = {
|
|
400
|
-
id: { type: "string",
|
|
401
|
-
description: "Unique identifier" }
|
|
402
|
-
};
|
|
403
|
-
const required: string[] = ["id"];
|
|
404
|
-
|
|
405
|
-
for (const [key, property] of Object.entries(collection.properties)) {
|
|
406
|
-
// Skip relation properties — they are virtual and not part of the REST payload
|
|
407
|
-
if (property.type === "relation") continue;
|
|
408
|
-
|
|
409
|
-
properties[key] = convertPropertyToSchema(property);
|
|
410
|
-
|
|
411
|
-
if (property.validation?.required) {
|
|
412
|
-
required.push(key);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return {
|
|
417
|
-
type: "object",
|
|
418
|
-
required: required.length > 0 ? required : undefined,
|
|
419
|
-
properties
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Build an input schema (for POST/PUT) — excludes auto-generated fields.
|
|
425
|
-
*/
|
|
426
|
-
function buildCollectionInputSchema(collection: EntityCollection): Record<string, unknown> {
|
|
427
|
-
const properties: Record<string, unknown> = {};
|
|
428
|
-
const required: string[] = [];
|
|
429
|
-
|
|
430
|
-
for (const [key, property] of Object.entries(collection.properties)) {
|
|
431
|
-
if (property.type === "relation") continue;
|
|
432
|
-
|
|
433
|
-
// Skip auto-value date fields from the input schema
|
|
434
|
-
if (property.type === "date" && property.autoValue) continue;
|
|
435
|
-
|
|
436
|
-
// Skip auto-generated ID fields
|
|
437
|
-
if ("isId" in property && property.isId && property.isId !== "manual" && property.isId !== true) continue;
|
|
438
|
-
|
|
439
|
-
properties[key] = convertPropertyToSchema(property);
|
|
440
|
-
|
|
441
|
-
if (property.validation?.required) {
|
|
442
|
-
required.push(key);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// Allow explicit ID for create (optional)
|
|
447
|
-
properties["id"] = {
|
|
448
|
-
type: "string",
|
|
449
|
-
description: "Optional: client-assigned ID. If omitted, the server generates one."
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
return {
|
|
453
|
-
type: "object",
|
|
454
|
-
required: required.length > 0 ? required : undefined,
|
|
455
|
-
properties
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* Convert a Rebase Property to an OpenAPI 3.0 schema object.
|
|
461
|
-
*/
|
|
462
|
-
function convertPropertyToSchema(property: Property): Record<string, unknown> {
|
|
463
|
-
const base: Record<string, unknown> = {};
|
|
464
|
-
|
|
465
|
-
if (property.name) {
|
|
466
|
-
base.description = property.name;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
switch (property.type) {
|
|
470
|
-
case "string": {
|
|
471
|
-
const sp = property as StringProperty;
|
|
472
|
-
base.type = "string";
|
|
473
|
-
|
|
474
|
-
if (sp.enum) {
|
|
475
|
-
const enumValues = resolveEnumValues(sp.enum);
|
|
476
|
-
if (enumValues.length > 0) {
|
|
477
|
-
base.enum = enumValues;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
if (sp.validation) {
|
|
482
|
-
if (sp.validation.min !== undefined) base.minLength = sp.validation.min;
|
|
483
|
-
if (sp.validation.max !== undefined) base.maxLength = sp.validation.max;
|
|
484
|
-
if (sp.validation.length !== undefined) {
|
|
485
|
-
base.minLength = sp.validation.length;
|
|
486
|
-
base.maxLength = sp.validation.length;
|
|
487
|
-
}
|
|
488
|
-
if (sp.validation.matches !== undefined) {
|
|
489
|
-
base.pattern = String(sp.validation.matches);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
if (sp.email) base.format = "email";
|
|
494
|
-
if (sp.url) base.format = "uri";
|
|
495
|
-
if (sp.storage) base.format = "uri";
|
|
496
|
-
if (sp.markdown) base.description = (base.description || "") + " (Markdown)";
|
|
497
|
-
|
|
498
|
-
return base;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
case "number": {
|
|
502
|
-
const np = property as NumberProperty;
|
|
503
|
-
const isInteger = np.validation?.integer || np.columnType === "integer" || np.columnType === "serial" || np.columnType === "bigserial" || np.columnType === "bigint";
|
|
504
|
-
base.type = isInteger ? "integer" : "number";
|
|
505
|
-
|
|
506
|
-
if (np.enum) {
|
|
507
|
-
const enumValues = resolveEnumValues(np.enum);
|
|
508
|
-
if (enumValues.length > 0) {
|
|
509
|
-
base.enum = enumValues;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
if (np.validation) {
|
|
514
|
-
if (np.validation.min !== undefined) base.minimum = np.validation.min;
|
|
515
|
-
if (np.validation.max !== undefined) base.maximum = np.validation.max;
|
|
516
|
-
if (np.validation.moreThan !== undefined) {
|
|
517
|
-
base.minimum = np.validation.moreThan;
|
|
518
|
-
base.exclusiveMinimum = true;
|
|
519
|
-
}
|
|
520
|
-
if (np.validation.lessThan !== undefined) {
|
|
521
|
-
base.maximum = np.validation.lessThan;
|
|
522
|
-
base.exclusiveMaximum = true;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
return base;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
case "boolean":
|
|
530
|
-
base.type = "boolean";
|
|
531
|
-
return base;
|
|
532
|
-
|
|
533
|
-
case "date": {
|
|
534
|
-
base.type = "string";
|
|
535
|
-
if (property.mode === "date") {
|
|
536
|
-
base.format = "date";
|
|
537
|
-
} else {
|
|
538
|
-
base.format = "date-time";
|
|
539
|
-
}
|
|
540
|
-
if (property.autoValue) {
|
|
541
|
-
base.readOnly = true;
|
|
542
|
-
base.description = (base.description || "") +
|
|
543
|
-
(property.autoValue === "on_create" ? " (Auto-set on creation)" : " (Auto-updated)");
|
|
544
|
-
}
|
|
545
|
-
return base;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
case "geopoint":
|
|
549
|
-
base.type = "object";
|
|
550
|
-
base.properties = {
|
|
551
|
-
latitude: { type: "number" },
|
|
552
|
-
longitude: { type: "number" }
|
|
553
|
-
};
|
|
554
|
-
base.required = ["latitude", "longitude"];
|
|
555
|
-
return base;
|
|
556
|
-
|
|
557
|
-
case "reference":
|
|
558
|
-
base.type = "string";
|
|
559
|
-
base.description = (base.description || "") + " (Reference ID)";
|
|
560
|
-
return base;
|
|
561
|
-
|
|
562
|
-
case "array": {
|
|
563
|
-
const ap = property as ArrayProperty;
|
|
564
|
-
base.type = "array";
|
|
565
|
-
|
|
566
|
-
if (ap.oneOf) {
|
|
567
|
-
// Discriminated union (e.g., content blocks)
|
|
568
|
-
const typeField = ap.oneOf.typeField || "type";
|
|
569
|
-
const valueField = ap.oneOf.valueField || "value";
|
|
570
|
-
const variants: Record<string, unknown>[] = [];
|
|
571
|
-
|
|
572
|
-
for (const [variantKey, variantProp] of Object.entries(ap.oneOf.properties)) {
|
|
573
|
-
variants.push({
|
|
574
|
-
type: "object",
|
|
575
|
-
properties: {
|
|
576
|
-
[typeField]: { type: "string",
|
|
577
|
-
enum: [variantKey] },
|
|
578
|
-
[valueField]: convertPropertyToSchema(variantProp)
|
|
579
|
-
},
|
|
580
|
-
required: [typeField, valueField]
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
base.items = { oneOf: variants };
|
|
585
|
-
} else if (ap.of) {
|
|
586
|
-
if (Array.isArray(ap.of)) {
|
|
587
|
-
base.items = { oneOf: ap.of.map(p => convertPropertyToSchema(p)) };
|
|
588
|
-
} else {
|
|
589
|
-
base.items = convertPropertyToSchema(ap.of);
|
|
590
|
-
}
|
|
591
|
-
} else {
|
|
592
|
-
base.items = {};
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
if (ap.validation) {
|
|
596
|
-
if (ap.validation.min !== undefined) base.minItems = ap.validation.min;
|
|
597
|
-
if (ap.validation.max !== undefined) base.maxItems = ap.validation.max;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
return base;
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
case "map": {
|
|
604
|
-
const mp = property as MapProperty;
|
|
605
|
-
base.type = "object";
|
|
606
|
-
|
|
607
|
-
if (mp.properties) {
|
|
608
|
-
const props: Record<string, unknown> = {};
|
|
609
|
-
const req: string[] = [];
|
|
610
|
-
|
|
611
|
-
for (const [key, subProp] of Object.entries(mp.properties)) {
|
|
612
|
-
props[key] = convertPropertyToSchema(subProp);
|
|
613
|
-
if (subProp.validation?.required) {
|
|
614
|
-
req.push(key);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
base.properties = props;
|
|
619
|
-
if (req.length > 0) base.required = req;
|
|
620
|
-
} else if (mp.keyValue) {
|
|
621
|
-
base.additionalProperties = true;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
return base;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
case "vector": {
|
|
628
|
-
const vp = property as VectorProperty;
|
|
629
|
-
base.type = "array";
|
|
630
|
-
base.items = { type: "number" };
|
|
631
|
-
base.description = (base.description || "") + ` (Vector(${vp.dimensions}))`;
|
|
632
|
-
return base;
|
|
633
|
-
}
|
|
634
|
-
case "binary": {
|
|
635
|
-
base.type = "string";
|
|
636
|
-
base.description = (base.description || "") + " (Binary/Base64)";
|
|
637
|
-
return base;
|
|
638
|
-
}
|
|
639
|
-
default:
|
|
640
|
-
base.type = "string";
|
|
641
|
-
return base;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
/**
|
|
646
|
-
* Resolve EnumValues (array or record) into a flat array of enum values.
|
|
647
|
-
*/
|
|
648
|
-
function resolveEnumValues(enumDef: Record<string | number, unknown> | Array<{ id: string | number }>): Array<string | number> {
|
|
649
|
-
if (Array.isArray(enumDef)) {
|
|
650
|
-
return enumDef.map(e => (typeof e === "object" && e !== null && "id" in e) ? e.id : e as string | number);
|
|
651
|
-
}
|
|
652
|
-
return Object.keys(enumDef).map(k => {
|
|
653
|
-
// Preserve numeric keys as numbers
|
|
654
|
-
const num = Number(k);
|
|
655
|
-
return isNaN(num) ? k : num;
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
/**
|
|
660
|
-
* Build PostgREST-style filter parameters for a collection.
|
|
661
|
-
* These are additional query parameters like `?status=eq.active&price=gte.100`.
|
|
662
|
-
*/
|
|
663
|
-
function buildFilterParameters(collection: EntityCollection): Array<Record<string, unknown>> {
|
|
664
|
-
const params: Array<Record<string, unknown>> = [];
|
|
665
|
-
|
|
666
|
-
for (const [key, property] of Object.entries(collection.properties)) {
|
|
667
|
-
if (property.type === "relation" || property.type === "map" || property.type === "array" || property.type === "geopoint") {
|
|
668
|
-
continue;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
params.push({
|
|
672
|
-
name: key,
|
|
673
|
-
in: "query",
|
|
674
|
-
required: false,
|
|
675
|
-
schema: { type: "string" },
|
|
676
|
-
description:
|
|
677
|
-
`Filter by \`${key}\`. Supports PostgREST operators: ` +
|
|
678
|
-
"`eq.value`, `neq.value`, `gt.value`, `gte.value`, `lt.value`, `lte.value`, " +
|
|
679
|
-
"`in.(a,b,c)`, `nin.(a,b,c)`, `cs.value` (array-contains), `csa.(a,b)` (array-contains-any). " +
|
|
680
|
-
"Plain values imply equality.",
|
|
681
|
-
example: property.type === "string" ? "eq.active" : property.type === "number" ? "gte.100" : undefined
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
return params;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* Standard error responses included on every endpoint.
|
|
690
|
-
*/
|
|
691
|
-
function errorResponses(requireAuth: boolean): Record<string, unknown> {
|
|
692
|
-
const responses: Record<string, unknown> = {
|
|
693
|
-
400: {
|
|
694
|
-
description: "Bad request",
|
|
695
|
-
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
696
|
-
},
|
|
697
|
-
500: {
|
|
698
|
-
description: "Internal server error",
|
|
699
|
-
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
700
|
-
}
|
|
701
|
-
};
|
|
702
|
-
|
|
703
|
-
if (requireAuth) {
|
|
704
|
-
responses[401] = {
|
|
705
|
-
description: "Authentication required or invalid token",
|
|
706
|
-
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
707
|
-
};
|
|
708
|
-
responses[403] = {
|
|
709
|
-
description: "Insufficient permissions",
|
|
710
|
-
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
return responses;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
/**
|
|
718
|
-
* Convert a string to PascalCase for schema names.
|
|
719
|
-
*/
|
|
720
|
-
function toPascalCase(str: string): string {
|
|
721
|
-
return str
|
|
722
|
-
.replace(/[^a-zA-Z0-9]+/g, " ")
|
|
723
|
-
.split(" ")
|
|
724
|
-
.filter(Boolean)
|
|
725
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
726
|
-
.join("");
|
|
727
|
-
}
|