@async/db 0.2.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/CHANGELOG.md +167 -0
- package/README.md +431 -0
- package/SPEC.md +1429 -0
- package/db.config.example.mjs +128 -0
- package/dist/cli/args.d.ts +8 -0
- package/dist/cli/args.js +16 -0
- package/dist/cli/commands/create.d.ts +3 -0
- package/dist/cli/commands/create.js +13 -0
- package/dist/cli/commands/doctor.d.ts +3 -0
- package/dist/cli/commands/doctor.js +31 -0
- package/dist/cli/commands/generate.d.ts +6 -0
- package/dist/cli/commands/generate.js +24 -0
- package/dist/cli/commands/operations.d.ts +12 -0
- package/dist/cli/commands/operations.js +61 -0
- package/dist/cli/commands/schema.d.ts +11 -0
- package/dist/cli/commands/schema.js +1086 -0
- package/dist/cli/commands/serve.d.ts +9 -0
- package/dist/cli/commands/serve.js +18 -0
- package/dist/cli/commands/sync.d.ts +3 -0
- package/dist/cli/commands/sync.js +11 -0
- package/dist/cli/commands/types.d.ts +7 -0
- package/dist/cli/commands/types.js +37 -0
- package/dist/cli/commands/viewer.d.ts +6 -0
- package/dist/cli/commands/viewer.js +29 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +108 -0
- package/dist/cli/output.d.ts +25 -0
- package/dist/cli/output.js +149 -0
- package/dist/cli/schema-prompt.d.ts +20 -0
- package/dist/cli/schema-prompt.js +66 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +3 -0
- package/dist/client-cache.d.ts +105 -0
- package/dist/client-cache.js +916 -0
- package/dist/client.d.ts +64 -0
- package/dist/client.js +405 -0
- package/dist/config-public.d.ts +1 -0
- package/dist/config-public.js +1 -0
- package/dist/config.d.ts +54 -0
- package/dist/config.js +2 -0
- package/dist/csv.d.ts +1 -0
- package/dist/csv.js +1 -0
- package/dist/db.d.ts +3 -0
- package/dist/db.js +3 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +1 -0
- package/dist/features/config/defaults.d.ts +98 -0
- package/dist/features/config/defaults.js +95 -0
- package/dist/features/config/load.d.ts +11 -0
- package/dist/features/config/load.js +265 -0
- package/dist/features/config/public.d.ts +17 -0
- package/dist/features/config/public.js +75 -0
- package/dist/features/doctor/duplicate-ids.d.ts +18 -0
- package/dist/features/doctor/duplicate-ids.js +79 -0
- package/dist/features/doctor/field-consistency.d.ts +17 -0
- package/dist/features/doctor/field-consistency.js +48 -0
- package/dist/features/doctor/index.d.ts +39 -0
- package/dist/features/doctor/index.js +177 -0
- package/dist/features/doctor/relations.d.ts +22 -0
- package/dist/features/doctor/relations.js +90 -0
- package/dist/features/doctor/schema-guidance.d.ts +35 -0
- package/dist/features/doctor/schema-guidance.js +184 -0
- package/dist/features/generate/registry.d.ts +14 -0
- package/dist/features/generate/registry.js +37 -0
- package/dist/features/http/registry.d.ts +46 -0
- package/dist/features/http/registry.js +86 -0
- package/dist/features/operations/index.d.ts +49 -0
- package/dist/features/operations/index.js +199 -0
- package/dist/features/operations/maps.d.ts +1 -0
- package/dist/features/operations/maps.js +10 -0
- package/dist/features/operations/readiness.d.ts +30 -0
- package/dist/features/operations/readiness.js +228 -0
- package/dist/features/operations/runtime.d.ts +57 -0
- package/dist/features/operations/runtime.js +288 -0
- package/dist/features/runtime/collection.d.ts +51 -0
- package/dist/features/runtime/collection.js +198 -0
- package/dist/features/runtime/db.d.ts +152 -0
- package/dist/features/runtime/db.js +824 -0
- package/dist/features/runtime/document.d.ts +43 -0
- package/dist/features/runtime/document.js +111 -0
- package/dist/features/runtime/fanout.d.ts +24 -0
- package/dist/features/runtime/fanout.js +77 -0
- package/dist/features/runtime/json-pointer.d.ts +5 -0
- package/dist/features/runtime/json-pointer.js +49 -0
- package/dist/features/runtime/scope-state.d.ts +44 -0
- package/dist/features/runtime/scope-state.js +185 -0
- package/dist/features/runtime/state.d.ts +1 -0
- package/dist/features/runtime/state.js +1 -0
- package/dist/features/schema/api.d.ts +107 -0
- package/dist/features/schema/api.js +460 -0
- package/dist/features/schema/builders.d.ts +86 -0
- package/dist/features/schema/builders.js +110 -0
- package/dist/features/schema/fields.d.ts +38 -0
- package/dist/features/schema/fields.js +296 -0
- package/dist/features/schema/generated.d.ts +29 -0
- package/dist/features/schema/generated.js +32 -0
- package/dist/features/schema/locator.d.ts +16 -0
- package/dist/features/schema/locator.js +135 -0
- package/dist/features/schema/manifest.d.ts +91 -0
- package/dist/features/schema/manifest.js +384 -0
- package/dist/features/schema/metadata.d.ts +30 -0
- package/dist/features/schema/metadata.js +75 -0
- package/dist/features/schema/project.d.ts +46 -0
- package/dist/features/schema/project.js +442 -0
- package/dist/features/schema/relations.d.ts +38 -0
- package/dist/features/schema/relations.js +109 -0
- package/dist/features/schema/resolvers.d.ts +36 -0
- package/dist/features/schema/resolvers.js +111 -0
- package/dist/features/schema/resource.d.ts +75 -0
- package/dist/features/schema/resource.js +253 -0
- package/dist/features/schema/source-definitions.d.ts +21 -0
- package/dist/features/schema/source-definitions.js +29 -0
- package/dist/features/schema/sources.d.ts +83 -0
- package/dist/features/schema/sources.js +689 -0
- package/dist/features/schema/standard-schema.d.ts +57 -0
- package/dist/features/schema/standard-schema.js +232 -0
- package/dist/features/schema/validation.d.ts +69 -0
- package/dist/features/schema/validation.js +434 -0
- package/dist/features/storage/events.d.ts +12 -0
- package/dist/features/storage/events.js +30 -0
- package/dist/features/storage/json.d.ts +112 -0
- package/dist/features/storage/json.js +239 -0
- package/dist/features/storage/memory.d.ts +30 -0
- package/dist/features/storage/memory.js +44 -0
- package/dist/features/storage/resource-json.d.ts +31 -0
- package/dist/features/storage/resource-json.js +76 -0
- package/dist/features/storage/runtime.d.ts +37 -0
- package/dist/features/storage/runtime.js +184 -0
- package/dist/features/storage/source-metadata.d.ts +20 -0
- package/dist/features/storage/source-metadata.js +25 -0
- package/dist/features/storage/source.d.ts +37 -0
- package/dist/features/storage/source.js +60 -0
- package/dist/features/storage/static.d.ts +29 -0
- package/dist/features/storage/static.js +42 -0
- package/dist/features/sync/defaults.d.ts +21 -0
- package/dist/features/sync/defaults.js +21 -0
- package/dist/features/sync/index.d.ts +35 -0
- package/dist/features/sync/index.js +85 -0
- package/dist/features/sync/mirror-state.d.ts +14 -0
- package/dist/features/sync/mirror-state.js +4 -0
- package/dist/features/sync/runtime-dirs.d.ts +5 -0
- package/dist/features/sync/runtime-dirs.js +9 -0
- package/dist/features/sync/source-writes.d.ts +15 -0
- package/dist/features/sync/source-writes.js +27 -0
- package/dist/features/sync/synthetic-seed.d.ts +26 -0
- package/dist/features/sync/synthetic-seed.js +83 -0
- package/dist/features/viewer/manifest.d.ts +148 -0
- package/dist/features/viewer/manifest.js +165 -0
- package/dist/fs-utils.d.ts +1 -0
- package/dist/fs-utils.js +1 -0
- package/dist/generate/hono/app.d.ts +6 -0
- package/dist/generate/hono/app.js +51 -0
- package/dist/generate/hono/graphql.d.ts +7 -0
- package/dist/generate/hono/graphql.js +53 -0
- package/dist/generate/hono/index.d.ts +55 -0
- package/dist/generate/hono/index.js +140 -0
- package/dist/generate/hono/package.d.ts +6 -0
- package/dist/generate/hono/package.js +44 -0
- package/dist/generate/hono/readme.d.ts +13 -0
- package/dist/generate/hono/readme.js +28 -0
- package/dist/generate/hono/repository.d.ts +1 -0
- package/dist/generate/hono/repository.js +27 -0
- package/dist/generate/hono/rest.d.ts +1 -0
- package/dist/generate/hono/rest.js +38 -0
- package/dist/generate/hono/schema.d.ts +13 -0
- package/dist/generate/hono/schema.js +18 -0
- package/dist/generate/hono/sqlite.d.ts +20 -0
- package/dist/generate/hono/sqlite.js +266 -0
- package/dist/generate/hono/validators.d.ts +1 -0
- package/dist/generate/hono/validators.js +141 -0
- package/dist/generate/hono.d.ts +1 -0
- package/dist/generate/hono.js +1 -0
- package/dist/graphql/execute.d.ts +14 -0
- package/dist/graphql/execute.js +719 -0
- package/dist/graphql/http.d.ts +15 -0
- package/dist/graphql/http.js +29 -0
- package/dist/graphql/index.d.ts +3 -0
- package/dist/graphql/index.js +3 -0
- package/dist/graphql/parser.d.ts +54 -0
- package/dist/graphql/parser.js +433 -0
- package/dist/hono.d.ts +77 -0
- package/dist/hono.js +1 -0
- package/dist/index.d.ts +1065 -0
- package/dist/index.js +14 -0
- package/dist/integrations/hono.d.ts +136 -0
- package/dist/integrations/hono.js +508 -0
- package/dist/integrations/kv.d.ts +69 -0
- package/dist/integrations/kv.js +69 -0
- package/dist/integrations/postgres.d.ts +52 -0
- package/dist/integrations/postgres.js +113 -0
- package/dist/integrations/sqlite.d.ts +112 -0
- package/dist/integrations/sqlite.js +489 -0
- package/dist/integrations/vite.d.ts +45 -0
- package/dist/integrations/vite.js +111 -0
- package/dist/json.d.ts +48 -0
- package/dist/json.js +1 -0
- package/dist/jsonc.d.ts +1 -0
- package/dist/jsonc.js +1 -0
- package/dist/kv.d.ts +24 -0
- package/dist/kv.js +1 -0
- package/dist/mock.d.ts +1 -0
- package/dist/mock.js +1 -0
- package/dist/names.d.ts +1 -0
- package/dist/names.js +1 -0
- package/dist/operations.d.ts +3 -0
- package/dist/operations.js +3 -0
- package/dist/postgres.d.ts +24 -0
- package/dist/postgres.js +1 -0
- package/dist/redis.d.ts +14 -0
- package/dist/redis.js +1 -0
- package/dist/rest/formats.d.ts +80 -0
- package/dist/rest/formats.js +318 -0
- package/dist/rest/handler.d.ts +111 -0
- package/dist/rest/handler.js +833 -0
- package/dist/rest/shape.d.ts +33 -0
- package/dist/rest/shape.js +218 -0
- package/dist/schema-builders.d.ts +1 -0
- package/dist/schema-builders.js +1 -0
- package/dist/schema-manifest.d.ts +1 -0
- package/dist/schema-manifest.js +1 -0
- package/dist/schema.d.ts +193 -0
- package/dist/schema.js +6 -0
- package/dist/server.d.ts +116 -0
- package/dist/server.js +601 -0
- package/dist/shared/csv.d.ts +8 -0
- package/dist/shared/csv.js +149 -0
- package/dist/shared/errors.d.ts +40 -0
- package/dist/shared/errors.js +55 -0
- package/dist/shared/fs-utils.d.ts +4 -0
- package/dist/shared/fs-utils.js +30 -0
- package/dist/shared/jsonc.d.ts +2 -0
- package/dist/shared/jsonc.js +99 -0
- package/dist/shared/mock.d.ts +40 -0
- package/dist/shared/mock.js +83 -0
- package/dist/shared/names.d.ts +28 -0
- package/dist/shared/names.js +127 -0
- package/dist/shared/operations.d.ts +32 -0
- package/dist/shared/operations.js +302 -0
- package/dist/sqlite.d.ts +24 -0
- package/dist/sqlite.js +1 -0
- package/dist/state.d.ts +1 -0
- package/dist/state.js +1 -0
- package/dist/sync.d.ts +1 -0
- package/dist/sync.js +1 -0
- package/dist/tracing.d.ts +95 -0
- package/dist/tracing.js +260 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.js +285 -0
- package/dist/viewer-manifest.d.ts +1 -0
- package/dist/viewer-manifest.js +1 -0
- package/dist/vite.d.ts +59 -0
- package/dist/vite.js +1 -0
- package/dist/web/json-viewer.d.ts +5 -0
- package/dist/web/json-viewer.js +176 -0
- package/dist/web/viewer.d.ts +12 -0
- package/dist/web/viewer.js +1015 -0
- package/docs/README.md +42 -0
- package/docs/architecture.md +112 -0
- package/docs/ci-and-release.md +177 -0
- package/docs/cms-storage-patterns.md +108 -0
- package/docs/concepts.md +141 -0
- package/docs/configuration.md +552 -0
- package/docs/fixtures-and-schemas.md +527 -0
- package/docs/fork-branch-workflows.md +108 -0
- package/docs/generated-files.md +174 -0
- package/docs/getting-started.md +165 -0
- package/docs/integrations.md +206 -0
- package/docs/json-production.md +120 -0
- package/docs/package-api.md +418 -0
- package/docs/prototype-to-production.md +378 -0
- package/docs/server-and-viewer.md +466 -0
- package/docs/store-graduation.md +120 -0
- package/docs/typescript-schema-sources.md +79 -0
- package/examples/advanced/README.md +55 -0
- package/examples/advanced/db/projects.schema.jsonc +44 -0
- package/examples/advanced/db/settings.jsonc +9 -0
- package/examples/advanced/db/users.json +23 -0
- package/examples/advanced/db/users.schema.mjs +31 -0
- package/examples/advanced/db.config.mjs +18 -0
- package/examples/advanced/example.json +5 -0
- package/examples/advanced/src/generated/db.types.d.ts +64 -0
- package/examples/basic/README.md +95 -0
- package/examples/basic/db/operations/get-user.jsonc +8 -0
- package/examples/basic/db/settings.json +7 -0
- package/examples/basic/db/users.schema.jsonc +36 -0
- package/examples/basic/db.config.mjs +68 -0
- package/examples/basic/example.json +5 -0
- package/examples/basic/src/generated/db.types.d.ts +39 -0
- package/examples/cms-json-publish/README.md +21 -0
- package/examples/cms-json-publish/db/navigation.json +7 -0
- package/examples/cms-json-publish/db/pages.json +18 -0
- package/examples/cms-json-publish/example.json +5 -0
- package/examples/cms-json-publish/src/cms.mjs +104 -0
- package/examples/computed-fields/README.md +93 -0
- package/examples/computed-fields/db/orders.schema.mjs +62 -0
- package/examples/computed-fields/db/posts.schema.mjs +59 -0
- package/examples/computed-fields/db/products.schema.mjs +39 -0
- package/examples/computed-fields/db/users.schema.mjs +43 -0
- package/examples/computed-fields/db.config.mjs +15 -0
- package/examples/computed-fields/example.json +5 -0
- package/examples/computed-fields/src/generated/db.types.d.ts +81 -0
- package/examples/content-collections/README.md +91 -0
- package/examples/content-collections/db/authors.json +12 -0
- package/examples/content-collections/db/authors.schema.mjs +20 -0
- package/examples/content-collections/db/blog/draft-roadmap.mdx +12 -0
- package/examples/content-collections/db/blog/index.schema.mjs +61 -0
- package/examples/content-collections/db/blog/launch-notes.mdx +15 -0
- package/examples/content-collections/db/docs/index.schema.mjs +32 -0
- package/examples/content-collections/db/docs/intro.mdx +11 -0
- package/examples/content-collections/db/docs/schema-workflow.mdx +10 -0
- package/examples/content-collections/db/site.schema.jsonc +21 -0
- package/examples/content-collections/db.config.mjs +26 -0
- package/examples/content-collections/example.json +5 -0
- package/examples/content-collections/src/content-preview.mjs +66 -0
- package/examples/content-collections/src/generated/db.types.d.ts +81 -0
- package/examples/csv/README.md +52 -0
- package/examples/csv/db/customers.csv +4 -0
- package/examples/csv/db.config.mjs +13 -0
- package/examples/csv/example.json +5 -0
- package/examples/data-first/README.md +54 -0
- package/examples/data-first/db/posts.json +16 -0
- package/examples/data-first/db/settings.json +8 -0
- package/examples/data-first/db/users.json +14 -0
- package/examples/data-first/db.config.mjs +13 -0
- package/examples/data-first/example.json +5 -0
- package/examples/diagnostics/README.md +55 -0
- package/examples/diagnostics/db/projects.schema.jsonc +27 -0
- package/examples/diagnostics/db/users.json +9 -0
- package/examples/diagnostics/db/users.schema.jsonc +23 -0
- package/examples/diagnostics/db.config.mjs +16 -0
- package/examples/diagnostics/example.json +5 -0
- package/examples/free-plan-upgrade/README.md +22 -0
- package/examples/free-plan-upgrade/db/appSettings.json +4 -0
- package/examples/free-plan-upgrade/db/projects.json +7 -0
- package/examples/free-plan-upgrade/example.json +5 -0
- package/examples/free-plan-upgrade/src/upgrade-tenant-to-paid.mjs +105 -0
- package/examples/hono-auth/README.md +74 -0
- package/examples/hono-auth/db/pages.schema.jsonc +44 -0
- package/examples/hono-auth/db/users.schema.jsonc +42 -0
- package/examples/hono-auth/db.config.mjs +17 -0
- package/examples/hono-auth/example.json +5 -0
- package/examples/hono-auth/package.json +14 -0
- package/examples/hono-auth/src/app.mjs +79 -0
- package/examples/hono-auth/src/server.mjs +13 -0
- package/examples/production-json/README.md +102 -0
- package/examples/production-json/db/appSettings.schema.jsonc +41 -0
- package/examples/production-json/db/featureFlags.schema.jsonc +84 -0
- package/examples/production-json/db/operations/get-control-plane.jsonc +6 -0
- package/examples/production-json/db/operations/get-feature-flag.jsonc +9 -0
- package/examples/production-json/db/operations/list-feature-flags.jsonc +8 -0
- package/examples/production-json/db/operations/read-public-settings.jsonc +8 -0
- package/examples/production-json/db.config.mjs +33 -0
- package/examples/production-json/example.json +5 -0
- package/examples/production-json/src/client-demo.mjs +28 -0
- package/examples/production-json/src/generated/db.types.d.ts +60 -0
- package/examples/relations/README.md +56 -0
- package/examples/relations/db/posts.schema.jsonc +46 -0
- package/examples/relations/db/users.schema.jsonc +34 -0
- package/examples/relations/db.config.mjs +13 -0
- package/examples/relations/example.json +5 -0
- package/examples/rest-client/README.md +54 -0
- package/examples/rest-client/db/settings.json +5 -0
- package/examples/rest-client/db/users.schema.jsonc +42 -0
- package/examples/rest-client/db.config.mjs +13 -0
- package/examples/rest-client/example.json +5 -0
- package/examples/rest-client/src/client-demo.mjs +24 -0
- package/examples/schema-first/README.md +55 -0
- package/examples/schema-first/db/auditEvents.schema.jsonc +24 -0
- package/examples/schema-first/db/settings.schema.jsonc +29 -0
- package/examples/schema-first/db/users.schema.jsonc +36 -0
- package/examples/schema-first/db.config.mjs +15 -0
- package/examples/schema-first/example.json +5 -0
- package/examples/schema-first/src/generated/db.types.d.ts +47 -0
- package/examples/schema-manifest/README.md +50 -0
- package/examples/schema-manifest/db/projects.schema.jsonc +48 -0
- package/examples/schema-manifest/db/users.schema.jsonc +35 -0
- package/examples/schema-manifest/db.config.mjs +41 -0
- package/examples/schema-manifest/example.json +5 -0
- package/examples/schema-manifest/src/generated/db.schema.json +130 -0
- package/examples/schema-manifest/src/generated/db.types.d.ts +50 -0
- package/examples/schema-ui/README.md +103 -0
- package/examples/schema-ui/db/pages.schema.jsonc +53 -0
- package/examples/schema-ui/db/users.schema.jsonc +30 -0
- package/examples/schema-ui/db.config.mjs +55 -0
- package/examples/schema-ui/example.json +5 -0
- package/examples/schema-ui/src/cms-ssr.mjs +276 -0
- package/examples/schema-ui/src/generated/db.schema.json +133 -0
- package/examples/schema-ui/src/generated/db.types.d.ts +46 -0
- package/examples/schema-ui/src/render-admin.mjs +175 -0
- package/examples/schema-ui/src/schema-ui-ssr-handler.mjs +149 -0
- package/examples/schema-ui/src/start-schema-ui-server.mjs +140 -0
- package/examples/standard-schema/README.md +55 -0
- package/examples/standard-schema/db/settings.schema.mjs +22 -0
- package/examples/standard-schema/db/users.schema.mjs +72 -0
- package/examples/standard-schema/example.json +5 -0
- package/package.json +108 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type GraphqlHttpDb = {
|
|
2
|
+
config: {
|
|
3
|
+
server?: {
|
|
4
|
+
maxBodyBytes?: number;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
resources: Map<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
type GraphqlHttpRequest = {
|
|
10
|
+
method?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
type GraphqlHttpResponse = Record<string, unknown>;
|
|
14
|
+
export declare function handleGraphqlRequest(db: GraphqlHttpDb, request: GraphqlHttpRequest, response: GraphqlHttpResponse): Promise<void>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { makeGeneratedSchema } from '../schema.js';
|
|
2
|
+
import { serializeError } from '../errors.js';
|
|
3
|
+
import { readJsonBody, sendJson, sendText } from '../rest/handler.js';
|
|
4
|
+
import { executeGraphql } from './execute.js';
|
|
5
|
+
export async function handleGraphqlRequest(db, request, response) {
|
|
6
|
+
try {
|
|
7
|
+
await handleGraphqlRequestUnsafe(db, request, response);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
sendJson(response, error.status ?? 500, serializeError(error, 'GRAPHQL_HTTP_ERROR'));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function handleGraphqlRequestUnsafe(db, request, response) {
|
|
14
|
+
if (request.method === 'GET') {
|
|
15
|
+
const schema = makeGeneratedSchema([...db.resources.values()]);
|
|
16
|
+
sendText(response, 200, schema.graphql, 'text/plain; charset=utf-8');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (request.method === 'POST') {
|
|
20
|
+
const body = await readJsonBody(request, {
|
|
21
|
+
maxBytes: Number(db.config.server?.maxBodyBytes ?? 1048576),
|
|
22
|
+
});
|
|
23
|
+
sendJson(response, 200, await executeGraphql(db, body));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
sendJson(response, 405, {
|
|
27
|
+
error: 'Method not allowed',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type GraphqlToken = {
|
|
2
|
+
type: 'name' | 'number' | 'punctuation' | 'string' | 'eof';
|
|
3
|
+
value: string;
|
|
4
|
+
};
|
|
5
|
+
export type GraphqlValueNode = {
|
|
6
|
+
kind: 'variable';
|
|
7
|
+
name: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'literal';
|
|
10
|
+
value: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'list';
|
|
13
|
+
values: GraphqlValueNode[];
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'object';
|
|
16
|
+
fields: Record<string, GraphqlValueNode>;
|
|
17
|
+
};
|
|
18
|
+
export type GraphqlDirectiveNode = {
|
|
19
|
+
kind: 'directive';
|
|
20
|
+
name: string;
|
|
21
|
+
arguments: Record<string, GraphqlValueNode>;
|
|
22
|
+
};
|
|
23
|
+
export type GraphqlSelectionNode = {
|
|
24
|
+
kind: 'field' | 'fragment_spread' | 'inline_fragment';
|
|
25
|
+
alias?: string | null;
|
|
26
|
+
name?: string;
|
|
27
|
+
typeCondition?: string;
|
|
28
|
+
arguments?: Record<string, GraphqlValueNode>;
|
|
29
|
+
directives?: GraphqlDirectiveNode[];
|
|
30
|
+
selectionSet?: GraphqlSelectionNode[] | null;
|
|
31
|
+
};
|
|
32
|
+
export type GraphqlOperationNode = {
|
|
33
|
+
kind: 'operation';
|
|
34
|
+
operation: string;
|
|
35
|
+
name: string | null;
|
|
36
|
+
directives: GraphqlDirectiveNode[];
|
|
37
|
+
selectionSet: GraphqlSelectionNode[];
|
|
38
|
+
};
|
|
39
|
+
export type GraphqlFragmentDefinition = {
|
|
40
|
+
kind: 'fragment_definition';
|
|
41
|
+
name: string;
|
|
42
|
+
typeCondition: string;
|
|
43
|
+
directives: GraphqlDirectiveNode[];
|
|
44
|
+
selectionSet: GraphqlSelectionNode[];
|
|
45
|
+
};
|
|
46
|
+
export type GraphqlDocumentNode = {
|
|
47
|
+
kind: 'document';
|
|
48
|
+
operation: string;
|
|
49
|
+
name: string | null;
|
|
50
|
+
selectionSet: GraphqlSelectionNode[];
|
|
51
|
+
operations: GraphqlOperationNode[];
|
|
52
|
+
fragments: Record<string, GraphqlFragmentDefinition>;
|
|
53
|
+
};
|
|
54
|
+
export declare function parseGraphql(source: string): GraphqlDocumentNode;
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { dbError } from '../errors.js';
|
|
2
|
+
export function parseGraphql(source) {
|
|
3
|
+
const parser = new Parser(tokenize(source));
|
|
4
|
+
return parser.parseDocument();
|
|
5
|
+
}
|
|
6
|
+
class Parser {
|
|
7
|
+
tokens;
|
|
8
|
+
index;
|
|
9
|
+
constructor(tokens) {
|
|
10
|
+
this.tokens = tokens;
|
|
11
|
+
this.index = 0;
|
|
12
|
+
}
|
|
13
|
+
parseDocument() {
|
|
14
|
+
const operations = [];
|
|
15
|
+
const fragments = {};
|
|
16
|
+
while (!this.peekValue('<eof>')) {
|
|
17
|
+
if (this.peekName('fragment')) {
|
|
18
|
+
const fragment = this.parseFragmentDefinition();
|
|
19
|
+
fragments[fragment.name] = fragment;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
operations.push(this.parseOperationDefinition());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const firstOperation = operations[0] ?? {
|
|
26
|
+
kind: 'operation',
|
|
27
|
+
operation: 'query',
|
|
28
|
+
name: null,
|
|
29
|
+
directives: [],
|
|
30
|
+
selectionSet: [],
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
kind: 'document',
|
|
34
|
+
operation: firstOperation.operation,
|
|
35
|
+
name: firstOperation.name,
|
|
36
|
+
selectionSet: firstOperation.selectionSet,
|
|
37
|
+
operations,
|
|
38
|
+
fragments,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
parseOperationDefinition() {
|
|
42
|
+
let operation = 'query';
|
|
43
|
+
let name = null;
|
|
44
|
+
if (this.peekValue('{')) {
|
|
45
|
+
return {
|
|
46
|
+
kind: 'operation',
|
|
47
|
+
operation,
|
|
48
|
+
name,
|
|
49
|
+
directives: [],
|
|
50
|
+
selectionSet: this.parseSelectionSet(),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (this.peekName('query') || this.peekName('mutation')) {
|
|
54
|
+
operation = this.consume().value;
|
|
55
|
+
if (this.peek().type === 'name') {
|
|
56
|
+
name = this.consume().value;
|
|
57
|
+
}
|
|
58
|
+
if (this.peekValue('(')) {
|
|
59
|
+
this.skipBalanced('(', ')');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (this.peekName('subscription')) {
|
|
63
|
+
throw dbError('GRAPHQL_SUBSCRIPTION_UNSUPPORTED', 'GraphQL subscriptions are not supported by db.', {
|
|
64
|
+
hint: 'Use query or mutation operations. db is a local fixture server and does not keep long-lived subscription streams.',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw dbError('GRAPHQL_PARSE_EXPECTED_OPERATION', `Expected GraphQL operation or fragment but found "${this.peek().value}".`, {
|
|
69
|
+
hint: 'Start the document with "{", "query", "mutation", or "fragment".',
|
|
70
|
+
details: { found: this.peek().value },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const directives = this.parseDirectives();
|
|
74
|
+
return {
|
|
75
|
+
kind: 'operation',
|
|
76
|
+
operation,
|
|
77
|
+
name,
|
|
78
|
+
directives,
|
|
79
|
+
selectionSet: this.parseSelectionSet(),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
parseFragmentDefinition() {
|
|
83
|
+
this.expectNameValue('fragment');
|
|
84
|
+
const name = this.expectName();
|
|
85
|
+
this.expectNameValue('on');
|
|
86
|
+
const typeCondition = this.expectName();
|
|
87
|
+
const directives = this.parseDirectives();
|
|
88
|
+
return {
|
|
89
|
+
kind: 'fragment_definition',
|
|
90
|
+
name,
|
|
91
|
+
typeCondition,
|
|
92
|
+
directives,
|
|
93
|
+
selectionSet: this.parseSelectionSet(),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
parseSelectionSet() {
|
|
97
|
+
this.expect('{');
|
|
98
|
+
const selections = [];
|
|
99
|
+
while (!this.peekValue('}')) {
|
|
100
|
+
selections.push(this.parseSelection());
|
|
101
|
+
}
|
|
102
|
+
this.expect('}');
|
|
103
|
+
return selections;
|
|
104
|
+
}
|
|
105
|
+
parseSelection() {
|
|
106
|
+
if (this.peekValue('...')) {
|
|
107
|
+
return this.parseFragmentSelection();
|
|
108
|
+
}
|
|
109
|
+
return this.parseField();
|
|
110
|
+
}
|
|
111
|
+
parseFragmentSelection() {
|
|
112
|
+
this.expect('...');
|
|
113
|
+
if (this.peekName('on')) {
|
|
114
|
+
this.consume();
|
|
115
|
+
const typeCondition = this.expectName();
|
|
116
|
+
const directives = this.parseDirectives();
|
|
117
|
+
return {
|
|
118
|
+
kind: 'inline_fragment',
|
|
119
|
+
typeCondition,
|
|
120
|
+
directives,
|
|
121
|
+
selectionSet: this.parseSelectionSet(),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const name = this.expectName();
|
|
125
|
+
const directives = this.parseDirectives();
|
|
126
|
+
return {
|
|
127
|
+
kind: 'fragment_spread',
|
|
128
|
+
name,
|
|
129
|
+
directives,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
parseField() {
|
|
133
|
+
const firstName = this.expectName();
|
|
134
|
+
let alias = null;
|
|
135
|
+
let name = firstName;
|
|
136
|
+
if (this.peekValue(':')) {
|
|
137
|
+
this.consume();
|
|
138
|
+
alias = firstName;
|
|
139
|
+
name = this.expectName();
|
|
140
|
+
}
|
|
141
|
+
const args = this.peekValue('(') ? this.parseArguments() : {};
|
|
142
|
+
const directives = this.parseDirectives();
|
|
143
|
+
const selectionSet = this.peekValue('{') ? this.parseSelectionSet() : null;
|
|
144
|
+
return {
|
|
145
|
+
kind: 'field',
|
|
146
|
+
alias,
|
|
147
|
+
name,
|
|
148
|
+
arguments: args,
|
|
149
|
+
directives,
|
|
150
|
+
selectionSet,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
parseDirectives() {
|
|
154
|
+
const directives = [];
|
|
155
|
+
while (this.peekValue('@')) {
|
|
156
|
+
this.consume();
|
|
157
|
+
const name = this.expectName();
|
|
158
|
+
directives.push({
|
|
159
|
+
kind: 'directive',
|
|
160
|
+
name,
|
|
161
|
+
arguments: this.peekValue('(') ? this.parseArguments() : {},
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return directives;
|
|
165
|
+
}
|
|
166
|
+
parseArguments() {
|
|
167
|
+
this.expect('(');
|
|
168
|
+
const args = {};
|
|
169
|
+
while (!this.peekValue(')')) {
|
|
170
|
+
const name = this.expectName();
|
|
171
|
+
this.expect(':');
|
|
172
|
+
args[name] = this.parseValue();
|
|
173
|
+
}
|
|
174
|
+
this.expect(')');
|
|
175
|
+
return args;
|
|
176
|
+
}
|
|
177
|
+
parseValue() {
|
|
178
|
+
const token = this.peek();
|
|
179
|
+
if (token.value === '$') {
|
|
180
|
+
this.consume();
|
|
181
|
+
return {
|
|
182
|
+
kind: 'variable',
|
|
183
|
+
name: this.expectName(),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
if (token.type === 'string') {
|
|
187
|
+
return {
|
|
188
|
+
kind: 'literal',
|
|
189
|
+
value: this.consume().value,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if (token.type === 'number') {
|
|
193
|
+
return {
|
|
194
|
+
kind: 'literal',
|
|
195
|
+
value: this.consume().value.includes('.') ? Number.parseFloat(token.value) : Number.parseInt(token.value, 10),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (token.type === 'name') {
|
|
199
|
+
const value = this.consume().value;
|
|
200
|
+
if (value === 'true') {
|
|
201
|
+
return { kind: 'literal', value: true };
|
|
202
|
+
}
|
|
203
|
+
if (value === 'false') {
|
|
204
|
+
return { kind: 'literal', value: false };
|
|
205
|
+
}
|
|
206
|
+
if (value === 'null') {
|
|
207
|
+
return { kind: 'literal', value: null };
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
kind: 'literal',
|
|
211
|
+
value,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (token.value === '[') {
|
|
215
|
+
return this.parseList();
|
|
216
|
+
}
|
|
217
|
+
if (token.value === '{') {
|
|
218
|
+
return this.parseObject();
|
|
219
|
+
}
|
|
220
|
+
throw dbError('GRAPHQL_PARSE_UNEXPECTED_VALUE', `Unexpected GraphQL value token "${token.value}".`, {
|
|
221
|
+
hint: 'Use a string, number, boolean, null, variable, list, or object literal for argument values.',
|
|
222
|
+
details: { token: token.value },
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
parseList() {
|
|
226
|
+
this.expect('[');
|
|
227
|
+
const values = [];
|
|
228
|
+
while (!this.peekValue(']')) {
|
|
229
|
+
values.push(this.parseValue());
|
|
230
|
+
}
|
|
231
|
+
this.expect(']');
|
|
232
|
+
return {
|
|
233
|
+
kind: 'list',
|
|
234
|
+
values,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
parseObject() {
|
|
238
|
+
this.expect('{');
|
|
239
|
+
const fields = {};
|
|
240
|
+
while (!this.peekValue('}')) {
|
|
241
|
+
const name = this.expectName();
|
|
242
|
+
this.expect(':');
|
|
243
|
+
fields[name] = this.parseValue();
|
|
244
|
+
}
|
|
245
|
+
this.expect('}');
|
|
246
|
+
return {
|
|
247
|
+
kind: 'object',
|
|
248
|
+
fields,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
skipBalanced(open, close) {
|
|
252
|
+
this.expect(open);
|
|
253
|
+
let depth = 1;
|
|
254
|
+
while (depth > 0) {
|
|
255
|
+
const token = this.consume();
|
|
256
|
+
if (token.type === 'eof') {
|
|
257
|
+
throw dbError('GRAPHQL_PARSE_UNTERMINATED_GROUP', `Unterminated GraphQL group "${open}".`, {
|
|
258
|
+
hint: `Add the matching "${close}" before the end of the query.`,
|
|
259
|
+
details: { open, close },
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
if (token.value === open) {
|
|
263
|
+
depth += 1;
|
|
264
|
+
}
|
|
265
|
+
if (token.value === close) {
|
|
266
|
+
depth -= 1;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
expect(value) {
|
|
271
|
+
const token = this.consume();
|
|
272
|
+
if (token.value !== value) {
|
|
273
|
+
throw dbError('GRAPHQL_PARSE_EXPECTED_TOKEN', `Expected GraphQL token "${value}" but found "${token.value}".`, {
|
|
274
|
+
hint: 'Check the query punctuation near this token. Common causes are missing braces, parentheses, or colons.',
|
|
275
|
+
details: { expected: value, found: token.value },
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return token;
|
|
279
|
+
}
|
|
280
|
+
expectName() {
|
|
281
|
+
const token = this.consume();
|
|
282
|
+
if (token.type !== 'name') {
|
|
283
|
+
throw dbError('GRAPHQL_PARSE_EXPECTED_NAME', `Expected a GraphQL name but found "${token.value}".`, {
|
|
284
|
+
hint: 'Field names, aliases, arguments, and operation names must use GraphQL identifier syntax.',
|
|
285
|
+
details: { found: token.value },
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return token.value;
|
|
289
|
+
}
|
|
290
|
+
expectNameValue(value) {
|
|
291
|
+
const name = this.expectName();
|
|
292
|
+
if (name !== value) {
|
|
293
|
+
throw dbError('GRAPHQL_PARSE_EXPECTED_NAME_VALUE', `Expected GraphQL name "${value}" but found "${name}".`, {
|
|
294
|
+
hint: `Use "${value}" in this part of the GraphQL document.`,
|
|
295
|
+
details: { expected: value, found: name },
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
return name;
|
|
299
|
+
}
|
|
300
|
+
peekName(name) {
|
|
301
|
+
const token = this.peek();
|
|
302
|
+
return token.type === 'name' && token.value === name;
|
|
303
|
+
}
|
|
304
|
+
peekValue(value) {
|
|
305
|
+
return this.peek().value === value;
|
|
306
|
+
}
|
|
307
|
+
peek() {
|
|
308
|
+
return this.tokens[this.index] ?? { type: 'eof', value: '<eof>' };
|
|
309
|
+
}
|
|
310
|
+
consume() {
|
|
311
|
+
const token = this.peek();
|
|
312
|
+
this.index += 1;
|
|
313
|
+
return token;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function tokenize(source) {
|
|
317
|
+
const tokens = [];
|
|
318
|
+
let index = 0;
|
|
319
|
+
while (index < source.length) {
|
|
320
|
+
const char = source[index];
|
|
321
|
+
if (/\s|,/.test(char)) {
|
|
322
|
+
index += 1;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (char === '#') {
|
|
326
|
+
while (index < source.length && source[index] !== '\n') {
|
|
327
|
+
index += 1;
|
|
328
|
+
}
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (source.startsWith('...', index)) {
|
|
332
|
+
tokens.push({ type: 'punctuation', value: '...' });
|
|
333
|
+
index += 3;
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if ('{}():[]!$=@'.includes(char)) {
|
|
337
|
+
tokens.push({ type: 'punctuation', value: char });
|
|
338
|
+
index += 1;
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (char === '"') {
|
|
342
|
+
const result = readString(source, index);
|
|
343
|
+
tokens.push({ type: 'string', value: result.value });
|
|
344
|
+
index = result.index;
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (char === '-' || /\d/.test(char)) {
|
|
348
|
+
const result = readNumber(source, index);
|
|
349
|
+
tokens.push({ type: 'number', value: result.value });
|
|
350
|
+
index = result.index;
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (/[A-Za-z_]/.test(char)) {
|
|
354
|
+
const result = readName(source, index);
|
|
355
|
+
tokens.push({ type: 'name', value: result.value });
|
|
356
|
+
index = result.index;
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
throw dbError('GRAPHQL_PARSE_UNEXPECTED_CHARACTER', `Unexpected GraphQL character "${char}".`, {
|
|
360
|
+
hint: 'db supports a focused GraphQL subset. Check for unsupported punctuation, fragments, or directives.',
|
|
361
|
+
details: { character: char, index },
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
tokens.push({ type: 'eof', value: '<eof>' });
|
|
365
|
+
return tokens;
|
|
366
|
+
}
|
|
367
|
+
function readString(source, start) {
|
|
368
|
+
let value = '';
|
|
369
|
+
let index = start + 1;
|
|
370
|
+
let escaping = false;
|
|
371
|
+
while (index < source.length) {
|
|
372
|
+
const char = source[index];
|
|
373
|
+
if (escaping) {
|
|
374
|
+
value += decodeEscape(char);
|
|
375
|
+
escaping = false;
|
|
376
|
+
index += 1;
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (char === '\\') {
|
|
380
|
+
escaping = true;
|
|
381
|
+
index += 1;
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (char === '"') {
|
|
385
|
+
return {
|
|
386
|
+
value,
|
|
387
|
+
index: index + 1,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
value += char;
|
|
391
|
+
index += 1;
|
|
392
|
+
}
|
|
393
|
+
throw dbError('GRAPHQL_PARSE_UNTERMINATED_STRING', 'Unterminated GraphQL string.', {
|
|
394
|
+
hint: 'Close the string with a double quote, or escape embedded quotes with \\".',
|
|
395
|
+
details: { start },
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
function readNumber(source, start) {
|
|
399
|
+
let index = start;
|
|
400
|
+
while (index < source.length && /[-0-9.]/.test(source[index])) {
|
|
401
|
+
index += 1;
|
|
402
|
+
}
|
|
403
|
+
return {
|
|
404
|
+
value: source.slice(start, index),
|
|
405
|
+
index,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function readName(source, start) {
|
|
409
|
+
let index = start;
|
|
410
|
+
while (index < source.length && /[A-Za-z0-9_]/.test(source[index])) {
|
|
411
|
+
index += 1;
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
value: source.slice(start, index),
|
|
415
|
+
index,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function decodeEscape(char) {
|
|
419
|
+
switch (char) {
|
|
420
|
+
case 'n':
|
|
421
|
+
return '\n';
|
|
422
|
+
case 'r':
|
|
423
|
+
return '\r';
|
|
424
|
+
case 't':
|
|
425
|
+
return '\t';
|
|
426
|
+
case '"':
|
|
427
|
+
case '\\':
|
|
428
|
+
case '/':
|
|
429
|
+
return char;
|
|
430
|
+
default:
|
|
431
|
+
return char;
|
|
432
|
+
}
|
|
433
|
+
}
|
package/dist/hono.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { DbOperationsOptions, DbOptions, DbTraceOptions } from './index.d.ts';
|
|
2
|
+
|
|
3
|
+
export type DbHonoOptions = DbOptions & {
|
|
4
|
+
api?: Array<'rest' | 'graphql'> | 'rest' | 'graphql' | 'rest,graphql';
|
|
5
|
+
graphqlPath?: string;
|
|
6
|
+
/** Explicit request trace option for generated Hono REST routes. Wins over db.config.mjs server.trace. */
|
|
7
|
+
trace?: DbTraceOptions;
|
|
8
|
+
restRoutes?: DbHonoRestRoutesOptions;
|
|
9
|
+
storage?: {
|
|
10
|
+
kind?: 'db' | 'sqlite';
|
|
11
|
+
file?: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type DbHonoRestMethod = 'list' | 'get' | 'create' | 'patch' | 'delete' | 'put';
|
|
16
|
+
|
|
17
|
+
export type DbHonoRestHookContext = {
|
|
18
|
+
c: unknown;
|
|
19
|
+
db: unknown;
|
|
20
|
+
resource: Record<string, unknown>;
|
|
21
|
+
resourceName: string;
|
|
22
|
+
method: DbHonoRestMethod;
|
|
23
|
+
id?: string;
|
|
24
|
+
body?: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type DbHonoOperationHookContext = {
|
|
28
|
+
c: unknown;
|
|
29
|
+
db: unknown;
|
|
30
|
+
resource: null;
|
|
31
|
+
resourceName: null;
|
|
32
|
+
method: 'operation';
|
|
33
|
+
ref: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type DbHonoBeforeRequestHookContext = DbHonoRestHookContext | DbHonoOperationHookContext;
|
|
37
|
+
|
|
38
|
+
export type DbHonoRestHook = (context: DbHonoRestHookContext) => unknown | Promise<unknown>;
|
|
39
|
+
export type DbHonoBeforeRequestHook = (context: DbHonoBeforeRequestHookContext) => unknown | Promise<unknown>;
|
|
40
|
+
|
|
41
|
+
export type DbHonoRestHooks = {
|
|
42
|
+
beforeList?: DbHonoRestHook;
|
|
43
|
+
beforeGet?: DbHonoRestHook;
|
|
44
|
+
beforeCreate?: DbHonoRestHook;
|
|
45
|
+
beforePatch?: DbHonoRestHook;
|
|
46
|
+
beforeDelete?: DbHonoRestHook;
|
|
47
|
+
beforePut?: DbHonoRestHook;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type DbHonoRestLifecycleHooks = {
|
|
51
|
+
beforeRequest?: DbHonoBeforeRequestHook;
|
|
52
|
+
beforeWrite?: DbHonoRestHook;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type DbHonoRestResourceOptions = false | {
|
|
56
|
+
methods?: DbHonoRestMethod[];
|
|
57
|
+
hooks?: DbHonoRestHooks;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type DbHonoRestRoutesOptions = {
|
|
61
|
+
prefix?: string;
|
|
62
|
+
/** Mount registered operation route. Defaults to "auto", which uses db.config.operations when enabled. */
|
|
63
|
+
operations?: 'auto' | boolean | DbOperationsOptions;
|
|
64
|
+
resources?: string[];
|
|
65
|
+
exclude?: string[];
|
|
66
|
+
methods?: DbHonoRestMethod[];
|
|
67
|
+
/** Explicit request trace option for registered Hono REST routes. Wins over db.config.mjs server.trace. */
|
|
68
|
+
trace?: DbTraceOptions;
|
|
69
|
+
hooks?: DbHonoRestHooks;
|
|
70
|
+
lifecycleHooks?: DbHonoRestLifecycleHooks;
|
|
71
|
+
resourceOptions?: Record<string, DbHonoRestResourceOptions>;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export function createDbHonoApp(options?: DbHonoOptions): Promise<unknown>;
|
|
75
|
+
export function createDbContext(options?: DbHonoOptions): Promise<unknown>;
|
|
76
|
+
export function dbContext(dbOrOptions?: unknown): unknown;
|
|
77
|
+
export function registerDbRoutes(app: unknown, db: unknown, options?: DbHonoRestRoutesOptions): void;
|
package/dist/hono.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createDbContext, createDbHonoApp, dbContext, registerDbRoutes } from './integrations/hono.js';
|