@open-aih/payload-ddb 3.1.0 → 4.1.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 +141 -18
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +4 -2
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +6 -1
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +6 -1
- package/dist/countVersions.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +31 -15
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +2 -14
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +3 -41
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts +6 -5
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +8 -48
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts +1 -6
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +8 -19
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +20 -24
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +8 -14
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +15 -2
- package/dist/find.js.map +1 -1
- package/dist/findDistinct.d.ts.map +1 -1
- package/dist/findDistinct.js +3 -1
- package/dist/findDistinct.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +3 -2
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +10 -2
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +17 -6
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +10 -2
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +24 -4
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts +5 -4
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +22 -36
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +3 -49
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateJobs.d.ts +21 -0
- package/dist/updateJobs.d.ts.map +1 -0
- package/dist/updateJobs.js +83 -0
- package/dist/updateJobs.js.map +1 -0
- package/dist/updateMany.d.ts +9 -3
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +47 -30
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.d.ts +6 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +49 -49
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +3 -52
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts +6 -0
- package/dist/upsert.d.ts.map +1 -1
- package/dist/upsert.js +57 -41
- package/dist/upsert.js.map +1 -1
- package/dist/utilities/backfillUniqueGuards.d.ts +42 -0
- package/dist/utilities/backfillUniqueGuards.d.ts.map +1 -0
- package/dist/utilities/backfillUniqueGuards.js +39 -0
- package/dist/utilities/backfillUniqueGuards.js.map +1 -0
- package/dist/utilities/buildFilterExpression.d.ts +29 -14
- package/dist/utilities/buildFilterExpression.d.ts.map +1 -1
- package/dist/utilities/buildFilterExpression.js +55 -14
- package/dist/utilities/buildFilterExpression.js.map +1 -1
- package/dist/utilities/castWhere.d.ts +84 -0
- package/dist/utilities/castWhere.d.ts.map +1 -0
- package/dist/utilities/castWhere.js +254 -0
- package/dist/utilities/castWhere.js.map +1 -0
- package/dist/utilities/findFirst.d.ts +3 -2
- package/dist/utilities/findFirst.d.ts.map +1 -1
- package/dist/utilities/findFirst.js +14 -46
- package/dist/utilities/findFirst.js.map +1 -1
- package/dist/utilities/geo.d.ts +36 -0
- package/dist/utilities/geo.d.ts.map +1 -0
- package/dist/utilities/geo.js +108 -0
- package/dist/utilities/geo.js.map +1 -0
- package/dist/utilities/mapWithConcurrency.d.ts +12 -0
- package/dist/utilities/mapWithConcurrency.d.ts.map +1 -0
- package/dist/utilities/mapWithConcurrency.js +32 -0
- package/dist/utilities/mapWithConcurrency.js.map +1 -0
- package/dist/utilities/matchesWhere.d.ts +25 -5
- package/dist/utilities/matchesWhere.d.ts.map +1 -1
- package/dist/utilities/matchesWhere.js +150 -38
- package/dist/utilities/matchesWhere.js.map +1 -1
- package/dist/utilities/operators.d.ts +22 -12
- package/dist/utilities/operators.d.ts.map +1 -1
- package/dist/utilities/operators.js +36 -31
- package/dist/utilities/operators.js.map +1 -1
- package/dist/utilities/optimistic.d.ts +29 -0
- package/dist/utilities/optimistic.d.ts.map +1 -0
- package/dist/utilities/optimistic.js +58 -0
- package/dist/utilities/optimistic.js.map +1 -0
- package/dist/utilities/prepareWhere.d.ts +63 -0
- package/dist/utilities/prepareWhere.d.ts.map +1 -0
- package/dist/utilities/prepareWhere.js +198 -0
- package/dist/utilities/prepareWhere.js.map +1 -0
- package/dist/utilities/queryCount.d.ts +6 -3
- package/dist/utilities/queryCount.d.ts.map +1 -1
- package/dist/utilities/queryCount.js +16 -45
- package/dist/utilities/queryCount.js.map +1 -1
- package/dist/utilities/queryMatching.d.ts +8 -7
- package/dist/utilities/queryMatching.d.ts.map +1 -1
- package/dist/utilities/queryMatching.js +17 -54
- package/dist/utilities/queryMatching.js.map +1 -1
- package/dist/utilities/queryPartition.d.ts +26 -0
- package/dist/utilities/queryPartition.d.ts.map +1 -0
- package/dist/utilities/queryPartition.js +55 -0
- package/dist/utilities/queryPartition.js.map +1 -0
- package/dist/utilities/resolveJoins.d.ts +37 -0
- package/dist/utilities/resolveJoins.d.ts.map +1 -0
- package/dist/utilities/resolveJoins.js +195 -0
- package/dist/utilities/resolveJoins.js.map +1 -0
- package/dist/utilities/stripInternalKeys.d.ts +17 -3
- package/dist/utilities/stripInternalKeys.d.ts.map +1 -1
- package/dist/utilities/stripInternalKeys.js +25 -4
- package/dist/utilities/stripInternalKeys.js.map +1 -1
- package/dist/utilities/uniqueGuards.d.ts +39 -0
- package/dist/utilities/uniqueGuards.d.ts.map +1 -0
- package/dist/utilities/uniqueGuards.js +106 -0
- package/dist/utilities/uniqueGuards.js.map +1 -0
- package/dist/utilities/updateVersionRow.d.ts +19 -0
- package/dist/utilities/updateVersionRow.d.ts.map +1 -0
- package/dist/utilities/updateVersionRow.js +40 -0
- package/dist/utilities/updateVersionRow.js.map +1 -0
- package/dist/utilities/writeErrors.d.ts +11 -0
- package/dist/utilities/writeErrors.d.ts.map +1 -0
- package/dist/utilities/writeErrors.js +27 -0
- package/dist/utilities/writeErrors.js.map +1 -0
- package/dist/utilities/writeItems.d.ts +124 -0
- package/dist/utilities/writeItems.d.ts.map +1 -0
- package/dist/utilities/writeItems.js +383 -0
- package/dist/utilities/writeItems.js.map +1 -0
- package/package.json +21 -14
package/dist/findOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { FindOne } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { collectionHasDrafts, fetchDraftsOnlySupplements } from './utilities/draftsFallback.js'\nimport { findFirst } from './utilities/findFirst.js'\n\n/**\n * Locate one doc in `collection` matching `where`. For drafts-enabled\n * collections, fall back to the `latest=true` version row when no main\n * partition row matches — that's how drafts-only docs (saved but never\n * published) become findable.\n */\nexport const findOne: FindOne = async function findOne(\n this: DynamoAdapter,\n { collection, where },\n) {\n const partition = this.resolvePartition(collection)\n
|
|
1
|
+
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { FindOne } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { collectionHasDrafts, fetchDraftsOnlySupplements } from './utilities/draftsFallback.js'\nimport { findFirst } from './utilities/findFirst.js'\nimport { prepareCollectionWhere } from './utilities/prepareWhere.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\n\n/**\n * Locate one doc in `collection` matching `where`. For drafts-enabled\n * collections, fall back to the `latest=true` version row when no main\n * partition row matches — that's how drafts-only docs (saved but never\n * published) become findable.\n */\nexport const findOne: FindOne = async function findOne(\n this: DynamoAdapter,\n { collection, joins, locale, where: rawWhere },\n) {\n const where = await prepareCollectionWhere(this, collection, rawWhere, locale)\n const partition = this.resolvePartition(collection)\n\n let doc = await findFirst(this, { partition, where })\n if (!doc && collectionHasDrafts(this, collection)) {\n const supplements = await fetchDraftsOnlySupplements(this, collection, [], where)\n doc = supplements[0] ?? null\n }\n if (!doc) return null as never\n\n await resolveJoins(this, { collectionSlug: collection, docs: [doc], joins, locale })\n return doc as never\n}\n"],"names":["collectionHasDrafts","fetchDraftsOnlySupplements","findFirst","prepareCollectionWhere","resolveJoins","findOne","collection","joins","locale","where","rawWhere","partition","resolvePartition","doc","supplements","collectionSlug","docs"],"mappings":"AAIA,SAASA,mBAAmB,EAAEC,0BAA0B,QAAQ,gCAA+B;AAC/F,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,YAAY,QAAQ,8BAA6B;AAE1D;;;;;CAKC,GACD,OAAO,MAAMC,UAAmB,eAAeA,QAE7C,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,OAAOC,QAAQ,EAAE;IAE9C,MAAMD,QAAQ,MAAMN,uBAAuB,IAAI,EAAEG,YAAYI,UAAUF;IACvE,MAAMG,YAAY,IAAI,CAACC,gBAAgB,CAACN;IAExC,IAAIO,MAAM,MAAMX,UAAU,IAAI,EAAE;QAAES;QAAWF;IAAM;IACnD,IAAI,CAACI,OAAOb,oBAAoB,IAAI,EAAEM,aAAa;QACjD,MAAMQ,cAAc,MAAMb,2BAA2B,IAAI,EAAEK,YAAY,EAAE,EAAEG;QAC3EI,MAAMC,WAAW,CAAC,EAAE,IAAI;IAC1B;IACA,IAAI,CAACD,KAAK,OAAO;IAEjB,MAAMT,aAAa,IAAI,EAAE;QAAEW,gBAAgBT;QAAYU,MAAM;YAACH;SAAI;QAAEN;QAAOC;IAAO;IAClF,OAAOK;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAA;AAQ1D;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,YA0C1B,CAAA"}
|
package/dist/findVersions.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { applySorts } from './utilities/applySorts.js';
|
|
2
|
+
import { prepareSort, prepareVersionsWhere } from './utilities/prepareWhere.js';
|
|
2
3
|
import { queryMatching } from './utilities/queryMatching.js';
|
|
3
4
|
/**
|
|
4
5
|
* Same shape as `find` but routed at the versions partition. Could share
|
|
@@ -6,10 +7,17 @@ import { queryMatching } from './utilities/queryMatching.js';
|
|
|
6
7
|
* helper, but keeping them separate makes per-method tweaks (e.g.
|
|
7
8
|
* version-only filters, eventual draft-aware logic) easier to land without
|
|
8
9
|
* refactoring.
|
|
9
|
-
*/ export const findVersions = async function findVersions({ collection, limit = 10, page = 1, pagination = true, sort, where }) {
|
|
10
|
+
*/ export const findVersions = async function findVersions({ collection, limit = 10, locale, page = 1, pagination = true, sort, where: rawWhere }) {
|
|
11
|
+
const where = await prepareVersionsWhere(this, {
|
|
12
|
+
kind: 'collection',
|
|
13
|
+
slug: collection
|
|
14
|
+
}, rawWhere, locale);
|
|
10
15
|
const partition = this.resolveVersionsPartition(collection);
|
|
11
16
|
const matched = await queryMatching(this, partition, where);
|
|
12
|
-
applySorts(matched,
|
|
17
|
+
applySorts(matched, prepareSort(this, {
|
|
18
|
+
kind: 'collectionVersions',
|
|
19
|
+
slug: collection
|
|
20
|
+
}, sort, locale));
|
|
13
21
|
const totalDocs = matched.length;
|
|
14
22
|
// `limit: 0` disables the cap. When pagination is false, limit/page still
|
|
15
23
|
// control the slice (e.g. enforceMaxVersions fetches page max+1 with limit 1
|
package/dist/findVersions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { FindVersions, PaginatedDocs } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { queryMatching } from './utilities/queryMatching.js'\n\n/**\n * Same shape as `find` but routed at the versions partition. Could share\n * more code with `find` via a `paginatedQuery(adapter, partition, args)`\n * helper, but keeping them separate makes per-method tweaks (e.g.\n * version-only filters, eventual draft-aware logic) easier to land without\n * refactoring.\n */\nexport const findVersions: FindVersions = async function findVersions(\n this: DynamoAdapter,\n { collection, limit = 10, page = 1, pagination = true, sort, where },\n) {\n const partition = this.resolveVersionsPartition(collection)\n const matched = await queryMatching(this, partition, where)\n applySorts(matched, sort)\n\n const totalDocs = matched.length\n // `limit: 0` disables the cap. When pagination is false, limit/page still\n // control the slice (e.g. enforceMaxVersions fetches page max+1 with limit 1\n // to find the oldest doc to prune). The pagination flag only gates whether\n // we compute meaningful total-count metadata.\n const useLimit = limit > 0\n const safePage = useLimit ? Math.max(1, page) : 1\n\n const start = useLimit ? (safePage - 1) * limit : 0\n const end = useLimit ? start + limit : totalDocs\n const docs = matched.slice(start, end)\n\n const effectiveLimit = useLimit ? limit : totalDocs\n const totalPages = pagination && useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1\n const hasNextPage = pagination && useLimit && safePage < totalPages\n const hasPrevPage = pagination && useLimit && safePage > 1\n\n const result: PaginatedDocs<Record<string, unknown>> = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: effectiveLimit,\n nextPage: hasNextPage ? safePage + 1 : null,\n page: safePage,\n pagingCounter: useLimit ? (safePage - 1) * limit + 1 : 1,\n prevPage: hasPrevPage ? safePage - 1 : null,\n totalDocs,\n totalPages,\n }\n return result as never\n}\n"],"names":["applySorts","queryMatching","findVersions","collection","limit","page","pagination","sort","where","partition","resolveVersionsPartition","matched","totalDocs","length","useLimit","safePage","Math","max","start","end","docs","slice","effectiveLimit","totalPages","ceil","hasNextPage","hasPrevPage","result","nextPage","pagingCounter","prevPage"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,aAAa,QAAQ,+BAA8B;AAE5D;;;;;;CAMC,GACD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,UAAU,EAAEC,QAAQ,EAAE,EAAEC,OAAO,CAAC,EAAEC,aAAa,IAAI,EAAEC,IAAI,EAAEC,
|
|
1
|
+
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { FindVersions, PaginatedDocs } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { prepareSort, prepareVersionsWhere } from './utilities/prepareWhere.js'\nimport { queryMatching } from './utilities/queryMatching.js'\n\n/**\n * Same shape as `find` but routed at the versions partition. Could share\n * more code with `find` via a `paginatedQuery(adapter, partition, args)`\n * helper, but keeping them separate makes per-method tweaks (e.g.\n * version-only filters, eventual draft-aware logic) easier to land without\n * refactoring.\n */\nexport const findVersions: FindVersions = async function findVersions(\n this: DynamoAdapter,\n { collection, limit = 10, locale, page = 1, pagination = true, sort, where: rawWhere },\n) {\n const where = await prepareVersionsWhere(this, { kind: 'collection', slug: collection }, rawWhere, locale)\n const partition = this.resolveVersionsPartition(collection)\n const matched = await queryMatching(this, partition, where)\n applySorts(\n matched,\n prepareSort(this, { kind: 'collectionVersions', slug: collection }, sort, locale),\n )\n\n const totalDocs = matched.length\n // `limit: 0` disables the cap. When pagination is false, limit/page still\n // control the slice (e.g. enforceMaxVersions fetches page max+1 with limit 1\n // to find the oldest doc to prune). The pagination flag only gates whether\n // we compute meaningful total-count metadata.\n const useLimit = limit > 0\n const safePage = useLimit ? Math.max(1, page) : 1\n\n const start = useLimit ? (safePage - 1) * limit : 0\n const end = useLimit ? start + limit : totalDocs\n const docs = matched.slice(start, end)\n\n const effectiveLimit = useLimit ? limit : totalDocs\n const totalPages = pagination && useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1\n const hasNextPage = pagination && useLimit && safePage < totalPages\n const hasPrevPage = pagination && useLimit && safePage > 1\n\n const result: PaginatedDocs<Record<string, unknown>> = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: effectiveLimit,\n nextPage: hasNextPage ? safePage + 1 : null,\n page: safePage,\n pagingCounter: useLimit ? (safePage - 1) * limit + 1 : 1,\n prevPage: hasPrevPage ? safePage - 1 : null,\n totalDocs,\n totalPages,\n }\n return result as never\n}\n"],"names":["applySorts","prepareSort","prepareVersionsWhere","queryMatching","findVersions","collection","limit","locale","page","pagination","sort","where","rawWhere","kind","slug","partition","resolveVersionsPartition","matched","totalDocs","length","useLimit","safePage","Math","max","start","end","docs","slice","effectiveLimit","totalPages","ceil","hasNextPage","hasPrevPage","result","nextPage","pagingCounter","prevPage"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,EAAEC,oBAAoB,QAAQ,8BAA6B;AAC/E,SAASC,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ACvD8B,UAAUJ,cAAcX,WAAW,IAAI;QACvCH;QACAW;IACF;IACA,OAAOI;AACT,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { DatabaseAdapterObj } from 'payload';
|
|
2
2
|
import type { Args, DynamoAdapter } from './types.js';
|
|
3
3
|
export type { Args, DynamoAdapter } from './types.js';
|
|
4
|
+
export { backfillUniqueGuards } from './utilities/backfillUniqueGuards.js';
|
|
5
|
+
export type { UniqueBackfillReport } from './utilities/backfillUniqueGuards.js';
|
|
4
6
|
export { scrubUnknownFields } from './utilities/scrubUnknownFields.js';
|
|
5
7
|
export type { ScrubReport } from './utilities/scrubUnknownFields.js';
|
|
6
8
|
export declare function dynamoAdapter(args?: Args): DatabaseAdapterObj<DynamoAdapter>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;AAI1D,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;AAI1D,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AA8BrD,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAA;AAC1E,YAAY,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAA;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AACtE,YAAY,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AAMpE,wBAAgB,aAAa,CAAC,IAAI,GAAE,IAAS,GAAG,kBAAkB,CAAC,aAAa,CAAC,CA0EhF"}
|
package/dist/index.js
CHANGED
|
@@ -21,10 +21,12 @@ import { init } from './init.js';
|
|
|
21
21
|
import { queryDrafts } from './queryDrafts.js';
|
|
22
22
|
import { updateGlobal } from './updateGlobal.js';
|
|
23
23
|
import { updateGlobalVersion } from './updateGlobalVersion.js';
|
|
24
|
+
import { updateJobs } from './updateJobs.js';
|
|
24
25
|
import { updateMany } from './updateMany.js';
|
|
25
26
|
import { updateOne } from './updateOne.js';
|
|
26
27
|
import { updateVersion } from './updateVersion.js';
|
|
27
28
|
import { upsert } from './upsert.js';
|
|
29
|
+
export { backfillUniqueGuards } from './utilities/backfillUniqueGuards.js';
|
|
28
30
|
export { scrubUnknownFields } from './utilities/scrubUnknownFields.js';
|
|
29
31
|
const NAME = 'dynamodb';
|
|
30
32
|
const PACKAGE_NAME = '@aih-software/payload-ddb';
|
|
@@ -52,6 +54,10 @@ export function dynamoAdapter(args = {}) {
|
|
|
52
54
|
ownsClient: !args.client,
|
|
53
55
|
tableName,
|
|
54
56
|
ensureTables: args.ensureTables ?? false,
|
|
57
|
+
// `createDatabaseAdapter` falls back to 'migrations' when this is unset.
|
|
58
|
+
...args.migrationDir ? {
|
|
59
|
+
migrationDir: args.migrationDir
|
|
60
|
+
} : {},
|
|
55
61
|
resolvePartition,
|
|
56
62
|
resolveVersionsPartition,
|
|
57
63
|
// ----- lifecycle -----
|
|
@@ -82,6 +88,7 @@ export function dynamoAdapter(args = {}) {
|
|
|
82
88
|
queryDrafts,
|
|
83
89
|
updateGlobal,
|
|
84
90
|
updateGlobalVersion,
|
|
91
|
+
updateJobs,
|
|
85
92
|
updateMany,
|
|
86
93
|
updateOne,
|
|
87
94
|
updateVersion,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { DatabaseAdapterObj, Payload } from 'payload'\n\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { Args, DynamoAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { countGlobalVersions } from './countGlobalVersions.js'\nimport { countVersions } from './countVersions.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findDistinct } from './findDistinct.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateMany } from './updateMany.js'\nimport { updateOne } from './updateOne.js'\nimport { updateVersion } from './updateVersion.js'\nimport { upsert } from './upsert.js'\n\nexport type { Args, DynamoAdapter } from './types.js'\nexport { scrubUnknownFields } from './utilities/scrubUnknownFields.js'\nexport type { ScrubReport } from './utilities/scrubUnknownFields.js'\n\nconst NAME = 'dynamodb'\nconst PACKAGE_NAME = '@aih-software/payload-ddb'\nconst DEFAULT_TABLE_NAME = 'payload'\n\nexport function dynamoAdapter(args: Args = {}): DatabaseAdapterObj<DynamoAdapter> {\n function adapterInit({ payload }: { payload: Payload }): DynamoAdapter {\n const tableName = args.tableName ?? DEFAULT_TABLE_NAME\n\n const resolvePartition = (slug: string): string => slug\n const resolveVersionsPartition = (slug: string): string => `${slug}_versions`\n\n return createDatabaseAdapter<DynamoAdapter>({\n name: NAME,\n packageName: PACKAGE_NAME,\n defaultIDType: 'text',\n payload,\n\n // ----- adapter-specific state -----\n clientConfig: args.clientConfig ?? {},\n translateConfig: args.translateConfig ?? {\n marshallOptions: {\n removeUndefinedValues: true,\n convertClassInstanceToMap: true,\n },\n },\n client: args.client,\n docClient: undefined,\n ownsClient: !args.client,\n tableName,\n ensureTables: args.ensureTables ?? false,\n resolvePartition,\n resolveVersionsPartition,\n\n // ----- lifecycle -----\n connect,\n destroy,\n init,\n\n // ----- transactions (no-op until DynamoDB transact-writes are wired) -----\n beginTransaction: async () => null,\n commitTransaction: async () => {},\n rollbackTransaction: async () => {},\n\n // ----- methods -----\n count,\n countGlobalVersions,\n countVersions,\n create,\n createGlobal,\n createGlobalVersion,\n createVersion,\n deleteMany,\n deleteOne,\n deleteVersions,\n find,\n findDistinct,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n queryDrafts,\n updateGlobal,\n updateGlobalVersion,\n updateMany,\n updateOne,\n updateVersion,\n upsert,\n })\n }\n\n return {\n name: NAME,\n defaultIDType: 'text',\n init: adapterInit,\n }\n}\n"],"names":["createDatabaseAdapter","connect","count","countGlobalVersions","countVersions","create","createGlobal","createGlobalVersion","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findDistinct","findGlobal","findGlobalVersions","findOne","findVersions","init","queryDrafts","updateGlobal","updateGlobalVersion","updateMany","updateOne","updateVersion","upsert","scrubUnknownFields","NAME","PACKAGE_NAME","DEFAULT_TABLE_NAME","dynamoAdapter","args","adapterInit","payload","tableName","resolvePartition","slug","resolveVersionsPartition","name","packageName","defaultIDType","clientConfig","translateConfig","marshallOptions","removeUndefinedValues","convertClassInstanceToMap","client","docClient","undefined","ownsClient","ensureTables","beginTransaction","commitTransaction","rollbackTransaction"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,UAAS;AAI/C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AAGpC,SAASC,kBAAkB,QAAQ,oCAAmC;AAGtE,MAAMC,OAAO;AACb,MAAMC,eAAe;AACrB,MAAMC,qBAAqB;AAE3B,OAAO,SAASC,cAAcC,OAAa,CAAC,CAAC;IAC3C,SAASC,YAAY,EAAEC,OAAO,EAAwB;QACpD,MAAMC,YAAYH,KAAKG,SAAS,IAAIL;QAEpC,MAAMM,mBAAmB,CAACC,OAAyBA;QACnD,MAAMC,2BAA2B,CAACD,OAAyB,GAAGA,KAAK,SAAS,CAAC;QAE7E,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { DatabaseAdapterObj, Payload } from 'payload'\n\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { Args, DynamoAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { countGlobalVersions } from './countGlobalVersions.js'\nimport { countVersions } from './countVersions.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findDistinct } from './findDistinct.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateJobs } from './updateJobs.js'\nimport { updateMany } from './updateMany.js'\nimport { updateOne } from './updateOne.js'\nimport { updateVersion } from './updateVersion.js'\nimport { upsert } from './upsert.js'\n\nexport type { Args, DynamoAdapter } from './types.js'\nexport { backfillUniqueGuards } from './utilities/backfillUniqueGuards.js'\nexport type { UniqueBackfillReport } from './utilities/backfillUniqueGuards.js'\nexport { scrubUnknownFields } from './utilities/scrubUnknownFields.js'\nexport type { ScrubReport } from './utilities/scrubUnknownFields.js'\n\nconst NAME = 'dynamodb'\nconst PACKAGE_NAME = '@aih-software/payload-ddb'\nconst DEFAULT_TABLE_NAME = 'payload'\n\nexport function dynamoAdapter(args: Args = {}): DatabaseAdapterObj<DynamoAdapter> {\n function adapterInit({ payload }: { payload: Payload }): DynamoAdapter {\n const tableName = args.tableName ?? DEFAULT_TABLE_NAME\n\n const resolvePartition = (slug: string): string => slug\n const resolveVersionsPartition = (slug: string): string => `${slug}_versions`\n\n return createDatabaseAdapter<DynamoAdapter>({\n name: NAME,\n packageName: PACKAGE_NAME,\n defaultIDType: 'text',\n payload,\n\n // ----- adapter-specific state -----\n clientConfig: args.clientConfig ?? {},\n translateConfig: args.translateConfig ?? {\n marshallOptions: {\n removeUndefinedValues: true,\n convertClassInstanceToMap: true,\n },\n },\n client: args.client,\n docClient: undefined,\n ownsClient: !args.client,\n tableName,\n ensureTables: args.ensureTables ?? false,\n // `createDatabaseAdapter` falls back to 'migrations' when this is unset.\n ...(args.migrationDir ? { migrationDir: args.migrationDir } : {}),\n resolvePartition,\n resolveVersionsPartition,\n\n // ----- lifecycle -----\n connect,\n destroy,\n init,\n\n // ----- transactions (no-op until DynamoDB transact-writes are wired) -----\n beginTransaction: async () => null,\n commitTransaction: async () => {},\n rollbackTransaction: async () => {},\n\n // ----- methods -----\n count,\n countGlobalVersions,\n countVersions,\n create,\n createGlobal,\n createGlobalVersion,\n createVersion,\n deleteMany,\n deleteOne,\n deleteVersions,\n find,\n findDistinct,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n queryDrafts,\n updateGlobal,\n updateGlobalVersion,\n updateJobs,\n updateMany,\n updateOne,\n updateVersion,\n upsert,\n })\n }\n\n return {\n name: NAME,\n defaultIDType: 'text',\n init: adapterInit,\n }\n}\n"],"names":["createDatabaseAdapter","connect","count","countGlobalVersions","countVersions","create","createGlobal","createGlobalVersion","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findDistinct","findGlobal","findGlobalVersions","findOne","findVersions","init","queryDrafts","updateGlobal","updateGlobalVersion","updateJobs","updateMany","updateOne","updateVersion","upsert","backfillUniqueGuards","scrubUnknownFields","NAME","PACKAGE_NAME","DEFAULT_TABLE_NAME","dynamoAdapter","args","adapterInit","payload","tableName","resolvePartition","slug","resolveVersionsPartition","name","packageName","defaultIDType","clientConfig","translateConfig","marshallOptions","removeUndefinedValues","convertClassInstanceToMap","client","docClient","undefined","ownsClient","ensureTables","migrationDir","beginTransaction","commitTransaction","rollbackTransaction"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,UAAS;AAI/C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MA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YAAY,IAAI,CAAC;YACpCC,iBAAiBX,KAAKW,eAAe,IAAI;gBACvCC,iBAAiB;oBACfC,uBAAuB;oBACvBC,2BAA2B;gBAC7B;YACF;YACAC,QAAQf,KAAKe,MAAM;YACnBC,WAAWC;YACXC,YAAY,CAAClB,KAAKe,MAAM;YACxBZ;YACAgB,cAAcnB,KAAKmB,YAAY,IAAI;YACnC,yEAAyE;YACzE,GAAInB,KAAKoB,YAAY,GAAG;gBAAEA,cAAcpB,KAAKoB,YAAY;YAAC,IAAI,CAAC,CAAC;YAChEhB;YACAE;YAEA,wBAAwB;YACxBvC;YACAW;YACAO;YAEA,4EAA4E;YAC5EoC,kBAAkB,UAAY;YAC9BC,mBAAmB,WAAa;YAChCC,qBAAqB,WAAa;YAElC,sBAAsB;YACtBvD;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACLc,MAAMX;QACNa,eAAe;QACfxB,MAAMgB;IACR;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,WAAW,EAAS,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,WAAW,EAAS,MAAM,SAAS,CAAA;AAwDhE,eAAO,MAAM,WAAW,EAAE,WA4EzB,CAAA"}
|
package/dist/queryDrafts.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { applySorts } from './utilities/applySorts.js';
|
|
2
2
|
import { matchesWhere } from './utilities/matchesWhere.js';
|
|
3
|
+
import { prepareCollectionWhere, prepareSort } from './utilities/prepareWhere.js';
|
|
3
4
|
import { queryMatching } from './utilities/queryMatching.js';
|
|
5
|
+
import { resolveJoins } from './utilities/resolveJoins.js';
|
|
4
6
|
/**
|
|
5
7
|
* Return the latest version of every doc as a paginated, doc-shaped result.
|
|
6
8
|
*
|
|
@@ -22,6 +24,11 @@ import { queryMatching } from './utilities/queryMatching.js';
|
|
|
22
24
|
// transforming e.g. `{ slug: { equals: 'x' } }` → `{ 'version.slug': { equals: 'x' } }`.
|
|
23
25
|
// But we project versionData flat to the top level, so those prefixed paths
|
|
24
26
|
// never resolve. Strip the leading `version.` to match the projected shape.
|
|
27
|
+
//
|
|
28
|
+
// The same core rewrite turns a doc-level `id` filter into `parent` (the
|
|
29
|
+
// version row's pointer to its doc). The projected docs carry that value as
|
|
30
|
+
// `id` again, so map it back — otherwise an `id` filter on a drafts query
|
|
31
|
+
// tests a `parent` key that no projected doc has, and matches nothing.
|
|
25
32
|
function stripVersionPrefix(where) {
|
|
26
33
|
if (!where || typeof where !== 'object') return where;
|
|
27
34
|
const result = {};
|
|
@@ -30,13 +37,17 @@ function stripVersionPrefix(where) {
|
|
|
30
37
|
if (Array.isArray(value)) {
|
|
31
38
|
result[key] = value.map((sub)=>stripVersionPrefix(sub)).filter(Boolean);
|
|
32
39
|
}
|
|
40
|
+
} else if (key.startsWith('version.')) {
|
|
41
|
+
// Checked first: a doc field that is itself named `parent` arrives as
|
|
42
|
+
// `version.parent` and must stay `parent`.
|
|
43
|
+
result[key.slice(8)] = value;
|
|
33
44
|
} else {
|
|
34
|
-
result[key
|
|
45
|
+
result[key === 'parent' ? 'id' : key] = value;
|
|
35
46
|
}
|
|
36
47
|
}
|
|
37
48
|
return result;
|
|
38
49
|
}
|
|
39
|
-
export const queryDrafts = async function queryDrafts({ collection, limit = 10, page = 1, pagination = true, sort, where }) {
|
|
50
|
+
export const queryDrafts = async function queryDrafts({ collection, joins, limit = 10, locale, page = 1, pagination = true, sort, where }) {
|
|
40
51
|
const versionsPartition = this.resolveVersionsPartition(collection);
|
|
41
52
|
const docsPartition = this.resolvePartition(collection);
|
|
42
53
|
const [latestRows, mainRows] = await Promise.all([
|
|
@@ -72,15 +83,24 @@ export const queryDrafts = async function queryDrafts({ collection, limit = 10,
|
|
|
72
83
|
// to the top level above, so those prefixed paths never resolve via
|
|
73
84
|
// getByPath. Strip the leading `version.` from every field key so the
|
|
74
85
|
// in-memory filter matches the projected shape.
|
|
75
|
-
const normalizedWhere = stripVersionPrefix(where);
|
|
86
|
+
const normalizedWhere = await prepareCollectionWhere(this, collection, stripVersionPrefix(where) ?? undefined, locale);
|
|
76
87
|
const matched = normalizedWhere ? projected.filter((doc)=>matchesWhere(doc, normalizedWhere)) : projected;
|
|
77
|
-
applySorts(matched,
|
|
88
|
+
applySorts(matched, prepareSort(this, {
|
|
89
|
+
kind: 'collection',
|
|
90
|
+
slug: collection
|
|
91
|
+
}, sort, locale));
|
|
78
92
|
const totalDocs = matched.length;
|
|
79
93
|
const useLimit = limit > 0;
|
|
80
94
|
const safePage = useLimit ? Math.max(1, page) : 1;
|
|
81
95
|
const start = useLimit ? (safePage - 1) * limit : 0;
|
|
82
96
|
const end = useLimit ? start + limit : totalDocs;
|
|
83
97
|
const docs = matched.slice(start, end);
|
|
98
|
+
await resolveJoins(this, {
|
|
99
|
+
collectionSlug: collection,
|
|
100
|
+
docs,
|
|
101
|
+
joins,
|
|
102
|
+
locale
|
|
103
|
+
});
|
|
84
104
|
const effectiveLimit = useLimit ? limit : totalDocs;
|
|
85
105
|
const totalPages = pagination && useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1;
|
|
86
106
|
const hasNextPage = pagination && useLimit && safePage < totalPages;
|
package/dist/queryDrafts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginatedDocs, QueryDrafts, Where } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { matchesWhere } from './utilities/matchesWhere.js'\nimport { queryMatching } from './utilities/queryMatching.js'\n\n/**\n * Return the latest version of every doc as a paginated, doc-shaped result.\n *\n * Strategy:\n * 1. Query the versions partition for `latest=true` rows (one per parent).\n * 2. Project each row's `version` payload up to top-level so the result\n * looks like a doc — this lets the user's `where` / `sort` operate in\n * doc-field terms instead of `version.x` paths.\n * 3. Fill in any docs that have a row in the *main* partition but no\n * `latest=true` version row. This covers two cases:\n * - documents created before versioning was enabled\n * - data orphaned by historical adapter bugs that dropped version writes\n * 4. Apply `where` post-projection, sort, paginate.\n *\n * No `_status` filter is applied — `queryDrafts` returns the latest version\n * regardless of draft/published state. Payload's higher-level code decides\n * how to use the result.\n */\n// Payload core calls appendVersionToQueryKey before invoking queryDrafts,\n// transforming e.g. `{ slug: { equals: 'x' } }` → `{ 'version.slug': { equals: 'x' } }`.\n// But we project versionData flat to the top level, so those prefixed paths\n// never resolve. Strip the leading `version.` to match the projected shape.\nfunction stripVersionPrefix(where: Where | null | undefined): Where | null | undefined {\n if (!where || typeof where !== 'object') return where\n const result: Where = {}\n for (const [key, value] of Object.entries(where)) {\n if (key === 'and' || key === 'or') {\n if (Array.isArray(value)) {\n result[key] = value.map((sub) => stripVersionPrefix(sub as Where)).filter(Boolean) as Where[]\n }\n } else
|
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginatedDocs, QueryDrafts, Where } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { matchesWhere } from './utilities/matchesWhere.js'\nimport { prepareCollectionWhere, prepareSort } from './utilities/prepareWhere.js'\nimport { queryMatching } from './utilities/queryMatching.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\n\n/**\n * Return the latest version of every doc as a paginated, doc-shaped result.\n *\n * Strategy:\n * 1. Query the versions partition for `latest=true` rows (one per parent).\n * 2. Project each row's `version` payload up to top-level so the result\n * looks like a doc — this lets the user's `where` / `sort` operate in\n * doc-field terms instead of `version.x` paths.\n * 3. Fill in any docs that have a row in the *main* partition but no\n * `latest=true` version row. This covers two cases:\n * - documents created before versioning was enabled\n * - data orphaned by historical adapter bugs that dropped version writes\n * 4. Apply `where` post-projection, sort, paginate.\n *\n * No `_status` filter is applied — `queryDrafts` returns the latest version\n * regardless of draft/published state. Payload's higher-level code decides\n * how to use the result.\n */\n// Payload core calls appendVersionToQueryKey before invoking queryDrafts,\n// transforming e.g. `{ slug: { equals: 'x' } }` → `{ 'version.slug': { equals: 'x' } }`.\n// But we project versionData flat to the top level, so those prefixed paths\n// never resolve. Strip the leading `version.` to match the projected shape.\n//\n// The same core rewrite turns a doc-level `id` filter into `parent` (the\n// version row's pointer to its doc). The projected docs carry that value as\n// `id` again, so map it back — otherwise an `id` filter on a drafts query\n// tests a `parent` key that no projected doc has, and matches nothing.\nfunction stripVersionPrefix(where: Where | null | undefined): Where | null | undefined {\n if (!where || typeof where !== 'object') return where\n const result: Where = {}\n for (const [key, value] of Object.entries(where)) {\n if (key === 'and' || key === 'or') {\n if (Array.isArray(value)) {\n result[key] = value.map((sub) => stripVersionPrefix(sub as Where)).filter(Boolean) as Where[]\n }\n } else if (key.startsWith('version.')) {\n // Checked first: a doc field that is itself named `parent` arrives as\n // `version.parent` and must stay `parent`.\n result[key.slice(8)] = value as Where[string]\n } else {\n result[key === 'parent' ? 'id' : key] = value as Where[string]\n }\n }\n return result\n}\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: DynamoAdapter,\n { collection, joins, limit = 10, locale, page = 1, pagination = true, sort, where },\n) {\n const versionsPartition = this.resolveVersionsPartition(collection)\n const docsPartition = this.resolvePartition(collection)\n\n const [latestRows, mainRows] = await Promise.all([\n queryMatching(this, versionsPartition, { latest: { equals: true } }),\n queryMatching(this, docsPartition, undefined),\n ])\n\n // Latest-version rows win. We key by parent id so `mainRows` only fills\n // entries that have no version backing.\n const docsByParent = new Map<unknown, Record<string, unknown>>()\n for (const row of latestRows) {\n const version = row['version']\n if (!version || typeof version !== 'object') continue\n docsByParent.set(row['parent'], {\n ...(version as Record<string, unknown>),\n id: row['parent'],\n })\n }\n\n for (const doc of mainRows) {\n if (!docsByParent.has(doc['id'])) {\n docsByParent.set(doc['id'], doc)\n }\n }\n\n const projected = [...docsByParent.values()]\n // Payload core calls appendVersionToQueryKey before invoking queryDrafts,\n // which transforms e.g. `{ slug: { equals: 'x' } }` into\n // `{ 'version.slug': { equals: 'x' } }`. But we project versionData flat\n // to the top level above, so those prefixed paths never resolve via\n // getByPath. Strip the leading `version.` from every field key so the\n // in-memory filter matches the projected shape.\n const normalizedWhere = await prepareCollectionWhere(\n this,\n collection,\n stripVersionPrefix(where) ?? undefined,\n locale,\n )\n const matched = normalizedWhere\n ? projected.filter((doc) => matchesWhere(doc, normalizedWhere))\n : projected\n\n applySorts(matched, prepareSort(this, { kind: 'collection', slug: collection }, sort, locale))\n\n const totalDocs = matched.length\n const useLimit = limit > 0\n const safePage = useLimit ? Math.max(1, page) : 1\n\n const start = useLimit ? (safePage - 1) * limit : 0\n const end = useLimit ? start + limit : totalDocs\n const docs = matched.slice(start, end)\n await resolveJoins(this, { collectionSlug: collection, docs, joins, locale })\n\n const effectiveLimit = useLimit ? limit : totalDocs\n const totalPages = pagination && useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1\n const hasNextPage = pagination && useLimit && safePage < totalPages\n const hasPrevPage = pagination && useLimit && safePage > 1\n\n const result: PaginatedDocs<Record<string, unknown>> = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: effectiveLimit,\n nextPage: hasNextPage ? safePage + 1 : null,\n page: safePage,\n pagingCounter: useLimit ? (safePage - 1) * limit + 1 : 1,\n prevPage: hasPrevPage ? safePage - 1 : null,\n totalDocs,\n totalPages,\n }\n return result as never\n}\n"],"names":["applySorts","matchesWhere","prepareCollectionWhere","prepareSort","queryMatching","resolveJoins","stripVersionPrefix","where","result","key","value","Object","entries","Array","isArray","map","sub","filter","Boolean","startsWith","slice","queryDrafts","collection","joins","limit","locale","page","pagination","sort","versionsPartition","resolveVersionsPartition","docsPartition","resolvePartition","latestRows","mainRows","Promise","all","latest","equals","undefined","docsByParent","Map","row","version","set","id","doc","has","projected","values","normalizedWhere","matched","kind","slug","totalDocs","length","useLimit","safePage","Math","max","start","end","docs","collectionSlug","effectiveLimit","totalPages","ceil","hasNextPage","hasPrevPage","nextPage","pagingCounter","prevPage"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,sBAAsB,EAAEC,WAAW,QAAQ,8BAA6B;AACjF,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,YAAY,QAAQ,8BAA6B;AAE1D;;;;;;;;;;;;;;;;;CAiBC,GACD,0EAA0E;AAC1E,yFAAyF;AACzF,4EAA4E;AAC5E,4EAA4E;AAC5E,EAAE;AACF,yEAAyE;AACzE,4EAA4E;AAC5E,0EAA0E;AAC1E,uEAAuE;AACvE,SAASC,mBAAmBC,KAA+B;IACzD,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU,OAAOA;IAChD,MAAMC,SAAgB,CAAC;IACvB,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACL,OAAQ;QAChD,IAAIE,QAAQ,SAASA,QAAQ,MAAM;YACjC,IAAII,MAAMC,OAAO,CAACJ,QAAQ;gBACxBF,MAAM,CAACC,IAAI,GAAGC,MAAMK,GAAG,CAAC,CAACC,MAAQV,mBAAmBU,MAAeC,MAAM,CAACC;YAC5E;QACF,OAAO,IAAIT,IAAIU,UAAU,CAAC,aAAa;YACrC,sEAAsE;YACtE,2CAA2C;YAC3CX,MAAM,CAACC,IAAIW,KAAK,CAAC,GAAG,GAAGV;QACzB,OAAO;YACLF,MAAM,CAACC,QAAQ,WAAW,OAAOA,IAAI,GAAGC;QAC1C;IACF;IACA,OAAOF;AACT;AAEA,OAAO,MAAMa,cAA2B,eAAeA,YA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AAM;QAAcC,MAAM/B;IAAW,GAAGM,MAAMH;IAEtF,MAAM6B,YAAYH,QAAQI,MAAM;IAChC,MAAMC,WAAWhC,QAAQ;IACzB,MAAMiC,WAAWD,WAAWE,KAAKC,GAAG,CAAC,GAAGjC,QAAQ;IAEhD,MAAMkC,QAAQJ,WAAW,AAACC,CAAAA,WAAW,CAAA,IAAKjC,QAAQ;IAClD,MAAMqC,MAAML,WAAWI,QAAQpC,QAAQ8B;IACvC,MAAMQ,OAAOX,QAAQ/B,KAAK,CAACwC,OAAOC;IAClC,MAAMxD,aAAa,IAAI,EAAE;QAAE0D,gBAAgBzC;QAAYwC;QAAMvC;QAAOE;IAAO;IAE3E,MAAMuC,iBAAiBR,WAAWhC,QAAQ8B;IAC1C,MAAMW,aAAatC,cAAc6B,WAAWE,KAAKC,GAAG,CAAC,GAAGD,KAAKQ,IAAI,CAACZ,YAAY9B,UAAU;IACxF,MAAM2C,cAAcxC,cAAc6B,YAAYC,WAAWQ;IACzD,MAAMG,cAAczC,cAAc6B,YAAYC,WAAW;IAEzD,MAAMjD,SAAiD;QACrDsD;QACAK;QACAC;QACA5C,OAAOwC;QACPK,UAAUF,cAAcV,WAAW,IAAI;QACvC/B,MAAM+B;QACNa,eAAed,WAAW,AAACC,CAAAA,WAAW,CAAA,IAAKjC,QAAQ,IAAI;QACvD+C,UAAUH,cAAcX,WAAW,IAAI;QACvCH;QACAW;IACF;IACA,OAAOzD;AACT,EAAC"}
|
package/dist/updateGlobal.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { UpdateGlobal } from 'payload';
|
|
2
2
|
/**
|
|
3
|
-
* Read-merge-write for the global's singleton row
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* Read-merge-write for the global's singleton row, retried if the row changes
|
|
4
|
+
* between the read and the write. Per Payload's contract, if the global
|
|
5
|
+
* doesn't exist callers should use `createGlobal` first — we surface the
|
|
6
|
+
* missing case as `null` cast (matching `updateOne`) rather than silently
|
|
7
|
+
* upserting, which would mask programmer errors.
|
|
7
8
|
*/
|
|
8
9
|
export declare const updateGlobal: UpdateGlobal;
|
|
9
10
|
//# sourceMappingURL=updateGlobal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAQ3C;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,YAkB1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,45 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { normalizeForDynamo } from './utilities/normalizeForDynamo.js';
|
|
1
|
+
import { getById, writeWithRetry } from './utilities/optimistic.js';
|
|
3
2
|
import { projectForGlobal } from './utilities/resolveSchema.js';
|
|
4
|
-
import {
|
|
3
|
+
import { putItem } from './utilities/writeItems.js';
|
|
5
4
|
/**
|
|
6
|
-
* Read-merge-write for the global's singleton row
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* Read-merge-write for the global's singleton row, retried if the row changes
|
|
6
|
+
* between the read and the write. Per Payload's contract, if the global
|
|
7
|
+
* doesn't exist callers should use `createGlobal` first — we surface the
|
|
8
|
+
* missing case as `null` cast (matching `updateOne`) rather than silently
|
|
9
|
+
* upserting, which would mask programmer errors.
|
|
10
10
|
*/ export const updateGlobal = async function updateGlobal({ slug, data, returning }) {
|
|
11
|
-
const docClient = this.docClient;
|
|
12
|
-
if (!docClient) {
|
|
13
|
-
throw new Error('payload-ddb: docClient is not initialized — call connect() first.');
|
|
14
|
-
}
|
|
15
11
|
const partition = this.resolvePartition(slug);
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
const read = ()=>getById(this, partition, slug);
|
|
13
|
+
const updated = await writeWithRetry(await read(), read, async (existing)=>{
|
|
14
|
+
const merged = {
|
|
15
|
+
...existing,
|
|
16
|
+
...data,
|
|
17
|
+
id: slug
|
|
18
|
+
};
|
|
19
|
+
const projected = projectForGlobal(this, slug, merged);
|
|
20
|
+
await putItem(this, partition, projected, {
|
|
21
|
+
replaces: existing
|
|
22
|
+
});
|
|
23
|
+
return projected;
|
|
24
|
+
});
|
|
25
|
+
if (!updated || returning === false) {
|
|
25
26
|
return null;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
const merged = {
|
|
29
|
-
...existing,
|
|
30
|
-
...data,
|
|
31
|
-
id: slug
|
|
32
|
-
};
|
|
33
|
-
const projected = projectForGlobal(this, slug, merged);
|
|
34
|
-
await docClient.send(new PutCommand({
|
|
35
|
-
TableName: this.tableName,
|
|
36
|
-
Item: normalizeForDynamo({
|
|
37
|
-
...projected,
|
|
38
|
-
pk: partition,
|
|
39
|
-
sk: slug
|
|
40
|
-
})
|
|
41
|
-
}));
|
|
42
|
-
return returning === false ? null : projected;
|
|
28
|
+
return updated;
|
|
43
29
|
};
|
|
44
30
|
|
|
45
31
|
//# sourceMappingURL=updateGlobal.js.map
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { UpdateGlobal } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { UpdateGlobal } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { getById, writeWithRetry } from './utilities/optimistic.js'\nimport { projectForGlobal } from './utilities/resolveSchema.js'\nimport { putItem } from './utilities/writeItems.js'\n\n/**\n * Read-merge-write for the global's singleton row, retried if the row changes\n * between the read and the write. Per Payload's contract, if the global\n * doesn't exist callers should use `createGlobal` first — we surface the\n * missing case as `null` cast (matching `updateOne`) rather than silently\n * upserting, which would mask programmer errors.\n */\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: DynamoAdapter,\n { slug, data, returning },\n) {\n const partition = this.resolvePartition(slug)\n const read = () => getById(this, partition, slug)\n\n const updated = await writeWithRetry(await read(), read, async (existing) => {\n const merged: Record<string, unknown> = { ...existing, ...data, id: slug }\n const projected = projectForGlobal(this, slug, merged)\n await putItem(this, partition, projected, { replaces: existing })\n return projected\n })\n\n if (!updated || returning === false) {\n return null as never\n }\n return updated as never\n}\n"],"names":["getById","writeWithRetry","projectForGlobal","putItem","updateGlobal","slug","data","returning","partition","resolvePartition","read","updated","existing","merged","id","projected","replaces"],"mappings":"AAIA,SAASA,OAAO,EAAEC,cAAc,QAAQ,4BAA2B;AACnE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,OAAO,QAAQ,4BAA2B;AAEnD;;;;;;CAMC,GACD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAAS,EAAE;IAEzB,MAAMC,YAAY,IAAI,CAACC,gBAAgB,CAACJ;IACxC,MAAMK,OAAO,IAAMV,QAAQ,IAAI,EAAEQ,WAAWH;IAE5C,MAAMM,UAAU,MAAMV,eAAe,MAAMS,QAAQA,MAAM,OAAOE;QAC9D,MAAMC,SAAkC;YAAE,GAAGD,QAAQ;YAAE,GAAGN,IAAI;YAAEQ,IAAIT;QAAK;QACzE,MAAMU,YAAYb,iBAAiB,IAAI,EAAEG,MAAMQ;QAC/C,MAAMV,QAAQ,IAAI,EAAEK,WAAWO,WAAW;YAAEC,UAAUJ;QAAS;QAC/D,OAAOG;IACT;IAEA,IAAI,CAACJ,WAAWJ,cAAc,OAAO;QACnC,OAAO;IACT;IACA,OAAOI;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAMlD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,mBAKjC,CAAA"}
|
|
@@ -1,59 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { findFirst } from './utilities/findFirst.js';
|
|
3
|
-
import { normalizeForDynamo } from './utilities/normalizeForDynamo.js';
|
|
4
|
-
import { projectVersionRow } from './utilities/resolveSchema.js';
|
|
5
|
-
import { stripInternalKeys } from './utilities/stripInternalKeys.js';
|
|
1
|
+
import { updateVersionRow } from './utilities/updateVersionRow.js';
|
|
6
2
|
/**
|
|
7
3
|
* Same read-merge-write semantics as `updateVersion`. Doesn't cascade
|
|
8
4
|
* `latest` flips for the same reason: Payload owns that contract by issuing
|
|
9
5
|
* paired updates.
|
|
10
6
|
*/ export const updateGlobalVersion = async function updateGlobalVersion(args) {
|
|
11
|
-
|
|
12
|
-
if (!docClient) {
|
|
13
|
-
throw new Error('payload-ddb: docClient is not initialized — call connect() first.');
|
|
14
|
-
}
|
|
15
|
-
const partition = this.resolveVersionsPartition(args.global);
|
|
16
|
-
let target = null;
|
|
17
|
-
if (args.id !== undefined && args.id !== null) {
|
|
18
|
-
const result = await docClient.send(new GetCommand({
|
|
19
|
-
TableName: this.tableName,
|
|
20
|
-
Key: {
|
|
21
|
-
pk: partition,
|
|
22
|
-
sk: String(args.id)
|
|
23
|
-
},
|
|
24
|
-
ConsistentRead: true
|
|
25
|
-
}));
|
|
26
|
-
target = result.Item ? stripInternalKeys(result.Item) : null;
|
|
27
|
-
} else if (args.where) {
|
|
28
|
-
target = await findFirst(this, {
|
|
29
|
-
partition,
|
|
30
|
-
where: args.where
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
if (!target) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
const merged = {
|
|
37
|
-
...target,
|
|
38
|
-
...args.versionData,
|
|
39
|
-
id: target['id']
|
|
40
|
-
};
|
|
41
|
-
const projected = projectVersionRow(this, {
|
|
7
|
+
return updateVersionRow(this, {
|
|
42
8
|
kind: 'global',
|
|
43
9
|
slug: args.global
|
|
44
|
-
},
|
|
45
|
-
await docClient.send(new PutCommand({
|
|
46
|
-
TableName: this.tableName,
|
|
47
|
-
Item: normalizeForDynamo({
|
|
48
|
-
...projected,
|
|
49
|
-
pk: partition,
|
|
50
|
-
sk: String(projected['id'])
|
|
51
|
-
})
|
|
52
|
-
}));
|
|
53
|
-
if (args.returning === false) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
return projected;
|
|
10
|
+
}, args);
|
|
57
11
|
};
|
|
58
12
|
|
|
59
13
|
//# sourceMappingURL=updateGlobalVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { UpdateGlobalVersion } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { UpdateGlobalVersion } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { updateVersionRow } from './utilities/updateVersionRow.js'\n\n/**\n * Same read-merge-write semantics as `updateVersion`. Doesn't cascade\n * `latest` flips for the same reason: Payload owns that contract by issuing\n * paired updates.\n */\nexport const updateGlobalVersion: UpdateGlobalVersion = async function updateGlobalVersion(\n this: DynamoAdapter,\n args,\n) {\n return updateVersionRow(this, { kind: 'global', slug: args.global }, args) as never\n}\n"],"names":["updateVersionRow","updateGlobalVersion","args","kind","slug","global"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,kCAAiC;AAElE;;;;CAIC,GACD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErEC,IAAI;IAEJ,OAAOF,iBAAiB,IAAI,EAAE;QAAEG,MAAM;QAAUC,MAAMF,KAAKG,MAAM;IAAC,GAAGH;AACvE,EAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { UpdateJobs } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Update rows of Payload's jobs queue (`payload-jobs`).
|
|
4
|
+
*
|
|
5
|
+
* The queue calls this to *claim* work: "set `processing: true` on up to N
|
|
6
|
+
* jobs where `processing` is false". With several workers polling at once,
|
|
7
|
+
* that only stays correct if a job can be claimed once. Each write is
|
|
8
|
+
* therefore conditional on its row being unchanged since it was read; a
|
|
9
|
+
* worker that loses the race re-reads the job, sees it no longer matches
|
|
10
|
+
* `where`, and leaves it out of its result instead of running it a second
|
|
11
|
+
* time. (Core's generic fallback for this method reads and then overwrites,
|
|
12
|
+
* so two workers could both walk away with the same job.)
|
|
13
|
+
*
|
|
14
|
+
* `data` is merged onto each row, with two queue-specific rules taken from
|
|
15
|
+
* Payload's Mongo adapter:
|
|
16
|
+
* - `log: { $push: entry }` appends to the job's log instead of replacing it;
|
|
17
|
+
* a non-empty array replaces it; anything else leaves the log alone.
|
|
18
|
+
* - a missing or `null` `updatedAt` means "now".
|
|
19
|
+
*/
|
|
20
|
+
export declare const updateJobs: UpdateJobs;
|
|
21
|
+
//# sourceMappingURL=updateJobs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAgBzC;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,EAAE,UAyCxB,CAAA"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { applySorts } from './utilities/applySorts.js';
|
|
2
|
+
import { mapWithConcurrency } from './utilities/mapWithConcurrency.js';
|
|
3
|
+
import { matchesWhere } from './utilities/matchesWhere.js';
|
|
4
|
+
import { getById, writeWithRetry } from './utilities/optimistic.js';
|
|
5
|
+
import { prepareCollectionWhere, prepareSort } from './utilities/prepareWhere.js';
|
|
6
|
+
import { queryMatching } from './utilities/queryMatching.js';
|
|
7
|
+
import { projectForCollection } from './utilities/resolveSchema.js';
|
|
8
|
+
import { putItem, WRITE_CONCURRENCY } from './utilities/writeItems.js';
|
|
9
|
+
/** Slug of Payload's jobs collection (core doesn't export the constant). */ const JOBS_COLLECTION = 'payload-jobs';
|
|
10
|
+
/**
|
|
11
|
+
* Update rows of Payload's jobs queue (`payload-jobs`).
|
|
12
|
+
*
|
|
13
|
+
* The queue calls this to *claim* work: "set `processing: true` on up to N
|
|
14
|
+
* jobs where `processing` is false". With several workers polling at once,
|
|
15
|
+
* that only stays correct if a job can be claimed once. Each write is
|
|
16
|
+
* therefore conditional on its row being unchanged since it was read; a
|
|
17
|
+
* worker that loses the race re-reads the job, sees it no longer matches
|
|
18
|
+
* `where`, and leaves it out of its result instead of running it a second
|
|
19
|
+
* time. (Core's generic fallback for this method reads and then overwrites,
|
|
20
|
+
* so two workers could both walk away with the same job.)
|
|
21
|
+
*
|
|
22
|
+
* `data` is merged onto each row, with two queue-specific rules taken from
|
|
23
|
+
* Payload's Mongo adapter:
|
|
24
|
+
* - `log: { $push: entry }` appends to the job's log instead of replacing it;
|
|
25
|
+
* a non-empty array replaces it; anything else leaves the log alone.
|
|
26
|
+
* - a missing or `null` `updatedAt` means "now".
|
|
27
|
+
*/ export const updateJobs = async function updateJobs({ id, data, limit, returning, sort, where: rawWhere }) {
|
|
28
|
+
const collection = JOBS_COLLECTION;
|
|
29
|
+
const partition = this.resolvePartition(collection);
|
|
30
|
+
const byId = id !== undefined && id !== null;
|
|
31
|
+
const where = byId ? undefined : await prepareCollectionWhere(this, collection, rawWhere);
|
|
32
|
+
let targets;
|
|
33
|
+
if (byId) {
|
|
34
|
+
const job = await getById(this, partition, id);
|
|
35
|
+
targets = job ? [
|
|
36
|
+
job
|
|
37
|
+
] : [];
|
|
38
|
+
} else {
|
|
39
|
+
const matched = await queryMatching(this, partition, where);
|
|
40
|
+
const defaultSort = this.payload.collections?.[collection]?.config.defaultSort;
|
|
41
|
+
applySorts(matched, prepareSort(this, {
|
|
42
|
+
kind: 'collection',
|
|
43
|
+
slug: collection
|
|
44
|
+
}, sort ?? defaultSort ?? '-createdAt'));
|
|
45
|
+
targets = limit && limit > 0 ? matched.slice(0, limit) : matched;
|
|
46
|
+
}
|
|
47
|
+
const updated = await mapWithConcurrency(targets, WRITE_CONCURRENCY, (target)=>writeWithRetry(target, async ()=>{
|
|
48
|
+
const fresh = await getById(this, partition, target['id']);
|
|
49
|
+
// Someone else changed it out from under us — if it no longer
|
|
50
|
+
// qualifies, it isn't ours to update.
|
|
51
|
+
return fresh && (!where || matchesWhere(fresh, where)) ? fresh : null;
|
|
52
|
+
}, async (current)=>{
|
|
53
|
+
const projected = projectForCollection(this, collection, applyJobData(current, data));
|
|
54
|
+
await putItem(this, partition, projected, {
|
|
55
|
+
replaces: current
|
|
56
|
+
});
|
|
57
|
+
return projected;
|
|
58
|
+
}));
|
|
59
|
+
return returning === false ? null : updated.filter((job)=>job !== null);
|
|
60
|
+
};
|
|
61
|
+
function applyJobData(current, data) {
|
|
62
|
+
const { log, updatedAt, ...rest } = data;
|
|
63
|
+
const merged = {
|
|
64
|
+
...current,
|
|
65
|
+
...rest,
|
|
66
|
+
id: current['id'],
|
|
67
|
+
updatedAt: updatedAt ?? new Date().toISOString()
|
|
68
|
+
};
|
|
69
|
+
if (Array.isArray(log)) {
|
|
70
|
+
if (log.length > 0) merged['log'] = log;
|
|
71
|
+
} else if (log && typeof log === 'object' && '$push' in log) {
|
|
72
|
+
const pushed = log.$push;
|
|
73
|
+
merged['log'] = [
|
|
74
|
+
...Array.isArray(current['log']) ? current['log'] : [],
|
|
75
|
+
...Array.isArray(pushed) ? pushed : [
|
|
76
|
+
pushed
|
|
77
|
+
]
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
return merged;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=updateJobs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { UpdateJobs } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { mapWithConcurrency } from './utilities/mapWithConcurrency.js'\nimport { matchesWhere } from './utilities/matchesWhere.js'\nimport { getById, writeWithRetry } from './utilities/optimistic.js'\nimport { prepareCollectionWhere, prepareSort } from './utilities/prepareWhere.js'\nimport { queryMatching } from './utilities/queryMatching.js'\nimport { projectForCollection } from './utilities/resolveSchema.js'\nimport { putItem, WRITE_CONCURRENCY } from './utilities/writeItems.js'\n\n/** Slug of Payload's jobs collection (core doesn't export the constant). */\nconst JOBS_COLLECTION = 'payload-jobs'\n\n/**\n * Update rows of Payload's jobs queue (`payload-jobs`).\n *\n * The queue calls this to *claim* work: \"set `processing: true` on up to N\n * jobs where `processing` is false\". With several workers polling at once,\n * that only stays correct if a job can be claimed once. Each write is\n * therefore conditional on its row being unchanged since it was read; a\n * worker that loses the race re-reads the job, sees it no longer matches\n * `where`, and leaves it out of its result instead of running it a second\n * time. (Core's generic fallback for this method reads and then overwrites,\n * so two workers could both walk away with the same job.)\n *\n * `data` is merged onto each row, with two queue-specific rules taken from\n * Payload's Mongo adapter:\n * - `log: { $push: entry }` appends to the job's log instead of replacing it;\n * a non-empty array replaces it; anything else leaves the log alone.\n * - a missing or `null` `updatedAt` means \"now\".\n */\nexport const updateJobs: UpdateJobs = async function updateJobs(\n this: DynamoAdapter,\n { id, data, limit, returning, sort, where: rawWhere },\n) {\n const collection = JOBS_COLLECTION\n const partition = this.resolvePartition(collection)\n const byId = id !== undefined && id !== null\n const where = byId ? undefined : await prepareCollectionWhere(this, collection, rawWhere)\n\n let targets: Record<string, unknown>[]\n if (byId) {\n const job = await getById(this, partition, id)\n targets = job ? [job] : []\n } else {\n const matched = await queryMatching(this, partition, where)\n const defaultSort = this.payload.collections?.[collection]?.config.defaultSort\n applySorts(\n matched,\n prepareSort(this, { kind: 'collection', slug: collection }, sort ?? defaultSort ?? '-createdAt'),\n )\n targets = limit && limit > 0 ? matched.slice(0, limit) : matched\n }\n\n const updated = await mapWithConcurrency(targets, WRITE_CONCURRENCY, (target) =>\n writeWithRetry(\n target,\n async () => {\n const fresh = await getById(this, partition, target['id'])\n // Someone else changed it out from under us — if it no longer\n // qualifies, it isn't ours to update.\n return fresh && (!where || matchesWhere(fresh, where)) ? fresh : null\n },\n async (current) => {\n const projected = projectForCollection(this, collection, applyJobData(current, data))\n await putItem(this, partition, projected, { replaces: current })\n return projected\n },\n ),\n )\n\n return returning === false ? null : (updated.filter((job) => job !== null) as never)\n}\n\nfunction applyJobData(\n current: Record<string, unknown>,\n data: Record<string, unknown>,\n): Record<string, unknown> {\n const { log, updatedAt, ...rest } = data\n const merged: Record<string, unknown> = {\n ...current,\n ...rest,\n id: current['id'],\n updatedAt: updatedAt ?? new Date().toISOString(),\n }\n\n if (Array.isArray(log)) {\n if (log.length > 0) merged['log'] = log\n } else if (log && typeof log === 'object' && '$push' in log) {\n const pushed = (log as { $push: unknown }).$push\n merged['log'] = [\n ...(Array.isArray(current['log']) ? current['log'] : []),\n ...(Array.isArray(pushed) ? pushed : [pushed]),\n ]\n }\n\n return merged\n}\n"],"names":["applySorts","mapWithConcurrency","matchesWhere","getById","writeWithRetry","prepareCollectionWhere","prepareSort","queryMatching","projectForCollection","putItem","WRITE_CONCURRENCY","JOBS_COLLECTION","updateJobs","id","data","limit","returning","sort","where","rawWhere","collection","partition","resolvePartition","byId","undefined","targets","job","matched","defaultSort","payload","collections","config","kind","slug","slice","updated","target","fresh","current","projected","applyJobData","replaces","filter","log","updatedAt","rest","merged","Date","toISOString","Array","isArray","length","pushed","$push"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,OAAO,EAAEC,cAAc,QAAQ,4BAA2B;AACnE,SAASC,sBAAsB,EAAEC,WAAW,QAAQ,8BAA6B;AACjF,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,OAAO,EAAEC,iBAAiB,QAAQ,4BAA2B;AAEtE,0EAA0E,GAC1E,MAAMC,kBAAkB;AAExB;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,EAAE,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAEC,IAAI,EAAEC,OAAOC,QAAQ,EAAE;IAErD,MAAMC,aAAaT;IACnB,MAAMU,YAAY,IAAI,CAACC,gBAAgB,CAACF;IACxC,MAAMG,OAAOV,OAAOW,aAAaX,OAAO;IACxC,MAAMK,QAAQK,OAAOC,YAAY,MAAMnB,uBAAuB,IAAI,EAAEe,YAAYD;IAEhF,IAAIM;IACJ,IAAIF,MAAM;QACR,MAAMG,MAAM,MAAMvB,QAAQ,IAAI,EAAEkB,WAAWR;QAC3CY,UAAUC,MAAM;YAACA;SAAI,GAAG,EAAE;IAC5B,OAAO;QACL,MAAMC,UAAU,MAAMpB,cAAc,IAAI,EAAEc,WAAWH;QACrD,MAAMU,cAAc,IAAI,CAACC,OAAO,CAACC,WAAW,EAAE,CAACV,WAAW,EAAEW,OAAOH;QACnE5B,WACE2B,SACArB,YAAY,IAAI,EAAE;YAAE0B,MAAM;YAAcC,MAAMb;QAAW,GAAGH,QAAQW,eAAe;QAErFH,UAAUV,SAASA,QAAQ,IAAIY,QAAQO,KAAK,CAAC,GAAGnB,SAASY;IAC3D;IAEA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