dinah 0.1.3 → 0.3.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.
@@ -0,0 +1,128 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ let typebox = require("typebox");
24
+ typebox = __toESM(typebox);
25
+ //#region src/util.ts
26
+ const resolveAttrType = (schema, attrName) => {
27
+ if (typebox.IsString(schema) || typebox.IsLiteralString(schema)) return "S";
28
+ if (typebox.IsNumber(schema) || typebox.IsLiteralNumber(schema) || typebox.IsInteger(schema)) return "N";
29
+ if (typebox.IsObject(schema)) {
30
+ const attrSchema = schema.properties[attrName];
31
+ if (!attrSchema) throw new Error(`Attribute "${attrName}" not found.`);
32
+ return resolveAttrType(attrSchema, attrName);
33
+ }
34
+ if (typebox.IsIntersect(schema) || typebox.IsUnion(schema)) {
35
+ const [firstType, ...otherTypes] = (typebox.IsUnion(schema) ? schema.anyOf : schema.allOf).flatMap((s) => resolveAttrType(s, attrName));
36
+ if (!firstType || otherTypes.some((t) => t !== firstType)) throw new Error(`Attribute "${attrName}" type not consistent.`);
37
+ return firstType;
38
+ }
39
+ throw new Error(`Unable to resolve type for attribute "${attrName}"`);
40
+ };
41
+ const extractTableDesc = (table) => {
42
+ const attributes = /* @__PURE__ */ new Map();
43
+ const setAttributes = (attrNames, keyType) => {
44
+ return attrNames.flatMap((attrName) => {
45
+ if (!attrName) return [];
46
+ attributes.set(attrName, {
47
+ AttributeName: attrName,
48
+ AttributeType: resolveAttrType(table.schema, attrName)
49
+ });
50
+ return {
51
+ AttributeName: attrName,
52
+ KeyType: keyType
53
+ };
54
+ });
55
+ };
56
+ let gsis;
57
+ if (table.def.gsis) gsis = Object.entries(table.def.gsis ?? {}).map(([indexName, gsi]) => {
58
+ return {
59
+ IndexName: indexName,
60
+ KeySchema: [...setAttributes([gsi.partitionKey].flat(), "HASH"), ...setAttributes([gsi.sortKey].flat(), "RANGE")],
61
+ Projection: {
62
+ ProjectionType: Array.isArray(gsi.projection) ? "INCLUDE" : gsi.projection ?? "ALL",
63
+ NonKeyAttributes: Array.isArray(gsi.projection) ? gsi.projection : void 0
64
+ }
65
+ };
66
+ });
67
+ return {
68
+ TableName: table.def.name,
69
+ KeySchema: [...setAttributes([table.def.partitionKey], "HASH"), ...setAttributes([table.def.sortKey], "RANGE")],
70
+ GlobalSecondaryIndexes: gsis,
71
+ AttributeDefinitions: [...attributes.values()],
72
+ BillingMode: table.def.billingMode,
73
+ StreamSpecification: table.def.stream ? {
74
+ StreamEnabled: true,
75
+ StreamViewType: table.def.stream
76
+ } : void 0
77
+ };
78
+ };
79
+ const chunk = (arr, chunkSize) => {
80
+ if (chunkSize <= 0) return [];
81
+ const chunks = [];
82
+ for (let i = 0; i < arr.length; i += chunkSize) chunks.push(arr.slice(i, i + chunkSize));
83
+ return chunks;
84
+ };
85
+ const removeUndefined = (obj) => {
86
+ const stack = [obj];
87
+ while (stack.length) {
88
+ const currentObj = stack.pop();
89
+ if (currentObj !== void 0) Object.entries(currentObj).forEach(([k, v]) => {
90
+ if (v && v instanceof Object) stack.push(v);
91
+ else if (v === void 0) delete currentObj[k];
92
+ });
93
+ }
94
+ return obj;
95
+ };
96
+ //#endregion
97
+ Object.defineProperty(exports, "__toESM", {
98
+ enumerable: true,
99
+ get: function() {
100
+ return __toESM;
101
+ }
102
+ });
103
+ Object.defineProperty(exports, "chunk", {
104
+ enumerable: true,
105
+ get: function() {
106
+ return chunk;
107
+ }
108
+ });
109
+ Object.defineProperty(exports, "extractTableDesc", {
110
+ enumerable: true,
111
+ get: function() {
112
+ return extractTableDesc;
113
+ }
114
+ });
115
+ Object.defineProperty(exports, "removeUndefined", {
116
+ enumerable: true,
117
+ get: function() {
118
+ return removeUndefined;
119
+ }
120
+ });
121
+ Object.defineProperty(exports, "resolveAttrType", {
122
+ enumerable: true,
123
+ get: function() {
124
+ return resolveAttrType;
125
+ }
126
+ });
127
+
128
+ //# sourceMappingURL=util-zAG7brd9.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util-zAG7brd9.cjs","names":["T"],"sources":["../src/util.ts"],"sourcesContent":["import type {\n AttributeDefinition,\n CreateTableCommandInput,\n ProjectionType,\n} from \"@aws-sdk/client-dynamodb\";\nimport { type TSchema } from \"typebox\";\nimport * as T from \"typebox\";\nimport type { Obj } from \"./types\";\nimport type { Table } from \"./table\";\n\nexport const resolveAttrType = (schema: TSchema, attrName: string): \"S\" | \"N\" => {\n if (T.IsString(schema) || T.IsLiteralString(schema)) {\n return \"S\";\n }\n\n if (T.IsNumber(schema) || T.IsLiteralNumber(schema) || T.IsInteger(schema)) {\n return \"N\";\n }\n\n if (T.IsObject(schema)) {\n const attrSchema = schema.properties[attrName];\n if (!attrSchema) {\n throw new Error(`Attribute \"${attrName}\" not found.`);\n }\n return resolveAttrType(attrSchema, attrName);\n }\n\n if (T.IsIntersect(schema) || T.IsUnion(schema)) {\n const schemas = T.IsUnion(schema) ? schema.anyOf : schema.allOf;\n const [firstType, ...otherTypes] = schemas.flatMap((s) => resolveAttrType(s, attrName));\n if (!firstType || otherTypes.some((t) => t !== firstType)) {\n throw new Error(`Attribute \"${attrName}\" type not consistent.`);\n }\n\n return firstType;\n }\n\n throw new Error(`Unable to resolve type for attribute \"${attrName}\"`);\n};\n\nexport const extractTableDesc = (table: Table): CreateTableCommandInput => {\n const attributes = new Map<string, AttributeDefinition>();\n\n const setAttributes = (\n attrNames: (string | undefined)[],\n keyType: \"HASH\" | \"RANGE\",\n ): { AttributeName: string; KeyType: \"HASH\" | \"RANGE\" }[] => {\n return attrNames.flatMap((attrName) => {\n if (!attrName) return [];\n attributes.set(attrName, {\n AttributeName: attrName,\n AttributeType: resolveAttrType(table.schema, attrName),\n });\n return { AttributeName: attrName, KeyType: keyType };\n });\n };\n\n let gsis: CreateTableCommandInput[\"GlobalSecondaryIndexes\"];\n if (table.def.gsis) {\n gsis = Object.entries(table.def.gsis ?? {}).map(([indexName, gsi]) => {\n return {\n IndexName: indexName,\n KeySchema: [\n ...setAttributes([gsi.partitionKey].flat(), \"HASH\"),\n ...setAttributes([gsi.sortKey].flat(), \"RANGE\"),\n ],\n Projection: {\n ProjectionType: (Array.isArray(gsi.projection)\n ? \"INCLUDE\"\n : (gsi.projection ?? \"ALL\")) as ProjectionType,\n NonKeyAttributes: Array.isArray(gsi.projection) ? gsi.projection : undefined,\n },\n };\n });\n }\n\n // attribute definitions need to go AFTER key schemas since\n // are built while resolving the rest of the configuration\n return {\n TableName: table.def.name,\n KeySchema: [\n ...setAttributes([table.def.partitionKey], \"HASH\"),\n ...setAttributes([table.def.sortKey], \"RANGE\"),\n ],\n GlobalSecondaryIndexes: gsis,\n AttributeDefinitions: [...attributes.values()],\n BillingMode: table.def.billingMode,\n StreamSpecification: table.def.stream\n ? { StreamEnabled: true, StreamViewType: table.def.stream }\n : undefined,\n };\n};\n\nexport const chunk = <T = unknown>(arr: T[], chunkSize: number): T[][] => {\n if (chunkSize <= 0) return [];\n\n const chunks: T[][] = [];\n for (let i = 0; i < arr.length; i += chunkSize) {\n chunks.push(arr.slice(i, i + chunkSize));\n }\n\n return chunks;\n};\n\n// this currently creates sparse arrays if an undefined\n// value is found inside an array...not sure if thats valid?\nexport const removeUndefined = (obj: Obj) => {\n const stack = [obj];\n while (stack.length) {\n const currentObj = stack.pop();\n if (currentObj !== undefined) {\n Object.entries(currentObj).forEach(([k, v]) => {\n if (v && v instanceof Object) stack.push(v);\n else if (v === undefined) delete currentObj[k];\n });\n }\n }\n return obj;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAa,mBAAmB,QAAiB,aAAgC;AAC/E,KAAIA,QAAE,SAAS,OAAO,IAAIA,QAAE,gBAAgB,OAAO,CACjD,QAAO;AAGT,KAAIA,QAAE,SAAS,OAAO,IAAIA,QAAE,gBAAgB,OAAO,IAAIA,QAAE,UAAU,OAAO,CACxE,QAAO;AAGT,KAAIA,QAAE,SAAS,OAAO,EAAE;EACtB,MAAM,aAAa,OAAO,WAAW;AACrC,MAAI,CAAC,WACH,OAAM,IAAI,MAAM,cAAc,SAAS,cAAc;AAEvD,SAAO,gBAAgB,YAAY,SAAS;;AAG9C,KAAIA,QAAE,YAAY,OAAO,IAAIA,QAAE,QAAQ,OAAO,EAAE;EAE9C,MAAM,CAAC,WAAW,GAAG,eADLA,QAAE,QAAQ,OAAO,GAAG,OAAO,QAAQ,OAAO,OACf,SAAS,MAAM,gBAAgB,GAAG,SAAS,CAAC;AACvF,MAAI,CAAC,aAAa,WAAW,MAAM,MAAM,MAAM,UAAU,CACvD,OAAM,IAAI,MAAM,cAAc,SAAS,wBAAwB;AAGjE,SAAO;;AAGT,OAAM,IAAI,MAAM,yCAAyC,SAAS,GAAG;;AAGvE,MAAa,oBAAoB,UAA0C;CACzE,MAAM,6BAAa,IAAI,KAAkC;CAEzD,MAAM,iBACJ,WACA,YAC2D;AAC3D,SAAO,UAAU,SAAS,aAAa;AACrC,OAAI,CAAC,SAAU,QAAO,EA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MAAM,aAAa,MAAM,KAAK;AAC9B,MAAI,eAAe,KAAA,EACjB,QAAO,QAAQ,WAAW,CAAC,SAAS,CAAC,GAAG,OAAO;AAC7C,OAAI,KAAK,aAAa,OAAQ,OAAM,KAAK,EAAE;YAClC,MAAM,KAAA,EAAW,QAAO,WAAW;IAC5C;;AAGN,QAAO"}
package/package.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "dinah",
3
+ "version": "0.3.0",
3
4
  "description": "A dynamodb client designed for typescript",
4
5
  "homepage": "https://github.com/jayalfredprufrock/dinah#readme",
5
6
  "bugs": {
@@ -14,15 +15,63 @@
14
15
  "files": [
15
16
  "dist"
16
17
  ],
18
+ "type": "module",
19
+ "sideEffects": false,
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.mjs",
22
+ "types": "./dist/index.d.cts",
23
+ "exports": {
24
+ ".": {
25
+ "import": "./dist/index.mjs",
26
+ "require": "./dist/index.cjs"
27
+ },
28
+ "./cdk": {
29
+ "import": "./dist/cdk.mjs",
30
+ "require": "./dist/cdk.cjs"
31
+ },
32
+ "./streams": {
33
+ "import": "./dist/streams.mjs",
34
+ "require": "./dist/streams.cjs"
35
+ },
36
+ "./package.json": "./package.json"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
17
41
  "devDependencies": {
42
+ "@aws-sdk/client-dynamodb": "^3.1027.0",
43
+ "@aws-sdk/lib-dynamodb": "^3.1027.0",
18
44
  "@semantic-release/exec": "^7.1.0",
19
45
  "@tsconfig/node24": "^24.0.4",
20
46
  "@types/node": "^24.12.0",
21
47
  "@typescript/native-preview": "7.0.0-dev.20260328.1",
48
+ "aws-cdk-lib": "^2.250.0",
22
49
  "semantic-release": "^25.0.3",
23
50
  "typebox": "^1.1.14",
24
51
  "vite-plus": "^0.1.14"
25
52
  },
53
+ "peerDependencies": {
54
+ "@aws-sdk/client-dynamodb": "^3.1027.0",
55
+ "@aws-sdk/client-dynamodb-streams": "^3.1027.0",
56
+ "@aws-sdk/lib-dynamodb": "^3.1027.0",
57
+ "aws-cdk-lib": "^2.250.0",
58
+ "sift": "^17.1.3",
59
+ "typebox": "^1.1.14"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "@aws-sdk/client-dynamodb-streams": {
63
+ "optional": true
64
+ },
65
+ "aws-cdk-lib": {
66
+ "optional": true
67
+ },
68
+ "sift": {
69
+ "optional": true
70
+ },
71
+ "typebox": {
72
+ "optional": true
73
+ }
74
+ },
26
75
  "release": {
27
76
  "branches": [
28
77
  "main"
@@ -33,16 +82,14 @@
33
82
  [
34
83
  "@semantic-release/exec",
35
84
  {
36
- "prepareCmd": "pnpm version ${nextRelease.version} --git-tag-version=false",
37
- "publishCmd": "pnpm --filter dinah publish --no-git-checks"
85
+ "prepareCmd": "pnpm version ${nextRelease.version} --no-git-tag-version",
86
+ "publishCmd": "pnpm publish --no-git-checks"
38
87
  }
39
88
  ],
40
89
  "@semantic-release/github"
41
90
  ]
42
91
  },
43
- "version": "0.1.3",
44
92
  "scripts": {
45
- "build": "vp run --recursive build",
46
- "test": "vp run --recursive test"
93
+ "dev": "vp pack --watch"
47
94
  }
48
95
  }