@classytic/mongokit 3.43.0 → 3.44.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 +14 -0
- package/dist/{PaginationEngine-DZnkbSrr.mjs → PaginationEngine-C9iS0U5l.mjs} +13 -27
- package/dist/{PaginationEngine-CRHyuUtw.d.mts → PaginationEngine-D17AthKw.d.mts} +1 -3
- package/dist/{Repository-DnL4xk5w.d.mts → Repository-B6oL6OMv.d.mts} +33 -11
- package/dist/{Repository-Dj6xqPxJ.mjs → Repository-eMRYZ_2Y.mjs} +204 -92
- package/dist/actions/index.d.mts +1 -1
- package/dist/actions/index.mjs +2 -12
- package/dist/actions-DExyXMTy.mjs +11 -0
- package/dist/adapter/index.d.mts +6 -10
- package/dist/adapter/index.mjs +1 -2
- package/dist/{adapter-CkMoMF83.mjs → adapter-Qzgc3ZD_.mjs} +4 -6
- package/dist/ai/index.d.mts +21 -8
- package/dist/ai/index.mjs +15 -9
- package/dist/better-auth/index.d.mts +18 -32
- package/dist/better-auth/index.mjs +3 -4
- package/dist/{coercion-BjdPX3YF.d.mts → coercion-COp9DRNw.d.mts} +0 -2
- package/dist/{create-repository-CJtVdwig.d.mts → create-repository-BOFUYj1l.d.mts} +5 -7
- package/dist/{create-repository-UjwPWR1z.mjs → create-repository-D7MQpIZo.mjs} +4 -5
- package/dist/{derive-DRBiegRH.mjs → derive-Dxsc31fV.mjs} +3 -6
- package/dist/{error-BuByZwKU.mjs → error-DjdmPLWO.mjs} +1 -2
- package/dist/{field-selection-FSQFLpsU.mjs → field-selection-DPFaFw9Y.mjs} +1 -2
- package/dist/{id-chunks-BmAwsqNk.mjs → id-chunks-DH-RAZWG.mjs} +13 -8
- package/dist/{id-resolution-BqDrk0S2.mjs → id-resolution-Cqh49d9J.mjs} +1 -2
- package/dist/idempotency/index.d.mts +4 -7
- package/dist/idempotency/index.mjs +1 -2
- package/dist/{index-SYF8N28D.d.mts → index-8QUEsOFI.d.mts} +3 -4
- package/dist/{index-C0AjVqX3.d.mts → index-ehGZLbrd.d.mts} +2 -8
- package/dist/index.d.mts +63 -96
- package/dist/index.mjs +36 -52
- package/dist/indexes/verify-indexes.d.mts +8 -11
- package/dist/indexes/verify-indexes.mjs +1 -2
- package/dist/{indexes-DIjMpYES.d.mts → indexes-FfyOuhDK.d.mts} +0 -2
- package/dist/{join-scope-DSAznE8E.mjs → join-scope-C1gOtZ59.mjs} +2 -3
- package/dist/kernel-conformance/index.d.mts +39 -13
- package/dist/kernel-conformance/index.mjs +4 -7
- package/dist/lock/index.d.mts +134 -7
- package/dist/lock/index.mjs +349 -14
- package/dist/{logger-K7dPmu2U.mjs → logger-hbWOlj_X.mjs} +1 -2
- package/dist/{method-registry.plugin-C63pGn1d.mjs → method-registry.plugin-CGAepsBU.mjs} +3 -5
- package/dist/{model-registry-ClKtWiHa.mjs → model-registry-DrVfJ3Nt.mjs} +1 -2
- package/dist/{mongooseToJsonSchema-C3k4ide0.mjs → mongooseToJsonSchema-DMDotz4_.mjs} +2 -3
- package/dist/{multi-tenant.plugin-B_q9NUHc.d.mts → multi-tenant.plugin-DfeDMiI8.d.mts} +143 -11
- package/dist/{operations-XiFgG5US.d.mts → operations-Dw9OFV0V.d.mts} +14 -5
- package/dist/outbox/index.d.mts +24 -9
- package/dist/outbox/index.mjs +17 -6
- package/dist/pagination/PaginationEngine.d.mts +1 -1
- package/dist/pagination/PaginationEngine.mjs +1 -2
- package/dist/pagination/utils/limits.d.mts +6 -9
- package/dist/pagination/utils/limits.mjs +2 -3
- package/dist/{pagination-D6psses0.d.mts → pagination-DAUg5zOY.d.mts} +2 -10
- package/dist/{plugin-options-Cirmb4Kp.d.mts → plugin-options-Bpcuz9kS.d.mts} +2 -4
- package/dist/plugins/index.d.mts +6 -7
- package/dist/plugins/index.mjs +6 -7
- package/dist/query/primitives/coercion.d.mts +1 -1
- package/dist/query/primitives/coercion.mjs +2 -3
- package/dist/query/primitives/geo.d.mts +11 -14
- package/dist/query/primitives/geo.mjs +1 -2
- package/dist/query/primitives/indexes.d.mts +1 -1
- package/dist/query/primitives/indexes.mjs +1 -2
- package/dist/{query-defaults-BxUcSOoF.mjs → query-defaults-aUoKlEbh.mjs} +2 -3
- package/dist/read-model/index.d.mts +18 -21
- package/dist/read-model/index.mjs +3 -4
- package/dist/{repository-MqAP409e.d.mts → repository-DzVIwhU2.d.mts} +25 -29
- package/dist/retention-purge-DqcYvRnG.d.mts +35 -0
- package/dist/{rolldown-runtime-D7D4PA-g.mjs → rolldown-runtime-D8jQpDG7.mjs} +1 -2
- package/dist/search/index.d.mts +1 -1
- package/dist/search/index.mjs +1 -2
- package/dist/sync/index.d.mts +95 -15
- package/dist/sync/index.mjs +308 -62
- package/dist/tenant/index.d.mts +8 -11
- package/dist/tenant/index.mjs +1 -2
- package/dist/testkit/index.d.mts +179 -23
- package/dist/testkit/index.mjs +421 -23
- package/dist/{timestamp.plugin-DpOWavVI.mjs → timestamp.plugin-Bz_zL9PX.mjs} +192 -49
- package/dist/{to-plain-vksRrLtc.mjs → to-plain-CEKv_ylg.mjs} +2 -4
- package/dist/{to-plain-o5tUY2nV.d.mts → to-plain-PO5r1Qoy.d.mts} +2 -16
- package/dist/{transaction-DmiB4k2P.mjs → transaction-C2PFxfIv.mjs} +5 -8
- package/dist/{type-utils-CLzRFtIA.d.mts → type-utils-CKvuewAL.d.mts} +0 -2
- package/dist/{update-WgeAUJ_I.mjs → update-DcfmNbJe.mjs} +12 -20
- package/dist/usage/index.d.mts +2 -5
- package/dist/usage/index.mjs +8 -6
- package/dist/utils/index.d.mts +8 -10
- package/dist/utils/index.mjs +7 -7
- package/dist/{validation-chain.plugin-BAeC5eVT.d.mts → validation-chain.plugin-B3gZCZj4.d.mts} +135 -48
- package/dist/{validation-chain.plugin-DRApTmkN.mjs → validation-chain.plugin-DNY6MIF6.mjs} +207 -55
- package/llms.txt +33 -0
- package/package.json +29 -25
- package/skills/mongokit/SKILL.md +112 -0
- package/skills/mongokit/references/pagination-search.md +87 -0
- package/skills/mongokit/references/plugins-tenancy.md +102 -0
- package/skills/mongokit/references/repository-api.md +83 -0
- package/skills/mongokit/references/transactions-outbox.md +101 -0
package/dist/index.mjs
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { n as idVariants } from "./id-resolution-
|
|
2
|
-
import { a as ALL_OPERATIONS, c as READ_OPERATIONS, i as searchKeysPlugin, l as operationsByPolicyKey, n as Repository, o as MUTATING_OPERATIONS, r as AggregationBuilder, s as OP_REGISTRY, t as HOOK_PRIORITY, u as createMongoPurgePort } from "./Repository-
|
|
3
|
-
import { C as isCreateManyPartialError, g as LookupBuilder, v as compileFilterToMongo } from "./update-
|
|
4
|
-
import {
|
|
5
|
-
import { n as
|
|
6
|
-
import {
|
|
7
|
-
import { t as
|
|
8
|
-
import {
|
|
9
|
-
import { _ as
|
|
10
|
-
import { n as
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
1
|
+
import { n as idVariants } from "./id-resolution-Cqh49d9J.mjs";
|
|
2
|
+
import { a as ALL_OPERATIONS, c as READ_OPERATIONS, d as RETENTION_PURGE_ERROR_CODES, i as searchKeysPlugin, l as operationsByPolicyKey, n as Repository, o as MUTATING_OPERATIONS, r as AggregationBuilder, s as OP_REGISTRY, t as HOOK_PRIORITY, u as createMongoPurgePort } from "./Repository-eMRYZ_2Y.mjs";
|
|
3
|
+
import { C as isCreateManyPartialError, g as LookupBuilder, v as compileFilterToMongo } from "./update-DcfmNbJe.mjs";
|
|
4
|
+
import { t as actions_exports } from "./actions-DExyXMTy.mjs";
|
|
5
|
+
import { a as supportsTransactions, c as MONGOKIT_CAPABILITIES, d as probeMongoCapabilities, f as resetCapabilityProbeCache, h as transactionResolutionOf, i as runTransaction, l as capabilitiesForSupport, m as resolveTransactionSupport, n as batchTransaction, o as withTransaction, p as resolveMongoCapabilities, r as isTransactionUnsupported, t as TRANSACTION_ERROR_CODES, u as classifyHelloReply } from "./transaction-C2PFxfIv.mjs";
|
|
6
|
+
import { t as createRepository } from "./create-repository-D7MQpIZo.mjs";
|
|
7
|
+
import { n as defineModel, r as isModelRegistered, t as ModelCollisionError } from "./model-registry-DrVfJ3Nt.mjs";
|
|
8
|
+
import { c as PAGINATION_ERROR_CODES, h as resetPaginationDefaults, m as getPaginationDefaults, p as configurePaginationDefaults, t as PaginationEngine } from "./PaginationEngine-C9iS0U5l.mjs";
|
|
9
|
+
import { C as ensureAuditTrailReady, S as auditTrailPlugin, _ as prefixedId, a as declareTenantContextKey, b as cachePlugin, c as tenantContextKeysOf, d as customIdPlugin, f as dateSequentialId, g as periodCounterKey, h as getNextSequence, i as multiTenantPlugin, l as civilPeriodKey, m as getNextPeriodSequence, n as softDeletePlugin, o as forwardScope, p as ensureSequenceAtLeast, r as adminBypass, s as isScopeKey, t as timestampPlugin, u as createSequenceCounter, v as readSequence, w as auditLogPlugin, x as AuditTrailQuery, y as sequentialId } from "./timestamp.plugin-Bz_zL9PX.mjs";
|
|
10
|
+
import { _ as cascadePlugin, a as uniqueField, c as subdocumentPlugin, d as mongoOperationsPlugin, f as leasePlugin, g as elasticSearchPlugin, h as fieldFilterPlugin, i as requireField, l as observabilityPlugin, m as idempotencyStorePlugin, n as blockIf, o as validationChainPlugin, p as immutableStatesPlugin, r as immutableField, s as createTenantContext, t as autoInject, u as MONGOKIT_PLUGIN_NAMES, v as appendOnlyPlugin, y as aggregateHelpersPlugin } from "./validation-chain.plugin-DNY6MIF6.mjs";
|
|
11
|
+
import { n as batchOperationsPlugin, t as methodRegistryPlugin } from "./method-registry.plugin-CGAepsBU.mjs";
|
|
12
|
+
import { n as warn, t as configureLogger } from "./logger-hbWOlj_X.mjs";
|
|
13
13
|
import { GEO_OPERATORS, parseGeoFilter } from "./query/primitives/geo.mjs";
|
|
14
|
-
import { n as declareCollectionScope, t as JOIN_ERROR_CODES } from "./join-scope-DSAznE8E.mjs";
|
|
15
|
-
import { t as createRepository } from "./create-repository-UjwPWR1z.mjs";
|
|
16
|
-
import { n as defineModel, r as isModelRegistered, t as ModelCollisionError } from "./model-registry-ClKtWiHa.mjs";
|
|
17
|
-
import { _ as cascadePlugin, a as uniqueField, c as subdocumentPlugin, d as mongoOperationsPlugin, f as leasePlugin, g as elasticSearchPlugin, h as fieldFilterPlugin, i as requireField, l as observabilityPlugin, m as idempotencyStorePlugin, n as blockIf, o as validationChainPlugin, p as immutableStatesPlugin, r as immutableField, s as createTenantContext, t as autoInject, u as MONGOKIT_PLUGIN_NAMES, v as appendOnlyPlugin, y as aggregateHelpersPlugin } from "./validation-chain.plugin-DRApTmkN.mjs";
|
|
18
|
-
import { i as getMongooseProjection, n as filterResponseData, r as getFieldsForUser, t as createFieldPreset } from "./field-selection-FSQFLpsU.mjs";
|
|
19
14
|
import { buildFieldTypeMap, coerceHeuristic } from "./query/primitives/coercion.mjs";
|
|
15
|
+
import { n as isDuplicateKeyError, r as parseDuplicateKeyError, t as createError } from "./error-DjdmPLWO.mjs";
|
|
20
16
|
import { extractSchemaIndexes } from "./query/primitives/indexes.mjs";
|
|
17
|
+
import { n as declareCollectionScope, t as JOIN_ERROR_CODES } from "./join-scope-C1gOtZ59.mjs";
|
|
18
|
+
import { a as assertQueryDefaultsConfigured, c as getQueryDefaults, l as resetQueryDefaults, o as configureAggregateDefaults, s as configureQueryDefaults, t as QUERY_DEFAULTS_ERROR_CODES, u as resolveQueryOptions } from "./query-defaults-aUoKlEbh.mjs";
|
|
19
|
+
import { _ as tokenizeSearchText, d as buildSearchKeys, f as prefixSearchFilter, g as normalizeSearchText, h as findSearchMatches, l as DEFAULT_SEARCH_KEYS_FIELD, m as searchKeysPath, n as SearchKeysWriteError, p as searchKeysIndex, t as SEARCH_KEYS_ERROR_CODES, u as MAX_PREFIX_SEARCH_TERMS } from "./derive-Dxsc31fV.mjs";
|
|
20
|
+
import { i as getMongooseProjection, n as filterResponseData, r as getFieldsForUser, t as createFieldPreset } from "./field-selection-DPFaFw9Y.mjs";
|
|
21
21
|
import "./search/index.mjs";
|
|
22
|
-
import { n as createMemoryCache, t as toPlain } from "./to-plain-
|
|
23
|
-
import { n as buildCrudSchemasFromMongooseSchema, t as buildCrudSchemasFromModel } from "./mongooseToJsonSchema-
|
|
22
|
+
import { n as createMemoryCache, t as toPlain } from "./to-plain-CEKv_ylg.mjs";
|
|
23
|
+
import { n as buildCrudSchemasFromMongooseSchema, t as buildCrudSchemasFromModel } from "./mongooseToJsonSchema-DMDotz4_.mjs";
|
|
24
24
|
import { runChunkedPurge } from "@classytic/repo-core/repository";
|
|
25
25
|
import { stableStringify } from "@classytic/repo-core/hash";
|
|
26
26
|
import { OPERATOR_DESCRIPTIONS, QueryGrammarError, URL_OPERATORS, clausesToFilter, escapeRegex, isQueryGrammarError, readFilterClauses, readPageRequest, readSearch, readSelect, readSort } from "@classytic/repo-core/query-parser";
|
|
27
|
-
|
|
27
|
+
// src/actions/cascade-references.ts
|
|
28
28
|
/**
|
|
29
29
|
* cascadePurgeReferences — imperative, multi-relation "purge by reference".
|
|
30
30
|
*
|
|
@@ -152,8 +152,7 @@ async function cascadePurgeReferences(options) {
|
|
|
152
152
|
for (const rel of relations) out.push(await purgeRelation(rel, match, mode, ctx));
|
|
153
153
|
return out;
|
|
154
154
|
}
|
|
155
|
-
|
|
156
|
-
//#region src/model-blueprint.ts
|
|
155
|
+
// src/model-blueprint.ts
|
|
157
156
|
function isProductionRuntime() {
|
|
158
157
|
return process.env.NODE_ENV === "production";
|
|
159
158
|
}
|
|
@@ -223,8 +222,7 @@ function defineModels(spec) {
|
|
|
223
222
|
}
|
|
224
223
|
};
|
|
225
224
|
}
|
|
226
|
-
|
|
227
|
-
//#region src/pagination/keyset-source.ts
|
|
225
|
+
// src/pagination/keyset-source.ts
|
|
228
226
|
/**
|
|
229
227
|
* `keysetSource(repo, { name, sort, filters, ...scope })` — a mongokit repository as a repo-core
|
|
230
228
|
* `KeysetSource`, for `mergeKeysetPages`. Pages are `getAll({ mode: 'keyset' })` under the given
|
|
@@ -262,8 +260,7 @@ function keysetSource(repo, options) {
|
|
|
262
260
|
})
|
|
263
261
|
};
|
|
264
262
|
}
|
|
265
|
-
|
|
266
|
-
//#region src/query/parser/pipeline-sanitizer.ts
|
|
263
|
+
// src/query/parser/pipeline-sanitizer.ts
|
|
267
264
|
/**
|
|
268
265
|
* Sanitize $match configuration to prevent dangerous operators.
|
|
269
266
|
* Recursively filters out operators like $where, $function, $accumulator.
|
|
@@ -372,8 +369,7 @@ function sanitizeExpressions(rt, config, depth = 0) {
|
|
|
372
369
|
}
|
|
373
370
|
return sanitized;
|
|
374
371
|
}
|
|
375
|
-
|
|
376
|
-
//#region src/query/parser/aggregation.ts
|
|
372
|
+
// src/query/parser/aggregation.ts
|
|
377
373
|
/**
|
|
378
374
|
* Parse aggregation pipeline from URL (advanced feature).
|
|
379
375
|
*
|
|
@@ -401,8 +397,7 @@ function parseAggregation(rt, aggregate) {
|
|
|
401
397
|
}
|
|
402
398
|
return pipeline.length > 0 ? pipeline : void 0;
|
|
403
399
|
}
|
|
404
|
-
|
|
405
|
-
//#region src/query/parser/filter-compiler.ts
|
|
400
|
+
// src/query/parser/filter-compiler.ts
|
|
406
401
|
/**
|
|
407
402
|
* URL filters → a MongoDB filter. The grammar (keys, operators, value coercion, refusals) is
|
|
408
403
|
* repo-core's `readFilterClauses`; its clauses compile through the Filter IR compiler every
|
|
@@ -531,8 +526,7 @@ function toGrammarFieldTypes(types) {
|
|
|
531
526
|
function isRecord(value) {
|
|
532
527
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
533
528
|
}
|
|
534
|
-
|
|
535
|
-
//#region src/query/parser/lookup.ts
|
|
529
|
+
// src/query/parser/lookup.ts
|
|
536
530
|
function pluralize(str) {
|
|
537
531
|
if (str.endsWith("y")) return `${str.slice(0, -1)}ies`;
|
|
538
532
|
if (str.endsWith("s")) return str;
|
|
@@ -606,8 +600,7 @@ function parseSingleLookup(rt, collectionName, config) {
|
|
|
606
600
|
}
|
|
607
601
|
return null;
|
|
608
602
|
}
|
|
609
|
-
|
|
610
|
-
//#region src/query/parser/runtime.ts
|
|
603
|
+
// src/query/parser/runtime.ts
|
|
611
604
|
/**
|
|
612
605
|
* Parser runtime — the shared context every parser module receives.
|
|
613
606
|
*
|
|
@@ -646,8 +639,7 @@ function guarded(rt, read, fallback) {
|
|
|
646
639
|
return fallback;
|
|
647
640
|
}
|
|
648
641
|
}
|
|
649
|
-
|
|
650
|
-
//#region src/query/parser/sort-select.ts
|
|
642
|
+
// src/query/parser/sort-select.ts
|
|
651
643
|
/**
|
|
652
644
|
* `?sort=-createdAt,name` and `?select=name,-password` — read through the shared grammar
|
|
653
645
|
* (`readSort` / `readSelect`), so an invalid or disallowed field is refused like any filter.
|
|
@@ -672,8 +664,7 @@ function parseSort(rt, sort) {
|
|
|
672
664
|
function parseSelect(rt, select) {
|
|
673
665
|
return guarded(rt, () => readSelect(select), void 0);
|
|
674
666
|
}
|
|
675
|
-
|
|
676
|
-
//#region src/query/parser/populate.ts
|
|
667
|
+
// src/query/parser/populate.ts
|
|
677
668
|
/**
|
|
678
669
|
* Populate parsing — simple string form (`?populate=author,category`) and
|
|
679
670
|
* qs-nested advanced form (`?populate[author][select]=name,email`), with
|
|
@@ -790,8 +781,7 @@ function convertPopulateMatch(rt, path, match) {
|
|
|
790
781
|
}
|
|
791
782
|
return converted;
|
|
792
783
|
}
|
|
793
|
-
|
|
794
|
-
//#region src/query/parser/schema-docs.ts
|
|
784
|
+
// src/query/parser/schema-docs.ts
|
|
795
785
|
/**
|
|
796
786
|
* OpenAPI query-schema generation — Arc's `defineResource()` auto-detects
|
|
797
787
|
* `getQuerySchema()` on the parser and uses it to document list-endpoint
|
|
@@ -932,8 +922,7 @@ function buildOpenAPIQuerySchema(rt) {
|
|
|
932
922
|
};
|
|
933
923
|
return schema;
|
|
934
924
|
}
|
|
935
|
-
|
|
936
|
-
//#region src/query/parser/search.ts
|
|
925
|
+
// src/query/parser/search.ts
|
|
937
926
|
/**
|
|
938
927
|
* `?search=` — length-checked through the shared grammar. Regex mode matches the term as LITERAL
|
|
939
928
|
* text across `searchFields` (`c++` and `a.b` mean exactly those characters).
|
|
@@ -947,8 +936,7 @@ function buildRegexSearch(rt, searchTerm) {
|
|
|
947
936
|
const pattern = new RegExp(escapeRegex(searchTerm), "i");
|
|
948
937
|
return fields.map((field) => ({ [field]: { $regex: pattern } }));
|
|
949
938
|
}
|
|
950
|
-
|
|
951
|
-
//#region src/query/QueryParser.ts
|
|
939
|
+
// src/query/QueryParser.ts
|
|
952
940
|
/**
|
|
953
941
|
* Modern Query Parser - URL to MongoDB Query Transpiler
|
|
954
942
|
*
|
|
@@ -1184,8 +1172,7 @@ function attachCondition(filters, condition) {
|
|
|
1184
1172
|
$and: and
|
|
1185
1173
|
};
|
|
1186
1174
|
}
|
|
1187
|
-
|
|
1188
|
-
//#region src/search/rebuild.ts
|
|
1175
|
+
// src/search/rebuild.ts
|
|
1189
1176
|
const sameKeys = (a, b) => Array.isArray(a) && a.length === b.length && a.every((v, i) => v === b[i]);
|
|
1190
1177
|
async function rebuildSearchKeys(source, options = {}) {
|
|
1191
1178
|
const repo = typeof source === "function" ? void 0 : source;
|
|
@@ -1230,8 +1217,7 @@ async function rebuildSearchKeys(source, options = {}) {
|
|
|
1230
1217
|
updated
|
|
1231
1218
|
};
|
|
1232
1219
|
}
|
|
1233
|
-
|
|
1234
|
-
//#region src/utils/repo-options.ts
|
|
1220
|
+
// src/utils/repo-options.ts
|
|
1235
1221
|
/**
|
|
1236
1222
|
* Forward request-scoped context fields into a mongokit options bag.
|
|
1237
1223
|
*
|
|
@@ -1443,8 +1429,7 @@ function systemContext(extra) {
|
|
|
1443
1429
|
bypassTenant: true
|
|
1444
1430
|
};
|
|
1445
1431
|
}
|
|
1446
|
-
|
|
1447
|
-
//#region src/index.ts
|
|
1432
|
+
// src/index.ts
|
|
1448
1433
|
/**
|
|
1449
1434
|
* MongoKit - Event-driven repository pattern for MongoDB
|
|
1450
1435
|
*
|
|
@@ -1484,5 +1469,4 @@ function systemContext(extra) {
|
|
|
1484
1469
|
* ```
|
|
1485
1470
|
*/
|
|
1486
1471
|
var src_default = Repository;
|
|
1487
|
-
|
|
1488
|
-
export { ALL_OPERATIONS, AggregationBuilder, AuditTrailQuery, DEFAULT_SEARCH_KEYS_FIELD, HOOK_PRIORITY, JOIN_ERROR_CODES, LookupBuilder, MAX_PREFIX_SEARCH_TERMS, MONGOKIT_CAPABILITIES, MONGOKIT_PLUGIN_NAMES, MUTATING_OPERATIONS, ModelCollisionError, OP_REGISTRY, PAGINATION_ERROR_CODES, PaginationEngine, QUERY_DEFAULTS_ERROR_CODES, QueryParser, READ_OPERATIONS, Repository, SEARCH_KEYS_ERROR_CODES, SearchKeysWriteError, TRANSACTION_ERROR_CODES, actions_exports as actions, adminBypass, aggregateHelpersPlugin, appendOnlyPlugin, assertQueryDefaultsConfigured, auditLogPlugin, auditTrailPlugin, autoInject, batchOperationsPlugin, batchTransaction, blockIf, buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, buildSearchKeys, cachePlugin, capabilitiesForSupport, cascadePlugin, cascadePurgeReferences, classifyHelloReply, compileFilterToMongo, configureAggregateDefaults, configureLogger, configurePaginationDefaults, configureQueryDefaults, createError, createFieldPreset, createMemoryCache, createOptionsExtractor, createRepository, createTenantContext, customIdPlugin, dateSequentialId, declareCollectionScope, declareTenantContextKey, src_default as default, defineModel, defineModels, elasticSearchPlugin, ensureAuditTrailReady, ensureSequenceAtLeast, fieldFilterPlugin, filterResponseData, findSearchMatches, forwardScope, getFieldsForUser, getMongooseProjection, getNextSequence, getPaginationDefaults, getQueryDefaults, idVariants, idempotencyStorePlugin, immutableField, immutableStatesPlugin, isCreateManyPartialError, isDuplicateKeyError, isModelRegistered, isTransactionUnsupported, keysetSource, leasePlugin, methodRegistryPlugin, mongoOperationsPlugin, multiTenantPlugin, normalizeSearchText, observabilityPlugin, operationsByPolicyKey, parseDuplicateKeyError, prefixSearchFilter, prefixedId, probeMongoCapabilities, readSequence, rebuildSearchKeys, repoOptionsFromCtx, requireField, resetCapabilityProbeCache, resetPaginationDefaults, resetQueryDefaults, resolveMongoCapabilities, resolveQueryOptions, resolveTransactionSupport, runTransaction, searchKeysIndex, searchKeysPath, searchKeysPlugin, sequentialId, softDeletePlugin, subdocumentPlugin, supportsTransactions, systemContext, tenantContextKeysOf, timestampPlugin, toPlain, tokenizeSearchText, transactionResolutionOf, uniqueField, validationChainPlugin, withTransaction };
|
|
1472
|
+
export { ALL_OPERATIONS, AggregationBuilder, AuditTrailQuery, DEFAULT_SEARCH_KEYS_FIELD, HOOK_PRIORITY, JOIN_ERROR_CODES, LookupBuilder, MAX_PREFIX_SEARCH_TERMS, MONGOKIT_CAPABILITIES, MONGOKIT_PLUGIN_NAMES, MUTATING_OPERATIONS, ModelCollisionError, OP_REGISTRY, PAGINATION_ERROR_CODES, PaginationEngine, QUERY_DEFAULTS_ERROR_CODES, QueryParser, READ_OPERATIONS, RETENTION_PURGE_ERROR_CODES, Repository, SEARCH_KEYS_ERROR_CODES, SearchKeysWriteError, TRANSACTION_ERROR_CODES, actions_exports as actions, adminBypass, aggregateHelpersPlugin, appendOnlyPlugin, assertQueryDefaultsConfigured, auditLogPlugin, auditTrailPlugin, autoInject, batchOperationsPlugin, batchTransaction, blockIf, buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, buildSearchKeys, cachePlugin, capabilitiesForSupport, cascadePlugin, cascadePurgeReferences, civilPeriodKey, classifyHelloReply, compileFilterToMongo, configureAggregateDefaults, configureLogger, configurePaginationDefaults, configureQueryDefaults, createError, createFieldPreset, createMemoryCache, createOptionsExtractor, createRepository, createSequenceCounter, createTenantContext, customIdPlugin, dateSequentialId, declareCollectionScope, declareTenantContextKey, src_default as default, defineModel, defineModels, elasticSearchPlugin, ensureAuditTrailReady, ensureSequenceAtLeast, fieldFilterPlugin, filterResponseData, findSearchMatches, forwardScope, getFieldsForUser, getMongooseProjection, getNextPeriodSequence, getNextSequence, getPaginationDefaults, getQueryDefaults, idVariants, idempotencyStorePlugin, immutableField, immutableStatesPlugin, isCreateManyPartialError, isDuplicateKeyError, isModelRegistered, isTransactionUnsupported, keysetSource, leasePlugin, methodRegistryPlugin, mongoOperationsPlugin, multiTenantPlugin, normalizeSearchText, observabilityPlugin, operationsByPolicyKey, parseDuplicateKeyError, periodCounterKey, prefixSearchFilter, prefixedId, probeMongoCapabilities, readSequence, rebuildSearchKeys, repoOptionsFromCtx, requireField, resetCapabilityProbeCache, resetPaginationDefaults, resetQueryDefaults, resolveMongoCapabilities, resolveQueryOptions, resolveTransactionSupport, runTransaction, searchKeysIndex, searchKeysPath, searchKeysPlugin, sequentialId, softDeletePlugin, subdocumentPlugin, supportsTransactions, systemContext, tenantContextKeysOf, timestampPlugin, toPlain, tokenizeSearchText, transactionResolutionOf, uniqueField, validationChainPlugin, withTransaction };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/indexes/verify-indexes.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Compare DECLARED indexes against what a database actually has.
|
|
4
3
|
*
|
|
@@ -27,11 +26,11 @@
|
|
|
27
26
|
* touches no connection. This module is the live comparison.
|
|
28
27
|
*/
|
|
29
28
|
/** The slice of a Mongoose-like connection this needs. Structural on purpose. */
|
|
30
|
-
interface IndexVerifiableConnection {
|
|
29
|
+
export interface IndexVerifiableConnection {
|
|
31
30
|
modelNames(): string[];
|
|
32
31
|
model(name: string): IndexVerifiableModel;
|
|
33
32
|
}
|
|
34
|
-
interface IndexVerifiableModel {
|
|
33
|
+
export interface IndexVerifiableModel {
|
|
35
34
|
schema: {
|
|
36
35
|
indexes(): Array<[Record<string, unknown>, Record<string, unknown>?]>;
|
|
37
36
|
};
|
|
@@ -42,20 +41,20 @@ interface IndexVerifiableModel {
|
|
|
42
41
|
};
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
|
-
interface MissingIndex {
|
|
44
|
+
export interface MissingIndex {
|
|
46
45
|
model: string;
|
|
47
46
|
collection: string;
|
|
48
47
|
/** The declared key, JSON-stringified — stable to log and to diff. */
|
|
49
48
|
key: string;
|
|
50
49
|
}
|
|
51
50
|
/** A live index on the declared keys whose correctness options differ from the declaration. */
|
|
52
|
-
interface IncompatibleIndex extends MissingIndex {
|
|
51
|
+
export interface IncompatibleIndex extends MissingIndex {
|
|
53
52
|
/** Declared `unique` — a mismatch here can already have admitted duplicates. */
|
|
54
53
|
unique: boolean;
|
|
55
54
|
/** One line per differing option: `unique: declared true, live false`. */
|
|
56
55
|
differences: string[];
|
|
57
56
|
}
|
|
58
|
-
interface IndexVerifyReport {
|
|
57
|
+
export interface IndexVerifyReport {
|
|
59
58
|
modelsChecked: number;
|
|
60
59
|
/** Declared `unique` indexes with nothing behind them. Duplicates can already exist. */
|
|
61
60
|
missingUnique: MissingIndex[];
|
|
@@ -65,7 +64,7 @@ interface IndexVerifyReport {
|
|
|
65
64
|
/** Models whose indexes could not be read — collection absent, or no permission. */
|
|
66
65
|
unreadable: string[];
|
|
67
66
|
}
|
|
68
|
-
interface VerifyIndexesOptions {
|
|
67
|
+
export interface VerifyIndexesOptions {
|
|
69
68
|
/**
|
|
70
69
|
* Include a model in the sweep. Default: every model.
|
|
71
70
|
*
|
|
@@ -75,8 +74,6 @@ interface VerifyIndexesOptions {
|
|
|
75
74
|
*/
|
|
76
75
|
includeModel?: (modelName: string) => boolean;
|
|
77
76
|
}
|
|
78
|
-
declare function verifyIndexes(connection: IndexVerifiableConnection, options?: VerifyIndexesOptions): Promise<IndexVerifyReport>;
|
|
77
|
+
export declare function verifyIndexes(connection: IndexVerifiableConnection, options?: VerifyIndexesOptions): Promise<IndexVerifyReport>;
|
|
79
78
|
/** One-line summary for a boot log. */
|
|
80
|
-
declare function formatIndexReport(report: IndexVerifyReport): string;
|
|
81
|
-
//#endregion
|
|
82
|
-
export { IncompatibleIndex, IndexVerifiableConnection, IndexVerifiableModel, IndexVerifyReport, MissingIndex, VerifyIndexesOptions, formatIndexReport, verifyIndexes };
|
|
79
|
+
export declare function formatIndexReport(report: IndexVerifyReport): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/indexes/verify-indexes.ts
|
|
2
2
|
/**
|
|
3
3
|
* Order-sensitive: a compound index is not the same index with keys swapped.
|
|
4
4
|
*
|
|
@@ -119,5 +119,4 @@ function formatIndexReport(report) {
|
|
|
119
119
|
if (report.unreadable.length > 0) parts.push(`unreadable: ${report.unreadable.length}`);
|
|
120
120
|
return `[index-check] ${parts.join(" — ")}`;
|
|
121
121
|
}
|
|
122
|
-
//#endregion
|
|
123
122
|
export { formatIndexReport, verifyIndexes };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/query/primitives/indexes.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Schema index introspection
|
|
4
3
|
*
|
|
@@ -37,5 +36,4 @@ interface SchemaIndexes {
|
|
|
37
36
|
* can read `.geoFields`/`.textFields` unconditionally without null checks.
|
|
38
37
|
*/
|
|
39
38
|
declare function extractSchemaIndexes(schema?: IndexableSchema | null): SchemaIndexes;
|
|
40
|
-
//#endregion
|
|
41
39
|
export { SchemaIndexes as n, extractSchemaIndexes as r, IndexableSchema as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createError } from "./error-
|
|
1
|
+
import { t as createError } from "./error-DjdmPLWO.mjs";
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
|
-
|
|
3
|
+
// src/repository/join-scope.ts
|
|
4
4
|
/**
|
|
5
5
|
* Join scope — a joined collection is read under ITS OWN policy, or not at all.
|
|
6
6
|
*
|
|
@@ -164,5 +164,4 @@ function walk(pipeline, env) {
|
|
|
164
164
|
return stage;
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
|
-
//#endregion
|
|
168
167
|
export { scopeJoins as a, scopeForCollection as i, declareCollectionScope as n, tenantFieldsOf as o, markGoverned as r, JOIN_ERROR_CODES as t };
|
|
@@ -1,19 +1,50 @@
|
|
|
1
1
|
import { Connection } from "mongoose";
|
|
2
|
-
//#region src/kernel-conformance/types.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Every check the suite can run, in execution order. The ids are STABLE — `skip` is typed
|
|
5
4
|
* against this tuple, so a typo is a compile error rather than a silently-ineffective skip
|
|
6
5
|
* (a skip that skips nothing is the same silent-permissiveness bug class the suite exists
|
|
7
6
|
* to catch).
|
|
8
7
|
*/
|
|
9
|
-
declare const KERNEL_CONFORMANCE_CHECKS: readonly [
|
|
8
|
+
export declare const KERNEL_CONFORMANCE_CHECKS: readonly [
|
|
9
|
+
/** §11.1 — `defineX(shape)` registers no model and performs no I/O. */
|
|
10
|
+
'describe-purity',
|
|
11
|
+
/** §11.1 — `modelNames` is non-empty, frozen, and matches `expectedModelNames`. */
|
|
12
|
+
'blueprint-model-names',
|
|
13
|
+
/** §11.1 — after `bind`, the connection holds EXACTLY the declared models. */
|
|
14
|
+
'bind-registers-declared-models',
|
|
15
|
+
/** §5.2 — `bind` uses the supplied connection's registry, never the global one. */
|
|
16
|
+
'bind-connection-scoped',
|
|
17
|
+
/** §11.11 — `bind` never synchronizes, creates or drops indexes. */
|
|
18
|
+
'bind-no-index-io',
|
|
19
|
+
/** §8.1 — every bound schema disables mongoose's own `autoIndex` build. */
|
|
20
|
+
'no-autoindex-on-bind',
|
|
21
|
+
/** §11.3 — a schema factory produces a FRESH schema per connection. */
|
|
22
|
+
'fresh-schema-per-connection',
|
|
23
|
+
/** §11.2/§11.12 — a second bind on one connection throws mongokit `ModelCollisionError`. */
|
|
24
|
+
'double-bind-collision',
|
|
25
|
+
/** §11.7 — a host-SUPPLIED transport is never closed by the engine. */
|
|
26
|
+
'transport-not-closed-when-supplied',
|
|
27
|
+
/** §11.7 — the internally-created bus IS closed by `close()`. */
|
|
28
|
+
'owned-transport-closed',
|
|
29
|
+
/** §6.4 — `close()` is idempotent. */
|
|
30
|
+
'close-idempotent',
|
|
31
|
+
/** §11.12 — one construction API (`defineX`), one teardown name (`close`). */
|
|
32
|
+
'no-legacy-surface',
|
|
33
|
+
/** §8 — a failing index sync REJECTS; it is never swallowed. */
|
|
34
|
+
'maintenance-fails-loud',
|
|
35
|
+
/** §11.5 — unmet runtime capability requirements fail the bind. (conditional) */
|
|
36
|
+
'bind-verifies-requirements',
|
|
37
|
+
/** §11.5 — an injected outbox that does not enlist `ctx.session` is REFUSED. (conditional) */
|
|
38
|
+
'outbox-requires-transactional-save',
|
|
39
|
+
/** §11.10 — a blueprint with optional modules off registers no extra models. (conditional) */
|
|
40
|
+
'optional-modules-register-no-models'];
|
|
10
41
|
type ConformanceCheck = (typeof KERNEL_CONFORMANCE_CHECKS)[number];
|
|
11
42
|
/**
|
|
12
43
|
* Checks that only run when the kernel supplies the input they need. When the input is
|
|
13
44
|
* absent they are reported as NOT EXERCISED — a visible marker test plus a report entry,
|
|
14
45
|
* never a silent pass.
|
|
15
46
|
*/
|
|
16
|
-
declare const CONDITIONAL_CHECKS: readonly ["bind-verifies-requirements", "outbox-requires-transactional-save", "optional-modules-register-no-models"];
|
|
47
|
+
export declare const CONDITIONAL_CHECKS: readonly ["bind-verifies-requirements", "outbox-requires-transactional-save", "optional-modules-register-no-models"];
|
|
17
48
|
/**
|
|
18
49
|
* The two runner functions the suite needs, INJECTED by the consumer.
|
|
19
50
|
*
|
|
@@ -192,15 +223,11 @@ interface KernelConformanceOptions<TBlueprint extends KernelBlueprintLike, TEngi
|
|
|
192
223
|
/** Receives the manifest before any test runs. Defaults to a `console` summary. */
|
|
193
224
|
readonly onReport?: (report: KernelConformanceReport) => void;
|
|
194
225
|
}
|
|
195
|
-
|
|
196
|
-
//#region src/kernel-conformance/suite.d.ts
|
|
197
|
-
declare function describeKernelConformance<TBlueprint extends KernelBlueprintLike, TEngine>(opts: KernelConformanceOptions<TBlueprint, TEngine>): void;
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region src/kernel-conformance/transport.d.ts
|
|
226
|
+
export declare function describeKernelConformance<TBlueprint extends KernelBlueprintLike, TEngine>(opts: KernelConformanceOptions<TBlueprint, TEngine>): void;
|
|
200
227
|
/** A minimal, valid domain-event envelope (`type` + `meta.id` is all any bus reads). */
|
|
201
|
-
declare function conformanceEvent(type: string): ConformanceEvent;
|
|
228
|
+
export declare function conformanceEvent(type: string): ConformanceEvent;
|
|
202
229
|
/** An in-process transport good enough to stand in for a host-owned shared bus. */
|
|
203
|
-
declare function createConformanceTransport(name?: string): EventTransportLike;
|
|
230
|
+
export declare function createConformanceTransport(name?: string): EventTransportLike;
|
|
204
231
|
interface InstrumentedTransport {
|
|
205
232
|
/** Hand THIS to the kernel. */
|
|
206
233
|
readonly transport: EventTransportLike;
|
|
@@ -212,6 +239,5 @@ interface InstrumentedTransport {
|
|
|
212
239
|
* the kernel cannot tell the difference — which is the point: ownership must be decided by
|
|
213
240
|
* "did I create this?", never by inspecting the object.
|
|
214
241
|
*/
|
|
215
|
-
declare function instrumentTransport(inner: EventTransportLike): InstrumentedTransport;
|
|
216
|
-
|
|
217
|
-
export { CONDITIONAL_CHECKS, type ConformanceCheck, type ConformanceCheckOutcome, type ConformanceCheckStatus, type ConformanceConnect, type ConformanceConnectionHandle, type ConformanceEvent, type ConformanceRunner, type ConformanceSkip, type EventTransportLike, type InstrumentedTransport, KERNEL_CONFORMANCE_CHECKS, type KernelBindContext, type KernelBlueprintLike, type KernelConformanceOptions, type KernelConformanceReport, conformanceEvent, createConformanceTransport, describeKernelConformance, instrumentTransport };
|
|
242
|
+
export declare function instrumentTransport(inner: EventTransportLike): InstrumentedTransport;
|
|
243
|
+
export type { ConformanceCheck, ConformanceCheckOutcome, ConformanceCheckStatus, ConformanceConnect, ConformanceConnectionHandle, ConformanceEvent, ConformanceRunner, ConformanceSkip, EventTransportLike, InstrumentedTransport, KernelBindContext, KernelBlueprintLike, KernelConformanceOptions, KernelConformanceReport };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as ModelCollisionError } from "../model-registry-
|
|
1
|
+
import { t as ModelCollisionError } from "../model-registry-DrVfJ3Nt.mjs";
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
|
-
|
|
3
|
+
// src/kernel-conformance/transport.ts
|
|
4
4
|
/** Exact match, `*`, or a `prefix.*` / `prefix:*` glob — the kernel bus convention. */
|
|
5
5
|
function matches(pattern, type) {
|
|
6
6
|
if (pattern === "*" || pattern === type) return true;
|
|
@@ -81,8 +81,7 @@ function instrumentTransport(inner) {
|
|
|
81
81
|
closeCalls: () => closeCalls
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
|
|
85
|
-
//#region src/kernel-conformance/types.ts
|
|
84
|
+
// src/kernel-conformance/types.ts
|
|
86
85
|
/**
|
|
87
86
|
* Every check the suite can run, in execution order. The ids are STABLE — `skip` is typed
|
|
88
87
|
* against this tuple, so a typo is a compile error rather than a silently-ineffective skip
|
|
@@ -117,8 +116,7 @@ const CONDITIONAL_CHECKS = [
|
|
|
117
116
|
"outbox-requires-transactional-save",
|
|
118
117
|
"optional-modules-register-no-models"
|
|
119
118
|
];
|
|
120
|
-
|
|
121
|
-
//#region src/kernel-conformance/suite.ts
|
|
119
|
+
// src/kernel-conformance/suite.ts
|
|
122
120
|
/**
|
|
123
121
|
* `describeKernelConformance` — the EXECUTABLE form of the Kernel Construction Standard
|
|
124
122
|
* (commerce `STANDARDIZATION-PLAN.md` §11).
|
|
@@ -599,5 +597,4 @@ function defaultReport(report) {
|
|
|
599
597
|
for (const s of report.notExercised) lines.push(` NOT EXERCISED ${s.check} — ${s.reason}`);
|
|
600
598
|
console.info(lines.join("\n"));
|
|
601
599
|
}
|
|
602
|
-
//#endregion
|
|
603
600
|
export { CONDITIONAL_CHECKS, KERNEL_CONFORMANCE_CHECKS, conformanceEvent, createConformanceTransport, describeKernelConformance, instrumentTransport };
|
package/dist/lock/index.d.mts
CHANGED
|
@@ -1,8 +1,91 @@
|
|
|
1
|
-
import { Connection } from "mongoose";
|
|
2
|
-
import { BaseLockAdapterOptions, LockAdapter } from "@classytic/repo-core/lock";
|
|
3
|
-
|
|
1
|
+
import { ClientSession, Connection } from "mongoose";
|
|
2
|
+
import { BaseLockAdapterOptions, LockAdapter, LockState } from "@classytic/repo-core/lock";
|
|
3
|
+
/** What a claim carries (mirrors arc's `DailyClaimInfo`). */
|
|
4
|
+
interface MongoDailyClaimInfo {
|
|
5
|
+
/** The gate's clock reading when the claim was attempted. */
|
|
6
|
+
readonly now: Date;
|
|
7
|
+
/** Uncompleted claims older than this may be re-granted. Omit to never re-grant. */
|
|
8
|
+
readonly staleAfterMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/** The ledger contract (structurally arc's `DailyLedger`, plus `inspect`). */
|
|
11
|
+
interface MongoDailyLedger {
|
|
12
|
+
claimDay(key: string, civilDate: string, info: MongoDailyClaimInfo): Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Mark the day done (stale recovery never applies again) and store `result`, fenced to the
|
|
15
|
+
* claim this invocation won. A no-op when that claim was re-granted, already completed or
|
|
16
|
+
* released, or when the caller holds no claim on the day (see `adminCompleteDay`).
|
|
17
|
+
*/
|
|
18
|
+
completeDay(key: string, civilDate: string, result?: Record<string, unknown>): Promise<void>;
|
|
19
|
+
/** Drop this invocation's UNCOMPLETED claim so the next tick retries. A completed day is kept. */
|
|
20
|
+
releaseDay(key: string, civilDate: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Claim the day and return a per-invocation handle (or `null` when not won). The handle's
|
|
23
|
+
* `complete` / `release` are fenced by its own token, whatever else claims the day later.
|
|
24
|
+
*/
|
|
25
|
+
claim(key: string, civilDate: string, info: MongoDailyClaimInfo): Promise<MongoDailyClaim | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Manual / admin completion: complete the day's UNCOMPLETED claim whoever holds it, unfenced.
|
|
28
|
+
* Explicit only; never a fallback of `completeDay`. Resolves `true` when it completed a row.
|
|
29
|
+
*/
|
|
30
|
+
adminCompleteDay(key: string, civilDate: string, result?: Record<string, unknown>): Promise<boolean>;
|
|
31
|
+
/** Read one day's row, or `null`. For assertions and admin views. */
|
|
32
|
+
inspect(key: string, civilDate: string): Promise<MongoDailyLedgerRow | null>;
|
|
33
|
+
}
|
|
34
|
+
/** One won claim (see `MongoDailyLedger.claim`). */
|
|
35
|
+
interface MongoDailyClaim {
|
|
36
|
+
readonly key: string;
|
|
37
|
+
readonly civilDate: string;
|
|
38
|
+
/** Unique per claim; the row carries it as `claimToken` while this claim holds the day. */
|
|
39
|
+
readonly token: string;
|
|
40
|
+
readonly claimedAt: Date;
|
|
41
|
+
/** Complete the day while this claim still holds it. `true` when it did. */
|
|
42
|
+
complete(result?: Record<string, unknown>): Promise<boolean>;
|
|
43
|
+
/** Drop the claim while it still holds the day uncompleted. `true` when it did. */
|
|
44
|
+
release(): Promise<boolean>;
|
|
45
|
+
}
|
|
46
|
+
interface MongoDailyLedgerRow {
|
|
47
|
+
key: string;
|
|
48
|
+
civilDate: string;
|
|
49
|
+
claimedAt: Date;
|
|
50
|
+
/** The winning claim's token (rows written by earlier versions have none). */
|
|
51
|
+
claimToken?: string;
|
|
52
|
+
completed: boolean;
|
|
53
|
+
completedAt?: Date;
|
|
54
|
+
result?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
interface MongoDailyLedgerOptions {
|
|
57
|
+
/** Mongoose connection. Default `mongoose.connection`. */
|
|
58
|
+
connection?: Connection;
|
|
59
|
+
/** Collection name. Default `mongo_daily_ledger`. */
|
|
60
|
+
collectionName?: string;
|
|
61
|
+
/** Mongoose model name. Default `MongoDailyLedger`. */
|
|
62
|
+
modelName?: string;
|
|
63
|
+
/** Clock for `completedAt`. Default `() => new Date()`. Claims use `info.now`. */
|
|
64
|
+
nowFn?: () => Date;
|
|
65
|
+
/**
|
|
66
|
+
* Optional session getter for `completeDay`, `releaseDay` and
|
|
67
|
+
* `inspect`, e.g. to complete a day inside the job's transaction.
|
|
68
|
+
* `claimDay` never uses it: a losing claim raises E11000, which would
|
|
69
|
+
* abort a surrounding transaction.
|
|
70
|
+
*/
|
|
71
|
+
session?: () => ClientSession | undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Build a Mongo-backed daily ledger. Idempotent per `(connection,
|
|
75
|
+
* modelName)` like `createMongoLockAdapter`.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* import { createDailyGate } from '@classytic/arc/plugins';
|
|
79
|
+
* import { createMongoDailyLedger } from '@classytic/mongokit/lock';
|
|
80
|
+
*
|
|
81
|
+
* const gate = createDailyGate({
|
|
82
|
+
* key: 'digest', zone: 'Asia/Dubai', hour: 6, staleAfterMs: 15 * 60_000,
|
|
83
|
+
* ledger: createMongoDailyLedger({ connection, collectionName: 'app_daily_ledger' }),
|
|
84
|
+
* });
|
|
85
|
+
*/
|
|
86
|
+
export declare function createMongoDailyLedger(options?: MongoDailyLedgerOptions): MongoDailyLedger;
|
|
4
87
|
/** Adapter-construction options. */
|
|
5
|
-
interface MongoLockAdapterOptions extends BaseLockAdapterOptions {
|
|
88
|
+
export interface MongoLockAdapterOptions extends BaseLockAdapterOptions {
|
|
6
89
|
/**
|
|
7
90
|
* Mongoose connection. Defaults to `mongoose.connection` (the
|
|
8
91
|
* default global connection) — most apps connect once via
|
|
@@ -15,6 +98,51 @@ interface MongoLockAdapterOptions extends BaseLockAdapterOptions {
|
|
|
15
98
|
collectionName?: string;
|
|
16
99
|
/** Override the Mongoose model name. Default `MongoLock`. */
|
|
17
100
|
modelName?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Clock for `tryAcquire` (expiry comparison + new expiry) and
|
|
103
|
+
* `inspect`. Inject one to drive lease expiry from tests or a host
|
|
104
|
+
* `Clock` port. Default `() => new Date()`.
|
|
105
|
+
*
|
|
106
|
+
* The collection's TTL index on `expiresAt` deletes by the server's
|
|
107
|
+
* real time, so in production `nowFn` must track wall-clock time: a
|
|
108
|
+
* clock running behind real time writes expiries the TTL monitor may
|
|
109
|
+
* already treat as past, and the lock can be swept (and taken by
|
|
110
|
+
* another holder) while still held. Skewed / frozen clocks are for
|
|
111
|
+
* tests only (use a far-future base there).
|
|
112
|
+
*/
|
|
113
|
+
nowFn?: () => Date;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The outcome of {@link MongoLockAdapter.acquire}, read from the same atomic write that took (or
|
|
117
|
+
* did not take) the lock. Structurally the same as repo-core's optional `LockAdapter.acquire`
|
|
118
|
+
* result (`LockAcquisition`), declared here so mongokit keeps its repo-core peer floor.
|
|
119
|
+
*/
|
|
120
|
+
export interface MongoLockAcquisition {
|
|
121
|
+
/** `true` when `holderId` holds the lock after this call (fresh, takeover or renewal). */
|
|
122
|
+
acquired: boolean;
|
|
123
|
+
/** The holder after this call: the caller when acquired, else the live holder that kept it. */
|
|
124
|
+
holder: string;
|
|
125
|
+
/**
|
|
126
|
+
* The holder recorded on the row BEFORE this write, when there was one: the caller itself on a
|
|
127
|
+
* renewal, another holder on a takeover of its lapsed lease. Absent when the lock was free
|
|
128
|
+
* (never taken, released, or swept by the TTL index). Only set when `acquired`.
|
|
129
|
+
*/
|
|
130
|
+
previousHolder?: string;
|
|
131
|
+
/** Since when `holder` holds the lock (kept across its renewals). */
|
|
132
|
+
acquiredAt: Date;
|
|
133
|
+
/** When `holder`'s lease ends. */
|
|
134
|
+
expiresAt: Date;
|
|
135
|
+
}
|
|
136
|
+
/** The Mongo lock adapter: the repo-core contract, with `inspect` and `acquire` always present. */
|
|
137
|
+
export interface MongoLockAdapter extends LockAdapter {
|
|
138
|
+
/**
|
|
139
|
+
* Like `tryAcquire` (take a free or lapsed lock, or renew one's own), but answers WHO held it
|
|
140
|
+
* before and who holds it now, from the one atomic write: no `inspect` before or after, so no
|
|
141
|
+
* race window between reading the previous holder and taking the lock. A refused acquire writes
|
|
142
|
+
* nothing and reports the live holder.
|
|
143
|
+
*/
|
|
144
|
+
acquire(name: string, holderId: string, leaseMs: number): Promise<MongoLockAcquisition>;
|
|
145
|
+
inspect(name: string): Promise<LockState | null>;
|
|
18
146
|
}
|
|
19
147
|
/**
|
|
20
148
|
* Build a Mongo-backed lock adapter. Idempotent — the underlying
|
|
@@ -22,6 +150,5 @@ interface MongoLockAdapterOptions extends BaseLockAdapterOptions {
|
|
|
22
150
|
* calling this multiple times with the same options shares the same
|
|
23
151
|
* collection (no duplicate-model errors).
|
|
24
152
|
*/
|
|
25
|
-
declare function createMongoLockAdapter(options?: MongoLockAdapterOptions):
|
|
26
|
-
|
|
27
|
-
export { MongoLockAdapterOptions, createMongoLockAdapter };
|
|
153
|
+
export declare function createMongoLockAdapter(options?: MongoLockAdapterOptions): MongoLockAdapter;
|
|
154
|
+
export type { MongoDailyClaim, MongoDailyClaimInfo, MongoDailyLedger, MongoDailyLedgerOptions, MongoDailyLedgerRow };
|