@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/docs/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @async/db Docs
|
|
2
|
+
|
|
3
|
+
This folder is the durable markdown manual for @async/db. The root [README](../README.md) is the mini guide; these pages hold the task and contract details.
|
|
4
|
+
|
|
5
|
+
## Start
|
|
6
|
+
|
|
7
|
+
- [Getting Started](./getting-started.md): install, first fixture, sync, serve, viewer, REST call, and first schema.
|
|
8
|
+
- [Concepts](./concepts.md): data-first fixtures, schema-first fixtures, mixed resources, runtime stores, source writebacks, and product boundaries.
|
|
9
|
+
- [Examples](../examples/basic/README.md): runnable example READMEs are the authority for example-specific commands.
|
|
10
|
+
|
|
11
|
+
## Build Local Data
|
|
12
|
+
|
|
13
|
+
- [Fixtures And Schemas](./fixtures-and-schemas.md): JSON, JSONC, CSV, schema files, `.schema.js`, Standard Schema validators, computed fields, source readers, nested folders, inference, and validation.
|
|
14
|
+
- [TypeScript Schema Sources](./typescript-schema-sources.md): JavaScript ESM schemas and TypeScript-authored schemas compiled to supported runtime files.
|
|
15
|
+
- [Generated Files](./generated-files.md): `.db/`, state, generated TypeScript, committed generated outputs, schema manifests, and cleanup rules.
|
|
16
|
+
- [Configuration](./configuration.md): `db.config.mjs`, fixture folders, resource naming, strictness, registered operations, mock delay/errors, server options, and runtime fork boundaries.
|
|
17
|
+
- [Production JSON Database](./json-production.md): scoped production use for `@async/db/json`, hard limits, operation boundaries, and mixed-store graduation.
|
|
18
|
+
- [Resource Graduation And Mixed Stores](./store-graduation.md): move one resource from JSON to SQLite/Postgres/custom stores while preserving app-facing operations.
|
|
19
|
+
- [Fork And Branch Workflows](./fork-branch-workflows.md): tenants, debug copies, snapshots, branches, and resource migrations as app-owned workflows.
|
|
20
|
+
- [CMS Storage Patterns](./cms-storage-patterns.md): app-owned CMS draft/publish helpers over JSON files, SQLite indexes, Postgres, and static JSON outputs.
|
|
21
|
+
- [Schema UI example](../examples/schema-ui/README.md): manifest-driven CMS HTML with **`serve.mjs`** SSR from live mirror rows (`node ./examples/schema-ui/serve.mjs`).
|
|
22
|
+
|
|
23
|
+
## Serve And Integrate
|
|
24
|
+
|
|
25
|
+
- [Server And Viewer](./server-and-viewer.md): REST routes, registered operations, GraphQL boundary, viewer, CSV import, watch behavior, batching, response formats, and local trust boundaries.
|
|
26
|
+
- [Prototype To Production REST Guide](./prototype-to-production.md): move `/db/*` prototypes to `/api/db/*` or `/api/*`, registered operation refs, and route lockdown.
|
|
27
|
+
- [Package API](./package-api.md): CLI commands, runtime API, HTTP client operations, schema/config helpers, and package export map.
|
|
28
|
+
- [Integrations](./integrations.md): Vite plugin, Hono route registration, SQLite starter generation, and optional dependency boundaries.
|
|
29
|
+
|
|
30
|
+
## Maintain The Repo
|
|
31
|
+
|
|
32
|
+
- [Architecture](./architecture.md): source-to-runtime flow, implementation boundaries, generated outputs, and where to start for code changes.
|
|
33
|
+
- [CI And Release](./ci-and-release.md): verification commands, Node versions, package `files`, pack dry-run expectations, and release hygiene.
|
|
34
|
+
- [Product Spec](../SPEC.md): full product model and acceptance criteria.
|
|
35
|
+
|
|
36
|
+
## Documentation Rules
|
|
37
|
+
|
|
38
|
+
- Keep the root README short enough to scan.
|
|
39
|
+
- Keep deep behavior near the contract it belongs to.
|
|
40
|
+
- Keep examples runnable and focused.
|
|
41
|
+
- Prefer exact commands and repo-relative links.
|
|
42
|
+
- When adding generated output examples, state whether the output is normally committed.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# @async/db Architecture
|
|
2
|
+
|
|
3
|
+
@async/db is a dependency-light Node.js ESM package. Fixture files become generated schema metadata, TypeScript types, runtime JSON state, and local API/viewer routes.
|
|
4
|
+
|
|
5
|
+
Use this page when deciding where behavior belongs in the implementation. Use [SPEC.md](../SPEC.md) for the full product and acceptance model.
|
|
6
|
+
|
|
7
|
+
## Main Flow
|
|
8
|
+
|
|
9
|
+
```txt
|
|
10
|
+
db/*.json, *.jsonc, *.csv, *.schema.json(c), *.schema.mjs, *.schema.js
|
|
11
|
+
-> source readers
|
|
12
|
+
-> resource schemas and diagnostics
|
|
13
|
+
-> sync output
|
|
14
|
+
-> .db/schema.generated.json
|
|
15
|
+
-> .db/types/index.d.ts and optional committed generated files
|
|
16
|
+
-> selected runtime store
|
|
17
|
+
-> package API, REST, GraphQL, viewer, client, and generators
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Public Surfaces
|
|
21
|
+
|
|
22
|
+
| Surface | Entry point | Notes |
|
|
23
|
+
| --- | --- | --- |
|
|
24
|
+
| CLI | `src/cli.ts`, `src/cli/index.ts`, `src/cli/commands/` | `sync`, `types`, `schema`, `doctor`, `check`, `create`, `serve`, `generate hono`. |
|
|
25
|
+
| Runtime API | `src/index.ts`, `src/features/runtime/` | Collections, singleton documents, validation, and storage adapters. |
|
|
26
|
+
| Config API | `src/config-public.ts`, `src/config.d.ts` | `defineConfig`, manifest helpers, and user config shape. |
|
|
27
|
+
| Schema helpers | `src/schema-builders.ts`, `src/schema.d.ts` | `.schema.mjs` and `.schema.js` authoring helpers. |
|
|
28
|
+
| HTTP client | `src/client.ts` | REST, GraphQL, registered query operations, direct batching, automatic batching, fork support. |
|
|
29
|
+
| REST server | `src/server.ts`, `src/rest/` | Dependency-free local routes and response shaping. |
|
|
30
|
+
| GraphQL | `src/graphql/` | Dependency-free subset parser, executor, and HTTP handler. |
|
|
31
|
+
| Viewer | `src/web/` | Built-in UI served at `server.apiBase`, defaulting to `/__db`. |
|
|
32
|
+
| Vite integration | `src/vite.ts`, `src/integrations/` | Optional dev server plugin and virtual client. |
|
|
33
|
+
| JSON/Hono/SQLite/Postgres/KV | `src/json.ts`, `src/hono.ts`, `src/sqlite.ts`, `src/postgres.ts`, `src/kv.ts`, `src/redis.ts`, `src/generate/hono.ts` | First-party JSON file database surface, optional runtime integrations, injected-client stores, and generated starter output. |
|
|
34
|
+
|
|
35
|
+
## Core Boundaries
|
|
36
|
+
|
|
37
|
+
- Source discovery and loading live under `src/features/schema/sources.ts`. Built-in readers handle JSON, JSONC, CSV, and schema files; custom readers normalize into the same data/schema source shape.
|
|
38
|
+
- Field normalization, inference, relations, and resource construction live under `src/features/schema/`.
|
|
39
|
+
- Validation and diagnostics live under `src/features/schema/validation.ts` and nearby schema feature modules.
|
|
40
|
+
- Sync lives under `src/features/sync/`. It writes generated schema, generated types, optional schema manifests, source metadata, and hydrates runtime store state.
|
|
41
|
+
- Runtime storage lives under `src/features/storage/` and `src/features/runtime/`. The default and first-party file database store is JSON files under `.db/state`; memory, static, sourceFile, SQLite, Postgres, KV, Redis-like, and custom stores fit behind the same store boundary.
|
|
42
|
+
- HTTP serving starts in `src/server.ts`. REST routing lives in `src/rest/`, GraphQL lives in `src/graphql/`, and built-in viewer HTML/JS lives in `src/web/`.
|
|
43
|
+
- Optional graduation paths are separate from the core. Hono/SQLite starter generation lives in `src/generate/hono.ts` and `src/generate/hono/`; optional integrations live in `src/integrations/`.
|
|
44
|
+
|
|
45
|
+
## Start Here When Changing Behavior
|
|
46
|
+
|
|
47
|
+
| Change | Start with |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| Source discovery or custom readers | `src/features/schema/sources.ts` |
|
|
50
|
+
| Schema inference or field normalization | `src/features/schema/fields.ts`, `src/features/schema/resource.ts` |
|
|
51
|
+
| Schema validation or diagnostics | `src/features/schema/validation.ts` |
|
|
52
|
+
| Runtime store hydration or generated outputs | `src/features/sync/index.ts`, `src/types.ts`, `src/schema-manifest.ts` |
|
|
53
|
+
| Package runtime APIs | `src/features/runtime/collection.ts`, `src/features/runtime/document.ts`, `src/features/runtime/db.ts` |
|
|
54
|
+
| REST routes or response shaping | `src/rest/handler.ts`, `src/rest/shape.ts` |
|
|
55
|
+
| GraphQL parsing or execution | `src/graphql/parser.ts`, `src/graphql/execute.ts` |
|
|
56
|
+
| Built-in viewer behavior | `src/web/viewer.ts` |
|
|
57
|
+
| CLI behavior | `src/cli/index.ts`, `src/cli/commands/` |
|
|
58
|
+
| Hono/SQLite starter generation | `src/generate/hono.ts`, `src/generate/hono/` |
|
|
59
|
+
| Optional Hono integration | `src/hono.ts` |
|
|
60
|
+
| Optional SQLite adapter | `src/sqlite.ts` |
|
|
61
|
+
| Optional Postgres/KV/Redis-like stores | `src/postgres.ts`, `src/kv.ts`, `src/redis.ts`, `src/integrations/` |
|
|
62
|
+
|
|
63
|
+
## Generated Outputs
|
|
64
|
+
|
|
65
|
+
Default generated runtime output:
|
|
66
|
+
|
|
67
|
+
```txt
|
|
68
|
+
.db/schema.generated.json
|
|
69
|
+
.db/types/index.d.ts
|
|
70
|
+
.db/state/*.json
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Normally `.db/` is uncommitted. Committed generated outputs are allowed only when configured, such as `outputs.committedTypes` or `outputs.schemaManifest`.
|
|
74
|
+
|
|
75
|
+
Examples that intentionally commit generated outputs:
|
|
76
|
+
|
|
77
|
+
```txt
|
|
78
|
+
examples/advanced/src/generated/db.types.d.ts
|
|
79
|
+
examples/basic/src/generated/db.types.d.ts
|
|
80
|
+
examples/computed-fields/src/generated/db.types.d.ts
|
|
81
|
+
examples/content-collections/src/generated/db.types.d.ts
|
|
82
|
+
examples/production-json/src/generated/db.types.d.ts
|
|
83
|
+
examples/schema-first/src/generated/db.types.d.ts
|
|
84
|
+
examples/schema-manifest/src/generated/db.schema.json
|
|
85
|
+
examples/schema-manifest/src/generated/db.types.d.ts
|
|
86
|
+
examples/schema-ui/src/generated/db.schema.json
|
|
87
|
+
examples/schema-ui/src/generated/db.types.d.ts
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
See [Generated Files](./generated-files.md).
|
|
91
|
+
|
|
92
|
+
## Local Trust Model
|
|
93
|
+
|
|
94
|
+
- `async-db serve` binds to `127.0.0.1` by default and is intended for local development.
|
|
95
|
+
- `.schema.mjs` and `.schema.js` files execute as local project JavaScript. Treat them like source code, not untrusted data.
|
|
96
|
+
- `db.config.mjs`, source readers, format renderers, and manifest hooks also execute as local project code.
|
|
97
|
+
- The viewer CSV import endpoint writes CSV files into the configured `dbDir`.
|
|
98
|
+
- The default `json` store keeps source fixtures clean and writes app changes to `.db/state`.
|
|
99
|
+
- The `sourceFile` store may write generated ids back to plain `.json` source fixtures when configured intentionally.
|
|
100
|
+
- `.db/` is generated runtime output and should normally stay uncommitted.
|
|
101
|
+
|
|
102
|
+
## Verification
|
|
103
|
+
|
|
104
|
+
Before handing off changes:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm run check
|
|
108
|
+
npm test
|
|
109
|
+
npm --cache /private/tmp/db-npm-cache pack --dry-run
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
See [CI And Release](./ci-and-release.md) for package and docs checks.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# CI And Release
|
|
2
|
+
|
|
3
|
+
This page documents the verification and package checks that keep docs, examples, and generated-file policy honest.
|
|
4
|
+
|
|
5
|
+
## Supported Node Versions
|
|
6
|
+
|
|
7
|
+
The package supports Node.js 20 and newer.
|
|
8
|
+
|
|
9
|
+
CI runs on Node.js 20, 22, and 24 through `.github/workflows/ci.yml`.
|
|
10
|
+
|
|
11
|
+
Generated Hono/SQLite standalone apps may require newer Node versions because SQLite output uses `node:sqlite`.
|
|
12
|
+
|
|
13
|
+
## Required Verification
|
|
14
|
+
|
|
15
|
+
Run these before handing off changes:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm run release:check
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
If the default npm cache has ownership or permission issues on this machine, use a temp cache for the pack check:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm --cache /private/tmp/async-db-npm-cache pack --dry-run
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`release:check` expands to:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm run check
|
|
31
|
+
npm test
|
|
32
|
+
npm pack --dry-run
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Useful Smoke Commands
|
|
36
|
+
|
|
37
|
+
Use the dev loop while editing package code:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm run dev # watch src and relaunch all examples
|
|
41
|
+
npm run examples # one-shot all examples server for smoke checks
|
|
42
|
+
npm run watch # compile dist and test-build in watch mode only
|
|
43
|
+
npm run cli -- sync --cwd ./examples/basic
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Use `npm run dev` for active package work. Use `npm run examples` for CI-like example smoke checks.
|
|
47
|
+
Npm task entrypoints live under `scripts/tasks/`; reusable helper scripts live directly under `scripts/`.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm run db -- sync --cwd ./examples/basic
|
|
51
|
+
npm run db -- schema validate --cwd ./examples/basic
|
|
52
|
+
npm run db -- create users '{"id":"u_2","name":"Grace Hopper","email":"grace@example.com"}' --cwd ./examples/basic
|
|
53
|
+
npm run examples
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Use `npm run examples -- --tailscale-serve` only for local tailnet previews.
|
|
57
|
+
The default examples command remains loopback-only and does not configure
|
|
58
|
+
Tailscale.
|
|
59
|
+
|
|
60
|
+
The local REST server binds a loopback port. In sandboxed environments this may require explicit approval:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm run db -- serve --cwd ./examples/basic
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Package Files Allowlist
|
|
67
|
+
|
|
68
|
+
`package.json` includes:
|
|
69
|
+
|
|
70
|
+
```txt
|
|
71
|
+
src/**/*.js
|
|
72
|
+
src/**/*.d.ts
|
|
73
|
+
scripts
|
|
74
|
+
examples/*/README.md
|
|
75
|
+
examples/*/example.json
|
|
76
|
+
examples/*/package.json
|
|
77
|
+
examples/*/db/**
|
|
78
|
+
examples/*/db.config.mjs
|
|
79
|
+
examples/*/src/**
|
|
80
|
+
docs/**/*.md
|
|
81
|
+
!docs/goals/**
|
|
82
|
+
db.config.example.mjs
|
|
83
|
+
CHANGELOG.md
|
|
84
|
+
README.md
|
|
85
|
+
SPEC.md
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Docs restructuring affects the published package because `docs/**/*.md` is included, except local GoalBuddy boards under `docs/goals/`. Use `npm pack --dry-run` to confirm the tarball contains the expected docs and does not include generated runtime output.
|
|
89
|
+
|
|
90
|
+
## Generated Runtime Output
|
|
91
|
+
|
|
92
|
+
Generated `.db/` output should normally stay uncommitted.
|
|
93
|
+
|
|
94
|
+
Committed generated files are allowed when configured:
|
|
95
|
+
|
|
96
|
+
```txt
|
|
97
|
+
examples/advanced/src/generated/db.types.d.ts
|
|
98
|
+
examples/basic/src/generated/db.types.d.ts
|
|
99
|
+
examples/computed-fields/src/generated/db.types.d.ts
|
|
100
|
+
examples/content-collections/src/generated/db.types.d.ts
|
|
101
|
+
examples/production-json/src/generated/db.types.d.ts
|
|
102
|
+
examples/schema-first/src/generated/db.types.d.ts
|
|
103
|
+
examples/schema-manifest/src/generated/db.schema.json
|
|
104
|
+
examples/schema-manifest/src/generated/db.types.d.ts
|
|
105
|
+
examples/schema-ui/src/generated/db.schema.json
|
|
106
|
+
examples/schema-ui/src/generated/db.types.d.ts
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
If a smoke command writes `.db/` inside an example, remove that generated runtime state before finalizing unless the task explicitly asks to commit it.
|
|
110
|
+
|
|
111
|
+
## Docs Link Checks
|
|
112
|
+
|
|
113
|
+
Use lightweight checks after docs edits:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
wc -l README.md
|
|
117
|
+
rg -n "\\]\\(#" README.md docs examples
|
|
118
|
+
rg -n "docs/|SPEC.md|architecture.md" README.md docs examples -g "*.md"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The first check confirms the README stayed compact. The second highlights same-page anchors that may need review after moving sections. The third makes docs and source-of-truth links easy to inspect.
|
|
122
|
+
|
|
123
|
+
## Release Hygiene
|
|
124
|
+
|
|
125
|
+
- Keep `CHANGELOG.md` focused on release history, not docs planning notes.
|
|
126
|
+
- Keep root `SPEC.md` as the product and acceptance source of truth.
|
|
127
|
+
- Keep implementation ownership and source maps in [Architecture](./architecture.md) and `AGENTS.md`, not duplicated across every doc page.
|
|
128
|
+
|
|
129
|
+
## Release Automation
|
|
130
|
+
|
|
131
|
+
Release pull requests and npm publication are handled by `.github/workflows/release.yml`.
|
|
132
|
+
|
|
133
|
+
- Every push to `main` runs Release Please.
|
|
134
|
+
- After `0.1.0`, Release Please opens or updates a release PR with the next version, `package.json`, `.release-please-manifest.json`, and `CHANGELOG.md`.
|
|
135
|
+
- Merging a release PR creates the GitHub release.
|
|
136
|
+
- When a Release Please release is created, the same workflow checks out the release commit, runs `npm run release:check`, packs the package, publishes `@async/db` to npm, and uploads the tarball to the GitHub release.
|
|
137
|
+
- The first `0.1.0` release is seeded in `.release-please-manifest.json`; publish it by pushing the existing `v0.1.0` tag, or by running the `Release` workflow manually with `v0.1.0` after the tag exists.
|
|
138
|
+
|
|
139
|
+
The release workflow uses npm Trusted Publishing through GitHub Actions OIDC. Before the first automated publish, configure npm for:
|
|
140
|
+
|
|
141
|
+
```txt
|
|
142
|
+
package: @async/db
|
|
143
|
+
owner/repo: async-framework/async-db
|
|
144
|
+
workflow: release.yml
|
|
145
|
+
environment: none
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Keep the package public through `publishConfig.access: "public"` and the workflow publish command:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npm publish --access public
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
If Trusted Publishing is not configured yet, the release workflow can create the release PR and GitHub release, but npm publish will fail until npm trusts this repository and workflow.
|
|
155
|
+
|
|
156
|
+
## First Release
|
|
157
|
+
|
|
158
|
+
The first public package version is already recorded as `0.1.0` in `package.json`, `CHANGELOG.md`, and `.release-please-manifest.json`. After npm Trusted Publishing is configured:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
git tag v0.1.0
|
|
162
|
+
git push origin v0.1.0
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The tag publish path validates that the tag matches `package.json`, runs `npm run release:check`, publishes the tarball, creates the GitHub release if needed, and uploads the tarball as a release asset.
|
|
166
|
+
|
|
167
|
+
## Manual Release Checks
|
|
168
|
+
|
|
169
|
+
Use local scripts for preflight and emergency manual publish work:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
npm run release:check
|
|
173
|
+
npm run release:pack
|
|
174
|
+
npm run release:publish
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Prefer the GitHub workflow for normal releases so npm provenance is tied to the release commit.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# CMS Storage Patterns
|
|
2
|
+
|
|
3
|
+
CMS workflows are app code on top of `@async/db` primitives. The package should not know what `draft`, `review`, `published`, or `unpublished` mean.
|
|
4
|
+
|
|
5
|
+
## App Code Boundary
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
export function createCms(db, { tenantId }) {
|
|
9
|
+
return {
|
|
10
|
+
async saveDraft(pageId, changes) {
|
|
11
|
+
const tenant = await db.forks.open(tenantId);
|
|
12
|
+
const draft = await tenant.branches.open('draft');
|
|
13
|
+
return draft.collection('pages').patch(pageId, {
|
|
14
|
+
...changes,
|
|
15
|
+
status: 'draft',
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
async publish() {
|
|
20
|
+
const tenant = await db.forks.open(tenantId);
|
|
21
|
+
const draft = await tenant.branches.open('draft');
|
|
22
|
+
const published = await tenant.branches.open('published');
|
|
23
|
+
const pages = await draft.collection('pages').all();
|
|
24
|
+
|
|
25
|
+
await published.collection('pages').replaceAll(
|
|
26
|
+
pages
|
|
27
|
+
.filter((page) => page.status === 'published')
|
|
28
|
+
.map(({ id, slug, title, status, summary, bodyMarkdown }) => ({
|
|
29
|
+
id,
|
|
30
|
+
slug,
|
|
31
|
+
title,
|
|
32
|
+
status,
|
|
33
|
+
summary,
|
|
34
|
+
bodyMarkdown,
|
|
35
|
+
})),
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`@async/db` owns forks, branches, snapshots, resources, operations, migrations, and routing. `@async/db/json` owns file/object storage, durability, encryption hooks, corruption checks, and layout.
|
|
43
|
+
|
|
44
|
+
## Pattern 1: One JSON File Per Resource
|
|
45
|
+
|
|
46
|
+
Use this for simple content:
|
|
47
|
+
|
|
48
|
+
```txt
|
|
49
|
+
forks/tenant_acme/branches/draft/resources/pages.json
|
|
50
|
+
forks/tenant_acme/branches/published/resources/pages.json
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The app filters draft records and writes the public result into the `published` branch.
|
|
54
|
+
|
|
55
|
+
## Pattern 2: App-Owned Static JSON Outputs
|
|
56
|
+
|
|
57
|
+
When static hosting, S3/R2 reads, or page-level cache invalidation matter, keep that materialization in app code instead of configuring the JSON store layout:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
const tenant = await db.forks.open(tenantId);
|
|
61
|
+
const publishedBranch = await tenant.branches.open('published');
|
|
62
|
+
const published = await publishedBranch.collection('pages').all();
|
|
63
|
+
|
|
64
|
+
for (const page of published) {
|
|
65
|
+
await writePublicJson(`pages/${page.slug}.json`, page);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The package owns resource reads/writes and branch isolation. The app owns any extra files it wants to publish for CDN or public API access.
|
|
70
|
+
|
|
71
|
+
## Pattern 3: JSON Files With SQLite Metadata Index
|
|
72
|
+
|
|
73
|
+
Use JSON files as documents and SQLite as an app-owned metadata index:
|
|
74
|
+
|
|
75
|
+
```txt
|
|
76
|
+
content/pages/home.json
|
|
77
|
+
content/pages/about.json
|
|
78
|
+
content-index.sqlite
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The app writes the JSON document and updates SQLite metadata such as `slug`, `status`, `published_at`, and `file_path`. Queries use SQLite to find files, then read JSON documents.
|
|
82
|
+
|
|
83
|
+
## Pattern 4: Draft JSON To Published Postgres
|
|
84
|
+
|
|
85
|
+
Keep editorial drafts as JSON, then materialize published records into Postgres:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
await cms.publish({
|
|
89
|
+
from: { branch: 'draft', store: 'json' },
|
|
90
|
+
to: { branch: 'published', store: 'postgres' },
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
This is useful when the public site needs database indexes but editorial workflow still benefits from file-like JSON.
|
|
95
|
+
|
|
96
|
+
## Pattern 5: Static JSON API Materialization
|
|
97
|
+
|
|
98
|
+
Publishing can write multiple public JSON outputs:
|
|
99
|
+
|
|
100
|
+
```txt
|
|
101
|
+
published/pages.json
|
|
102
|
+
published/pages/home.json
|
|
103
|
+
published/navigation.json
|
|
104
|
+
published/search-index.json
|
|
105
|
+
published/sitemap.json
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
That materialization is app-owned. The package provides resource reads/writes, branches, snapshots, and JSON storage helpers.
|
package/docs/concepts.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Concepts
|
|
2
|
+
|
|
3
|
+
@async/db turns local fixture sources into generated contracts, runtime state, local APIs, and type metadata. The default path is intentionally small: write fixture files first, then add schema only when the app contract needs it.
|
|
4
|
+
|
|
5
|
+
## Product Boundary
|
|
6
|
+
|
|
7
|
+
@async/db is:
|
|
8
|
+
|
|
9
|
+
- local development and test infrastructure
|
|
10
|
+
- a simple JSON file database for scoped low-write production resources
|
|
11
|
+
- data-first by default
|
|
12
|
+
- REST-first by default
|
|
13
|
+
- dependency-light in the core package
|
|
14
|
+
- useful before the real database or backend contract is settled
|
|
15
|
+
- a stable API/data layer while selected resources graduate to SQLite, Postgres, or custom stores
|
|
16
|
+
- a way to isolate data in forks, branches, snapshots, and resource-by-resource migrations
|
|
17
|
+
|
|
18
|
+
@async/db is not:
|
|
19
|
+
|
|
20
|
+
- a hosted production database service
|
|
21
|
+
- a multi-writer transactional database
|
|
22
|
+
- an auth or permission system
|
|
23
|
+
- an ORM
|
|
24
|
+
- broad JSON Schema compatibility
|
|
25
|
+
- a replacement for application-owned validation in production services
|
|
26
|
+
|
|
27
|
+
The JSON store is appropriate in production only for small, low-write, file-suitable resources such as settings, feature flags, content, templates, policy rules, and seed data. Use SQLite, Postgres, or another app-owned store for high-write records, transactional data, analytics/events, chat/messages, ledgers, inventory counters, multi-instance writes, and compliance-heavy data.
|
|
28
|
+
|
|
29
|
+
Forks and branches are generic database lifecycle primitives. App code can use them for tenants, CMS draft/publish workflows, feature-flag previews, settings rollback, prompt experiments, debug snapshots, and forked test environments. @async/db does not know what "paid", "published", or "approved" means; those decisions belong to the app.
|
|
30
|
+
|
|
31
|
+
## Data-First
|
|
32
|
+
|
|
33
|
+
Start with `db/*.json`, `db/*.jsonc`, or `db/*.csv` when you already have sample records.
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
[
|
|
37
|
+
{
|
|
38
|
+
"id": "u_1",
|
|
39
|
+
"name": "Ada Lovelace",
|
|
40
|
+
"active": true
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
@async/db infers useful local contracts from the fixture shape. It uses those contracts for generated types, REST metadata, GraphQL metadata, viewer metadata, and write validation.
|
|
46
|
+
|
|
47
|
+
When inference is ambiguous, @async/db should emit diagnostics and `doctor` suggestions instead of guessing too hard.
|
|
48
|
+
|
|
49
|
+
## Schema-First
|
|
50
|
+
|
|
51
|
+
Use schema-first fixtures when you know the contract before you have useful records.
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"kind": "collection",
|
|
56
|
+
"idField": "id",
|
|
57
|
+
"fields": {
|
|
58
|
+
"id": { "type": "string", "required": true },
|
|
59
|
+
"role": {
|
|
60
|
+
"type": "enum",
|
|
61
|
+
"values": ["admin", "user"],
|
|
62
|
+
"default": "user"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"seed": []
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Schema-first resources can start empty and still generate types, REST metadata, GraphQL metadata, and viewer metadata.
|
|
70
|
+
|
|
71
|
+
## Mixed Mode
|
|
72
|
+
|
|
73
|
+
Mixed mode means a resource has both schema and data sources:
|
|
74
|
+
|
|
75
|
+
```txt
|
|
76
|
+
db/users.schema.json
|
|
77
|
+
db/users.json
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The schema file is authoritative. The data file provides seed records. If a schema file still contains embedded `seed` while a data fixture exists, @async/db ignores the embedded seed and warns.
|
|
81
|
+
|
|
82
|
+
Useful commands:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm run db -- schema unbundle users
|
|
86
|
+
npm run db -- schema bundle users --out artifacts/users.bundle.schema.json
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Keep bundled schema-plus-seed artifacts outside `db/` unless you intentionally use `--force`.
|
|
90
|
+
|
|
91
|
+
## Runtime Stores
|
|
92
|
+
|
|
93
|
+
The default `json` store keeps source fixtures clean and writes app changes to generated runtime state:
|
|
94
|
+
|
|
95
|
+
```txt
|
|
96
|
+
db/users.json source fixture
|
|
97
|
+
.db/state/users.json writable runtime JSON store
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This is the safest default for local development because tests, demos, and UI prototyping do not rewrite committed fixtures.
|
|
101
|
+
|
|
102
|
+
It is also the first-party JSON file database for production resources that should remain small, reviewable, and low-write. Keep production app traffic behind @async/db resources or registered operations so a resource can later move from JSON to SQLite, Postgres, or a custom store without rewriting frontend data access.
|
|
103
|
+
|
|
104
|
+
Bind a resource to a different store when runtime state belongs somewhere else:
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
export default {
|
|
108
|
+
stores: {
|
|
109
|
+
default: 'json',
|
|
110
|
+
},
|
|
111
|
+
resources: {
|
|
112
|
+
settings: { store: 'json' },
|
|
113
|
+
activityEvents: { store: 'sqlite' },
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Source File Store
|
|
119
|
+
|
|
120
|
+
Use the `sourceFile` store only when you intentionally want @async/db to write supported changes back to source files.
|
|
121
|
+
|
|
122
|
+
The main source writeback case is generated ids for plain `.json` collection fixtures that omit `id`. JSONC and CSV sources remain parsed source inputs; generated runtime state still lives under `.db/`.
|
|
123
|
+
|
|
124
|
+
## Diagnostics
|
|
125
|
+
|
|
126
|
+
Diagnostics are part of the workflow:
|
|
127
|
+
|
|
128
|
+
- schema errors should block invalid resources
|
|
129
|
+
- warnings should surface schema/data drift without breaking unrelated resources
|
|
130
|
+
- `doctor` should suggest helpful schema or fixture improvements
|
|
131
|
+
- `check --strict` should make warnings fail in CI
|
|
132
|
+
|
|
133
|
+
Commands:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npm run db -- doctor
|
|
137
|
+
npm run db -- doctor --json
|
|
138
|
+
npm run db -- check --strict
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
See [Fixtures And Schemas](./fixtures-and-schemas.md) for authoring details and [Server And Viewer](./server-and-viewer.md) for how diagnostics appear while serving.
|