@webiny/api-core 6.0.0 → 6.1.0-beta.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/domain/security/ApiToken.d.ts +1 -0
- package/domain/security/ApiToken.js +1 -0
- package/domain/security/ApiToken.js.map +1 -1
- package/exports/api/security.d.ts +2 -0
- package/exports/api/security.js +2 -0
- package/exports/api/security.js.map +1 -1
- package/features/buildParams/abstractions.d.ts +2 -0
- package/features/buildParams/abstractions.js +2 -0
- package/features/buildParams/abstractions.js.map +1 -1
- package/features/eventPublisher/abstractions.d.ts +2 -0
- package/features/eventPublisher/abstractions.js +3 -0
- package/features/eventPublisher/abstractions.js.map +1 -1
- package/features/keyValueStore/abstractions.d.ts +4 -0
- package/features/keyValueStore/abstractions.js +4 -0
- package/features/keyValueStore/abstractions.js.map +1 -1
- package/features/logger/abstractions.d.ts +1 -0
- package/features/logger/abstractions.js +1 -0
- package/features/logger/abstractions.js.map +1 -1
- package/features/security/IdentityContext/abstractions.d.ts +1 -0
- package/features/security/IdentityContext/abstractions.js +1 -0
- package/features/security/IdentityContext/abstractions.js.map +1 -1
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js +1 -1
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/CreateApiKey/abstractions.d.ts +1 -0
- package/features/security/apiKeys/CreateApiKey/abstractions.js +1 -0
- package/features/security/apiKeys/CreateApiKey/abstractions.js.map +1 -1
- package/features/security/apiKeys/CreateApiKey/events.d.ts +2 -0
- package/features/security/apiKeys/CreateApiKey/events.js +4 -0
- package/features/security/apiKeys/CreateApiKey/events.js.map +1 -1
- package/features/security/apiKeys/DeleteApiKey/abstractions.d.ts +1 -0
- package/features/security/apiKeys/DeleteApiKey/abstractions.js +1 -0
- package/features/security/apiKeys/DeleteApiKey/abstractions.js.map +1 -1
- package/features/security/apiKeys/DeleteApiKey/events.d.ts +2 -0
- package/features/security/apiKeys/DeleteApiKey/events.js +4 -0
- package/features/security/apiKeys/DeleteApiKey/events.js.map +1 -1
- package/features/security/apiKeys/GetApiKey/abstractions.d.ts +1 -0
- package/features/security/apiKeys/GetApiKey/abstractions.js +1 -0
- package/features/security/apiKeys/GetApiKey/abstractions.js.map +1 -1
- package/features/security/apiKeys/GetApiKeyBySlug/abstractions.d.ts +1 -0
- package/features/security/apiKeys/GetApiKeyBySlug/abstractions.js +1 -0
- package/features/security/apiKeys/GetApiKeyBySlug/abstractions.js.map +1 -1
- package/features/security/apiKeys/GetApiKeyByToken/abstractions.d.ts +1 -0
- package/features/security/apiKeys/GetApiKeyByToken/abstractions.js +1 -0
- package/features/security/apiKeys/GetApiKeyByToken/abstractions.js.map +1 -1
- package/features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.js +1 -1
- package/features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.js.map +1 -1
- package/features/security/apiKeys/ListApiKeys/abstractions.d.ts +1 -0
- package/features/security/apiKeys/ListApiKeys/abstractions.js +1 -0
- package/features/security/apiKeys/ListApiKeys/abstractions.js.map +1 -1
- package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js +1 -1
- package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/UpdateApiKey/abstractions.d.ts +1 -0
- package/features/security/apiKeys/UpdateApiKey/abstractions.js +1 -0
- package/features/security/apiKeys/UpdateApiKey/abstractions.js.map +1 -1
- package/features/security/apiKeys/UpdateApiKey/events.d.ts +2 -0
- package/features/security/apiKeys/UpdateApiKey/events.js +4 -0
- package/features/security/apiKeys/UpdateApiKey/events.js.map +1 -1
- package/features/security/apiKeys/shared/abstractions.d.ts +5 -2
- package/features/security/apiKeys/shared/abstractions.js +3 -0
- package/features/security/apiKeys/shared/abstractions.js.map +1 -1
- package/features/security/apiKeys/shared/schemas.d.ts +10 -71
- package/features/security/apiKeys/shared/schemas.js +4 -4
- package/features/security/apiKeys/shared/schemas.js.map +1 -1
- package/features/security/authentication/AuthenticationContext/abstractions.d.ts +1 -0
- package/features/security/authentication/AuthenticationContext/abstractions.js +1 -0
- package/features/security/authentication/AuthenticationContext/abstractions.js.map +1 -1
- package/features/security/authentication/AuthenticationContext/events.d.ts +2 -0
- package/features/security/authentication/AuthenticationContext/events.js +4 -0
- package/features/security/authentication/AuthenticationContext/events.js.map +1 -1
- package/features/security/authentication/Authenticator/abstractions.d.ts +1 -0
- package/features/security/authentication/Authenticator/abstractions.js +1 -0
- package/features/security/authentication/Authenticator/abstractions.js.map +1 -1
- package/features/security/authorization/AuthorizationContext/abstractions.d.ts +2 -0
- package/features/security/authorization/AuthorizationContext/abstractions.js +2 -0
- package/features/security/authorization/AuthorizationContext/abstractions.js.map +1 -1
- package/features/security/authorization/Authorizer/abstractions.d.ts +1 -0
- package/features/security/authorization/Authorizer/abstractions.js +1 -0
- package/features/security/authorization/Authorizer/abstractions.js.map +1 -1
- package/features/security/login/abstractions.d.ts +1 -0
- package/features/security/login/abstractions.js +2 -0
- package/features/security/login/abstractions.js.map +1 -1
- package/features/security/roles/CreateRole/CreateRoleUseCase.d.ts +1 -3
- package/features/security/roles/CreateRole/CreateRoleUseCase.js +3 -7
- package/features/security/roles/CreateRole/CreateRoleUseCase.js.map +1 -1
- package/features/security/roles/CreateRole/abstractions.d.ts +1 -0
- package/features/security/roles/CreateRole/abstractions.js +1 -0
- package/features/security/roles/CreateRole/abstractions.js.map +1 -1
- package/features/security/roles/CreateRole/events.d.ts +2 -0
- package/features/security/roles/CreateRole/events.js +4 -0
- package/features/security/roles/CreateRole/events.js.map +1 -1
- package/features/security/roles/CreateRole/schema.d.ts +2 -20
- package/features/security/roles/CreateRole/schema.js +2 -2
- package/features/security/roles/CreateRole/schema.js.map +1 -1
- package/features/security/roles/DeleteRole/abstractions.d.ts +1 -0
- package/features/security/roles/DeleteRole/abstractions.js +1 -0
- package/features/security/roles/DeleteRole/abstractions.js.map +1 -1
- package/features/security/roles/DeleteRole/events.d.ts +2 -0
- package/features/security/roles/DeleteRole/events.js +4 -0
- package/features/security/roles/DeleteRole/events.js.map +1 -1
- package/features/security/roles/GetRole/abstractions.d.ts +1 -0
- package/features/security/roles/GetRole/abstractions.js +1 -0
- package/features/security/roles/GetRole/abstractions.js.map +1 -1
- package/features/security/roles/ListRoles/abstractions.d.ts +1 -0
- package/features/security/roles/ListRoles/abstractions.js +1 -0
- package/features/security/roles/ListRoles/abstractions.js.map +1 -1
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js +1 -1
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js.map +1 -1
- package/features/security/roles/UpdateRole/abstractions.d.ts +1 -0
- package/features/security/roles/UpdateRole/abstractions.js +1 -0
- package/features/security/roles/UpdateRole/abstractions.js.map +1 -1
- package/features/security/roles/UpdateRole/events.d.ts +2 -0
- package/features/security/roles/UpdateRole/events.js +4 -0
- package/features/security/roles/UpdateRole/events.js.map +1 -1
- package/features/security/roles/UpdateRole/schema.d.ts +2 -18
- package/features/security/roles/UpdateRole/schema.js +2 -2
- package/features/security/roles/UpdateRole/schema.js.map +1 -1
- package/features/security/roles/feature.js +2 -0
- package/features/security/roles/feature.js.map +1 -1
- package/features/security/roles/shared/RoleProvider.d.ts +13 -0
- package/features/security/roles/shared/RoleProvider.js +29 -0
- package/features/security/roles/shared/RoleProvider.js.map +1 -0
- package/features/security/roles/shared/RolesRepository.d.ts +3 -1
- package/features/security/roles/shared/RolesRepository.js +19 -18
- package/features/security/roles/shared/RolesRepository.js.map +1 -1
- package/features/security/roles/shared/abstractions.d.ts +19 -0
- package/features/security/roles/shared/abstractions.js +3 -0
- package/features/security/roles/shared/abstractions.js.map +1 -1
- package/features/security/shared/abstractions.d.ts +5 -14
- package/features/security/shared/abstractions.js +3 -16
- package/features/security/shared/abstractions.js.map +1 -1
- package/features/security/teams/CreateTeam/CreateTeamUseCase.d.ts +1 -3
- package/features/security/teams/CreateTeam/CreateTeamUseCase.js +3 -7
- package/features/security/teams/CreateTeam/CreateTeamUseCase.js.map +1 -1
- package/features/security/teams/CreateTeam/abstractions.d.ts +1 -0
- package/features/security/teams/CreateTeam/abstractions.js +1 -0
- package/features/security/teams/CreateTeam/abstractions.js.map +1 -1
- package/features/security/teams/CreateTeam/events.d.ts +2 -0
- package/features/security/teams/CreateTeam/events.js +4 -0
- package/features/security/teams/CreateTeam/events.js.map +1 -1
- package/features/security/teams/CreateTeam/schema.d.ts +2 -12
- package/features/security/teams/DeleteTeam/abstractions.d.ts +1 -0
- package/features/security/teams/DeleteTeam/abstractions.js +1 -0
- package/features/security/teams/DeleteTeam/abstractions.js.map +1 -1
- package/features/security/teams/DeleteTeam/events.d.ts +2 -0
- package/features/security/teams/DeleteTeam/events.js +4 -0
- package/features/security/teams/DeleteTeam/events.js.map +1 -1
- package/features/security/teams/GetTeam/abstractions.d.ts +1 -0
- package/features/security/teams/GetTeam/abstractions.js +1 -0
- package/features/security/teams/GetTeam/abstractions.js.map +1 -1
- package/features/security/teams/ListTeams/abstractions.d.ts +1 -0
- package/features/security/teams/ListTeams/abstractions.js +1 -0
- package/features/security/teams/ListTeams/abstractions.js.map +1 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js +1 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js.map +1 -1
- package/features/security/teams/UpdateTeam/abstractions.d.ts +1 -0
- package/features/security/teams/UpdateTeam/abstractions.js +1 -0
- package/features/security/teams/UpdateTeam/abstractions.js.map +1 -1
- package/features/security/teams/UpdateTeam/events.d.ts +2 -0
- package/features/security/teams/UpdateTeam/events.js +4 -0
- package/features/security/teams/UpdateTeam/events.js.map +1 -1
- package/features/security/teams/UpdateTeam/schema.d.ts +2 -10
- package/features/security/teams/feature.js +6 -0
- package/features/security/teams/feature.js.map +1 -1
- package/features/security/teams/shared/TeamProvider.d.ts +13 -0
- package/features/security/teams/shared/TeamProvider.js +29 -0
- package/features/security/teams/shared/TeamProvider.js.map +1 -0
- package/features/security/teams/shared/TeamsRepository.js +20 -18
- package/features/security/teams/shared/TeamsRepository.js.map +1 -1
- package/features/security/teams/shared/abstractions.d.ts +18 -0
- package/features/security/teams/shared/abstractions.js +3 -0
- package/features/security/teams/shared/abstractions.js.map +1 -1
- package/features/security/teams/shared/decorators/TeamsRepositoryCachingDecorator.d.ts +17 -0
- package/features/security/teams/shared/decorators/TeamsRepositoryCachingDecorator.js +76 -0
- package/features/security/teams/shared/decorators/TeamsRepositoryCachingDecorator.js.map +1 -0
- package/features/security/utils/verifyJwtUsingJwk.d.ts +2 -4
- package/features/security/utils/verifyJwtUsingJwk.js +1 -1
- package/features/security/utils/verifyJwtUsingJwk.js.map +1 -1
- package/features/system/InstallSystem/abstractions.d.ts +2 -3
- package/features/system/InstallSystem/abstractions.js +2 -3
- package/features/system/InstallSystem/abstractions.js.map +1 -1
- package/features/task/TaskController/abstractions.d.ts +1 -0
- package/features/task/TaskController/abstractions.js +1 -0
- package/features/task/TaskController/abstractions.js.map +1 -1
- package/features/task/TaskDefinition/abstractions.d.ts +1 -0
- package/features/task/TaskDefinition/abstractions.js +1 -0
- package/features/task/TaskDefinition/abstractions.js.map +1 -1
- package/features/task/TaskService/abstractions.d.ts +1 -0
- package/features/task/TaskService/abstractions.js +1 -0
- package/features/task/TaskService/abstractions.js.map +1 -1
- package/features/tenancy/CreateTenant/abstractions.d.ts +5 -3
- package/features/tenancy/CreateTenant/abstractions.js +5 -3
- package/features/tenancy/CreateTenant/abstractions.js.map +1 -1
- package/features/tenancy/DeleteTenant/abstractions.d.ts +5 -0
- package/features/tenancy/DeleteTenant/abstractions.js +5 -0
- package/features/tenancy/DeleteTenant/abstractions.js.map +1 -1
- package/features/tenancy/GetTenantById/abstractions.d.ts +3 -0
- package/features/tenancy/GetTenantById/abstractions.js +3 -9
- package/features/tenancy/GetTenantById/abstractions.js.map +1 -1
- package/features/tenancy/InstallTenant/abstractions.d.ts +3 -9
- package/features/tenancy/InstallTenant/abstractions.js +3 -12
- package/features/tenancy/InstallTenant/abstractions.js.map +1 -1
- package/features/tenancy/TenantContext/abstractions.d.ts +1 -0
- package/features/tenancy/TenantContext/abstractions.js +1 -0
- package/features/tenancy/TenantContext/abstractions.js.map +1 -1
- package/features/tenancy/UpdateTenant/abstractions.d.ts +5 -0
- package/features/tenancy/UpdateTenant/abstractions.js +5 -0
- package/features/tenancy/UpdateTenant/abstractions.js.map +1 -1
- package/features/users/CreateUser/CreateUserUseCase.js +1 -1
- package/features/users/CreateUser/CreateUserUseCase.js.map +1 -1
- package/features/users/CreateUser/abstractions.d.ts +1 -0
- package/features/users/CreateUser/abstractions.js +1 -1
- package/features/users/CreateUser/abstractions.js.map +1 -1
- package/features/users/CreateUser/events.d.ts +2 -0
- package/features/users/CreateUser/events.js +4 -0
- package/features/users/CreateUser/events.js.map +1 -1
- package/features/users/CreateUser/schema.d.ts +4 -36
- package/features/users/DeleteUser/abstractions.d.ts +1 -0
- package/features/users/DeleteUser/abstractions.js +1 -1
- package/features/users/DeleteUser/abstractions.js.map +1 -1
- package/features/users/DeleteUser/events.d.ts +2 -0
- package/features/users/DeleteUser/events.js +4 -0
- package/features/users/DeleteUser/events.js.map +1 -1
- package/features/users/GetUser/abstractions.d.ts +1 -0
- package/features/users/GetUser/abstractions.js +1 -1
- package/features/users/GetUser/abstractions.js.map +1 -1
- package/features/users/ListUserTeams/abstractions.d.ts +1 -0
- package/features/users/ListUserTeams/abstractions.js +1 -1
- package/features/users/ListUserTeams/abstractions.js.map +1 -1
- package/features/users/ListUsers/abstractions.d.ts +1 -0
- package/features/users/ListUsers/abstractions.js +1 -1
- package/features/users/ListUsers/abstractions.js.map +1 -1
- package/features/users/UpdateUser/UpdateUserUseCase.js +1 -1
- package/features/users/UpdateUser/UpdateUserUseCase.js.map +1 -1
- package/features/users/UpdateUser/abstractions.d.ts +1 -0
- package/features/users/UpdateUser/abstractions.js +1 -1
- package/features/users/UpdateUser/abstractions.js.map +1 -1
- package/features/users/UpdateUser/events.d.ts +2 -0
- package/features/users/UpdateUser/events.js +4 -0
- package/features/users/UpdateUser/events.js.map +1 -1
- package/features/users/UpdateUser/schema.d.ts +4 -30
- package/features/users/shared/abstractions.d.ts +1 -0
- package/features/users/shared/abstractions.js +1 -1
- package/features/users/shared/abstractions.js.map +1 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +0 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
- package/graphql/security/NotAuthorizedResponse.d.ts +1 -0
- package/graphql/security/NotAuthorizedResponse.js +1 -0
- package/graphql/security/NotAuthorizedResponse.js.map +1 -1
- package/idp/abstractions.d.ts +4 -0
- package/idp/abstractions.js +4 -0
- package/idp/abstractions.js.map +1 -1
- package/legacy/security/createSecurityContext.js +0 -11
- package/legacy/security/createSecurityContext.js.map +1 -1
- package/models/base/BaseModel.js +2 -2
- package/models/base/BaseModel.js.map +1 -1
- package/models/base/ModelBuilder.d.ts +2 -2
- package/models/base/ModelBuilder.js +21 -2
- package/models/base/ModelBuilder.js.map +1 -1
- package/models/cms/FieldBuilder.d.ts +3 -2
- package/models/cms/FieldBuilder.js +12 -17
- package/models/cms/FieldBuilder.js.map +1 -1
- package/models/cms/FieldBuilderRegistry.d.ts +1 -1
- package/models/cms/FieldBuilderRegistry.js.map +1 -1
- package/models/cms/FieldDefinitionsBuilder.d.ts +1 -0
- package/models/cms/FieldDefinitionsBuilder.js +13 -15
- package/models/cms/FieldDefinitionsBuilder.js.map +1 -1
- package/models/cms/PrivateCmsModelBuilder.js.map +1 -1
- package/models/cms/abstractions.d.ts +1 -1
- package/models/cms/abstractions.js.map +1 -1
- package/models/cms/fieldsBuilder.md +1 -1
- package/models/simple/Page/abstractions.d.ts +1 -11
- package/package.json +20 -20
- package/types/security.d.ts +13 -10
- package/types/security.js.map +1 -1
- package/features/security/shared/abstractions.ts.bak +0 -52
- package/legacy/security/plugins/SecurityRolePlugin.d.ts +0 -16
- package/legacy/security/plugins/SecurityRolePlugin.js +0 -33
- package/legacy/security/plugins/SecurityRolePlugin.js.map +0 -1
- package/legacy/security/plugins/SecurityTeamPlugin.d.ts +0 -16
- package/legacy/security/plugins/SecurityTeamPlugin.js +0 -33
- package/legacy/security/plugins/SecurityTeamPlugin.js.map +0 -1
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import { ContextPlugin } from "@webiny/api";
|
|
2
|
-
import { RolesProvider, TeamsProvider } from "../../features/security/shared/abstractions.js";
|
|
3
|
-
import { SecurityRolePlugin } from "./plugins/SecurityRolePlugin.js";
|
|
4
|
-
import { SecurityTeamPlugin } from "./plugins/SecurityTeamPlugin.js";
|
|
5
2
|
import { LegacyContext } from "./LegacyContext.js";
|
|
6
3
|
import { createSecurityGraphQL } from "../../graphql/security/index.js";
|
|
7
4
|
export const createSecurityContext = () => {
|
|
8
5
|
return new ContextPlugin(async context => {
|
|
9
|
-
// Register roles and teams providers for plugin-defined roles/teams
|
|
10
|
-
context.container.registerFactory(RolesProvider, () => {
|
|
11
|
-
return async () => context.plugins.byType(SecurityRolePlugin.type).map(plugin => plugin.securityRole);
|
|
12
|
-
});
|
|
13
|
-
context.container.registerFactory(TeamsProvider, () => {
|
|
14
|
-
return async () => context.plugins.byType(SecurityTeamPlugin.type).map(plugin => plugin.securityTeam);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
6
|
// Create a legacy context that delegates to new features
|
|
18
7
|
context.security = new LegacyContext(context.container);
|
|
19
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ContextPlugin","
|
|
1
|
+
{"version":3,"names":["ContextPlugin","LegacyContext","createSecurityGraphQL","createSecurityContext","context","security","container","plugins","register"],"sources":["createSecurityContext.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { LegacyContext } from \"~/legacy/security/LegacyContext.js\";\nimport { createSecurityGraphQL } from \"~/graphql/security/index.js\";\n\nexport const createSecurityContext = () => {\n return new ContextPlugin<ApiCoreContext>(async context => {\n // Create a legacy context that delegates to new features\n context.security = new LegacyContext(context.container);\n\n // Register GraphQL plugins\n context.plugins.register(createSecurityGraphQL());\n });\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,aAAa;AAE3C,SAASC,aAAa;AACtB,SAASC,qBAAqB;AAE9B,OAAO,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;EACvC,OAAO,IAAIH,aAAa,CAAiB,MAAMI,OAAO,IAAI;IACtD;IACAA,OAAO,CAACC,QAAQ,GAAG,IAAIJ,aAAa,CAACG,OAAO,CAACE,SAAS,CAAC;;IAEvD;IACAF,OAAO,CAACG,OAAO,CAACC,QAAQ,CAACN,qBAAqB,CAAC,CAAC,CAAC;EACrD,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
package/models/base/BaseModel.js
CHANGED
|
@@ -27,7 +27,7 @@ export class BaseModel {
|
|
|
27
27
|
return new Constructor(this.toData());
|
|
28
28
|
}
|
|
29
29
|
toData() {
|
|
30
|
-
if (this.__schema && this.__schema.
|
|
30
|
+
if (this.__schema && this.__schema.def?.type === "object") {
|
|
31
31
|
const result = {};
|
|
32
32
|
const shape = this.__schema.shape;
|
|
33
33
|
for (const key in shape) {
|
|
@@ -55,7 +55,7 @@ export class BaseModel {
|
|
|
55
55
|
throw new WebinyError({
|
|
56
56
|
message: "Validation error",
|
|
57
57
|
code: "DOMAIN_MODEL_VALIDATION_ERROR",
|
|
58
|
-
data: result.error.
|
|
58
|
+
data: result.error.issues
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","WebinyError","BaseModel","__schema","Error","constructor","data","validateData","populate","Object","assign","validate","toData","ok","error","fail","validateOrThrow","clone","Constructor","
|
|
1
|
+
{"version":3,"names":["Result","WebinyError","BaseModel","__schema","Error","constructor","data","validateData","populate","Object","assign","validate","toData","ok","error","fail","validateOrThrow","clone","Constructor","def","type","result","shape","key","structuredClone","updateWith","partial","updated","safeParse","success","message","code","issues"],"sources":["BaseModel.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { WebinyError } from \"@webiny/error\";\nimport z from \"zod\";\n\ntype DataProperties<T> = Omit<T, \"__schema\">;\n\nexport type IModelData<T> = {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n [K in keyof DataProperties<T> as T[K] extends Function ? never : K]: T[K];\n};\n\nexport type IModelInput<T> = IModelData<T>;\n\nexport abstract class BaseModel<TModel extends z.ZodObject<any> = any> {\n get __schema(): TModel {\n throw new Error(\"Schema getter is not implemented!\");\n }\n\n constructor(data: IModelData<TModel>) {\n this.validateData(data);\n this.populate(data);\n }\n\n populate(data: IModelData<TModel>): void {\n Object.assign(this, data);\n }\n\n validate(): Result<true, WebinyError> {\n try {\n this.validateData(this.toData());\n return Result.ok(true);\n } catch (error) {\n return Result.fail(error);\n }\n }\n\n validateOrThrow(): void {\n this.validateData(this.toData());\n }\n\n clone(): this {\n const Constructor = this.constructor as new (data: IModelData<TModel>) => this;\n return new Constructor(this.toData());\n }\n\n toData(): IModelData<TModel> {\n if (this.__schema && this.__schema.def?.type === \"object\") {\n const result = {} as IModelData<TModel>;\n const shape = this.__schema.shape;\n for (const key in shape) {\n // always use structuredClone for safety.\n // @ts-expect-error allow index.\n result[key] = structuredClone(this[key]);\n }\n return result;\n }\n\n return { ...(this as any) } as IModelData<TModel>;\n }\n\n updateWith(partial: Partial<IModelData<this>>): void {\n const updated = { ...this.toData(), ...partial };\n this.validateData(updated);\n this.populate(updated);\n }\n\n protected validateData(data: IModelData<TModel>): void {\n const result = this.__schema.safeParse(data);\n if (!result.success) {\n throw new WebinyError({\n message: \"Validation error\",\n code: \"DOMAIN_MODEL_VALIDATION_ERROR\",\n data: result.error.issues\n });\n }\n }\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,WAAW,QAAQ,eAAe;AAY3C,OAAO,MAAeC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E,GAAI;IAAa,CAAC;EAC/B;EAEAI,UAAUA,CAACC,OAAkC,EAAQ;IACjD,MAAMC,OAAO,GAAG;MAAE,GAAG,IAAI,CAACf,MAAM,CAAC,CAAC;MAAE,GAAGc;IAAQ,CAAC;IAChD,IAAI,CAACnB,YAAY,CAACoB,OAAO,CAAC;IAC1B,IAAI,CAACnB,QAAQ,CAACmB,OAAO,CAAC;EAC1B;EAEUpB,YAAYA,CAACD,IAAwB,EAAQ;IACnD,MAAMe,MAAM,GAAG,IAAI,CAAClB,QAAQ,CAACyB,SAAS,CAACtB,IAAI,CAAC;IAC5C,IAAI,CAACe,MAAM,CAACQ,OAAO,EAAE;MACjB,MAAM,IAAI5B,WAAW,CAAC;QAClB6B,OAAO,EAAE,kBAAkB;QAC3BC,IAAI,EAAE,+BAA+B;QACrCzB,IAAI,EAAEe,MAAM,CAACP,KAAK,CAACkB;MACvB,CAAC,CAAC;IACN;EACJ;AACJ","ignoreList":[]}
|
|
@@ -5,11 +5,11 @@ export type ModelClass<TModel extends BaseModel<any>> = {
|
|
|
5
5
|
new (data: ExtractModelData<TModel>): TModel;
|
|
6
6
|
create(data: ExtractModelData<TModel>): TModel;
|
|
7
7
|
};
|
|
8
|
-
export declare const createModelSchema: <TReturn extends z.ZodRawShape>(factory: (zod: typeof z) => TReturn) => z.ZodObject<
|
|
8
|
+
export declare const createModelSchema: <TReturn extends z.ZodRawShape>(factory: (zod: typeof z) => TReturn) => z.ZodObject<{ -readonly [P in keyof TReturn]: TReturn[P]; }, z.core.$strip>;
|
|
9
9
|
export declare class ModelBuilder<TModel extends BaseModel<any>> {
|
|
10
10
|
private name;
|
|
11
11
|
private schema;
|
|
12
|
-
private methods;
|
|
12
|
+
private readonly methods;
|
|
13
13
|
constructor(name: string, schema: TModel["__schema"]);
|
|
14
14
|
extendSchema<TExt extends z.ZodRawShape>(extensionFn: (zod: typeof z) => TExt): this;
|
|
15
15
|
withMethods<TExtMethods extends object>(methods: TExtMethods & ThisType<TModel & TExtMethods>): ModelBuilder<TModel & TExtMethods>;
|
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BaseModel } from "./BaseModel.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom type to compare Zod types and extract the inner type if it's wrapped in ZodOptional, ZodNullable, or ZodDefault.
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
export const createModelSchema = factory => {
|
|
4
9
|
return z.object({
|
|
5
10
|
...factory(z)
|
|
6
11
|
});
|
|
7
12
|
};
|
|
13
|
+
const shouldAssign = inner => {
|
|
14
|
+
if (!inner) {
|
|
15
|
+
return false;
|
|
16
|
+
} else if (!("def" in inner)) {
|
|
17
|
+
return false;
|
|
18
|
+
} else if (inner.def.type === "optional") {
|
|
19
|
+
return true;
|
|
20
|
+
} else if (inner.def.type === "nullable") {
|
|
21
|
+
return true;
|
|
22
|
+
} else if (inner.def.type === "default") {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
};
|
|
8
27
|
export class ModelBuilder {
|
|
9
28
|
methods = {};
|
|
10
29
|
constructor(name, schema) {
|
|
@@ -20,8 +39,8 @@ export class ModelBuilder {
|
|
|
20
39
|
baseExtensionsObject = baseExtensions;
|
|
21
40
|
} else if (baseExtensions) {
|
|
22
41
|
let inner = baseExtensions;
|
|
23
|
-
while (
|
|
24
|
-
inner = inner.
|
|
42
|
+
while (shouldAssign(inner)) {
|
|
43
|
+
inner = inner.def.innerType;
|
|
25
44
|
}
|
|
26
45
|
baseExtensionsObject = inner instanceof z.ZodObject ? inner : z.object({});
|
|
27
46
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["z","BaseModel","createModelSchema","factory","object","ModelBuilder","methods","constructor","name","schema","extendSchema","extensionFn","shape","baseExtensions","extensions","baseExtensionsObject","ZodObject","
|
|
1
|
+
{"version":3,"names":["z","BaseModel","createModelSchema","factory","object","shouldAssign","inner","def","type","ModelBuilder","methods","constructor","name","schema","extendSchema","extensionFn","shape","baseExtensions","extensions","baseExtensionsObject","ZodObject","innerType","newExtensions","extend","withMethods","Object","assign","getSchema","build","Model","__schema","create","data","clone","Constructor","toData","prototype","defineProperty","Symbol","toStringTag","value"],"sources":["ModelBuilder.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { BaseModel, type IModelData as ExtractModelData } from \"./BaseModel.js\";\nimport type { $ZodTypeDef } from \"zod/v4/core\";\n\nexport type ModelClass<TModel extends BaseModel<any>> = {\n __schema: TModel[\"__schema\"];\n new (data: ExtractModelData<TModel>): TModel;\n create(data: ExtractModelData<TModel>): TModel;\n};\n\n/**\n * Custom type to compare Zod types and extract the inner type if it's wrapped in ZodOptional, ZodNullable, or ZodDefault.\n */\ntype InnerType = z.ZodTypeAny & {\n def: $ZodTypeDef & {\n innerType?: z.ZodObject<any>;\n };\n};\n\nexport const createModelSchema = <TReturn extends z.ZodRawShape>(\n factory: (zod: typeof z) => TReturn\n) => {\n return z.object({ ...factory(z) });\n};\n\nconst shouldAssign = (inner: InnerType): boolean => {\n if (!inner) {\n return false;\n } else if (!(\"def\" in inner)) {\n return false;\n } else if (inner.def.type === \"optional\") {\n return true;\n } else if (inner.def.type === \"nullable\") {\n return true;\n } else if (inner.def.type === \"default\") {\n return true;\n }\n return false;\n};\n\nexport class ModelBuilder<TModel extends BaseModel<any>> {\n private readonly methods: Partial<Record<keyof TModel, any>> = {};\n\n constructor(\n private name: string,\n private schema: TModel[\"__schema\"]\n ) {\n this.methods = {};\n }\n\n extendSchema<TExt extends z.ZodRawShape>(extensionFn: (zod: typeof z) => TExt): this {\n const shape = extensionFn(z);\n const baseExtensions = this.schema.shape.extensions;\n\n let baseExtensionsObject: z.ZodObject<any>;\n if (baseExtensions instanceof z.ZodObject) {\n baseExtensionsObject = baseExtensions;\n } else if (baseExtensions) {\n let inner = baseExtensions as InnerType;\n\n while (shouldAssign(inner)) {\n inner = inner.def.innerType!;\n }\n baseExtensionsObject = inner instanceof z.ZodObject ? inner : z.object({});\n } else {\n baseExtensionsObject = z.object({});\n }\n\n const newExtensions = baseExtensionsObject.extend(shape);\n this.schema = this.schema.extend({\n extensions: newExtensions\n }) as TModel[\"__schema\"];\n\n return this;\n }\n\n withMethods<TExtMethods extends object>(\n methods: TExtMethods & ThisType<TModel & TExtMethods>\n ): ModelBuilder<TModel & TExtMethods> {\n Object.assign(this.methods, methods);\n return this as unknown as ModelBuilder<TModel & TExtMethods>;\n }\n\n getSchema() {\n return this.schema;\n }\n\n build(): ModelClass<TModel> {\n const schema = this.schema;\n const methods = this.methods;\n const name = this.name;\n\n type ModelData = ExtractModelData<TModel>;\n\n class Model extends BaseModel<TModel[\"__schema\"]> {\n public override get __schema() {\n return schema;\n }\n\n static __schema = schema;\n\n static create(data: ModelData) {\n return new this(data) as unknown as TModel;\n }\n\n override clone(): this {\n const Constructor = this.constructor as new (data: ModelData) => this;\n return new Constructor(this.toData());\n }\n }\n\n Object.assign(Model.prototype, methods);\n\n Object.defineProperty(Model.prototype, Symbol.toStringTag, {\n value: name\n });\n\n return Model as unknown as ModelClass<TModel>;\n }\n}\n"],"mappings":"AAAA,SAASA,CAAC,QAAQ,KAAK;AACvB,SAASC,SAAS;;AASlB;AACA;AACA;;AAOA,OAAO,MAAMC,iBAAiB,GAC1BC,OAAmC,IAClC;EACD,OAAOH,CAAC,CAACI,MAAM,CAAC;IAAE,GAAGD,OAAO,CAACH,CAAC;EAAE,CAAC,CAAC;AACtC,CAAC;AAED,MAAMK,YAAY,GAAIC,KAAgB,IAAc;EAChD,IAAI,CAACA,KAAK,EAAE;IACR,OAAO,KAAK;EAChB,CAAC,MAAM,IAAI,EAAE,KAAK,IAAIA,KAAK,CAAC,EAAE;IAC1B,OAAO,KAAK;EAChB,CAAC,MAAM,IAAIA,KAAK,CAACC,GAAG,CAACC,IAAI,KAAK,UAAU,EAAE;IACtC,OAAO,IAAI;EACf,CAAC,MAAM,IAAIF,KAAK,CAACC,GAAG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AI;EACf;EAEAE,WAAWA,CACPd,OAAqD,EACnB;IAClCe,MAAM,CAACC,MAAM,CAAC,IAAI,CAAChB,OAAO,EAAEA,OAAO,CAAC;IACpC,OAAO,IAAI;EACf;EAEAiB,SAASA,CAAA,EAAG;IACR,OAAO,IAAI,CAACd,MAAM;EACtB;EAEAe,KAAKA,CAAA,EAAuB;IACxB,MAAMf,MAAM,GAAG,IAAI,CAACA,MAAM;IAC1B,MAAMH,OAAO,GAAG,IAAI,CAACA,OAAO;IAC5B,MAAME,IAAI,GAAG,IAAI,CAACA,IAAI;IAItB,MAAMiB,KAAK,SAAS5B,SAAS,CAAqB;MAC9C,IAAoB6B,QAAQA,CAAA,EAAG;QAC3B,OAAOjB,MAAM;MACjB;MAEA,OAAOiB,QAAQ,GAAGjB,MAAM;MAExB,OAAOkB,MAAMA,CAACC,IAAe,EAAE;QAC3B,OAAO,IAAI,IAAI,CAACA,IAAI,CAAC;MACzB;MAESC,KAAKA,CAAA,EAAS;QACnB,MAAMC,WAAW,GAAG,IAAI,CAACvB,WAA4C;QACrE,OAAO,IAAIuB,WAAW,CAAC,IAAI,CAACC,MAAM,CAAC,CAAC,CAAC;MACzC;IACJ;IAEAV,MAAM,CAACC,MAAM,CAACG,KAAK,CAACO,SAAS,EAAE1B,OAAO,CAAC;IAEvCe,MAAM,CAACY,cAAc,CAACR,KAAK,CAACO,SAAS,EAAEE,MAAM,CAACC,WAAW,EAAE;MACvDC,KAAK,EAAE5B;IACX,CAAC,CAAC;IAEF,OAAOiB,KAAK;EAChB;AACJ","ignoreList":[]}
|
|
@@ -19,12 +19,13 @@ export declare class TextFieldBuilder<TZod extends z.ZodString = z.ZodString> ex
|
|
|
19
19
|
slug(): this;
|
|
20
20
|
email(): this;
|
|
21
21
|
url(): this;
|
|
22
|
+
private addStringValidator;
|
|
22
23
|
unique(): this;
|
|
23
24
|
}
|
|
24
25
|
export declare class ObjectFieldBuilder<TShape extends z.ZodRawShape> extends FieldBuilder<z.ZodObject<TShape>> {
|
|
25
|
-
private nestedFields;
|
|
26
|
+
private readonly nestedFields;
|
|
26
27
|
constructor(fields: (registry: IFieldBuilderRegistry) => {
|
|
27
|
-
[K in keyof TShape]: FieldBuilder<TShape[K]>;
|
|
28
|
+
[K in keyof TShape]: FieldBuilder<TShape[K] & z.ZodTypeAny>;
|
|
28
29
|
}, registry: IFieldBuilderRegistry);
|
|
29
30
|
optional(): ObjectFieldBuilder<TShape> & {
|
|
30
31
|
getZodSchema(): z.ZodOptional<z.ZodObject<TShape>>;
|
|
@@ -61,28 +61,19 @@ export class TextFieldBuilder extends FieldBuilder {
|
|
|
61
61
|
return this;
|
|
62
62
|
}
|
|
63
63
|
slug() {
|
|
64
|
-
this.
|
|
65
|
-
this.config.validation?.push({
|
|
66
|
-
name: "slug",
|
|
67
|
-
message: "Must be a valid slug",
|
|
68
|
-
settings: {}
|
|
69
|
-
});
|
|
70
|
-
return this;
|
|
64
|
+
return this.addStringValidator(this.zodSchema.regex(/^[a-z0-9-]+$/, "Must be a valid slug (lowercase letters, numbers, and hyphens only)"), "slug", "Must be a valid slug");
|
|
71
65
|
}
|
|
72
66
|
email() {
|
|
73
|
-
this.
|
|
74
|
-
this.config.validation?.push({
|
|
75
|
-
name: "email",
|
|
76
|
-
message: "Must be a valid email",
|
|
77
|
-
settings: {}
|
|
78
|
-
});
|
|
79
|
-
return this;
|
|
67
|
+
return this.addStringValidator(this.zodSchema.email("Must be a valid email"), "email", "Must be a valid email");
|
|
80
68
|
}
|
|
81
69
|
url() {
|
|
82
|
-
this.
|
|
70
|
+
return this.addStringValidator(this.zodSchema.url("Must be a valid URL"), "url", "Must be a valid URL");
|
|
71
|
+
}
|
|
72
|
+
addStringValidator(schema, name, message) {
|
|
73
|
+
this.zodSchema = schema;
|
|
83
74
|
this.config.validation?.push({
|
|
84
|
-
name
|
|
85
|
-
message
|
|
75
|
+
name,
|
|
76
|
+
message,
|
|
86
77
|
settings: {}
|
|
87
78
|
});
|
|
88
79
|
return this;
|
|
@@ -115,11 +106,15 @@ export class ObjectFieldBuilder extends FieldBuilder {
|
|
|
115
106
|
this.config.fields = nestedConfigs;
|
|
116
107
|
}
|
|
117
108
|
optional() {
|
|
109
|
+
// @ts-expect-error
|
|
118
110
|
this.zodSchema = this.zodSchema.optional();
|
|
111
|
+
// @ts-expect-error
|
|
119
112
|
return this;
|
|
120
113
|
}
|
|
121
114
|
nullable() {
|
|
115
|
+
// @ts-expect-error
|
|
122
116
|
this.zodSchema = this.zodSchema.nullable();
|
|
117
|
+
// @ts-expect-error
|
|
123
118
|
return this;
|
|
124
119
|
}
|
|
125
120
|
toConfig() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["z","FieldBuilder","config","validation","constructor","type","initialSchema","zodSchema","label","text","help","placeholder","toConfig","fieldId","settings","getZodSchema","TextFieldBuilder","schema","string","required","message","newSchema","min","push","name","minLength","length","maxLength","max","slug","regex","email","url","unique","ObjectFieldBuilder","nestedFields","fields","registry","fieldBuilders","shape","nestedConfigs","builder","Object","entries","object","optional","nullable"],"sources":["FieldBuilder.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { FieldConfig } from \"./types.js\";\nimport type { IFieldBuilderRegistry } from \"./abstractions.js\";\n\n// Make FieldBuilder return the Zod type it produces\nexport abstract class FieldBuilder<TZod extends z.ZodTypeAny> {\n protected config: Partial<FieldConfig> = {\n validation: []\n };\n protected zodSchema: TZod;\n\n constructor(type: string, initialSchema: TZod) {\n this.config.type = type;\n this.zodSchema = initialSchema;\n }\n\n label(text: string): this {\n this.config.label = text;\n return this;\n }\n\n help(text: string): this {\n this.config.help = text;\n return this;\n }\n\n placeholder(text: string): this {\n this.config.placeholder = text;\n return this;\n }\n\n toConfig(): FieldConfig {\n return {\n fieldId: \"\",\n type: this.config.type!,\n label: this.config.label,\n help: this.config.help,\n placeholder: this.config.placeholder,\n validation: this.config.validation || [],\n settings: this.config.settings || {},\n zodSchema: this.zodSchema\n };\n }\n\n getZodSchema(): TZod {\n return this.zodSchema;\n }\n}\n\n// Text Field Builder - properly track type transformations\nexport class TextFieldBuilder<TZod extends z.ZodString = z.ZodString> extends FieldBuilder<TZod> {\n constructor(schema?: TZod) {\n super(\"text\", (schema || z.string()) as TZod);\n }\n\n required(message?: string): TextFieldBuilder<z.ZodString> {\n const newSchema =
|
|
1
|
+
{"version":3,"names":["z","FieldBuilder","config","validation","constructor","type","initialSchema","zodSchema","label","text","help","placeholder","toConfig","fieldId","settings","getZodSchema","TextFieldBuilder","schema","string","required","message","newSchema","min","push","name","minLength","length","maxLength","max","slug","addStringValidator","regex","email","url","unique","ObjectFieldBuilder","nestedFields","fields","registry","fieldBuilders","shape","nestedConfigs","builder","Object","entries","object","optional","nullable"],"sources":["FieldBuilder.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { FieldConfig } from \"./types.js\";\nimport type { IFieldBuilderRegistry } from \"./abstractions.js\";\n\n// Make FieldBuilder return the Zod type it produces\nexport abstract class FieldBuilder<TZod extends z.ZodTypeAny> {\n protected config: Partial<FieldConfig> = {\n validation: []\n };\n protected zodSchema: TZod;\n\n constructor(type: string, initialSchema: TZod) {\n this.config.type = type;\n this.zodSchema = initialSchema;\n }\n\n label(text: string): this {\n this.config.label = text;\n return this;\n }\n\n help(text: string): this {\n this.config.help = text;\n return this;\n }\n\n placeholder(text: string): this {\n this.config.placeholder = text;\n return this;\n }\n\n toConfig(): FieldConfig {\n return {\n fieldId: \"\",\n type: this.config.type!,\n label: this.config.label,\n help: this.config.help,\n placeholder: this.config.placeholder,\n validation: this.config.validation || [],\n settings: this.config.settings || {},\n zodSchema: this.zodSchema\n };\n }\n\n getZodSchema(): TZod {\n return this.zodSchema;\n }\n}\n\n// Text Field Builder - properly track type transformations\nexport class TextFieldBuilder<TZod extends z.ZodString = z.ZodString> extends FieldBuilder<TZod> {\n constructor(schema?: TZod) {\n super(\"text\", (schema || z.string()) as TZod);\n }\n\n required(message?: string): TextFieldBuilder<z.ZodString> {\n const newSchema = this.zodSchema.min(1, message || \"Field is required\");\n this.zodSchema = newSchema;\n this.config.validation?.push({\n name: \"required\",\n message: message || \"Field is required\",\n settings: {}\n });\n return this;\n }\n\n minLength(length: number, message?: string): this {\n this.zodSchema = this.zodSchema.min(length, message) as TZod;\n return this;\n }\n\n maxLength(length: number, message?: string): this {\n this.zodSchema = this.zodSchema.max(length, message) as TZod;\n return this;\n }\n\n slug(): this {\n return this.addStringValidator(\n this.zodSchema.regex(\n /^[a-z0-9-]+$/,\n \"Must be a valid slug (lowercase letters, numbers, and hyphens only)\"\n ),\n \"slug\",\n \"Must be a valid slug\"\n );\n }\n\n email(): this {\n return this.addStringValidator(\n this.zodSchema.email(\"Must be a valid email\"),\n \"email\",\n \"Must be a valid email\"\n );\n }\n\n url(): this {\n return this.addStringValidator(\n this.zodSchema.url(\"Must be a valid URL\"),\n \"url\",\n \"Must be a valid URL\"\n );\n }\n\n private addStringValidator(schema: z.ZodString, name: string, message: string): this {\n this.zodSchema = schema as TZod;\n this.config.validation?.push({ name, message, settings: {} });\n return this;\n }\n\n unique(): this {\n this.config.validation?.push({\n name: \"unique\",\n message: \"Value must be unique\",\n settings: {}\n });\n return this;\n }\n}\n\n// Object Field Builder - track the shape type\nexport class ObjectFieldBuilder<TShape extends z.ZodRawShape> extends FieldBuilder<\n z.ZodObject<TShape>\n> {\n private readonly nestedFields: FieldConfig[] = [];\n\n constructor(\n fields: (registry: IFieldBuilderRegistry) => {\n [K in keyof TShape]: FieldBuilder<TShape[K] & z.ZodTypeAny>;\n },\n registry: IFieldBuilderRegistry\n ) {\n const fieldBuilders = fields(registry);\n const shape = {} as TShape;\n const nestedConfigs: FieldConfig[] = [];\n\n for (const [fieldId, builder] of Object.entries(fieldBuilders) as Array<\n [keyof TShape, FieldBuilder<any>]\n >) {\n const config = builder.toConfig();\n config.fieldId = fieldId as string;\n nestedConfigs.push(config);\n shape[fieldId] = builder.getZodSchema() as TShape[keyof TShape];\n }\n\n super(\"object\", z.object(shape));\n this.nestedFields = nestedConfigs;\n this.config.fields = nestedConfigs;\n }\n\n optional(): ObjectFieldBuilder<TShape> & {\n getZodSchema(): z.ZodOptional<z.ZodObject<TShape>>;\n } {\n // @ts-expect-error\n this.zodSchema = this.zodSchema.optional();\n // @ts-expect-error\n return this;\n }\n\n nullable(): ObjectFieldBuilder<TShape> & {\n getZodSchema(): z.ZodNullable<z.ZodObject<TShape>>;\n } {\n // @ts-expect-error\n this.zodSchema = this.zodSchema.nullable();\n // @ts-expect-error\n return this;\n }\n\n override toConfig(): FieldConfig {\n const config = super.toConfig();\n config.fields = this.nestedFields;\n return config;\n }\n}\n"],"mappings":"AAAA,SAASA,CAAC,QAAQ,KAAK;AAIvB;AACA,OAAO,MAAeC,YAAY,CAA4B;EAChDC,MAAM,GAAyB;IACrCC,UAAU,EAAE;EAChB,CAAC;EAGDC,WAAWA,CAACC,IAAY,EAAEC,aAAmB,EAAE;IAC3C,IAAI,CAACJ,MAAM,CAACG,IAAI,GAAGA,IAAI;IACvB,IAAI,CAACE,SAAS,GAAGD,aAAa;EAClC;EAEAE,KAAKA,CAACC,IAAY,EAAQ;IACtB,IAAI,CAACP,MAAM,CAACM,KAAK,GAAGC,IAAI;IACxB,OAAO,IAAI;EACf;EAEAC,IAAIA,CAACD,IAAY,EAAQ;IACrB,IAAI,CAACP,MAAM,CAACQ,IAAI,GAAGD,IAAI;IACvB,OAAO,IAAI;EACf;EAEAE,WAAWA,CAACF,IAAY,EAAQ;IAC5B,IAAI,CAACP,MAAM,CAACS,WAAW,GAAGF,IAAI;IAC9B,OAAO,IAAI;EACf;EAEAG,QAAQA,CAAA,EAAgB;IACpB,OAAO;MACHC,OAAO,EAAE,EAAE;MACXR,IAAI,EAAE,IAAI,CAACH,MAAM,CAACG,IAAK;MACvBG,KAAK,EAAE,IAAI,CAACN,MAAM,CAACM,KAAK;MACxBE,IAAI,EAAE,IAAI,CAACR,MAAM,CAACQ,IAAI;MACtBC,WAAW,EAAE,IAAI,CAACT,MAAM,CAACS,WAAW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,CAAC,CAAC;MACjCV,MAAM,CAACW,OAAO,GAAGA,OAAiB;MAClC4B,aAAa,CAAClB,IAAI,CAACrB,MAAM,CAAC;MAC1BsC,KAAK,CAAC3B,OAAO,CAAC,GAAG6B,OAAO,CAAC3B,YAAY,CAAC,CAAyB;IACnE;IAEA,KAAK,CAAC,QAAQ,EAAEf,CAAC,CAAC6C,MAAM,CAACL,KAAK,CAAC,CAAC;IAChC,IAAI,CAACJ,YAAY,GAAGK,aAAa;IACjC,IAAI,CAACvC,MAAM,CAACmC,MAAM,GAAGI,aAAa;EACtC;EAEAK,QAAQA,CAAA,EAEN;IACE;IACA,IAAI,CAACvC,SAAS,GAAG,IAAI,CAACA,SAAS,CAACuC,QAAQ,CAAC,CAAC;IAC1C;IACA,OAAO,IAAI;EACf;EAEAC,QAAQA,CAAA,EAEN;IACE;IACA,IAAI,CAACxC,SAAS,GAAG,IAAI,CAACA,SAAS,CAACwC,QAAQ,CAAC,CAAC;IAC1C;IACA,OAAO,IAAI;EACf;EAESnC,QAAQA,CAAA,EAAgB;IAC7B,MAAMV,MAAM,GAAG,KAAK,CAACU,QAAQ,CAAC,CAAC;IAC/BV,MAAM,CAACmC,MAAM,GAAG,IAAI,CAACD,YAAY;IACjC,OAAOlC,MAAM;EACjB;AACJ","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@ import { TextFieldBuilder, ObjectFieldBuilder, type FieldBuilder } from "./Field
|
|
|
3
3
|
import { type IFieldBuilderRegistry } from "./abstractions.js";
|
|
4
4
|
declare class FieldBuilderRegistryImpl implements IFieldBuilderRegistry {
|
|
5
5
|
text(): TextFieldBuilder<z.ZodString>;
|
|
6
|
-
object<TShape extends z.
|
|
6
|
+
object<TShape extends Record<string, z.ZodTypeAny>>(fields: (registry: IFieldBuilderRegistry) => {
|
|
7
7
|
[K in keyof TShape]: FieldBuilder<TShape[K]>;
|
|
8
8
|
}): ObjectFieldBuilder<TShape>;
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createImplementation","TextFieldBuilder","ObjectFieldBuilder","FieldBuilderRegistry","RegistryAbstraction","FieldBuilderRegistryImpl","text","object","fields","abstraction","implementation","dependencies"],"sources":["FieldBuilderRegistry.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { createImplementation } from \"@webiny/di\";\nimport { TextFieldBuilder, ObjectFieldBuilder, type FieldBuilder } from \"./FieldBuilder.js\";\nimport {\n FieldBuilderRegistry as RegistryAbstraction,\n type IFieldBuilderRegistry\n} from \"./abstractions.js\";\n\nclass FieldBuilderRegistryImpl implements IFieldBuilderRegistry {\n text(): TextFieldBuilder<z.ZodString> {\n return new TextFieldBuilder();\n }\n\n object<TShape extends z.
|
|
1
|
+
{"version":3,"names":["createImplementation","TextFieldBuilder","ObjectFieldBuilder","FieldBuilderRegistry","RegistryAbstraction","FieldBuilderRegistryImpl","text","object","fields","abstraction","implementation","dependencies"],"sources":["FieldBuilderRegistry.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { createImplementation } from \"@webiny/di\";\nimport { TextFieldBuilder, ObjectFieldBuilder, type FieldBuilder } from \"./FieldBuilder.js\";\nimport {\n FieldBuilderRegistry as RegistryAbstraction,\n type IFieldBuilderRegistry\n} from \"./abstractions.js\";\n\nclass FieldBuilderRegistryImpl implements IFieldBuilderRegistry {\n text(): TextFieldBuilder<z.ZodString> {\n return new TextFieldBuilder();\n }\n\n object<TShape extends Record<string, z.ZodTypeAny>>(\n fields: (registry: IFieldBuilderRegistry) => {\n [K in keyof TShape]: FieldBuilder<TShape[K]>;\n }\n ): ObjectFieldBuilder<TShape> {\n return new ObjectFieldBuilder(fields, this);\n }\n}\n\nexport const FieldBuilderRegistry = createImplementation({\n abstraction: RegistryAbstraction,\n implementation: FieldBuilderRegistryImpl,\n dependencies: []\n});\n"],"mappings":"AACA,SAASA,oBAAoB,QAAQ,YAAY;AACjD,SAASC,gBAAgB,EAAEC,kBAAkB;AAC7C,SACIC,oBAAoB,IAAIC,mBAAmB;AAI/C,MAAMC,wBAAwB,CAAkC;EAC5DC,IAAIA,CAAA,EAAkC;IAClC,OAAO,IAAIL,gBAAgB,CAAC,CAAC;EACjC;EAEAM,MAAMA,CACFC,MAEC,EACyB;IAC1B,OAAO,IAAIN,kBAAkB,CAACM,MAAM,EAAE,IAAI,CAAC;EAC/C;AACJ;AAEA,OAAO,MAAML,oBAAoB,GAAGH,oBAAoB,CAAC;EACrDS,WAAW,EAAEL,mBAAmB;EAChCM,cAAc,EAAEL,wBAAwB;EACxCM,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -10,6 +10,7 @@ export declare class FieldDefinitionsBuilder<TFields extends z.ZodRawShape = {}>
|
|
|
10
10
|
__fromObject<TShape extends Record<string, FieldBuilder<any>>>(shape: TShape): FieldDefinitionsBuilder<{
|
|
11
11
|
[K in keyof TShape]: ReturnType<TShape[K]["getZodSchema"]>;
|
|
12
12
|
}>;
|
|
13
|
+
private registerField;
|
|
13
14
|
__toZodSchema(): z.ZodObject<TFields>;
|
|
14
15
|
__getFields(): FieldConfig[];
|
|
15
16
|
__getFieldsMap(): Map<string, FieldBuilderConfig>;
|
|
@@ -8,30 +8,28 @@ export class FieldDefinitionsBuilder {
|
|
|
8
8
|
|
|
9
9
|
// Keep the old .field() method for internal use
|
|
10
10
|
field(name, configure) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
config.fieldId = name;
|
|
14
|
-
this.fields.set(name, {
|
|
15
|
-
fieldId: name,
|
|
16
|
-
config,
|
|
17
|
-
zodSchema: fieldBuilder.getZodSchema()
|
|
18
|
-
});
|
|
11
|
+
this.registerField(name, configure(this.registry));
|
|
12
|
+
// @ts-expect-error
|
|
19
13
|
return this;
|
|
20
14
|
}
|
|
21
15
|
|
|
22
16
|
// Internal method to build from object
|
|
23
17
|
__fromObject(shape) {
|
|
24
18
|
for (const [fieldId, fieldBuilder] of Object.entries(shape)) {
|
|
25
|
-
|
|
26
|
-
config.fieldId = fieldId;
|
|
27
|
-
this.fields.set(fieldId, {
|
|
28
|
-
fieldId,
|
|
29
|
-
config,
|
|
30
|
-
zodSchema: fieldBuilder.getZodSchema()
|
|
31
|
-
});
|
|
19
|
+
this.registerField(fieldId, fieldBuilder);
|
|
32
20
|
}
|
|
21
|
+
// @ts-expect-error
|
|
33
22
|
return this;
|
|
34
23
|
}
|
|
24
|
+
registerField(fieldId, fieldBuilder) {
|
|
25
|
+
const config = fieldBuilder.toConfig();
|
|
26
|
+
config.fieldId = fieldId;
|
|
27
|
+
this.fields.set(fieldId, {
|
|
28
|
+
fieldId,
|
|
29
|
+
config,
|
|
30
|
+
zodSchema: fieldBuilder.getZodSchema()
|
|
31
|
+
});
|
|
32
|
+
}
|
|
35
33
|
__toZodSchema() {
|
|
36
34
|
const schemaShape = {};
|
|
37
35
|
for (const [fieldId, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["z","FieldDefinitionsBuilder","fields","Map","constructor","registry","field","name","configure","
|
|
1
|
+
{"version":3,"names":["z","FieldDefinitionsBuilder","fields","Map","constructor","registry","field","name","configure","registerField","__fromObject","shape","fieldId","fieldBuilder","Object","entries","config","toConfig","set","zodSchema","getZodSchema","__toZodSchema","schemaShape","object","__getFields","Array","from","values","map","f","__getFieldsMap","createFieldDefinitions","factory","__type"],"sources":["FieldDefinitionsBuilder.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { FieldBuilder } from \"./FieldBuilder.js\";\nimport type { IFieldBuilderRegistry } from \"./abstractions.js\";\nimport type { FieldConfig, FieldBuilderConfig } from \"./types.js\";\n\n// eslint-disable-next-line\nexport class FieldDefinitionsBuilder<TFields extends z.ZodRawShape = {}> {\n private fields = new Map<string, FieldBuilderConfig>();\n\n constructor(private registry: IFieldBuilderRegistry) {}\n\n // Keep the old .field() method for internal use\n field<K extends string, TZod extends z.ZodTypeAny>(\n name: K,\n configure: (field: IFieldBuilderRegistry) => FieldBuilder<TZod>\n ): FieldDefinitionsBuilder<TFields & Record<K, TZod>> {\n this.registerField(name, configure(this.registry));\n // @ts-expect-error\n return this;\n }\n\n // Internal method to build from object\n __fromObject<TShape extends Record<string, FieldBuilder<any>>>(\n shape: TShape\n ): FieldDefinitionsBuilder<{ [K in keyof TShape]: ReturnType<TShape[K][\"getZodSchema\"]> }> {\n for (const [fieldId, fieldBuilder] of Object.entries(shape)) {\n this.registerField(fieldId, fieldBuilder);\n }\n // @ts-expect-error\n return this;\n }\n\n private registerField(fieldId: string, fieldBuilder: FieldBuilder<any>): void {\n const config = fieldBuilder.toConfig();\n config.fieldId = fieldId;\n this.fields.set(fieldId, { fieldId, config, zodSchema: fieldBuilder.getZodSchema() });\n }\n\n __toZodSchema(): z.ZodObject<TFields> {\n const schemaShape = {} as TFields;\n\n for (const [fieldId, { zodSchema }] of this.fields) {\n schemaShape[fieldId as keyof TFields] = zodSchema as unknown as TFields[keyof TFields];\n }\n\n return z.object(schemaShape);\n }\n\n __getFields(): FieldConfig[] {\n return Array.from(this.fields.values()).map(f => f.config);\n }\n\n __getFieldsMap(): Map<string, FieldBuilderConfig> {\n return new Map(this.fields);\n }\n}\n\n// Updated factory function - now takes an object!\nexport function createFieldDefinitions<TShape extends Record<string, FieldBuilder<any>>>(\n factory: (fields: IFieldBuilderRegistry) => TShape\n): FieldDefinitionsFactory<{ [K in keyof TShape]: ReturnType<TShape[K][\"getZodSchema\"]> }> {\n return {\n __type: \"FieldDefinitionsFactory\" as const,\n factory\n };\n}\n\n// TODO: check the unused generic\n// eslint-disable-next-line\nexport interface FieldDefinitionsFactory<TFields extends z.ZodRawShape> {\n __type: \"FieldDefinitionsFactory\";\n factory: (fields: IFieldBuilderRegistry) => Record<string, FieldBuilder<any>>;\n}\n\nexport type InferFieldSchema<T> =\n T extends FieldDefinitionsFactory<infer TFields> ? z.ZodObject<TFields> : never;\n"],"mappings":"AAAA,SAASA,CAAC,QAAQ,KAAK;AAKvB;AACA,OAAO,MAAMC,uBAAuB,CAAqC;EAC7DC,MAAM,GAAG,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M,CAAC;EAC9D;EAEAc,cAAcA,CAAA,EAAoC;IAC9C,OAAO,IAAI3B,GAAG,CAAC,IAAI,CAACD,MAAM,CAAC;EAC/B;AACJ;;AAEA;AACA,OAAO,SAAS6B,sBAAsBA,CAClCC,OAAkD,EACqC;EACvF,OAAO;IACHC,MAAM,EAAE,yBAAkC;IAC1CD;EACJ,CAAC;AACL;;AAEA;AACA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["z","FieldDefinitionsBuilder","createImplementation","FieldBuilderRegistry","PrivateCmsModelBuilder","BuilderAbstraction","ModelBuilder","PrivateCmsModelBuilderImpl","constructor","fieldBuilderRegistry","create","modelId","fieldDefinitions","builder","fieldShape","factory","fieldDefinitionsBuilder","__fromObject","PrivateCmsModelConfiguration","metadata","modelMethods","extensionFields","Map","withMethods","methods","Object","assign","extendFields","fieldId","fieldBuilder","entries","config","toConfig","zodSchema","getZodSchema","set","build","baseSchema","__toZodSchema","finalSchema","size","extensionsShape","optional","extensionsSchema","object","extend","extensions","modelBuilder","keys","length","ModelClass","allFields","__getFields","type","label","validation","settings","fromEntries","Array","from","map","id","fields","values","f","modelType","Model","name","icon","description","schema","getSchema","data","abstraction","implementation","dependencies"],"sources":["PrivateCmsModelBuilder.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n FieldDefinitionsBuilder,\n type FieldDefinitionsFactory\n} from \"./FieldDefinitionsBuilder.js\";\nimport type { BaseModel } from \"../base/BaseModel.js\";\nimport type { IModelData } from \"../base/abstractions.js\";\nimport type { PrivateCmsModel, CmsModelMetadata, FieldBuilderConfig } from \"./types.js\";\n// Import your existing ModelBuilder\nimport { FieldBuilder } from \"./FieldBuilder.js\";\nimport { createImplementation } from \"@webiny/di\";\nimport {\n FieldBuilderRegistry,\n type IFieldBuilderRegistry,\n PrivateCmsModelBuilder as BuilderAbstraction\n} from \"~/models/cms/abstractions.js\";\nimport { ModelBuilder } from \"~/models/base/ModelBuilder.js\";\n\nexport interface IPrivateCmsModelBuilder {\n create<TModel extends BaseModel<any>, TFields extends z.ZodRawShape = any>(\n modelId: string,\n fieldDefinitions: FieldDefinitionsFactory<TFields>\n ): IPrivateCmsModelConfiguration<TModel>;\n}\n\nexport interface IPrivateCmsModelConfiguration<TModel extends BaseModel<any>> {\n withMethods<TMethods extends object>(\n methods: TMethods & ThisType<TModel & TMethods>\n ): IPrivateCmsModelConfiguration<TModel>;\n extendFields(\n factory: (fields: IFieldBuilderRegistry) => Record<string, FieldBuilder<any>>\n ): IPrivateCmsModelConfiguration<TModel>;\n build(): PrivateCmsModel<TModel>;\n}\n\nclass PrivateCmsModelBuilderImpl implements IPrivateCmsModelBuilder {\n constructor(private fieldBuilderRegistry: IFieldBuilderRegistry) {}\n\n create<TModel extends BaseModel<any>, TFields extends z.ZodRawShape = any>(\n modelId: string,\n fieldDefinitions: FieldDefinitionsFactory<TFields>\n ): IPrivateCmsModelConfiguration<TModel> {\n const builder = new FieldDefinitionsBuilder(this.fieldBuilderRegistry);\n const fieldShape = fieldDefinitions.factory(this.fieldBuilderRegistry);\n const fieldDefinitionsBuilder = builder.__fromObject(fieldShape);\n\n return new PrivateCmsModelConfiguration<TModel>(\n modelId,\n this.fieldBuilderRegistry,\n fieldDefinitionsBuilder\n );\n }\n}\n\nclass PrivateCmsModelConfiguration<TModel extends BaseModel<any>>\n implements IPrivateCmsModelConfiguration<TModel>\n{\n private metadata: CmsModelMetadata = {};\n // eslint-disable-next-line\n private modelMethods: Record<string, Function> = {};\n private extensionFields = new Map<string, FieldBuilderConfig>();\n\n constructor(\n private modelId: string,\n private fieldBuilderRegistry: IFieldBuilderRegistry,\n private fieldDefinitionsBuilder: FieldDefinitionsBuilder\n ) {}\n\n withMethods<TMethods extends object>(\n methods: TMethods & ThisType<TModel & TMethods>\n ): IPrivateCmsModelConfiguration<TModel> {\n Object.assign(this.modelMethods, methods);\n return this as any;\n }\n\n extendFields(\n factory: (fields: IFieldBuilderRegistry) => Record<string, FieldBuilder<any>>\n ): IPrivateCmsModelConfiguration<TModel> {\n // Use the factory to get field shape - same as createFieldDefinitions!\n const fieldShape = factory(this.fieldBuilderRegistry);\n\n // Convert to field configs\n for (const [fieldId, fieldBuilder] of Object.entries(fieldShape)) {\n const config = fieldBuilder.toConfig();\n config.fieldId = fieldId;\n const zodSchema = fieldBuilder.getZodSchema();\n\n this.extensionFields.set(fieldId, {\n fieldId,\n config,\n zodSchema\n });\n }\n\n return this as any;\n }\n\n build(): PrivateCmsModel<TModel> {\n const baseSchema = this.fieldDefinitionsBuilder.__toZodSchema();\n let finalSchema = baseSchema;\n\n if (this.extensionFields.size > 0) {\n const extensionsShape: z.ZodRawShape = {};\n\n for (const [fieldId, { zodSchema }] of this.extensionFields) {\n // Make each extension field optional\n extensionsShape[fieldId] = zodSchema.optional();\n }\n\n const extensionsSchema = z.object(extensionsShape).optional();\n\n finalSchema = baseSchema.extend({\n extensions: extensionsSchema\n }) as any;\n }\n\n let modelBuilder = new ModelBuilder<any>(this.modelId, finalSchema);\n\n if (Object.keys(this.modelMethods).length > 0) {\n modelBuilder = modelBuilder.withMethods(this.modelMethods);\n }\n\n const ModelClass = modelBuilder.build();\n\n const allFields = [\n ...this.fieldDefinitionsBuilder.__getFields(),\n ...(this.extensionFields.size > 0\n ? [\n {\n fieldId: \"extensions\",\n type: \"object\",\n label: \"Extensions\",\n validation: [],\n settings: {},\n zodSchema: z\n .object(\n Object.fromEntries(\n Array.from(this.extensionFields.entries()).map(\n ([id, { zodSchema }]) => [id, zodSchema.optional()]\n )\n )\n )\n .optional(),\n fields: Array.from(this.extensionFields.values()).map(f => f.config)\n }\n ]\n : [])\n ];\n\n return {\n type: \"private\" as const,\n modelType: \"private\" as const,\n Model: ModelClass as any,\n modelId: this.modelId,\n name: this.modelId,\n icon: this.metadata.icon,\n description: this.metadata.description,\n fields: allFields,\n schema: modelBuilder.getSchema() as TModel[\"__schema\"],\n create: (data: IModelData<TModel>) => ModelClass.create(data) as TModel\n };\n }\n}\n\nexport const PrivateCmsModelBuilder = createImplementation({\n abstraction: BuilderAbstraction,\n implementation: PrivateCmsModelBuilderImpl,\n dependencies: [FieldBuilderRegistry]\n});\n"],"mappings":"AAAA,SAASA,CAAC,QAAQ,KAAK;AACvB,SACIC,uBAAuB;;AAM3B;;AAEA,SAASC,oBAAoB,QAAQ,YAAY;AACjD,SACIC,oBAAoB,EAEpBC,sBAAsB,IAAIC,kBAAkB;AAEhD,SAASC,YAAY;AAmBrB,MAAMC,0BAA0B,CAAoC;EAChEC,WAAWA,CAASC,oBAA2C,EAAE;IAAA,KAA7CA,oBAA2C,GAA3CA,oBAA2C;EAAG;EAElEC,MAAMA,CACFC,OAAe,EACfC,gBAAkD,EACb;IACrC,MAAMC,OAAO,GAAG,IAAIZ,uBAAuB,CAAC,IAAI,CAACQ,oBAAoB,CAAC;IACtE,MAAMK,UAAU,GAAGF,gBAAgB,CAACG,OAAO,CAAC,IAAI,CAACN,oBAAoB,CAAC;IACtE,MAAMO,uBAAuB,GAAGH,OAAO,CAACI,YAAY,CAACH,UAAU,CAAC;IAEhE,OAAO,IAAII,4BAA4B,CACnCP,OAAO,EACP,IAAI,CAACF,oBAAoB,EACzBO,uBACJ,CAAC;EACL;AACJ;AAEA,MAAME,4BAA4B,CAElC;EACYC,QAAQ,GAAqB,CAAC,CAAC;EACvC;EACQC,YAAY,GAA6B,CAAC,CAAC;EAC3CC,eAAe,GAAG,IAAIC,GAAG,CAA6B,CAAC;EAE/Dd,WAAWA,CACCG,OAAe,EACfF,oBAA2C,EAC3CO,uBAAgD,EAC1D;IAAA,KAHUL,OAAe,GAAfA,OAAe;IAAA,KACfF,oBAA2C,GAA3CA,oBAA2C;IAAA,KAC3CO,uBAAgD,GAAhDA,uBAAgD;EACzD;EAEHO,WAAWA,CACPC,OAA+C,EACV;IACrCC,MAAM,CAACC,MAAM,CAAC,IAAI,CAACN,YAAY,EAAEI,OAAO,CAAC;IACzC,OAAO,IAAI;EACf;EAEAG,YAAYA,CACRZ,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Q,CAACkD,WAAW;MACtCP,MAAM,EAAEX,SAAS;MACjBmB,MAAM,EAAEvB,YAAY,CAACwB,SAAS,CAAC,CAAuB;MACtD7D,MAAM,EAAG8D,IAAwB,IAAKtB,UAAU,CAACxC,MAAM,CAAC8D,IAAI;IAChE,CAAC;EACL;AACJ;AAEA,OAAO,MAAMpE,sBAAsB,GAAGF,oBAAoB,CAAC;EACvDuE,WAAW,EAAEpE,kBAAkB;EAC/BqE,cAAc,EAAEnE,0BAA0B;EAC1CoE,YAAY,EAAE,CAACxE,oBAAoB;AACvC,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["z","FieldDefinitionsBuilder","createImplementation","FieldBuilderRegistry","PrivateCmsModelBuilder","BuilderAbstraction","ModelBuilder","PrivateCmsModelBuilderImpl","constructor","fieldBuilderRegistry","create","modelId","fieldDefinitions","builder","fieldShape","factory","fieldDefinitionsBuilder","__fromObject","PrivateCmsModelConfiguration","metadata","modelMethods","extensionFields","Map","withMethods","methods","Object","assign","extendFields","fieldId","fieldBuilder","entries","config","toConfig","zodSchema","getZodSchema","set","build","baseSchema","__toZodSchema","finalSchema","size","extensionsShape","optional","extensionsSchema","object","extend","extensions","modelBuilder","keys","length","ModelClass","allFields","__getFields","type","label","validation","settings","fromEntries","Array","from","map","id","fields","values","f","modelType","Model","name","icon","description","schema","getSchema","data","abstraction","implementation","dependencies"],"sources":["PrivateCmsModelBuilder.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n FieldDefinitionsBuilder,\n type FieldDefinitionsFactory\n} from \"./FieldDefinitionsBuilder.js\";\nimport type { BaseModel } from \"../base/BaseModel.js\";\nimport type { IModelData } from \"../base/abstractions.js\";\nimport type { PrivateCmsModel, CmsModelMetadata, FieldBuilderConfig } from \"./types.js\";\n// Import your existing ModelBuilder\nimport { FieldBuilder } from \"./FieldBuilder.js\";\nimport { createImplementation } from \"@webiny/di\";\nimport {\n FieldBuilderRegistry,\n type IFieldBuilderRegistry,\n PrivateCmsModelBuilder as BuilderAbstraction\n} from \"~/models/cms/abstractions.js\";\nimport { ModelBuilder } from \"~/models/base/ModelBuilder.js\";\n\nexport interface IPrivateCmsModelBuilder {\n create<TModel extends BaseModel<any>, TFields extends z.ZodRawShape = any>(\n modelId: string,\n fieldDefinitions: FieldDefinitionsFactory<TFields>\n ): IPrivateCmsModelConfiguration<TModel>;\n}\n\nexport interface IPrivateCmsModelConfiguration<TModel extends BaseModel<any>> {\n withMethods<TMethods extends object>(\n methods: TMethods & ThisType<TModel & TMethods>\n ): IPrivateCmsModelConfiguration<TModel>;\n extendFields(\n factory: (fields: IFieldBuilderRegistry) => Record<string, FieldBuilder<any>>\n ): IPrivateCmsModelConfiguration<TModel>;\n build(): PrivateCmsModel<TModel>;\n}\n\nclass PrivateCmsModelBuilderImpl implements IPrivateCmsModelBuilder {\n constructor(private fieldBuilderRegistry: IFieldBuilderRegistry) {}\n\n create<TModel extends BaseModel<any>, TFields extends z.ZodRawShape = any>(\n modelId: string,\n fieldDefinitions: FieldDefinitionsFactory<TFields>\n ): IPrivateCmsModelConfiguration<TModel> {\n const builder = new FieldDefinitionsBuilder(this.fieldBuilderRegistry);\n const fieldShape = fieldDefinitions.factory(this.fieldBuilderRegistry);\n const fieldDefinitionsBuilder = builder.__fromObject(fieldShape);\n\n return new PrivateCmsModelConfiguration<TModel>(\n modelId,\n this.fieldBuilderRegistry,\n fieldDefinitionsBuilder\n );\n }\n}\n\nclass PrivateCmsModelConfiguration<TModel extends BaseModel<any>>\n implements IPrivateCmsModelConfiguration<TModel>\n{\n private metadata: CmsModelMetadata = {};\n // eslint-disable-next-line\n private modelMethods: Record<string, Function> = {};\n private extensionFields = new Map<string, FieldBuilderConfig>();\n\n constructor(\n private modelId: string,\n private fieldBuilderRegistry: IFieldBuilderRegistry,\n private fieldDefinitionsBuilder: FieldDefinitionsBuilder\n ) {}\n\n withMethods<TMethods extends object>(\n methods: TMethods & ThisType<TModel & TMethods>\n ): IPrivateCmsModelConfiguration<TModel> {\n Object.assign(this.modelMethods, methods);\n return this as any;\n }\n\n extendFields(\n factory: (fields: IFieldBuilderRegistry) => Record<string, FieldBuilder<any>>\n ): IPrivateCmsModelConfiguration<TModel> {\n // Use the factory to get field shape - same as createFieldDefinitions!\n const fieldShape = factory(this.fieldBuilderRegistry);\n\n // Convert to field configs\n for (const [fieldId, fieldBuilder] of Object.entries(fieldShape)) {\n const config = fieldBuilder.toConfig();\n config.fieldId = fieldId;\n const zodSchema = fieldBuilder.getZodSchema();\n\n this.extensionFields.set(fieldId, {\n fieldId,\n config,\n zodSchema\n });\n }\n\n return this as any;\n }\n\n build(): PrivateCmsModel<TModel> {\n const baseSchema = this.fieldDefinitionsBuilder.__toZodSchema();\n let finalSchema = baseSchema;\n\n if (this.extensionFields.size > 0) {\n const extensionsShape: Record<string, z.ZodTypeAny> = {};\n\n for (const [fieldId, { zodSchema }] of this.extensionFields) {\n // Make each extension field optional\n extensionsShape[fieldId] = zodSchema.optional();\n }\n\n const extensionsSchema = z.object(extensionsShape).optional();\n\n finalSchema = baseSchema.extend({\n extensions: extensionsSchema\n }) as any;\n }\n\n let modelBuilder = new ModelBuilder<any>(this.modelId, finalSchema);\n\n if (Object.keys(this.modelMethods).length > 0) {\n modelBuilder = modelBuilder.withMethods(this.modelMethods);\n }\n\n const ModelClass = modelBuilder.build();\n\n const allFields = [\n ...this.fieldDefinitionsBuilder.__getFields(),\n ...(this.extensionFields.size > 0\n ? [\n {\n fieldId: \"extensions\",\n type: \"object\",\n label: \"Extensions\",\n validation: [],\n settings: {},\n zodSchema: z\n .object(\n Object.fromEntries(\n Array.from(this.extensionFields.entries()).map(\n ([id, { zodSchema }]) => [id, zodSchema.optional()]\n )\n )\n )\n .optional(),\n fields: Array.from(this.extensionFields.values()).map(f => f.config)\n }\n ]\n : [])\n ];\n\n return {\n type: \"private\" as const,\n modelType: \"private\" as const,\n Model: ModelClass as any,\n modelId: this.modelId,\n name: this.modelId,\n icon: this.metadata.icon,\n description: this.metadata.description,\n fields: allFields,\n schema: modelBuilder.getSchema() as TModel[\"__schema\"],\n create: (data: IModelData<TModel>) => ModelClass.create(data) as TModel\n };\n }\n}\n\nexport const PrivateCmsModelBuilder = createImplementation({\n abstraction: BuilderAbstraction,\n implementation: PrivateCmsModelBuilderImpl,\n dependencies: [FieldBuilderRegistry]\n});\n"],"mappings":"AAAA,SAASA,CAAC,QAAQ,KAAK;AACvB,SACIC,uBAAuB;;AAM3B;;AAEA,SAASC,oBAAoB,QAAQ,YAAY;AACjD,SACIC,oBAAoB,EAEpBC,sBAAsB,IAAIC,kBAAkB;AAEhD,SAASC,YAAY;AAmBrB,MAAMC,0BAA0B,CAAoC;EAChEC,WAAWA,CAASC,oBAA2C,EAAE;IAAA,KAA7CA,oBAA2C,GAA3CA,oBAA2C;EAAG;EAElEC,MAAMA,CACFC,OAAe,EACfC,gBAAkD,EACb;IACrC,MAAMC,OAAO,GAAG,IAAIZ,uBAAuB,CAAC,IAAI,CAACQ,oBAAoB,CAAC;IACtE,MAAMK,UAAU,GAAGF,gBAAgB,CAACG,OAAO,CAAC,IAAI,CAACN,oBAAoB,CAAC;IACtE,MAAMO,uBAAuB,GAAGH,OAAO,CAACI,YAAY,CAACH,UAAU,CAAC;IAEhE,OAAO,IAAII,4BAA4B,CACnCP,OAAO,EACP,IAAI,CAACF,oBAAoB,EACzBO,uBACJ,CAAC;EACL;AACJ;AAEA,MAAME,4BAA4B,CAElC;EACYC,QAAQ,GAAqB,CAAC,CAAC;EACvC;EACQC,YAAY,GAA6B,CAAC,CAAC;EAC3CC,eAAe,GAAG,IAAIC,GAAG,CAA6B,CAAC;EAE/Dd,WAAWA,CACCG,OAAe,EACfF,oBAA2C,EAC3CO,uBAAgD,EAC1D;IAAA,KAHUL,OAAe,GAAfA,OAAe;IAAA,KACfF,oBAA2C,GAA3CA,oBAA2C;IAAA,KAC3CO,uBAAgD,GAAhDA,uBAAgD;EACzD;EAEHO,WAAWA,CACPC,OAA+C,EACV;IACrCC,MA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CAACxD,OAAO;MAClByD,IAAI,EAAE,IAAI,CAACjD,QAAQ,CAACiD,IAAI;MACxBC,WAAW,EAAE,IAAI,CAAClD,QAAQ,CAACkD,WAAW;MACtCP,MAAM,EAAEX,SAAS;MACjBmB,MAAM,EAAEvB,YAAY,CAACwB,SAAS,CAAC,CAAuB;MACtD7D,MAAM,EAAG8D,IAAwB,IAAKtB,UAAU,CAACxC,MAAM,CAAC8D,IAAI;IAChE,CAAC;EACL;AACJ;AAEA,OAAO,MAAMpE,sBAAsB,GAAGF,oBAAoB,CAAC;EACvDuE,WAAW,EAAEpE,kBAAkB;EAC/BqE,cAAc,EAAEnE,0BAA0B;EAC1CoE,YAAY,EAAE,CAACxE,oBAAoB;AACvC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -9,7 +9,7 @@ import type { BaseModel, IModelData } from "../../models/base/BaseModel.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export interface IFieldBuilderRegistry {
|
|
11
11
|
text(): TextFieldBuilder<z.ZodString>;
|
|
12
|
-
object<TShape extends z.
|
|
12
|
+
object<TShape extends Record<string, z.ZodTypeAny>>(fields: (registry: IFieldBuilderRegistry) => {
|
|
13
13
|
[K in keyof TShape]: FieldBuilder<TShape[K]>;
|
|
14
14
|
}): ObjectFieldBuilder<TShape>;
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Abstraction","FieldBuilderRegistry","PrivateCmsModelBuilder"],"sources":["abstractions.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Abstraction } from \"@webiny/di\";\nimport type { IPrivateCmsModelConfiguration } from \"./PrivateCmsModelBuilder.js\";\nimport type { FieldDefinitionsFactory } from \"./FieldDefinitionsBuilder.js\";\nimport { type TextFieldBuilder, type ObjectFieldBuilder, FieldBuilder } from \"./FieldBuilder.js\";\nimport type { BaseModel, IModelData } from \"~/models/base/BaseModel.js\";\n\n/**\n * Field Builder Registry - provides field builders\n */\nexport interface IFieldBuilderRegistry {\n text(): TextFieldBuilder<z.ZodString>;\n object<TShape extends z.
|
|
1
|
+
{"version":3,"names":["Abstraction","FieldBuilderRegistry","PrivateCmsModelBuilder"],"sources":["abstractions.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Abstraction } from \"@webiny/di\";\nimport type { IPrivateCmsModelConfiguration } from \"./PrivateCmsModelBuilder.js\";\nimport type { FieldDefinitionsFactory } from \"./FieldDefinitionsBuilder.js\";\nimport { type TextFieldBuilder, type ObjectFieldBuilder, FieldBuilder } from \"./FieldBuilder.js\";\nimport type { BaseModel, IModelData } from \"~/models/base/BaseModel.js\";\n\n/**\n * Field Builder Registry - provides field builders\n */\nexport interface IFieldBuilderRegistry {\n text(): TextFieldBuilder<z.ZodString>;\n object<TShape extends Record<string, z.ZodTypeAny>>(\n fields: (registry: IFieldBuilderRegistry) => {\n [K in keyof TShape]: FieldBuilder<TShape[K]>;\n }\n ): ObjectFieldBuilder<TShape>;\n}\n\nexport const FieldBuilderRegistry = new Abstraction<IFieldBuilderRegistry>(\"FieldBuilderRegistry\");\n\n/**\n * Private CMS Model Builder - builds CMS model configurations\n */\nexport interface IPrivateCmsModelBuilder {\n create<TModel extends BaseModel<any>>(\n modelId: string,\n fieldDefinitions: FieldDefinitionsFactory<any>\n ): IPrivateCmsModelConfiguration<TModel>;\n}\n\nexport const PrivateCmsModelBuilder = new Abstraction<IPrivateCmsModelBuilder>(\n \"PrivateCmsModelBuilder\"\n);\n\nexport namespace PrivateCmsModelBuilder {\n export type Interface = IPrivateCmsModelBuilder;\n}\n\n/**\n * CMS Model Builder - builds the model configuration for a specific model\n */\nexport interface ICmsModelBuilder<TModel extends BaseModel<any>> {\n buildCmsModel(): Promise<IPrivateCmsModelConfiguration<TModel>>;\n}\n\n/**\n * CMS Model Factory - creates model instances\n */\nexport interface ICmsModelFactory<TModel extends BaseModel<any>> {\n create(data: IModelData<TModel>): Promise<TModel>;\n}\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,YAAY;;AAMxC;AACA;AACA;;AAUA,OAAO,MAAMC,oBAAoB,GAAG,IAAID,WAAW,CAAwB,sBAAsB,CAAC;;AAElG;AACA;AACA;;AAQA,OAAO,MAAME,sBAAsB,GAAG,IAAIF,WAAW,CACjD,wBACJ,CAAC;;AAMD;AACA;AACA;;AAKA;AACA;AACA","ignoreList":[]}
|
|
@@ -194,7 +194,7 @@ import type { FieldBuilder } from "./FieldBuilder.js";
|
|
|
194
194
|
export interface IFieldBuilderRegistry {
|
|
195
195
|
text(): ITextFieldBuilder;
|
|
196
196
|
// object is special - needs registry reference
|
|
197
|
-
object<TShape extends z.
|
|
197
|
+
object<TShape extends Record<string, z.ZodTypeAny>>(
|
|
198
198
|
fields: (registry: IFieldBuilderRegistry) => { [K in keyof TShape]: FieldBuilder<TShape[K]> }
|
|
199
199
|
): FieldBuilder<z.ZodObject<TShape>>;
|
|
200
200
|
}
|
|
@@ -5,17 +5,7 @@ export declare const PageSchema: import("zod").ZodObject<{
|
|
|
5
5
|
title: import("zod").ZodString;
|
|
6
6
|
content: import("zod").ZodString;
|
|
7
7
|
publishedAt: import("zod").ZodNullable<import("zod").ZodDate>;
|
|
8
|
-
},
|
|
9
|
-
id: string;
|
|
10
|
-
title: string;
|
|
11
|
-
publishedAt: Date | null;
|
|
12
|
-
content: string;
|
|
13
|
-
}, {
|
|
14
|
-
id: string;
|
|
15
|
-
title: string;
|
|
16
|
-
publishedAt: Date | null;
|
|
17
|
-
content: string;
|
|
18
|
-
}>;
|
|
8
|
+
}, import("zod/v4/core").$strip>;
|
|
19
9
|
export interface IPageExtensions {
|
|
20
10
|
}
|
|
21
11
|
export interface IPage extends IModel<typeof PageSchema> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-core",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.1.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -57,41 +57,41 @@
|
|
|
57
57
|
},
|
|
58
58
|
"license": "MIT",
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@webiny/api": "6.0.
|
|
60
|
+
"@webiny/api": "6.1.0-beta.1",
|
|
61
61
|
"@webiny/di": "0.2.3",
|
|
62
|
-
"@webiny/error": "6.0.
|
|
63
|
-
"@webiny/feature": "6.0.
|
|
64
|
-
"@webiny/feature-flags": "6.0.
|
|
65
|
-
"@webiny/handler": "6.0.
|
|
66
|
-
"@webiny/handler-db": "6.0.
|
|
67
|
-
"@webiny/handler-graphql": "6.0.
|
|
68
|
-
"@webiny/plugins": "6.0.
|
|
69
|
-
"@webiny/utils": "6.0.
|
|
70
|
-
"@webiny/wcp": "6.0.
|
|
62
|
+
"@webiny/error": "6.1.0-beta.1",
|
|
63
|
+
"@webiny/feature": "6.1.0-beta.1",
|
|
64
|
+
"@webiny/feature-flags": "6.1.0-beta.1",
|
|
65
|
+
"@webiny/handler": "6.1.0-beta.1",
|
|
66
|
+
"@webiny/handler-db": "6.1.0-beta.1",
|
|
67
|
+
"@webiny/handler-graphql": "6.1.0-beta.1",
|
|
68
|
+
"@webiny/plugins": "6.1.0-beta.1",
|
|
69
|
+
"@webiny/utils": "6.1.0-beta.1",
|
|
70
|
+
"@webiny/wcp": "6.1.0-beta.1",
|
|
71
71
|
"dataloader": "2.2.3",
|
|
72
|
-
"jose": "
|
|
72
|
+
"jose": "6.2.2",
|
|
73
73
|
"jsonwebtoken": "9.0.3",
|
|
74
74
|
"lodash": "4.17.23",
|
|
75
75
|
"minimatch": "10.2.4",
|
|
76
|
-
"pino": "
|
|
76
|
+
"pino": "10.3.1",
|
|
77
77
|
"pino-lambda": "4.4.1",
|
|
78
|
-
"zod": "3.
|
|
78
|
+
"zod": "4.3.6"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@types/jsonwebtoken": "9.0.10",
|
|
82
82
|
"@types/md5": "2.3.6",
|
|
83
|
-
"@webiny/build-tools": "6.0.
|
|
84
|
-
"@webiny/db-dynamodb": "6.0.
|
|
85
|
-
"@webiny/handler-aws": "6.0.
|
|
86
|
-
"@webiny/project-utils": "6.0.
|
|
83
|
+
"@webiny/build-tools": "6.1.0-beta.1",
|
|
84
|
+
"@webiny/db-dynamodb": "6.1.0-beta.1",
|
|
85
|
+
"@webiny/handler-aws": "6.1.0-beta.1",
|
|
86
|
+
"@webiny/project-utils": "6.1.0-beta.1",
|
|
87
87
|
"jest-dynalite": "3.6.1",
|
|
88
88
|
"rimraf": "6.1.3",
|
|
89
89
|
"typescript": "5.9.3",
|
|
90
|
-
"vitest": "4.
|
|
90
|
+
"vitest": "4.1.2"
|
|
91
91
|
},
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public",
|
|
94
94
|
"directory": "dist"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "3c1293ba17a14f239fb1cbf5d80cd66846849309"
|
|
97
97
|
}
|