@lenne.tech/nest-server 12.1.1 → 12.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/rules/architecture.md +1 -0
- package/.claude/rules/better-auth.md +31 -4
- package/.claude/rules/configurable-features.md +8 -6
- package/.claude/rules/package-management.md +29 -2
- package/.claude/rules/persistence.md +27 -1
- package/.claude/rules/testing.md +80 -15
- package/.claude/rules/versioning.md +13 -2
- package/CLAUDE.md +7 -1
- package/FRAMEWORK-API.md +20 -4
- package/README.md +20 -2
- package/dist/config.env.js +2 -2
- package/dist/config.env.js.map +1 -1
- package/dist/core/common/helpers/graphql-ws-connection.helper.d.ts +4 -0
- package/dist/core/common/helpers/graphql-ws-connection.helper.js +17 -3
- package/dist/core/common/helpers/graphql-ws-connection.helper.js.map +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +49 -0
- package/dist/core/common/interfaces/service-options.interface.d.ts +3 -0
- package/dist/core/common/persistence/core-persistence.module.js +12 -2
- package/dist/core/common/persistence/core-persistence.module.js.map +1 -1
- package/dist/core/common/persistence/data-source.runtime.js +4 -2
- package/dist/core/common/persistence/data-source.runtime.js.map +1 -1
- package/dist/core/common/persistence/data-store.interface.d.ts +24 -9
- package/dist/core/common/persistence/id-format.d.ts +2 -0
- package/dist/core/common/persistence/id-format.js +14 -0
- package/dist/core/common/persistence/id-format.js.map +1 -1
- package/dist/core/common/persistence/model-descriptor.interface.d.ts +6 -0
- package/dist/core/common/persistence/model-metadata.registry.d.ts +2 -1
- package/dist/core/common/persistence/model-metadata.registry.js +20 -2
- package/dist/core/common/persistence/model-metadata.registry.js.map +1 -1
- package/dist/core/common/persistence/mongo/sync-schema.plugin.d.ts +18 -0
- package/dist/core/common/persistence/mongo/sync-schema.plugin.js +368 -0
- package/dist/core/common/persistence/mongo/sync-schema.plugin.js.map +1 -0
- package/dist/core/common/persistence/mongoose-data-store.d.ts +19 -9
- package/dist/core/common/persistence/mongoose-data-store.js +107 -31
- package/dist/core/common/persistence/mongoose-data-store.js.map +1 -1
- package/dist/core/common/persistence/persisted-model.decorator.d.ts +3 -0
- package/dist/core/common/persistence/persisted-model.decorator.js +9 -0
- package/dist/core/common/persistence/persisted-model.decorator.js.map +1 -1
- package/dist/core/common/persistence/policies/sync.policy.d.ts +17 -0
- package/dist/core/common/persistence/policies/sync.policy.js +77 -0
- package/dist/core/common/persistence/policies/sync.policy.js.map +1 -0
- package/dist/core/common/persistence/sql/mysql/mysql-data-store.d.ts +12 -8
- package/dist/core/common/persistence/sql/mysql/mysql-data-store.js +82 -29
- package/dist/core/common/persistence/sql/mysql/mysql-data-store.js.map +1 -1
- package/dist/core/common/persistence/sql/mysql/mysql-schema.compiler.d.ts +10 -0
- package/dist/core/common/persistence/sql/mysql/mysql-schema.compiler.js +61 -4
- package/dist/core/common/persistence/sql/mysql/mysql-schema.compiler.js.map +1 -1
- package/dist/core/common/persistence/sql/mysql/mysql-schema.migrator.js +101 -4
- package/dist/core/common/persistence/sql/mysql/mysql-schema.migrator.js.map +1 -1
- package/dist/core/common/persistence/sql/postgres/postgres-schema.compiler.d.ts +10 -0
- package/dist/core/common/persistence/sql/postgres/postgres-schema.compiler.js +41 -2
- package/dist/core/common/persistence/sql/postgres/postgres-schema.compiler.js.map +1 -1
- package/dist/core/common/persistence/sql/postgres/postgres-schema.migrator.js +98 -10
- package/dist/core/common/persistence/sql/postgres/postgres-schema.migrator.js.map +1 -1
- package/dist/core/common/persistence/sql/sql-data-store.d.ts +38 -14
- package/dist/core/common/persistence/sql/sql-data-store.js +212 -38
- package/dist/core/common/persistence/sql/sql-data-store.js.map +1 -1
- package/dist/core/common/persistence/sql/sql-errors.d.ts +2 -1
- package/dist/core/common/persistence/sql/sql-errors.js +3 -1
- package/dist/core/common/persistence/sql/sql-errors.js.map +1 -1
- package/dist/core/common/persistence/sync-access.registry.d.ts +17 -0
- package/dist/core/common/persistence/sync-access.registry.js +8 -0
- package/dist/core/common/persistence/sync-access.registry.js.map +1 -0
- package/dist/core/common/persistence/sync-model.d.ts +29 -0
- package/dist/core/common/persistence/sync-model.js +138 -0
- package/dist/core/common/persistence/sync-model.js.map +1 -0
- package/dist/core/common/services/crud.service.d.ts +13 -1
- package/dist/core/common/services/crud.service.js +174 -16
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/core/modules/ai/core-ai-mcp.controller.d.ts +3 -0
- package/dist/core/modules/ai/core-ai-mcp.controller.js +29 -0
- package/dist/core/modules/ai/core-ai-mcp.controller.js.map +1 -1
- package/dist/core/modules/ai/core-ai.constants.d.ts +2 -0
- package/dist/core/modules/ai/core-ai.constants.js +2 -0
- package/dist/core/modules/ai/core-ai.constants.js.map +1 -1
- package/dist/core/modules/ai/core-ai.controller.d.ts +6 -0
- package/dist/core/modules/ai/core-ai.controller.js +31 -1
- package/dist/core/modules/ai/core-ai.controller.js.map +1 -1
- package/dist/core/modules/ai/core-ai.module.d.ts +2 -0
- package/dist/core/modules/ai/core-ai.module.js +8 -1
- package/dist/core/modules/ai/core-ai.module.js.map +1 -1
- package/dist/core/modules/ai/core-ai.resolver.d.ts +6 -0
- package/dist/core/modules/ai/core-ai.resolver.js +32 -0
- package/dist/core/modules/ai/core-ai.resolver.js.map +1 -1
- package/dist/core/modules/ai/helpers/ai-mcp-oauth-consent.helper.d.ts +65 -1
- package/dist/core/modules/ai/helpers/ai-mcp-oauth-consent.helper.js +6 -3
- package/dist/core/modules/ai/helpers/ai-mcp-oauth-consent.helper.js.map +1 -1
- package/dist/core/modules/ai/helpers/ai-mcp-oauth.helper.js +48 -1
- package/dist/core/modules/ai/helpers/ai-mcp-oauth.helper.js.map +1 -1
- package/dist/core/modules/ai/helpers/ai-tool-authorization.helper.d.ts +9 -0
- package/dist/core/modules/ai/helpers/ai-tool-authorization.helper.js +54 -0
- package/dist/core/modules/ai/helpers/ai-tool-authorization.helper.js.map +1 -0
- package/dist/core/modules/ai/index.d.ts +7 -0
- package/dist/core/modules/ai/index.js +6 -0
- package/dist/core/modules/ai/index.js.map +1 -1
- package/dist/core/modules/ai/inputs/core-ai-settings.input.d.ts +3 -0
- package/dist/core/modules/ai/inputs/core-ai-settings.input.js +31 -0
- package/dist/core/modules/ai/inputs/core-ai-settings.input.js.map +1 -0
- package/dist/core/modules/ai/interfaces/ai-tool.interface.d.ts +2 -0
- package/dist/core/modules/ai/models/core-ai-settings.model.d.ts +4 -0
- package/dist/core/modules/ai/models/core-ai-settings.model.js +30 -0
- package/dist/core/modules/ai/models/core-ai-settings.model.js.map +1 -0
- package/dist/core/modules/ai/models/core-ai-user-setting.model.d.ts +8 -0
- package/dist/core/modules/ai/models/core-ai-user-setting.model.js +45 -0
- package/dist/core/modules/ai/models/core-ai-user-setting.model.js.map +1 -0
- package/dist/core/modules/ai/services/core-ai-conversation.service.d.ts +4 -1
- package/dist/core/modules/ai/services/core-ai-conversation.service.js +16 -4
- package/dist/core/modules/ai/services/core-ai-conversation.service.js.map +1 -1
- package/dist/core/modules/ai/services/core-ai-mcp-oauth.service.js +6 -6
- package/dist/core/modules/ai/services/core-ai-mcp-oauth.service.js.map +1 -1
- package/dist/core/modules/ai/services/core-ai-mcp.service.d.ts +27 -2
- package/dist/core/modules/ai/services/core-ai-mcp.service.js +118 -11
- package/dist/core/modules/ai/services/core-ai-mcp.service.js.map +1 -1
- package/dist/core/modules/ai/services/core-ai-prompt-builder.service.js +9 -6
- package/dist/core/modules/ai/services/core-ai-prompt-builder.service.js.map +1 -1
- package/dist/core/modules/ai/services/core-ai-user-setting.service.d.ts +17 -0
- package/dist/core/modules/ai/services/core-ai-user-setting.service.js +72 -0
- package/dist/core/modules/ai/services/core-ai-user-setting.service.js.map +1 -0
- package/dist/core/modules/ai/services/core-ai.service.d.ts +8 -3
- package/dist/core/modules/ai/services/core-ai.service.js +68 -29
- package/dist/core/modules/ai/services/core-ai.service.js.map +1 -1
- package/dist/core/modules/better-auth/better-auth.config.js +3 -1
- package/dist/core/modules/better-auth/better-auth.config.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js +2 -2
- package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-path-guard.middleware.d.ts +8 -0
- package/dist/core/modules/better-auth/core-better-auth-path-guard.middleware.js +64 -0
- package/dist/core/modules/better-auth/core-better-auth-path-guard.middleware.js.map +1 -0
- package/dist/core/modules/better-auth/core-better-auth-rate-limit.middleware.js +2 -1
- package/dist/core/modules/better-auth/core-better-auth-rate-limit.middleware.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-rate-limiter.service.d.ts +1 -1
- package/dist/core/modules/better-auth/core-better-auth-rate-limiter.service.js +5 -3
- package/dist/core/modules/better-auth/core-better-auth-rate-limiter.service.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth.module.js +2 -0
- package/dist/core/modules/better-auth/core-better-auth.module.js.map +1 -1
- package/dist/core/modules/better-auth/index.d.ts +1 -0
- package/dist/core/modules/better-auth/index.js +1 -0
- package/dist/core/modules/better-auth/index.js.map +1 -1
- package/dist/core/modules/error-code/error-codes.d.ts +72 -0
- package/dist/core/modules/error-code/error-codes.js +64 -0
- package/dist/core/modules/error-code/error-codes.js.map +1 -1
- package/dist/core/modules/migrate/sql-migration.helper.d.ts +15 -1
- package/dist/core/modules/migrate/sql-migration.helper.js +90 -5
- package/dist/core/modules/migrate/sql-migration.helper.js.map +1 -1
- package/dist/core/modules/sync/core-sync-base.controller.d.ts +7 -0
- package/dist/core/modules/sync/core-sync-base.controller.js +44 -0
- package/dist/core/modules/sync/core-sync-base.controller.js.map +1 -0
- package/dist/core/modules/sync/core-sync-cursor.d.ts +19 -0
- package/dist/core/modules/sync/core-sync-cursor.js +77 -0
- package/dist/core/modules/sync/core-sync-cursor.js.map +1 -0
- package/dist/core/modules/sync/core-sync-hints.controller.d.ts +4 -0
- package/dist/core/modules/sync/core-sync-hints.controller.js +55 -0
- package/dist/core/modules/sync/core-sync-hints.controller.js.map +1 -0
- package/dist/core/modules/sync/core-sync-hints.service.d.ts +28 -0
- package/dist/core/modules/sync/core-sync-hints.service.js +155 -0
- package/dist/core/modules/sync/core-sync-hints.service.js.map +1 -0
- package/dist/core/modules/sync/core-sync-infrastructure.models.d.ts +2 -0
- package/dist/core/modules/sync/core-sync-infrastructure.models.js +17 -0
- package/dist/core/modules/sync/core-sync-infrastructure.models.js.map +1 -0
- package/dist/core/modules/sync/core-sync-mutation.store.d.ts +43 -0
- package/dist/core/modules/sync/core-sync-mutation.store.js +88 -0
- package/dist/core/modules/sync/core-sync-mutation.store.js.map +1 -0
- package/dist/core/modules/sync/core-sync-state.store.d.ts +18 -0
- package/dist/core/modules/sync/core-sync-state.store.js +64 -0
- package/dist/core/modules/sync/core-sync-state.store.js.map +1 -0
- package/dist/core/modules/sync/core-sync.constants.d.ts +28 -0
- package/dist/core/modules/sync/core-sync.constants.js +23 -0
- package/dist/core/modules/sync/core-sync.constants.js.map +1 -0
- package/dist/core/modules/sync/core-sync.controller.d.ts +8 -0
- package/dist/core/modules/sync/core-sync.controller.js +79 -0
- package/dist/core/modules/sync/core-sync.controller.js.map +1 -0
- package/dist/core/modules/sync/core-sync.decorators.d.ts +12 -0
- package/dist/core/modules/sync/core-sync.decorators.js +28 -0
- package/dist/core/modules/sync/core-sync.decorators.js.map +1 -0
- package/dist/core/modules/sync/core-sync.module.d.ts +16 -0
- package/dist/core/modules/sync/core-sync.module.js +50 -0
- package/dist/core/modules/sync/core-sync.module.js.map +1 -0
- package/dist/core/modules/sync/core-sync.resolver.d.ts +9 -0
- package/dist/core/modules/sync/core-sync.resolver.js +46 -0
- package/dist/core/modules/sync/core-sync.resolver.js.map +1 -0
- package/dist/core/modules/sync/core-sync.service.d.ts +143 -0
- package/dist/core/modules/sync/core-sync.service.js +1237 -0
- package/dist/core/modules/sync/core-sync.service.js.map +1 -0
- package/dist/core/modules/sync/interfaces/core-sync.interfaces.d.ts +56 -0
- package/dist/core/modules/sync/interfaces/core-sync.interfaces.js +2 -0
- package/dist/core/modules/sync/interfaces/core-sync.interfaces.js.map +1 -0
- package/dist/core/modules/sync/models/core-sync-hint.model.d.ts +4 -0
- package/dist/core/modules/sync/models/core-sync-hint.model.js +30 -0
- package/dist/core/modules/sync/models/core-sync-hint.model.js.map +1 -0
- package/dist/core/modules/tenant/core-tenant.guard.js +14 -0
- package/dist/core/modules/tenant/core-tenant.guard.js.map +1 -1
- package/dist/core/modules/tenant/core-tenant.service.d.ts +21 -1
- package/dist/core/modules/tenant/core-tenant.service.js +153 -1
- package/dist/core/modules/tenant/core-tenant.service.js.map +1 -1
- package/dist/core.module.js +14 -0
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/dist/server/modules/error-code/error-codes.d.ts +8 -0
- package/dist/server/modules/sync-note/inputs/sync-note-create.input.d.ts +4 -0
- package/dist/server/modules/sync-note/inputs/sync-note-create.input.js +27 -0
- package/dist/server/modules/sync-note/inputs/sync-note-create.input.js.map +1 -0
- package/dist/server/modules/sync-note/inputs/sync-note.input.d.ts +6 -0
- package/dist/server/modules/sync-note/inputs/sync-note.input.js +37 -0
- package/dist/server/modules/sync-note/inputs/sync-note.input.js.map +1 -0
- package/dist/server/modules/sync-note/sync-note.model.d.ts +10 -0
- package/dist/server/modules/sync-note/sync-note.model.js +73 -0
- package/dist/server/modules/sync-note/sync-note.model.js.map +1 -0
- package/dist/server/modules/sync-note/sync-note.module.d.ts +2 -0
- package/dist/server/modules/sync-note/sync-note.module.js +21 -0
- package/dist/server/modules/sync-note/sync-note.module.js.map +1 -0
- package/dist/server/modules/sync-note/sync-note.service.d.ts +10 -0
- package/dist/server/modules/sync-note/sync-note.service.js +35 -0
- package/dist/server/modules/sync-note/sync-note.service.js.map +1 -0
- package/dist/test/test.helper.d.ts +1 -0
- package/dist/test/test.helper.js +9 -2
- package/dist/test/test.helper.js.map +1 -1
- package/docs/REQUEST-LIFECYCLE.md +4 -2
- package/docs/error-codes.md +14 -0
- package/docs/offline-sync-protocol.md +111 -68
- package/docs/security-overrides.md +14 -0
- package/migration-guides/12.0.x-to-12.1.x.md +0 -1
- package/migration-guides/12.1.x-to-12.2.x.md +154 -0
- package/migration-guides/12.2.x-to-12.3.x.md +440 -0
- package/package.json +23 -21
- package/src/config.env.ts +6 -2
- package/src/core/common/helpers/graphql-ws-connection.helper.ts +32 -4
- package/src/core/common/interfaces/server-options.interface.ts +229 -8
- package/src/core/common/interfaces/service-options.interface.ts +15 -0
- package/src/core/common/persistence/core-persistence.module.ts +21 -2
- package/src/core/common/persistence/data-source.runtime.ts +5 -2
- package/src/core/common/persistence/data-store.interface.ts +65 -12
- package/src/core/common/persistence/id-format.ts +26 -0
- package/src/core/common/persistence/model-descriptor.interface.ts +12 -0
- package/src/core/common/persistence/model-metadata.registry.ts +31 -2
- package/src/core/common/persistence/mongo/sync-schema.plugin.ts +508 -0
- package/src/core/common/persistence/mongoose-data-store.ts +171 -35
- package/src/core/common/persistence/persisted-model.decorator.ts +26 -0
- package/src/core/common/persistence/policies/sync.policy.ts +121 -0
- package/src/core/common/persistence/sql/mysql/mysql-data-store.ts +108 -30
- package/src/core/common/persistence/sql/mysql/mysql-schema.compiler.ts +107 -4
- package/src/core/common/persistence/sql/mysql/mysql-schema.migrator.ts +129 -3
- package/src/core/common/persistence/sql/postgres/postgres-schema.compiler.ts +74 -2
- package/src/core/common/persistence/sql/postgres/postgres-schema.migrator.ts +139 -7
- package/src/core/common/persistence/sql/sql-data-store.ts +325 -44
- package/src/core/common/persistence/sql/sql-errors.ts +5 -1
- package/src/core/common/persistence/sync-access.registry.ts +50 -0
- package/src/core/common/persistence/sync-model.ts +270 -0
- package/src/core/common/services/crud.service.ts +257 -19
- package/src/core/modules/ai/INTEGRATION-CHECKLIST.md +36 -15
- package/src/core/modules/ai/README.md +163 -25
- package/src/core/modules/ai/core-ai-mcp.controller.ts +48 -1
- package/src/core/modules/ai/core-ai.constants.ts +6 -0
- package/src/core/modules/ai/core-ai.controller.ts +36 -1
- package/src/core/modules/ai/core-ai.module.ts +12 -0
- package/src/core/modules/ai/core-ai.resolver.ts +36 -0
- package/src/core/modules/ai/helpers/ai-mcp-oauth-consent.helper.ts +35 -4
- package/src/core/modules/ai/helpers/ai-mcp-oauth.helper.ts +68 -1
- package/src/core/modules/ai/helpers/ai-tool-authorization.helper.ts +99 -0
- package/src/core/modules/ai/index.ts +18 -0
- package/src/core/modules/ai/inputs/core-ai-settings.input.ts +24 -0
- package/src/core/modules/ai/interfaces/ai-hook.interface.ts +1 -1
- package/src/core/modules/ai/interfaces/ai-tool.interface.ts +38 -26
- package/src/core/modules/ai/models/core-ai-mode.model.ts +1 -1
- package/src/core/modules/ai/models/core-ai-settings.model.ts +23 -0
- package/src/core/modules/ai/models/core-ai-tool-policy.model.ts +1 -1
- package/src/core/modules/ai/models/core-ai-user-setting.model.ts +46 -0
- package/src/core/modules/ai/services/core-ai-conversation.service.ts +31 -6
- package/src/core/modules/ai/services/core-ai-mcp-oauth.service.ts +12 -9
- package/src/core/modules/ai/services/core-ai-mcp.service.ts +206 -13
- package/src/core/modules/ai/services/core-ai-prompt-builder.service.ts +13 -6
- package/src/core/modules/ai/services/core-ai-user-setting.service.ts +85 -0
- package/src/core/modules/ai/services/core-ai.service.ts +134 -35
- package/src/core/modules/api-token/README.md +4 -2
- package/src/core/modules/better-auth/CUSTOMIZATION.md +1 -1
- package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +7 -0
- package/src/core/modules/better-auth/README.md +32 -1
- package/src/core/modules/better-auth/better-auth.config.ts +12 -1
- package/src/core/modules/better-auth/core-better-auth-email-verification.service.ts +5 -2
- package/src/core/modules/better-auth/core-better-auth-path-guard.middleware.ts +85 -0
- package/src/core/modules/better-auth/core-better-auth-rate-limit.middleware.ts +5 -2
- package/src/core/modules/better-auth/core-better-auth-rate-limiter.service.ts +14 -7
- package/src/core/modules/better-auth/core-better-auth.module.ts +12 -2
- package/src/core/modules/better-auth/index.ts +1 -0
- package/src/core/modules/error-code/error-codes.ts +77 -0
- package/src/core/modules/migrate/sql-migration.helper.ts +141 -7
- package/src/core/modules/sync/INTEGRATION-CHECKLIST.md +95 -0
- package/src/core/modules/sync/README.md +198 -0
- package/src/core/modules/sync/SECURITY.md +65 -0
- package/src/core/modules/sync/core-sync-base.controller.ts +43 -0
- package/src/core/modules/sync/core-sync-cursor.ts +117 -0
- package/src/core/modules/sync/core-sync-hints.controller.ts +52 -0
- package/src/core/modules/sync/core-sync-hints.service.ts +178 -0
- package/src/core/modules/sync/core-sync-infrastructure.models.ts +40 -0
- package/src/core/modules/sync/core-sync-mutation.store.ts +146 -0
- package/src/core/modules/sync/core-sync-state.store.ts +89 -0
- package/src/core/modules/sync/core-sync.constants.ts +51 -0
- package/src/core/modules/sync/core-sync.controller.ts +68 -0
- package/src/core/modules/sync/core-sync.decorators.ts +84 -0
- package/src/core/modules/sync/core-sync.module.ts +75 -0
- package/src/core/modules/sync/core-sync.resolver.ts +35 -0
- package/src/core/modules/sync/core-sync.service.ts +1773 -0
- package/src/core/modules/sync/interfaces/core-sync.interfaces.ts +85 -0
- package/src/core/modules/sync/models/core-sync-hint.model.ts +18 -0
- package/src/core/modules/tenant/INTEGRATION-CHECKLIST.md +12 -1
- package/src/core/modules/tenant/README.md +49 -3
- package/src/core/modules/tenant/core-tenant.guard.ts +26 -2
- package/src/core/modules/tenant/core-tenant.service.ts +287 -2
- package/src/core.module.ts +25 -0
- package/src/index.ts +21 -0
- package/src/server/modules/sync-note/inputs/sync-note-create.input.ts +14 -0
- package/src/server/modules/sync-note/inputs/sync-note.input.ts +23 -0
- package/src/server/modules/sync-note/sync-note.model.ts +77 -0
- package/src/server/modules/sync-note/sync-note.module.ts +16 -0
- package/src/server/modules/sync-note/sync-note.service.ts +25 -0
- package/src/test/test.helper.ts +17 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createSchema } from '../../common/persistence/mongo/mongoose-compat.js';
|
|
2
|
+
export const SyncMutationSchema = createSchema({
|
|
3
|
+
attempt: { type: Number },
|
|
4
|
+
claimedAt: { type: Date },
|
|
5
|
+
code: { type: String },
|
|
6
|
+
expiresAt: { index: { expireAfterSeconds: 0 }, type: Date },
|
|
7
|
+
key: { index: { unique: true }, type: String },
|
|
8
|
+
state: { type: String },
|
|
9
|
+
status: { type: String },
|
|
10
|
+
version: { type: Number },
|
|
11
|
+
}, { collection: 'syncMutations', versionKey: false });
|
|
12
|
+
export const SyncStateSchema = createSchema({
|
|
13
|
+
epoch: { type: Number },
|
|
14
|
+
horizon: { type: Date },
|
|
15
|
+
key: { index: { unique: true }, type: String },
|
|
16
|
+
}, { collection: 'syncStates', versionKey: false });
|
|
17
|
+
//# sourceMappingURL=core-sync-infrastructure.models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-sync-infrastructure.models.js","sourceRoot":"","sources":["../../../../src/core/modules/sync/core-sync-infrastructure.models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mDAAmD,CAAC;AAcjF,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAC5C;IACE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACzB,SAAS,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;IACzB,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACtB,SAAS,EAAE,EAAE,KAAK,EAAE,EAAE,kBAAkB,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;IAC3D,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IAC9C,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACvB,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACxB,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;CAC1B,EACD,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,EAAE,CACnD,CAAC;AAMF,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CACzC;IACE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACvB,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;IACvB,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;CAC/C,EACD,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,CAChD,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DataStore, StoredRecord } from '../../common/persistence/data-store.interface.js';
|
|
2
|
+
export interface SyncMutationOutcome {
|
|
3
|
+
code?: string;
|
|
4
|
+
status: string;
|
|
5
|
+
version?: number;
|
|
6
|
+
}
|
|
7
|
+
export type SyncMutationClaim = {
|
|
8
|
+
kind: 'busy';
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'claimed';
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'done';
|
|
13
|
+
outcome: SyncMutationOutcome;
|
|
14
|
+
};
|
|
15
|
+
interface MutationRecord {
|
|
16
|
+
attempt?: number;
|
|
17
|
+
claimedAt?: Date;
|
|
18
|
+
code?: null | string;
|
|
19
|
+
expiresAt?: Date;
|
|
20
|
+
key: string;
|
|
21
|
+
state?: string;
|
|
22
|
+
status?: null | string;
|
|
23
|
+
version?: null | number;
|
|
24
|
+
}
|
|
25
|
+
export declare class CoreSyncMutationStore {
|
|
26
|
+
protected readonly store: DataStore<MutationRecord>;
|
|
27
|
+
protected readonly options: {
|
|
28
|
+
claimTimeoutMs: number;
|
|
29
|
+
retentionMs: number;
|
|
30
|
+
};
|
|
31
|
+
constructor(store: DataStore<MutationRecord>, options: {
|
|
32
|
+
claimTimeoutMs: number;
|
|
33
|
+
retentionMs: number;
|
|
34
|
+
});
|
|
35
|
+
static key(model: string, userId: string, recordId: string, mutationId: string): string;
|
|
36
|
+
claim(key: string, now?: Date): Promise<SyncMutationClaim>;
|
|
37
|
+
complete(key: string, outcome: SyncMutationOutcome, now?: Date): Promise<void>;
|
|
38
|
+
release(key: string): Promise<void>;
|
|
39
|
+
protected pending(now: Date, attempt: number): Omit<MutationRecord, 'key'>;
|
|
40
|
+
protected takeOver(existing: StoredRecord<MutationRecord>, now: Date): Promise<boolean>;
|
|
41
|
+
}
|
|
42
|
+
export declare function isDuplicateKey(error: unknown): boolean;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
export class CoreSyncMutationStore {
|
|
3
|
+
store;
|
|
4
|
+
options;
|
|
5
|
+
constructor(store, options) {
|
|
6
|
+
this.store = store;
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
static key(model, userId, recordId, mutationId) {
|
|
10
|
+
return createHash('sha256').update([model, userId, recordId, mutationId].join('\u0000')).digest('hex');
|
|
11
|
+
}
|
|
12
|
+
async claim(key, now = new Date()) {
|
|
13
|
+
for (let round = 0; round < 3; round++) {
|
|
14
|
+
const existing = await this.store.findOne({ key });
|
|
15
|
+
if (!existing) {
|
|
16
|
+
try {
|
|
17
|
+
await this.store.insert({ key, ...this.pending(now, 1) });
|
|
18
|
+
return { kind: 'claimed' };
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (!isDuplicateKey(error)) {
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (isExpired(existing, now)) {
|
|
28
|
+
if (await this.takeOver(existing, now)) {
|
|
29
|
+
return { kind: 'claimed' };
|
|
30
|
+
}
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (existing.state === 'done' && existing.status) {
|
|
34
|
+
return { kind: 'done', outcome: outcomeOf(existing) };
|
|
35
|
+
}
|
|
36
|
+
const claimedAt = existing.claimedAt ? new Date(existing.claimedAt).getTime() : 0;
|
|
37
|
+
if (now.getTime() - claimedAt < this.options.claimTimeoutMs) {
|
|
38
|
+
return { kind: 'busy' };
|
|
39
|
+
}
|
|
40
|
+
return (await this.takeOver(existing, now)) ? { kind: 'claimed' } : { kind: 'busy' };
|
|
41
|
+
}
|
|
42
|
+
return { kind: 'busy' };
|
|
43
|
+
}
|
|
44
|
+
async complete(key, outcome, now = new Date()) {
|
|
45
|
+
await this.store.updateOne({ key }, {
|
|
46
|
+
$set: {
|
|
47
|
+
code: outcome.code ?? null,
|
|
48
|
+
expiresAt: new Date(now.getTime() + this.options.retentionMs),
|
|
49
|
+
state: 'done',
|
|
50
|
+
status: outcome.status,
|
|
51
|
+
version: outcome.version ?? null,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async release(key) {
|
|
56
|
+
await this.store.deleteOne({ key, state: 'pending' });
|
|
57
|
+
}
|
|
58
|
+
pending(now, attempt) {
|
|
59
|
+
return {
|
|
60
|
+
attempt,
|
|
61
|
+
claimedAt: now,
|
|
62
|
+
code: null,
|
|
63
|
+
expiresAt: new Date(now.getTime() + this.options.retentionMs),
|
|
64
|
+
state: 'pending',
|
|
65
|
+
status: null,
|
|
66
|
+
version: null,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
async takeOver(existing, now) {
|
|
70
|
+
const attempt = existing.attempt ?? 0;
|
|
71
|
+
const taken = await this.store.updateOne({ attempt: existing.attempt ?? null, id: existing.id }, { $set: this.pending(now, attempt + 1) });
|
|
72
|
+
return !!taken;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function isExpired(record, now) {
|
|
76
|
+
return !!record.expiresAt && new Date(record.expiresAt).getTime() <= now.getTime();
|
|
77
|
+
}
|
|
78
|
+
function outcomeOf(record) {
|
|
79
|
+
return {
|
|
80
|
+
...(record.code ? { code: record.code } : {}),
|
|
81
|
+
status: record.status,
|
|
82
|
+
...(typeof record.version === 'number' ? { version: record.version } : {}),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export function isDuplicateKey(error) {
|
|
86
|
+
return error?.code === 11000;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=core-sync-mutation.store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-sync-mutation.store.js","sourceRoot":"","sources":["../../../../src/core/modules/sync/core-sync-mutation.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAuCzC,MAAM,OAAO,qBAAqB;IAEX;IACA;IAFrB,YACqB,KAAgC,EAChC,OAAwD;QADxD,UAAK,GAAL,KAAK,CAA2B;QAChC,YAAO,GAAP,OAAO,CAAiD;IAC1E,CAAC;IAMJ,MAAM,CAAC,GAAG,CAAC,KAAa,EAAE,MAAc,EAAE,QAAgB,EAAE,UAAkB;QAC5E,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzG,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,GAAG,GAAG,IAAI,IAAI,EAAE;QAEvC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;YACvC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;YACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,IAAI,CAAC;oBACH,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;oBAC1D,OAAO,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CAAC,EAAE,CACzC,CAAC;QACF,OAAO,CAAC,CAAC,KAAK,CAAC;IACjB,CAAC;CACF;AAED,SAAS,SAAS,CAAC,MAAsB,EAAE,GAAS;IAClD,OAAO,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;AACrF,CAAC;AAED,SAAS,SAAS,CAAC,MAAsB;IACvC,OAAO;QACL,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7C,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,GAAG,CAAC,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3E,CAAC;AACJ,CAAC;AAGD,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAQ,KAA4B,EAAE,IAAI,KAAK,KAAK,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DataStore } from '../../common/persistence/data-store.interface.js';
|
|
2
|
+
interface StateRecord {
|
|
3
|
+
epoch?: null | number;
|
|
4
|
+
horizon?: Date | null;
|
|
5
|
+
key: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class CoreSyncStateStore {
|
|
8
|
+
protected readonly store: DataStore<StateRecord>;
|
|
9
|
+
constructor(store: DataStore<StateRecord>);
|
|
10
|
+
static tenantEpochKey(model: string, tenantId: string): string;
|
|
11
|
+
static userEpochKey(model: string, tenantId: string, userId: string): string;
|
|
12
|
+
static horizonKey(model: string): string;
|
|
13
|
+
epochs(keys: readonly string[]): Promise<Map<string, number>>;
|
|
14
|
+
bump(key: string): Promise<void>;
|
|
15
|
+
horizon(model: string): Promise<Date | undefined>;
|
|
16
|
+
advanceHorizon(model: string, at: Date): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { isDuplicateKey } from './core-sync-mutation.store.js';
|
|
2
|
+
export class CoreSyncStateStore {
|
|
3
|
+
store;
|
|
4
|
+
constructor(store) {
|
|
5
|
+
this.store = store;
|
|
6
|
+
}
|
|
7
|
+
static tenantEpochKey(model, tenantId) {
|
|
8
|
+
return `epoch:t:${model}:${tenantId}`;
|
|
9
|
+
}
|
|
10
|
+
static userEpochKey(model, tenantId, userId) {
|
|
11
|
+
return `epoch:u:${model}:${tenantId}:${userId}`;
|
|
12
|
+
}
|
|
13
|
+
static horizonKey(model) {
|
|
14
|
+
return `horizon:${model}`;
|
|
15
|
+
}
|
|
16
|
+
async epochs(keys) {
|
|
17
|
+
const result = new Map(keys.map((key) => [key, 0]));
|
|
18
|
+
if (!keys.length) {
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
for (const row of await this.store.find({ key: { $in: [...keys] } }, { select: ['epoch', 'key'] })) {
|
|
22
|
+
result.set(row.key, typeof row.epoch === 'number' ? row.epoch : 0);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
async bump(key) {
|
|
27
|
+
if (await this.store.updateOne({ key }, { $inc: { epoch: 1 } })) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
await this.store.insert({ epoch: 1, key });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (!isDuplicateKey(error)) {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
await this.store.updateOne({ key }, { $inc: { epoch: 1 } });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async horizon(model) {
|
|
41
|
+
const row = await this.store.findOne({ key: CoreSyncStateStore.horizonKey(model) });
|
|
42
|
+
return row?.horizon ? new Date(row.horizon) : undefined;
|
|
43
|
+
}
|
|
44
|
+
async advanceHorizon(model, at) {
|
|
45
|
+
const key = CoreSyncStateStore.horizonKey(model);
|
|
46
|
+
const behind = { $or: [{ horizon: null }, { horizon: { $lt: at } }], key };
|
|
47
|
+
if (await this.store.updateOne(behind, { $set: { horizon: at } })) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (await this.store.findOne({ key })) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
await this.store.insert({ horizon: at, key });
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (!isDuplicateKey(error)) {
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
await this.store.updateOne(behind, { $set: { horizon: at } });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=core-sync-state.store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-sync-state.store.js","sourceRoot":"","sources":["../../../../src/core/modules/sync/core-sync-state.store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAoB/D,MAAM,OAAO,kBAAkB;IACE;IAA/B,YAA+B,KAA6B;QAA7B,UAAK,GAAL,KAAK,CAAwB;IAAG,CAAC;IAEhE,MAAM,CAAC,cAAc,CAAC,KAAa,EAAE,QAAgB;QACnD,OAAO,WAAW,KAAK,IAAI,QAAQ,EAAE,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,KAAa,EAAE,QAAgB,EAAE,MAAc;QACjE,OAAO,WAAW,KAAK,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAa;QAC7B,OAAO,WAAW,KAAK,EAAE,CAAC;IAC5B,CAAC;IAGD,KAAK,CAAC,MAAM,CAAC,IAAuB;QAClC,MAAM,MA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AE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const SYNC_MUTATION_MODEL = "SyncMutation";
|
|
2
|
+
export declare const SYNC_STATE_MODEL = "SyncState";
|
|
3
|
+
export declare const SYNC_SERVICE_METADATA = "lt:sync:service";
|
|
4
|
+
export declare const SYNC_FIELD_METADATA = "lt:sync:fields";
|
|
5
|
+
export declare const SYNC_CLAIM_TIMEOUT_MS = 30000;
|
|
6
|
+
export declare const SYNC_REAPPLY_ATTEMPTS = 3;
|
|
7
|
+
export declare const SYNC_DEFAULTS: Readonly<{
|
|
8
|
+
hintDebounceMs: 250;
|
|
9
|
+
maxBytes: 1048576;
|
|
10
|
+
maxItems: 100;
|
|
11
|
+
maxLimit: 1000;
|
|
12
|
+
mutationsDays: 30;
|
|
13
|
+
path: "sync";
|
|
14
|
+
pullLimit: 200;
|
|
15
|
+
rateLimitPull: {
|
|
16
|
+
max: number;
|
|
17
|
+
windowSeconds: number;
|
|
18
|
+
};
|
|
19
|
+
rateLimitPush: {
|
|
20
|
+
max: number;
|
|
21
|
+
windowSeconds: number;
|
|
22
|
+
};
|
|
23
|
+
tombstonesDays: 90;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const SYNC_PURGE_BATCH = 1000;
|
|
26
|
+
export declare const SYNC_PURGE_INTERVAL_MS: number;
|
|
27
|
+
export declare const SYNC_HINT_KEEPALIVE_MS = 25000;
|
|
28
|
+
export declare const SYNC_PULL_LIMIT_CEILING = 1000;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const SYNC_MUTATION_MODEL = 'SyncMutation';
|
|
2
|
+
export const SYNC_STATE_MODEL = 'SyncState';
|
|
3
|
+
export const SYNC_SERVICE_METADATA = 'lt:sync:service';
|
|
4
|
+
export const SYNC_FIELD_METADATA = 'lt:sync:fields';
|
|
5
|
+
export const SYNC_CLAIM_TIMEOUT_MS = 30_000;
|
|
6
|
+
export const SYNC_REAPPLY_ATTEMPTS = 3;
|
|
7
|
+
export const SYNC_DEFAULTS = Object.freeze({
|
|
8
|
+
hintDebounceMs: 250,
|
|
9
|
+
maxBytes: 1_048_576,
|
|
10
|
+
maxItems: 100,
|
|
11
|
+
maxLimit: 1000,
|
|
12
|
+
mutationsDays: 30,
|
|
13
|
+
path: 'sync',
|
|
14
|
+
pullLimit: 200,
|
|
15
|
+
rateLimitPull: { max: 120, windowSeconds: 60 },
|
|
16
|
+
rateLimitPush: { max: 60, windowSeconds: 60 },
|
|
17
|
+
tombstonesDays: 90,
|
|
18
|
+
});
|
|
19
|
+
export const SYNC_PURGE_BATCH = 1000;
|
|
20
|
+
export const SYNC_PURGE_INTERVAL_MS = 60 * 60_000;
|
|
21
|
+
export const SYNC_HINT_KEEPALIVE_MS = 25_000;
|
|
22
|
+
export const SYNC_PULL_LIMIT_CEILING = 1000;
|
|
23
|
+
//# sourceMappingURL=core-sync.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-sync.constants.js","sourceRoot":"","sources":["../../../../src/core/modules/sync/core-sync.constants.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAGlD,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAG5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AAGvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AAMpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAG5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAGvC,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,cAAc,EAAE,GAAG;IACnB,QAAQ,EAAE,SAAS;IACnB,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,IAAI;IACd,aAAa,EAAE,EAAE;IACjB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,GAAG;IACd,aAAa,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE;IAC9C,aAAa,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE;IAC7C,cAAc,EAAE,EAAE;CACnB,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAErC,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,GAAG,MAAM,CAAC;AAGlD,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAG7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CoreSyncBaseController } from './core-sync-base.controller.js';
|
|
2
|
+
import type { ISyncPullResult, ISyncPushResult } from './interfaces/core-sync.interfaces.js';
|
|
3
|
+
export declare class CoreSyncController extends CoreSyncBaseController {
|
|
4
|
+
pull(model: string, cursor: string, limit: string, currentUser: any, req: any, res: any): Promise<ISyncPullResult | object>;
|
|
5
|
+
push(model: string, body: any, currentUser: any, req: any, res: any): Promise<{
|
|
6
|
+
results: ISyncPushResult[];
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Body, Controller, Get, HttpCode, HttpStatus, Param, Post, Query, Req, Res } from '@nestjs/common';
|
|
14
|
+
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
15
|
+
import { CurrentUser } from '../../common/decorators/current-user.decorator.js';
|
|
16
|
+
import { Roles } from '../../common/decorators/roles.decorator.js';
|
|
17
|
+
import { RoleEnum } from '../../common/enums/role.enum.js';
|
|
18
|
+
import { CoreSyncBaseController } from './core-sync-base.controller.js';
|
|
19
|
+
import { SYNC_DEFAULTS } from './core-sync.constants.js';
|
|
20
|
+
import { SyncResyncRequiredException } from './core-sync.service.js';
|
|
21
|
+
let CoreSyncController = class CoreSyncController extends CoreSyncBaseController {
|
|
22
|
+
async pull(model, cursor, limit, currentUser, req, res) {
|
|
23
|
+
await this.limit('pull', currentUser, res);
|
|
24
|
+
await this.scopeTenants(req, currentUser);
|
|
25
|
+
try {
|
|
26
|
+
return await this.syncService.pull(model, { cursor, limit }, currentUser);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error instanceof SyncResyncRequiredException) {
|
|
30
|
+
res?.status?.(error.getStatus());
|
|
31
|
+
return error.getResponse();
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async push(model, body, currentUser, req, res) {
|
|
37
|
+
this.syncService.assertPushRequest(req);
|
|
38
|
+
await this.limit('push', currentUser, res);
|
|
39
|
+
await this.scopeTenants(req, currentUser);
|
|
40
|
+
return this.syncService.push(model, body, currentUser);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
__decorate([
|
|
44
|
+
ApiBearerAuth(),
|
|
45
|
+
ApiOperation({ description: 'One page of changes after the cursor (protocol §5)', summary: 'Pull changes' }),
|
|
46
|
+
Get(':model'),
|
|
47
|
+
Roles(RoleEnum.S_USER),
|
|
48
|
+
__param(0, Param('model')),
|
|
49
|
+
__param(1, Query('cursor')),
|
|
50
|
+
__param(2, Query('limit')),
|
|
51
|
+
__param(3, CurrentUser()),
|
|
52
|
+
__param(4, Req()),
|
|
53
|
+
__param(5, Res({ passthrough: true })),
|
|
54
|
+
__metadata("design:type", Function),
|
|
55
|
+
__metadata("design:paramtypes", [String, String, String, Object, Object, Object]),
|
|
56
|
+
__metadata("design:returntype", Promise)
|
|
57
|
+
], CoreSyncController.prototype, "pull", null);
|
|
58
|
+
__decorate([
|
|
59
|
+
ApiBearerAuth(),
|
|
60
|
+
ApiOperation({ description: 'Apply pushed changes item by item (protocol §6)', summary: 'Push changes' }),
|
|
61
|
+
HttpCode(HttpStatus.OK),
|
|
62
|
+
Post(':model'),
|
|
63
|
+
Roles(RoleEnum.S_USER),
|
|
64
|
+
__param(0, Param('model')),
|
|
65
|
+
__param(1, Body()),
|
|
66
|
+
__param(2, CurrentUser()),
|
|
67
|
+
__param(3, Req()),
|
|
68
|
+
__param(4, Res({ passthrough: true })),
|
|
69
|
+
__metadata("design:type", Function),
|
|
70
|
+
__metadata("design:paramtypes", [String, Object, Object, Object, Object]),
|
|
71
|
+
__metadata("design:returntype", Promise)
|
|
72
|
+
], CoreSyncController.prototype, "push", null);
|
|
73
|
+
CoreSyncController = __decorate([
|
|
74
|
+
ApiTags('sync'),
|
|
75
|
+
Controller(SYNC_DEFAULTS.path),
|
|
76
|
+
Roles(RoleEnum.S_USER)
|
|
77
|
+
], CoreSyncController);
|
|
78
|
+
export { CoreSyncController };
|
|
79
|
+
//# sourceMappingURL=core-sync.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-sync.controller.js","sourceRoot":"","sources":["../../../../src/core/modules/sync/core-sync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AA;IACb,WAAA,GAAG,EAAE,CAAA;IACL,WAAA,GAAG,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;;;;8CAM5B;AA3CU,kBAAkB;IAH9B,OAAO,CAAC,MAAM,CAAC;IACf,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC;IAC9B,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;GACV,kBAAkB,CA4C9B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Type } from '@nestjs/common';
|
|
2
|
+
export interface SyncServiceOptions {
|
|
3
|
+
createInput: Type<any>;
|
|
4
|
+
model: Type<any>;
|
|
5
|
+
modelName?: string;
|
|
6
|
+
updateInput: Type<any>;
|
|
7
|
+
}
|
|
8
|
+
export declare function SyncService(options: SyncServiceOptions): ClassDecorator;
|
|
9
|
+
export declare function getSyncServiceOptions(target: Function): SyncServiceOptions | undefined;
|
|
10
|
+
export type SyncFieldStrategy = 'lww' | 'reject';
|
|
11
|
+
export declare function SyncField(strategy: SyncFieldStrategy): PropertyDecorator;
|
|
12
|
+
export declare function getSyncFieldStrategies(modelClass: Function): Record<string, SyncFieldStrategy>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SYNC_FIELD_METADATA, SYNC_SERVICE_METADATA } from './core-sync.constants.js';
|
|
2
|
+
export function SyncService(options) {
|
|
3
|
+
return (target) => {
|
|
4
|
+
Reflect.defineMetadata(SYNC_SERVICE_METADATA, { ...options }, target);
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export function getSyncServiceOptions(target) {
|
|
8
|
+
return Reflect.getMetadata(SYNC_SERVICE_METADATA, target);
|
|
9
|
+
}
|
|
10
|
+
export function SyncField(strategy) {
|
|
11
|
+
if (strategy !== 'lww' && strategy !== 'reject') {
|
|
12
|
+
throw new Error(`@SyncField: strategy must be 'lww' or 'reject', got ${JSON.stringify(strategy)}`);
|
|
13
|
+
}
|
|
14
|
+
return (target, property) => {
|
|
15
|
+
const own = Reflect.hasOwnMetadata(SYNC_FIELD_METADATA, target.constructor)
|
|
16
|
+
? Reflect.getOwnMetadata(SYNC_FIELD_METADATA, target.constructor)
|
|
17
|
+
: {};
|
|
18
|
+
Reflect.defineMetadata(SYNC_FIELD_METADATA, { ...own, [String(property)]: strategy }, target.constructor);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function getSyncFieldStrategies(modelClass) {
|
|
22
|
+
const chain = [];
|
|
23
|
+
for (let current = modelClass; current && current !== Function.prototype; current = Object.getPrototypeOf(current)) {
|
|
24
|
+
chain.unshift(current);
|
|
25
|
+
}
|
|
26
|
+
return Object.assign({}, ...chain.map((current) => Reflect.hasOwnMetadata(SYNC_FIELD_METADATA, current) ? Reflect.getOwnMetadata(SYNC_FIELD_METADATA, current) : {}));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=core-sync.decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-sync.decorators.js","sourceRoot":"","sources":["../../../../src/core/modules/sync/core-sync.decorators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AA8BtF,MAAM,UAAU,WAAW,CAAC,OAA2B;IACrD,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,OAAO,CAAC,cAAc,CAAC,qBAAqB,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;IACxE,CAAC,CAAC;AACJ,CAAC;AAGD,MAAM,UAAU,qBAAqB,CAAC,MAAgB;IACpD,OAAO,OAAO,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC;AAkBD,MAAM,UAAU,SAAS,CAAC,QAA2B;IACnD,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,uDAAuD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACrG,CAAC;IACD,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE;QAC1B,MAAM,GAAG,GAAsC,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,MAAM,CAAC,WAAW,CAAC;YAC5G,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,MAAM,CAAC,WAAW,CAAC;YACjE,CAAC,CAAC,EAAE,CAAC;QACP,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,EAAE,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5G,CAAC,CAAC;AACJ,CAAC;AAGD,MAAM,UAAU,sBAAsB,CAAC,UAAoB;IACzD,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,KAAK,IAAI,OAAO,GAAG,UAAU,EAAE,OAAO,IAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;QACnH,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAClB,EAAE,EACF,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CACvB,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CACjH,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DynamicModule, Type } from '@nestjs/common';
|
|
2
|
+
import { CoreSyncController } from './core-sync.controller.js';
|
|
3
|
+
import { CoreSyncHintsController } from './core-sync-hints.controller.js';
|
|
4
|
+
import { CoreSyncResolver } from './core-sync.resolver.js';
|
|
5
|
+
import { CoreSyncService } from './core-sync.service.js';
|
|
6
|
+
export interface CoreSyncModuleOptions {
|
|
7
|
+
controller?: Type<CoreSyncController>;
|
|
8
|
+
graphQlHints?: boolean;
|
|
9
|
+
hintsController?: Type<CoreSyncHintsController>;
|
|
10
|
+
path?: string;
|
|
11
|
+
resolver?: Type<CoreSyncResolver>;
|
|
12
|
+
service?: Type<CoreSyncService>;
|
|
13
|
+
}
|
|
14
|
+
export declare class CoreSyncModule {
|
|
15
|
+
static forRoot(options?: CoreSyncModuleOptions): DynamicModule;
|
|
16
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var CoreSyncModule_1;
|
|
8
|
+
import { Module } from '@nestjs/common';
|
|
9
|
+
import { PATH_METADATA } from '@nestjs/common/constants';
|
|
10
|
+
import { DiscoveryModule } from '@nestjs/core';
|
|
11
|
+
import { CorePersistenceModule } from '../../common/persistence/core-persistence.module.js';
|
|
12
|
+
import { SYNC_DEFAULTS, SYNC_MUTATION_MODEL, SYNC_STATE_MODEL } from './core-sync.constants.js';
|
|
13
|
+
import { CoreSyncController } from './core-sync.controller.js';
|
|
14
|
+
import { CoreSyncHintsController } from './core-sync-hints.controller.js';
|
|
15
|
+
import { CoreSyncHintService } from './core-sync-hints.service.js';
|
|
16
|
+
import { SyncMutationSchema, SyncStateSchema } from './core-sync-infrastructure.models.js';
|
|
17
|
+
import { CoreSyncResolver } from './core-sync.resolver.js';
|
|
18
|
+
import { CoreSyncService } from './core-sync.service.js';
|
|
19
|
+
let CoreSyncModule = CoreSyncModule_1 = class CoreSyncModule {
|
|
20
|
+
static forRoot(options = {}) {
|
|
21
|
+
const controller = options.controller ?? CoreSyncController;
|
|
22
|
+
const hintsController = options.hintsController ?? CoreSyncHintsController;
|
|
23
|
+
for (const routes of [hintsController, controller]) {
|
|
24
|
+
Reflect.defineMetadata(PATH_METADATA, options.path || SYNC_DEFAULTS.path, routes);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
controllers: [hintsController, controller],
|
|
28
|
+
exports: [CoreSyncHintService, CoreSyncService],
|
|
29
|
+
global: true,
|
|
30
|
+
imports: [
|
|
31
|
+
DiscoveryModule,
|
|
32
|
+
CorePersistenceModule.forFeature([
|
|
33
|
+
{ name: SYNC_MUTATION_MODEL, schema: SyncMutationSchema },
|
|
34
|
+
{ name: SYNC_STATE_MODEL, schema: SyncStateSchema },
|
|
35
|
+
]),
|
|
36
|
+
],
|
|
37
|
+
module: CoreSyncModule_1,
|
|
38
|
+
providers: [
|
|
39
|
+
CoreSyncHintService,
|
|
40
|
+
options.service ? { provide: CoreSyncService, useClass: options.service } : CoreSyncService,
|
|
41
|
+
...(options.graphQlHints === false ? [] : [options.resolver ?? CoreSyncResolver]),
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
CoreSyncModule = CoreSyncModule_1 = __decorate([
|
|
47
|
+
Module({})
|
|
48
|
+
], CoreSyncModule);
|
|
49
|
+
export { CoreSyncModule };
|
|
50
|
+
//# sourceMappingURL=core-sync.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-sync.module.js","sourceRoot":"","sources":["../../../../src/core/modules/sync/core-sync.module.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAiB,MAAM,EAAQ,MAA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AAE,kBAAkB,EAAE;oBACzD,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,eAAe,EAAE;iBACpD,CAAC;aACH;YACD,MAAM,EAAE,gBAAc;YACtB,SAAS,EAAE;gBACT,mBAAmB;gBACnB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,eAAe;gBAC3F,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,gBAAgB,CAAC,CAAC;aAClF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA/BY,cAAc;IAD1B,MAAM,CAAC,EAAE,CAAC;GACE,cAAc,CA+B1B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CoreSyncService } from './core-sync.service.js';
|
|
2
|
+
import { CoreSyncHintModel } from './models/core-sync-hint.model.js';
|
|
3
|
+
export declare class CoreSyncResolver {
|
|
4
|
+
protected readonly syncService: CoreSyncService;
|
|
5
|
+
constructor(syncService: CoreSyncService);
|
|
6
|
+
syncHint(currentUser: any, models?: string[]): Promise<AsyncIterableIterator<{
|
|
7
|
+
syncHint: CoreSyncHintModel;
|
|
8
|
+
}>>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Args, Resolver, Subscription } from '@nestjs/graphql';
|
|
14
|
+
import { GraphQLUser } from '../../common/decorators/graphql-user.decorator.js';
|
|
15
|
+
import { Roles } from '../../common/decorators/roles.decorator.js';
|
|
16
|
+
import { RoleEnum } from '../../common/enums/role.enum.js';
|
|
17
|
+
import { CoreSyncService } from './core-sync.service.js';
|
|
18
|
+
import { CoreSyncHintModel } from './models/core-sync-hint.model.js';
|
|
19
|
+
let CoreSyncResolver = class CoreSyncResolver {
|
|
20
|
+
syncService;
|
|
21
|
+
constructor(syncService) {
|
|
22
|
+
this.syncService = syncService;
|
|
23
|
+
}
|
|
24
|
+
syncHint(currentUser, models) {
|
|
25
|
+
return this.syncService.hintIterator(currentUser, models);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
__decorate([
|
|
29
|
+
Roles(RoleEnum.S_USER),
|
|
30
|
+
Subscription(() => CoreSyncHintModel, {
|
|
31
|
+
description: 'A hint whenever a synchronized model the subscriber may pull changes',
|
|
32
|
+
name: 'syncHint',
|
|
33
|
+
}),
|
|
34
|
+
__param(0, GraphQLUser()),
|
|
35
|
+
__param(1, Args('models', { description: 'Only these models (all when absent)', nullable: true, type: () => [String] })),
|
|
36
|
+
__metadata("design:type", Function),
|
|
37
|
+
__metadata("design:paramtypes", [Object, Array]),
|
|
38
|
+
__metadata("design:returntype", Promise)
|
|
39
|
+
], CoreSyncResolver.prototype, "syncHint", null);
|
|
40
|
+
CoreSyncResolver = __decorate([
|
|
41
|
+
Resolver(),
|
|
42
|
+
Roles(RoleEnum.S_USER),
|
|
43
|
+
__metadata("design:paramtypes", [CoreSyncService])
|
|
44
|
+
], CoreSyncResolver);
|
|
45
|
+
export { CoreSyncResolver };
|
|
46
|
+
//# sourceMappingURL=core-sync.resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-sync.resolver.js","sourceRoot":"","sources":["../../../../src/core/modules/sync/core-sync.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,4CAA4C,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAa9D,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACI;IAA/B,YAA+B,WAA4B;QAA5B,gBAAW,GAAX,WAAW,CAAiB;IAAG,CAAC;IAO/D,QAAQ,CACS,WAAgB,EAE/B,MAAiB;QAEjB,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC5D,CAAC;CACF,CAAA;AAPC;IALC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;IACtB,YAAY,CAAC,GAAG,EAAE,CAAC,iBAAiB,EAAE;QACrC,WAAW,EAAE,sEAAsE;QACnF,IAAI,EAAE,UAAU;KACjB,CAAC;IAEC,WAAA,WAAW,EAAE,CAAA;IACb,WAAA,IAAI,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,qCAAqC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;;;;gDAI9G;AAdU,gBAAgB;IAF5B,QAAQ,EAAE;IACV,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;qCAEuB,eAAe;GADhD,gBAAgB,CAe5B"}
|