@xube/kit-aws 0.0.46 → 0.0.47

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.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  export * from "./resources/dynamodb/get";
2
2
  export * from "./resources/dynamodb/put";
3
- export * from "./resources/dynamodb/schema/item";
4
- export * from "./resources/dynamodb/schema/keys";
5
3
  export * from "./resources/dynamodb/query";
6
4
  export * from "./resources/dynamodb/transform";
package/dist/index.js CHANGED
@@ -16,7 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./resources/dynamodb/get"), exports);
18
18
  __exportStar(require("./resources/dynamodb/put"), exports);
19
- __exportStar(require("./resources/dynamodb/schema/item"), exports);
20
- __exportStar(require("./resources/dynamodb/schema/keys"), exports);
21
19
  __exportStar(require("./resources/dynamodb/query"), exports);
22
20
  __exportStar(require("./resources/dynamodb/transform"), exports);
@@ -4,4 +4,7 @@ export declare const putItemInTable: <TItem extends {
4
4
  id: string;
5
5
  PK: string;
6
6
  SK: string;
7
+ type: string;
8
+ s: number;
9
+ us?: number | undefined;
7
10
  }>(table: string, item: TItem, log?: XubeLog) => Promise<XubeResponse<boolean>>;
@@ -1,7 +1,6 @@
1
- import { TableItem } from "./schema/item";
2
- import { PartialTableKey } from "./schema/keys";
3
1
  import { XubeResponse } from "@xube/kit-request";
4
2
  import { XubeLog } from "@xube/kit-log";
3
+ import { PartialTableKey, TableItem } from "@xube/kit-aws-schema";
5
4
  export declare const queryItemsFromTable: (tableName: string, keys: PartialTableKey, indexName: string | undefined, keyLabels?: {
6
5
  partitionKey: string;
7
6
  sortKey?: string;
@@ -2,28 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.queryItemsFromTable = void 0;
4
4
  const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
5
- const item_1 = require("./schema/item");
6
- const keys_1 = require("./schema/keys");
7
5
  const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
8
6
  const kit_request_1 = require("@xube/kit-request");
9
7
  const kit_log_1 = require("@xube/kit-log");
8
+ const kit_aws_schema_1 = require("@xube/kit-aws-schema");
10
9
  const ddbClient = new client_dynamodb_1.DynamoDBClient({ region: process.env.AWS_REGION });
11
10
  const ddbDocClient = lib_dynamodb_1.DynamoDBDocumentClient.from(ddbClient);
12
11
  const queryItemsFromTable = async (tableName, keys, indexName, keyLabels = {
13
- partitionKey: keys_1.PARTITION_KEY,
14
- sortKey: keys_1.SORT_KEY,
12
+ partitionKey: kit_aws_schema_1.PARTITION_KEY,
13
+ sortKey: kit_aws_schema_1.SORT_KEY,
15
14
  }, log = kit_log_1.XubeLog.getInstance()) => {
16
15
  let KeyConditionExpression = "#pk = :pkValue";
17
16
  let ExpressionAttributeNames = {
18
17
  "#pk": keyLabels.partitionKey,
19
18
  };
20
19
  let ExpressionAttributeValues = {
21
- ":pkValue": keys[keys_1.PARTITION_KEY],
20
+ ":pkValue": keys[kit_aws_schema_1.PARTITION_KEY],
22
21
  };
23
- if (keys[keys_1.SORT_KEY]) {
22
+ if (keys[kit_aws_schema_1.SORT_KEY]) {
24
23
  KeyConditionExpression += " AND begins_with(#sk, :skPrefix)";
25
- ExpressionAttributeNames["#sk"] = keyLabels.sortKey ?? keys_1.SORT_KEY;
26
- ExpressionAttributeValues[":skPrefix"] = keys[keys_1.SORT_KEY];
24
+ ExpressionAttributeNames["#sk"] = keyLabels.sortKey ?? kit_aws_schema_1.SORT_KEY;
25
+ ExpressionAttributeValues[":skPrefix"] = keys[kit_aws_schema_1.SORT_KEY];
27
26
  }
28
27
  const params = {
29
28
  TableName: tableName,
@@ -40,7 +39,7 @@ const queryItemsFromTable = async (tableName, keys, indexName, keyLabels = {
40
39
  error: `No items found.`,
41
40
  });
42
41
  }
43
- if (!(0, item_1.areTableItems)(response.Items)) {
42
+ if (!(0, kit_aws_schema_1.areTableItems)(response.Items)) {
44
43
  return new kit_request_1.XubeResponse({
45
44
  statusCode: 500,
46
45
  error: `Items returned from DynamoDB are not valid TableItems.`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xube/kit-aws",
3
- "version": "0.0.46",
3
+ "version": "0.0.47",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -18,14 +18,16 @@
18
18
  "homepage": "https://github.com/XubeLtd/dev-kit#readme",
19
19
  "devDependencies": {
20
20
  "@types/aws-lambda": "^8.10.119",
21
- "@xube/kit-build": "^0.0.46"
21
+ "@xube/kit-build": "^0.0.47"
22
22
  },
23
23
  "dependencies": {
24
24
  "@aws-sdk/client-dynamodb": "^3.427.0",
25
25
  "@aws-sdk/lib-dynamodb": "^3.427.0",
26
26
  "@aws-sdk/util-dynamodb": "^3.427.0",
27
- "@xube/kit-log": "^0.0.46",
28
- "@xube/kit-request": "^0.0.46",
27
+ "@xube/kit-aws-schema": "^0.0.47",
28
+ "@xube/kit-log": "^0.0.47",
29
+ "@xube/kit-request": "^0.0.47",
30
+ "@xube/kit-schema": "^0.0.47",
29
31
  "zod": "^3.22.4"
30
32
  }
31
33
  }
package/src/index.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  export * from "./resources/dynamodb/get";
2
2
  export * from "./resources/dynamodb/put";
3
- export * from "./resources/dynamodb/schema/item";
4
- export * from "./resources/dynamodb/schema/keys";
5
3
  export * from "./resources/dynamodb/query";
6
4
  export * from "./resources/dynamodb/transform";
@@ -5,9 +5,9 @@ import {
5
5
  PutCommandOutput,
6
6
  } from "@aws-sdk/lib-dynamodb";
7
7
  import { XubeResponse } from "@xube/kit-request";
8
- import { TableItem } from "./schema/item";
9
8
  import { StatusCode } from "@xube/kit-constants";
10
9
  import { XubeLog } from "@xube/kit-log";
10
+ import { TableItem } from "@xube/kit-aws-schema";
11
11
 
12
12
  const ddbClient = new DynamoDBClient({
13
13
  region: process.env.AWS_REGION,
@@ -1,14 +1,8 @@
1
1
  import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb";
2
- import { TableItem, areTableItems } from "./schema/item";
3
- import {
4
- PARTITION_KEY,
5
- PartialTableKey,
6
- SORT_KEY,
7
- TableKey,
8
- } from "./schema/keys";
9
2
  import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
10
3
  import { XubeResponse } from "@xube/kit-request";
11
4
  import { XubeLog } from "@xube/kit-log";
5
+ import { PARTITION_KEY, PartialTableKey, SORT_KEY, TableItem, areTableItems } from "@xube/kit-aws-schema";
12
6
 
13
7
  const ddbClient = new DynamoDBClient({ region: process.env.AWS_REGION });
14
8
  const ddbDocClient = DynamoDBDocumentClient.from(ddbClient);
package/tsconfig.json CHANGED
@@ -12,6 +12,12 @@
12
12
  {
13
13
  "path": "../kit-log"
14
14
  },
15
+ {
16
+ "path": "../kit-schema"
17
+ },
18
+ {
19
+ "path": "../kit-aws-schema"
20
+ },
15
21
  {
16
22
  "path": "../kit-request"
17
23
  }
@@ -1 +0,0 @@
1
- export declare const ID_FIELD = "id";
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ID_FIELD = void 0;
4
- exports.ID_FIELD = "id";
@@ -1,25 +0,0 @@
1
- import { z } from "zod";
2
- export declare const TableItemSchema: z.ZodObject<{
3
- id: z.ZodString;
4
- PK: z.ZodString;
5
- SK: z.ZodString;
6
- }, "strip", z.ZodTypeAny, {
7
- id: string;
8
- PK: string;
9
- SK: string;
10
- }, {
11
- id: string;
12
- PK: string;
13
- SK: string;
14
- }>;
15
- export type TableItem = z.infer<typeof TableItemSchema>;
16
- export declare const isTableItem: (obj: unknown) => obj is {
17
- id: string;
18
- PK: string;
19
- SK: string;
20
- };
21
- export declare const areTableItems: (obj: unknown) => obj is {
22
- id: string;
23
- PK: string;
24
- SK: string;
25
- }[];
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.areTableItems = exports.isTableItem = exports.TableItemSchema = void 0;
4
- const fields_1 = require("./fields");
5
- const keys_1 = require("./keys");
6
- const zod_1 = require("zod");
7
- exports.TableItemSchema = zod_1.z
8
- .object({
9
- [fields_1.ID_FIELD]: zod_1.z.string(),
10
- })
11
- .merge(keys_1.TableKeySchema);
12
- const isTableItem = (obj) => exports.TableItemSchema.passthrough().safeParse(obj).success;
13
- exports.isTableItem = isTableItem;
14
- const areTableItems = (obj) => {
15
- return zod_1.z.array(exports.TableItemSchema.passthrough()).safeParse(obj).success;
16
- };
17
- exports.areTableItems = areTableItems;
@@ -1,26 +0,0 @@
1
- import { z } from "zod";
2
- export declare const PARTITION_KEY = "PK";
3
- export declare const SORT_KEY = "SK";
4
- export declare const TableKeySchema: z.ZodObject<{
5
- PK: z.ZodString;
6
- SK: z.ZodString;
7
- }, "strip", z.ZodTypeAny, {
8
- PK: string;
9
- SK: string;
10
- }, {
11
- PK: string;
12
- SK: string;
13
- }>;
14
- export type TableKey = z.infer<typeof TableKeySchema>;
15
- export declare const PartialTableKey: z.ZodObject<{
16
- PK: z.ZodString;
17
- SK: z.ZodOptional<z.ZodString>;
18
- }, "strip", z.ZodTypeAny, {
19
- PK: string;
20
- SK?: string | undefined;
21
- }, {
22
- PK: string;
23
- SK?: string | undefined;
24
- }>;
25
- export type PartialTableKey = z.infer<typeof PartialTableKey>;
26
- export declare const getAggregateKeyFromTableKey: (tableKey: TableKey) => string;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAggregateKeyFromTableKey = exports.PartialTableKey = exports.TableKeySchema = exports.SORT_KEY = exports.PARTITION_KEY = void 0;
4
- const zod_1 = require("zod");
5
- exports.PARTITION_KEY = "PK";
6
- exports.SORT_KEY = "SK";
7
- exports.TableKeySchema = zod_1.z.object({
8
- [exports.PARTITION_KEY]: zod_1.z.string(),
9
- [exports.SORT_KEY]: zod_1.z.string(),
10
- });
11
- exports.PartialTableKey = zod_1.z.object({
12
- [exports.PARTITION_KEY]: zod_1.z.string(),
13
- [exports.SORT_KEY]: zod_1.z.string().optional(),
14
- });
15
- const getAggregateKeyFromTableKey = (tableKey) => {
16
- return `${tableKey[exports.PARTITION_KEY]}##${tableKey[exports.SORT_KEY]}`;
17
- };
18
- exports.getAggregateKeyFromTableKey = getAggregateKeyFromTableKey;
@@ -1 +0,0 @@
1
- export const ID_FIELD = "id"
@@ -1,16 +0,0 @@
1
- import { ID_FIELD } from "./fields";
2
- import { PARTITION_KEY, SORT_KEY, TableKeySchema } from "./keys";
3
- import { z } from "zod";
4
-
5
- export const TableItemSchema = z
6
- .object({
7
- [ID_FIELD]: z.string(),
8
- })
9
- .merge(TableKeySchema);
10
- export type TableItem = z.infer<typeof TableItemSchema>;
11
- export const isTableItem = (obj: unknown): obj is TableItem =>
12
- TableItemSchema.passthrough().safeParse(obj).success;
13
-
14
- export const areTableItems = (obj: unknown): obj is TableItem[] => {
15
- return z.array(TableItemSchema.passthrough()).safeParse(obj).success;
16
- };
@@ -1,20 +0,0 @@
1
- import { z } from "zod";
2
-
3
- export const PARTITION_KEY = "PK";
4
- export const SORT_KEY = "SK";
5
-
6
- export const TableKeySchema = z.object({
7
- [PARTITION_KEY]: z.string(),
8
- [SORT_KEY]: z.string(),
9
- });
10
- export type TableKey = z.infer<typeof TableKeySchema>;
11
-
12
- export const PartialTableKey = z.object({
13
- [PARTITION_KEY]: z.string(),
14
- [SORT_KEY]: z.string().optional(),
15
- });
16
- export type PartialTableKey = z.infer<typeof PartialTableKey>;
17
-
18
- export const getAggregateKeyFromTableKey = (tableKey: TableKey) => {
19
- return `${tableKey[PARTITION_KEY]}##${tableKey[SORT_KEY]}`;
20
- };