@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,69 @@
|
|
|
1
|
+
type KvClient = {
|
|
2
|
+
get(key: string): string | null | undefined | Promise<string | null | undefined>;
|
|
3
|
+
set(key: string, value: string): unknown | Promise<unknown>;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
};
|
|
6
|
+
type KvStoreOptions = {
|
|
7
|
+
client?: KvClient | null;
|
|
8
|
+
prefix?: string;
|
|
9
|
+
close?: boolean | ((client: KvClient | null | undefined) => unknown | Promise<unknown>);
|
|
10
|
+
};
|
|
11
|
+
type RuntimeConfig = Record<string, unknown>;
|
|
12
|
+
type RuntimeResource = {
|
|
13
|
+
name: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
type StoreFactoryContext = {
|
|
17
|
+
config: RuntimeConfig;
|
|
18
|
+
storeName: string;
|
|
19
|
+
};
|
|
20
|
+
type ResourceWriteOperation<T> = () => T | Promise<T>;
|
|
21
|
+
export declare const kvStoreCapabilities: {
|
|
22
|
+
writable: boolean;
|
|
23
|
+
persistence: string;
|
|
24
|
+
atomicity: string;
|
|
25
|
+
liveEvents: boolean;
|
|
26
|
+
staticExport: boolean;
|
|
27
|
+
production: string;
|
|
28
|
+
};
|
|
29
|
+
export declare function kvStore(options?: KvStoreOptions): ({ config, storeName }: StoreFactoryContext) => {
|
|
30
|
+
name: string;
|
|
31
|
+
capabilities: {
|
|
32
|
+
writable: boolean;
|
|
33
|
+
persistence: string;
|
|
34
|
+
atomicity: string;
|
|
35
|
+
liveEvents: boolean;
|
|
36
|
+
staticExport: boolean;
|
|
37
|
+
production: string;
|
|
38
|
+
};
|
|
39
|
+
hydrate(resources: RuntimeResource[]): Promise<void>;
|
|
40
|
+
readResource(resource: RuntimeResource, fallback: unknown): Promise<unknown>;
|
|
41
|
+
writeResource(resource: RuntimeResource, value: unknown): Promise<void>;
|
|
42
|
+
withResourceWrite<T>(resource: RuntimeResource, operation: ResourceWriteOperation<T>): Promise<T>;
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
};
|
|
45
|
+
export declare function redisStore(options?: KvStoreOptions): ({ config, storeName }: StoreFactoryContext) => {
|
|
46
|
+
name: string;
|
|
47
|
+
capabilities: {
|
|
48
|
+
writable: boolean;
|
|
49
|
+
persistence: string;
|
|
50
|
+
atomicity: string;
|
|
51
|
+
liveEvents: boolean;
|
|
52
|
+
staticExport: boolean;
|
|
53
|
+
production: string;
|
|
54
|
+
};
|
|
55
|
+
hydrate(resources: RuntimeResource[]): Promise<void>;
|
|
56
|
+
readResource(resource: RuntimeResource, fallback: unknown): Promise<unknown>;
|
|
57
|
+
writeResource(resource: RuntimeResource, value: unknown): Promise<void>;
|
|
58
|
+
withResourceWrite<T>(resource: RuntimeResource, operation: ResourceWriteOperation<T>): Promise<T>;
|
|
59
|
+
close(): Promise<void>;
|
|
60
|
+
};
|
|
61
|
+
export declare const redisStoreCapabilities: {
|
|
62
|
+
writable: boolean;
|
|
63
|
+
persistence: string;
|
|
64
|
+
atomicity: string;
|
|
65
|
+
liveEvents: boolean;
|
|
66
|
+
staticExport: boolean;
|
|
67
|
+
production: string;
|
|
68
|
+
};
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { dbError } from '../errors.js';
|
|
2
|
+
import { closeInjectedClient, createResourceWriteQueue, envelopeForResource, hydrateJsonResourceStore, parseJsonEnvelope, } from '../features/storage/resource-json.js';
|
|
3
|
+
export const kvStoreCapabilities = {
|
|
4
|
+
writable: true,
|
|
5
|
+
persistence: 'kv',
|
|
6
|
+
atomicity: 'resource',
|
|
7
|
+
liveEvents: true,
|
|
8
|
+
staticExport: false,
|
|
9
|
+
production: 'small-app',
|
|
10
|
+
};
|
|
11
|
+
export function kvStore(options = {}) {
|
|
12
|
+
const { client, prefix = 'async-db:', close = false, } = options;
|
|
13
|
+
const withQueuedWrite = createResourceWriteQueue();
|
|
14
|
+
return ({ config, storeName }) => {
|
|
15
|
+
assertKvClient(client, storeName);
|
|
16
|
+
function keyFor(resource) {
|
|
17
|
+
return `${prefix}${encodeURIComponent(resource.name)}`;
|
|
18
|
+
}
|
|
19
|
+
async function readEnvelope(resource) {
|
|
20
|
+
return parseJsonEnvelope(await client.get(keyFor(resource)), storeName);
|
|
21
|
+
}
|
|
22
|
+
async function writeEnvelope(resource, envelope) {
|
|
23
|
+
await client.set(keyFor(resource), JSON.stringify(envelope));
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
name: storeName,
|
|
27
|
+
capabilities: kvStoreCapabilities,
|
|
28
|
+
async hydrate(resources) {
|
|
29
|
+
for (const resource of resources) {
|
|
30
|
+
await hydrateJsonResourceStore({
|
|
31
|
+
config,
|
|
32
|
+
resource,
|
|
33
|
+
readEnvelope,
|
|
34
|
+
writeEnvelope,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
async readResource(resource, fallback) {
|
|
39
|
+
const envelope = await readEnvelope(resource);
|
|
40
|
+
return envelope ? envelope.value : fallback;
|
|
41
|
+
},
|
|
42
|
+
async writeResource(resource, value) {
|
|
43
|
+
await writeEnvelope(resource, envelopeForResource(resource, value));
|
|
44
|
+
},
|
|
45
|
+
withResourceWrite(resource, operation) {
|
|
46
|
+
return withQueuedWrite(keyFor(resource), operation);
|
|
47
|
+
},
|
|
48
|
+
close() {
|
|
49
|
+
return closeInjectedClient(client, close);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function redisStore(options = {}) {
|
|
55
|
+
return kvStore(options);
|
|
56
|
+
}
|
|
57
|
+
export const redisStoreCapabilities = kvStoreCapabilities;
|
|
58
|
+
function assertKvClient(client, storeName) {
|
|
59
|
+
if (client && typeof client.get === 'function' && typeof client.set === 'function') {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
throw dbError('KV_STORE_CLIENT_REQUIRED', `KV store "${storeName}" requires an injected client with get(key) and set(key, value).`, {
|
|
63
|
+
status: 500,
|
|
64
|
+
hint: 'Pass a Redis-like, edge KV, or compatible object to kvStore({ client }).',
|
|
65
|
+
details: {
|
|
66
|
+
store: storeName,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
type PostgresQueryResult = {
|
|
2
|
+
rows?: Array<Record<string, unknown>>;
|
|
3
|
+
};
|
|
4
|
+
type PostgresClient = {
|
|
5
|
+
query(sql: string, params?: unknown[]): PostgresQueryResult | Promise<PostgresQueryResult>;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
type PostgresStoreOptions = {
|
|
9
|
+
client?: PostgresClient | null;
|
|
10
|
+
schema?: string;
|
|
11
|
+
table?: string;
|
|
12
|
+
namespace?: string;
|
|
13
|
+
migrate?: boolean;
|
|
14
|
+
close?: boolean | ((client: PostgresClient | null | undefined) => unknown | Promise<unknown>);
|
|
15
|
+
};
|
|
16
|
+
type RuntimeConfig = Record<string, unknown>;
|
|
17
|
+
type RuntimeResource = {
|
|
18
|
+
name: string;
|
|
19
|
+
kind?: string;
|
|
20
|
+
dataHash?: string | null;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
};
|
|
23
|
+
type StoreFactoryContext = {
|
|
24
|
+
config: RuntimeConfig;
|
|
25
|
+
storeName: string;
|
|
26
|
+
};
|
|
27
|
+
type ResourceWriteOperation<T> = () => T | Promise<T>;
|
|
28
|
+
export declare const postgresStoreCapabilities: {
|
|
29
|
+
writable: boolean;
|
|
30
|
+
persistence: string;
|
|
31
|
+
atomicity: string;
|
|
32
|
+
liveEvents: boolean;
|
|
33
|
+
staticExport: boolean;
|
|
34
|
+
production: string;
|
|
35
|
+
};
|
|
36
|
+
export declare function postgresStore(options?: PostgresStoreOptions): ({ config, storeName }: StoreFactoryContext) => {
|
|
37
|
+
name: string;
|
|
38
|
+
capabilities: {
|
|
39
|
+
writable: boolean;
|
|
40
|
+
persistence: string;
|
|
41
|
+
atomicity: string;
|
|
42
|
+
liveEvents: boolean;
|
|
43
|
+
staticExport: boolean;
|
|
44
|
+
production: string;
|
|
45
|
+
};
|
|
46
|
+
hydrate(resources: RuntimeResource[]): Promise<void>;
|
|
47
|
+
readResource(resource: RuntimeResource, fallback: unknown): Promise<unknown>;
|
|
48
|
+
writeResource(resource: RuntimeResource, value: unknown): Promise<void>;
|
|
49
|
+
withResourceWrite<T>(resource: RuntimeResource, operation: ResourceWriteOperation<T>): Promise<T>;
|
|
50
|
+
close(): Promise<void>;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { dbError } from '../errors.js';
|
|
2
|
+
import { createResourceWriteQueue, hydrateJsonResourceStore, closeInjectedClient, } from '../features/storage/resource-json.js';
|
|
3
|
+
export const postgresStoreCapabilities = {
|
|
4
|
+
writable: true,
|
|
5
|
+
persistence: 'postgres',
|
|
6
|
+
atomicity: 'resource',
|
|
7
|
+
liveEvents: true,
|
|
8
|
+
staticExport: false,
|
|
9
|
+
production: 'small-app',
|
|
10
|
+
};
|
|
11
|
+
export function postgresStore(options = {}) {
|
|
12
|
+
const { client, schema = 'public', table = '_async_db_resources', namespace = 'default', migrate = true, close = false, } = options;
|
|
13
|
+
const withQueuedWrite = createResourceWriteQueue();
|
|
14
|
+
let migrated = false;
|
|
15
|
+
return ({ config, storeName }) => {
|
|
16
|
+
assertPostgresClient(client, storeName);
|
|
17
|
+
const qualifiedTable = `${quoteIdentifier(schema)}.${quoteIdentifier(table)}`;
|
|
18
|
+
async function ensureMigrated() {
|
|
19
|
+
if (!migrate || migrated) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (schema !== 'public') {
|
|
23
|
+
await client.query(`CREATE SCHEMA IF NOT EXISTS ${quoteIdentifier(schema)}`);
|
|
24
|
+
}
|
|
25
|
+
await client.query(`CREATE TABLE IF NOT EXISTS ${qualifiedTable} (
|
|
26
|
+
namespace TEXT NOT NULL,
|
|
27
|
+
name TEXT NOT NULL,
|
|
28
|
+
kind TEXT NOT NULL,
|
|
29
|
+
source_hash TEXT,
|
|
30
|
+
value JSONB NOT NULL,
|
|
31
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
32
|
+
PRIMARY KEY (namespace, name)
|
|
33
|
+
)`);
|
|
34
|
+
migrated = true;
|
|
35
|
+
}
|
|
36
|
+
async function readEnvelope(resource) {
|
|
37
|
+
await ensureMigrated();
|
|
38
|
+
const result = await client.query(`SELECT kind, source_hash, value FROM ${qualifiedTable} WHERE namespace = $1 AND name = $2`, [namespace, resource.name]);
|
|
39
|
+
const row = result?.rows?.[0];
|
|
40
|
+
if (!row) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
kind: String(row.kind),
|
|
45
|
+
sourceHash: typeof row.source_hash === 'string' ? row.source_hash : null,
|
|
46
|
+
value: typeof row.value === 'string' ? JSON.parse(row.value) : row.value,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function writeEnvelope(resource, envelope) {
|
|
50
|
+
await ensureMigrated();
|
|
51
|
+
await client.query(`INSERT INTO ${qualifiedTable} (namespace, name, kind, source_hash, value, updated_at)
|
|
52
|
+
VALUES ($1, $2, $3, $4, $5, CURRENT_TIMESTAMP)
|
|
53
|
+
ON CONFLICT (namespace, name) DO UPDATE SET
|
|
54
|
+
kind = EXCLUDED.kind,
|
|
55
|
+
source_hash = EXCLUDED.source_hash,
|
|
56
|
+
value = EXCLUDED.value,
|
|
57
|
+
updated_at = CURRENT_TIMESTAMP`, [
|
|
58
|
+
namespace,
|
|
59
|
+
resource.name,
|
|
60
|
+
envelope.kind,
|
|
61
|
+
envelope.sourceHash ?? null,
|
|
62
|
+
JSON.stringify(envelope.value),
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
name: storeName,
|
|
67
|
+
capabilities: postgresStoreCapabilities,
|
|
68
|
+
async hydrate(resources) {
|
|
69
|
+
await ensureMigrated();
|
|
70
|
+
for (const resource of resources) {
|
|
71
|
+
await hydrateJsonResourceStore({
|
|
72
|
+
config,
|
|
73
|
+
resource,
|
|
74
|
+
readEnvelope,
|
|
75
|
+
writeEnvelope,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
async readResource(resource, fallback) {
|
|
80
|
+
const envelope = await readEnvelope(resource);
|
|
81
|
+
return envelope ? envelope.value : fallback;
|
|
82
|
+
},
|
|
83
|
+
async writeResource(resource, value) {
|
|
84
|
+
await writeEnvelope(resource, {
|
|
85
|
+
kind: resource.kind,
|
|
86
|
+
sourceHash: resource.dataHash ?? null,
|
|
87
|
+
value,
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
withResourceWrite(resource, operation) {
|
|
91
|
+
return withQueuedWrite(`${namespace}:${resource.name}`, operation);
|
|
92
|
+
},
|
|
93
|
+
close() {
|
|
94
|
+
return closeInjectedClient(client, close);
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function assertPostgresClient(client, storeName) {
|
|
100
|
+
if (client && typeof client.query === 'function') {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
throw dbError('POSTGRES_STORE_CLIENT_REQUIRED', `Postgres store "${storeName}" requires an injected client with query(sql, params).`, {
|
|
104
|
+
status: 500,
|
|
105
|
+
hint: 'Pass a pg Pool, pg Client, or compatible object to postgresStore({ client }).',
|
|
106
|
+
details: {
|
|
107
|
+
store: storeName,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function quoteIdentifier(value) {
|
|
112
|
+
return `"${String(value).replaceAll('"', '""')}"`;
|
|
113
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { SchemaField } from '../features/schema/fields.js';
|
|
2
|
+
type SqliteValue = string | number | bigint | Buffer | null;
|
|
3
|
+
type SqliteRow = Record<string, SqliteValue>;
|
|
4
|
+
type SqliteRunResult = {
|
|
5
|
+
changes: number;
|
|
6
|
+
lastInsertRowid?: number | bigint;
|
|
7
|
+
};
|
|
8
|
+
type SqliteStatement = {
|
|
9
|
+
get(...values: unknown[]): SqliteRow | undefined;
|
|
10
|
+
all(...values: unknown[]): SqliteRow[];
|
|
11
|
+
run(...values: unknown[]): SqliteRunResult;
|
|
12
|
+
};
|
|
13
|
+
type SqliteDatabase = {
|
|
14
|
+
exec(sql: string): void;
|
|
15
|
+
prepare(sql: string): SqliteStatement;
|
|
16
|
+
close(): void;
|
|
17
|
+
};
|
|
18
|
+
type SqliteConfig = {
|
|
19
|
+
cwd: string;
|
|
20
|
+
stateDir: string;
|
|
21
|
+
defaults?: {
|
|
22
|
+
applyOnCreate?: boolean;
|
|
23
|
+
applyOnSafeMigration?: boolean;
|
|
24
|
+
};
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
type SqliteResource = {
|
|
28
|
+
name: string;
|
|
29
|
+
kind: 'collection' | 'document' | string;
|
|
30
|
+
idField?: string;
|
|
31
|
+
fields: Record<string, SchemaField>;
|
|
32
|
+
dataHash?: string | null;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
type SqliteProject = {
|
|
36
|
+
resources: SqliteResource[];
|
|
37
|
+
};
|
|
38
|
+
type OpenSqliteOptions = Record<string, unknown> & {
|
|
39
|
+
project?: SqliteProject;
|
|
40
|
+
storage?: {
|
|
41
|
+
file?: string;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
};
|
|
44
|
+
file?: string;
|
|
45
|
+
};
|
|
46
|
+
type SqliteStoreOptions = {
|
|
47
|
+
file?: string;
|
|
48
|
+
};
|
|
49
|
+
type StoreContext = {
|
|
50
|
+
config: SqliteConfig;
|
|
51
|
+
storeName: string;
|
|
52
|
+
};
|
|
53
|
+
type StoreAdapter = {
|
|
54
|
+
name: string;
|
|
55
|
+
capabilities: typeof sqliteStoreCapabilities;
|
|
56
|
+
statePath(): string | undefined;
|
|
57
|
+
hydrate(resources: SqliteResource[]): Promise<void>;
|
|
58
|
+
readResource(resource: SqliteResource, fallback: unknown): unknown;
|
|
59
|
+
writeResource(resource: SqliteResource, value: unknown): void;
|
|
60
|
+
withResourceWrite<T>(resource: SqliteResource, operation: () => T | Promise<T>): Promise<T>;
|
|
61
|
+
close(): void;
|
|
62
|
+
};
|
|
63
|
+
type ResourceKind = 'collection' | 'document';
|
|
64
|
+
export declare function openSqliteDb(options?: OpenSqliteOptions): Promise<SqliteDb>;
|
|
65
|
+
export declare function sqliteStore(options?: SqliteStoreOptions): (context: StoreContext) => StoreAdapter;
|
|
66
|
+
export declare const sqliteStoreCapabilities: {
|
|
67
|
+
writable: boolean;
|
|
68
|
+
persistence: string;
|
|
69
|
+
atomicity: string;
|
|
70
|
+
liveEvents: boolean;
|
|
71
|
+
staticExport: boolean;
|
|
72
|
+
production: string;
|
|
73
|
+
};
|
|
74
|
+
export declare function migrateSqliteDb(database: SqliteDatabase, resources: SqliteResource[]): void;
|
|
75
|
+
export declare class SqliteDb {
|
|
76
|
+
config: SqliteConfig;
|
|
77
|
+
resources: Map<string, SqliteResource>;
|
|
78
|
+
database: SqliteDatabase;
|
|
79
|
+
constructor(config: SqliteConfig, resources: SqliteResource[], database: SqliteDatabase);
|
|
80
|
+
collection(name: string): SqliteDbCollection;
|
|
81
|
+
document(name: string): SqliteDbDocument;
|
|
82
|
+
resourceNames(): string[];
|
|
83
|
+
close(): void;
|
|
84
|
+
requireResource(name: string, kind: ResourceKind): SqliteResource;
|
|
85
|
+
}
|
|
86
|
+
export declare class SqliteDbCollection {
|
|
87
|
+
config: SqliteConfig;
|
|
88
|
+
resource: SqliteResource;
|
|
89
|
+
database: SqliteDatabase;
|
|
90
|
+
table: string;
|
|
91
|
+
constructor(config: SqliteConfig, resource: SqliteResource, database: SqliteDatabase);
|
|
92
|
+
all(): Promise<Record<string, unknown>[]>;
|
|
93
|
+
get(id: unknown): Promise<Record<string, unknown> | null>;
|
|
94
|
+
exists(id: unknown): Promise<boolean>;
|
|
95
|
+
create(record: unknown): Promise<Record<string, unknown>>;
|
|
96
|
+
update(id: unknown, patch: unknown): Promise<Record<string, unknown> | null>;
|
|
97
|
+
patch(id: unknown, patch: unknown): Promise<Record<string, unknown> | null>;
|
|
98
|
+
delete(id: unknown): Promise<boolean>;
|
|
99
|
+
nextId(): Promise<string>;
|
|
100
|
+
}
|
|
101
|
+
export declare class SqliteDbDocument {
|
|
102
|
+
config: SqliteConfig;
|
|
103
|
+
resource: SqliteResource;
|
|
104
|
+
database: SqliteDatabase;
|
|
105
|
+
constructor(config: SqliteConfig, resource: SqliteResource, database: SqliteDatabase);
|
|
106
|
+
all(): Promise<Record<string, unknown>>;
|
|
107
|
+
get(pointer?: string): Promise<unknown>;
|
|
108
|
+
put(value: unknown): Promise<Record<string, unknown>>;
|
|
109
|
+
set(pointer: string, value: unknown): Promise<unknown>;
|
|
110
|
+
update(patch: unknown): Promise<Record<string, unknown>>;
|
|
111
|
+
}
|
|
112
|
+
export {};
|