bazis 0.96.1
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/LICENSE +21 -0
- package/README.md +146 -0
- package/cli/build.ts +147 -0
- package/cli/codegen.ts +40 -0
- package/cli/generateModule.ts +187 -0
- package/cli/generateProject.ts +183 -0
- package/cli/main.ts +125 -0
- package/cli/moduleRegistration.ts +127 -0
- package/cli/naming.ts +124 -0
- package/cli/parseCli.ts +151 -0
- package/cli/templates/module.ts +497 -0
- package/cli/templates/pack.ts +76 -0
- package/cli/templates/passport.ts +178 -0
- package/core/agent/AgentContextBuilder.ts +567 -0
- package/core/agent/AgentDataDefinition.ts +8 -0
- package/core/agent/AgentRegistry.ts +539 -0
- package/core/agent/AgentRuntime.ts +47 -0
- package/core/agent/AgentToolExecutor.ts +2130 -0
- package/core/agent/AgentToolHooks.ts +39 -0
- package/core/agent/ModelProvider.ts +21 -0
- package/core/agent/README.md +229 -0
- package/core/agent/Tool.contract.ts +20 -0
- package/core/agent/decorators/Agent.ts +11 -0
- package/core/agent/decorators/Prompt.ts +11 -0
- package/core/agent/decorators/Task.ts +29 -0
- package/core/agent/decorators/Tool.ts +12 -0
- package/core/agent/errors.ts +43 -0
- package/core/agent/generated/catalog.ts +26 -0
- package/core/agent/index.ts +170 -0
- package/core/agent/internal/AgentExecutionDriver.ts +1497 -0
- package/core/agent/internal/AgentExecutionState.ts +775 -0
- package/core/agent/internal/AgentJsonSchema.ts +150 -0
- package/core/agent/internal/AgentModelBinding.ts +57 -0
- package/core/agent/internal/Schema.contract.ts +36 -0
- package/core/agent/internal/ToolAudit.projector.ts +163 -0
- package/core/agent/internal/ToolContract.validator.ts +102 -0
- package/core/agent/metadata.ts +398 -0
- package/core/agent/moduleContributions-v1.ts +113 -0
- package/core/agent/semantic.ts +903 -0
- package/core/agent/session/codec.ts +33 -0
- package/core/agent/session/contracts.ts +96 -0
- package/core/agent/session/entities.ts +84 -0
- package/core/agent/session/protector.ts +92 -0
- package/core/app/index.ts +5 -0
- package/core/app/runApp.ts +293 -0
- package/core/app/ui/index.ts +29 -0
- package/core/app/ui/uiProfileResolver.ts +966 -0
- package/core/app/ui/uiSurfaceHosting.ts +38 -0
- package/core/app/ui/uiSurfaceHttp.ts +476 -0
- package/core/background/BackgroundService.ts +223 -0
- package/core/background/backgroundModule.ts +42 -0
- package/core/background/decorator.ts +43 -0
- package/core/background/delay.ts +27 -0
- package/core/background/index.ts +15 -0
- package/core/cache/COMPATIBILITY.md +13 -0
- package/core/cache/ICache.ts +71 -0
- package/core/cache/MemoryCache.ts +394 -0
- package/core/cache/README.md +83 -0
- package/core/cache/SPEC.md +1355 -0
- package/core/cache/cacheModule.ts +21 -0
- package/core/cache/decorators/Cacheable.ts +38 -0
- package/core/cache/decorators/CacheableRedis.ts +39 -0
- package/core/cache/decorators/OutputCache.ts +33 -0
- package/core/cache/decorators/OutputRedisCache.ts +33 -0
- package/core/cache/decorators/cacheableMetadata.ts +78 -0
- package/core/cache/decorators/cacheableRedisMetadata.ts +81 -0
- package/core/cache/decorators/outputCacheMetadata.ts +71 -0
- package/core/cache/decorators/outputRedisCacheMetadata.ts +77 -0
- package/core/cache/di/classProviderHook.ts +26 -0
- package/core/cache/distributed/CacheCodec.ts +5 -0
- package/core/cache/distributed/DistributedCache.ts +403 -0
- package/core/cache/distributed/DistributedCacheDriver.ts +83 -0
- package/core/cache/distributed/DistributedCacheStores.ts +28 -0
- package/core/cache/distributed/IDistributedCache.ts +40 -0
- package/core/cache/distributed/NamedCacheRegistry.ts +23 -0
- package/core/cache/distributed/codecs.ts +32 -0
- package/core/cache/distributed/index.ts +19 -0
- package/core/cache/errors/CacheError.ts +16 -0
- package/core/cache/http/CachedHttpPayload.ts +213 -0
- package/core/cache/http/applyClientCacheHeaders.ts +61 -0
- package/core/cache/http/buildOutputCacheKey.ts +154 -0
- package/core/cache/http/buildRedisOutputCacheKey.ts +16 -0
- package/core/cache/http/composeOutputCache.ts +130 -0
- package/core/cache/http/outputCacheMiddleware.ts +111 -0
- package/core/cache/http/outputCacheSecurityWarning.ts +58 -0
- package/core/cache/http/outputRedisCacheMiddleware.ts +118 -0
- package/core/cache/index.ts +97 -0
- package/core/cache/internal/AutomaticCacheKey.ts +106 -0
- package/core/cache/internal/CacheKeyGuard.ts +56 -0
- package/core/cache/internal/buildCacheProviders.ts +146 -0
- package/core/cache/internal/normalizeCacheKey.ts +9 -0
- package/core/cache/internal/resolveCachePolicy.ts +32 -0
- package/core/cache/internal/resolveCacheableRedisPolicy.ts +17 -0
- package/core/cache/internal/resolveOutputRedisCachePolicy.ts +17 -0
- package/core/cache/providers/cachedProviders.ts +68 -0
- package/core/cache/services/cacheProxy.ts +243 -0
- package/core/cache/tokens/CACHE_POLICIES.ts +5 -0
- package/core/cache/tokens/DISTRIBUTED_CACHE.ts +30 -0
- package/core/cache/types/CacheEntry.ts +7 -0
- package/core/cache/types/CacheOptions.ts +60 -0
- package/core/cache/types/CachePolicy.ts +74 -0
- package/core/cache/types/CacheableRedisOptions.ts +23 -0
- package/core/cache/types/OutputRedisCacheOptions.ts +25 -0
- package/core/di/README.md +104 -0
- package/core/di/ServiceCollection.ts +185 -0
- package/core/di/ServiceProvider.ts +689 -0
- package/core/di/ServiceScope.ts +61 -0
- package/core/di/container.ts +38 -0
- package/core/di/errors/AmbiguousNamedDependencyError.ts +10 -0
- package/core/di/errors/AsyncResolutionRequiredError.ts +12 -0
- package/core/di/errors/CircularDependencyError.ts +10 -0
- package/core/di/errors/ClassDependenciesMismatchError.ts +15 -0
- package/core/di/errors/DiError.ts +6 -0
- package/core/di/errors/InvalidProviderError.ts +9 -0
- package/core/di/errors/ModuleEncapsulationError.ts +7 -0
- package/core/di/errors/ModuleOwnedProviderConflictError.ts +8 -0
- package/core/di/errors/NamedDependencyNotFoundError.ts +7 -0
- package/core/di/errors/OptionsValidationError.ts +7 -0
- package/core/di/errors/ProviderNotFoundError.ts +10 -0
- package/core/di/errors/ScopeDisposedError.ts +7 -0
- package/core/di/errors/ScopedServiceFromRootError.ts +9 -0
- package/core/di/errors/ServiceValidationError.ts +7 -0
- package/core/di/errors/index.ts +14 -0
- package/core/di/extensions/activator.ts +39 -0
- package/core/di/extensions/application.ts +117 -0
- package/core/di/extensions/hosted-service.ts +124 -0
- package/core/di/extensions/index.ts +23 -0
- package/core/di/extensions/options-reloadable.ts +137 -0
- package/core/di/extensions/options.ts +91 -0
- package/core/di/extensions/service-provider-token.ts +21 -0
- package/core/di/index.ts +97 -0
- package/core/di/internal/GraphValidator.ts +119 -0
- package/core/di/internal/HostedServicePlan.ts +158 -0
- package/core/di/internal/NamedTokenIndex.ts +55 -0
- package/core/di/internal/OpenGenericRegistration.ts +14 -0
- package/core/di/internal/ResolutionPlan.ts +18 -0
- package/core/di/internal/ResolutionScopeState.ts +19 -0
- package/core/di/internal/ResolutionTracker.ts +153 -0
- package/core/di/internal/ScopeLifecycle.ts +159 -0
- package/core/di/internal/ServiceRegistration.ts +14 -0
- package/core/di/internal/ServiceRegistry.ts +252 -0
- package/core/di/internal/classDeps.ts +38 -0
- package/core/di/internal/disposal.ts +58 -0
- package/core/di/internal/providerDeps.ts +26 -0
- package/core/di/module/DI.ts +146 -0
- package/core/di/module/Global.ts +25 -0
- package/core/di/module/Module.ts +44 -0
- package/core/di/module/ModuleRegistrar.ts +69 -0
- package/core/di/module/autoDeps.ts +39 -0
- package/core/di/module/classProviderHooks.ts +66 -0
- package/core/di/module/collectModuleConfigs.ts +57 -0
- package/core/di/module/collectModuleControllers.ts +53 -0
- package/core/di/module/collectModuleUiProfiles.ts +53 -0
- package/core/di/module/createContainer.ts +261 -0
- package/core/di/module/encapsulation.ts +416 -0
- package/core/di/module/encapsulationHooks.ts +36 -0
- package/core/di/module/generatedProviderAttachments.ts +102 -0
- package/core/di/module/index.ts +41 -0
- package/core/di/module/moduleExtensions.ts +35 -0
- package/core/di/module/moduleNameBinding.ts +136 -0
- package/core/di/module/moduleOwnedProviderContributors.ts +409 -0
- package/core/di/module/providerSelection.ts +90 -0
- package/core/di/module/shortcuts.ts +111 -0
- package/core/di/module/types/BazisModule.ts +71 -0
- package/core/di/module/types/DiRegistrar.ts +24 -0
- package/core/di/module/types/index.ts +2 -0
- package/core/di/provider/index.ts +26 -0
- package/core/di/provider/providerGuards.ts +17 -0
- package/core/di/provider/types/AsyncFactoryProvider.ts +15 -0
- package/core/di/provider/types/ClassProvider.ts +18 -0
- package/core/di/provider/types/FactoryProvider.ts +20 -0
- package/core/di/provider/types/KeyedDependency.ts +20 -0
- package/core/di/provider/types/LazyDependency.ts +31 -0
- package/core/di/provider/types/NamedDependency.ts +16 -0
- package/core/di/provider/types/Provider.ts +10 -0
- package/core/di/provider/types/ProviderDefinition.ts +11 -0
- package/core/di/provider/types/ProviderDependencyList.ts +11 -0
- package/core/di/provider/types/ProviderLifetime.ts +1 -0
- package/core/di/provider/types/ProviderOwnership.ts +7 -0
- package/core/di/provider/types/ResolvedDeps.ts +18 -0
- package/core/di/provider/types/ValueProvider.ts +6 -0
- package/core/di/provider/types/index.ts +13 -0
- package/core/di/token.ts +84 -0
- package/core/di/types/BuildServiceProviderOptions.ts +4 -0
- package/core/di/types/ServiceKey.ts +1 -0
- package/core/di/types/ServiceResolver.ts +16 -0
- package/core/di/types/index.ts +3 -0
- package/core/generatedFingerprint.ts +60 -0
- package/core/generatedRuntime.ts +187 -0
- package/core/grpc/Grpc.module.ts +23 -0
- package/core/grpc/GrpcBinding.contract.ts +35 -0
- package/core/grpc/GrpcCall.ts +73 -0
- package/core/grpc/GrpcClient.ts +172 -0
- package/core/grpc/GrpcClientCall.ts +267 -0
- package/core/grpc/GrpcError.ts +19 -0
- package/core/grpc/GrpcRequest.binding.ts +45 -0
- package/core/grpc/GrpcServer.ts +204 -0
- package/core/grpc/GrpcStatus.ts +8 -0
- package/core/grpc/GrpcTransport.ts +174 -0
- package/core/grpc/Metadata.ts +73 -0
- package/core/grpc/ProtoCodec.ts +225 -0
- package/core/grpc/ProtoParser.ts +192 -0
- package/core/grpc/ProtoReader.ts +34 -0
- package/core/grpc/ProtoSchema.ts +52 -0
- package/core/grpc/ServerCredentials.ts +30 -0
- package/core/grpc/clientContracts.ts +39 -0
- package/core/grpc/contracts.ts +45 -0
- package/core/grpc/decorators.ts +82 -0
- package/core/grpc/grpcClientProvider.ts +9 -0
- package/core/grpc/index.ts +17 -0
- package/core/grpc/moduleControllers.ts +38 -0
- package/core/grpc/protobuf.ts +80 -0
- package/core/grpc/serviceDefinition.ts +20 -0
- package/core/http/Authorization/Authorize.ts +52 -0
- package/core/http/Authorization/authorizeComposer.ts +31 -0
- package/core/http/Authorization/metadata.ts +158 -0
- package/core/http/Binding/ParameterBinder.ts +109 -0
- package/core/http/Binding/RequestModel.ts +27 -0
- package/core/http/Binding/autoBindings.ts +125 -0
- package/core/http/Binding/bindings.ts +19 -0
- package/core/http/Binding/convert.ts +48 -0
- package/core/http/Binding/generatedSpec.ts +18 -0
- package/core/http/Binding/listModelRegistry.ts +47 -0
- package/core/http/Binding/modelBinder.ts +345 -0
- package/core/http/Binding/modelValidator.ts +30 -0
- package/core/http/Binding/requestModelRegistry.ts +117 -0
- package/core/http/Decorators/attributes.ts +92 -0
- package/core/http/Decorators/controller.ts +24 -0
- package/core/http/Decorators/metadata.ts +107 -0
- package/core/http/Decorators/routes.ts +131 -0
- package/core/http/Errors/HttpError.ts +92 -0
- package/core/http/HttpContext/HttpContext.ts +148 -0
- package/core/http/HttpContext/ResponseBuilder.ts +37 -0
- package/core/http/HttpContext/inspectableRedirects.ts +47 -0
- package/core/http/HttpContext/principal.ts +24 -0
- package/core/http/HttpContext/responseLifetime.ts +45 -0
- package/core/http/HttpServer.ts +627 -0
- package/core/http/Middleware/accessLog.ts +90 -0
- package/core/http/Middleware/cors.ts +160 -0
- package/core/http/Middleware/errorHandler.ts +100 -0
- package/core/http/Middleware/pipeline.ts +21 -0
- package/core/http/Middleware/rateLimit.ts +104 -0
- package/core/http/Middleware/securityHeaders.ts +118 -0
- package/core/http/Middleware/types.ts +19 -0
- package/core/http/OpenApi/generatedOpenApiRegistry.ts +102 -0
- package/core/http/OpenApi/openApiDocs.ts +75 -0
- package/core/http/OpenApi/openApiDocument.ts +356 -0
- package/core/http/README.md +139 -0
- package/core/http/Results/HttpResult.ts +19 -0
- package/core/http/Results/normalize.ts +93 -0
- package/core/http/Results/results.ts +70 -0
- package/core/http/Routing/Router.ts +201 -0
- package/core/http/Routing/RouterBuilder.ts +184 -0
- package/core/http/Routing/template.ts +112 -0
- package/core/http/SPEC.md +981 -0
- package/core/http/Versioning/VersionReader.ts +20 -0
- package/core/http/WebSocketUpgrade.ts +29 -0
- package/core/http/composeRouteMiddlewareComposers.ts +21 -0
- package/core/http/correlation/createCorrelationIdMiddleware.ts +79 -0
- package/core/http/httpModule.ts +48 -0
- package/core/http/index.ts +140 -0
- package/core/http/middlewareTokens.ts +48 -0
- package/core/http/options.ts +134 -0
- package/core/http-client/index.ts +105 -0
- package/core/infra/Infra.ts +158 -0
- package/core/infra/InfraConnector.ts +86 -0
- package/core/infra/InfraLifecycle.ts +86 -0
- package/core/infra/cache/RedisDistributedCacheBackend.ts +88 -0
- package/core/infra/cache/RedisDistributedCacheDriver.ts +186 -0
- package/core/infra/cache/index.ts +7 -0
- package/core/infra/connectorConfig.ts +29 -0
- package/core/infra/connectorIdentity.ts +39 -0
- package/core/infra/connectors/codex/CodexAppServer.ts +146 -0
- package/core/infra/connectors/codex/CodexAppServerClient.ts +258 -0
- package/core/infra/connectors/codex/CodexPolicy.ts +114 -0
- package/core/infra/connectors/codex/CodexTurn.ts +133 -0
- package/core/infra/connectors/codex/contracts.ts +82 -0
- package/core/infra/connectors/codex.ts +26 -0
- package/core/infra/connectors/llm.ts +78 -0
- package/core/infra/connectors/llmRouter.ts +443 -0
- package/core/infra/connectors/openaiCompatible.ts +590 -0
- package/core/infra/connectors/openaiTextStream.ts +134 -0
- package/core/infra/connectors/opensearch.ts +307 -0
- package/core/infra/connectors/postgres.ts +105 -0
- package/core/infra/connectors/redis.ts +132 -0
- package/core/infra/index.ts +58 -0
- package/core/kernel/ApplicationLifetime.ts +91 -0
- package/core/kernel/Bazis.ts +73 -0
- package/core/kernel/Environment.ts +53 -0
- package/core/kernel/Kernel.ts +391 -0
- package/core/kernel/KernelBuilder.ts +172 -0
- package/core/kernel/LifecycleCoordinator.ts +204 -0
- package/core/kernel/README.md +66 -0
- package/core/kernel/SupervisedHostedService.ts +147 -0
- package/core/kernel/config/ConfigRegistry.ts +48 -0
- package/core/kernel/config/Configuration.ts +110 -0
- package/core/kernel/config/README.md +62 -0
- package/core/kernel/config/Secret.ts +29 -0
- package/core/kernel/config/addConfigOptions.ts +63 -0
- package/core/kernel/config/defineConfig.ts +211 -0
- package/core/kernel/config/sources.ts +123 -0
- package/core/kernel/correlation/requestContext.ts +57 -0
- package/core/kernel/errors/ConfigKeyMissingError.ts +7 -0
- package/core/kernel/errors/KernelError.ts +7 -0
- package/core/kernel/errors/ShutdownTimeoutError.ts +7 -0
- package/core/kernel/errors/StartupAbortedError.ts +7 -0
- package/core/kernel/errors/StartupTimeoutError.ts +7 -0
- package/core/kernel/errors/index.ts +5 -0
- package/core/kernel/events/EventBus.ts +140 -0
- package/core/kernel/events/EventToken.ts +17 -0
- package/core/kernel/events/eventSubscribers.ts +126 -0
- package/core/kernel/events/kernelEvents.ts +16 -0
- package/core/kernel/events/onEvent.ts +32 -0
- package/core/kernel/health/HealthCheckContracts.ts +42 -0
- package/core/kernel/health/HealthService.ts +93 -0
- package/core/kernel/index.ts +96 -0
- package/core/kernel/internal/awaitAbortable.ts +18 -0
- package/core/kernel/internal/awaitShutdown.ts +21 -0
- package/core/kernel/internal/reportDiagnosticFailure.ts +8 -0
- package/core/kernel/internal/validateTimeout.ts +8 -0
- package/core/kernel/lifecycleHooks.ts +18 -0
- package/core/kernel/logging/ConsoleLogger.ts +68 -0
- package/core/kernel/logging/Logger.ts +22 -0
- package/core/kernel/types/ConfigSource.ts +9 -0
- package/core/kernel/types/EnvironmentName.ts +1 -0
- package/core/kernel/types/KernelOptions.ts +23 -0
- package/core/kernel/types/LifecycleHook.ts +18 -0
- package/core/kernel/types/index.ts +4 -0
- package/core/orm/DATABASE_PROVIDER.ts +5 -0
- package/core/orm/OrmHostedPlan.validator.ts +55 -0
- package/core/orm/OrmLifecycle.ts +146 -0
- package/core/orm/OrmOwnedStoreLifecycle.ts +96 -0
- package/core/orm/buildOrmProviders.ts +152 -0
- package/core/orm/databaseConnector.ts +108 -0
- package/core/orm/encapsulationHook.ts +19 -0
- package/core/orm/index.ts +95 -0
- package/core/orm/listQuery.ts +198 -0
- package/core/orm/ormModule.ts +173 -0
- package/core/orm/ownedStoreContributions.ts +195 -0
- package/core/orm/registerRepositories.ts +27 -0
- package/core/orm/repository.ts +45 -0
- package/core/orm/strictSchemaHostedIdentity.ts +17 -0
- package/core/scripts/agent-codegen.ts +1166 -0
- package/core/scripts/di-generate-target.ts +90 -0
- package/core/scripts/di-generate.ts +1837 -0
- package/core/scripts/orm-predicate-codegen.ts +33 -0
- package/core/scripts/request-model-codegen.ts +326 -0
- package/core/websocket/DESIGN.md +297 -0
- package/core/websocket/WsRateLimiter.ts +101 -0
- package/core/websocket/adapter/adapter.interface.ts +45 -0
- package/core/websocket/adapter/in-memory.adapter.ts +190 -0
- package/core/websocket/adapter/redis-delivery-scripts.ts +135 -0
- package/core/websocket/adapter/redis-delivery-store.ts +86 -0
- package/core/websocket/adapter/redis-operations.ts +33 -0
- package/core/websocket/adapter/redis.adapter.ts +218 -0
- package/core/websocket/codec/binary.codec.ts +87 -0
- package/core/websocket/codec/json.codec.ts +34 -0
- package/core/websocket/codec/packet-codec.interface.ts +17 -0
- package/core/websocket/decorators.ts +165 -0
- package/core/websocket/explorer.ts +126 -0
- package/core/websocket/index.ts +78 -0
- package/core/websocket/middleware.ts +146 -0
- package/core/websocket/packet-codec.ts +75 -0
- package/core/websocket/reliable-delivery.ts +56 -0
- package/core/websocket/session-creation.ts +16 -0
- package/core/websocket/session-manager.ts +856 -0
- package/core/websocket/socket-wrapper.ts +314 -0
- package/core/websocket/topic-cache.ts +59 -0
- package/core/websocket/types.ts +122 -0
- package/core/websocket/websocketModule.ts +96 -0
- package/core/websocket/ws-dispatch.ts +123 -0
- package/core/websocket/ws-server.ts +1707 -0
- package/index.ts +281 -0
- package/library/boundary/diagnostics-v1.ts +136 -0
- package/library/boundary/index.ts +73 -0
- package/library/boundary/json/decodeBoundedJsonV1.ts +518 -0
- package/library/boundary/json/limits-v1.ts +46 -0
- package/library/boundary/json/normalizeBoundedJsonV1.ts +256 -0
- package/library/boundary/json/types-v1.ts +11 -0
- package/library/boundary/schema/boundarySchemaHashV1.ts +6 -0
- package/library/boundary/schema/collectBoundaryValueDiagnosticsV1.ts +325 -0
- package/library/boundary/schema/decodeBoundarySchemaV1.ts +646 -0
- package/library/boundary/schema/index.ts +8 -0
- package/library/boundary/schema/types-v1.ts +99 -0
- package/library/boundary/schema/validateBoundaryValueV1.ts +58 -0
- package/library/boundary/serialization/canonicalJsonV1.ts +66 -0
- package/library/http-client/HttpClient.ts +969 -0
- package/library/http-client/HttpClientFactory.ts +45 -0
- package/library/http-client/errors.ts +68 -0
- package/library/http-client/index.ts +43 -0
- package/library/http-client/interceptors.ts +40 -0
- package/library/http-client/progress.ts +62 -0
- package/library/http-client/redirectProtocol.ts +6 -0
- package/library/http-client/serialize.ts +133 -0
- package/library/http-client/types.ts +174 -0
- package/library/jsonapi/ListQueryError.ts +25 -0
- package/library/jsonapi/ListRequest.ts +37 -0
- package/library/jsonapi/decorators.ts +161 -0
- package/library/jsonapi/document.ts +124 -0
- package/library/jsonapi/index.ts +40 -0
- package/library/jsonapi/parseListQuery.ts +291 -0
- package/library/jsonapi/types.ts +125 -0
- package/library/jwt/JwtEncoder.ts +40 -0
- package/library/jwt/JwtKeyRing.ts +164 -0
- package/library/jwt/JwtValidator.ts +210 -0
- package/library/jwt/TokenIssuer.ts +149 -0
- package/library/jwt/TokenService.ts +51 -0
- package/library/jwt/base64url.ts +61 -0
- package/library/jwt/claims.ts +36 -0
- package/library/jwt/errors.ts +44 -0
- package/library/jwt/index.ts +59 -0
- package/library/jwt/limits.ts +8 -0
- package/library/jwt/signing/Hs256Algorithm.ts +62 -0
- package/library/jwt/signing/Rs256Algorithm.ts +133 -0
- package/library/jwt/signing/SigningAlgorithm.ts +18 -0
- package/library/jwt/signing/pem.ts +30 -0
- package/library/openapi/codegen.ts +875 -0
- package/library/openapi/document.ts +326 -0
- package/library/openapi/index.ts +13 -0
- package/library/openapi/types.ts +69 -0
- package/library/openapi/ui.ts +182 -0
- package/library/orm/DatabaseFacade.ts +209 -0
- package/library/orm/DbContext.ts +107 -0
- package/library/orm/DbContextFactory.ts +25 -0
- package/library/orm/DbContextOptions.ts +33 -0
- package/library/orm/Metadata/DynamicModelBuilder.ts +497 -0
- package/library/orm/Metadata/KeyTuple.ts +36 -0
- package/library/orm/Metadata/ModelBuilder.ts +299 -0
- package/library/orm/Metadata/OrmModel.ts +80 -0
- package/library/orm/Metadata/ValueConverter.ts +57 -0
- package/library/orm/Metadata/conventions.ts +54 -0
- package/library/orm/Metadata/decorators.ts +396 -0
- package/library/orm/Metadata/types.ts +140 -0
- package/library/orm/Providers/OwnedStoreCatalog.reader.ts +1802 -0
- package/library/orm/Providers/PostgresDialect.ts +234 -0
- package/library/orm/Providers/PostgresProvider.ts +1494 -0
- package/library/orm/Providers/PostgresSchema.decoder.ts +107 -0
- package/library/orm/Providers/limits.ts +29 -0
- package/library/orm/Providers/operationDeadline.ts +43 -0
- package/library/orm/Providers/ormOwnedStoreRuntime.ts +19 -0
- package/library/orm/Providers/ormTransactionRuntime.ts +117 -0
- package/library/orm/Providers/propertyConversion.ts +14 -0
- package/library/orm/Providers/resolvedForeignKey.ts +16 -0
- package/library/orm/Providers/transactionCallbacks.ts +45 -0
- package/library/orm/Providers/transactionOutcome.ts +82 -0
- package/library/orm/Providers/transactionScopes.ts +78 -0
- package/library/orm/Providers/types.ts +207 -0
- package/library/orm/Query/DbSet.ts +78 -0
- package/library/orm/Query/EntityQuery.ts +247 -0
- package/library/orm/Query/ImmediateMutations.ts +226 -0
- package/library/orm/Query/IncludeLoader.ts +200 -0
- package/library/orm/Query/QueryPlan.ts +55 -0
- package/library/orm/Query/SqlTranslator.ts +195 -0
- package/library/orm/Query/conditions.ts +127 -0
- package/library/orm/Query/materialize.ts +39 -0
- package/library/orm/README.md +256 -0
- package/library/orm/Repository/README.md +684 -0
- package/library/orm/Repository/Repository.ts +68 -0
- package/library/orm/Saving/CommandBuilder.ts +139 -0
- package/library/orm/Saving/ExecutionStrategy.ts +128 -0
- package/library/orm/Saving/SaveExecutor.ts +413 -0
- package/library/orm/Saving/applyConventions.ts +64 -0
- package/library/orm/Schema/CheckExpression.ts +327 -0
- package/library/orm/Schema/ExactSchemaVerifier.ts +168 -0
- package/library/orm/Schema/ExpectedSchema.ts +43 -0
- package/library/orm/Schema/MigrationRunner.ts +146 -0
- package/library/orm/Schema/Migrator.ts +73 -0
- package/library/orm/Schema/OrmOwnedStore.ts +123 -0
- package/library/orm/Schema/OwnedStoreAdmission.ts +752 -0
- package/library/orm/Schema/OwnedStoreCanonical.ts +273 -0
- package/library/orm/Schema/OwnedStoreCatalog.ts +1325 -0
- package/library/orm/Schema/SafeAdditiveSchema.ts +100 -0
- package/library/orm/Schema/SchemaAdmission.ts +62 -0
- package/library/orm/Schema/SchemaDiffer.ts +78 -0
- package/library/orm/Schema/formatSchemaDifferences.ts +62 -0
- package/library/orm/Schema/introspection.ts +52 -0
- package/library/orm/Schema/physicalColumnTypes.ts +37 -0
- package/library/orm/Schema/tableKey.ts +26 -0
- package/library/orm/Tracking/ChangeTracker.ts +448 -0
- package/library/orm/Tracking/EntityState.ts +13 -0
- package/library/orm/Transactions/OrmTransaction.ts +30 -0
- package/library/orm/Transactions/TransactionScopeCoordinator.ts +377 -0
- package/library/orm/errors.ts +190 -0
- package/library/orm/index.ts +162 -0
- package/library/orm/runtime.ts +14 -0
- package/library/redaction/index.ts +166 -0
- package/library/ui/UiProfile.ts +77 -0
- package/library/ui/compiled-v1.ts +131 -0
- package/library/ui/compiler/compileUiSurfaceV1.ts +717 -0
- package/library/ui/compiler/contracts-v1.ts +25 -0
- package/library/ui/compiler/index.ts +12 -0
- package/library/ui/compiler/openApiIndex.ts +246 -0
- package/library/ui/defineUiProfile.ts +340 -0
- package/library/ui/diagnostics-v1.ts +33 -0
- package/library/ui/index.ts +129 -0
- package/library/ui/profile-v1.ts +191 -0
- package/library/ui/serialization.ts +130 -0
- package/library/ui/uiProfileAuthoring.ts +289 -0
- package/library/ui/uiProfileAuthoringMetadata.ts +78 -0
- package/library/validation/MessageRegistry.ts +144 -0
- package/library/validation/README.md +62 -0
- package/library/validation/RuleCompiler.ts +183 -0
- package/library/validation/RuleEngine.ts +401 -0
- package/library/validation/SPEC.md +579 -0
- package/library/validation/ValidationError.ts +37 -0
- package/library/validation/ValidationResult.ts +63 -0
- package/library/validation/Validator.ts +101 -0
- package/library/validation/index.ts +16 -0
- package/library/validation/metadata.ts +69 -0
- package/library/validation/modelValidatorAdapter.ts +119 -0
- package/library/validation/types/ValidationCode.ts +69 -0
- package/library/validation/types/ValidatorOptions.ts +153 -0
- package/package.json +80 -0
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appendJsonPointerV1,
|
|
3
|
+
finalizeBazisDiagnosticsV1,
|
|
4
|
+
BAZIS_DIAGNOSTIC_LIMIT_V1,
|
|
5
|
+
bazisDiagnosticV1,
|
|
6
|
+
type BazisDiagnosticsV1,
|
|
7
|
+
type BazisDiagnosticV1,
|
|
8
|
+
} from "../diagnostics-v1";
|
|
9
|
+
import {
|
|
10
|
+
isBoundaryJsonObject,
|
|
11
|
+
type BoundaryJsonObject,
|
|
12
|
+
type BoundaryJsonValue,
|
|
13
|
+
} from "../json/types-v1";
|
|
14
|
+
import { normalizeBoundedJsonV1 } from "../json/normalizeBoundedJsonV1";
|
|
15
|
+
import { collectBoundaryValueDiagnosticsV1 } from "./collectBoundaryValueDiagnosticsV1";
|
|
16
|
+
import {
|
|
17
|
+
BOUNDARY_SCHEMA_MAX_DEPTH_V1,
|
|
18
|
+
BOUNDARY_SCHEMA_MAX_ENUM_VALUES_V1,
|
|
19
|
+
BOUNDARY_SCHEMA_MAX_NODES_V1,
|
|
20
|
+
type BoundarySchemaTypeV1,
|
|
21
|
+
type BoundarySchemaV1,
|
|
22
|
+
type BoundaryStringFormatV1,
|
|
23
|
+
} from "./types-v1";
|
|
24
|
+
|
|
25
|
+
export interface DecodeBoundarySchemaV1Options {
|
|
26
|
+
readonly pointer?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type DecodeBoundarySchemaV1Result =
|
|
30
|
+
| ({ readonly ok: true; readonly schema: BoundarySchemaV1 } & BazisDiagnosticsV1)
|
|
31
|
+
| ({ readonly ok: false } & BazisDiagnosticsV1);
|
|
32
|
+
|
|
33
|
+
const SCHEMA_TYPES = new Set<BoundarySchemaTypeV1>([
|
|
34
|
+
"null",
|
|
35
|
+
"boolean",
|
|
36
|
+
"string",
|
|
37
|
+
"number",
|
|
38
|
+
"integer",
|
|
39
|
+
"array",
|
|
40
|
+
"object",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const STRING_FORMATS = new Set<BoundaryStringFormatV1>([
|
|
44
|
+
"date",
|
|
45
|
+
"time",
|
|
46
|
+
"date-time",
|
|
47
|
+
"uuid",
|
|
48
|
+
"email",
|
|
49
|
+
"decimal",
|
|
50
|
+
"int64-string",
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
const COMMON_PROPERTIES = [
|
|
54
|
+
"type",
|
|
55
|
+
"title",
|
|
56
|
+
"description",
|
|
57
|
+
"nullable",
|
|
58
|
+
"readOnly",
|
|
59
|
+
"writeOnly",
|
|
60
|
+
"secret",
|
|
61
|
+
"default",
|
|
62
|
+
] as const;
|
|
63
|
+
|
|
64
|
+
const TYPE_PROPERTIES: Readonly<Record<BoundarySchemaTypeV1, readonly string[]>> = Object.freeze({
|
|
65
|
+
null: Object.freeze(["enum"]),
|
|
66
|
+
boolean: Object.freeze(["enum"]),
|
|
67
|
+
string: Object.freeze(["enum", "minLength", "maxLength", "format"]),
|
|
68
|
+
number: Object.freeze(["enum", "minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum"]),
|
|
69
|
+
integer: Object.freeze(["enum", "minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum"]),
|
|
70
|
+
array: Object.freeze(["items", "minItems", "maxItems", "uniqueItems"]),
|
|
71
|
+
object: Object.freeze([
|
|
72
|
+
"properties",
|
|
73
|
+
"required",
|
|
74
|
+
"minProperties",
|
|
75
|
+
"maxProperties",
|
|
76
|
+
"additionalProperties",
|
|
77
|
+
]),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const UTF8 = new TextEncoder();
|
|
81
|
+
const MAX_TITLE_BYTES = 256;
|
|
82
|
+
const MAX_DESCRIPTION_BYTES = 8_192;
|
|
83
|
+
|
|
84
|
+
export function decodeBoundarySchemaV1(
|
|
85
|
+
input: unknown,
|
|
86
|
+
options: DecodeBoundarySchemaV1Options = {},
|
|
87
|
+
): DecodeBoundarySchemaV1Result {
|
|
88
|
+
const pointer = options.pointer ?? "";
|
|
89
|
+
const normalized = normalizeBoundedJsonV1(input);
|
|
90
|
+
if (!normalized.ok) {
|
|
91
|
+
const diagnostics = pointer === ""
|
|
92
|
+
? normalized.diagnostics
|
|
93
|
+
: Object.freeze(normalized.diagnostics.map((item) => bazisDiagnosticV1({
|
|
94
|
+
...item,
|
|
95
|
+
pointer: pointer + item.pointer,
|
|
96
|
+
})));
|
|
97
|
+
return Object.freeze({
|
|
98
|
+
ok: false,
|
|
99
|
+
diagnostics,
|
|
100
|
+
truncated: normalized.truncated,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const decoder = new BoundarySchemaDecoderV1();
|
|
105
|
+
const schema = decoder.decode(normalized.value, pointer, 1);
|
|
106
|
+
const finalized = finalizeBazisDiagnosticsV1(decoder.diagnostics);
|
|
107
|
+
if (schema === undefined || finalized.diagnostics.length > 0) {
|
|
108
|
+
return Object.freeze({ ok: false, ...finalized });
|
|
109
|
+
}
|
|
110
|
+
return Object.freeze({ ok: true, schema, ...finalized });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
class BoundarySchemaDecoderV1 {
|
|
114
|
+
readonly diagnostics: BazisDiagnosticV1[] = [];
|
|
115
|
+
private nodes = 0;
|
|
116
|
+
private nodeLimitReported = false;
|
|
117
|
+
|
|
118
|
+
decode(input: BoundaryJsonValue, pointer: string, depth: number): BoundarySchemaV1 | undefined {
|
|
119
|
+
if (depth > BOUNDARY_SCHEMA_MAX_DEPTH_V1) {
|
|
120
|
+
this.add(
|
|
121
|
+
"BSV1_SCHEMA_DEPTH_LIMIT",
|
|
122
|
+
"Boundary Schema nesting depth exceeds the v1 ceiling.",
|
|
123
|
+
pointer,
|
|
124
|
+
);
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
this.nodes += 1;
|
|
128
|
+
if (this.nodes > BOUNDARY_SCHEMA_MAX_NODES_V1) {
|
|
129
|
+
if (!this.nodeLimitReported) {
|
|
130
|
+
this.nodeLimitReported = true;
|
|
131
|
+
this.add(
|
|
132
|
+
"BSV1_SCHEMA_NODE_LIMIT",
|
|
133
|
+
"Boundary Schema node count exceeds the v1 ceiling.",
|
|
134
|
+
pointer,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
if (!isBoundaryJsonObject(input)) {
|
|
140
|
+
this.add("BSV1_SCHEMA_OBJECT", "A Boundary Schema node must be an object.", pointer);
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const rawType = input.type;
|
|
145
|
+
const typePointer = appendJsonPointerV1(pointer, "type");
|
|
146
|
+
if (typeof rawType !== "string" || !SCHEMA_TYPES.has(rawType as BoundarySchemaTypeV1)) {
|
|
147
|
+
this.add(
|
|
148
|
+
rawType === undefined ? "BSV1_SCHEMA_REQUIRED" : "BSV1_SCHEMA_TYPE",
|
|
149
|
+
rawType === undefined
|
|
150
|
+
? "Boundary Schema property 'type' is required."
|
|
151
|
+
: "Boundary Schema 'type' is not supported by v1.",
|
|
152
|
+
typePointer,
|
|
153
|
+
);
|
|
154
|
+
this.rejectUnknownProperties(input, pointer, undefined);
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const type = rawType as BoundarySchemaTypeV1;
|
|
159
|
+
const diagnosticsBefore = this.diagnostics.length;
|
|
160
|
+
this.rejectUnknownProperties(input, pointer, type);
|
|
161
|
+
const output = Object.create(null) as Record<string, unknown>;
|
|
162
|
+
output.type = type;
|
|
163
|
+
this.decodeCommon(input, output, pointer);
|
|
164
|
+
|
|
165
|
+
switch (type) {
|
|
166
|
+
case "null":
|
|
167
|
+
case "boolean":
|
|
168
|
+
case "string":
|
|
169
|
+
case "number":
|
|
170
|
+
case "integer":
|
|
171
|
+
this.decodeScalar(input, output, pointer, type);
|
|
172
|
+
break;
|
|
173
|
+
case "array":
|
|
174
|
+
this.decodeArray(input, output, pointer, depth);
|
|
175
|
+
break;
|
|
176
|
+
case "object":
|
|
177
|
+
this.decodeObject(input, output, pointer, depth);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (hasOwn(input, "default")) {
|
|
182
|
+
output.default = cloneBoundaryJsonValue(input.default!);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const schema = Object.freeze(output) as unknown as BoundarySchemaV1;
|
|
186
|
+
if (hasOwn(input, "default") && this.diagnostics.length === diagnosticsBefore) {
|
|
187
|
+
collectBoundaryValueDiagnosticsV1(
|
|
188
|
+
schema,
|
|
189
|
+
output.default as BoundaryJsonValue,
|
|
190
|
+
appendJsonPointerV1(pointer, "default"),
|
|
191
|
+
this.diagnostics,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return schema;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private decodeCommon(
|
|
198
|
+
input: BoundaryJsonObject,
|
|
199
|
+
output: Record<string, unknown>,
|
|
200
|
+
pointer: string,
|
|
201
|
+
): void {
|
|
202
|
+
const title = this.optionalString(input, "title", pointer);
|
|
203
|
+
if (title !== undefined) {
|
|
204
|
+
output.title = title;
|
|
205
|
+
if (UTF8.encode(title).byteLength > MAX_TITLE_BYTES) {
|
|
206
|
+
this.add(
|
|
207
|
+
"BSV1_SCHEMA_TITLE_LIMIT",
|
|
208
|
+
"Boundary Schema title exceeds 256 UTF-8 bytes.",
|
|
209
|
+
appendJsonPointerV1(pointer, "title"),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const description = this.optionalString(input, "description", pointer);
|
|
214
|
+
if (description !== undefined) {
|
|
215
|
+
output.description = description;
|
|
216
|
+
if (UTF8.encode(description).byteLength > MAX_DESCRIPTION_BYTES) {
|
|
217
|
+
this.add(
|
|
218
|
+
"BSV1_SCHEMA_DESCRIPTION_LIMIT",
|
|
219
|
+
"Boundary Schema description exceeds 8192 UTF-8 bytes.",
|
|
220
|
+
appendJsonPointerV1(pointer, "description"),
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (const property of ["nullable", "readOnly", "writeOnly", "secret"] as const) {
|
|
225
|
+
const value = this.optionalBoolean(input, property, pointer);
|
|
226
|
+
if (value !== undefined) output[property] = value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private decodeScalar(
|
|
231
|
+
input: BoundaryJsonObject,
|
|
232
|
+
output: Record<string, unknown>,
|
|
233
|
+
pointer: string,
|
|
234
|
+
type: "null" | "boolean" | "string" | "number" | "integer",
|
|
235
|
+
): void {
|
|
236
|
+
const enumeration = this.optionalEnum(input, pointer, type);
|
|
237
|
+
if (enumeration !== undefined) output.enum = enumeration;
|
|
238
|
+
|
|
239
|
+
if (type === "string") {
|
|
240
|
+
const minimum = this.optionalCount(input, "minLength", pointer);
|
|
241
|
+
const maximum = this.optionalCount(input, "maxLength", pointer);
|
|
242
|
+
if (minimum !== undefined) output.minLength = minimum;
|
|
243
|
+
if (maximum !== undefined) output.maxLength = maximum;
|
|
244
|
+
this.checkOrderedRange(minimum, maximum, pointer, "minLength", "maxLength");
|
|
245
|
+
|
|
246
|
+
if (hasOwn(input, "format")) {
|
|
247
|
+
const format = input.format;
|
|
248
|
+
if (typeof format !== "string" || !STRING_FORMATS.has(format as BoundaryStringFormatV1)) {
|
|
249
|
+
this.add(
|
|
250
|
+
"BSV1_SCHEMA_FORMAT",
|
|
251
|
+
"Boundary Schema string format is not supported by v1.",
|
|
252
|
+
appendJsonPointerV1(pointer, "format"),
|
|
253
|
+
);
|
|
254
|
+
} else {
|
|
255
|
+
output.format = format;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (type === "number" || type === "integer") {
|
|
262
|
+
const minimum = this.optionalNumber(input, "minimum", pointer);
|
|
263
|
+
const maximum = this.optionalNumber(input, "maximum", pointer);
|
|
264
|
+
const exclusiveMinimum = this.optionalNumber(input, "exclusiveMinimum", pointer);
|
|
265
|
+
const exclusiveMaximum = this.optionalNumber(input, "exclusiveMaximum", pointer);
|
|
266
|
+
if (minimum !== undefined) output.minimum = minimum;
|
|
267
|
+
if (maximum !== undefined) output.maximum = maximum;
|
|
268
|
+
if (exclusiveMinimum !== undefined) output.exclusiveMinimum = exclusiveMinimum;
|
|
269
|
+
if (exclusiveMaximum !== undefined) output.exclusiveMaximum = exclusiveMaximum;
|
|
270
|
+
this.checkNumericRange(minimum, maximum, exclusiveMinimum, exclusiveMaximum, pointer);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private decodeArray(
|
|
275
|
+
input: BoundaryJsonObject,
|
|
276
|
+
output: Record<string, unknown>,
|
|
277
|
+
pointer: string,
|
|
278
|
+
depth: number,
|
|
279
|
+
): void {
|
|
280
|
+
const itemsPointer = appendJsonPointerV1(pointer, "items");
|
|
281
|
+
if (!hasOwn(input, "items")) {
|
|
282
|
+
this.add("BSV1_SCHEMA_REQUIRED", "Array schema property 'items' is required.", itemsPointer);
|
|
283
|
+
} else {
|
|
284
|
+
const items = this.decode(input.items!, itemsPointer, depth + 1);
|
|
285
|
+
if (items !== undefined) output.items = items;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const minimum = this.optionalCount(input, "minItems", pointer);
|
|
289
|
+
const maximum = this.optionalCount(input, "maxItems", pointer);
|
|
290
|
+
if (minimum !== undefined) output.minItems = minimum;
|
|
291
|
+
if (maximum !== undefined) output.maxItems = maximum;
|
|
292
|
+
this.checkOrderedRange(minimum, maximum, pointer, "minItems", "maxItems");
|
|
293
|
+
|
|
294
|
+
if (hasOwn(input, "uniqueItems")) {
|
|
295
|
+
if (input.uniqueItems !== true) {
|
|
296
|
+
this.add(
|
|
297
|
+
"BSV1_SCHEMA_UNIQUE_ITEMS",
|
|
298
|
+
"Boundary Schema uniqueItems, when present, must be true.",
|
|
299
|
+
appendJsonPointerV1(pointer, "uniqueItems"),
|
|
300
|
+
);
|
|
301
|
+
} else {
|
|
302
|
+
output.uniqueItems = true;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
private decodeObject(
|
|
308
|
+
input: BoundaryJsonObject,
|
|
309
|
+
output: Record<string, unknown>,
|
|
310
|
+
pointer: string,
|
|
311
|
+
depth: number,
|
|
312
|
+
): void {
|
|
313
|
+
let declaredProperties = new Set<string>();
|
|
314
|
+
if (hasOwn(input, "properties")) {
|
|
315
|
+
const propertiesPointer = appendJsonPointerV1(pointer, "properties");
|
|
316
|
+
if (!isBoundaryJsonObject(input.properties!)) {
|
|
317
|
+
this.add("BSV1_SCHEMA_PROPERTIES", "Boundary Schema properties must be an object.", propertiesPointer);
|
|
318
|
+
} else {
|
|
319
|
+
const properties = Object.create(null) as Record<string, BoundarySchemaV1>;
|
|
320
|
+
const keys = Object.keys(input.properties!).sort(compareText);
|
|
321
|
+
declaredProperties = new Set(keys);
|
|
322
|
+
for (const key of keys) {
|
|
323
|
+
const propertySchema = this.decode(
|
|
324
|
+
input.properties![key]!,
|
|
325
|
+
appendJsonPointerV1(propertiesPointer, key),
|
|
326
|
+
depth + 1,
|
|
327
|
+
);
|
|
328
|
+
if (propertySchema !== undefined) properties[key] = propertySchema;
|
|
329
|
+
}
|
|
330
|
+
output.properties = Object.freeze(properties);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (hasOwn(input, "required")) {
|
|
335
|
+
const requiredPointer = appendJsonPointerV1(pointer, "required");
|
|
336
|
+
if (!Array.isArray(input.required)) {
|
|
337
|
+
this.add("BSV1_SCHEMA_REQUIRED_LIST", "Boundary Schema required must be an array.", requiredPointer);
|
|
338
|
+
} else {
|
|
339
|
+
const required: string[] = [];
|
|
340
|
+
const seen = new Set<string>();
|
|
341
|
+
for (let index = 0; index < input.required.length; index += 1) {
|
|
342
|
+
const entry = input.required[index];
|
|
343
|
+
const entryPointer = appendJsonPointerV1(requiredPointer, index);
|
|
344
|
+
if (typeof entry !== "string") {
|
|
345
|
+
this.add("BSV1_SCHEMA_REQUIRED_NAME", "Required property names must be strings.", entryPointer);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (seen.has(entry)) {
|
|
349
|
+
this.add("BSV1_SCHEMA_REQUIRED_DUPLICATE", "Required property names must be unique.", entryPointer);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
seen.add(entry);
|
|
353
|
+
required.push(entry);
|
|
354
|
+
if (!declaredProperties.has(entry)) {
|
|
355
|
+
this.add(
|
|
356
|
+
"BSV1_SCHEMA_REQUIRED_UNKNOWN",
|
|
357
|
+
"Required property must be declared in properties.",
|
|
358
|
+
entryPointer,
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
output.required = Object.freeze(required);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const minimum = this.optionalCount(input, "minProperties", pointer);
|
|
367
|
+
const maximum = this.optionalCount(input, "maxProperties", pointer);
|
|
368
|
+
if (minimum !== undefined) output.minProperties = minimum;
|
|
369
|
+
if (maximum !== undefined) output.maxProperties = maximum;
|
|
370
|
+
this.checkOrderedRange(minimum, maximum, pointer, "minProperties", "maxProperties");
|
|
371
|
+
|
|
372
|
+
if (hasOwn(input, "additionalProperties")) {
|
|
373
|
+
const additionalPointer = appendJsonPointerV1(pointer, "additionalProperties");
|
|
374
|
+
if (input.additionalProperties === false) {
|
|
375
|
+
output.additionalProperties = false;
|
|
376
|
+
} else if (isBoundaryJsonObject(input.additionalProperties!)) {
|
|
377
|
+
const additional = this.decode(input.additionalProperties!, additionalPointer, depth + 1);
|
|
378
|
+
if (additional !== undefined) output.additionalProperties = additional;
|
|
379
|
+
} else {
|
|
380
|
+
this.add(
|
|
381
|
+
"BSV1_SCHEMA_ADDITIONAL_PROPERTIES",
|
|
382
|
+
"Boundary Schema additionalProperties must be false or a schema object.",
|
|
383
|
+
additionalPointer,
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
private optionalEnum(
|
|
390
|
+
input: BoundaryJsonObject,
|
|
391
|
+
pointer: string,
|
|
392
|
+
type: "null" | "boolean" | "string" | "number" | "integer",
|
|
393
|
+
): readonly (null | boolean | string | number)[] | undefined {
|
|
394
|
+
if (!hasOwn(input, "enum")) return undefined;
|
|
395
|
+
const enumPointer = appendJsonPointerV1(pointer, "enum");
|
|
396
|
+
if (!Array.isArray(input.enum)) {
|
|
397
|
+
this.add("BSV1_SCHEMA_ENUM", "Boundary Schema enum must be an array.", enumPointer);
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
400
|
+
if (input.enum.length < 1 || input.enum.length > BOUNDARY_SCHEMA_MAX_ENUM_VALUES_V1) {
|
|
401
|
+
this.add(
|
|
402
|
+
"BSV1_SCHEMA_ENUM_LIMIT",
|
|
403
|
+
"Boundary Schema enum must contain between 1 and 256 values.",
|
|
404
|
+
enumPointer,
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
const output: (null | boolean | string | number)[] = [];
|
|
408
|
+
for (let index = 0; index < input.enum.length; index += 1) {
|
|
409
|
+
const value = input.enum[index]!;
|
|
410
|
+
const itemPointer = appendJsonPointerV1(enumPointer, index);
|
|
411
|
+
if (!matchesScalarType(value, type)) {
|
|
412
|
+
this.add(
|
|
413
|
+
"BSV1_SCHEMA_ENUM_TYPE",
|
|
414
|
+
"Boundary Schema enum value must have the declared scalar type.",
|
|
415
|
+
itemPointer,
|
|
416
|
+
);
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
if (output.some((existing) => Object.is(existing, value))) {
|
|
420
|
+
this.add("BSV1_SCHEMA_ENUM_DUPLICATE", "Boundary Schema enum values must be unique.", itemPointer);
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
output.push(value);
|
|
424
|
+
}
|
|
425
|
+
return Object.freeze(output);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
private optionalString(
|
|
429
|
+
input: BoundaryJsonObject,
|
|
430
|
+
property: string,
|
|
431
|
+
pointer: string,
|
|
432
|
+
): string | undefined {
|
|
433
|
+
if (!hasOwn(input, property)) return undefined;
|
|
434
|
+
const value = input[property];
|
|
435
|
+
if (typeof value !== "string") {
|
|
436
|
+
this.add(
|
|
437
|
+
"BSV1_SCHEMA_KEYWORD_TYPE",
|
|
438
|
+
`Boundary Schema '${property}' must be a string.`,
|
|
439
|
+
appendJsonPointerV1(pointer, property),
|
|
440
|
+
);
|
|
441
|
+
return undefined;
|
|
442
|
+
}
|
|
443
|
+
return value;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
private optionalBoolean(
|
|
447
|
+
input: BoundaryJsonObject,
|
|
448
|
+
property: string,
|
|
449
|
+
pointer: string,
|
|
450
|
+
): boolean | undefined {
|
|
451
|
+
if (!hasOwn(input, property)) return undefined;
|
|
452
|
+
const value = input[property];
|
|
453
|
+
if (typeof value !== "boolean") {
|
|
454
|
+
this.add(
|
|
455
|
+
"BSV1_SCHEMA_KEYWORD_TYPE",
|
|
456
|
+
`Boundary Schema '${property}' must be a boolean.`,
|
|
457
|
+
appendJsonPointerV1(pointer, property),
|
|
458
|
+
);
|
|
459
|
+
return undefined;
|
|
460
|
+
}
|
|
461
|
+
return value;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
private optionalCount(
|
|
465
|
+
input: BoundaryJsonObject,
|
|
466
|
+
property: string,
|
|
467
|
+
pointer: string,
|
|
468
|
+
): number | undefined {
|
|
469
|
+
if (!hasOwn(input, property)) return undefined;
|
|
470
|
+
const value = input[property];
|
|
471
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
472
|
+
this.add(
|
|
473
|
+
"BSV1_SCHEMA_COUNT",
|
|
474
|
+
`Boundary Schema '${property}' must be a non-negative safe integer.`,
|
|
475
|
+
appendJsonPointerV1(pointer, property),
|
|
476
|
+
);
|
|
477
|
+
return undefined;
|
|
478
|
+
}
|
|
479
|
+
return value;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
private optionalNumber(
|
|
483
|
+
input: BoundaryJsonObject,
|
|
484
|
+
property: string,
|
|
485
|
+
pointer: string,
|
|
486
|
+
): number | undefined {
|
|
487
|
+
if (!hasOwn(input, property)) return undefined;
|
|
488
|
+
const value = input[property];
|
|
489
|
+
if (!isSupportedNumber(value)) {
|
|
490
|
+
this.add(
|
|
491
|
+
"BSV1_SCHEMA_NUMBER",
|
|
492
|
+
`Boundary Schema '${property}' must be a finite supported number.`,
|
|
493
|
+
appendJsonPointerV1(pointer, property),
|
|
494
|
+
);
|
|
495
|
+
return undefined;
|
|
496
|
+
}
|
|
497
|
+
return value;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
private rejectUnknownProperties(
|
|
501
|
+
input: BoundaryJsonObject,
|
|
502
|
+
pointer: string,
|
|
503
|
+
type: BoundarySchemaTypeV1 | undefined,
|
|
504
|
+
): void {
|
|
505
|
+
const allowed = new Set<string>(COMMON_PROPERTIES);
|
|
506
|
+
if (type !== undefined) {
|
|
507
|
+
for (const property of TYPE_PROPERTIES[type]) allowed.add(property);
|
|
508
|
+
}
|
|
509
|
+
for (const key of Object.keys(input).sort(compareText)) {
|
|
510
|
+
if (!allowed.has(key)) {
|
|
511
|
+
this.add(
|
|
512
|
+
"BSV1_SCHEMA_UNKNOWN_PROPERTY",
|
|
513
|
+
"Property is not supported by this Boundary Schema node type.",
|
|
514
|
+
appendJsonPointerV1(pointer, key),
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
private checkOrderedRange(
|
|
521
|
+
minimum: number | undefined,
|
|
522
|
+
maximum: number | undefined,
|
|
523
|
+
pointer: string,
|
|
524
|
+
minimumName: string,
|
|
525
|
+
maximumName: string,
|
|
526
|
+
): void {
|
|
527
|
+
if (minimum !== undefined && maximum !== undefined && minimum > maximum) {
|
|
528
|
+
this.add(
|
|
529
|
+
"BSV1_SCHEMA_RANGE",
|
|
530
|
+
`Boundary Schema '${minimumName}' cannot exceed '${maximumName}'.`,
|
|
531
|
+
pointer,
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
private checkNumericRange(
|
|
537
|
+
minimum: number | undefined,
|
|
538
|
+
maximum: number | undefined,
|
|
539
|
+
exclusiveMinimum: number | undefined,
|
|
540
|
+
exclusiveMaximum: number | undefined,
|
|
541
|
+
pointer: string,
|
|
542
|
+
): void {
|
|
543
|
+
const lower = strongestLowerBound(minimum, exclusiveMinimum);
|
|
544
|
+
const upper = strongestUpperBound(maximum, exclusiveMaximum);
|
|
545
|
+
if (
|
|
546
|
+
lower !== undefined
|
|
547
|
+
&& upper !== undefined
|
|
548
|
+
&& (lower.value > upper.value || (lower.value === upper.value && (lower.exclusive || upper.exclusive)))
|
|
549
|
+
) {
|
|
550
|
+
this.add(
|
|
551
|
+
"BSV1_SCHEMA_RANGE",
|
|
552
|
+
"Boundary Schema numeric constraints describe an empty range.",
|
|
553
|
+
pointer,
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
private add(code: string, message: string, pointer: string): void {
|
|
559
|
+
if (this.diagnostics.length > BAZIS_DIAGNOSTIC_LIMIT_V1) return;
|
|
560
|
+
this.diagnostics.push(bazisDiagnosticV1({
|
|
561
|
+
severity: "error",
|
|
562
|
+
stage: "schema",
|
|
563
|
+
code,
|
|
564
|
+
message,
|
|
565
|
+
pointer,
|
|
566
|
+
}));
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
interface NumericBound {
|
|
571
|
+
readonly value: number;
|
|
572
|
+
readonly exclusive: boolean;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function strongestLowerBound(
|
|
576
|
+
minimum: number | undefined,
|
|
577
|
+
exclusiveMinimum: number | undefined,
|
|
578
|
+
): NumericBound | undefined {
|
|
579
|
+
if (minimum === undefined) {
|
|
580
|
+
return exclusiveMinimum === undefined ? undefined : { value: exclusiveMinimum, exclusive: true };
|
|
581
|
+
}
|
|
582
|
+
if (exclusiveMinimum === undefined || minimum > exclusiveMinimum) {
|
|
583
|
+
return { value: minimum, exclusive: false };
|
|
584
|
+
}
|
|
585
|
+
return { value: exclusiveMinimum, exclusive: true };
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function strongestUpperBound(
|
|
589
|
+
maximum: number | undefined,
|
|
590
|
+
exclusiveMaximum: number | undefined,
|
|
591
|
+
): NumericBound | undefined {
|
|
592
|
+
if (maximum === undefined) {
|
|
593
|
+
return exclusiveMaximum === undefined ? undefined : { value: exclusiveMaximum, exclusive: true };
|
|
594
|
+
}
|
|
595
|
+
if (exclusiveMaximum === undefined || maximum < exclusiveMaximum) {
|
|
596
|
+
return { value: maximum, exclusive: false };
|
|
597
|
+
}
|
|
598
|
+
return { value: exclusiveMaximum, exclusive: true };
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function matchesScalarType(
|
|
602
|
+
value: BoundaryJsonValue,
|
|
603
|
+
type: "null" | "boolean" | "string" | "number" | "integer",
|
|
604
|
+
): value is null | boolean | string | number {
|
|
605
|
+
switch (type) {
|
|
606
|
+
case "null":
|
|
607
|
+
return value === null;
|
|
608
|
+
case "boolean":
|
|
609
|
+
return typeof value === "boolean";
|
|
610
|
+
case "string":
|
|
611
|
+
return typeof value === "string";
|
|
612
|
+
case "number":
|
|
613
|
+
return isSupportedNumber(value);
|
|
614
|
+
case "integer":
|
|
615
|
+
return typeof value === "number" && Number.isSafeInteger(value);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
function isSupportedNumber(value: BoundaryJsonValue | undefined): value is number {
|
|
620
|
+
return typeof value === "number"
|
|
621
|
+
&& Number.isFinite(value)
|
|
622
|
+
&& (!Number.isInteger(value) || Number.isSafeInteger(value));
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function cloneBoundaryJsonValue(value: BoundaryJsonValue): BoundaryJsonValue {
|
|
626
|
+
if (value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
|
|
627
|
+
return value;
|
|
628
|
+
}
|
|
629
|
+
if (Array.isArray(value)) {
|
|
630
|
+
return Object.freeze(value.map(cloneBoundaryJsonValue));
|
|
631
|
+
}
|
|
632
|
+
const object = value as BoundaryJsonObject;
|
|
633
|
+
const output = Object.create(null) as Record<string, BoundaryJsonValue>;
|
|
634
|
+
for (const key of Object.keys(object).sort(compareText)) {
|
|
635
|
+
output[key] = cloneBoundaryJsonValue(object[key]!);
|
|
636
|
+
}
|
|
637
|
+
return Object.freeze(output);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function hasOwn(input: BoundaryJsonObject, property: string): boolean {
|
|
641
|
+
return Object.prototype.hasOwnProperty.call(input, property);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function compareText(left: string, right: string): number {
|
|
645
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
646
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./boundarySchemaHashV1";
|
|
2
|
+
export * from "./decodeBoundarySchemaV1";
|
|
3
|
+
export * from "./types-v1";
|
|
4
|
+
export {
|
|
5
|
+
validateBoundaryValueV1,
|
|
6
|
+
type ValidateBoundaryValueV1Options,
|
|
7
|
+
type ValidateBoundaryValueV1Result,
|
|
8
|
+
} from "./validateBoundaryValueV1";
|