@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,111 @@
|
|
|
1
|
+
export function createResolverContext(internal = {}, provided = {}) {
|
|
2
|
+
const internalMap = normalizeContextMap(internal);
|
|
3
|
+
const services = internalMap.get('services');
|
|
4
|
+
if (services && typeof services === 'object' && !Array.isArray(services)) {
|
|
5
|
+
for (const [key, value] of Object.entries(services)) {
|
|
6
|
+
if (!internalMap.has(key)) {
|
|
7
|
+
internalMap.set(key, value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const providedMap = normalizeContextMap(provided);
|
|
12
|
+
const context = {
|
|
13
|
+
get(key) {
|
|
14
|
+
return providedMap.has(key) ? providedMap.get(key) : internalMap.get(key);
|
|
15
|
+
},
|
|
16
|
+
has(key) {
|
|
17
|
+
return providedMap.has(key) || internalMap.has(key);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(context, '_internal', {
|
|
21
|
+
enumerable: false,
|
|
22
|
+
value: createInternalView(internalMap),
|
|
23
|
+
});
|
|
24
|
+
for (const key of new Set([...internalMap.keys(), ...providedMap.keys()])) {
|
|
25
|
+
if (key in context) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
Object.defineProperty(context, key, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get() {
|
|
31
|
+
return context.get(key);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return context;
|
|
36
|
+
}
|
|
37
|
+
export async function callFieldResolver(resolver, args, options = {}) {
|
|
38
|
+
const value = options.value ?? args?.record ?? args?.records ?? args?.value;
|
|
39
|
+
const db = options.db;
|
|
40
|
+
const config = options.config;
|
|
41
|
+
const resolverThis = createResolverContext({
|
|
42
|
+
db: options.db,
|
|
43
|
+
config: options.config ?? db?.config,
|
|
44
|
+
resource: options.resource,
|
|
45
|
+
field: options.resource?.fields?.[options.fieldName],
|
|
46
|
+
fieldName: options.fieldName,
|
|
47
|
+
cache: options.cache,
|
|
48
|
+
services: options.services ?? config?.services ?? db?.config?.services ?? {},
|
|
49
|
+
value,
|
|
50
|
+
record: args?.record ?? value,
|
|
51
|
+
records: args?.records,
|
|
52
|
+
args,
|
|
53
|
+
}, options.context);
|
|
54
|
+
return resolver.call(resolverThis, args);
|
|
55
|
+
}
|
|
56
|
+
export function valueFromResolveManyResult(values, resource, record, index = 0) {
|
|
57
|
+
if (Array.isArray(values)) {
|
|
58
|
+
return values[index];
|
|
59
|
+
}
|
|
60
|
+
if (values instanceof Map) {
|
|
61
|
+
const key = keyForRecord(record, resource, index);
|
|
62
|
+
return values.get(key) ?? values.get(String(key)) ?? values.get(index);
|
|
63
|
+
}
|
|
64
|
+
if (values && typeof values === 'object') {
|
|
65
|
+
const key = keyForRecord(record, resource, index);
|
|
66
|
+
const recordValues = values;
|
|
67
|
+
return recordValues[key] ?? recordValues[String(key)] ?? recordValues[index];
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
function createInternalView(internalMap) {
|
|
72
|
+
const view = {
|
|
73
|
+
get(key) {
|
|
74
|
+
return internalMap.get(key);
|
|
75
|
+
},
|
|
76
|
+
has(key) {
|
|
77
|
+
return internalMap.has(key);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
for (const key of internalMap.keys()) {
|
|
81
|
+
if (key in view) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
Object.defineProperty(view, key, {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get() {
|
|
87
|
+
return internalMap.get(key);
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return Object.freeze(view);
|
|
92
|
+
}
|
|
93
|
+
function normalizeContextMap(value) {
|
|
94
|
+
if (value instanceof Map) {
|
|
95
|
+
return new Map(value);
|
|
96
|
+
}
|
|
97
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
98
|
+
return new Map();
|
|
99
|
+
}
|
|
100
|
+
return new Map(Object.entries(value));
|
|
101
|
+
}
|
|
102
|
+
function keyForRecord(record, resource, index) {
|
|
103
|
+
if (resource?.kind === 'collection') {
|
|
104
|
+
const idField = resource.idField ?? 'id';
|
|
105
|
+
const id = record?.[idField];
|
|
106
|
+
if (id !== undefined && id !== null && id !== '') {
|
|
107
|
+
return id;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return index;
|
|
111
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type SchemaField } from './fields.js';
|
|
2
|
+
import { relationsForResource } from './relations.js';
|
|
3
|
+
import { normalizeFilesSource, type FilesSourceDefinition } from './source-definitions.js';
|
|
4
|
+
import { type SchemaDiagnostic } from './standard-schema.js';
|
|
5
|
+
type ResourceKind = 'collection' | 'document';
|
|
6
|
+
type ResourceConfig = {
|
|
7
|
+
idField?: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
type SchemaBuildConfig = {
|
|
11
|
+
collections?: Record<string, ResourceConfig>;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
type RawSchema = {
|
|
15
|
+
kind?: ResourceKind;
|
|
16
|
+
idField?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
seed?: unknown;
|
|
19
|
+
fields?: Record<string, unknown>;
|
|
20
|
+
validator?: unknown;
|
|
21
|
+
standardSchema?: unknown;
|
|
22
|
+
source?: Parameters<typeof normalizeFilesSource>[0];
|
|
23
|
+
parser?: string;
|
|
24
|
+
store?: unknown;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
type BuildResourceInput = {
|
|
28
|
+
name: string;
|
|
29
|
+
dataPath?: string | null;
|
|
30
|
+
dataFormat?: string | null;
|
|
31
|
+
dataHash?: string | null;
|
|
32
|
+
schemaPath?: string | null;
|
|
33
|
+
schemaSource?: string | null;
|
|
34
|
+
rawData?: unknown;
|
|
35
|
+
rawSchema?: RawSchema | null;
|
|
36
|
+
config: SchemaBuildConfig;
|
|
37
|
+
includeSeed?: boolean;
|
|
38
|
+
};
|
|
39
|
+
type FieldResolver = (...args: unknown[]) => unknown;
|
|
40
|
+
type RawResolverField = {
|
|
41
|
+
resolve?: FieldResolver;
|
|
42
|
+
resolveMany?: FieldResolver;
|
|
43
|
+
};
|
|
44
|
+
type ResourceResolvers = {
|
|
45
|
+
fields: Record<string, RawResolverField>;
|
|
46
|
+
};
|
|
47
|
+
type BuiltResource = {
|
|
48
|
+
name: string;
|
|
49
|
+
kind: ResourceKind;
|
|
50
|
+
idField: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
fields: Record<string, SchemaField>;
|
|
53
|
+
seed: unknown;
|
|
54
|
+
dataPath?: string | null;
|
|
55
|
+
dataFormat?: string | null;
|
|
56
|
+
dataHash?: string | null;
|
|
57
|
+
schemaPath?: string | null;
|
|
58
|
+
schemaSource: string | null;
|
|
59
|
+
schemaHasSeed?: boolean;
|
|
60
|
+
schemaSeed?: unknown;
|
|
61
|
+
typeSource: 'schema' | 'data';
|
|
62
|
+
generatedIds: boolean;
|
|
63
|
+
resolvers: ResourceResolvers;
|
|
64
|
+
validators: Record<string, unknown>;
|
|
65
|
+
validatorSource?: string;
|
|
66
|
+
fieldsAuthoritative: boolean;
|
|
67
|
+
typeFallback?: string;
|
|
68
|
+
diagnostics?: SchemaDiagnostic[];
|
|
69
|
+
source?: FilesSourceDefinition | null;
|
|
70
|
+
typeName?: string;
|
|
71
|
+
routePath?: string;
|
|
72
|
+
relations?: ReturnType<typeof relationsForResource>;
|
|
73
|
+
};
|
|
74
|
+
export declare function buildResource({ name, dataPath, dataFormat, dataHash, schemaPath, schemaSource, rawData, rawSchema, config, includeSeed, }: BuildResourceInput): BuiltResource;
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { resourceConfigValue, routePathForResource, typeNameForResource } from '../../names.js';
|
|
2
|
+
import { inferFieldsFromData, normalizeField } from './fields.js';
|
|
3
|
+
import { relationsForResource } from './relations.js';
|
|
4
|
+
import { normalizeFilesSource } from './source-definitions.js';
|
|
5
|
+
import { mergeStandardSchemaFields, standardJsonSchemaFields } from './standard-schema.js';
|
|
6
|
+
export function buildResource({ name, dataPath, dataFormat, dataHash, schemaPath, schemaSource, rawData, rawSchema, config, includeSeed = true, }) {
|
|
7
|
+
const collectionConfig = resourceConfigValue(config.collections, name) ?? {};
|
|
8
|
+
if (rawSchema) {
|
|
9
|
+
const kind = rawSchema.kind ?? inferKindFromData(rawData) ?? 'collection';
|
|
10
|
+
const idField = rawSchema.idField ?? collectionConfig.idField ?? 'id';
|
|
11
|
+
const schemaHasSeed = Object.prototype.hasOwnProperty.call(rawSchema, 'seed');
|
|
12
|
+
const schemaSeed = includeSeed && schemaHasSeed ? rawSchema.seed : emptySeedForKind(kind);
|
|
13
|
+
const seed = includeSeed && rawData !== undefined ? rawData : schemaSeed;
|
|
14
|
+
const standardSchema = rawSchema.validator ?? rawSchema.standardSchema;
|
|
15
|
+
const standardSchemaSource = rawSchema.validator ? 'validator' : rawSchema.standardSchema ? 'standardSchema' : undefined;
|
|
16
|
+
const standardFields = standardSchema
|
|
17
|
+
? standardJsonSchemaFields(standardSchema, name)
|
|
18
|
+
: { fields: {}, authoritative: true, diagnostics: [] };
|
|
19
|
+
const rawFields = standardSchema
|
|
20
|
+
? mergeStandardSchemaFields(standardFields.fields, rawSchema.fields ?? {})
|
|
21
|
+
: rawSchema.fields ?? {};
|
|
22
|
+
const standardDiagnostics = standardSchema && Object.keys(rawFields).length === 0
|
|
23
|
+
? standardFields.diagnostics
|
|
24
|
+
: [];
|
|
25
|
+
const resolvers = resolversForFieldMap(rawFields);
|
|
26
|
+
let fields = Object.fromEntries(Object.entries(rawFields).map(([fieldName, field]) => [fieldName, normalizeField(field, fieldName)]));
|
|
27
|
+
if (kind === 'collection') {
|
|
28
|
+
fields = ensureCollectionIdField(fields, idField);
|
|
29
|
+
}
|
|
30
|
+
const normalizedSeed = normalizeSeed(dataFormat === 'csv' ? coerceCsvSeedToSchema(seed, fields, kind) : seed, kind);
|
|
31
|
+
const idResult = ensureCollectionSeedIds(normalizedSeed, kind, idField);
|
|
32
|
+
const normalizedSchemaSeed = includeSeed && schemaHasSeed
|
|
33
|
+
? ensureCollectionSeedIds(normalizeSeed(schemaSeed, kind), kind, idField).seed
|
|
34
|
+
: undefined;
|
|
35
|
+
return withComputedMetadata({
|
|
36
|
+
name,
|
|
37
|
+
kind,
|
|
38
|
+
idField,
|
|
39
|
+
description: rawSchema.description,
|
|
40
|
+
fields,
|
|
41
|
+
seed: idResult.seed,
|
|
42
|
+
dataPath,
|
|
43
|
+
dataFormat,
|
|
44
|
+
dataHash,
|
|
45
|
+
schemaPath,
|
|
46
|
+
schemaSource: schemaSource ?? null,
|
|
47
|
+
schemaHasSeed,
|
|
48
|
+
schemaSeed: normalizedSchemaSeed,
|
|
49
|
+
typeSource: 'schema',
|
|
50
|
+
generatedIds: idResult.generated,
|
|
51
|
+
resolvers,
|
|
52
|
+
validators: standardSchema ? { standard: standardSchema } : {},
|
|
53
|
+
validatorSource: standardSchemaSource,
|
|
54
|
+
fieldsAuthoritative: standardSchema ? standardFields.authoritative : true,
|
|
55
|
+
typeFallback: standardSchema && Object.keys(rawFields).length === 0 ? 'record' : undefined,
|
|
56
|
+
diagnostics: standardDiagnostics,
|
|
57
|
+
source: normalizeFilesSource(rawSchema.source, { read: rawSchema.parser }),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const kind = inferKindFromData(rawData);
|
|
61
|
+
const idField = collectionConfig.idField ?? inferIdField(rawData, kind);
|
|
62
|
+
const normalizedSeed = normalizeSeed(rawData, kind);
|
|
63
|
+
const idResult = ensureCollectionSeedIds(normalizedSeed, kind, idField);
|
|
64
|
+
const fields = kind === 'collection'
|
|
65
|
+
? ensureCollectionIdField(inferFieldsFromData(idResult.seed, kind), idField)
|
|
66
|
+
: inferFieldsFromData(idResult.seed, kind);
|
|
67
|
+
return withComputedMetadata({
|
|
68
|
+
name,
|
|
69
|
+
kind,
|
|
70
|
+
idField,
|
|
71
|
+
fields,
|
|
72
|
+
seed: idResult.seed,
|
|
73
|
+
dataPath,
|
|
74
|
+
dataFormat,
|
|
75
|
+
dataHash,
|
|
76
|
+
schemaPath,
|
|
77
|
+
schemaSource: null,
|
|
78
|
+
typeSource: 'data',
|
|
79
|
+
generatedIds: idResult.generated,
|
|
80
|
+
resolvers: { fields: {} },
|
|
81
|
+
validators: {},
|
|
82
|
+
fieldsAuthoritative: true,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function resolversForFieldMap(fields) {
|
|
86
|
+
const resolvers = {};
|
|
87
|
+
for (const [fieldName, field] of Object.entries(fields ?? {})) {
|
|
88
|
+
if (!isPlainRecord(field)) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const resolver = {};
|
|
92
|
+
if (typeof field.resolve === 'function') {
|
|
93
|
+
resolver.resolve = field.resolve;
|
|
94
|
+
}
|
|
95
|
+
if (typeof field.resolveMany === 'function') {
|
|
96
|
+
resolver.resolveMany = field.resolveMany;
|
|
97
|
+
}
|
|
98
|
+
if (Object.keys(resolver).length > 0) {
|
|
99
|
+
resolvers[fieldName] = resolver;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { fields: resolvers };
|
|
103
|
+
}
|
|
104
|
+
function coerceCsvSeedToSchema(seed, fields, kind) {
|
|
105
|
+
if (kind === 'collection') {
|
|
106
|
+
return Array.isArray(seed)
|
|
107
|
+
? seed.map((record) => coerceCsvRecordToSchema(record, fields))
|
|
108
|
+
: seed;
|
|
109
|
+
}
|
|
110
|
+
return coerceCsvRecordToSchema(seed, fields);
|
|
111
|
+
}
|
|
112
|
+
function coerceCsvRecordToSchema(record, fields) {
|
|
113
|
+
if (!isPlainRecord(record)) {
|
|
114
|
+
return record;
|
|
115
|
+
}
|
|
116
|
+
const next = { ...record };
|
|
117
|
+
for (const [fieldName, field] of Object.entries(fields ?? {})) {
|
|
118
|
+
if (field.type === 'array' && typeof next[fieldName] === 'string') {
|
|
119
|
+
next[fieldName] = parseCsvArrayValue(next[fieldName], field.items ?? { type: 'unknown' });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return next;
|
|
123
|
+
}
|
|
124
|
+
function parseCsvArrayValue(value, itemField) {
|
|
125
|
+
const trimmed = value.trim();
|
|
126
|
+
if (trimmed.startsWith('[')) {
|
|
127
|
+
try {
|
|
128
|
+
const parsed = JSON.parse(trimmed);
|
|
129
|
+
if (Array.isArray(parsed)) {
|
|
130
|
+
return parsed.map((item) => coerceCsvArrayItem(item, itemField));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return trimmed
|
|
138
|
+
.split(';')
|
|
139
|
+
.map((item) => item.trim())
|
|
140
|
+
.filter((item) => item !== '')
|
|
141
|
+
.map((item) => coerceCsvArrayItem(item, itemField));
|
|
142
|
+
}
|
|
143
|
+
function coerceCsvArrayItem(value, itemField) {
|
|
144
|
+
if (typeof value !== 'string') {
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
if (itemField.type === 'number' && /^[+-]?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(value)) {
|
|
148
|
+
return Number(value);
|
|
149
|
+
}
|
|
150
|
+
if (itemField.type === 'boolean') {
|
|
151
|
+
const lower = value.toLowerCase();
|
|
152
|
+
if (lower === 'true') {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
if (lower === 'false') {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
function withComputedMetadata(resource) {
|
|
162
|
+
const next = {
|
|
163
|
+
...resource,
|
|
164
|
+
typeName: typeNameForResource(resource.name, resource.kind),
|
|
165
|
+
routePath: routePathForResource(resource.name),
|
|
166
|
+
};
|
|
167
|
+
next.relations = relationsForResource(next);
|
|
168
|
+
return next;
|
|
169
|
+
}
|
|
170
|
+
function inferKindFromData(data) {
|
|
171
|
+
return Array.isArray(data) ? 'collection' : 'document';
|
|
172
|
+
}
|
|
173
|
+
function inferIdField(data, kind) {
|
|
174
|
+
if (kind !== 'collection' || !Array.isArray(data) || data.length === 0) {
|
|
175
|
+
return 'id';
|
|
176
|
+
}
|
|
177
|
+
if (data.every((record) => isPlainRecord(record) && 'id' in record)) {
|
|
178
|
+
return 'id';
|
|
179
|
+
}
|
|
180
|
+
const firstRecord = data.find((record) => isPlainRecord(record));
|
|
181
|
+
return Object.keys(firstRecord ?? {}).find((fieldName) => /id$/i.test(fieldName)) ?? 'id';
|
|
182
|
+
}
|
|
183
|
+
function ensureCollectionIdField(fields, idField) {
|
|
184
|
+
if (idField in fields) {
|
|
185
|
+
return fields;
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
[idField]: {
|
|
189
|
+
type: 'string',
|
|
190
|
+
required: true,
|
|
191
|
+
description: 'Generated local id.',
|
|
192
|
+
},
|
|
193
|
+
...fields,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function ensureCollectionSeedIds(seed, kind, idField) {
|
|
197
|
+
if (kind !== 'collection' || !Array.isArray(seed)) {
|
|
198
|
+
return {
|
|
199
|
+
seed,
|
|
200
|
+
generated: false,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const usedIds = new Set(seed
|
|
204
|
+
.map((record) => isPlainRecord(record) ? record[idField] : undefined)
|
|
205
|
+
.filter((id) => id !== undefined && id !== null && id !== '')
|
|
206
|
+
.map((id) => String(id)));
|
|
207
|
+
let nextId = nextCounterId(usedIds);
|
|
208
|
+
let generated = false;
|
|
209
|
+
const records = seed.map((record) => {
|
|
210
|
+
if (!isPlainRecord(record) || (record[idField] !== undefined && record[idField] !== null && record[idField] !== '')) {
|
|
211
|
+
return record;
|
|
212
|
+
}
|
|
213
|
+
generated = true;
|
|
214
|
+
while (usedIds.has(String(nextId))) {
|
|
215
|
+
nextId += 1;
|
|
216
|
+
}
|
|
217
|
+
const id = String(nextId);
|
|
218
|
+
usedIds.add(id);
|
|
219
|
+
nextId += 1;
|
|
220
|
+
return {
|
|
221
|
+
[idField]: id,
|
|
222
|
+
...record,
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
seed: records,
|
|
227
|
+
generated,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function nextCounterId(usedIds) {
|
|
231
|
+
const numericIds = [...usedIds]
|
|
232
|
+
.map((id) => Number(id))
|
|
233
|
+
.filter((id) => Number.isInteger(id) && id > 0);
|
|
234
|
+
if (numericIds.length > 0) {
|
|
235
|
+
return Math.max(...numericIds) + 1;
|
|
236
|
+
}
|
|
237
|
+
return 1;
|
|
238
|
+
}
|
|
239
|
+
function normalizeSeed(seed, kind) {
|
|
240
|
+
if (kind === 'collection') {
|
|
241
|
+
return Array.isArray(seed) ? seed : [];
|
|
242
|
+
}
|
|
243
|
+
if (isPlainRecord(seed)) {
|
|
244
|
+
return seed;
|
|
245
|
+
}
|
|
246
|
+
return {};
|
|
247
|
+
}
|
|
248
|
+
function emptySeedForKind(kind) {
|
|
249
|
+
return kind === 'collection' ? [] : {};
|
|
250
|
+
}
|
|
251
|
+
function isPlainRecord(value) {
|
|
252
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
253
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type FilesSourceInput = string | readonly string[] | {
|
|
2
|
+
kind?: string;
|
|
3
|
+
patterns?: string | readonly string[];
|
|
4
|
+
pattern?: string | readonly string[];
|
|
5
|
+
glob?: string | readonly string[];
|
|
6
|
+
source?: string | readonly string[];
|
|
7
|
+
read?: string;
|
|
8
|
+
};
|
|
9
|
+
export type FilesSourceDefinition = {
|
|
10
|
+
kind: 'files';
|
|
11
|
+
patterns: string[];
|
|
12
|
+
read: string;
|
|
13
|
+
};
|
|
14
|
+
type FilesSourceOptions = {
|
|
15
|
+
read?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function normalizeFilesSource(source: FilesSourceInput | null | undefined, options?: FilesSourceOptions): FilesSourceDefinition | null;
|
|
18
|
+
export declare function isFilesSource(value: unknown): value is Extract<FilesSourceInput, {
|
|
19
|
+
kind?: string;
|
|
20
|
+
}>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function normalizeFilesSource(source, options = {}) {
|
|
2
|
+
if (!source) {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
if (isFilesSource(source)) {
|
|
6
|
+
return {
|
|
7
|
+
kind: 'files',
|
|
8
|
+
patterns: normalizePatterns(source.patterns ?? source.pattern ?? source.glob ?? source.source),
|
|
9
|
+
read: source.read ?? options.read ?? 'frontmatter',
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
kind: 'files',
|
|
14
|
+
patterns: normalizePatterns(source),
|
|
15
|
+
read: options.read ?? 'frontmatter',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function isFilesSource(value) {
|
|
19
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value) && value.kind === 'files';
|
|
20
|
+
}
|
|
21
|
+
function normalizePatterns(value) {
|
|
22
|
+
if (Array.isArray(value)) {
|
|
23
|
+
return value.map(String);
|
|
24
|
+
}
|
|
25
|
+
if (value === undefined || value === null) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
return [String(value)];
|
|
29
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { resourceNameFromPath } from '../../config-public.js';
|
|
2
|
+
type SourceKind = 'data' | 'schema';
|
|
3
|
+
type ResourceNamingStrategy = Parameters<typeof resourceNameFromPath>[1]['strategy'] | string;
|
|
4
|
+
type SchemaDiagnostic = {
|
|
5
|
+
code: string;
|
|
6
|
+
severity: 'error' | 'warn' | 'info';
|
|
7
|
+
resource?: string;
|
|
8
|
+
file?: string;
|
|
9
|
+
message: string;
|
|
10
|
+
hint?: string;
|
|
11
|
+
details?: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
type SchemaLocator = {
|
|
14
|
+
mode?: 'project' | 'root-schema' | 'schema-file' | 'source-dir' | string;
|
|
15
|
+
file?: string | null;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
type SchemaConfig = {
|
|
19
|
+
cwd?: string;
|
|
20
|
+
sourceDir?: string;
|
|
21
|
+
schema?: {
|
|
22
|
+
source?: 'data' | 'schema' | string;
|
|
23
|
+
allowJsonc?: boolean;
|
|
24
|
+
autoModulePackageJson?: boolean;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
schemaLocator?: SchemaLocator | null;
|
|
28
|
+
operations?: {
|
|
29
|
+
sourceDir?: string;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
};
|
|
32
|
+
resources?: {
|
|
33
|
+
naming?: ResourceNamingStrategy;
|
|
34
|
+
customizeResource?: (context: ResourceCustomizeContext) => unknown;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
};
|
|
37
|
+
sources?: {
|
|
38
|
+
readers?: unknown[];
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
};
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
};
|
|
43
|
+
type SourceFileListConfig = {
|
|
44
|
+
sourceDir?: string;
|
|
45
|
+
operations?: SchemaConfig['operations'];
|
|
46
|
+
};
|
|
47
|
+
type SourceRecord = {
|
|
48
|
+
kind: SourceKind;
|
|
49
|
+
name: string;
|
|
50
|
+
file: string;
|
|
51
|
+
sourceFile: string;
|
|
52
|
+
format: string;
|
|
53
|
+
hash?: string;
|
|
54
|
+
data?: unknown;
|
|
55
|
+
schema?: unknown;
|
|
56
|
+
baseDir?: string;
|
|
57
|
+
};
|
|
58
|
+
type SourceReadResult = {
|
|
59
|
+
sources: SourceRecord[];
|
|
60
|
+
diagnostics: SchemaDiagnostic[];
|
|
61
|
+
};
|
|
62
|
+
type RootSchemaReadResult = SourceReadResult & {
|
|
63
|
+
found: boolean;
|
|
64
|
+
file?: string | null;
|
|
65
|
+
};
|
|
66
|
+
type ResourceCustomizeContext = {
|
|
67
|
+
file: string;
|
|
68
|
+
sourceFile: string;
|
|
69
|
+
basename: string;
|
|
70
|
+
folder: string | null;
|
|
71
|
+
folders: string[];
|
|
72
|
+
extension: string;
|
|
73
|
+
defaultName: string;
|
|
74
|
+
defaultResource: {
|
|
75
|
+
name: string;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export declare function listSourceFiles(sourceDirOrConfig: string | SourceFileListConfig): Promise<string[]>;
|
|
79
|
+
export declare function readRootSchemaFile(config: SchemaConfig): Promise<RootSchemaReadResult>;
|
|
80
|
+
export declare function readSourceFile(config: SchemaConfig, filename: string): Promise<SourceReadResult>;
|
|
81
|
+
export declare function trackResourceSource(resourceSources: Map<string, unknown>, name: string, filename: string, kind: SourceKind): void;
|
|
82
|
+
export declare function duplicateResourceDiagnostics(resourceSources: Map<string, unknown>): SchemaDiagnostic[];
|
|
83
|
+
export {};
|