@classytic/work-period 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,13 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## 0.1.0 — 2026-10-18
3
+ ## Unreleased
4
4
 
5
- First published release: a country-neutral approved work-period and locked payroll-facts kernel.
5
+ ## 0.2.0 — 2026-11-28
6
6
 
7
- - `defineWorkPeriod()` describe/bind engine, the `WorkPeriod` model and `WorkPeriodRepository` (`create`, `reconcile`, and the submit, approve, reject, reopen and lock transitions, each guarded by a compare-and-set on status).
8
- - A period carries its attendance facts, leave facts and policy reference, so payroll reads a frozen, approved set of facts and not live bridges.
9
- - Events: `WORK_PERIOD_EVENTS` and `workPeriodEventDefinitions` (created, reconciled, submitted, approved, rejected, reopened, locked), with `InProcessWorkPeriodBus`.
10
- - Typed errors: duplicate period, invalid transition, approval, capability, concurrency, not found.
11
- - Peers: `@classytic/mongokit` `>=3.41.0`, `@classytic/primitives` `>=0.32.0`, `@classytic/repo-core` `>=0.31.0`, `mongoose` `>=9.11.0` (`zod >=4.0.0` unchanged).
12
- - Entries: `.` and `./schemas`.
13
- - Licensed under the Classytic Source-Available License, as the other `@classytic/hr` packages.
7
+ Peers raised to the latest published: `@classytic/mongokit >=3.47.0`, `@classytic/primitives >=0.39.0`, `@classytic/repo-core >=0.39.0`, `mongoose >=9.13.1`.
8
+
9
+ - The repository takes mongokit's `distribution` option (`onMissingKey`, `exemptOperations`, or `false`) and installs `multiTenantPlugin` from it. Peer `@classytic/mongokit >=3.45.0`. Consumers: none to change.
package/dist/engine.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { WorkPeriodContext } from "./context.mjs";
2
2
  import { WorkPeriodDocument } from "./model.mjs";
3
3
  import { WorkPeriodRepository } from "./repository.mjs";
4
- import { MultiTenantOptions, PluginType } from "@classytic/mongokit";
4
+ import { MultiTenantOptions, PluginType, RepositoryOptions } from "@classytic/mongokit";
5
5
  import { ResolvedTenantConfig, TenantConfig } from "@classytic/repo-core/tenant";
6
6
  import { EventTransport } from "@classytic/primitives/events";
7
7
  import { Connection, Model } from "mongoose";
@@ -13,6 +13,25 @@ export interface WorkPeriodShape {
13
13
  autoIndex?: boolean | undefined;
14
14
  collectionPrefix?: string | undefined;
15
15
  forceRecreate?: boolean | undefined;
16
+ /**
17
+ * Declare the tenant field as the distribution (shard / partition) key on
18
+ * the `workPeriod` repository, so a query that omits it is reported by
19
+ * mongokit's distribution guard (repo-core `DistributionConfig`). The guard
20
+ * runs after the tenant plugin, so every tenant-scoped call carries the key;
21
+ * only unscoped calls (a host `skipWhen` / `skipOperations` bypass) are flagged.
22
+ *
23
+ * DEFAULT ON when tenant scoping is enabled with `strategy: 'field'`:
24
+ * `{ key: tenantField, onMissingKey: 'warn', exemptOperations: [] }`.
25
+ * Work-period performs no built-in cross-tenant read, so nothing is exempt
26
+ * by default. A legitimate cross-tenant operation — a platform sweep run
27
+ * with the tenant plugin skipped — goes in `exemptOperations` (mongokit op
28
+ * names, e.g. `'findAll'`, `'aggregate'`). `onMissingKey: 'throw'` rejects
29
+ * instead of warning; `false` declares nothing. Ignored when tenant scoping is off.
30
+ */
31
+ distribution?: {
32
+ onMissingKey?: 'warn' | 'throw' | 'off' | undefined;
33
+ exemptOperations?: readonly string[] | undefined;
34
+ } | false | undefined;
16
35
  }
17
36
  export interface WorkPeriodRuntime {
18
37
  eventTransport?: EventTransport | undefined;
@@ -26,6 +45,8 @@ export interface WorkPeriodEngine {
26
45
  readonly config: Readonly<{
27
46
  tenant: ResolvedTenantConfig;
28
47
  hasOutbox: boolean;
48
+ /** The distribution key declared on `workPeriod`, or `undefined` when none is. */
49
+ distribution?: RepositoryOptions['distribution'] | undefined;
29
50
  }>;
30
51
  readonly models: Readonly<{
31
52
  WorkPeriod: Model<WorkPeriodDocument>;
package/dist/engine.mjs CHANGED
@@ -8,6 +8,11 @@ import { resolveTenantConfig } from "@classytic/repo-core/tenant";
8
8
  //#region src/engine.ts
9
9
  function defineWorkPeriod(shape = {}) {
10
10
  const tenant = resolveTenantConfig(shape.tenant);
11
+ const distribution = tenant.enabled && tenant.strategy === "field" && shape.distribution !== false ? {
12
+ key: tenant.tenantField,
13
+ onMissingKey: shape.distribution?.onMissingKey ?? "warn",
14
+ exemptOperations: [...shape.distribution?.exemptOperations ?? []]
15
+ } : void 0;
11
16
  const modelsBlueprint = defineModels({
12
17
  models: [{
13
18
  name: "WorkPeriod",
@@ -48,6 +53,7 @@ function defineWorkPeriod(shape = {}) {
48
53
  const workPeriod = new WorkPeriodRepository({
49
54
  model: models.WorkPeriod,
50
55
  plugins: [...tenantPlugins, ...runtime.repositoryPlugins ?? []],
56
+ ...distribution ? { distribution } : {},
51
57
  eventTransport: events,
52
58
  outbox: runtime.outbox,
53
59
  logger
@@ -56,7 +62,8 @@ function defineWorkPeriod(shape = {}) {
56
62
  const engine = {
57
63
  config: Object.freeze({
58
64
  tenant,
59
- hasOutbox: runtime.outbox !== void 0
65
+ hasOutbox: runtime.outbox !== void 0,
66
+ distribution
60
67
  }),
61
68
  models: Object.freeze(models),
62
69
  repositories: Object.freeze({ workPeriod }),
package/dist/model.mjs CHANGED
@@ -87,7 +87,10 @@ function buildWorkPeriodSchema() {
87
87
  required: true,
88
88
  min: 0
89
89
  }
90
- }, { _id: false }) },
90
+ }, {
91
+ _id: false,
92
+ minimize: false
93
+ }) },
91
94
  values: { type: Schema.Types.Mixed },
92
95
  sourceRefs: {
93
96
  type: [externalRefSchema],
@@ -1,7 +1,7 @@
1
1
  import { WorkPeriodContext } from "./context.mjs";
2
2
  import { WorkPeriodAttendanceFacts, WorkPeriodDocument, WorkPeriodLeaveFacts, WorkPeriodPolicyRef } from "./model.mjs";
3
3
  import { EventChannels } from "./events.mjs";
4
- import { PluginType, Repository } from "@classytic/mongokit";
4
+ import { PluginType, Repository, RepositoryOptions } from "@classytic/mongokit";
5
5
  import { Model } from "mongoose";
6
6
  import { ApprovalChain } from "@classytic/primitives/approval";
7
7
  import { ExternalRef } from "@classytic/primitives/reference";
@@ -21,6 +21,8 @@ export type ReconcileWorkPeriodInput = Pick<CreateWorkPeriodInput, 'attendance'
21
21
  export interface WorkPeriodRepositoryConfig extends EventChannels {
22
22
  model: Model<WorkPeriodDocument>;
23
23
  plugins?: PluginType[] | undefined;
24
+ /** Shard-key declaration (repo-core distribution guard); set by the engine. */
25
+ distribution?: RepositoryOptions['distribution'];
24
26
  }
25
27
  export declare class WorkPeriodRepository extends Repository<WorkPeriodDocument> {
26
28
  private readonly channels;
@@ -6,7 +6,7 @@ import { isApproved } from "@classytic/primitives/approval";
6
6
  var WorkPeriodRepository = class extends Repository {
7
7
  channels;
8
8
  constructor(config) {
9
- super(config.model, config.plugins ?? [], { maxLimit: 200 });
9
+ super(config.model, config.plugins ?? [], { maxLimit: 200 }, { ...config.distribution ? { distribution: config.distribution } : {} });
10
10
  this.channels = config;
11
11
  }
12
12
  async createPeriod(input, ctx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/work-period",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Country-neutral approved work-period and locked payroll-facts kernel.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -37,20 +37,20 @@
37
37
  "release": "npm run push -- main && npm run release:tag && npm publish"
38
38
  },
39
39
  "peerDependencies": {
40
- "@classytic/mongokit": ">=3.41.0",
41
- "@classytic/primitives": ">=0.32.0",
42
- "@classytic/repo-core": ">=0.31.0",
43
- "mongoose": ">=9.11.0",
40
+ "@classytic/mongokit": ">=3.47.0",
41
+ "@classytic/primitives": ">=0.39.0",
42
+ "@classytic/repo-core": ">=0.39.0",
43
+ "mongoose": ">=9.13.1",
44
44
  "zod": ">=4.0.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@classytic/dev-tools": "^0.2.1",
48
- "@classytic/mongokit": "^3.43.0",
49
- "@classytic/primitives": "^0.34.0",
50
- "@classytic/repo-core": "^0.31.1",
48
+ "@classytic/mongokit": "^3.47.0",
49
+ "@classytic/primitives": "^0.39.0",
50
+ "@classytic/repo-core": "^0.39.0",
51
51
  "@types/node": "^26.6.5",
52
52
  "mongodb-memory-server": "^11.3.0",
53
- "mongoose": "^9.11.2",
53
+ "mongoose": "^9.13.1",
54
54
  "publint": "^0.3.25",
55
55
  "tsdown": "^0.23.1",
56
56
  "typescript": "^7.0.2",