@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,18 @@
|
|
|
1
|
+
import { startDbServer } from '../../server.js';
|
|
2
|
+
import { isHelpRequested, valueAfter } from '../args.js';
|
|
3
|
+
import { printServeHelp } from '../output.js';
|
|
4
|
+
export async function runServe(config, args) {
|
|
5
|
+
if (isHelpRequested(args)) {
|
|
6
|
+
printServeHelp();
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const host = valueAfter(args, '--host') ?? config.server.host;
|
|
10
|
+
const port = valueAfter(args, '--port') ?? config.server.port;
|
|
11
|
+
const { url } = await startDbServer({
|
|
12
|
+
...config,
|
|
13
|
+
host,
|
|
14
|
+
port,
|
|
15
|
+
});
|
|
16
|
+
console.log(`db server listening at ${url}`);
|
|
17
|
+
return new Promise(() => { });
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { syncDb } from '../../sync.js';
|
|
2
|
+
import { printDiagnostic } from '../output.js';
|
|
3
|
+
export async function runSync(config) {
|
|
4
|
+
const result = await syncDb(config);
|
|
5
|
+
for (const diagnostic of result.diagnostics) {
|
|
6
|
+
printDiagnostic(diagnostic);
|
|
7
|
+
}
|
|
8
|
+
for (const line of result.logs) {
|
|
9
|
+
console.log(line);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { loadProjectSchema } from '../../schema.js';
|
|
4
|
+
import { generateTypes } from '../../types.js';
|
|
5
|
+
import { isHelpRequested, valueAfter } from '../args.js';
|
|
6
|
+
import { printDiagnostic, printTypesHelp } from '../output.js';
|
|
7
|
+
export async function runTypes(config, args) {
|
|
8
|
+
if (isHelpRequested(args)) {
|
|
9
|
+
printTypesHelp();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (args.includes('--watch')) {
|
|
13
|
+
await runTypesOnce(config, args);
|
|
14
|
+
console.log(`Watching ${path.relative(config.cwd, config.sourceDir) || '.'}`);
|
|
15
|
+
watch(config.sourceDir, { recursive: true }, async () => {
|
|
16
|
+
try {
|
|
17
|
+
await runTypesOnce(config, args);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.error(error.message);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return new Promise(() => { });
|
|
24
|
+
}
|
|
25
|
+
await runTypesOnce(config, args);
|
|
26
|
+
}
|
|
27
|
+
async function runTypesOnce(config, args) {
|
|
28
|
+
const outFile = valueAfter(args, '--out');
|
|
29
|
+
const project = await loadProjectSchema(config);
|
|
30
|
+
const result = await generateTypes(config, { project, outFile });
|
|
31
|
+
for (const diagnostic of result.diagnostics) {
|
|
32
|
+
printDiagnostic(diagnostic);
|
|
33
|
+
}
|
|
34
|
+
for (const filePath of result.outFiles) {
|
|
35
|
+
console.log(`Generated ${path.relative(config.cwd, filePath)}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { dbError } from '../../errors.js';
|
|
3
|
+
import { loadProjectSchema } from '../../schema.js';
|
|
4
|
+
import { generateViewerManifest } from '../../viewer-manifest.js';
|
|
5
|
+
import { isHelpRequested, valueAfter } from '../args.js';
|
|
6
|
+
import { printViewerHelp } from '../output.js';
|
|
7
|
+
export async function runViewer(config, args) {
|
|
8
|
+
if (isHelpRequested(args)) {
|
|
9
|
+
printViewerHelp();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (args[0] !== 'manifest') {
|
|
13
|
+
throw dbError('VIEWER_UNKNOWN_COMMAND', `Unknown viewer command "${args[0] ?? ''}".`, {
|
|
14
|
+
hint: 'Use async-db viewer manifest [--out <file>].',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const project = await loadProjectSchema(config);
|
|
18
|
+
const result = await generateViewerManifest(config, {
|
|
19
|
+
project,
|
|
20
|
+
outFile: valueAfter(args, '--out'),
|
|
21
|
+
});
|
|
22
|
+
if (result.outFiles.length === 0) {
|
|
23
|
+
console.log(result.content);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
for (const filePath of result.outFiles) {
|
|
27
|
+
console.log(`Generated ${path.relative(config.cwd, filePath)}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { loadConfig } from '../config.js';
|
|
2
|
+
import { defaultGeneratorRegistry } from '../features/generate/registry.js';
|
|
3
|
+
import { isHelpRequested, parseGlobalOptions } from './args.js';
|
|
4
|
+
import { runCreate } from './commands/create.js';
|
|
5
|
+
import { runDoctor } from './commands/doctor.js';
|
|
6
|
+
import { runGenerate } from './commands/generate.js';
|
|
7
|
+
import { runSchema } from './commands/schema.js';
|
|
8
|
+
import { runServe } from './commands/serve.js';
|
|
9
|
+
import { runSync } from './commands/sync.js';
|
|
10
|
+
import { runTypes } from './commands/types.js';
|
|
11
|
+
import { runViewer } from './commands/viewer.js';
|
|
12
|
+
import { runOperations } from './commands/operations.js';
|
|
13
|
+
import { printDiagnostic, printDoctorHelp, printGenerateHelp, printHelp, printOperationsHelp, printSchemaHelp, printServeHelp, printTypesHelp, printViewerHelp } from './output.js';
|
|
14
|
+
export async function main(args = process.argv.slice(2)) {
|
|
15
|
+
const command = args[0] ?? 'help';
|
|
16
|
+
if (command === 'help' || command === '--help' || command === '-h') {
|
|
17
|
+
printHelp();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (command === '--version' || command === '-v') {
|
|
21
|
+
console.log('0.1.0');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (printSubcommandHelp(command, args.slice(1))) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const config = await loadConfig(parseGlobalOptions(args));
|
|
28
|
+
switch (command) {
|
|
29
|
+
case 'sync':
|
|
30
|
+
await runSync(config);
|
|
31
|
+
break;
|
|
32
|
+
case 'types':
|
|
33
|
+
await runTypes(config, args.slice(1));
|
|
34
|
+
break;
|
|
35
|
+
case 'schema':
|
|
36
|
+
await runSchema(config, args.slice(1));
|
|
37
|
+
break;
|
|
38
|
+
case 'doctor':
|
|
39
|
+
case 'check':
|
|
40
|
+
await runDoctor(config, args.slice(1));
|
|
41
|
+
break;
|
|
42
|
+
case 'create':
|
|
43
|
+
await runCreate(config, args.slice(1));
|
|
44
|
+
break;
|
|
45
|
+
case 'serve':
|
|
46
|
+
await runServe(config, args.slice(1));
|
|
47
|
+
break;
|
|
48
|
+
case 'viewer':
|
|
49
|
+
await runViewer(config, args.slice(1));
|
|
50
|
+
break;
|
|
51
|
+
case 'operations':
|
|
52
|
+
await runOperations(config, args.slice(1));
|
|
53
|
+
break;
|
|
54
|
+
case 'generate':
|
|
55
|
+
await runGenerate(config, args.slice(1));
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
throw new Error(`Unknown command "${command}". Run "async-db help".`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function printSubcommandHelp(command, args) {
|
|
62
|
+
if (!isHelpRequested(args)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
switch (command) {
|
|
66
|
+
case 'types':
|
|
67
|
+
printTypesHelp();
|
|
68
|
+
return true;
|
|
69
|
+
case 'schema':
|
|
70
|
+
printSchemaHelp();
|
|
71
|
+
return true;
|
|
72
|
+
case 'doctor':
|
|
73
|
+
case 'check':
|
|
74
|
+
printDoctorHelp();
|
|
75
|
+
return true;
|
|
76
|
+
case 'serve':
|
|
77
|
+
printServeHelp();
|
|
78
|
+
return true;
|
|
79
|
+
case 'viewer':
|
|
80
|
+
printViewerHelp();
|
|
81
|
+
return true;
|
|
82
|
+
case 'operations':
|
|
83
|
+
printOperationsHelp();
|
|
84
|
+
return true;
|
|
85
|
+
case 'generate':
|
|
86
|
+
printGenerateHelp(generateHelpUsage(args));
|
|
87
|
+
return true;
|
|
88
|
+
default:
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function generateHelpUsage(args) {
|
|
93
|
+
const registry = defaultGeneratorRegistry();
|
|
94
|
+
const target = args.find((arg) => !arg.startsWith('-'));
|
|
95
|
+
return registry.get(target)?.usage ?? registry.usage();
|
|
96
|
+
}
|
|
97
|
+
export function runCli(args = process.argv.slice(2)) {
|
|
98
|
+
main(args).catch((error) => {
|
|
99
|
+
const cliError = error;
|
|
100
|
+
if (cliError.diagnostics) {
|
|
101
|
+
for (const diagnostic of cliError.diagnostics) {
|
|
102
|
+
printDiagnostic(diagnostic);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
console.error(cliError.message);
|
|
106
|
+
process.exitCode = 1;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type CliDiagnostic = {
|
|
2
|
+
severity?: string;
|
|
3
|
+
message: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
};
|
|
6
|
+
type DoctorFinding = {
|
|
7
|
+
severity: string;
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
hint?: string;
|
|
11
|
+
};
|
|
12
|
+
type DoctorResult = {
|
|
13
|
+
findings: DoctorFinding[];
|
|
14
|
+
};
|
|
15
|
+
export declare function printDiagnostic(diagnostic: CliDiagnostic): void;
|
|
16
|
+
export declare function printDoctorResult(result: DoctorResult): void;
|
|
17
|
+
export declare function printHelp(): void;
|
|
18
|
+
export declare function printOperationsHelp(): void;
|
|
19
|
+
export declare function printTypesHelp(): void;
|
|
20
|
+
export declare function printSchemaHelp(): void;
|
|
21
|
+
export declare function printDoctorHelp(): void;
|
|
22
|
+
export declare function printViewerHelp(): void;
|
|
23
|
+
export declare function printServeHelp(): void;
|
|
24
|
+
export declare function printGenerateHelp(usage: string): void;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export function printDiagnostic(diagnostic) {
|
|
2
|
+
const prefix = diagnostic.severity === 'error' ? 'error' : 'warn';
|
|
3
|
+
console.error(`${prefix}: ${diagnostic.message}`);
|
|
4
|
+
}
|
|
5
|
+
export function printDoctorResult(result) {
|
|
6
|
+
if (result.findings.length === 0) {
|
|
7
|
+
console.log('async-db doctor found no issues');
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
console.log(`async-db doctor found ${result.findings.length} finding${result.findings.length === 1 ? '' : 's'}`);
|
|
11
|
+
for (const finding of result.findings) {
|
|
12
|
+
console.log(`${finding.severity}: ${finding.code}: ${finding.message}`);
|
|
13
|
+
if (finding.hint) {
|
|
14
|
+
console.log(` hint: ${finding.hint}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function printHelp() {
|
|
19
|
+
console.log(`async-db
|
|
20
|
+
|
|
21
|
+
Usage:
|
|
22
|
+
async-db sync
|
|
23
|
+
async-db types [--watch] [--out <file>]
|
|
24
|
+
async-db schema [resource]
|
|
25
|
+
async-db schema infer [resource] [--out <file>]
|
|
26
|
+
async-db schema unbundle [resource] [--schema-out <file>] [--seed-out <file>] [--empty-seed] [--force]
|
|
27
|
+
async-db schema unbundle --all [--schema-dir <dir>] [--force]
|
|
28
|
+
async-db schema bundle [resource] [--out <file>] [--force]
|
|
29
|
+
async-db schema bundle --all [--out <file>] [--force]
|
|
30
|
+
async-db schema manifest [--out <file>]
|
|
31
|
+
async-db schema validate
|
|
32
|
+
async-db operations build [--out <file>] [--refs-out <file>]
|
|
33
|
+
async-db operations contract [--out <file>] [--check]
|
|
34
|
+
async-db viewer manifest [--out <file>]
|
|
35
|
+
async-db doctor [--strict] [--json] [--production]
|
|
36
|
+
async-db check [--strict] [--json] [--production]
|
|
37
|
+
async-db create <collection> <json>
|
|
38
|
+
async-db serve [--host <host>] [--port <port>]
|
|
39
|
+
async-db generate hono [--out <dir>] [--api <targets>] [--app <shape>]
|
|
40
|
+
|
|
41
|
+
Options:
|
|
42
|
+
--cwd <dir> Project directory
|
|
43
|
+
--config <file> Config file path
|
|
44
|
+
`);
|
|
45
|
+
}
|
|
46
|
+
export function printOperationsHelp() {
|
|
47
|
+
console.log(`async-db operations
|
|
48
|
+
|
|
49
|
+
Usage:
|
|
50
|
+
async-db operations build [--out <file>] [--refs-out <file>]
|
|
51
|
+
async-db operations contract [--out <file>] [--check]
|
|
52
|
+
|
|
53
|
+
Options:
|
|
54
|
+
--out <file> Build: write the full server registry. Contract: write or check the client contract
|
|
55
|
+
--refs-out <file> Build only: write client-safe operation refs
|
|
56
|
+
--check Contract only: fail if the generated client contract differs from --out or outputs.operationRefs
|
|
57
|
+
--cwd <dir> Project directory
|
|
58
|
+
--config <file> Config file path
|
|
59
|
+
`);
|
|
60
|
+
}
|
|
61
|
+
export function printTypesHelp() {
|
|
62
|
+
console.log(`async-db types
|
|
63
|
+
|
|
64
|
+
Usage:
|
|
65
|
+
async-db types [--watch] [--out <file>]
|
|
66
|
+
|
|
67
|
+
Options:
|
|
68
|
+
--watch Regenerate types when fixture sources change
|
|
69
|
+
--out <file> Write generated types to this path
|
|
70
|
+
--cwd <dir> Project directory
|
|
71
|
+
--config <file> Config file path
|
|
72
|
+
`);
|
|
73
|
+
}
|
|
74
|
+
export function printSchemaHelp() {
|
|
75
|
+
console.log(`async-db schema
|
|
76
|
+
|
|
77
|
+
Usage:
|
|
78
|
+
async-db schema [resource]
|
|
79
|
+
async-db schema infer [resource] [--out <file>]
|
|
80
|
+
async-db schema unbundle [resource] [--schema-out <file>] [--seed-out <file>] [--empty-seed] [--force]
|
|
81
|
+
async-db schema unbundle --all [--schema-dir <dir>] [--force]
|
|
82
|
+
async-db schema bundle [resource] [--out <file>] [--force]
|
|
83
|
+
async-db schema bundle --all [--out <file>] [--force]
|
|
84
|
+
async-db schema manifest [--out <file>]
|
|
85
|
+
async-db schema validate
|
|
86
|
+
|
|
87
|
+
Options:
|
|
88
|
+
--out <file> Write schema manifest, inferred schema, or bundled schema output to this path
|
|
89
|
+
--schema-out <file> Write unbundled schema output to this path
|
|
90
|
+
--seed-out <file> Write unbundled seed output to this path
|
|
91
|
+
--schema-dir <dir> Write aggregate unbundled schema files under this directory
|
|
92
|
+
--empty-seed Write an empty seed fixture when unbundling schema-only resources
|
|
93
|
+
--force Allow overwriting outputs or writing bundle output inside db/
|
|
94
|
+
--all Skip the interactive target prompt and use all schemas
|
|
95
|
+
--cwd <dir> Project directory
|
|
96
|
+
--config <file> Config file path
|
|
97
|
+
`);
|
|
98
|
+
}
|
|
99
|
+
export function printDoctorHelp() {
|
|
100
|
+
console.log(`async-db doctor
|
|
101
|
+
|
|
102
|
+
Usage:
|
|
103
|
+
async-db doctor [--strict] [--json] [--production]
|
|
104
|
+
async-db check [--strict] [--json] [--production]
|
|
105
|
+
|
|
106
|
+
Options:
|
|
107
|
+
--strict Exit with an error when warnings are present
|
|
108
|
+
--json Print machine-readable findings
|
|
109
|
+
--production Include production-readiness guidance for JSON-backed resources
|
|
110
|
+
--cwd <dir> Project directory
|
|
111
|
+
--config <file> Config file path
|
|
112
|
+
`);
|
|
113
|
+
}
|
|
114
|
+
export function printViewerHelp() {
|
|
115
|
+
console.log(`async-db viewer
|
|
116
|
+
|
|
117
|
+
Usage:
|
|
118
|
+
async-db viewer manifest [--out <file>]
|
|
119
|
+
|
|
120
|
+
Options:
|
|
121
|
+
--out <file> Write generated viewer manifest output to this path
|
|
122
|
+
--cwd <dir> Project directory
|
|
123
|
+
--config <file> Config file path
|
|
124
|
+
`);
|
|
125
|
+
}
|
|
126
|
+
export function printServeHelp() {
|
|
127
|
+
console.log(`async-db serve
|
|
128
|
+
|
|
129
|
+
Usage:
|
|
130
|
+
async-db serve [--host <host>] [--port <port>]
|
|
131
|
+
|
|
132
|
+
Options:
|
|
133
|
+
--host <host> Host to bind, defaulting to configured server.host
|
|
134
|
+
--port <port> Port to bind, defaulting to configured server.port
|
|
135
|
+
--cwd <dir> Project directory
|
|
136
|
+
--config <file> Config file path
|
|
137
|
+
`);
|
|
138
|
+
}
|
|
139
|
+
export function printGenerateHelp(usage) {
|
|
140
|
+
console.log(`async-db generate
|
|
141
|
+
|
|
142
|
+
Usage:
|
|
143
|
+
${usage}
|
|
144
|
+
|
|
145
|
+
Options:
|
|
146
|
+
--cwd <dir> Project directory
|
|
147
|
+
--config <file> Config file path
|
|
148
|
+
`);
|
|
149
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'node:stream';
|
|
2
|
+
type SchemaPromptTarget = {
|
|
3
|
+
all?: boolean;
|
|
4
|
+
resourceName?: string;
|
|
5
|
+
};
|
|
6
|
+
type SchemaPromptOptions = {
|
|
7
|
+
command: string;
|
|
8
|
+
resources: string[];
|
|
9
|
+
input?: Readable & {
|
|
10
|
+
isTTY?: boolean;
|
|
11
|
+
};
|
|
12
|
+
output?: Writable & {
|
|
13
|
+
isTTY?: boolean;
|
|
14
|
+
};
|
|
15
|
+
isInteractive?: boolean;
|
|
16
|
+
ask?: (prompt: string) => Promise<string | undefined> | string | undefined;
|
|
17
|
+
write?: (text: string) => unknown;
|
|
18
|
+
};
|
|
19
|
+
export declare function promptForSchemaTarget(options: SchemaPromptOptions): Promise<SchemaPromptTarget | undefined>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline/promises';
|
|
2
|
+
export async function promptForSchemaTarget(options) {
|
|
3
|
+
const { command, resources, input = process.stdin, output = process.stdout, isInteractive = Boolean(input.isTTY && output.isTTY), ask, write = (text) => output.write(text), } = options;
|
|
4
|
+
if (!isInteractive) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const choices = [
|
|
8
|
+
{ label: 'All schemas', value: { all: true } },
|
|
9
|
+
...resources.map((resourceName) => ({
|
|
10
|
+
label: resourceName,
|
|
11
|
+
value: { resourceName },
|
|
12
|
+
})),
|
|
13
|
+
];
|
|
14
|
+
const prompt = createPrompt({ ask, input, output });
|
|
15
|
+
try {
|
|
16
|
+
write(`Select schema ${command} target:\n`);
|
|
17
|
+
for (const [index, choice] of choices.entries()) {
|
|
18
|
+
write(` ${index + 1}. ${choice.label}\n`);
|
|
19
|
+
}
|
|
20
|
+
write(' q. Cancel\n');
|
|
21
|
+
while (true) {
|
|
22
|
+
const answer = await prompt.question('Choice: ');
|
|
23
|
+
const normalized = String(answer ?? '').trim().toLowerCase();
|
|
24
|
+
if (normalized === '' || normalized === 'q' || normalized === 'quit' || normalized === 'cancel') {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (normalized === 'all') {
|
|
28
|
+
return { all: true };
|
|
29
|
+
}
|
|
30
|
+
const number = Number(normalized);
|
|
31
|
+
if (Number.isInteger(number) && number >= 1 && number <= choices.length) {
|
|
32
|
+
return choices[number - 1].value;
|
|
33
|
+
}
|
|
34
|
+
const resource = resources.find((resourceName) => resourceName.toLowerCase() === normalized);
|
|
35
|
+
if (resource) {
|
|
36
|
+
return { resourceName: resource };
|
|
37
|
+
}
|
|
38
|
+
write(`Invalid selection "${answer}". Choose 1-${choices.length}, "all", a resource name, or "q".\n`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
prompt.close();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function createPrompt({ ask, input, output }) {
|
|
46
|
+
if (ask) {
|
|
47
|
+
return {
|
|
48
|
+
question: ask,
|
|
49
|
+
close() { },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const rl = createInterface({ input, output });
|
|
53
|
+
return {
|
|
54
|
+
async question(prompt) {
|
|
55
|
+
try {
|
|
56
|
+
return await rl.question(prompt);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
close() {
|
|
63
|
+
rl.close();
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
type CacheWritePolicy = 'merge-and-invalidate' | 'invalidate' | 'refetch' | string;
|
|
2
|
+
type CacheEventPolicy = 'invalidate' | 'refetch' | false | string;
|
|
3
|
+
type CacheManifest = Record<string, unknown> & {
|
|
4
|
+
generatedAt?: string;
|
|
5
|
+
collections?: Record<string, unknown>;
|
|
6
|
+
documents?: Record<string, unknown>;
|
|
7
|
+
api?: {
|
|
8
|
+
log?: string;
|
|
9
|
+
events?: string;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type ClientCacheStorageContext = {
|
|
14
|
+
baseNamespace: string;
|
|
15
|
+
manifestFingerprint: string | null;
|
|
16
|
+
namespace: string;
|
|
17
|
+
};
|
|
18
|
+
type ClientCacheStorage = {
|
|
19
|
+
load?(context: ClientCacheStorageContext): unknown | Promise<unknown>;
|
|
20
|
+
save?(snapshot: ClientCacheSnapshot, context: ClientCacheStorageContext): unknown | Promise<unknown>;
|
|
21
|
+
clear?(context: ClientCacheStorageContext): unknown | Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
type ClientCacheSnapshot = {
|
|
24
|
+
namespace?: string;
|
|
25
|
+
manifestFingerprint?: string | null;
|
|
26
|
+
manifest?: unknown;
|
|
27
|
+
queries?: unknown[];
|
|
28
|
+
resources?: Record<string, unknown>;
|
|
29
|
+
entities?: Record<string, unknown>;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
};
|
|
32
|
+
type ClientCacheConfigInput = {
|
|
33
|
+
enabled?: boolean;
|
|
34
|
+
readPolicy?: string;
|
|
35
|
+
writePolicy?: CacheWritePolicy;
|
|
36
|
+
eventPolicy?: CacheEventPolicy;
|
|
37
|
+
manifest?: CacheManifest | null;
|
|
38
|
+
storage?: ClientCacheStorage | 'memory' | null;
|
|
39
|
+
};
|
|
40
|
+
type ClientCacheFactoryOptions = {
|
|
41
|
+
cache?: boolean | ClientCacheConfigInput | null;
|
|
42
|
+
cacheNamespace?: unknown;
|
|
43
|
+
fetchManifest?: () => unknown | Promise<unknown>;
|
|
44
|
+
createEventSource?: (path: string) => CacheEventSource | null | undefined;
|
|
45
|
+
restBasePath?: string;
|
|
46
|
+
};
|
|
47
|
+
type CacheEventSource = {
|
|
48
|
+
addEventListener?: (type: string, listener: (event: CacheEvent) => void) => unknown;
|
|
49
|
+
on?: (type: string, listener: (event: CacheEvent) => void) => unknown;
|
|
50
|
+
};
|
|
51
|
+
type CacheEvent = {
|
|
52
|
+
data?: string;
|
|
53
|
+
[key: string]: unknown;
|
|
54
|
+
};
|
|
55
|
+
type RestCacheRequest = Record<string, unknown> & {
|
|
56
|
+
method?: string;
|
|
57
|
+
path?: string;
|
|
58
|
+
};
|
|
59
|
+
type RestCacheResult = Record<string, unknown> & {
|
|
60
|
+
status?: number;
|
|
61
|
+
body?: unknown;
|
|
62
|
+
};
|
|
63
|
+
type GraphqlCacheRequest = Record<string, unknown> & {
|
|
64
|
+
query?: string;
|
|
65
|
+
variables?: unknown;
|
|
66
|
+
operationName?: string;
|
|
67
|
+
};
|
|
68
|
+
type GraphqlCacheResult = Record<string, unknown> & {
|
|
69
|
+
data?: unknown;
|
|
70
|
+
errors?: unknown[];
|
|
71
|
+
};
|
|
72
|
+
type CacheRequestOptions = {
|
|
73
|
+
cache?: false | string | {
|
|
74
|
+
readPolicy?: string;
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
type PublicClientCacheApi = {
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
clear(): void;
|
|
81
|
+
invalidate(resourceName?: string | null): void;
|
|
82
|
+
snapshot(): ClientCacheSnapshot;
|
|
83
|
+
watch(request: unknown, callback: (event: {
|
|
84
|
+
data: unknown;
|
|
85
|
+
stale: boolean;
|
|
86
|
+
source: 'cache';
|
|
87
|
+
}) => unknown): () => void;
|
|
88
|
+
};
|
|
89
|
+
type ClientCacheController = {
|
|
90
|
+
enabled: boolean;
|
|
91
|
+
publicApi: PublicClientCacheApi;
|
|
92
|
+
executeRestRead(request: RestCacheRequest, network: () => RestCacheResult | Promise<RestCacheResult>, requestOptions?: CacheRequestOptions): Promise<RestCacheResult | null>;
|
|
93
|
+
executeGraphqlRead(request: GraphqlCacheRequest, network: () => GraphqlCacheResult | Promise<GraphqlCacheResult>, requestOptions?: CacheRequestOptions): Promise<GraphqlCacheResult | null>;
|
|
94
|
+
recordRestWrite(request: RestCacheRequest, result: RestCacheResult): void;
|
|
95
|
+
recordGraphqlWrite(result: GraphqlCacheResult): void;
|
|
96
|
+
};
|
|
97
|
+
type IndexedDbCacheStorageOptions = {
|
|
98
|
+
name?: string;
|
|
99
|
+
storeName?: string;
|
|
100
|
+
key?: string;
|
|
101
|
+
indexedDB?: IDBFactory;
|
|
102
|
+
};
|
|
103
|
+
export declare function createClientCache(options?: ClientCacheFactoryOptions): ClientCacheController;
|
|
104
|
+
export declare function createIndexedDbCacheStorage(options?: IndexedDbCacheStorageOptions): ClientCacheStorage;
|
|
105
|
+
export {};
|