@classytic/mongokit 3.17.0 → 3.18.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/README.md +2 -1
- package/dist/plugins/index.d.mts +17 -1
- package/dist/plugins/index.mjs +71 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Requirements:
|
|
|
17
17
|
|
|
18
18
|
- Node.js `>=22`
|
|
19
19
|
- Mongoose `>=9.4.1`
|
|
20
|
-
- `@classytic/repo-core >=0.
|
|
20
|
+
- `@classytic/repo-core >=0.7.0`
|
|
21
21
|
|
|
22
22
|
## Quick Start
|
|
23
23
|
|
|
@@ -237,6 +237,7 @@ Supports common URL operators such as `_gt`, `_gte`, `_lt`, `_lte`, `_in`, `_nin
|
|
|
237
237
|
| `mongoOperationsPlugin` | Hook-routed Mongo update helpers |
|
|
238
238
|
| `aggregateHelpersPlugin` | Common aggregation helpers |
|
|
239
239
|
| `subdocumentPlugin` | Nested array document helpers |
|
|
240
|
+
| `changeLogPlugin` | Durable per-doc change feed (`@classytic/repo-core/sync`) for offline-first pull/push and replicas |
|
|
240
241
|
|
|
241
242
|
Import only the plugins you use.
|
|
242
243
|
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
+
import { G as Plugin } from "../types-CU3SEDbD.mjs";
|
|
1
2
|
import { $ as AuditEntry, B as IdGenerator, C as LeasePluginOptions, D as elasticSearchPlugin, E as ElasticSearchOptions, F as MultiTenantOptions, G as getNextSequence, H as SequentialIdOptions, J as CacheAdapter, K as prefixedId, L as multiTenantPlugin, M as auditLogPlugin, N as AggregateHelpersMethods, O as cascadePlugin, P as aggregateHelpersPlugin, Q as cachePlugin, R as CustomIdOptions, S as LeaseMethods, T as fieldFilterPlugin, U as customIdPlugin, V as PrefixedIdOptions, W as dateSequentialId, X as RepositoryCacheHandle, Y as CacheOptions, Z as RepositoryCachePluginOptions, _ as observabilityPlugin, a as uniqueField, at as AuditTrailQuery, b as MethodRegistryRepository, c as TenantContext, d as SubdocumentMethods, et as AuditOperation, f as subdocumentPlugin, g as OperationMetric, h as ObservabilityOptions, i as requireField, it as AuditTrailOptions, j as batchOperationsPlugin, k as BatchOperationsMethods, l as TenantStore, m as softDeletePlugin, n as blockIf, nt as AuditQueryResult, o as validationChainPlugin, ot as auditTrailPlugin, p as SoftDeleteMethods, q as sequentialId, r as immutableField, rt as AuditTrailMethods, s as timestampPlugin, t as autoInject, tt as AuditQueryOptions, u as createTenantContext, v as MongoOperationsMethods, w as leasePlugin, x as methodRegistryPlugin, y as mongoOperationsPlugin, z as DateSequentialIdOptions } from "../validation-chain.plugin-BpMfy18N.mjs";
|
|
2
|
-
|
|
3
|
+
import { ChangeLogStore } from "@classytic/repo-core/sync";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/change-log.plugin.d.ts
|
|
6
|
+
interface ChangeLogPluginOptions {
|
|
7
|
+
/** Durable feed implementing the repo-core/sync contract. */
|
|
8
|
+
store: ChangeLogStore;
|
|
9
|
+
/** Logical scope for entries (resource name a client subscribes to). */
|
|
10
|
+
scope: string;
|
|
11
|
+
/** Tenant partition field on docs/context. Default `organizationId`. */
|
|
12
|
+
tenantField?: string;
|
|
13
|
+
/** Monotonic per-doc version field. Default `version` (kernel convention). */
|
|
14
|
+
versionField?: string;
|
|
15
|
+
}
|
|
16
|
+
declare function changeLogPlugin(options: ChangeLogPluginOptions): Plugin;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { type AggregateHelpersMethods, type AuditEntry, type AuditOperation, type AuditQueryOptions, type AuditQueryResult, type AuditTrailMethods, type AuditTrailOptions, AuditTrailQuery, type BatchOperationsMethods, type CacheAdapter, type CacheOptions, type ChangeLogPluginOptions, type CustomIdOptions, type DateSequentialIdOptions, type ElasticSearchOptions, type IdGenerator, type LeaseMethods, type LeasePluginOptions, type MethodRegistryRepository, type MongoOperationsMethods, type MultiTenantOptions, type ObservabilityOptions, type OperationMetric, type PrefixedIdOptions, type RepositoryCacheHandle, type RepositoryCachePluginOptions, type SequentialIdOptions, type SoftDeleteMethods, type SubdocumentMethods, type TenantContext, type TenantStore, aggregateHelpersPlugin, auditLogPlugin, auditTrailPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, cascadePlugin, changeLogPlugin, createTenantContext, customIdPlugin, dateSequentialId, elasticSearchPlugin, fieldFilterPlugin, getNextSequence, immutableField, leasePlugin, methodRegistryPlugin, mongoOperationsPlugin, multiTenantPlugin, observabilityPlugin, prefixedId, requireField, sequentialId, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validationChainPlugin };
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,2 +1,72 @@
|
|
|
1
1
|
import { A as auditLogPlugin, C as getNextSequence, D as batchOperationsPlugin, E as cachePlugin, O as AuditTrailQuery, S as dateSequentialId, T as sequentialId, _ as softDeletePlugin, a as uniqueField, b as methodRegistryPlugin, c as subdocumentPlugin, d as leasePlugin, f as fieldFilterPlugin, g as timestampPlugin, h as aggregateHelpersPlugin, i as requireField, k as auditTrailPlugin, l as observabilityPlugin, m as cascadePlugin, n as blockIf, o as validationChainPlugin, p as elasticSearchPlugin, r as immutableField, s as createTenantContext, t as autoInject, u as mongoOperationsPlugin, w as prefixedId, x as customIdPlugin, y as multiTenantPlugin } from "../validation-chain.plugin-DJtC0KJ-.mjs";
|
|
2
|
-
|
|
2
|
+
//#region src/plugins/change-log.plugin.ts
|
|
3
|
+
const PLUGIN_NAME = "changeLog";
|
|
4
|
+
function isSkipped(context) {
|
|
5
|
+
const list = context.skipPlugins;
|
|
6
|
+
return Array.isArray(list) && list.includes(PLUGIN_NAME);
|
|
7
|
+
}
|
|
8
|
+
function changeLogPlugin(options) {
|
|
9
|
+
const { store, scope, tenantField = "organizationId", versionField = "version" } = options;
|
|
10
|
+
const toRecord = (doc) => {
|
|
11
|
+
if (!doc || typeof doc !== "object") return null;
|
|
12
|
+
const d = doc;
|
|
13
|
+
return typeof d.toObject === "function" ? d.toObject() : doc;
|
|
14
|
+
};
|
|
15
|
+
const versionOf = (doc) => {
|
|
16
|
+
const v = doc[versionField] ?? doc.__v;
|
|
17
|
+
if (typeof v === "number") return v;
|
|
18
|
+
const updatedAt = doc.updatedAt;
|
|
19
|
+
return updatedAt instanceof Date ? updatedAt.getTime() : 0;
|
|
20
|
+
};
|
|
21
|
+
const tenantOf = (doc, context) => {
|
|
22
|
+
const raw = doc[tenantField] ?? context.organizationId;
|
|
23
|
+
return raw === void 0 || raw === null ? void 0 : String(raw);
|
|
24
|
+
};
|
|
25
|
+
const capture = async (op, doc, context) => {
|
|
26
|
+
const record = toRecord(doc);
|
|
27
|
+
if (!record || record._id === void 0) return;
|
|
28
|
+
const tenantId = tenantOf(record, context);
|
|
29
|
+
await store.append({
|
|
30
|
+
scope,
|
|
31
|
+
docId: String(record._id),
|
|
32
|
+
op,
|
|
33
|
+
version: versionOf(record),
|
|
34
|
+
...op === "upsert" ? { doc: record } : {},
|
|
35
|
+
...tenantId !== void 0 ? { tenantId } : {}
|
|
36
|
+
}, context.session !== void 0 ? { session: context.session } : void 0);
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
name: PLUGIN_NAME,
|
|
40
|
+
apply(repo) {
|
|
41
|
+
repo.on("after:create", async ({ context, result }) => {
|
|
42
|
+
if (isSkipped(context) || !result) return;
|
|
43
|
+
await capture("upsert", result, context);
|
|
44
|
+
});
|
|
45
|
+
repo.on("after:createMany", async ({ context, result }) => {
|
|
46
|
+
if (isSkipped(context) || !Array.isArray(result)) return;
|
|
47
|
+
for (const doc of result) await capture("upsert", doc, context);
|
|
48
|
+
});
|
|
49
|
+
repo.on("after:update", async ({ context, result }) => {
|
|
50
|
+
if (isSkipped(context) || !result) return;
|
|
51
|
+
await capture("upsert", result, context);
|
|
52
|
+
});
|
|
53
|
+
repo.on("after:delete", async ({ context, result }) => {
|
|
54
|
+
if (isSkipped(context) || !result) return;
|
|
55
|
+
const summary = result;
|
|
56
|
+
const ctxId = context.id;
|
|
57
|
+
const docId = summary.id ?? ctxId;
|
|
58
|
+
if (docId === void 0 || docId === null) return;
|
|
59
|
+
const tenantRaw = context.organizationId;
|
|
60
|
+
await store.append({
|
|
61
|
+
scope,
|
|
62
|
+
docId: String(docId),
|
|
63
|
+
op: "delete",
|
|
64
|
+
version: 0,
|
|
65
|
+
...tenantRaw !== void 0 && tenantRaw !== null ? { tenantId: String(tenantRaw) } : {}
|
|
66
|
+
}, context.session !== void 0 ? { session: context.session } : void 0);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { AuditTrailQuery, aggregateHelpersPlugin, auditLogPlugin, auditTrailPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, cascadePlugin, changeLogPlugin, createTenantContext, customIdPlugin, dateSequentialId, elasticSearchPlugin, fieldFilterPlugin, getNextSequence, immutableField, leasePlugin, methodRegistryPlugin, mongoOperationsPlugin, multiTenantPlugin, observabilityPlugin, prefixedId, requireField, sequentialId, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validationChainPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classytic/mongokit",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.18.0",
|
|
4
4
|
"description": "Production-grade MongoDB repositories - smart pagination, events, and plugins. Built on @classytic/repo-core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
},
|
|
106
106
|
"homepage": "https://github.com/classytic/mongokit#readme",
|
|
107
107
|
"peerDependencies": {
|
|
108
|
-
"@classytic/repo-core": ">=0.
|
|
108
|
+
"@classytic/repo-core": ">=0.7.0",
|
|
109
109
|
"better-auth": ">=1.6.0",
|
|
110
110
|
"mongoose": ">=9.4.1"
|
|
111
111
|
},
|
|
@@ -117,6 +117,9 @@
|
|
|
117
117
|
"engines": {
|
|
118
118
|
"node": ">=22"
|
|
119
119
|
},
|
|
120
|
+
"publishConfig": {
|
|
121
|
+
"access": "public"
|
|
122
|
+
},
|
|
120
123
|
"scripts": {
|
|
121
124
|
"build": "tsdown",
|
|
122
125
|
"dev": "tsdown --watch",
|
|
@@ -138,7 +141,7 @@
|
|
|
138
141
|
"publish:dry": "npm publish --dry-run --access public",
|
|
139
142
|
"publish:npm": "npm publish --access public",
|
|
140
143
|
"release:tag": "node -e \"require('child_process').execSync('npm run push -- v'+require('./package.json').version,{stdio:'inherit'})\"",
|
|
141
|
-
"release": "npm run push -- main && npm run release:tag && npm publish",
|
|
144
|
+
"release": "npm run push -- main && npm run release:tag && npm publish --access public",
|
|
142
145
|
"release:patch": "npm version patch && npm run release",
|
|
143
146
|
"release:minor": "npm version minor && npm run release",
|
|
144
147
|
"release:major": "npm version major && npm run release"
|
|
@@ -149,7 +152,7 @@
|
|
|
149
152
|
"@better-auth/mongo-adapter": "^1.6.22",
|
|
150
153
|
"@biomejs/biome": "^2.4.10",
|
|
151
154
|
"@classytic/dev-tools": "^0.2.0",
|
|
152
|
-
"@classytic/repo-core": "0.
|
|
155
|
+
"@classytic/repo-core": "^0.7.0",
|
|
153
156
|
"@types/node": "^22.0.0",
|
|
154
157
|
"@vitest/coverage-v8": "^4.1.4",
|
|
155
158
|
"ajv": "^8.18.0",
|
|
@@ -157,6 +160,7 @@
|
|
|
157
160
|
"better-auth": "^1.6.22",
|
|
158
161
|
"dotenv": "^17.4.2",
|
|
159
162
|
"knip": "^6.3.0",
|
|
163
|
+
"mongodb": "7.2.0",
|
|
160
164
|
"mongodb-memory-server": "^10.4.3",
|
|
161
165
|
"mongoose": "^9.4.1",
|
|
162
166
|
"publint": "^0.3.18",
|