@eresearchqut/ddb-repository 1.13.4 → 1.14.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/dist/index.cjs +5 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +5 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -27
package/dist/index.cjs
CHANGED
|
@@ -22,10 +22,10 @@ const expressionAttributeKey = (key) => (0, lodash.replace)(key, /-/g, "_");
|
|
|
22
22
|
const mapInKeys = (filterExpression) => Array.isArray(filterExpression.value) ? filterExpression.value.map((_, index) => `:${expressionAttributeKey(filterExpression.attribute)}${index}`) : `:${expressionAttributeKey(filterExpression.attribute)}`;
|
|
23
23
|
const mapFilterExpression = (filterExpression) => {
|
|
24
24
|
switch (filterExpression.operator) {
|
|
25
|
-
case
|
|
26
|
-
case
|
|
27
|
-
case
|
|
28
|
-
case
|
|
25
|
+
case "IN": return `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} (${mapInKeys(filterExpression)})`;
|
|
26
|
+
case "BETWEEN": return `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} :${expressionAttributeKey(filterExpression.attribute)}0 AND :${expressionAttributeKey(filterExpression.attribute)}1`;
|
|
27
|
+
case "BEGINS_WITH":
|
|
28
|
+
case "CONTAINS": return `${filterExpression.operator.toLowerCase()}(#${expressionAttributeKey(filterExpression.attribute)}, :${expressionAttributeKey(filterExpression.attribute)})`;
|
|
29
29
|
default: return `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} :${expressionAttributeKey(filterExpression.attribute)}`;
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -328,8 +328,7 @@ const flattenDocument = (doc, prefix = "") => {
|
|
|
328
328
|
if (doc === null) return { [prefix]: null };
|
|
329
329
|
if (typeof doc !== "object") {
|
|
330
330
|
if (isJsonPointerValue(doc)) return { [prefix]: doc };
|
|
331
|
-
|
|
332
|
-
throw new TypeError(`Unsupported value at JSON pointer "${pointer}": expected string, number, boolean, or null but received ${typeof doc}.`);
|
|
331
|
+
throw new TypeError(`Unsupported value at JSON pointer "${prefix === "" ? "/" : prefix}": expected string, number, boolean, or null but received ${typeof doc}.`);
|
|
333
332
|
}
|
|
334
333
|
const result = {};
|
|
335
334
|
if (Array.isArray(doc)) for (let i = 0; i < doc.length; i++) Object.assign(result, flattenDocument(doc[i], `${prefix}/${i}`));
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["GetItemCommand","PutItemCommand","DeleteItemCommand","ReturnValue","UpdateItemCommand","QueryCommand","isEqual","BatchGetItemCommand","BatchWriteItemCommand","ReturnConsumedCapacity"],"sources":["../src/DynamoDbRepository.ts","../src/consumed-capacity-middleware.ts","../src/JsonPointerRepository.ts"],"sourcesContent":["import {\n BatchGetItemCommand,\n BatchGetItemCommandInput,\n BatchWriteItemCommand,\n DeleteItemCommand,\n DynamoDBClient,\n GetItemCommand,\n paginateQuery,\n PutItemCommand,\n QueryCommand,\n QueryCommandInput,\n ReturnConsumedCapacity,\n ReturnValue,\n UpdateItemCommand,\n WriteRequest,\n} from \"@aws-sdk/client-dynamodb\";\nimport {marshall, unmarshall, NativeAttributeValue} from \"@aws-sdk/util-dynamodb\";\nimport {replace, uniqWith, isEqual, pickBy} from \"lodash\";\n\nexport enum FilterOperator {\n EQUALS = \"=\",\n NOT_EQUALS = \"<>\",\n GREATER_THAN_OR_EQUALS = \">=\",\n GREATER_THAN = \">\",\n LESS_THAN = \"<\",\n LESS_THAN_OR_EQUALS = \"<=\",\n IN = \"IN\",\n BETWEEN = \"BETWEEN\",\n BEGINS_WITH = \"BEGINS_WITH\",\n CONTAINS = \"CONTAINS\",\n}\n\nexport interface FilterExpression {\n attribute: string;\n value:\n | string\n | number\n | boolean\n | Array<string | number>\n | [string, string]\n | [number, number];\n operator: FilterOperator;\n negate?: boolean;\n}\n\nexport interface FilterableQuery {\n filterExpressions: Array<FilterExpression>;\n}\n\nexport interface ProjectedQuery {\n projectedAttributes: string[];\n}\n\nexport interface IndexedQuery {\n index: string;\n}\n\nexport interface Query extends Partial<FilterableQuery>, Partial<ProjectedQuery>, Partial<IndexedQuery> {\n [key: string]: unknown;\n filterExpressions?: Array<FilterExpression>;\n projectedAttributes?: string[];\n index?: string;\n sortOrder?: \"ASC\" | \"DESC\";\n limit?: number\n}\n\nconst marshallKey = (key: unknown) =>\n marshall(key as Record<string, NativeAttributeValue>, {removeUndefinedValues: true});\n\nconst expressionAttributeKey = (key: string) => replace(key, /-/g, \"_\");\n\nconst mapInKeys = (filterExpression: FilterExpression) =>\n Array.isArray(filterExpression.value)\n ? filterExpression.value.map(\n (_, index) => `:${expressionAttributeKey(filterExpression.attribute)}${index}`,\n )\n : `:${expressionAttributeKey(filterExpression.attribute)}`;\n\nconst mapFilterExpression = (filterExpression: FilterExpression) => {\n switch (filterExpression.operator) {\n case FilterOperator.IN:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `(${mapInKeys(filterExpression)})`\n );\n case FilterOperator.BETWEEN:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `:${expressionAttributeKey(filterExpression.attribute)}0 AND :${expressionAttributeKey(filterExpression.attribute)}1`\n );\n case FilterOperator.BEGINS_WITH:\n case FilterOperator.CONTAINS:\n return (\n `${filterExpression.operator.toLowerCase()}(#${expressionAttributeKey(filterExpression.attribute)}, ` +\n `:${expressionAttributeKey(filterExpression.attribute)})`\n );\n default:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `:${expressionAttributeKey(filterExpression.attribute)}`\n );\n }\n};\n\nconst mapFilterExpressions = (\n filterExpressions: Array<FilterExpression>,\n) =>\n filterExpressions\n .map((filterExpression) =>\n filterExpression.negate\n ? `NOT ${mapFilterExpression(filterExpression)}`\n : mapFilterExpression(filterExpression),\n )\n .join(\" AND \");\n\nconst mapFilterExpressionValues = (\n filterExpression: FilterExpression,\n): Record<string, string | number | boolean> =>\n Array.isArray(filterExpression.value)\n ? filterExpression.value.reduce(\n (reduction, value, index) => ({\n ...reduction,\n [`:${expressionAttributeKey(filterExpression.attribute)}${index}`]: value,\n }),\n Object.assign({}),\n )\n : {\n [`:${expressionAttributeKey(filterExpression.attribute)}`]:\n filterExpression.value,\n };\n\nconst paginate = <T>(array: Array<T>, pageSize: number) => {\n return array.reduce((acc, val, i) => {\n const idx = Math.floor(i / pageSize)\n const page = acc[idx] || (acc[idx] = [])\n page.push(val)\n return acc\n }, [] as Array<Array<T>>);\n}\n\nexport interface DynamoDbRepositoryOptions {\n client: DynamoDBClient;\n tableName: string;\n hashKey: string;\n rangeKey?: string;\n returnConsumedCapacity?: ReturnConsumedCapacity;\n}\n\nexport interface PageResult<T> {\n items: Array<T>;\n cursor?: string;\n}\n\nexport class DynamoDbRepository<K, T> {\n private readonly dynamoDBClient: DynamoDBClient;\n private readonly tableName: string;\n private readonly hashKey: string;\n private readonly rangKey?: string;\n private readonly returnConsumedCapacity: ReturnConsumedCapacity | undefined;\n\n constructor(options: DynamoDbRepositoryOptions) {\n this.dynamoDBClient = options.client;\n this.tableName = options.tableName;\n this.hashKey = options.hashKey;\n this.rangKey = options.rangeKey;\n this.returnConsumedCapacity = options.returnConsumedCapacity ?? ReturnConsumedCapacity.TOTAL;\n }\n\n getItem = async (key: K): Promise<T | undefined> => {\n return this.dynamoDBClient\n .send(\n new GetItemCommand({\n TableName: this.tableName,\n Key: marshallKey(key),\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }),\n )\n .then((result) =>\n result.Item ? unmarshall(result.Item) as T : undefined,\n )\n };\n\n putItem = async (key: K, record: T): Promise<T> => {\n const Item = marshall({...record, ...key} as Record<string, NativeAttributeValue>, {removeUndefinedValues: true});\n return this.dynamoDBClient\n .send(\n new PutItemCommand({\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n Item,\n }),\n )\n .then(() => unmarshall(Item) as T);\n };\n\n deleteItem = async (key: K): Promise<T | undefined> => {\n return this.dynamoDBClient.send(new DeleteItemCommand({\n TableName: this.tableName,\n Key: marshallKey(key),\n ReturnValues: ReturnValue.ALL_OLD,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n })).then((result) => result.Attributes ?\n unmarshall(result.Attributes) as T : undefined);\n };\n\n\n updateItem = async (\n key: K,\n updates: Partial<T>,\n remove?: string[],\n ): Promise<T | undefined> => {\n const filteredUpdateEntries = Object.entries(updates).filter(([, value]) => value !== undefined);\n const hasUpdates = filteredUpdateEntries.length > 0;\n if (!hasUpdates && !remove?.length) {\n return this.getItem(key);\n }\n const setAttributesExpression = hasUpdates ? `SET ${filteredUpdateEntries\n .map(\n ([key]) =>\n `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`,\n )\n .join(\", \")}` : '';\n const removeAttributesExpression = remove?.length\n ? ` REMOVE ${remove.map((key) => `#${expressionAttributeKey(key)}`).join(\", \")}`\n : \"\";\n const removeAttributeNames = remove?.length\n ? remove.reduce(\n (acc, key) => ({\n ...acc,\n [`#${expressionAttributeKey(key)}`]: key,\n }),\n {} as Record<string, string>,\n )\n : {};\n const updateItemCommandInput = {\n TableName: this.tableName,\n Key: marshallKey(key),\n UpdateExpression: `${setAttributesExpression}${removeAttributesExpression}`,\n ExpressionAttributeNames: filteredUpdateEntries\n .reduce(\n (acc, [key]) => ({\n ...acc,\n [`#${expressionAttributeKey(key)}`]: key,\n }),\n Object.assign(\n removeAttributeNames,\n ),\n ) as Record<string, string>,\n ExpressionAttributeValues: hasUpdates ? marshall(\n filteredUpdateEntries.reduce(\n (acc, [key, value]) => ({\n ...acc,\n [`:${expressionAttributeKey(key)}`]: value,\n }),\n {} as Record<string, NativeAttributeValue>,\n ),\n {removeUndefinedValues: true},\n ) : undefined,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n };\n return this.dynamoDBClient\n .send(new UpdateItemCommand({...updateItemCommandInput, ReturnValues: 'ALL_NEW'}))\n .then((result) => result.Attributes ? unmarshall(result.Attributes) as T : undefined);\n };\n\n\n getItems = async (\n query: Query\n ): Promise<Array<T> | undefined> => {\n const {index, filterExpressions, projectedAttributes, limit, sortOrder,...keys} = query;\n const KeyConditionExpression = Object.keys(keys)\n .map((key) => `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`).join(' AND ');\n const keyExpressionAttributeNames = Object.keys(keys)\n .reduce((acc, key) => ({...acc, [`#${expressionAttributeKey(key)}`]: key}), Object.assign({}));\n const keyExpressionAttributeValues = Object.entries(keys)\n .reduce((acc, [key, value]) => ({...acc, [`:${expressionAttributeKey(key)}`]: value}), Object.assign({}));\n\n const gsiKeyAttributes = index\n ? [this.hashKey, ...(this.rangKey ? [this.rangKey] : [])]\n : [];\n\n const ProjectionExpression = index\n ? gsiKeyAttributes.map((attr) => `#${expressionAttributeKey(attr)}`).join(',')\n : (projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined);\n\n const projectionAttributeNames: Record<string, string> = index\n ? gsiKeyAttributes.reduce(\n (acc: Record<string, string>, attr: string) => ({\n ...acc,\n [`#${expressionAttributeKey(attr)}`]: attr,\n }),\n {},\n )\n : (projectedAttributes ? projectedAttributes.reduce(\n (\n reduction: Record<string, string>,\n attribute: string,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]:\n attribute,\n }),\n Object.assign({}),\n ) : {})\n const hasFilterExpressions = Array.isArray(filterExpressions) && filterExpressions.length > 0;\n const FilterExpression = hasFilterExpressions\n ? mapFilterExpressions(filterExpressions!)\n : undefined;\n const filterAttributeNames: Record<string, string> = hasFilterExpressions\n ? filterExpressions!.reduce(\n (\n reduction: Record<string, string>,\n filterExpression: FilterExpression,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(filterExpression.attribute)}`]:\n filterExpression.attribute,\n }),\n Object.assign({}),\n )\n : {};\n const filterAttributeValues = filterExpressions\n ? filterExpressions.reduce(\n (reduction, filterExpression) => ({\n ...reduction,\n ...mapFilterExpressionValues(filterExpression),\n }),\n Object.assign({}),\n )\n : {};\n\n const Limit = limit;\n const ScanIndexForward = sortOrder === \"DESC\" ? false : undefined;\n const queryCommandInput: QueryCommandInput = {\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n IndexName: index,\n KeyConditionExpression,\n FilterExpression,\n ProjectionExpression,\n ExpressionAttributeNames: {\n ...keyExpressionAttributeNames,\n ...filterAttributeNames,\n ...projectionAttributeNames\n },\n ExpressionAttributeValues: marshall(\n {...keyExpressionAttributeValues, ...filterAttributeValues} as Record<string, NativeAttributeValue>,\n {removeUndefinedValues: true},\n ),\n Limit,\n ScanIndexForward\n };\n const paginator = paginateQuery(\n {client: this.dynamoDBClient, pageSize: 100},\n queryCommandInput,\n );\n\n if (index) {\n const collectedKeys: Array<K> = [];\n for await (const page of paginator) {\n if (page.Items) {\n collectedKeys.push(\n ...(page.Items.map((item) => unmarshall(item) as T)\n .map((item: T) =>\n pickBy(item as object, (_, key) => (key === this.hashKey || key === this.rangKey)) as K)),\n )\n }\n if (limit && collectedKeys.length >= limit) break;\n }\n const keysBatch = limit ? collectedKeys.slice(0, limit) : collectedKeys;\n const keyAttrs = [this.hashKey, ...(this.rangKey ? [this.rangKey] : [])];\n const batchProjectedQuery = projectedAttributes\n ? { ...query, projectedAttributes: [...new Set([...projectedAttributes, ...keyAttrs])] } as ProjectedQuery\n : query as ProjectedQuery;\n const items = await this.batchGetItems(keysBatch, batchProjectedQuery);\n const orderedItems = keysBatch.flatMap((key) => {\n const k = key as Record<string, unknown>;\n const match = (items as Array<T | undefined>).find((item) => {\n if (!item) return false;\n const t = item as Record<string, unknown>;\n return t[this.hashKey] === k[this.hashKey] &&\n (!this.rangKey || t[this.rangKey] === k[this.rangKey]);\n });\n return match ? [match] : [];\n });\n if (projectedAttributes) {\n const projSet = new Set(projectedAttributes);\n return orderedItems.map(item =>\n pickBy(item as object, (_, key) => projSet.has(key)) as T\n ) as Array<T>;\n }\n return orderedItems as Array<T>;\n }\n\n const items: Array<T> = [];\n for await (const page of paginator) {\n if (page.Items) {\n items.push(\n ...(page.Items?.map((item) => unmarshall(item) as T) || []),\n )\n }\n if (limit && items.length >= limit) break;\n }\n return limit ? items.slice(0, limit) : items;\n };\n\n\n getItemsPage = async (\n query: Query & { cursor?: string }\n ): Promise<PageResult<T>> => {\n const {index, filterExpressions, projectedAttributes, limit, sortOrder, cursor, ...keys} = query;\n const KeyConditionExpression = Object.keys(keys)\n .map((key) => `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`).join(' AND ');\n const keyExpressionAttributeNames = Object.keys(keys)\n .reduce((acc, key) => ({...acc, [`#${expressionAttributeKey(key)}`]: key}), Object.assign({}));\n const keyExpressionAttributeValues = Object.entries(keys)\n .reduce((acc, [key, value]) => ({...acc, [`:${expressionAttributeKey(key)}`]: value}), Object.assign({}));\n\n const ProjectionExpression = !index && projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined;\n const projectionAttributeNames: Record<string, string> = !index && projectedAttributes ? projectedAttributes.reduce(\n (reduction: Record<string, string>, attribute: string) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]: attribute,\n }),\n Object.assign({}),\n ) : {};\n const hasFilterExpressions = Array.isArray(filterExpressions) && filterExpressions.length > 0;\n const FilterExpression = hasFilterExpressions\n ? mapFilterExpressions(filterExpressions!)\n : undefined;\n const filterAttributeNames: Record<string, string> = hasFilterExpressions\n ? filterExpressions!.reduce(\n (reduction: Record<string, string>, filterExpression: FilterExpression) => ({\n ...reduction,\n [`#${expressionAttributeKey(filterExpression.attribute)}`]: filterExpression.attribute,\n }),\n Object.assign({}),\n )\n : {};\n const filterAttributeValues = filterExpressions\n ? filterExpressions.reduce(\n (reduction, filterExpression) => ({\n ...reduction,\n ...mapFilterExpressionValues(filterExpression),\n }),\n Object.assign({}),\n )\n : {};\n\n const ExclusiveStartKey = cursor\n ? JSON.parse(Buffer.from(cursor, 'base64').toString('utf-8')) as Record<string, unknown>\n : undefined;\n\n const queryCommandInput: QueryCommandInput = {\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n IndexName: index,\n KeyConditionExpression,\n FilterExpression,\n ProjectionExpression,\n ExpressionAttributeNames: {\n ...keyExpressionAttributeNames,\n ...filterAttributeNames,\n ...projectionAttributeNames\n },\n ExpressionAttributeValues: marshall(\n {...keyExpressionAttributeValues, ...filterAttributeValues} as Record<string, NativeAttributeValue>,\n {removeUndefinedValues: true},\n ),\n Limit: limit,\n ScanIndexForward: sortOrder === \"DESC\" ? false : undefined,\n ExclusiveStartKey: ExclusiveStartKey\n ? marshall(ExclusiveStartKey as Record<string, NativeAttributeValue>, {removeUndefinedValues: true})\n : undefined,\n };\n\n const result = await this.dynamoDBClient.send(new QueryCommand(queryCommandInput));\n const nextCursor = result.LastEvaluatedKey\n ? Buffer.from(JSON.stringify(unmarshall(result.LastEvaluatedKey))).toString('base64')\n : undefined;\n\n if (index) {\n const collectedKeys = (result.Items ?? [])\n .map((item) => unmarshall(item) as T)\n .map((item: T) =>\n pickBy(item as object, (_, key) => (key === this.hashKey || key === this.rangKey)) as K\n );\n const items = await this.batchGetItems(collectedKeys, query as ProjectedQuery);\n return {items: items.filter((item): item is T => item !== undefined), cursor: nextCursor};\n }\n\n const items = (result.Items ?? []).map((item) => unmarshall(item) as T);\n return {items, cursor: nextCursor};\n };\n\n\n batchGetItems = async (\n keys: K[], projectedQuery?: ProjectedQuery\n ): Promise<Array<T | undefined>> => {\n const uniqueKeys = uniqWith(keys, isEqual);\n const keyPages = paginate(uniqueKeys, 100);\n const {projectedAttributes} = projectedQuery || {};\n const ProjectionExpression = projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined;\n const ExpressionAttributeNames = projectedAttributes ?\n projectedAttributes.reduce(\n (\n reduction: Record<string, string>,\n attribute: string,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]:\n attribute,\n }),\n Object.assign({}),\n ) : undefined;\n return Promise.all((keyPages.map(async (keyPage) => {\n const batchRequest: BatchGetItemCommandInput = {\n RequestItems: {\n [this.tableName]: {\n Keys: keyPage.map((key) => marshallKey(key)),\n ProjectionExpression,\n ExpressionAttributeNames,\n }\n },\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }\n\n const fetchPage = async (request: BatchGetItemCommandInput): Promise<T[]> => {\n const result = await this.dynamoDBClient.send(new BatchGetItemCommand(request));\n const retrieved = result.Responses?.[this.tableName]?.map((item) => unmarshall(item) as T) ?? [];\n const unprocessed = result.UnprocessedKeys;\n if (!unprocessed || Object.keys(unprocessed).length === 0) return retrieved;\n return [...retrieved, ...await fetchPage({\n RequestItems: unprocessed,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n })];\n };\n\n return fetchPage(batchRequest);\n })))\n .then((itemSets) => itemSets.flat());\n };\n\n batchWriteItems = async (\n puts: { key: K; item: T }[],\n deletes: K[],\n ): Promise<void> => {\n const requests: WriteRequest[] = [\n ...puts.map(({ key, item }) => ({\n PutRequest: {\n Item: marshall(\n { ...item, ...key } as Record<string, NativeAttributeValue>,\n { removeUndefinedValues: true },\n ),\n },\n })),\n ...deletes.map((key) => ({\n DeleteRequest: { Key: marshallKey(key) },\n })),\n ];\n\n const sendBatch = async (requestItems: Record<string, WriteRequest[]>): Promise<void> => {\n const result = await this.dynamoDBClient.send(\n new BatchWriteItemCommand({\n RequestItems: requestItems,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }),\n );\n const unprocessed = result.UnprocessedItems;\n if (unprocessed && Object.keys(unprocessed).length > 0) {\n await sendBatch(unprocessed as Record<string, WriteRequest[]>);\n }\n };\n\n await Promise.all(\n paginate(requests, 25).map(batch => sendBatch({ [this.tableName]: batch })),\n );\n };\n}\n\n","import {\n ConsumedCapacity,\n ReturnConsumedCapacity,\n ServiceInputTypes,\n ServiceOutputTypes,\n} from \"@aws-sdk/client-dynamodb\";\n\nimport {\n InitializeHandler,\n InitializeHandlerArguments,\n InitializeHandlerOutput,\n} from \"@smithy/types\";\n\nimport {get} from \"lodash\";\n\nexport interface ConsumedCapacityDetail {\n ReturnConsumedCapacity: ReturnConsumedCapacity | undefined\n ConsumedCapacity: ConsumedCapacity | ConsumedCapacity[] | undefined\n}\n\nexport interface ConsumedCapacityMiddlewareConfig {\n onConsumedCapacity: (consumedCapacity: ConsumedCapacityDetail) => Promise<unknown>;\n}\n\nexport const consumedCapacityMiddleware =\n (consumedCapacityMiddlewareConfig: ConsumedCapacityMiddlewareConfig) =>\n (next: InitializeHandler<ServiceInputTypes, ServiceOutputTypes>) =>\n async (args: InitializeHandlerArguments<ServiceInputTypes>): Promise<InitializeHandlerOutput<ServiceOutputTypes>> => {\n const {input} = args;\n const returnConsumedCapacity = get(input, \"ReturnConsumedCapacity\") as ReturnConsumedCapacity | undefined;\n const response = await next(args);\n const {output} = response;\n const consumedCapacity = get(output, \"ConsumedCapacity\") as ConsumedCapacity | ConsumedCapacity[] | undefined;\n await consumedCapacityMiddlewareConfig.onConsumedCapacity({ReturnConsumedCapacity: returnConsumedCapacity, ConsumedCapacity: consumedCapacity});\n return response;\n };","import { DynamoDBClient, ReturnConsumedCapacity } from \"@aws-sdk/client-dynamodb\";\nimport { DynamoDbRepository } from \"./DynamoDbRepository\";\n\nexport type JsonPointerValue = string | number | boolean | null;\n\nexport interface JsonPointerRepositoryOptions {\n client: DynamoDBClient;\n tableName: string;\n idKey?: string;\n pointerKey?: string;\n valueKey?: string;\n returnConsumedCapacity?: ReturnConsumedCapacity;\n}\n\ntype PointerKey = Record<string, string>;\ntype PointerItem = Record<string, unknown>;\n\nconst isJsonPointerValue = (value: unknown): value is JsonPointerValue =>\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\";\n\nconst escapeToken = (token: string): string =>\n token.replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\n\nconst unescapeToken = (token: string): string =>\n token.replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n\nconst validatePointer = (pointer: string): void => {\n if (!pointer.startsWith(\"/\")) {\n throw new TypeError(`Invalid JSON Pointer \"${pointer}\": must start with \"/\".`);\n }\n};\n\nconst flattenDocument = (doc: unknown, prefix = \"\"): Record<string, JsonPointerValue> => {\n if (doc === null) return { [prefix]: null };\n if (typeof doc !== \"object\") {\n if (isJsonPointerValue(doc)) {\n return { [prefix]: doc };\n }\n const pointer = prefix === \"\" ? \"/\" : prefix;\n throw new TypeError(\n `Unsupported value at JSON pointer \"${pointer}\": expected string, number, boolean, or null but received ${typeof doc}.`,\n );\n }\n\n const result: Record<string, JsonPointerValue> = {};\n\n if (Array.isArray(doc)) {\n for (let i = 0; i < doc.length; i++) {\n Object.assign(result, flattenDocument(doc[i], `${prefix}/${i}`));\n }\n } else {\n for (const [key, value] of Object.entries(doc)) {\n Object.assign(result, flattenDocument(value, `${prefix}/${escapeToken(key)}`));\n }\n }\n\n return result;\n};\n\nconst setAtPointer = (\n root: Record<string, unknown>,\n pointer: string,\n value: JsonPointerValue,\n): void => {\n const tokens = pointer.split(\"/\").slice(1).map(unescapeToken);\n if (tokens.length === 0) return;\n\n let current: Record<string, unknown> = root;\n for (let i = 0; i < tokens.length - 1; i++) {\n const token = tokens[i];\n const nextToken = tokens[i + 1];\n if (current[token] == null) {\n current[token] = /^\\d+$/.test(nextToken) ? [] : {};\n } else if (typeof current[token] !== \"object\") {\n throw new TypeError(\n `Conflicting pointers: cannot traverse \"${pointer}\" because \"/${tokens.slice(0, i + 1).join(\"/\")}\" already holds a primitive value.`,\n );\n }\n current = current[token] as Record<string, unknown>;\n }\n\n const lastToken = tokens[tokens.length - 1];\n current[lastToken] = value;\n};\n\nconst reconstructDocument = <T>(\n items: Array<{ pointer: string; value: JsonPointerValue }>,\n): T => {\n const root: Record<string, unknown> = {};\n const sorted = [...items].sort((a, b) => a.pointer.localeCompare(b.pointer));\n for (const item of sorted) {\n setAtPointer(root, item.pointer, item.value);\n }\n return root as T;\n};\n\n/**\n * Stores JSON documents as individual per-pointer DynamoDB items addressed by JSON Pointer (RFC 6901).\n *\n * Only JSON objects are supported as the root document (`T extends Record<string, unknown>`).\n * Root arrays and primitives are not supported. Documents must contain at least one leaf value;\n * empty objects and empty arrays are not supported.\n */\nexport class JsonPointerRepository<T extends Record<string, unknown>> {\n private readonly repository: DynamoDbRepository<PointerKey, PointerItem>;\n private readonly idKey: string;\n private readonly pointerKey: string;\n private readonly valueKey: string;\n\n constructor(options: JsonPointerRepositoryOptions) {\n const {\n client,\n tableName,\n idKey = \"id\",\n pointerKey = \"pointer\",\n valueKey = \"value\",\n returnConsumedCapacity,\n } = options;\n\n this.idKey = idKey;\n this.pointerKey = pointerKey;\n this.valueKey = valueKey;\n\n this.repository = new DynamoDbRepository<PointerKey, PointerItem>({\n client,\n tableName,\n hashKey: idKey,\n rangeKey: pointerKey,\n returnConsumedCapacity,\n });\n }\n\n putDocument = async (id: string, document: T): Promise<void> => {\n const flat = flattenDocument(document);\n const newPointers = Object.keys(flat);\n\n if (newPointers.length === 0) {\n throw new TypeError(\n \"Cannot store a document with no leaf values. Empty objects and arrays are not supported.\",\n );\n }\n\n const newPointerSet = new Set(newPointers);\n const existing = await this.repository.getItems({ [this.idKey]: id }) ?? [];\n const existingPointers = existing.map(item => item[this.pointerKey] as string);\n const stalePointers = existingPointers.filter(p => !newPointerSet.has(p));\n\n const puts = Object.entries(flat).map(([pointer, value]) => {\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n return { key, item: { ...key, [this.valueKey]: value } as PointerItem };\n });\n const deleteKeys = stalePointers.map(\n pointer => ({ [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey),\n );\n await this.repository.batchWriteItems(puts, deleteKeys);\n };\n\n getDocument = async (id: string): Promise<T | undefined> => {\n const items = await this.repository.getItems({ [this.idKey]: id });\n if (!items || items.length === 0) return undefined;\n\n return reconstructDocument<T>(\n items.map(item => ({\n pointer: item[this.pointerKey] as string,\n value: item[this.valueKey] as JsonPointerValue,\n })),\n );\n };\n\n getAttribute = async <V = JsonPointerValue>(\n id: string,\n pointer: string,\n ): Promise<V | undefined> => {\n validatePointer(pointer);\n const item = await this.repository.getItem({\n [this.idKey]: id,\n [this.pointerKey]: pointer,\n } as PointerKey);\n return item ? (item[this.valueKey] as V) : undefined;\n };\n\n putAttribute = async (\n id: string,\n pointer: string,\n value: JsonPointerValue,\n ): Promise<void> => {\n validatePointer(pointer);\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n await this.repository.putItem(key, { ...key, [this.valueKey]: value } as PointerItem);\n };\n\n deleteAttribute = async (id: string, pointer: string): Promise<void> => {\n validatePointer(pointer);\n await this.repository.deleteItem({\n [this.idKey]: id,\n [this.pointerKey]: pointer,\n } as PointerKey);\n };\n\n deleteDocument = async (id: string): Promise<void> => {\n const items = await this.repository.getItems({ [this.idKey]: id }) ?? [];\n if (items.length === 0) return;\n const deleteKeys = items.map(\n item => ({ [this.idKey]: id, [this.pointerKey]: item[this.pointerKey] as string } as PointerKey),\n );\n await this.repository.batchWriteItems([], deleteKeys);\n };\n\n patchDocument = async (\n id: string,\n updates: Record<string, JsonPointerValue | undefined>,\n ): Promise<void> => {\n const entries = Object.entries(updates);\n if (entries.length === 0) return;\n entries.forEach(([pointer]) => validatePointer(pointer));\n const puts = entries\n .filter((entry): entry is [string, JsonPointerValue] => entry[1] !== undefined)\n .map(([pointer, value]) => {\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n return { key, item: { ...key, [this.valueKey]: value } as PointerItem };\n });\n const deleteKeys = entries\n .filter(([, value]) => value === undefined)\n .map(([pointer]) => ({ [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey));\n await this.repository.batchWriteItems(puts, deleteKeys);\n };\n}\n"],"mappings":";;;;;;AAmBA,IAAY,0DAAL;AACH;AACA;AACA;AACA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KAAG,KAAK,QAAQ;KAAK,KAAK,aAAa;IAAS,EAAgB;AACzF,SAAM,KAAK,WAAW,gBAAgB,MAAM,WAAW;;EAlHvD,MAAM,EACF,QACA,WACA,QAAQ,MACR,aAAa,WACb,WAAW,SACX,2BACA;AAEJ,OAAK,QAAQ;AACb,OAAK,aAAa;AAClB,OAAK,WAAW;AAEhB,OAAK,aAAa,IAAI,mBAA4C;GAC9D;GACA;GACA,SAAS;GACT,UAAU;GACV;GACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["GetItemCommand","PutItemCommand","DeleteItemCommand","ReturnValue","UpdateItemCommand","QueryCommand","isEqual","BatchGetItemCommand","BatchWriteItemCommand","ReturnConsumedCapacity"],"sources":["../src/DynamoDbRepository.ts","../src/consumed-capacity-middleware.ts","../src/JsonPointerRepository.ts"],"sourcesContent":["import {\n BatchGetItemCommand,\n BatchGetItemCommandInput,\n BatchWriteItemCommand,\n DeleteItemCommand,\n DynamoDBClient,\n GetItemCommand,\n paginateQuery,\n PutItemCommand,\n QueryCommand,\n QueryCommandInput,\n ReturnConsumedCapacity,\n ReturnValue,\n UpdateItemCommand,\n WriteRequest,\n} from \"@aws-sdk/client-dynamodb\";\nimport {marshall, unmarshall, NativeAttributeValue} from \"@aws-sdk/util-dynamodb\";\nimport {replace, uniqWith, isEqual, pickBy} from \"lodash\";\n\nexport enum FilterOperator {\n EQUALS = \"=\",\n NOT_EQUALS = \"<>\",\n GREATER_THAN_OR_EQUALS = \">=\",\n GREATER_THAN = \">\",\n LESS_THAN = \"<\",\n LESS_THAN_OR_EQUALS = \"<=\",\n IN = \"IN\",\n BETWEEN = \"BETWEEN\",\n BEGINS_WITH = \"BEGINS_WITH\",\n CONTAINS = \"CONTAINS\",\n}\n\nexport interface FilterExpression {\n attribute: string;\n value:\n | string\n | number\n | boolean\n | Array<string | number>\n | [string, string]\n | [number, number];\n operator: FilterOperator;\n negate?: boolean;\n}\n\nexport interface FilterableQuery {\n filterExpressions: Array<FilterExpression>;\n}\n\nexport interface ProjectedQuery {\n projectedAttributes: string[];\n}\n\nexport interface IndexedQuery {\n index: string;\n}\n\nexport interface Query extends Partial<FilterableQuery>, Partial<ProjectedQuery>, Partial<IndexedQuery> {\n [key: string]: unknown;\n filterExpressions?: Array<FilterExpression>;\n projectedAttributes?: string[];\n index?: string;\n sortOrder?: \"ASC\" | \"DESC\";\n limit?: number\n}\n\nconst marshallKey = (key: unknown) =>\n marshall(key as Record<string, NativeAttributeValue>, {removeUndefinedValues: true});\n\nconst expressionAttributeKey = (key: string) => replace(key, /-/g, \"_\");\n\nconst mapInKeys = (filterExpression: FilterExpression) =>\n Array.isArray(filterExpression.value)\n ? filterExpression.value.map(\n (_, index) => `:${expressionAttributeKey(filterExpression.attribute)}${index}`,\n )\n : `:${expressionAttributeKey(filterExpression.attribute)}`;\n\nconst mapFilterExpression = (filterExpression: FilterExpression) => {\n switch (filterExpression.operator) {\n case FilterOperator.IN:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `(${mapInKeys(filterExpression)})`\n );\n case FilterOperator.BETWEEN:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `:${expressionAttributeKey(filterExpression.attribute)}0 AND :${expressionAttributeKey(filterExpression.attribute)}1`\n );\n case FilterOperator.BEGINS_WITH:\n case FilterOperator.CONTAINS:\n return (\n `${filterExpression.operator.toLowerCase()}(#${expressionAttributeKey(filterExpression.attribute)}, ` +\n `:${expressionAttributeKey(filterExpression.attribute)})`\n );\n default:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `:${expressionAttributeKey(filterExpression.attribute)}`\n );\n }\n};\n\nconst mapFilterExpressions = (\n filterExpressions: Array<FilterExpression>,\n) =>\n filterExpressions\n .map((filterExpression) =>\n filterExpression.negate\n ? `NOT ${mapFilterExpression(filterExpression)}`\n : mapFilterExpression(filterExpression),\n )\n .join(\" AND \");\n\nconst mapFilterExpressionValues = (\n filterExpression: FilterExpression,\n): Record<string, string | number | boolean> =>\n Array.isArray(filterExpression.value)\n ? filterExpression.value.reduce(\n (reduction, value, index) => ({\n ...reduction,\n [`:${expressionAttributeKey(filterExpression.attribute)}${index}`]: value,\n }),\n Object.assign({}),\n )\n : {\n [`:${expressionAttributeKey(filterExpression.attribute)}`]:\n filterExpression.value,\n };\n\nconst paginate = <T>(array: Array<T>, pageSize: number) => {\n return array.reduce((acc, val, i) => {\n const idx = Math.floor(i / pageSize)\n const page = acc[idx] || (acc[idx] = [])\n page.push(val)\n return acc\n }, [] as Array<Array<T>>);\n}\n\nexport interface DynamoDbRepositoryOptions {\n client: DynamoDBClient;\n tableName: string;\n hashKey: string;\n rangeKey?: string;\n returnConsumedCapacity?: ReturnConsumedCapacity;\n}\n\nexport interface PageResult<T> {\n items: Array<T>;\n cursor?: string;\n}\n\nexport class DynamoDbRepository<K, T> {\n private readonly dynamoDBClient: DynamoDBClient;\n private readonly tableName: string;\n private readonly hashKey: string;\n private readonly rangKey?: string;\n private readonly returnConsumedCapacity: ReturnConsumedCapacity | undefined;\n\n constructor(options: DynamoDbRepositoryOptions) {\n this.dynamoDBClient = options.client;\n this.tableName = options.tableName;\n this.hashKey = options.hashKey;\n this.rangKey = options.rangeKey;\n this.returnConsumedCapacity = options.returnConsumedCapacity ?? ReturnConsumedCapacity.TOTAL;\n }\n\n getItem = async (key: K): Promise<T | undefined> => {\n return this.dynamoDBClient\n .send(\n new GetItemCommand({\n TableName: this.tableName,\n Key: marshallKey(key),\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }),\n )\n .then((result) =>\n result.Item ? unmarshall(result.Item) as T : undefined,\n )\n };\n\n putItem = async (key: K, record: T): Promise<T> => {\n const Item = marshall({...record, ...key} as Record<string, NativeAttributeValue>, {removeUndefinedValues: true});\n return this.dynamoDBClient\n .send(\n new PutItemCommand({\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n Item,\n }),\n )\n .then(() => unmarshall(Item) as T);\n };\n\n deleteItem = async (key: K): Promise<T | undefined> => {\n return this.dynamoDBClient.send(new DeleteItemCommand({\n TableName: this.tableName,\n Key: marshallKey(key),\n ReturnValues: ReturnValue.ALL_OLD,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n })).then((result) => result.Attributes ?\n unmarshall(result.Attributes) as T : undefined);\n };\n\n\n updateItem = async (\n key: K,\n updates: Partial<T>,\n remove?: string[],\n ): Promise<T | undefined> => {\n const filteredUpdateEntries = Object.entries(updates).filter(([, value]) => value !== undefined);\n const hasUpdates = filteredUpdateEntries.length > 0;\n if (!hasUpdates && !remove?.length) {\n return this.getItem(key);\n }\n const setAttributesExpression = hasUpdates ? `SET ${filteredUpdateEntries\n .map(\n ([key]) =>\n `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`,\n )\n .join(\", \")}` : '';\n const removeAttributesExpression = remove?.length\n ? ` REMOVE ${remove.map((key) => `#${expressionAttributeKey(key)}`).join(\", \")}`\n : \"\";\n const removeAttributeNames = remove?.length\n ? remove.reduce(\n (acc, key) => ({\n ...acc,\n [`#${expressionAttributeKey(key)}`]: key,\n }),\n {} as Record<string, string>,\n )\n : {};\n const updateItemCommandInput = {\n TableName: this.tableName,\n Key: marshallKey(key),\n UpdateExpression: `${setAttributesExpression}${removeAttributesExpression}`,\n ExpressionAttributeNames: filteredUpdateEntries\n .reduce(\n (acc, [key]) => ({\n ...acc,\n [`#${expressionAttributeKey(key)}`]: key,\n }),\n Object.assign(\n removeAttributeNames,\n ),\n ) as Record<string, string>,\n ExpressionAttributeValues: hasUpdates ? marshall(\n filteredUpdateEntries.reduce(\n (acc, [key, value]) => ({\n ...acc,\n [`:${expressionAttributeKey(key)}`]: value,\n }),\n {} as Record<string, NativeAttributeValue>,\n ),\n {removeUndefinedValues: true},\n ) : undefined,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n };\n return this.dynamoDBClient\n .send(new UpdateItemCommand({...updateItemCommandInput, ReturnValues: 'ALL_NEW'}))\n .then((result) => result.Attributes ? unmarshall(result.Attributes) as T : undefined);\n };\n\n\n getItems = async (\n query: Query\n ): Promise<Array<T> | undefined> => {\n const {index, filterExpressions, projectedAttributes, limit, sortOrder,...keys} = query;\n const KeyConditionExpression = Object.keys(keys)\n .map((key) => `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`).join(' AND ');\n const keyExpressionAttributeNames = Object.keys(keys)\n .reduce((acc, key) => ({...acc, [`#${expressionAttributeKey(key)}`]: key}), Object.assign({}));\n const keyExpressionAttributeValues = Object.entries(keys)\n .reduce((acc, [key, value]) => ({...acc, [`:${expressionAttributeKey(key)}`]: value}), Object.assign({}));\n\n const gsiKeyAttributes = index\n ? [this.hashKey, ...(this.rangKey ? [this.rangKey] : [])]\n : [];\n\n const ProjectionExpression = index\n ? gsiKeyAttributes.map((attr) => `#${expressionAttributeKey(attr)}`).join(',')\n : (projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined);\n\n const projectionAttributeNames: Record<string, string> = index\n ? gsiKeyAttributes.reduce(\n (acc: Record<string, string>, attr: string) => ({\n ...acc,\n [`#${expressionAttributeKey(attr)}`]: attr,\n }),\n {},\n )\n : (projectedAttributes ? projectedAttributes.reduce(\n (\n reduction: Record<string, string>,\n attribute: string,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]:\n attribute,\n }),\n Object.assign({}),\n ) : {})\n const hasFilterExpressions = Array.isArray(filterExpressions) && filterExpressions.length > 0;\n const FilterExpression = hasFilterExpressions\n ? mapFilterExpressions(filterExpressions!)\n : undefined;\n const filterAttributeNames: Record<string, string> = hasFilterExpressions\n ? filterExpressions!.reduce(\n (\n reduction: Record<string, string>,\n filterExpression: FilterExpression,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(filterExpression.attribute)}`]:\n filterExpression.attribute,\n }),\n Object.assign({}),\n )\n : {};\n const filterAttributeValues = filterExpressions\n ? filterExpressions.reduce(\n (reduction, filterExpression) => ({\n ...reduction,\n ...mapFilterExpressionValues(filterExpression),\n }),\n Object.assign({}),\n )\n : {};\n\n const Limit = limit;\n const ScanIndexForward = sortOrder === \"DESC\" ? false : undefined;\n const queryCommandInput: QueryCommandInput = {\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n IndexName: index,\n KeyConditionExpression,\n FilterExpression,\n ProjectionExpression,\n ExpressionAttributeNames: {\n ...keyExpressionAttributeNames,\n ...filterAttributeNames,\n ...projectionAttributeNames\n },\n ExpressionAttributeValues: marshall(\n {...keyExpressionAttributeValues, ...filterAttributeValues} as Record<string, NativeAttributeValue>,\n {removeUndefinedValues: true},\n ),\n Limit,\n ScanIndexForward\n };\n const paginator = paginateQuery(\n {client: this.dynamoDBClient, pageSize: 100},\n queryCommandInput,\n );\n\n if (index) {\n const collectedKeys: Array<K> = [];\n for await (const page of paginator) {\n if (page.Items) {\n collectedKeys.push(\n ...(page.Items.map((item) => unmarshall(item) as T)\n .map((item: T) =>\n pickBy(item as object, (_, key) => (key === this.hashKey || key === this.rangKey)) as K)),\n )\n }\n if (limit && collectedKeys.length >= limit) break;\n }\n const keysBatch = limit ? collectedKeys.slice(0, limit) : collectedKeys;\n const keyAttrs = [this.hashKey, ...(this.rangKey ? [this.rangKey] : [])];\n const batchProjectedQuery = projectedAttributes\n ? { ...query, projectedAttributes: [...new Set([...projectedAttributes, ...keyAttrs])] } as ProjectedQuery\n : query as ProjectedQuery;\n const items = await this.batchGetItems(keysBatch, batchProjectedQuery);\n const orderedItems = keysBatch.flatMap((key) => {\n const k = key as Record<string, unknown>;\n const match = (items as Array<T | undefined>).find((item) => {\n if (!item) return false;\n const t = item as Record<string, unknown>;\n return t[this.hashKey] === k[this.hashKey] &&\n (!this.rangKey || t[this.rangKey] === k[this.rangKey]);\n });\n return match ? [match] : [];\n });\n if (projectedAttributes) {\n const projSet = new Set(projectedAttributes);\n return orderedItems.map(item =>\n pickBy(item as object, (_, key) => projSet.has(key)) as T\n ) as Array<T>;\n }\n return orderedItems as Array<T>;\n }\n\n const items: Array<T> = [];\n for await (const page of paginator) {\n if (page.Items) {\n items.push(\n ...(page.Items?.map((item) => unmarshall(item) as T) || []),\n )\n }\n if (limit && items.length >= limit) break;\n }\n return limit ? items.slice(0, limit) : items;\n };\n\n\n getItemsPage = async (\n query: Query & { cursor?: string }\n ): Promise<PageResult<T>> => {\n const {index, filterExpressions, projectedAttributes, limit, sortOrder, cursor, ...keys} = query;\n const KeyConditionExpression = Object.keys(keys)\n .map((key) => `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`).join(' AND ');\n const keyExpressionAttributeNames = Object.keys(keys)\n .reduce((acc, key) => ({...acc, [`#${expressionAttributeKey(key)}`]: key}), Object.assign({}));\n const keyExpressionAttributeValues = Object.entries(keys)\n .reduce((acc, [key, value]) => ({...acc, [`:${expressionAttributeKey(key)}`]: value}), Object.assign({}));\n\n const ProjectionExpression = !index && projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined;\n const projectionAttributeNames: Record<string, string> = !index && projectedAttributes ? projectedAttributes.reduce(\n (reduction: Record<string, string>, attribute: string) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]: attribute,\n }),\n Object.assign({}),\n ) : {};\n const hasFilterExpressions = Array.isArray(filterExpressions) && filterExpressions.length > 0;\n const FilterExpression = hasFilterExpressions\n ? mapFilterExpressions(filterExpressions!)\n : undefined;\n const filterAttributeNames: Record<string, string> = hasFilterExpressions\n ? filterExpressions!.reduce(\n (reduction: Record<string, string>, filterExpression: FilterExpression) => ({\n ...reduction,\n [`#${expressionAttributeKey(filterExpression.attribute)}`]: filterExpression.attribute,\n }),\n Object.assign({}),\n )\n : {};\n const filterAttributeValues = filterExpressions\n ? filterExpressions.reduce(\n (reduction, filterExpression) => ({\n ...reduction,\n ...mapFilterExpressionValues(filterExpression),\n }),\n Object.assign({}),\n )\n : {};\n\n const ExclusiveStartKey = cursor\n ? JSON.parse(Buffer.from(cursor, 'base64').toString('utf-8')) as Record<string, unknown>\n : undefined;\n\n const queryCommandInput: QueryCommandInput = {\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n IndexName: index,\n KeyConditionExpression,\n FilterExpression,\n ProjectionExpression,\n ExpressionAttributeNames: {\n ...keyExpressionAttributeNames,\n ...filterAttributeNames,\n ...projectionAttributeNames\n },\n ExpressionAttributeValues: marshall(\n {...keyExpressionAttributeValues, ...filterAttributeValues} as Record<string, NativeAttributeValue>,\n {removeUndefinedValues: true},\n ),\n Limit: limit,\n ScanIndexForward: sortOrder === \"DESC\" ? false : undefined,\n ExclusiveStartKey: ExclusiveStartKey\n ? marshall(ExclusiveStartKey as Record<string, NativeAttributeValue>, {removeUndefinedValues: true})\n : undefined,\n };\n\n const result = await this.dynamoDBClient.send(new QueryCommand(queryCommandInput));\n const nextCursor = result.LastEvaluatedKey\n ? Buffer.from(JSON.stringify(unmarshall(result.LastEvaluatedKey))).toString('base64')\n : undefined;\n\n if (index) {\n const collectedKeys = (result.Items ?? [])\n .map((item) => unmarshall(item) as T)\n .map((item: T) =>\n pickBy(item as object, (_, key) => (key === this.hashKey || key === this.rangKey)) as K\n );\n const items = await this.batchGetItems(collectedKeys, query as ProjectedQuery);\n return {items: items.filter((item): item is T => item !== undefined), cursor: nextCursor};\n }\n\n const items = (result.Items ?? []).map((item) => unmarshall(item) as T);\n return {items, cursor: nextCursor};\n };\n\n\n batchGetItems = async (\n keys: K[], projectedQuery?: ProjectedQuery\n ): Promise<Array<T | undefined>> => {\n const uniqueKeys = uniqWith(keys, isEqual);\n const keyPages = paginate(uniqueKeys, 100);\n const {projectedAttributes} = projectedQuery || {};\n const ProjectionExpression = projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined;\n const ExpressionAttributeNames = projectedAttributes ?\n projectedAttributes.reduce(\n (\n reduction: Record<string, string>,\n attribute: string,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]:\n attribute,\n }),\n Object.assign({}),\n ) : undefined;\n return Promise.all((keyPages.map(async (keyPage) => {\n const batchRequest: BatchGetItemCommandInput = {\n RequestItems: {\n [this.tableName]: {\n Keys: keyPage.map((key) => marshallKey(key)),\n ProjectionExpression,\n ExpressionAttributeNames,\n }\n },\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }\n\n const fetchPage = async (request: BatchGetItemCommandInput): Promise<T[]> => {\n const result = await this.dynamoDBClient.send(new BatchGetItemCommand(request));\n const retrieved = result.Responses?.[this.tableName]?.map((item) => unmarshall(item) as T) ?? [];\n const unprocessed = result.UnprocessedKeys;\n if (!unprocessed || Object.keys(unprocessed).length === 0) return retrieved;\n return [...retrieved, ...await fetchPage({\n RequestItems: unprocessed,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n })];\n };\n\n return fetchPage(batchRequest);\n })))\n .then((itemSets) => itemSets.flat());\n };\n\n batchWriteItems = async (\n puts: { key: K; item: T }[],\n deletes: K[],\n ): Promise<void> => {\n const requests: WriteRequest[] = [\n ...puts.map(({ key, item }) => ({\n PutRequest: {\n Item: marshall(\n { ...item, ...key } as Record<string, NativeAttributeValue>,\n { removeUndefinedValues: true },\n ),\n },\n })),\n ...deletes.map((key) => ({\n DeleteRequest: { Key: marshallKey(key) },\n })),\n ];\n\n const sendBatch = async (requestItems: Record<string, WriteRequest[]>): Promise<void> => {\n const result = await this.dynamoDBClient.send(\n new BatchWriteItemCommand({\n RequestItems: requestItems,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }),\n );\n const unprocessed = result.UnprocessedItems;\n if (unprocessed && Object.keys(unprocessed).length > 0) {\n await sendBatch(unprocessed as Record<string, WriteRequest[]>);\n }\n };\n\n await Promise.all(\n paginate(requests, 25).map(batch => sendBatch({ [this.tableName]: batch })),\n );\n };\n}\n\n","import {\n ConsumedCapacity,\n ReturnConsumedCapacity,\n ServiceInputTypes,\n ServiceOutputTypes,\n} from \"@aws-sdk/client-dynamodb\";\n\nimport {\n InitializeHandler,\n InitializeHandlerArguments,\n InitializeHandlerOutput,\n} from \"@smithy/types\";\n\nimport {get} from \"lodash\";\n\nexport interface ConsumedCapacityDetail {\n ReturnConsumedCapacity: ReturnConsumedCapacity | undefined\n ConsumedCapacity: ConsumedCapacity | ConsumedCapacity[] | undefined\n}\n\nexport interface ConsumedCapacityMiddlewareConfig {\n onConsumedCapacity: (consumedCapacity: ConsumedCapacityDetail) => Promise<unknown>;\n}\n\nexport const consumedCapacityMiddleware =\n (consumedCapacityMiddlewareConfig: ConsumedCapacityMiddlewareConfig) =>\n (next: InitializeHandler<ServiceInputTypes, ServiceOutputTypes>) =>\n async (args: InitializeHandlerArguments<ServiceInputTypes>): Promise<InitializeHandlerOutput<ServiceOutputTypes>> => {\n const {input} = args;\n const returnConsumedCapacity = get(input, \"ReturnConsumedCapacity\") as ReturnConsumedCapacity | undefined;\n const response = await next(args);\n const {output} = response;\n const consumedCapacity = get(output, \"ConsumedCapacity\") as ConsumedCapacity | ConsumedCapacity[] | undefined;\n await consumedCapacityMiddlewareConfig.onConsumedCapacity({ReturnConsumedCapacity: returnConsumedCapacity, ConsumedCapacity: consumedCapacity});\n return response;\n };","import { DynamoDBClient, ReturnConsumedCapacity } from \"@aws-sdk/client-dynamodb\";\nimport { DynamoDbRepository } from \"./DynamoDbRepository\";\n\nexport type JsonPointerValue = string | number | boolean | null;\n\nexport interface JsonPointerRepositoryOptions {\n client: DynamoDBClient;\n tableName: string;\n idKey?: string;\n pointerKey?: string;\n valueKey?: string;\n returnConsumedCapacity?: ReturnConsumedCapacity;\n}\n\ntype PointerKey = Record<string, string>;\ntype PointerItem = Record<string, unknown>;\n\nconst isJsonPointerValue = (value: unknown): value is JsonPointerValue =>\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\";\n\nconst escapeToken = (token: string): string =>\n token.replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\n\nconst unescapeToken = (token: string): string =>\n token.replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n\nconst validatePointer = (pointer: string): void => {\n if (!pointer.startsWith(\"/\")) {\n throw new TypeError(`Invalid JSON Pointer \"${pointer}\": must start with \"/\".`);\n }\n};\n\nconst flattenDocument = (doc: unknown, prefix = \"\"): Record<string, JsonPointerValue> => {\n if (doc === null) return { [prefix]: null };\n if (typeof doc !== \"object\") {\n if (isJsonPointerValue(doc)) {\n return { [prefix]: doc };\n }\n const pointer = prefix === \"\" ? \"/\" : prefix;\n throw new TypeError(\n `Unsupported value at JSON pointer \"${pointer}\": expected string, number, boolean, or null but received ${typeof doc}.`,\n );\n }\n\n const result: Record<string, JsonPointerValue> = {};\n\n if (Array.isArray(doc)) {\n for (let i = 0; i < doc.length; i++) {\n Object.assign(result, flattenDocument(doc[i], `${prefix}/${i}`));\n }\n } else {\n for (const [key, value] of Object.entries(doc)) {\n Object.assign(result, flattenDocument(value, `${prefix}/${escapeToken(key)}`));\n }\n }\n\n return result;\n};\n\nconst setAtPointer = (\n root: Record<string, unknown>,\n pointer: string,\n value: JsonPointerValue,\n): void => {\n const tokens = pointer.split(\"/\").slice(1).map(unescapeToken);\n if (tokens.length === 0) return;\n\n let current: Record<string, unknown> = root;\n for (let i = 0; i < tokens.length - 1; i++) {\n const token = tokens[i];\n const nextToken = tokens[i + 1];\n if (current[token] == null) {\n current[token] = /^\\d+$/.test(nextToken) ? [] : {};\n } else if (typeof current[token] !== \"object\") {\n throw new TypeError(\n `Conflicting pointers: cannot traverse \"${pointer}\" because \"/${tokens.slice(0, i + 1).join(\"/\")}\" already holds a primitive value.`,\n );\n }\n current = current[token] as Record<string, unknown>;\n }\n\n const lastToken = tokens[tokens.length - 1];\n current[lastToken] = value;\n};\n\nconst reconstructDocument = <T>(\n items: Array<{ pointer: string; value: JsonPointerValue }>,\n): T => {\n const root: Record<string, unknown> = {};\n const sorted = [...items].sort((a, b) => a.pointer.localeCompare(b.pointer));\n for (const item of sorted) {\n setAtPointer(root, item.pointer, item.value);\n }\n return root as T;\n};\n\n/**\n * Stores JSON documents as individual per-pointer DynamoDB items addressed by JSON Pointer (RFC 6901).\n *\n * Only JSON objects are supported as the root document (`T extends Record<string, unknown>`).\n * Root arrays and primitives are not supported. Documents must contain at least one leaf value;\n * empty objects and empty arrays are not supported.\n */\nexport class JsonPointerRepository<T extends Record<string, unknown>> {\n private readonly repository: DynamoDbRepository<PointerKey, PointerItem>;\n private readonly idKey: string;\n private readonly pointerKey: string;\n private readonly valueKey: string;\n\n constructor(options: JsonPointerRepositoryOptions) {\n const {\n client,\n tableName,\n idKey = \"id\",\n pointerKey = \"pointer\",\n valueKey = \"value\",\n returnConsumedCapacity,\n } = options;\n\n this.idKey = idKey;\n this.pointerKey = pointerKey;\n this.valueKey = valueKey;\n\n this.repository = new DynamoDbRepository<PointerKey, PointerItem>({\n client,\n tableName,\n hashKey: idKey,\n rangeKey: pointerKey,\n returnConsumedCapacity,\n });\n }\n\n putDocument = async (id: string, document: T): Promise<void> => {\n const flat = flattenDocument(document);\n const newPointers = Object.keys(flat);\n\n if (newPointers.length === 0) {\n throw new TypeError(\n \"Cannot store a document with no leaf values. Empty objects and arrays are not supported.\",\n );\n }\n\n const newPointerSet = new Set(newPointers);\n const existing = await this.repository.getItems({ [this.idKey]: id }) ?? [];\n const existingPointers = existing.map(item => item[this.pointerKey] as string);\n const stalePointers = existingPointers.filter(p => !newPointerSet.has(p));\n\n const puts = Object.entries(flat).map(([pointer, value]) => {\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n return { key, item: { ...key, [this.valueKey]: value } as PointerItem };\n });\n const deleteKeys = stalePointers.map(\n pointer => ({ [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey),\n );\n await this.repository.batchWriteItems(puts, deleteKeys);\n };\n\n getDocument = async (id: string): Promise<T | undefined> => {\n const items = await this.repository.getItems({ [this.idKey]: id });\n if (!items || items.length === 0) return undefined;\n\n return reconstructDocument<T>(\n items.map(item => ({\n pointer: item[this.pointerKey] as string,\n value: item[this.valueKey] as JsonPointerValue,\n })),\n );\n };\n\n getAttribute = async <V = JsonPointerValue>(\n id: string,\n pointer: string,\n ): Promise<V | undefined> => {\n validatePointer(pointer);\n const item = await this.repository.getItem({\n [this.idKey]: id,\n [this.pointerKey]: pointer,\n } as PointerKey);\n return item ? (item[this.valueKey] as V) : undefined;\n };\n\n putAttribute = async (\n id: string,\n pointer: string,\n value: JsonPointerValue,\n ): Promise<void> => {\n validatePointer(pointer);\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n await this.repository.putItem(key, { ...key, [this.valueKey]: value } as PointerItem);\n };\n\n deleteAttribute = async (id: string, pointer: string): Promise<void> => {\n validatePointer(pointer);\n await this.repository.deleteItem({\n [this.idKey]: id,\n [this.pointerKey]: pointer,\n } as PointerKey);\n };\n\n deleteDocument = async (id: string): Promise<void> => {\n const items = await this.repository.getItems({ [this.idKey]: id }) ?? [];\n if (items.length === 0) return;\n const deleteKeys = items.map(\n item => ({ [this.idKey]: id, [this.pointerKey]: item[this.pointerKey] as string } as PointerKey),\n );\n await this.repository.batchWriteItems([], deleteKeys);\n };\n\n patchDocument = async (\n id: string,\n updates: Record<string, JsonPointerValue | undefined>,\n ): Promise<void> => {\n const entries = Object.entries(updates);\n if (entries.length === 0) return;\n entries.forEach(([pointer]) => validatePointer(pointer));\n const puts = entries\n .filter((entry): entry is [string, JsonPointerValue] => entry[1] !== undefined)\n .map(([pointer, value]) => {\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n return { key, item: { ...key, [this.valueKey]: value } as PointerItem };\n });\n const deleteKeys = entries\n .filter(([, value]) => value === undefined)\n .map(([pointer]) => ({ [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey));\n await this.repository.batchWriteItems(puts, deleteKeys);\n };\n}\n"],"mappings":";;;;;;AAmBA,IAAY,iBAAL;CACH;CACA;CACA;CACA;CACA;CACA;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GAAG;OAAM,KAAK,WAAW;KAAM;IAAiB;GAC1E,CAAC;GACL,MAAM,aAAa,QACd,QAAQ,GAAG,WAAW,UAAU,MAAS,EACzC,KAAK,CAAC,cAAc;KAAG,KAAK,QAAQ;KAAK,KAAK,aAAa;GAAQ,EAAgB;GACxF,MAAM,KAAK,WAAW,gBAAgB,MAAM,UAAU;EAC1D;EAnHI,MAAM,EACF,QACA,WACA,QAAQ,MACR,aAAa,WACb,WAAW,SACX,2BACA;EAEJ,KAAK,QAAQ;EACb,KAAK,aAAa;EAClB,KAAK,WAAW;EAEhB,KAAK,aAAa,IAAI,mBAA4C;GAC9D;GACA;GACA,SAAS;GACT,UAAU;GACV;EACJ,CAAC;CACL;AAgGJ"}
|
package/dist/index.mjs
CHANGED
|
@@ -21,10 +21,10 @@ const expressionAttributeKey = (key) => replace(key, /-/g, "_");
|
|
|
21
21
|
const mapInKeys = (filterExpression) => Array.isArray(filterExpression.value) ? filterExpression.value.map((_, index) => `:${expressionAttributeKey(filterExpression.attribute)}${index}`) : `:${expressionAttributeKey(filterExpression.attribute)}`;
|
|
22
22
|
const mapFilterExpression = (filterExpression) => {
|
|
23
23
|
switch (filterExpression.operator) {
|
|
24
|
-
case
|
|
25
|
-
case
|
|
26
|
-
case
|
|
27
|
-
case
|
|
24
|
+
case "IN": return `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} (${mapInKeys(filterExpression)})`;
|
|
25
|
+
case "BETWEEN": return `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} :${expressionAttributeKey(filterExpression.attribute)}0 AND :${expressionAttributeKey(filterExpression.attribute)}1`;
|
|
26
|
+
case "BEGINS_WITH":
|
|
27
|
+
case "CONTAINS": return `${filterExpression.operator.toLowerCase()}(#${expressionAttributeKey(filterExpression.attribute)}, :${expressionAttributeKey(filterExpression.attribute)})`;
|
|
28
28
|
default: return `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} :${expressionAttributeKey(filterExpression.attribute)}`;
|
|
29
29
|
}
|
|
30
30
|
};
|
|
@@ -327,8 +327,7 @@ const flattenDocument = (doc, prefix = "") => {
|
|
|
327
327
|
if (doc === null) return { [prefix]: null };
|
|
328
328
|
if (typeof doc !== "object") {
|
|
329
329
|
if (isJsonPointerValue(doc)) return { [prefix]: doc };
|
|
330
|
-
|
|
331
|
-
throw new TypeError(`Unsupported value at JSON pointer "${pointer}": expected string, number, boolean, or null but received ${typeof doc}.`);
|
|
330
|
+
throw new TypeError(`Unsupported value at JSON pointer "${prefix === "" ? "/" : prefix}": expected string, number, boolean, or null but received ${typeof doc}.`);
|
|
332
331
|
}
|
|
333
332
|
const result = {};
|
|
334
333
|
if (Array.isArray(doc)) for (let i = 0; i < doc.length; i++) Object.assign(result, flattenDocument(doc[i], `${prefix}/${i}`));
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/DynamoDbRepository.ts","../src/consumed-capacity-middleware.ts","../src/JsonPointerRepository.ts"],"sourcesContent":["import {\n BatchGetItemCommand,\n BatchGetItemCommandInput,\n BatchWriteItemCommand,\n DeleteItemCommand,\n DynamoDBClient,\n GetItemCommand,\n paginateQuery,\n PutItemCommand,\n QueryCommand,\n QueryCommandInput,\n ReturnConsumedCapacity,\n ReturnValue,\n UpdateItemCommand,\n WriteRequest,\n} from \"@aws-sdk/client-dynamodb\";\nimport {marshall, unmarshall, NativeAttributeValue} from \"@aws-sdk/util-dynamodb\";\nimport {replace, uniqWith, isEqual, pickBy} from \"lodash\";\n\nexport enum FilterOperator {\n EQUALS = \"=\",\n NOT_EQUALS = \"<>\",\n GREATER_THAN_OR_EQUALS = \">=\",\n GREATER_THAN = \">\",\n LESS_THAN = \"<\",\n LESS_THAN_OR_EQUALS = \"<=\",\n IN = \"IN\",\n BETWEEN = \"BETWEEN\",\n BEGINS_WITH = \"BEGINS_WITH\",\n CONTAINS = \"CONTAINS\",\n}\n\nexport interface FilterExpression {\n attribute: string;\n value:\n | string\n | number\n | boolean\n | Array<string | number>\n | [string, string]\n | [number, number];\n operator: FilterOperator;\n negate?: boolean;\n}\n\nexport interface FilterableQuery {\n filterExpressions: Array<FilterExpression>;\n}\n\nexport interface ProjectedQuery {\n projectedAttributes: string[];\n}\n\nexport interface IndexedQuery {\n index: string;\n}\n\nexport interface Query extends Partial<FilterableQuery>, Partial<ProjectedQuery>, Partial<IndexedQuery> {\n [key: string]: unknown;\n filterExpressions?: Array<FilterExpression>;\n projectedAttributes?: string[];\n index?: string;\n sortOrder?: \"ASC\" | \"DESC\";\n limit?: number\n}\n\nconst marshallKey = (key: unknown) =>\n marshall(key as Record<string, NativeAttributeValue>, {removeUndefinedValues: true});\n\nconst expressionAttributeKey = (key: string) => replace(key, /-/g, \"_\");\n\nconst mapInKeys = (filterExpression: FilterExpression) =>\n Array.isArray(filterExpression.value)\n ? filterExpression.value.map(\n (_, index) => `:${expressionAttributeKey(filterExpression.attribute)}${index}`,\n )\n : `:${expressionAttributeKey(filterExpression.attribute)}`;\n\nconst mapFilterExpression = (filterExpression: FilterExpression) => {\n switch (filterExpression.operator) {\n case FilterOperator.IN:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `(${mapInKeys(filterExpression)})`\n );\n case FilterOperator.BETWEEN:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `:${expressionAttributeKey(filterExpression.attribute)}0 AND :${expressionAttributeKey(filterExpression.attribute)}1`\n );\n case FilterOperator.BEGINS_WITH:\n case FilterOperator.CONTAINS:\n return (\n `${filterExpression.operator.toLowerCase()}(#${expressionAttributeKey(filterExpression.attribute)}, ` +\n `:${expressionAttributeKey(filterExpression.attribute)})`\n );\n default:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `:${expressionAttributeKey(filterExpression.attribute)}`\n );\n }\n};\n\nconst mapFilterExpressions = (\n filterExpressions: Array<FilterExpression>,\n) =>\n filterExpressions\n .map((filterExpression) =>\n filterExpression.negate\n ? `NOT ${mapFilterExpression(filterExpression)}`\n : mapFilterExpression(filterExpression),\n )\n .join(\" AND \");\n\nconst mapFilterExpressionValues = (\n filterExpression: FilterExpression,\n): Record<string, string | number | boolean> =>\n Array.isArray(filterExpression.value)\n ? filterExpression.value.reduce(\n (reduction, value, index) => ({\n ...reduction,\n [`:${expressionAttributeKey(filterExpression.attribute)}${index}`]: value,\n }),\n Object.assign({}),\n )\n : {\n [`:${expressionAttributeKey(filterExpression.attribute)}`]:\n filterExpression.value,\n };\n\nconst paginate = <T>(array: Array<T>, pageSize: number) => {\n return array.reduce((acc, val, i) => {\n const idx = Math.floor(i / pageSize)\n const page = acc[idx] || (acc[idx] = [])\n page.push(val)\n return acc\n }, [] as Array<Array<T>>);\n}\n\nexport interface DynamoDbRepositoryOptions {\n client: DynamoDBClient;\n tableName: string;\n hashKey: string;\n rangeKey?: string;\n returnConsumedCapacity?: ReturnConsumedCapacity;\n}\n\nexport interface PageResult<T> {\n items: Array<T>;\n cursor?: string;\n}\n\nexport class DynamoDbRepository<K, T> {\n private readonly dynamoDBClient: DynamoDBClient;\n private readonly tableName: string;\n private readonly hashKey: string;\n private readonly rangKey?: string;\n private readonly returnConsumedCapacity: ReturnConsumedCapacity | undefined;\n\n constructor(options: DynamoDbRepositoryOptions) {\n this.dynamoDBClient = options.client;\n this.tableName = options.tableName;\n this.hashKey = options.hashKey;\n this.rangKey = options.rangeKey;\n this.returnConsumedCapacity = options.returnConsumedCapacity ?? ReturnConsumedCapacity.TOTAL;\n }\n\n getItem = async (key: K): Promise<T | undefined> => {\n return this.dynamoDBClient\n .send(\n new GetItemCommand({\n TableName: this.tableName,\n Key: marshallKey(key),\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }),\n )\n .then((result) =>\n result.Item ? unmarshall(result.Item) as T : undefined,\n )\n };\n\n putItem = async (key: K, record: T): Promise<T> => {\n const Item = marshall({...record, ...key} as Record<string, NativeAttributeValue>, {removeUndefinedValues: true});\n return this.dynamoDBClient\n .send(\n new PutItemCommand({\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n Item,\n }),\n )\n .then(() => unmarshall(Item) as T);\n };\n\n deleteItem = async (key: K): Promise<T | undefined> => {\n return this.dynamoDBClient.send(new DeleteItemCommand({\n TableName: this.tableName,\n Key: marshallKey(key),\n ReturnValues: ReturnValue.ALL_OLD,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n })).then((result) => result.Attributes ?\n unmarshall(result.Attributes) as T : undefined);\n };\n\n\n updateItem = async (\n key: K,\n updates: Partial<T>,\n remove?: string[],\n ): Promise<T | undefined> => {\n const filteredUpdateEntries = Object.entries(updates).filter(([, value]) => value !== undefined);\n const hasUpdates = filteredUpdateEntries.length > 0;\n if (!hasUpdates && !remove?.length) {\n return this.getItem(key);\n }\n const setAttributesExpression = hasUpdates ? `SET ${filteredUpdateEntries\n .map(\n ([key]) =>\n `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`,\n )\n .join(\", \")}` : '';\n const removeAttributesExpression = remove?.length\n ? ` REMOVE ${remove.map((key) => `#${expressionAttributeKey(key)}`).join(\", \")}`\n : \"\";\n const removeAttributeNames = remove?.length\n ? remove.reduce(\n (acc, key) => ({\n ...acc,\n [`#${expressionAttributeKey(key)}`]: key,\n }),\n {} as Record<string, string>,\n )\n : {};\n const updateItemCommandInput = {\n TableName: this.tableName,\n Key: marshallKey(key),\n UpdateExpression: `${setAttributesExpression}${removeAttributesExpression}`,\n ExpressionAttributeNames: filteredUpdateEntries\n .reduce(\n (acc, [key]) => ({\n ...acc,\n [`#${expressionAttributeKey(key)}`]: key,\n }),\n Object.assign(\n removeAttributeNames,\n ),\n ) as Record<string, string>,\n ExpressionAttributeValues: hasUpdates ? marshall(\n filteredUpdateEntries.reduce(\n (acc, [key, value]) => ({\n ...acc,\n [`:${expressionAttributeKey(key)}`]: value,\n }),\n {} as Record<string, NativeAttributeValue>,\n ),\n {removeUndefinedValues: true},\n ) : undefined,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n };\n return this.dynamoDBClient\n .send(new UpdateItemCommand({...updateItemCommandInput, ReturnValues: 'ALL_NEW'}))\n .then((result) => result.Attributes ? unmarshall(result.Attributes) as T : undefined);\n };\n\n\n getItems = async (\n query: Query\n ): Promise<Array<T> | undefined> => {\n const {index, filterExpressions, projectedAttributes, limit, sortOrder,...keys} = query;\n const KeyConditionExpression = Object.keys(keys)\n .map((key) => `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`).join(' AND ');\n const keyExpressionAttributeNames = Object.keys(keys)\n .reduce((acc, key) => ({...acc, [`#${expressionAttributeKey(key)}`]: key}), Object.assign({}));\n const keyExpressionAttributeValues = Object.entries(keys)\n .reduce((acc, [key, value]) => ({...acc, [`:${expressionAttributeKey(key)}`]: value}), Object.assign({}));\n\n const gsiKeyAttributes = index\n ? [this.hashKey, ...(this.rangKey ? [this.rangKey] : [])]\n : [];\n\n const ProjectionExpression = index\n ? gsiKeyAttributes.map((attr) => `#${expressionAttributeKey(attr)}`).join(',')\n : (projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined);\n\n const projectionAttributeNames: Record<string, string> = index\n ? gsiKeyAttributes.reduce(\n (acc: Record<string, string>, attr: string) => ({\n ...acc,\n [`#${expressionAttributeKey(attr)}`]: attr,\n }),\n {},\n )\n : (projectedAttributes ? projectedAttributes.reduce(\n (\n reduction: Record<string, string>,\n attribute: string,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]:\n attribute,\n }),\n Object.assign({}),\n ) : {})\n const hasFilterExpressions = Array.isArray(filterExpressions) && filterExpressions.length > 0;\n const FilterExpression = hasFilterExpressions\n ? mapFilterExpressions(filterExpressions!)\n : undefined;\n const filterAttributeNames: Record<string, string> = hasFilterExpressions\n ? filterExpressions!.reduce(\n (\n reduction: Record<string, string>,\n filterExpression: FilterExpression,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(filterExpression.attribute)}`]:\n filterExpression.attribute,\n }),\n Object.assign({}),\n )\n : {};\n const filterAttributeValues = filterExpressions\n ? filterExpressions.reduce(\n (reduction, filterExpression) => ({\n ...reduction,\n ...mapFilterExpressionValues(filterExpression),\n }),\n Object.assign({}),\n )\n : {};\n\n const Limit = limit;\n const ScanIndexForward = sortOrder === \"DESC\" ? false : undefined;\n const queryCommandInput: QueryCommandInput = {\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n IndexName: index,\n KeyConditionExpression,\n FilterExpression,\n ProjectionExpression,\n ExpressionAttributeNames: {\n ...keyExpressionAttributeNames,\n ...filterAttributeNames,\n ...projectionAttributeNames\n },\n ExpressionAttributeValues: marshall(\n {...keyExpressionAttributeValues, ...filterAttributeValues} as Record<string, NativeAttributeValue>,\n {removeUndefinedValues: true},\n ),\n Limit,\n ScanIndexForward\n };\n const paginator = paginateQuery(\n {client: this.dynamoDBClient, pageSize: 100},\n queryCommandInput,\n );\n\n if (index) {\n const collectedKeys: Array<K> = [];\n for await (const page of paginator) {\n if (page.Items) {\n collectedKeys.push(\n ...(page.Items.map((item) => unmarshall(item) as T)\n .map((item: T) =>\n pickBy(item as object, (_, key) => (key === this.hashKey || key === this.rangKey)) as K)),\n )\n }\n if (limit && collectedKeys.length >= limit) break;\n }\n const keysBatch = limit ? collectedKeys.slice(0, limit) : collectedKeys;\n const keyAttrs = [this.hashKey, ...(this.rangKey ? [this.rangKey] : [])];\n const batchProjectedQuery = projectedAttributes\n ? { ...query, projectedAttributes: [...new Set([...projectedAttributes, ...keyAttrs])] } as ProjectedQuery\n : query as ProjectedQuery;\n const items = await this.batchGetItems(keysBatch, batchProjectedQuery);\n const orderedItems = keysBatch.flatMap((key) => {\n const k = key as Record<string, unknown>;\n const match = (items as Array<T | undefined>).find((item) => {\n if (!item) return false;\n const t = item as Record<string, unknown>;\n return t[this.hashKey] === k[this.hashKey] &&\n (!this.rangKey || t[this.rangKey] === k[this.rangKey]);\n });\n return match ? [match] : [];\n });\n if (projectedAttributes) {\n const projSet = new Set(projectedAttributes);\n return orderedItems.map(item =>\n pickBy(item as object, (_, key) => projSet.has(key)) as T\n ) as Array<T>;\n }\n return orderedItems as Array<T>;\n }\n\n const items: Array<T> = [];\n for await (const page of paginator) {\n if (page.Items) {\n items.push(\n ...(page.Items?.map((item) => unmarshall(item) as T) || []),\n )\n }\n if (limit && items.length >= limit) break;\n }\n return limit ? items.slice(0, limit) : items;\n };\n\n\n getItemsPage = async (\n query: Query & { cursor?: string }\n ): Promise<PageResult<T>> => {\n const {index, filterExpressions, projectedAttributes, limit, sortOrder, cursor, ...keys} = query;\n const KeyConditionExpression = Object.keys(keys)\n .map((key) => `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`).join(' AND ');\n const keyExpressionAttributeNames = Object.keys(keys)\n .reduce((acc, key) => ({...acc, [`#${expressionAttributeKey(key)}`]: key}), Object.assign({}));\n const keyExpressionAttributeValues = Object.entries(keys)\n .reduce((acc, [key, value]) => ({...acc, [`:${expressionAttributeKey(key)}`]: value}), Object.assign({}));\n\n const ProjectionExpression = !index && projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined;\n const projectionAttributeNames: Record<string, string> = !index && projectedAttributes ? projectedAttributes.reduce(\n (reduction: Record<string, string>, attribute: string) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]: attribute,\n }),\n Object.assign({}),\n ) : {};\n const hasFilterExpressions = Array.isArray(filterExpressions) && filterExpressions.length > 0;\n const FilterExpression = hasFilterExpressions\n ? mapFilterExpressions(filterExpressions!)\n : undefined;\n const filterAttributeNames: Record<string, string> = hasFilterExpressions\n ? filterExpressions!.reduce(\n (reduction: Record<string, string>, filterExpression: FilterExpression) => ({\n ...reduction,\n [`#${expressionAttributeKey(filterExpression.attribute)}`]: filterExpression.attribute,\n }),\n Object.assign({}),\n )\n : {};\n const filterAttributeValues = filterExpressions\n ? filterExpressions.reduce(\n (reduction, filterExpression) => ({\n ...reduction,\n ...mapFilterExpressionValues(filterExpression),\n }),\n Object.assign({}),\n )\n : {};\n\n const ExclusiveStartKey = cursor\n ? JSON.parse(Buffer.from(cursor, 'base64').toString('utf-8')) as Record<string, unknown>\n : undefined;\n\n const queryCommandInput: QueryCommandInput = {\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n IndexName: index,\n KeyConditionExpression,\n FilterExpression,\n ProjectionExpression,\n ExpressionAttributeNames: {\n ...keyExpressionAttributeNames,\n ...filterAttributeNames,\n ...projectionAttributeNames\n },\n ExpressionAttributeValues: marshall(\n {...keyExpressionAttributeValues, ...filterAttributeValues} as Record<string, NativeAttributeValue>,\n {removeUndefinedValues: true},\n ),\n Limit: limit,\n ScanIndexForward: sortOrder === \"DESC\" ? false : undefined,\n ExclusiveStartKey: ExclusiveStartKey\n ? marshall(ExclusiveStartKey as Record<string, NativeAttributeValue>, {removeUndefinedValues: true})\n : undefined,\n };\n\n const result = await this.dynamoDBClient.send(new QueryCommand(queryCommandInput));\n const nextCursor = result.LastEvaluatedKey\n ? Buffer.from(JSON.stringify(unmarshall(result.LastEvaluatedKey))).toString('base64')\n : undefined;\n\n if (index) {\n const collectedKeys = (result.Items ?? [])\n .map((item) => unmarshall(item) as T)\n .map((item: T) =>\n pickBy(item as object, (_, key) => (key === this.hashKey || key === this.rangKey)) as K\n );\n const items = await this.batchGetItems(collectedKeys, query as ProjectedQuery);\n return {items: items.filter((item): item is T => item !== undefined), cursor: nextCursor};\n }\n\n const items = (result.Items ?? []).map((item) => unmarshall(item) as T);\n return {items, cursor: nextCursor};\n };\n\n\n batchGetItems = async (\n keys: K[], projectedQuery?: ProjectedQuery\n ): Promise<Array<T | undefined>> => {\n const uniqueKeys = uniqWith(keys, isEqual);\n const keyPages = paginate(uniqueKeys, 100);\n const {projectedAttributes} = projectedQuery || {};\n const ProjectionExpression = projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined;\n const ExpressionAttributeNames = projectedAttributes ?\n projectedAttributes.reduce(\n (\n reduction: Record<string, string>,\n attribute: string,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]:\n attribute,\n }),\n Object.assign({}),\n ) : undefined;\n return Promise.all((keyPages.map(async (keyPage) => {\n const batchRequest: BatchGetItemCommandInput = {\n RequestItems: {\n [this.tableName]: {\n Keys: keyPage.map((key) => marshallKey(key)),\n ProjectionExpression,\n ExpressionAttributeNames,\n }\n },\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }\n\n const fetchPage = async (request: BatchGetItemCommandInput): Promise<T[]> => {\n const result = await this.dynamoDBClient.send(new BatchGetItemCommand(request));\n const retrieved = result.Responses?.[this.tableName]?.map((item) => unmarshall(item) as T) ?? [];\n const unprocessed = result.UnprocessedKeys;\n if (!unprocessed || Object.keys(unprocessed).length === 0) return retrieved;\n return [...retrieved, ...await fetchPage({\n RequestItems: unprocessed,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n })];\n };\n\n return fetchPage(batchRequest);\n })))\n .then((itemSets) => itemSets.flat());\n };\n\n batchWriteItems = async (\n puts: { key: K; item: T }[],\n deletes: K[],\n ): Promise<void> => {\n const requests: WriteRequest[] = [\n ...puts.map(({ key, item }) => ({\n PutRequest: {\n Item: marshall(\n { ...item, ...key } as Record<string, NativeAttributeValue>,\n { removeUndefinedValues: true },\n ),\n },\n })),\n ...deletes.map((key) => ({\n DeleteRequest: { Key: marshallKey(key) },\n })),\n ];\n\n const sendBatch = async (requestItems: Record<string, WriteRequest[]>): Promise<void> => {\n const result = await this.dynamoDBClient.send(\n new BatchWriteItemCommand({\n RequestItems: requestItems,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }),\n );\n const unprocessed = result.UnprocessedItems;\n if (unprocessed && Object.keys(unprocessed).length > 0) {\n await sendBatch(unprocessed as Record<string, WriteRequest[]>);\n }\n };\n\n await Promise.all(\n paginate(requests, 25).map(batch => sendBatch({ [this.tableName]: batch })),\n );\n };\n}\n\n","import {\n ConsumedCapacity,\n ReturnConsumedCapacity,\n ServiceInputTypes,\n ServiceOutputTypes,\n} from \"@aws-sdk/client-dynamodb\";\n\nimport {\n InitializeHandler,\n InitializeHandlerArguments,\n InitializeHandlerOutput,\n} from \"@smithy/types\";\n\nimport {get} from \"lodash\";\n\nexport interface ConsumedCapacityDetail {\n ReturnConsumedCapacity: ReturnConsumedCapacity | undefined\n ConsumedCapacity: ConsumedCapacity | ConsumedCapacity[] | undefined\n}\n\nexport interface ConsumedCapacityMiddlewareConfig {\n onConsumedCapacity: (consumedCapacity: ConsumedCapacityDetail) => Promise<unknown>;\n}\n\nexport const consumedCapacityMiddleware =\n (consumedCapacityMiddlewareConfig: ConsumedCapacityMiddlewareConfig) =>\n (next: InitializeHandler<ServiceInputTypes, ServiceOutputTypes>) =>\n async (args: InitializeHandlerArguments<ServiceInputTypes>): Promise<InitializeHandlerOutput<ServiceOutputTypes>> => {\n const {input} = args;\n const returnConsumedCapacity = get(input, \"ReturnConsumedCapacity\") as ReturnConsumedCapacity | undefined;\n const response = await next(args);\n const {output} = response;\n const consumedCapacity = get(output, \"ConsumedCapacity\") as ConsumedCapacity | ConsumedCapacity[] | undefined;\n await consumedCapacityMiddlewareConfig.onConsumedCapacity({ReturnConsumedCapacity: returnConsumedCapacity, ConsumedCapacity: consumedCapacity});\n return response;\n };","import { DynamoDBClient, ReturnConsumedCapacity } from \"@aws-sdk/client-dynamodb\";\nimport { DynamoDbRepository } from \"./DynamoDbRepository\";\n\nexport type JsonPointerValue = string | number | boolean | null;\n\nexport interface JsonPointerRepositoryOptions {\n client: DynamoDBClient;\n tableName: string;\n idKey?: string;\n pointerKey?: string;\n valueKey?: string;\n returnConsumedCapacity?: ReturnConsumedCapacity;\n}\n\ntype PointerKey = Record<string, string>;\ntype PointerItem = Record<string, unknown>;\n\nconst isJsonPointerValue = (value: unknown): value is JsonPointerValue =>\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\";\n\nconst escapeToken = (token: string): string =>\n token.replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\n\nconst unescapeToken = (token: string): string =>\n token.replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n\nconst validatePointer = (pointer: string): void => {\n if (!pointer.startsWith(\"/\")) {\n throw new TypeError(`Invalid JSON Pointer \"${pointer}\": must start with \"/\".`);\n }\n};\n\nconst flattenDocument = (doc: unknown, prefix = \"\"): Record<string, JsonPointerValue> => {\n if (doc === null) return { [prefix]: null };\n if (typeof doc !== \"object\") {\n if (isJsonPointerValue(doc)) {\n return { [prefix]: doc };\n }\n const pointer = prefix === \"\" ? \"/\" : prefix;\n throw new TypeError(\n `Unsupported value at JSON pointer \"${pointer}\": expected string, number, boolean, or null but received ${typeof doc}.`,\n );\n }\n\n const result: Record<string, JsonPointerValue> = {};\n\n if (Array.isArray(doc)) {\n for (let i = 0; i < doc.length; i++) {\n Object.assign(result, flattenDocument(doc[i], `${prefix}/${i}`));\n }\n } else {\n for (const [key, value] of Object.entries(doc)) {\n Object.assign(result, flattenDocument(value, `${prefix}/${escapeToken(key)}`));\n }\n }\n\n return result;\n};\n\nconst setAtPointer = (\n root: Record<string, unknown>,\n pointer: string,\n value: JsonPointerValue,\n): void => {\n const tokens = pointer.split(\"/\").slice(1).map(unescapeToken);\n if (tokens.length === 0) return;\n\n let current: Record<string, unknown> = root;\n for (let i = 0; i < tokens.length - 1; i++) {\n const token = tokens[i];\n const nextToken = tokens[i + 1];\n if (current[token] == null) {\n current[token] = /^\\d+$/.test(nextToken) ? [] : {};\n } else if (typeof current[token] !== \"object\") {\n throw new TypeError(\n `Conflicting pointers: cannot traverse \"${pointer}\" because \"/${tokens.slice(0, i + 1).join(\"/\")}\" already holds a primitive value.`,\n );\n }\n current = current[token] as Record<string, unknown>;\n }\n\n const lastToken = tokens[tokens.length - 1];\n current[lastToken] = value;\n};\n\nconst reconstructDocument = <T>(\n items: Array<{ pointer: string; value: JsonPointerValue }>,\n): T => {\n const root: Record<string, unknown> = {};\n const sorted = [...items].sort((a, b) => a.pointer.localeCompare(b.pointer));\n for (const item of sorted) {\n setAtPointer(root, item.pointer, item.value);\n }\n return root as T;\n};\n\n/**\n * Stores JSON documents as individual per-pointer DynamoDB items addressed by JSON Pointer (RFC 6901).\n *\n * Only JSON objects are supported as the root document (`T extends Record<string, unknown>`).\n * Root arrays and primitives are not supported. Documents must contain at least one leaf value;\n * empty objects and empty arrays are not supported.\n */\nexport class JsonPointerRepository<T extends Record<string, unknown>> {\n private readonly repository: DynamoDbRepository<PointerKey, PointerItem>;\n private readonly idKey: string;\n private readonly pointerKey: string;\n private readonly valueKey: string;\n\n constructor(options: JsonPointerRepositoryOptions) {\n const {\n client,\n tableName,\n idKey = \"id\",\n pointerKey = \"pointer\",\n valueKey = \"value\",\n returnConsumedCapacity,\n } = options;\n\n this.idKey = idKey;\n this.pointerKey = pointerKey;\n this.valueKey = valueKey;\n\n this.repository = new DynamoDbRepository<PointerKey, PointerItem>({\n client,\n tableName,\n hashKey: idKey,\n rangeKey: pointerKey,\n returnConsumedCapacity,\n });\n }\n\n putDocument = async (id: string, document: T): Promise<void> => {\n const flat = flattenDocument(document);\n const newPointers = Object.keys(flat);\n\n if (newPointers.length === 0) {\n throw new TypeError(\n \"Cannot store a document with no leaf values. Empty objects and arrays are not supported.\",\n );\n }\n\n const newPointerSet = new Set(newPointers);\n const existing = await this.repository.getItems({ [this.idKey]: id }) ?? [];\n const existingPointers = existing.map(item => item[this.pointerKey] as string);\n const stalePointers = existingPointers.filter(p => !newPointerSet.has(p));\n\n const puts = Object.entries(flat).map(([pointer, value]) => {\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n return { key, item: { ...key, [this.valueKey]: value } as PointerItem };\n });\n const deleteKeys = stalePointers.map(\n pointer => ({ [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey),\n );\n await this.repository.batchWriteItems(puts, deleteKeys);\n };\n\n getDocument = async (id: string): Promise<T | undefined> => {\n const items = await this.repository.getItems({ [this.idKey]: id });\n if (!items || items.length === 0) return undefined;\n\n return reconstructDocument<T>(\n items.map(item => ({\n pointer: item[this.pointerKey] as string,\n value: item[this.valueKey] as JsonPointerValue,\n })),\n );\n };\n\n getAttribute = async <V = JsonPointerValue>(\n id: string,\n pointer: string,\n ): Promise<V | undefined> => {\n validatePointer(pointer);\n const item = await this.repository.getItem({\n [this.idKey]: id,\n [this.pointerKey]: pointer,\n } as PointerKey);\n return item ? (item[this.valueKey] as V) : undefined;\n };\n\n putAttribute = async (\n id: string,\n pointer: string,\n value: JsonPointerValue,\n ): Promise<void> => {\n validatePointer(pointer);\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n await this.repository.putItem(key, { ...key, [this.valueKey]: value } as PointerItem);\n };\n\n deleteAttribute = async (id: string, pointer: string): Promise<void> => {\n validatePointer(pointer);\n await this.repository.deleteItem({\n [this.idKey]: id,\n [this.pointerKey]: pointer,\n } as PointerKey);\n };\n\n deleteDocument = async (id: string): Promise<void> => {\n const items = await this.repository.getItems({ [this.idKey]: id }) ?? [];\n if (items.length === 0) return;\n const deleteKeys = items.map(\n item => ({ [this.idKey]: id, [this.pointerKey]: item[this.pointerKey] as string } as PointerKey),\n );\n await this.repository.batchWriteItems([], deleteKeys);\n };\n\n patchDocument = async (\n id: string,\n updates: Record<string, JsonPointerValue | undefined>,\n ): Promise<void> => {\n const entries = Object.entries(updates);\n if (entries.length === 0) return;\n entries.forEach(([pointer]) => validatePointer(pointer));\n const puts = entries\n .filter((entry): entry is [string, JsonPointerValue] => entry[1] !== undefined)\n .map(([pointer, value]) => {\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n return { key, item: { ...key, [this.valueKey]: value } as PointerItem };\n });\n const deleteKeys = entries\n .filter(([, value]) => value === undefined)\n .map(([pointer]) => ({ [this.idKey]: id, [this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W;IACvB,MAAM,MAAM;MAAG,KAAK,QAAQ;MAAK,KAAK,aAAa;KAAS;AAC5D,WAAO;KAAE;KAAK,MAAM;MAAE,GAAG;OAAM,KAAK,WAAW;MAAO;KAAiB;KACzE;GACN,MAAM,aAAa,QACd,QAAQ,GAAG,WAAW,UAAU,OAAU,CAC1C,KAAK,CAAC,cAAc;KAAG,KAAK,QAAQ;KAAK,KAAK,aAAa;IAAS,EAAgB;AACzF,SAAM,KAAK,WAAW,gBAAgB,MAAM,WAAW;;EAlHvD,MAAM,EACF,QACA,WACA,QAAQ,MACR,aAAa,WACb,WAAW,SACX,2BACA;AAEJ,OAAK,QAAQ;AACb,OAAK,aAAa;AAClB,OAAK,WAAW;AAEhB,OAAK,aAAa,IAAI,mBAA4C;GAC9D;GACA;GACA,SAAS;GACT,UAAU;GACV;GACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/DynamoDbRepository.ts","../src/consumed-capacity-middleware.ts","../src/JsonPointerRepository.ts"],"sourcesContent":["import {\n BatchGetItemCommand,\n BatchGetItemCommandInput,\n BatchWriteItemCommand,\n DeleteItemCommand,\n DynamoDBClient,\n GetItemCommand,\n paginateQuery,\n PutItemCommand,\n QueryCommand,\n QueryCommandInput,\n ReturnConsumedCapacity,\n ReturnValue,\n UpdateItemCommand,\n WriteRequest,\n} from \"@aws-sdk/client-dynamodb\";\nimport {marshall, unmarshall, NativeAttributeValue} from \"@aws-sdk/util-dynamodb\";\nimport {replace, uniqWith, isEqual, pickBy} from \"lodash\";\n\nexport enum FilterOperator {\n EQUALS = \"=\",\n NOT_EQUALS = \"<>\",\n GREATER_THAN_OR_EQUALS = \">=\",\n GREATER_THAN = \">\",\n LESS_THAN = \"<\",\n LESS_THAN_OR_EQUALS = \"<=\",\n IN = \"IN\",\n BETWEEN = \"BETWEEN\",\n BEGINS_WITH = \"BEGINS_WITH\",\n CONTAINS = \"CONTAINS\",\n}\n\nexport interface FilterExpression {\n attribute: string;\n value:\n | string\n | number\n | boolean\n | Array<string | number>\n | [string, string]\n | [number, number];\n operator: FilterOperator;\n negate?: boolean;\n}\n\nexport interface FilterableQuery {\n filterExpressions: Array<FilterExpression>;\n}\n\nexport interface ProjectedQuery {\n projectedAttributes: string[];\n}\n\nexport interface IndexedQuery {\n index: string;\n}\n\nexport interface Query extends Partial<FilterableQuery>, Partial<ProjectedQuery>, Partial<IndexedQuery> {\n [key: string]: unknown;\n filterExpressions?: Array<FilterExpression>;\n projectedAttributes?: string[];\n index?: string;\n sortOrder?: \"ASC\" | \"DESC\";\n limit?: number\n}\n\nconst marshallKey = (key: unknown) =>\n marshall(key as Record<string, NativeAttributeValue>, {removeUndefinedValues: true});\n\nconst expressionAttributeKey = (key: string) => replace(key, /-/g, \"_\");\n\nconst mapInKeys = (filterExpression: FilterExpression) =>\n Array.isArray(filterExpression.value)\n ? filterExpression.value.map(\n (_, index) => `:${expressionAttributeKey(filterExpression.attribute)}${index}`,\n )\n : `:${expressionAttributeKey(filterExpression.attribute)}`;\n\nconst mapFilterExpression = (filterExpression: FilterExpression) => {\n switch (filterExpression.operator) {\n case FilterOperator.IN:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `(${mapInKeys(filterExpression)})`\n );\n case FilterOperator.BETWEEN:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `:${expressionAttributeKey(filterExpression.attribute)}0 AND :${expressionAttributeKey(filterExpression.attribute)}1`\n );\n case FilterOperator.BEGINS_WITH:\n case FilterOperator.CONTAINS:\n return (\n `${filterExpression.operator.toLowerCase()}(#${expressionAttributeKey(filterExpression.attribute)}, ` +\n `:${expressionAttributeKey(filterExpression.attribute)})`\n );\n default:\n return (\n `#${expressionAttributeKey(filterExpression.attribute)} ${filterExpression.operator} ` +\n `:${expressionAttributeKey(filterExpression.attribute)}`\n );\n }\n};\n\nconst mapFilterExpressions = (\n filterExpressions: Array<FilterExpression>,\n) =>\n filterExpressions\n .map((filterExpression) =>\n filterExpression.negate\n ? `NOT ${mapFilterExpression(filterExpression)}`\n : mapFilterExpression(filterExpression),\n )\n .join(\" AND \");\n\nconst mapFilterExpressionValues = (\n filterExpression: FilterExpression,\n): Record<string, string | number | boolean> =>\n Array.isArray(filterExpression.value)\n ? filterExpression.value.reduce(\n (reduction, value, index) => ({\n ...reduction,\n [`:${expressionAttributeKey(filterExpression.attribute)}${index}`]: value,\n }),\n Object.assign({}),\n )\n : {\n [`:${expressionAttributeKey(filterExpression.attribute)}`]:\n filterExpression.value,\n };\n\nconst paginate = <T>(array: Array<T>, pageSize: number) => {\n return array.reduce((acc, val, i) => {\n const idx = Math.floor(i / pageSize)\n const page = acc[idx] || (acc[idx] = [])\n page.push(val)\n return acc\n }, [] as Array<Array<T>>);\n}\n\nexport interface DynamoDbRepositoryOptions {\n client: DynamoDBClient;\n tableName: string;\n hashKey: string;\n rangeKey?: string;\n returnConsumedCapacity?: ReturnConsumedCapacity;\n}\n\nexport interface PageResult<T> {\n items: Array<T>;\n cursor?: string;\n}\n\nexport class DynamoDbRepository<K, T> {\n private readonly dynamoDBClient: DynamoDBClient;\n private readonly tableName: string;\n private readonly hashKey: string;\n private readonly rangKey?: string;\n private readonly returnConsumedCapacity: ReturnConsumedCapacity | undefined;\n\n constructor(options: DynamoDbRepositoryOptions) {\n this.dynamoDBClient = options.client;\n this.tableName = options.tableName;\n this.hashKey = options.hashKey;\n this.rangKey = options.rangeKey;\n this.returnConsumedCapacity = options.returnConsumedCapacity ?? ReturnConsumedCapacity.TOTAL;\n }\n\n getItem = async (key: K): Promise<T | undefined> => {\n return this.dynamoDBClient\n .send(\n new GetItemCommand({\n TableName: this.tableName,\n Key: marshallKey(key),\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }),\n )\n .then((result) =>\n result.Item ? unmarshall(result.Item) as T : undefined,\n )\n };\n\n putItem = async (key: K, record: T): Promise<T> => {\n const Item = marshall({...record, ...key} as Record<string, NativeAttributeValue>, {removeUndefinedValues: true});\n return this.dynamoDBClient\n .send(\n new PutItemCommand({\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n Item,\n }),\n )\n .then(() => unmarshall(Item) as T);\n };\n\n deleteItem = async (key: K): Promise<T | undefined> => {\n return this.dynamoDBClient.send(new DeleteItemCommand({\n TableName: this.tableName,\n Key: marshallKey(key),\n ReturnValues: ReturnValue.ALL_OLD,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n })).then((result) => result.Attributes ?\n unmarshall(result.Attributes) as T : undefined);\n };\n\n\n updateItem = async (\n key: K,\n updates: Partial<T>,\n remove?: string[],\n ): Promise<T | undefined> => {\n const filteredUpdateEntries = Object.entries(updates).filter(([, value]) => value !== undefined);\n const hasUpdates = filteredUpdateEntries.length > 0;\n if (!hasUpdates && !remove?.length) {\n return this.getItem(key);\n }\n const setAttributesExpression = hasUpdates ? `SET ${filteredUpdateEntries\n .map(\n ([key]) =>\n `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`,\n )\n .join(\", \")}` : '';\n const removeAttributesExpression = remove?.length\n ? ` REMOVE ${remove.map((key) => `#${expressionAttributeKey(key)}`).join(\", \")}`\n : \"\";\n const removeAttributeNames = remove?.length\n ? remove.reduce(\n (acc, key) => ({\n ...acc,\n [`#${expressionAttributeKey(key)}`]: key,\n }),\n {} as Record<string, string>,\n )\n : {};\n const updateItemCommandInput = {\n TableName: this.tableName,\n Key: marshallKey(key),\n UpdateExpression: `${setAttributesExpression}${removeAttributesExpression}`,\n ExpressionAttributeNames: filteredUpdateEntries\n .reduce(\n (acc, [key]) => ({\n ...acc,\n [`#${expressionAttributeKey(key)}`]: key,\n }),\n Object.assign(\n removeAttributeNames,\n ),\n ) as Record<string, string>,\n ExpressionAttributeValues: hasUpdates ? marshall(\n filteredUpdateEntries.reduce(\n (acc, [key, value]) => ({\n ...acc,\n [`:${expressionAttributeKey(key)}`]: value,\n }),\n {} as Record<string, NativeAttributeValue>,\n ),\n {removeUndefinedValues: true},\n ) : undefined,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n };\n return this.dynamoDBClient\n .send(new UpdateItemCommand({...updateItemCommandInput, ReturnValues: 'ALL_NEW'}))\n .then((result) => result.Attributes ? unmarshall(result.Attributes) as T : undefined);\n };\n\n\n getItems = async (\n query: Query\n ): Promise<Array<T> | undefined> => {\n const {index, filterExpressions, projectedAttributes, limit, sortOrder,...keys} = query;\n const KeyConditionExpression = Object.keys(keys)\n .map((key) => `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`).join(' AND ');\n const keyExpressionAttributeNames = Object.keys(keys)\n .reduce((acc, key) => ({...acc, [`#${expressionAttributeKey(key)}`]: key}), Object.assign({}));\n const keyExpressionAttributeValues = Object.entries(keys)\n .reduce((acc, [key, value]) => ({...acc, [`:${expressionAttributeKey(key)}`]: value}), Object.assign({}));\n\n const gsiKeyAttributes = index\n ? [this.hashKey, ...(this.rangKey ? [this.rangKey] : [])]\n : [];\n\n const ProjectionExpression = index\n ? gsiKeyAttributes.map((attr) => `#${expressionAttributeKey(attr)}`).join(',')\n : (projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined);\n\n const projectionAttributeNames: Record<string, string> = index\n ? gsiKeyAttributes.reduce(\n (acc: Record<string, string>, attr: string) => ({\n ...acc,\n [`#${expressionAttributeKey(attr)}`]: attr,\n }),\n {},\n )\n : (projectedAttributes ? projectedAttributes.reduce(\n (\n reduction: Record<string, string>,\n attribute: string,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]:\n attribute,\n }),\n Object.assign({}),\n ) : {})\n const hasFilterExpressions = Array.isArray(filterExpressions) && filterExpressions.length > 0;\n const FilterExpression = hasFilterExpressions\n ? mapFilterExpressions(filterExpressions!)\n : undefined;\n const filterAttributeNames: Record<string, string> = hasFilterExpressions\n ? filterExpressions!.reduce(\n (\n reduction: Record<string, string>,\n filterExpression: FilterExpression,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(filterExpression.attribute)}`]:\n filterExpression.attribute,\n }),\n Object.assign({}),\n )\n : {};\n const filterAttributeValues = filterExpressions\n ? filterExpressions.reduce(\n (reduction, filterExpression) => ({\n ...reduction,\n ...mapFilterExpressionValues(filterExpression),\n }),\n Object.assign({}),\n )\n : {};\n\n const Limit = limit;\n const ScanIndexForward = sortOrder === \"DESC\" ? false : undefined;\n const queryCommandInput: QueryCommandInput = {\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n IndexName: index,\n KeyConditionExpression,\n FilterExpression,\n ProjectionExpression,\n ExpressionAttributeNames: {\n ...keyExpressionAttributeNames,\n ...filterAttributeNames,\n ...projectionAttributeNames\n },\n ExpressionAttributeValues: marshall(\n {...keyExpressionAttributeValues, ...filterAttributeValues} as Record<string, NativeAttributeValue>,\n {removeUndefinedValues: true},\n ),\n Limit,\n ScanIndexForward\n };\n const paginator = paginateQuery(\n {client: this.dynamoDBClient, pageSize: 100},\n queryCommandInput,\n );\n\n if (index) {\n const collectedKeys: Array<K> = [];\n for await (const page of paginator) {\n if (page.Items) {\n collectedKeys.push(\n ...(page.Items.map((item) => unmarshall(item) as T)\n .map((item: T) =>\n pickBy(item as object, (_, key) => (key === this.hashKey || key === this.rangKey)) as K)),\n )\n }\n if (limit && collectedKeys.length >= limit) break;\n }\n const keysBatch = limit ? collectedKeys.slice(0, limit) : collectedKeys;\n const keyAttrs = [this.hashKey, ...(this.rangKey ? [this.rangKey] : [])];\n const batchProjectedQuery = projectedAttributes\n ? { ...query, projectedAttributes: [...new Set([...projectedAttributes, ...keyAttrs])] } as ProjectedQuery\n : query as ProjectedQuery;\n const items = await this.batchGetItems(keysBatch, batchProjectedQuery);\n const orderedItems = keysBatch.flatMap((key) => {\n const k = key as Record<string, unknown>;\n const match = (items as Array<T | undefined>).find((item) => {\n if (!item) return false;\n const t = item as Record<string, unknown>;\n return t[this.hashKey] === k[this.hashKey] &&\n (!this.rangKey || t[this.rangKey] === k[this.rangKey]);\n });\n return match ? [match] : [];\n });\n if (projectedAttributes) {\n const projSet = new Set(projectedAttributes);\n return orderedItems.map(item =>\n pickBy(item as object, (_, key) => projSet.has(key)) as T\n ) as Array<T>;\n }\n return orderedItems as Array<T>;\n }\n\n const items: Array<T> = [];\n for await (const page of paginator) {\n if (page.Items) {\n items.push(\n ...(page.Items?.map((item) => unmarshall(item) as T) || []),\n )\n }\n if (limit && items.length >= limit) break;\n }\n return limit ? items.slice(0, limit) : items;\n };\n\n\n getItemsPage = async (\n query: Query & { cursor?: string }\n ): Promise<PageResult<T>> => {\n const {index, filterExpressions, projectedAttributes, limit, sortOrder, cursor, ...keys} = query;\n const KeyConditionExpression = Object.keys(keys)\n .map((key) => `#${expressionAttributeKey(key)} = :${expressionAttributeKey(key)}`).join(' AND ');\n const keyExpressionAttributeNames = Object.keys(keys)\n .reduce((acc, key) => ({...acc, [`#${expressionAttributeKey(key)}`]: key}), Object.assign({}));\n const keyExpressionAttributeValues = Object.entries(keys)\n .reduce((acc, [key, value]) => ({...acc, [`:${expressionAttributeKey(key)}`]: value}), Object.assign({}));\n\n const ProjectionExpression = !index && projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined;\n const projectionAttributeNames: Record<string, string> = !index && projectedAttributes ? projectedAttributes.reduce(\n (reduction: Record<string, string>, attribute: string) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]: attribute,\n }),\n Object.assign({}),\n ) : {};\n const hasFilterExpressions = Array.isArray(filterExpressions) && filterExpressions.length > 0;\n const FilterExpression = hasFilterExpressions\n ? mapFilterExpressions(filterExpressions!)\n : undefined;\n const filterAttributeNames: Record<string, string> = hasFilterExpressions\n ? filterExpressions!.reduce(\n (reduction: Record<string, string>, filterExpression: FilterExpression) => ({\n ...reduction,\n [`#${expressionAttributeKey(filterExpression.attribute)}`]: filterExpression.attribute,\n }),\n Object.assign({}),\n )\n : {};\n const filterAttributeValues = filterExpressions\n ? filterExpressions.reduce(\n (reduction, filterExpression) => ({\n ...reduction,\n ...mapFilterExpressionValues(filterExpression),\n }),\n Object.assign({}),\n )\n : {};\n\n const ExclusiveStartKey = cursor\n ? JSON.parse(Buffer.from(cursor, 'base64').toString('utf-8')) as Record<string, unknown>\n : undefined;\n\n const queryCommandInput: QueryCommandInput = {\n TableName: this.tableName,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n IndexName: index,\n KeyConditionExpression,\n FilterExpression,\n ProjectionExpression,\n ExpressionAttributeNames: {\n ...keyExpressionAttributeNames,\n ...filterAttributeNames,\n ...projectionAttributeNames\n },\n ExpressionAttributeValues: marshall(\n {...keyExpressionAttributeValues, ...filterAttributeValues} as Record<string, NativeAttributeValue>,\n {removeUndefinedValues: true},\n ),\n Limit: limit,\n ScanIndexForward: sortOrder === \"DESC\" ? false : undefined,\n ExclusiveStartKey: ExclusiveStartKey\n ? marshall(ExclusiveStartKey as Record<string, NativeAttributeValue>, {removeUndefinedValues: true})\n : undefined,\n };\n\n const result = await this.dynamoDBClient.send(new QueryCommand(queryCommandInput));\n const nextCursor = result.LastEvaluatedKey\n ? Buffer.from(JSON.stringify(unmarshall(result.LastEvaluatedKey))).toString('base64')\n : undefined;\n\n if (index) {\n const collectedKeys = (result.Items ?? [])\n .map((item) => unmarshall(item) as T)\n .map((item: T) =>\n pickBy(item as object, (_, key) => (key === this.hashKey || key === this.rangKey)) as K\n );\n const items = await this.batchGetItems(collectedKeys, query as ProjectedQuery);\n return {items: items.filter((item): item is T => item !== undefined), cursor: nextCursor};\n }\n\n const items = (result.Items ?? []).map((item) => unmarshall(item) as T);\n return {items, cursor: nextCursor};\n };\n\n\n batchGetItems = async (\n keys: K[], projectedQuery?: ProjectedQuery\n ): Promise<Array<T | undefined>> => {\n const uniqueKeys = uniqWith(keys, isEqual);\n const keyPages = paginate(uniqueKeys, 100);\n const {projectedAttributes} = projectedQuery || {};\n const ProjectionExpression = projectedAttributes\n ? projectedAttributes.map((attribute) => `#${expressionAttributeKey(attribute)}`).join(',')\n : undefined;\n const ExpressionAttributeNames = projectedAttributes ?\n projectedAttributes.reduce(\n (\n reduction: Record<string, string>,\n attribute: string,\n ) => ({\n ...reduction,\n [`#${expressionAttributeKey(attribute)}`]:\n attribute,\n }),\n Object.assign({}),\n ) : undefined;\n return Promise.all((keyPages.map(async (keyPage) => {\n const batchRequest: BatchGetItemCommandInput = {\n RequestItems: {\n [this.tableName]: {\n Keys: keyPage.map((key) => marshallKey(key)),\n ProjectionExpression,\n ExpressionAttributeNames,\n }\n },\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }\n\n const fetchPage = async (request: BatchGetItemCommandInput): Promise<T[]> => {\n const result = await this.dynamoDBClient.send(new BatchGetItemCommand(request));\n const retrieved = result.Responses?.[this.tableName]?.map((item) => unmarshall(item) as T) ?? [];\n const unprocessed = result.UnprocessedKeys;\n if (!unprocessed || Object.keys(unprocessed).length === 0) return retrieved;\n return [...retrieved, ...await fetchPage({\n RequestItems: unprocessed,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n })];\n };\n\n return fetchPage(batchRequest);\n })))\n .then((itemSets) => itemSets.flat());\n };\n\n batchWriteItems = async (\n puts: { key: K; item: T }[],\n deletes: K[],\n ): Promise<void> => {\n const requests: WriteRequest[] = [\n ...puts.map(({ key, item }) => ({\n PutRequest: {\n Item: marshall(\n { ...item, ...key } as Record<string, NativeAttributeValue>,\n { removeUndefinedValues: true },\n ),\n },\n })),\n ...deletes.map((key) => ({\n DeleteRequest: { Key: marshallKey(key) },\n })),\n ];\n\n const sendBatch = async (requestItems: Record<string, WriteRequest[]>): Promise<void> => {\n const result = await this.dynamoDBClient.send(\n new BatchWriteItemCommand({\n RequestItems: requestItems,\n ReturnConsumedCapacity: this.returnConsumedCapacity,\n }),\n );\n const unprocessed = result.UnprocessedItems;\n if (unprocessed && Object.keys(unprocessed).length > 0) {\n await sendBatch(unprocessed as Record<string, WriteRequest[]>);\n }\n };\n\n await Promise.all(\n paginate(requests, 25).map(batch => sendBatch({ [this.tableName]: batch })),\n );\n };\n}\n\n","import {\n ConsumedCapacity,\n ReturnConsumedCapacity,\n ServiceInputTypes,\n ServiceOutputTypes,\n} from \"@aws-sdk/client-dynamodb\";\n\nimport {\n InitializeHandler,\n InitializeHandlerArguments,\n InitializeHandlerOutput,\n} from \"@smithy/types\";\n\nimport {get} from \"lodash\";\n\nexport interface ConsumedCapacityDetail {\n ReturnConsumedCapacity: ReturnConsumedCapacity | undefined\n ConsumedCapacity: ConsumedCapacity | ConsumedCapacity[] | undefined\n}\n\nexport interface ConsumedCapacityMiddlewareConfig {\n onConsumedCapacity: (consumedCapacity: ConsumedCapacityDetail) => Promise<unknown>;\n}\n\nexport const consumedCapacityMiddleware =\n (consumedCapacityMiddlewareConfig: ConsumedCapacityMiddlewareConfig) =>\n (next: InitializeHandler<ServiceInputTypes, ServiceOutputTypes>) =>\n async (args: InitializeHandlerArguments<ServiceInputTypes>): Promise<InitializeHandlerOutput<ServiceOutputTypes>> => {\n const {input} = args;\n const returnConsumedCapacity = get(input, \"ReturnConsumedCapacity\") as ReturnConsumedCapacity | undefined;\n const response = await next(args);\n const {output} = response;\n const consumedCapacity = get(output, \"ConsumedCapacity\") as ConsumedCapacity | ConsumedCapacity[] | undefined;\n await consumedCapacityMiddlewareConfig.onConsumedCapacity({ReturnConsumedCapacity: returnConsumedCapacity, ConsumedCapacity: consumedCapacity});\n return response;\n };","import { DynamoDBClient, ReturnConsumedCapacity } from \"@aws-sdk/client-dynamodb\";\nimport { DynamoDbRepository } from \"./DynamoDbRepository\";\n\nexport type JsonPointerValue = string | number | boolean | null;\n\nexport interface JsonPointerRepositoryOptions {\n client: DynamoDBClient;\n tableName: string;\n idKey?: string;\n pointerKey?: string;\n valueKey?: string;\n returnConsumedCapacity?: ReturnConsumedCapacity;\n}\n\ntype PointerKey = Record<string, string>;\ntype PointerItem = Record<string, unknown>;\n\nconst isJsonPointerValue = (value: unknown): value is JsonPointerValue =>\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\";\n\nconst escapeToken = (token: string): string =>\n token.replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\n\nconst unescapeToken = (token: string): string =>\n token.replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n\nconst validatePointer = (pointer: string): void => {\n if (!pointer.startsWith(\"/\")) {\n throw new TypeError(`Invalid JSON Pointer \"${pointer}\": must start with \"/\".`);\n }\n};\n\nconst flattenDocument = (doc: unknown, prefix = \"\"): Record<string, JsonPointerValue> => {\n if (doc === null) return { [prefix]: null };\n if (typeof doc !== \"object\") {\n if (isJsonPointerValue(doc)) {\n return { [prefix]: doc };\n }\n const pointer = prefix === \"\" ? \"/\" : prefix;\n throw new TypeError(\n `Unsupported value at JSON pointer \"${pointer}\": expected string, number, boolean, or null but received ${typeof doc}.`,\n );\n }\n\n const result: Record<string, JsonPointerValue> = {};\n\n if (Array.isArray(doc)) {\n for (let i = 0; i < doc.length; i++) {\n Object.assign(result, flattenDocument(doc[i], `${prefix}/${i}`));\n }\n } else {\n for (const [key, value] of Object.entries(doc)) {\n Object.assign(result, flattenDocument(value, `${prefix}/${escapeToken(key)}`));\n }\n }\n\n return result;\n};\n\nconst setAtPointer = (\n root: Record<string, unknown>,\n pointer: string,\n value: JsonPointerValue,\n): void => {\n const tokens = pointer.split(\"/\").slice(1).map(unescapeToken);\n if (tokens.length === 0) return;\n\n let current: Record<string, unknown> = root;\n for (let i = 0; i < tokens.length - 1; i++) {\n const token = tokens[i];\n const nextToken = tokens[i + 1];\n if (current[token] == null) {\n current[token] = /^\\d+$/.test(nextToken) ? [] : {};\n } else if (typeof current[token] !== \"object\") {\n throw new TypeError(\n `Conflicting pointers: cannot traverse \"${pointer}\" because \"/${tokens.slice(0, i + 1).join(\"/\")}\" already holds a primitive value.`,\n );\n }\n current = current[token] as Record<string, unknown>;\n }\n\n const lastToken = tokens[tokens.length - 1];\n current[lastToken] = value;\n};\n\nconst reconstructDocument = <T>(\n items: Array<{ pointer: string; value: JsonPointerValue }>,\n): T => {\n const root: Record<string, unknown> = {};\n const sorted = [...items].sort((a, b) => a.pointer.localeCompare(b.pointer));\n for (const item of sorted) {\n setAtPointer(root, item.pointer, item.value);\n }\n return root as T;\n};\n\n/**\n * Stores JSON documents as individual per-pointer DynamoDB items addressed by JSON Pointer (RFC 6901).\n *\n * Only JSON objects are supported as the root document (`T extends Record<string, unknown>`).\n * Root arrays and primitives are not supported. Documents must contain at least one leaf value;\n * empty objects and empty arrays are not supported.\n */\nexport class JsonPointerRepository<T extends Record<string, unknown>> {\n private readonly repository: DynamoDbRepository<PointerKey, PointerItem>;\n private readonly idKey: string;\n private readonly pointerKey: string;\n private readonly valueKey: string;\n\n constructor(options: JsonPointerRepositoryOptions) {\n const {\n client,\n tableName,\n idKey = \"id\",\n pointerKey = \"pointer\",\n valueKey = \"value\",\n returnConsumedCapacity,\n } = options;\n\n this.idKey = idKey;\n this.pointerKey = pointerKey;\n this.valueKey = valueKey;\n\n this.repository = new DynamoDbRepository<PointerKey, PointerItem>({\n client,\n tableName,\n hashKey: idKey,\n rangeKey: pointerKey,\n returnConsumedCapacity,\n });\n }\n\n putDocument = async (id: string, document: T): Promise<void> => {\n const flat = flattenDocument(document);\n const newPointers = Object.keys(flat);\n\n if (newPointers.length === 0) {\n throw new TypeError(\n \"Cannot store a document with no leaf values. Empty objects and arrays are not supported.\",\n );\n }\n\n const newPointerSet = new Set(newPointers);\n const existing = await this.repository.getItems({ [this.idKey]: id }) ?? [];\n const existingPointers = existing.map(item => item[this.pointerKey] as string);\n const stalePointers = existingPointers.filter(p => !newPointerSet.has(p));\n\n const puts = Object.entries(flat).map(([pointer, value]) => {\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n return { key, item: { ...key, [this.valueKey]: value } as PointerItem };\n });\n const deleteKeys = stalePointers.map(\n pointer => ({ [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey),\n );\n await this.repository.batchWriteItems(puts, deleteKeys);\n };\n\n getDocument = async (id: string): Promise<T | undefined> => {\n const items = await this.repository.getItems({ [this.idKey]: id });\n if (!items || items.length === 0) return undefined;\n\n return reconstructDocument<T>(\n items.map(item => ({\n pointer: item[this.pointerKey] as string,\n value: item[this.valueKey] as JsonPointerValue,\n })),\n );\n };\n\n getAttribute = async <V = JsonPointerValue>(\n id: string,\n pointer: string,\n ): Promise<V | undefined> => {\n validatePointer(pointer);\n const item = await this.repository.getItem({\n [this.idKey]: id,\n [this.pointerKey]: pointer,\n } as PointerKey);\n return item ? (item[this.valueKey] as V) : undefined;\n };\n\n putAttribute = async (\n id: string,\n pointer: string,\n value: JsonPointerValue,\n ): Promise<void> => {\n validatePointer(pointer);\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n await this.repository.putItem(key, { ...key, [this.valueKey]: value } as PointerItem);\n };\n\n deleteAttribute = async (id: string, pointer: string): Promise<void> => {\n validatePointer(pointer);\n await this.repository.deleteItem({\n [this.idKey]: id,\n [this.pointerKey]: pointer,\n } as PointerKey);\n };\n\n deleteDocument = async (id: string): Promise<void> => {\n const items = await this.repository.getItems({ [this.idKey]: id }) ?? [];\n if (items.length === 0) return;\n const deleteKeys = items.map(\n item => ({ [this.idKey]: id, [this.pointerKey]: item[this.pointerKey] as string } as PointerKey),\n );\n await this.repository.batchWriteItems([], deleteKeys);\n };\n\n patchDocument = async (\n id: string,\n updates: Record<string, JsonPointerValue | undefined>,\n ): Promise<void> => {\n const entries = Object.entries(updates);\n if (entries.length === 0) return;\n entries.forEach(([pointer]) => validatePointer(pointer));\n const puts = entries\n .filter((entry): entry is [string, JsonPointerValue] => entry[1] !== undefined)\n .map(([pointer, value]) => {\n const key = { [this.idKey]: id, [this.pointerKey]: pointer } as PointerKey;\n return { key, item: { ...key, [this.valueKey]: value } as PointerItem };\n });\n const deleteKeys = entries\n .filter(([, value]) => value === undefined)\n .map(([pointer]) => ({ [this.idKey]: id, [this.pointerKey]: pointer } as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AAC,aAAa,gBAAgB,OAAO,CAAC;GACvD,MAAM,OAAO,QACR,QAAQ,UAA+C,MAAM,OAAO,MAAS,EAC7E,KAAK,CAAC,SAAS,WAAW;IACvB,MAAM,MAAM;MAAG,KAAK,QAAQ;MAAK,KAAK,aAAa;IAAQ;IAC3D,OAAO;KAAE;KAAK,MAAM;MAAE,GAAG;OAAM,KAAK,WAAW;KAAM;IAAiB;GAC1E,CAAC;GACL,MAAM,aAAa,QACd,QAAQ,GAAG,WAAW,UAAU,MAAS,EACzC,KAAK,CAAC,cAAc;KAAG,KAAK,QAAQ;KAAK,KAAK,aAAa;GAAQ,EAAgB;GACxF,MAAM,KAAK,WAAW,gBAAgB,MAAM,UAAU;EAC1D;EAnHI,MAAM,EACF,QACA,WACA,QAAQ,MACR,aAAa,WACb,WAAW,SACX,2BACA;EAEJ,KAAK,QAAQ;EACb,KAAK,aAAa;EAClB,KAAK,WAAW;EAEhB,KAAK,aAAa,IAAI,mBAA4C;GAC9D;GACA;GACA,SAAS;GACT,UAAU;GACV;EACJ,CAAC;CACL;AAgGJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eresearchqut/ddb-repository",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A TypeScript library providing a generic repository pattern implementation for AWS DynamoDB, simplifying CRUD operations and common database interactions.",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -22,39 +22,37 @@
|
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsdown",
|
|
25
|
-
"test": "
|
|
26
|
-
"test:watch": "
|
|
27
|
-
"test:coverage": "
|
|
28
|
-
"lint": "eslint .
|
|
29
|
-
"lint:fix": "eslint . --
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"test:coverage": "vitest run --coverage",
|
|
28
|
+
"lint": "eslint .",
|
|
29
|
+
"lint:fix": "eslint . --fix"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
33
|
-
"@aws-sdk/util-dynamodb": "^3.
|
|
34
|
-
"@eslint/js": "^
|
|
32
|
+
"@aws-sdk/client-dynamodb": "^3.1050.0",
|
|
33
|
+
"@aws-sdk/util-dynamodb": "^3.996.2",
|
|
34
|
+
"@eslint/js": "^10.0.1",
|
|
35
35
|
"@semantic-release/changelog": "^6.0.3",
|
|
36
|
+
"@semantic-release/exec": "^7.1.0",
|
|
36
37
|
"@semantic-release/git": "^10.0.1",
|
|
37
|
-
"@semantic-release/github": "^12.0.
|
|
38
|
-
"@semantic-release/npm": "^13.1.
|
|
39
|
-
"@smithy/types": "^4.
|
|
40
|
-
"@types/
|
|
41
|
-
"@types/
|
|
42
|
-
"@
|
|
43
|
-
"eslint": "^
|
|
44
|
-
"eslint-plugin-jest": "^29.15.0",
|
|
45
|
-
"jest": "^30.2.0",
|
|
38
|
+
"@semantic-release/github": "^12.0.8",
|
|
39
|
+
"@semantic-release/npm": "^13.1.5",
|
|
40
|
+
"@smithy/types": "^4.14.2",
|
|
41
|
+
"@types/lodash": "^4.17.24",
|
|
42
|
+
"@types/node": "^25.9.1",
|
|
43
|
+
"@vitest/coverage-v8": "^4.1.6",
|
|
44
|
+
"eslint": "^10.4.0",
|
|
46
45
|
"semantic-release": "^25.0.3",
|
|
47
|
-
"testcontainers": "^
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"typescript-eslint": "^8.56.0"
|
|
46
|
+
"testcontainers": "^12.0.0",
|
|
47
|
+
"tsdown": "^0.22.0",
|
|
48
|
+
"typescript": "^6.0.3",
|
|
49
|
+
"typescript-eslint": "^8.59.4",
|
|
50
|
+
"vitest": "^4.1.6"
|
|
53
51
|
},
|
|
54
52
|
"peerDependencies": {
|
|
55
|
-
"@aws-sdk/client-dynamodb": ">= 3.
|
|
56
|
-
"@aws-sdk/util-dynamodb": ">= 3.
|
|
57
|
-
"lodash": ">= 4.
|
|
53
|
+
"@aws-sdk/client-dynamodb": ">= 3.1050.0",
|
|
54
|
+
"@aws-sdk/util-dynamodb": ">= 3.996.2",
|
|
55
|
+
"lodash": ">= 4.18.1"
|
|
58
56
|
},
|
|
59
57
|
"repository": {
|
|
60
58
|
"type": "git",
|