@type-map-for/dynamodb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -0
- package/package.json +22 -0
- package/src/index.ts +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type DdbAttributeType = 'S' | 'N' | 'BOOL' | 'L' | 'M';
|
|
2
|
+
type DdbType<T> = NonNullable<T> extends string ? 'S' : NonNullable<T> extends number ? 'N' : NonNullable<T> extends boolean ? 'BOOL' : NonNullable<T> extends any[] ? 'L' : 'M';
|
|
3
|
+
export type DynamoDBField<T, K extends keyof T> = {
|
|
4
|
+
AttributeName: K;
|
|
5
|
+
AttributeType: DdbType<T[K]>;
|
|
6
|
+
};
|
|
7
|
+
export type DynamoDBSchema<T> = Array<{
|
|
8
|
+
[K in keyof T]-?: DynamoDBField<T, K>;
|
|
9
|
+
}[keyof T]>;
|
|
10
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@type-map-for/dynamodb",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Compile-time TypeScript → DynamoDB field mapping",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Nathan Frenette",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": { "types": "./dist/index.d.ts" }
|
|
10
|
+
},
|
|
11
|
+
"files": ["dist", "src"],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc -p tsconfig.json"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": { "access": "public" },
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@type-map-for/core": "*"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "*"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* ------------------------------------------------------------------ *
|
|
2
|
+
* @type-map-for/dynamodb *
|
|
3
|
+
* *
|
|
4
|
+
* - Output shape: Array<{ AttributeName, AttributeType }> *
|
|
5
|
+
* - Type system: S | N | BOOL | L (list) | M (map) *
|
|
6
|
+
* - Optionality: not expressed — DynamoDB is schemaless for *
|
|
7
|
+
* non-key attributes *
|
|
8
|
+
* ------------------------------------------------------------------ */
|
|
9
|
+
|
|
10
|
+
export type DdbAttributeType = 'S' | 'N' | 'BOOL' | 'L' | 'M';
|
|
11
|
+
|
|
12
|
+
type DdbType<T> =
|
|
13
|
+
NonNullable<T> extends string ? 'S'
|
|
14
|
+
: NonNullable<T> extends number ? 'N'
|
|
15
|
+
: NonNullable<T> extends boolean ? 'BOOL'
|
|
16
|
+
: NonNullable<T> extends any[] ? 'L'
|
|
17
|
+
: 'M';
|
|
18
|
+
|
|
19
|
+
export type DynamoDBField<T, K extends keyof T> = {
|
|
20
|
+
AttributeName: K;
|
|
21
|
+
AttributeType: DdbType<T[K]>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type DynamoDBSchema<T> = Array<{
|
|
25
|
+
[K in keyof T]-?: DynamoDBField<T, K>
|
|
26
|
+
}[keyof T]>;
|