@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
package/dist/jsonc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseJsonc, stripJsonc } from './shared/jsonc.js';
|
package/dist/kv.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type KvStoreClient = {
|
|
2
|
+
get(key: string): unknown | Promise<unknown>;
|
|
3
|
+
set(key: string, value: string): unknown | Promise<unknown>;
|
|
4
|
+
close?: () => void | Promise<void>;
|
|
5
|
+
end?: () => void | Promise<void>;
|
|
6
|
+
quit?: () => void | Promise<void>;
|
|
7
|
+
disconnect?: () => void | Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type KvStoreOptions = {
|
|
11
|
+
client: KvStoreClient;
|
|
12
|
+
prefix?: string;
|
|
13
|
+
close?: boolean | ((client: KvStoreClient) => void | Promise<void>);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function kvStore(options: KvStoreOptions): unknown;
|
|
17
|
+
export const kvStoreCapabilities: {
|
|
18
|
+
writable: true;
|
|
19
|
+
persistence: 'kv';
|
|
20
|
+
atomicity: 'resource';
|
|
21
|
+
liveEvents: true;
|
|
22
|
+
staticExport: false;
|
|
23
|
+
production: 'small-app';
|
|
24
|
+
};
|
package/dist/kv.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { kvStore, kvStoreCapabilities, } from './integrations/kv.js';
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { normalizeMockDelay, pickDelayMs, runMockBehavior } from './shared/mock.js';
|
package/dist/mock.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { normalizeMockDelay, pickDelayMs, runMockBehavior } from './shared/mock.js';
|
package/dist/names.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { camelCase, kebabCase, pascalCase, resolveResource, resourceAliasCollisionGroups, resourceAliasCollisions, resourceConfigValue, resourceNameCandidates, routePathForResource, singularResourceName, typeNameForResource, } from './shared/names.js';
|
package/dist/names.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { camelCase, kebabCase, pascalCase, resolveResource, resourceAliasCollisionGroups, resourceAliasCollisions, resourceConfigValue, resourceNameCandidates, routePathForResource, singularResourceName, typeNameForResource, } from './shared/names.js';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { buildOperationManifest, hashOperation, operationClientContract } from './features/operations/index.js';
|
|
2
|
+
export { createDbOperationHandler } from './features/operations/runtime.js';
|
|
3
|
+
export { normalizeOperationTemplate, operationRequest } from './shared/operations.js';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { buildOperationManifest, hashOperation, operationClientContract } from './features/operations/index.js';
|
|
2
|
+
export { createDbOperationHandler } from './features/operations/runtime.js';
|
|
3
|
+
export { normalizeOperationTemplate, operationRequest } from './shared/operations.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type PostgresStoreClient = {
|
|
2
|
+
query(sql: string, params?: unknown[]): Promise<{ rows?: Array<Record<string, unknown>> }> | { rows?: Array<Record<string, unknown>> };
|
|
3
|
+
close?: () => void | Promise<void>;
|
|
4
|
+
end?: () => void | Promise<void>;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type PostgresStoreOptions = {
|
|
8
|
+
client: PostgresStoreClient;
|
|
9
|
+
schema?: string;
|
|
10
|
+
table?: string;
|
|
11
|
+
namespace?: string;
|
|
12
|
+
migrate?: boolean;
|
|
13
|
+
close?: boolean | ((client: PostgresStoreClient) => void | Promise<void>);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function postgresStore(options: PostgresStoreOptions): unknown;
|
|
17
|
+
export const postgresStoreCapabilities: {
|
|
18
|
+
writable: true;
|
|
19
|
+
persistence: 'postgres';
|
|
20
|
+
atomicity: 'resource';
|
|
21
|
+
liveEvents: true;
|
|
22
|
+
staticExport: false;
|
|
23
|
+
production: 'small-app';
|
|
24
|
+
};
|
package/dist/postgres.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { postgresStore, postgresStoreCapabilities, } from './integrations/postgres.js';
|
package/dist/redis.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { KvStoreClient, KvStoreOptions } from './kv.d.ts';
|
|
2
|
+
|
|
3
|
+
export type RedisStoreClient = KvStoreClient;
|
|
4
|
+
export type RedisStoreOptions = KvStoreOptions;
|
|
5
|
+
|
|
6
|
+
export function redisStore(options: RedisStoreOptions): unknown;
|
|
7
|
+
export const redisStoreCapabilities: {
|
|
8
|
+
writable: true;
|
|
9
|
+
persistence: 'kv';
|
|
10
|
+
atomicity: 'resource';
|
|
11
|
+
liveEvents: true;
|
|
12
|
+
staticExport: false;
|
|
13
|
+
production: 'small-app';
|
|
14
|
+
};
|
package/dist/redis.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { redisStore, redisStoreCapabilities, } from './integrations/kv.js';
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
type RestFormatTarget = 'resource' | 'manifest';
|
|
2
|
+
type RestResource = {
|
|
3
|
+
name: string;
|
|
4
|
+
kind?: string;
|
|
5
|
+
routePath?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
type RestRoutes = {
|
|
9
|
+
manifestPath?: string;
|
|
10
|
+
manifestJsonPath?: string;
|
|
11
|
+
manifestHtmlPath?: string;
|
|
12
|
+
manifestMarkdownPath?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
type RestRenderContext = {
|
|
16
|
+
db?: unknown;
|
|
17
|
+
resource?: RestResource;
|
|
18
|
+
resourceName?: string;
|
|
19
|
+
data: unknown;
|
|
20
|
+
manifest?: unknown;
|
|
21
|
+
format?: string;
|
|
22
|
+
request?: unknown;
|
|
23
|
+
url?: URL;
|
|
24
|
+
routes?: RestRoutes;
|
|
25
|
+
target?: RestFormatTarget;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
};
|
|
28
|
+
type RestRenderer = (context: RestRenderContext) => unknown;
|
|
29
|
+
type RestFormatObject = {
|
|
30
|
+
mediaTypes?: string | string[];
|
|
31
|
+
contentType?: string;
|
|
32
|
+
render?: RestRenderer;
|
|
33
|
+
renderResource?: RestRenderer;
|
|
34
|
+
renderManifest?: RestRenderer;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
};
|
|
37
|
+
type RestFormatInput = string | RestRenderer | RestFormatObject | null | undefined;
|
|
38
|
+
type RestConfig = {
|
|
39
|
+
rest?: {
|
|
40
|
+
formats?: Record<string, RestFormatInput> & {
|
|
41
|
+
default?: RestFormatInput;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
};
|
|
46
|
+
type RestFormatDefinition = {
|
|
47
|
+
key?: string;
|
|
48
|
+
alias?: string;
|
|
49
|
+
mediaTypes: string[];
|
|
50
|
+
contentType?: string;
|
|
51
|
+
renderResource?: RestRenderer;
|
|
52
|
+
renderManifest?: RestRenderer;
|
|
53
|
+
};
|
|
54
|
+
type RestFormatRegistry = Record<string, RestFormatDefinition>;
|
|
55
|
+
type ResolvedRestFormat = {
|
|
56
|
+
key: string;
|
|
57
|
+
contentType: string;
|
|
58
|
+
renderer: RestRenderer;
|
|
59
|
+
};
|
|
60
|
+
type RestFormatMetadata = {
|
|
61
|
+
extension: string;
|
|
62
|
+
mediaTypes: string[];
|
|
63
|
+
contentType: string;
|
|
64
|
+
manifestPath: string;
|
|
65
|
+
};
|
|
66
|
+
type HeaderBag = {
|
|
67
|
+
get?: (name: string) => string | null;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
};
|
|
70
|
+
type HeaderRequest = {
|
|
71
|
+
headers?: HeaderBag | null;
|
|
72
|
+
};
|
|
73
|
+
export declare function normalizeRestFormatRegistry(config?: RestConfig): RestFormatRegistry;
|
|
74
|
+
export declare function negotiateRestFormat(config: RestConfig, request: HeaderRequest, target?: RestFormatTarget): string;
|
|
75
|
+
export declare function resolveRestFormat(config: RestConfig, format: string | null | undefined, target?: RestFormatTarget): ResolvedRestFormat | null;
|
|
76
|
+
export declare function availableRestFormats(config?: RestConfig, target?: RestFormatTarget | null): string[];
|
|
77
|
+
export declare function restFormatMetadata(config?: RestConfig, routes?: RestRoutes): Record<string, RestFormatMetadata>;
|
|
78
|
+
export declare function manifestPathForFormat(routes: RestRoutes | undefined, format: string): string;
|
|
79
|
+
export declare function renderMarkdownJson(title: string, value: unknown, metadata?: Array<readonly [string, unknown]>): string;
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { renderJsonViewer } from '../web/json-viewer.js';
|
|
2
|
+
const BUILT_IN_FORMATS = {
|
|
3
|
+
json: {
|
|
4
|
+
mediaTypes: ['application/json'],
|
|
5
|
+
contentType: 'application/json; charset=utf-8',
|
|
6
|
+
renderResource: ({ data }) => `${JSON.stringify(data, null, 2)}\n`,
|
|
7
|
+
renderManifest: ({ data }) => `${JSON.stringify(data, null, 2)}\n`,
|
|
8
|
+
},
|
|
9
|
+
html: {
|
|
10
|
+
mediaTypes: ['text/html'],
|
|
11
|
+
contentType: 'text/html; charset=utf-8',
|
|
12
|
+
renderResource: ({ data, url }) => renderJsonViewer(data, { title: jsonViewerTitle(url) }),
|
|
13
|
+
renderManifest: ({ data }) => renderJsonViewer(data, { title: 'db viewer manifest' }),
|
|
14
|
+
},
|
|
15
|
+
md: {
|
|
16
|
+
mediaTypes: ['text/markdown'],
|
|
17
|
+
contentType: 'text/markdown; charset=utf-8',
|
|
18
|
+
renderResource: ({ resource, data }) => renderMarkdownJson(resource.name, data, [
|
|
19
|
+
['Resource', resource.name],
|
|
20
|
+
['Kind', resource.kind],
|
|
21
|
+
['Route', resource.routePath],
|
|
22
|
+
]),
|
|
23
|
+
renderManifest: ({ data, routes }) => renderMarkdownJson('db viewer manifest', data, [
|
|
24
|
+
['Kind', 'db.viewerManifest'],
|
|
25
|
+
['JSON', routes?.manifestJsonPath ?? manifestPathForFormat(routes, 'json')],
|
|
26
|
+
]),
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export function normalizeRestFormatRegistry(config = {}) {
|
|
30
|
+
const configuredFormats = config.rest?.formats ?? {};
|
|
31
|
+
const keys = new Set([
|
|
32
|
+
...Object.keys(BUILT_IN_FORMATS),
|
|
33
|
+
...Object.keys(configuredFormats).filter((key) => key !== 'default'),
|
|
34
|
+
]);
|
|
35
|
+
const registry = {};
|
|
36
|
+
for (const key of keys) {
|
|
37
|
+
registry[key] = normalizeFormatDefinition(key, configuredFormats[key], BUILT_IN_FORMATS[key]);
|
|
38
|
+
}
|
|
39
|
+
return registry;
|
|
40
|
+
}
|
|
41
|
+
export function negotiateRestFormat(config, request, target = 'resource') {
|
|
42
|
+
const accept = headerValue(request, 'accept');
|
|
43
|
+
const fallback = defaultFormatKey(config, target);
|
|
44
|
+
if (!accept) {
|
|
45
|
+
return fallback;
|
|
46
|
+
}
|
|
47
|
+
const preferences = parseAcceptHeader(accept);
|
|
48
|
+
if (preferences.length === 0) {
|
|
49
|
+
return fallback;
|
|
50
|
+
}
|
|
51
|
+
const registry = normalizeRestFormatRegistry(config);
|
|
52
|
+
let bestFormat = null;
|
|
53
|
+
let bestScore = {
|
|
54
|
+
quality: 0,
|
|
55
|
+
specificity: -1,
|
|
56
|
+
index: Number.MAX_SAFE_INTEGER,
|
|
57
|
+
};
|
|
58
|
+
for (const [format, definition] of Object.entries(registry)) {
|
|
59
|
+
if (!rendererForTarget(definition, target)) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
for (const mediaType of definition.mediaTypes ?? []) {
|
|
63
|
+
const score = acceptedMediaScore(preferences, mediaType);
|
|
64
|
+
if (compareAcceptScores(score, bestScore) > 0) {
|
|
65
|
+
bestFormat = format;
|
|
66
|
+
bestScore = score;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return bestScore.quality > 0 ? bestFormat : fallback;
|
|
71
|
+
}
|
|
72
|
+
export function resolveRestFormat(config, format, target = 'resource') {
|
|
73
|
+
const registry = normalizeRestFormatRegistry(config);
|
|
74
|
+
const key = format ?? defaultFormatKey(config, target);
|
|
75
|
+
return resolveRestFormatFromRegistry(config, registry, key, target);
|
|
76
|
+
}
|
|
77
|
+
export function availableRestFormats(config = {}, target = null) {
|
|
78
|
+
const registry = normalizeRestFormatRegistry(config);
|
|
79
|
+
return Object.keys(registry)
|
|
80
|
+
.filter((format) => !target || resolveRestFormat(config, format, target)?.renderer)
|
|
81
|
+
.sort();
|
|
82
|
+
}
|
|
83
|
+
export function restFormatMetadata(config = {}, routes = {}) {
|
|
84
|
+
const registry = normalizeRestFormatRegistry(config);
|
|
85
|
+
return Object.fromEntries(availableRestFormats(config).map((format) => {
|
|
86
|
+
const definition = registry[format];
|
|
87
|
+
return [format, {
|
|
88
|
+
extension: `.${format}`,
|
|
89
|
+
mediaTypes: definition.mediaTypes ?? [],
|
|
90
|
+
contentType: definition.contentType ?? contentTypeForMediaTypes(definition.mediaTypes),
|
|
91
|
+
manifestPath: manifestPathForFormat(routes, format),
|
|
92
|
+
}];
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
export function manifestPathForFormat(routes = {}, format) {
|
|
96
|
+
if (format === 'json' && routes.manifestJsonPath) {
|
|
97
|
+
return routes.manifestJsonPath;
|
|
98
|
+
}
|
|
99
|
+
if (format === 'html' && routes.manifestHtmlPath) {
|
|
100
|
+
return routes.manifestHtmlPath;
|
|
101
|
+
}
|
|
102
|
+
if (format === 'md' && routes.manifestMarkdownPath) {
|
|
103
|
+
return routes.manifestMarkdownPath;
|
|
104
|
+
}
|
|
105
|
+
return `${routes.manifestPath ?? '/__db/manifest'}.${format}`;
|
|
106
|
+
}
|
|
107
|
+
export function renderMarkdownJson(title, value, metadata = []) {
|
|
108
|
+
return [
|
|
109
|
+
`# ${title}`,
|
|
110
|
+
'',
|
|
111
|
+
...metadata.map(([label, detail]) => `- ${label}: \`${escapeMarkdownInline(detail)}\``),
|
|
112
|
+
'',
|
|
113
|
+
'```json',
|
|
114
|
+
JSON.stringify(value, null, 2),
|
|
115
|
+
'```',
|
|
116
|
+
'',
|
|
117
|
+
].join('\n');
|
|
118
|
+
}
|
|
119
|
+
function normalizeFormatDefinition(key, configured, fallback) {
|
|
120
|
+
const base = fallback ?? {
|
|
121
|
+
mediaTypes: [],
|
|
122
|
+
};
|
|
123
|
+
if (typeof configured === 'string') {
|
|
124
|
+
return {
|
|
125
|
+
key,
|
|
126
|
+
alias: configured,
|
|
127
|
+
mediaTypes: normalizeMediaTypes(base.mediaTypes),
|
|
128
|
+
contentType: base.contentType ?? contentTypeForMediaTypes(base.mediaTypes),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (typeof configured === 'function') {
|
|
132
|
+
return {
|
|
133
|
+
key,
|
|
134
|
+
mediaTypes: normalizeMediaTypes(base.mediaTypes),
|
|
135
|
+
contentType: base.contentType ?? contentTypeForMediaTypes(base.mediaTypes),
|
|
136
|
+
renderResource: configured,
|
|
137
|
+
renderManifest: base.renderManifest,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (isFormatObject(configured)) {
|
|
141
|
+
const mediaTypes = normalizeMediaTypes(configured.mediaTypes ?? base.mediaTypes);
|
|
142
|
+
const genericRenderer = typeof configured.render === 'function'
|
|
143
|
+
? configured.render
|
|
144
|
+
: null;
|
|
145
|
+
return {
|
|
146
|
+
key,
|
|
147
|
+
mediaTypes,
|
|
148
|
+
contentType: configured.contentType ?? base.contentType ?? contentTypeForMediaTypes(mediaTypes),
|
|
149
|
+
renderResource: typeof configured.renderResource === 'function'
|
|
150
|
+
? configured.renderResource
|
|
151
|
+
: genericRenderer ?? base.renderResource,
|
|
152
|
+
renderManifest: typeof configured.renderManifest === 'function'
|
|
153
|
+
? configured.renderManifest
|
|
154
|
+
: genericRenderer ?? base.renderManifest,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
key,
|
|
159
|
+
mediaTypes: normalizeMediaTypes(base.mediaTypes),
|
|
160
|
+
contentType: base.contentType ?? contentTypeForMediaTypes(base.mediaTypes),
|
|
161
|
+
renderResource: base.renderResource,
|
|
162
|
+
renderManifest: base.renderManifest,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function resolveRestFormatFromRegistry(config, registry, key, target, seen = new Set()) {
|
|
166
|
+
const normalizedKey = normalizeFormatKey(key);
|
|
167
|
+
if (!normalizedKey) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
if (seen.has(normalizedKey)) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
seen.add(normalizedKey);
|
|
174
|
+
if (normalizedKey === 'default') {
|
|
175
|
+
const configured = config.rest?.formats?.default;
|
|
176
|
+
if (typeof configured === 'string') {
|
|
177
|
+
return resolveRestFormatFromRegistry(config, registry, configured, target, seen);
|
|
178
|
+
}
|
|
179
|
+
if (typeof configured === 'function') {
|
|
180
|
+
return target === 'resource'
|
|
181
|
+
? {
|
|
182
|
+
key: 'default',
|
|
183
|
+
contentType: 'text/plain; charset=utf-8',
|
|
184
|
+
renderer: configured,
|
|
185
|
+
}
|
|
186
|
+
: resolveRestFormatFromRegistry(config, registry, 'json', target, seen);
|
|
187
|
+
}
|
|
188
|
+
if (isFormatObject(configured)) {
|
|
189
|
+
const definition = normalizeFormatDefinition('default', configured, null);
|
|
190
|
+
const renderer = rendererForTarget(definition, target);
|
|
191
|
+
if (renderer) {
|
|
192
|
+
return {
|
|
193
|
+
key: 'default',
|
|
194
|
+
contentType: definition.contentType,
|
|
195
|
+
renderer,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return resolveRestFormatFromRegistry(config, registry, 'json', target, seen);
|
|
200
|
+
}
|
|
201
|
+
const definition = registry[normalizedKey];
|
|
202
|
+
if (!definition) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
if (definition.alias) {
|
|
206
|
+
return resolveRestFormatFromRegistry(config, registry, definition.alias, target, seen);
|
|
207
|
+
}
|
|
208
|
+
const renderer = rendererForTarget(definition, target);
|
|
209
|
+
if (!renderer) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
key: normalizedKey,
|
|
214
|
+
contentType: definition.contentType ?? contentTypeForMediaTypes(definition.mediaTypes),
|
|
215
|
+
renderer,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function defaultFormatKey(config, target) {
|
|
219
|
+
const configured = config.rest?.formats?.default;
|
|
220
|
+
if (typeof configured === 'string') {
|
|
221
|
+
return configured;
|
|
222
|
+
}
|
|
223
|
+
if (target === 'resource' && (typeof configured === 'function' || configured)) {
|
|
224
|
+
return 'default';
|
|
225
|
+
}
|
|
226
|
+
return 'json';
|
|
227
|
+
}
|
|
228
|
+
function rendererForTarget(definition, target) {
|
|
229
|
+
return target === 'manifest' ? definition.renderManifest : definition.renderResource;
|
|
230
|
+
}
|
|
231
|
+
function normalizeFormatKey(value) {
|
|
232
|
+
return String(value ?? '').replace(/^\./, '').trim();
|
|
233
|
+
}
|
|
234
|
+
function normalizeMediaTypes(value) {
|
|
235
|
+
if (!value) {
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
238
|
+
const values = Array.isArray(value) ? value : [value];
|
|
239
|
+
return values
|
|
240
|
+
.filter((item) => typeof item === 'string' && item.trim())
|
|
241
|
+
.map((item) => item.trim().toLowerCase());
|
|
242
|
+
}
|
|
243
|
+
function contentTypeForMediaTypes(mediaTypes = []) {
|
|
244
|
+
return mediaTypes[0] ? `${mediaTypes[0]}; charset=utf-8` : 'text/plain; charset=utf-8';
|
|
245
|
+
}
|
|
246
|
+
function jsonViewerTitle(url) {
|
|
247
|
+
if (!url?.pathname) {
|
|
248
|
+
return 'db JSON';
|
|
249
|
+
}
|
|
250
|
+
return url.pathname.split('/').filter(Boolean).pop() ?? 'db JSON';
|
|
251
|
+
}
|
|
252
|
+
function escapeMarkdownInline(value) {
|
|
253
|
+
return String(value).replaceAll('`', '\\`');
|
|
254
|
+
}
|
|
255
|
+
function headerValue(request, name) {
|
|
256
|
+
if (typeof request.headers?.get === 'function') {
|
|
257
|
+
return request.headers.get(name);
|
|
258
|
+
}
|
|
259
|
+
const value = request.headers?.[name] ?? request.headers?.[name.toLowerCase()];
|
|
260
|
+
if (value === null || value === undefined) {
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
return String(value);
|
|
264
|
+
}
|
|
265
|
+
function parseAcceptHeader(value) {
|
|
266
|
+
return String(value).split(',').map((entry, index) => {
|
|
267
|
+
const [mediaRange, ...parameters] = entry.trim().split(';');
|
|
268
|
+
let quality = 1;
|
|
269
|
+
for (const parameter of parameters) {
|
|
270
|
+
const [name, rawValue] = parameter.trim().split('=');
|
|
271
|
+
if (name?.toLowerCase() === 'q') {
|
|
272
|
+
const parsed = Number(rawValue);
|
|
273
|
+
quality = Number.isFinite(parsed) ? Math.min(1, Math.max(0, parsed)) : 0;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
index,
|
|
278
|
+
mediaRange: mediaRange.toLowerCase(),
|
|
279
|
+
quality,
|
|
280
|
+
};
|
|
281
|
+
}).filter((preference) => preference.mediaRange.includes('/'));
|
|
282
|
+
}
|
|
283
|
+
function acceptedMediaScore(preferences, mediaType) {
|
|
284
|
+
const [wantedType, wantedSubtype] = mediaType.split('/');
|
|
285
|
+
let best = {
|
|
286
|
+
quality: 0,
|
|
287
|
+
specificity: -1,
|
|
288
|
+
index: Number.MAX_SAFE_INTEGER,
|
|
289
|
+
};
|
|
290
|
+
for (const preference of preferences) {
|
|
291
|
+
const [type, subtype] = preference.mediaRange.split('/');
|
|
292
|
+
if ((type !== '*' && type !== wantedType) || (subtype !== '*' && subtype !== wantedSubtype)) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const specificity = Number(type !== '*') + Number(subtype !== '*');
|
|
296
|
+
const candidate = {
|
|
297
|
+
quality: preference.quality,
|
|
298
|
+
specificity,
|
|
299
|
+
index: preference.index,
|
|
300
|
+
};
|
|
301
|
+
if (compareAcceptScores(candidate, best) > 0) {
|
|
302
|
+
best = candidate;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return best;
|
|
306
|
+
}
|
|
307
|
+
function compareAcceptScores(left, right) {
|
|
308
|
+
if (left.quality !== right.quality) {
|
|
309
|
+
return left.quality - right.quality;
|
|
310
|
+
}
|
|
311
|
+
if (left.specificity !== right.specificity) {
|
|
312
|
+
return left.specificity - right.specificity;
|
|
313
|
+
}
|
|
314
|
+
return right.index - left.index;
|
|
315
|
+
}
|
|
316
|
+
function isFormatObject(value) {
|
|
317
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
318
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
type RestConfig = {
|
|
3
|
+
cwd: string;
|
|
4
|
+
sourceDir: string;
|
|
5
|
+
stateDir: string;
|
|
6
|
+
server?: {
|
|
7
|
+
apiBase?: string;
|
|
8
|
+
maxBodyBytes?: number;
|
|
9
|
+
viewerLinks?: unknown[];
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
graphql?: {
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
path?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
rest?: {
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
formats?: Record<string, RestFormatInputLike> & {
|
|
20
|
+
default?: RestFormatInputLike;
|
|
21
|
+
};
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
};
|
|
26
|
+
type RestRendererLike = (context: Record<string, unknown>) => unknown;
|
|
27
|
+
type RestFormatObjectLike = {
|
|
28
|
+
mediaTypes?: string | string[];
|
|
29
|
+
contentType?: string;
|
|
30
|
+
render?: RestRendererLike;
|
|
31
|
+
renderResource?: RestRendererLike;
|
|
32
|
+
renderManifest?: RestRendererLike;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
type RestFormatInputLike = string | RestRendererLike | RestFormatObjectLike | null | undefined;
|
|
36
|
+
type RestResource = {
|
|
37
|
+
name: string;
|
|
38
|
+
kind?: string;
|
|
39
|
+
routePath?: string;
|
|
40
|
+
idField?: string;
|
|
41
|
+
dataPath?: string;
|
|
42
|
+
schemaPath?: string;
|
|
43
|
+
seed?: unknown;
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
};
|
|
46
|
+
type RestCollection = {
|
|
47
|
+
all(): unknown[] | Promise<unknown[]>;
|
|
48
|
+
get(id: string): unknown | Promise<unknown>;
|
|
49
|
+
create(body: unknown): unknown | Promise<unknown>;
|
|
50
|
+
patch(id: string, body: unknown): unknown | Promise<unknown>;
|
|
51
|
+
delete(id: string): boolean | Promise<boolean>;
|
|
52
|
+
};
|
|
53
|
+
type RestDocument = {
|
|
54
|
+
all(): unknown | Promise<unknown>;
|
|
55
|
+
put(body: unknown): unknown | Promise<unknown>;
|
|
56
|
+
update(body: unknown): unknown | Promise<unknown>;
|
|
57
|
+
};
|
|
58
|
+
type RestDb = {
|
|
59
|
+
config: RestConfig;
|
|
60
|
+
resources: Map<string, RestResource>;
|
|
61
|
+
diagnostics?: unknown[];
|
|
62
|
+
schemaVersion?: number;
|
|
63
|
+
collection(name: string): RestCollection;
|
|
64
|
+
document(name: string): RestDocument;
|
|
65
|
+
resourceNames(): string[];
|
|
66
|
+
};
|
|
67
|
+
type RestHeaderBag = {
|
|
68
|
+
get?: (name: string) => string | null;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
};
|
|
71
|
+
type RestRequest = (IncomingMessage | AsyncIterable<unknown>) & {
|
|
72
|
+
method?: string;
|
|
73
|
+
url?: string;
|
|
74
|
+
headers?: RestHeaderBag;
|
|
75
|
+
};
|
|
76
|
+
type RestRouteOptionsInput = {
|
|
77
|
+
apiBase?: string;
|
|
78
|
+
viewerPath?: string;
|
|
79
|
+
manifestPath?: string;
|
|
80
|
+
manifestJsonPath?: string;
|
|
81
|
+
manifestHtmlPath?: string;
|
|
82
|
+
manifestMarkdownPath?: string;
|
|
83
|
+
schemaPath?: string;
|
|
84
|
+
batchPath?: string;
|
|
85
|
+
importPath?: string;
|
|
86
|
+
eventsPath?: string;
|
|
87
|
+
graphqlPath?: string;
|
|
88
|
+
restBasePath?: string;
|
|
89
|
+
resourceRoutesEnabled?: boolean;
|
|
90
|
+
trace?: unknown;
|
|
91
|
+
traceNested?: boolean;
|
|
92
|
+
[key: string]: unknown;
|
|
93
|
+
};
|
|
94
|
+
type RestResult = {
|
|
95
|
+
status: number;
|
|
96
|
+
headers: Record<string, unknown>;
|
|
97
|
+
body: unknown;
|
|
98
|
+
};
|
|
99
|
+
type RawBodyOptions = {
|
|
100
|
+
maxBytes?: number;
|
|
101
|
+
};
|
|
102
|
+
export declare function handleRestRequest(db: unknown, request: RestRequest, response: unknown, url?: URL, options?: RestRouteOptionsInput): Promise<void>;
|
|
103
|
+
export declare function findResourceByRoute(db: RestDb, routeName: string): RestResource | undefined;
|
|
104
|
+
export declare function executeRestBatch(db: RestDb, body: unknown, options?: RestRouteOptionsInput): Promise<Array<RestResult & {
|
|
105
|
+
index: number;
|
|
106
|
+
}>>;
|
|
107
|
+
export declare function readRawBody(request: unknown, options?: RawBodyOptions): Promise<Buffer>;
|
|
108
|
+
export declare function readJsonBody(request: unknown, options?: RawBodyOptions): Promise<unknown>;
|
|
109
|
+
export declare function sendJson(response: unknown, status: number, body: unknown): void;
|
|
110
|
+
export declare function sendText(response: unknown, status: number, body: unknown, contentType: string): void;
|
|
111
|
+
export {};
|