@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/client.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createIndexedDbCacheStorage } from './client-cache.js';
|
|
2
|
+
import { type OperationTemplate, type OperationVariables } from './shared/operations.js';
|
|
3
|
+
export { createIndexedDbCacheStorage };
|
|
4
|
+
type ClientBatchingOptions = boolean | {
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
delayMs?: number;
|
|
7
|
+
dedupe?: boolean | 'reads' | 'all';
|
|
8
|
+
};
|
|
9
|
+
type ClientRequestOptions = {
|
|
10
|
+
batch?: boolean;
|
|
11
|
+
cache?: unknown;
|
|
12
|
+
};
|
|
13
|
+
type ClientOptions = {
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
apiBase?: string;
|
|
16
|
+
restBasePath?: string;
|
|
17
|
+
graphqlPath?: string;
|
|
18
|
+
restBatchPath?: string;
|
|
19
|
+
manifestPath?: string;
|
|
20
|
+
batching?: ClientBatchingOptions;
|
|
21
|
+
cache?: unknown;
|
|
22
|
+
};
|
|
23
|
+
type GraphqlRequest = {
|
|
24
|
+
query: string;
|
|
25
|
+
variables?: OperationVariables;
|
|
26
|
+
operationName?: string | null;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
type RestRequestInput = {
|
|
30
|
+
method?: string;
|
|
31
|
+
path?: string;
|
|
32
|
+
body?: unknown;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
type RestRequest = {
|
|
36
|
+
method: string;
|
|
37
|
+
path: string;
|
|
38
|
+
body?: unknown;
|
|
39
|
+
};
|
|
40
|
+
type RestResponse = {
|
|
41
|
+
status: number;
|
|
42
|
+
headers: Record<string, string>;
|
|
43
|
+
body: unknown;
|
|
44
|
+
};
|
|
45
|
+
export declare function createDbClient(options?: ClientOptions): {
|
|
46
|
+
cache: unknown;
|
|
47
|
+
graphql: {
|
|
48
|
+
(query: string | GraphqlRequest, variables?: OperationVariables, requestOptions?: ClientRequestOptions): Promise<unknown>;
|
|
49
|
+
batch: (requests: GraphqlRequest[]) => Promise<unknown[]>;
|
|
50
|
+
request: /*elided*/ any;
|
|
51
|
+
};
|
|
52
|
+
operation: (template: OperationTemplate, variables?: OperationVariables, requestOptions?: ClientRequestOptions) => Promise<unknown>;
|
|
53
|
+
query: (template: OperationTemplate, variables?: OperationVariables, requestOptions?: ClientRequestOptions) => Promise<unknown>;
|
|
54
|
+
rest: {
|
|
55
|
+
(method: string | RestRequestInput, path?: string, body?: unknown, requestOptions?: ClientRequestOptions): Promise<RestResponse>;
|
|
56
|
+
batch: (requests: RestRequest[]) => Promise<RestResponse[]>;
|
|
57
|
+
request: /*elided*/ any;
|
|
58
|
+
get(path: any, requestOptions: any): Promise<RestResponse>;
|
|
59
|
+
post(path: any, body: any, requestOptions: any): Promise<RestResponse>;
|
|
60
|
+
patch(path: any, body: any, requestOptions: any): Promise<RestResponse>;
|
|
61
|
+
put(path: any, body: any, requestOptions: any): Promise<RestResponse>;
|
|
62
|
+
delete(path: any, requestOptions: any): Promise<RestResponse>;
|
|
63
|
+
};
|
|
64
|
+
};
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { dbError } from './errors.js';
|
|
2
|
+
import { createClientCache, createIndexedDbCacheStorage } from './client-cache.js';
|
|
3
|
+
import { operationRequest } from './shared/operations.js';
|
|
4
|
+
export { createIndexedDbCacheStorage };
|
|
5
|
+
export function createDbClient(options = {}) {
|
|
6
|
+
rejectRemovedForkOption(options);
|
|
7
|
+
const baseUrl = options.baseUrl ?? '';
|
|
8
|
+
const apiBase = normalizeBasePath(options.apiBase ?? '/__db');
|
|
9
|
+
const restBasePath = options.restBasePath ?? '';
|
|
10
|
+
const graphqlPath = options.graphqlPath ?? '/graphql';
|
|
11
|
+
const restBatchPath = options.restBatchPath ?? `${apiBase}/batch`;
|
|
12
|
+
const manifestPath = options.manifestPath ?? `${apiBase}/manifest.json`;
|
|
13
|
+
const batching = normalizeBatching(options.batching);
|
|
14
|
+
const cache = createClientCache({
|
|
15
|
+
cache: options.cache,
|
|
16
|
+
cacheNamespace: {
|
|
17
|
+
baseUrl,
|
|
18
|
+
apiBase,
|
|
19
|
+
manifestPath,
|
|
20
|
+
},
|
|
21
|
+
restBasePath,
|
|
22
|
+
fetchManifest: () => getJson(resolveUrl(baseUrl, manifestPath)),
|
|
23
|
+
createEventSource(path) {
|
|
24
|
+
if (typeof EventSource !== 'function') {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return new EventSource(resolveUrl(baseUrl, path));
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const graphqlQueue = createQueue((requests) => graphqlBatch(requests), batching, {
|
|
31
|
+
shouldDedupeRequest: isGraphqlDedupeSafe,
|
|
32
|
+
});
|
|
33
|
+
const restQueue = createQueue((requests) => restBatch(requests), batching, {
|
|
34
|
+
shouldDedupeRequest: isRestDedupeSafe,
|
|
35
|
+
});
|
|
36
|
+
async function graphql(query, variables, requestOptions = {}) {
|
|
37
|
+
const request = typeof query === 'string' ? { query, variables } : query;
|
|
38
|
+
if (cache.enabled && isGraphqlDedupeSafe(request)) {
|
|
39
|
+
return cache.executeGraphqlRead(request, () => graphqlDirect(request), requestOptions);
|
|
40
|
+
}
|
|
41
|
+
if (shouldBatch(requestOptions, batching)) {
|
|
42
|
+
const result = await graphqlQueue({ request });
|
|
43
|
+
cache.recordGraphqlWrite(result);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
const result = await graphqlDirect(request);
|
|
47
|
+
cache.recordGraphqlWrite(result);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
async function graphqlDirect(request) {
|
|
51
|
+
return postJson(resolveUrl(baseUrl, graphqlPath), request);
|
|
52
|
+
}
|
|
53
|
+
async function graphqlBatch(requests) {
|
|
54
|
+
return postJson(resolveUrl(baseUrl, graphqlPath), requests);
|
|
55
|
+
}
|
|
56
|
+
async function rest(method, path, body, requestOptions = {}) {
|
|
57
|
+
const request = normalizeRestRequest(method, path, body);
|
|
58
|
+
return executeRestRequest(request, requestOptions);
|
|
59
|
+
}
|
|
60
|
+
async function executeRestRequest(request, requestOptions = {}) {
|
|
61
|
+
if (cache.enabled && isRestDedupeSafe(request)) {
|
|
62
|
+
return cache.executeRestRead(request, () => restDirect(request), requestOptions);
|
|
63
|
+
}
|
|
64
|
+
if (shouldBatch(requestOptions, batching)) {
|
|
65
|
+
const result = await restQueue({ request });
|
|
66
|
+
cache.recordRestWrite(request, result);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
const result = await restDirect(request);
|
|
70
|
+
cache.recordRestWrite(request, result);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
async function restDirect(request) {
|
|
74
|
+
const init = {
|
|
75
|
+
method: request.method,
|
|
76
|
+
headers: {
|
|
77
|
+
'content-type': 'application/json',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
if (!['GET', 'DELETE'].includes(request.method) && request.body !== undefined) {
|
|
81
|
+
init.body = JSON.stringify(request.body);
|
|
82
|
+
}
|
|
83
|
+
const response = await fetch(resolveUrl(baseUrl, joinPaths(restBasePath, request.path)), init);
|
|
84
|
+
return {
|
|
85
|
+
status: response.status,
|
|
86
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
87
|
+
body: await readResponseBody(response),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async function restBatch(requests) {
|
|
91
|
+
return postJson(resolveUrl(baseUrl, restBatchPath), requests.map(normalizeRestRequestObject));
|
|
92
|
+
}
|
|
93
|
+
async function operation(template, variables = {}, requestOptions = {}) {
|
|
94
|
+
const request = typeof template === 'string' && !isRestOperationString(template)
|
|
95
|
+
? { ref: template }
|
|
96
|
+
: operationRequest(template, variables);
|
|
97
|
+
return executeOperationRequest(request, variables, requestOptions);
|
|
98
|
+
}
|
|
99
|
+
async function query(template, variables = {}, requestOptions = {}) {
|
|
100
|
+
const request = typeof template === 'string' && !isRestOperationString(template)
|
|
101
|
+
? { ref: template }
|
|
102
|
+
: operationRequest(template, variables);
|
|
103
|
+
return executeOperationRequest(request, variables, requestOptions);
|
|
104
|
+
}
|
|
105
|
+
async function executeOperationRequest(request, variables, requestOptions) {
|
|
106
|
+
if (request.ref) {
|
|
107
|
+
return postJson(resolveUrl(baseUrl, `${apiBase}/operations/${encodeURIComponent(request.ref)}`), {
|
|
108
|
+
variables,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (request.kind === 'graphql') {
|
|
112
|
+
return graphql({
|
|
113
|
+
query: request.query,
|
|
114
|
+
variables: request.variables,
|
|
115
|
+
operationName: request.operationName,
|
|
116
|
+
}, undefined, requestOptions);
|
|
117
|
+
}
|
|
118
|
+
return executeRestRequest(request, requestOptions).then((result) => result.body);
|
|
119
|
+
}
|
|
120
|
+
graphql.batch = graphqlBatch;
|
|
121
|
+
graphql.request = graphql;
|
|
122
|
+
rest.batch = restBatch;
|
|
123
|
+
rest.request = rest;
|
|
124
|
+
rest.get = (path, requestOptions) => rest('GET', path, undefined, requestOptions);
|
|
125
|
+
rest.post = (path, body, requestOptions) => rest('POST', path, body, requestOptions);
|
|
126
|
+
rest.patch = (path, body, requestOptions) => rest('PATCH', path, body, requestOptions);
|
|
127
|
+
rest.put = (path, body, requestOptions) => rest('PUT', path, body, requestOptions);
|
|
128
|
+
rest.delete = (path, requestOptions) => rest('DELETE', path, undefined, requestOptions);
|
|
129
|
+
return {
|
|
130
|
+
cache: cache.publicApi,
|
|
131
|
+
graphql,
|
|
132
|
+
operation,
|
|
133
|
+
query,
|
|
134
|
+
rest,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function rejectRemovedForkOption(options) {
|
|
138
|
+
const fork = options.fork;
|
|
139
|
+
if (fork !== undefined) {
|
|
140
|
+
throw dbError('CLIENT_FORK_OPTION_REMOVED', 'The HTTP client fork option was removed with fixture-folder fork routes.', {
|
|
141
|
+
hint: 'Use the package API runtime scope with db.forks.open(name) and tenant.branches.open(name), or pass explicit REST/GraphQL paths for an app-owned tenant route.',
|
|
142
|
+
details: {
|
|
143
|
+
fork,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function normalizeBatching(value) {
|
|
149
|
+
if (value === true) {
|
|
150
|
+
return {
|
|
151
|
+
enabled: true,
|
|
152
|
+
delayMs: 10,
|
|
153
|
+
dedupe: 'reads',
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (!value) {
|
|
157
|
+
return {
|
|
158
|
+
enabled: false,
|
|
159
|
+
delayMs: 10,
|
|
160
|
+
dedupe: 'reads',
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
enabled: Boolean(value.enabled),
|
|
165
|
+
delayMs: Number(value.delayMs ?? 10),
|
|
166
|
+
dedupe: normalizeDedupeMode(value.dedupe),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function normalizeDedupeMode(value) {
|
|
170
|
+
if (value === false) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
if (value === 'all') {
|
|
174
|
+
return 'all';
|
|
175
|
+
}
|
|
176
|
+
return 'reads';
|
|
177
|
+
}
|
|
178
|
+
function shouldBatch(requestOptions, batching) {
|
|
179
|
+
if (requestOptions?.batch === false) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
if (requestOptions?.batch === true) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
return batching.enabled;
|
|
186
|
+
}
|
|
187
|
+
function isRestOperationString(value) {
|
|
188
|
+
const trimmed = String(value ?? '').trim();
|
|
189
|
+
if (trimmed.startsWith('/')) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
const methodMatch = trimmed.match(/^(GET|POST|PUT|PATCH|DELETE)\s+/i);
|
|
193
|
+
if (!methodMatch) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
return trimmed.slice(methodMatch[0].length).trimStart().startsWith('/');
|
|
197
|
+
}
|
|
198
|
+
function createQueue(flush, batching, options = {}) {
|
|
199
|
+
let pending = [];
|
|
200
|
+
let timer = null;
|
|
201
|
+
return (item) => new Promise((resolve, reject) => {
|
|
202
|
+
pending.push({
|
|
203
|
+
...item,
|
|
204
|
+
resolve,
|
|
205
|
+
reject,
|
|
206
|
+
});
|
|
207
|
+
if (!timer) {
|
|
208
|
+
timer = setTimeout(async () => {
|
|
209
|
+
const items = pending;
|
|
210
|
+
pending = [];
|
|
211
|
+
timer = null;
|
|
212
|
+
try {
|
|
213
|
+
const groups = batching.dedupe ? groupQueuedItems(items, (request) => shouldDedupeRequest(request, batching, options)) : items.map((queued) => ({
|
|
214
|
+
request: queued.request,
|
|
215
|
+
queued: [queued],
|
|
216
|
+
}));
|
|
217
|
+
const results = await flush(groups.map((group) => group.request));
|
|
218
|
+
groups.forEach((group, index) => {
|
|
219
|
+
for (const queued of group.queued) {
|
|
220
|
+
queued.resolve(results[index]);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
items.forEach((queued) => queued.reject(error));
|
|
226
|
+
}
|
|
227
|
+
}, batching.delayMs);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function shouldDedupeRequest(request, batching, options) {
|
|
232
|
+
if (batching.dedupe === 'all') {
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
if (batching.dedupe === 'reads') {
|
|
236
|
+
return options.shouldDedupeRequest?.(request) === true;
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
function groupQueuedItems(items, canDedupe) {
|
|
241
|
+
const groups = [];
|
|
242
|
+
let readSegment = new Map();
|
|
243
|
+
for (const item of items) {
|
|
244
|
+
if (!canDedupe(item.request)) {
|
|
245
|
+
groups.push({
|
|
246
|
+
request: item.request,
|
|
247
|
+
queued: [item],
|
|
248
|
+
});
|
|
249
|
+
readSegment = new Map();
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const key = stableStringify(item.request);
|
|
253
|
+
const group = readSegment.get(key);
|
|
254
|
+
if (group) {
|
|
255
|
+
group.queued.push(item);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
const nextGroup = {
|
|
259
|
+
request: item.request,
|
|
260
|
+
queued: [item],
|
|
261
|
+
};
|
|
262
|
+
readSegment.set(key, nextGroup);
|
|
263
|
+
groups.push(nextGroup);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return groups;
|
|
267
|
+
}
|
|
268
|
+
function isGraphqlDedupeSafe(request) {
|
|
269
|
+
const query = String(request.query ?? '').trimStart();
|
|
270
|
+
return !/^(mutation|subscription)\b/.test(query);
|
|
271
|
+
}
|
|
272
|
+
function isRestDedupeSafe(request) {
|
|
273
|
+
return String(request.method ?? 'GET').toUpperCase() === 'GET';
|
|
274
|
+
}
|
|
275
|
+
async function postJson(url, body) {
|
|
276
|
+
let response;
|
|
277
|
+
try {
|
|
278
|
+
response = await fetch(url, {
|
|
279
|
+
method: 'POST',
|
|
280
|
+
headers: {
|
|
281
|
+
'content-type': 'application/json',
|
|
282
|
+
},
|
|
283
|
+
body: JSON.stringify(body),
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
throw dbError('CLIENT_FETCH_FAILED', `db client could not reach ${url}.`, {
|
|
288
|
+
hint: 'Make sure async-db serve is running and baseUrl points at the correct host and port.',
|
|
289
|
+
details: {
|
|
290
|
+
url,
|
|
291
|
+
cause: error instanceof Error ? error.message : String(error),
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
const responseBody = await readResponseBody(response);
|
|
296
|
+
if (response.ok === false) {
|
|
297
|
+
throw dbError('CLIENT_HTTP_ERROR', `db client request to ${url} failed with HTTP ${response.status}.`, {
|
|
298
|
+
status: response.status,
|
|
299
|
+
hint: 'Inspect details.responseBody for the server error payload.',
|
|
300
|
+
details: {
|
|
301
|
+
url,
|
|
302
|
+
status: response.status,
|
|
303
|
+
responseBody,
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
return responseBody;
|
|
308
|
+
}
|
|
309
|
+
async function getJson(url) {
|
|
310
|
+
let response;
|
|
311
|
+
try {
|
|
312
|
+
response = await fetch(url, {
|
|
313
|
+
method: 'GET',
|
|
314
|
+
headers: {
|
|
315
|
+
accept: 'application/json',
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
throw dbError('CLIENT_FETCH_FAILED', `db client could not reach ${url}.`, {
|
|
321
|
+
hint: 'Make sure async-db serve is running and baseUrl points at the correct host and port.',
|
|
322
|
+
details: {
|
|
323
|
+
url,
|
|
324
|
+
cause: error instanceof Error ? error.message : String(error),
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
const responseBody = await readResponseBody(response);
|
|
329
|
+
if (response.ok === false) {
|
|
330
|
+
throw dbError('CLIENT_HTTP_ERROR', `db client request to ${url} failed with HTTP ${response.status}.`, {
|
|
331
|
+
status: response.status,
|
|
332
|
+
hint: 'Inspect details.responseBody for the server error payload.',
|
|
333
|
+
details: {
|
|
334
|
+
url,
|
|
335
|
+
status: response.status,
|
|
336
|
+
responseBody,
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return responseBody;
|
|
341
|
+
}
|
|
342
|
+
async function readResponseBody(response) {
|
|
343
|
+
const text = await response.text();
|
|
344
|
+
if (!text) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
try {
|
|
348
|
+
return JSON.parse(text);
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
return text;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function normalizeRestRequest(method, path, body) {
|
|
355
|
+
if (typeof method === 'object' && method !== null) {
|
|
356
|
+
return normalizeRestRequestObject(method);
|
|
357
|
+
}
|
|
358
|
+
return normalizeRestRequestObject({
|
|
359
|
+
method: String(method),
|
|
360
|
+
path,
|
|
361
|
+
body,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
function normalizeRestRequestObject(request) {
|
|
365
|
+
if (!request || typeof request !== 'object' || Array.isArray(request)) {
|
|
366
|
+
throw dbError('CLIENT_REST_INVALID_REQUEST', 'REST request must be an object or method/path arguments.', {
|
|
367
|
+
hint: 'Use client.rest("GET", "/users") or client.rest({ method: "GET", path: "/users" }).',
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
method: String(request.method ?? 'GET').toUpperCase(),
|
|
372
|
+
path: request.path ?? '/',
|
|
373
|
+
body: request.body,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function resolveUrl(baseUrl, path) {
|
|
377
|
+
if (!baseUrl) {
|
|
378
|
+
return path;
|
|
379
|
+
}
|
|
380
|
+
return new URL(path, baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`).href;
|
|
381
|
+
}
|
|
382
|
+
function joinPaths(basePath, requestPath) {
|
|
383
|
+
if (!basePath) {
|
|
384
|
+
return requestPath;
|
|
385
|
+
}
|
|
386
|
+
const normalizedBase = `/${String(basePath).replace(/^\/+/, '').replace(/\/+$/, '')}`;
|
|
387
|
+
const normalizedPath = `/${String(requestPath ?? '/').replace(/^\/+/, '')}`;
|
|
388
|
+
return `${normalizedBase}${normalizedPath === '/' ? '' : normalizedPath}`;
|
|
389
|
+
}
|
|
390
|
+
function normalizeBasePath(value) {
|
|
391
|
+
const path = `/${String(value ?? '').replace(/^\/+/, '').replace(/\/+$/, '')}`;
|
|
392
|
+
return path === '/' ? '' : path;
|
|
393
|
+
}
|
|
394
|
+
function stableStringify(value) {
|
|
395
|
+
if (Array.isArray(value)) {
|
|
396
|
+
return `[${value.map(stableStringify).join(',')}]`;
|
|
397
|
+
}
|
|
398
|
+
if (isRecord(value)) {
|
|
399
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`).join(',')}}`;
|
|
400
|
+
}
|
|
401
|
+
return JSON.stringify(value);
|
|
402
|
+
}
|
|
403
|
+
function isRecord(value) {
|
|
404
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
405
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineConfig, mergeManifest, parseFixturePath, resourceNameFromPath } from './features/config/public.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineConfig, mergeManifest, parseFixturePath, resourceNameFromPath } from './features/config/public.js';
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { DbOptions } from './index.d.ts';
|
|
2
|
+
|
|
3
|
+
export type {
|
|
4
|
+
DbSourceReader,
|
|
5
|
+
DbSourceReaderContext,
|
|
6
|
+
DbSourceReaderResult,
|
|
7
|
+
DbSourceReaderDataResult,
|
|
8
|
+
DbSourceReaderSchemaResult,
|
|
9
|
+
DbSourcesOptions,
|
|
10
|
+
DbCustomStore,
|
|
11
|
+
DbCustomStoreFactory,
|
|
12
|
+
DbStoreName,
|
|
13
|
+
DbStoreOptions,
|
|
14
|
+
DbStoresOptions,
|
|
15
|
+
} from './index.d.ts';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* db project configuration.
|
|
19
|
+
*
|
|
20
|
+
* Use with `// @ts-check` in `db.config.mjs` for editor autocomplete:
|
|
21
|
+
*
|
|
22
|
+
* ```js
|
|
23
|
+
* import { defineConfig } from '@async/db/config';
|
|
24
|
+
*
|
|
25
|
+
* export default defineConfig({
|
|
26
|
+
* dbDir: './db',
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type DbConfig = DbOptions;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Type-only helper for authoring `db.config.mjs`.
|
|
34
|
+
*
|
|
35
|
+
* It returns the config unchanged at runtime and exists so JavaScript config
|
|
36
|
+
* files get autocomplete, literal value checking, and inline JSDoc.
|
|
37
|
+
*/
|
|
38
|
+
export function defineConfig<Config extends DbConfig>(config: Config): Config;
|
|
39
|
+
|
|
40
|
+
/** Deep-merge JSON-serializable manifest patches without mutating inputs. */
|
|
41
|
+
export function mergeManifest<Base, Patch>(base: Base, patch: Patch): Base & Patch;
|
|
42
|
+
|
|
43
|
+
/** Derive a resource name from a fixture path using db naming strategies. */
|
|
44
|
+
export function resourceNameFromPath(file: string, options?: { strategy?: 'basename' | 'folder-prefixed' | 'path' }): string;
|
|
45
|
+
|
|
46
|
+
/** Parse a fixture path into folder, basename, filename, and extension metadata. */
|
|
47
|
+
export function parseFixturePath(file: string): {
|
|
48
|
+
file: string;
|
|
49
|
+
folders: string[];
|
|
50
|
+
folder: string | null;
|
|
51
|
+
filename: string;
|
|
52
|
+
basename: string;
|
|
53
|
+
extension: string;
|
|
54
|
+
};
|
package/dist/config.js
ADDED
package/dist/csv.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseCsvRecords, parseCsvRows } from './shared/csv.js';
|
package/dist/csv.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseCsvRecords, parseCsvRows } from './shared/csv.js';
|
package/dist/db.d.ts
ADDED
package/dist/db.js
ADDED
package/dist/doctor.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { runDbDoctor } from './features/doctor/index.js';
|
package/dist/doctor.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { runDbDoctor } from './features/doctor/index.js';
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { describeValue, graphqlError, DbError, dbError, listChoices, serializeError, } from './shared/errors.js';
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { describeValue, graphqlError, DbError, dbError, listChoices, serializeError, } from './shared/errors.js';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
type NullableOutput = string | null;
|
|
2
|
+
type DefaultConfig = {
|
|
3
|
+
dbDir: string;
|
|
4
|
+
sourceDir: string;
|
|
5
|
+
stateDir: string;
|
|
6
|
+
outputs: {
|
|
7
|
+
stateDir: string;
|
|
8
|
+
types: string;
|
|
9
|
+
committedTypes: NullableOutput;
|
|
10
|
+
schemaManifest: NullableOutput;
|
|
11
|
+
viewerManifest: NullableOutput;
|
|
12
|
+
operationRegistry: NullableOutput;
|
|
13
|
+
operationRefs: NullableOutput;
|
|
14
|
+
honoStarterDir: string;
|
|
15
|
+
};
|
|
16
|
+
schemaOutFile: NullableOutput;
|
|
17
|
+
viewerManifestOutFile: NullableOutput;
|
|
18
|
+
schemaManifest: Record<string, unknown>;
|
|
19
|
+
sources: {
|
|
20
|
+
readers: unknown[];
|
|
21
|
+
writePolicy: 'preserve' | string;
|
|
22
|
+
};
|
|
23
|
+
stores: {
|
|
24
|
+
default: string;
|
|
25
|
+
json: {
|
|
26
|
+
driver: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
types: {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
outFile: string;
|
|
32
|
+
commitOutFile: NullableOutput;
|
|
33
|
+
useReadonly: boolean;
|
|
34
|
+
emitComments: boolean;
|
|
35
|
+
exportRuntimeHelpers: boolean;
|
|
36
|
+
};
|
|
37
|
+
schema: {
|
|
38
|
+
source: 'auto' | string;
|
|
39
|
+
allowJsonc: boolean;
|
|
40
|
+
autoModulePackageJson: boolean;
|
|
41
|
+
standardSchema: boolean;
|
|
42
|
+
unknownFields: 'warn' | string;
|
|
43
|
+
additiveChanges: 'auto' | string;
|
|
44
|
+
destructiveChanges: 'manual' | string;
|
|
45
|
+
typeChanges: 'manual' | string;
|
|
46
|
+
};
|
|
47
|
+
defaults: {
|
|
48
|
+
applyOnCreate: boolean;
|
|
49
|
+
applyOnSafeMigration: boolean;
|
|
50
|
+
};
|
|
51
|
+
seed: {
|
|
52
|
+
generateFromSchema: boolean;
|
|
53
|
+
generatedCount: number;
|
|
54
|
+
};
|
|
55
|
+
collections: Record<string, unknown>;
|
|
56
|
+
resources: {
|
|
57
|
+
naming: 'basename' | string;
|
|
58
|
+
};
|
|
59
|
+
server: {
|
|
60
|
+
apiBase: string;
|
|
61
|
+
dataPath: string | false;
|
|
62
|
+
host: string;
|
|
63
|
+
port: number;
|
|
64
|
+
maxBodyBytes: number;
|
|
65
|
+
viewerLinks: unknown[];
|
|
66
|
+
};
|
|
67
|
+
rest: {
|
|
68
|
+
enabled: boolean;
|
|
69
|
+
};
|
|
70
|
+
graphql: {
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
path: string;
|
|
73
|
+
};
|
|
74
|
+
operations: {
|
|
75
|
+
enabled: boolean;
|
|
76
|
+
sourceDir: string;
|
|
77
|
+
outFile: NullableOutput;
|
|
78
|
+
refsOutFile: NullableOutput;
|
|
79
|
+
acceptRefs: 'both' | string;
|
|
80
|
+
registry: Record<string, unknown>;
|
|
81
|
+
};
|
|
82
|
+
mock: {
|
|
83
|
+
delay: [number, number] | number | false;
|
|
84
|
+
errors: unknown;
|
|
85
|
+
};
|
|
86
|
+
generate: {
|
|
87
|
+
hono: {
|
|
88
|
+
outDir: string;
|
|
89
|
+
api: string[];
|
|
90
|
+
db: string;
|
|
91
|
+
app: string;
|
|
92
|
+
runtime: string;
|
|
93
|
+
seed: boolean;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
export declare const DEFAULT_CONFIG: DefaultConfig;
|
|
98
|
+
export {};
|