dyno-table 0.1.7 → 0.2.0-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/LICENSE +21 -0
- package/README.md +681 -160
- package/dist/builder-types-C_PDZhnP.d.ts +118 -0
- package/dist/builder-types-DtwbqMeF.d.cts +118 -0
- package/dist/builders/condition-check-builder.cjs +394 -0
- package/dist/builders/condition-check-builder.cjs.map +1 -0
- package/dist/builders/condition-check-builder.d.cts +157 -0
- package/dist/builders/condition-check-builder.d.ts +157 -0
- package/dist/builders/condition-check-builder.js +392 -0
- package/dist/builders/condition-check-builder.js.map +1 -0
- package/dist/builders/delete-builder.cjs +405 -0
- package/dist/builders/delete-builder.cjs.map +1 -0
- package/dist/builders/delete-builder.d.cts +166 -0
- package/dist/builders/delete-builder.d.ts +166 -0
- package/dist/builders/delete-builder.js +403 -0
- package/dist/builders/delete-builder.js.map +1 -0
- package/dist/builders/paginator.cjs +199 -0
- package/dist/builders/paginator.cjs.map +1 -0
- package/dist/builders/paginator.d.cts +179 -0
- package/dist/builders/paginator.d.ts +179 -0
- package/dist/builders/paginator.js +197 -0
- package/dist/builders/paginator.js.map +1 -0
- package/dist/builders/put-builder.cjs +476 -0
- package/dist/builders/put-builder.cjs.map +1 -0
- package/dist/builders/put-builder.d.cts +274 -0
- package/dist/builders/put-builder.d.ts +274 -0
- package/dist/builders/put-builder.js +474 -0
- package/dist/builders/put-builder.js.map +1 -0
- package/dist/builders/query-builder.cjs +674 -0
- package/dist/builders/query-builder.cjs.map +1 -0
- package/dist/builders/query-builder.d.cts +6 -0
- package/dist/builders/query-builder.d.ts +6 -0
- package/dist/builders/query-builder.js +672 -0
- package/dist/builders/query-builder.js.map +1 -0
- package/dist/builders/transaction-builder.cjs +894 -0
- package/dist/builders/transaction-builder.cjs.map +1 -0
- package/dist/builders/transaction-builder.d.cts +511 -0
- package/dist/builders/transaction-builder.d.ts +511 -0
- package/dist/builders/transaction-builder.js +892 -0
- package/dist/builders/transaction-builder.js.map +1 -0
- package/dist/builders/update-builder.cjs +627 -0
- package/dist/builders/update-builder.cjs.map +1 -0
- package/dist/builders/update-builder.d.cts +365 -0
- package/dist/builders/update-builder.d.ts +365 -0
- package/dist/builders/update-builder.js +625 -0
- package/dist/builders/update-builder.js.map +1 -0
- package/dist/conditions--ld9a78i.d.ts +331 -0
- package/dist/conditions-ChhQWd6z.d.cts +331 -0
- package/dist/conditions.cjs +59 -0
- package/dist/conditions.cjs.map +1 -0
- package/dist/conditions.d.cts +3 -0
- package/dist/conditions.d.ts +3 -0
- package/dist/conditions.js +43 -0
- package/dist/conditions.js.map +1 -0
- package/dist/entity.cjs +228 -0
- package/dist/entity.cjs.map +1 -0
- package/dist/entity.d.cts +149 -0
- package/dist/entity.d.ts +149 -0
- package/dist/entity.js +224 -0
- package/dist/entity.js.map +1 -0
- package/dist/query-builder-Csror9Iu.d.ts +507 -0
- package/dist/query-builder-D2FM9rsu.d.cts +507 -0
- package/dist/standard-schema.cjs +4 -0
- package/dist/standard-schema.cjs.map +1 -0
- package/dist/standard-schema.d.cts +57 -0
- package/dist/standard-schema.d.ts +57 -0
- package/dist/standard-schema.js +3 -0
- package/dist/standard-schema.js.map +1 -0
- package/dist/table-BEhBPy2G.d.cts +364 -0
- package/dist/table-BW3cmUqr.d.ts +364 -0
- package/dist/{index.js → table.cjs} +330 -354
- package/dist/table.cjs.map +1 -0
- package/dist/table.d.cts +12 -0
- package/dist/table.d.ts +12 -0
- package/dist/table.js +3243 -0
- package/dist/table.js.map +1 -0
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +22 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/partition-key-template.cjs +19 -0
- package/dist/utils/partition-key-template.cjs.map +1 -0
- package/dist/utils/partition-key-template.d.cts +32 -0
- package/dist/utils/partition-key-template.d.ts +32 -0
- package/dist/utils/partition-key-template.js +17 -0
- package/dist/utils/partition-key-template.js.map +1 -0
- package/dist/utils/sort-key-template.cjs +19 -0
- package/dist/utils/sort-key-template.cjs.map +1 -0
- package/dist/utils/sort-key-template.d.cts +35 -0
- package/dist/utils/sort-key-template.d.ts +35 -0
- package/dist/utils/sort-key-template.js +17 -0
- package/dist/utils/sort-key-template.js.map +1 -0
- package/package.json +97 -22
- package/dist/index.d.ts +0 -2923
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/partition-key-template.ts
|
|
4
|
+
function partitionKey(strings, ...keys) {
|
|
5
|
+
return (params) => {
|
|
6
|
+
let result = strings[0] ?? "";
|
|
7
|
+
for (let i = 0; i < keys.length; i++) {
|
|
8
|
+
const key = keys[i];
|
|
9
|
+
if (key) {
|
|
10
|
+
result += params[key] + (strings[i + 1] ?? "");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.partitionKey = partitionKey;
|
|
18
|
+
//# sourceMappingURL=partition-key-template.cjs.map
|
|
19
|
+
//# sourceMappingURL=partition-key-template.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/partition-key-template.ts"],"names":[],"mappings":";;;AA8BO,SAAS,YAAA,CACd,YACG,IACwC,EAAA;AAC3C,EAAA,OAAO,CAAC,MAAW,KAAA;AACjB,IAAI,IAAA,MAAA,GAAS,OAAQ,CAAA,CAAC,CAAK,IAAA,EAAA;AAE3B,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,CAAK,QAAQ,CAAK,EAAA,EAAA;AACpC,MAAM,MAAA,GAAA,GAAM,KAAK,CAAC,CAAA;AAClB,MAAA,IAAI,GAAK,EAAA;AACP,QAAA,MAAA,IAAU,OAAO,GAAgB,CAAA,IAAK,OAAQ,CAAA,CAAA,GAAI,CAAC,CAAK,IAAA,EAAA,CAAA;AAAA;AAC1D;AAGF,IAAO,OAAA,MAAA;AAAA,GACT;AACF","file":"partition-key-template.cjs","sourcesContent":["export type StrictGenerateType<T extends readonly string[]> = {\n [K in T[number]]: string;\n};\n\n/**\n * Creates a template function for generating DynamoDB partition keys with dynamic values.\n * Use this function when you need to:\n * - Create consistent partition key patterns with variable parts\n * - Generate partition keys that follow a specific format\n * - Ensure type safety for partition key parameters\n * - Require all parameters to be provided\n *\n * @example\n * ```ts\n * // Define a partition key template\n * const pk = partitionKey`country#${\"country\"}#enclosure#${\"enclosure\"}`;\n *\n * // Generate a partition key (all parameters required)\n * const key = pk({ country: \"NZ\", enclosure: \"A1\" });\n * // Result: \"country#NZ#enclosure#A1\"\n *\n * // Type checking ensures all parameters are provided\n * const invalidKey = pk({ country: \"NZ\" }); // TypeScript error\n * ```\n *\n * @param strings - The static parts of the template string\n * @param keys - The dynamic parts of the template string that will be replaced with values\n *\n * @returns A function that accepts an object with the dynamic values and returns the formatted partition key\n */\nexport function partitionKey<T extends readonly string[]>(\n strings: TemplateStringsArray,\n ...keys: T\n): (params: StrictGenerateType<T>) => string {\n return (params) => {\n let result = strings[0] ?? \"\";\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (key) {\n result += params[key as T[number]] + (strings[i + 1] ?? \"\");\n }\n }\n\n return result;\n };\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type StrictGenerateType<T extends readonly string[]> = {
|
|
2
|
+
[K in T[number]]: string;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Creates a template function for generating DynamoDB partition keys with dynamic values.
|
|
6
|
+
* Use this function when you need to:
|
|
7
|
+
* - Create consistent partition key patterns with variable parts
|
|
8
|
+
* - Generate partition keys that follow a specific format
|
|
9
|
+
* - Ensure type safety for partition key parameters
|
|
10
|
+
* - Require all parameters to be provided
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Define a partition key template
|
|
15
|
+
* const pk = partitionKey`country#${"country"}#enclosure#${"enclosure"}`;
|
|
16
|
+
*
|
|
17
|
+
* // Generate a partition key (all parameters required)
|
|
18
|
+
* const key = pk({ country: "NZ", enclosure: "A1" });
|
|
19
|
+
* // Result: "country#NZ#enclosure#A1"
|
|
20
|
+
*
|
|
21
|
+
* // Type checking ensures all parameters are provided
|
|
22
|
+
* const invalidKey = pk({ country: "NZ" }); // TypeScript error
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param strings - The static parts of the template string
|
|
26
|
+
* @param keys - The dynamic parts of the template string that will be replaced with values
|
|
27
|
+
*
|
|
28
|
+
* @returns A function that accepts an object with the dynamic values and returns the formatted partition key
|
|
29
|
+
*/
|
|
30
|
+
declare function partitionKey<T extends readonly string[]>(strings: TemplateStringsArray, ...keys: T): (params: StrictGenerateType<T>) => string;
|
|
31
|
+
|
|
32
|
+
export { type StrictGenerateType, partitionKey };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type StrictGenerateType<T extends readonly string[]> = {
|
|
2
|
+
[K in T[number]]: string;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Creates a template function for generating DynamoDB partition keys with dynamic values.
|
|
6
|
+
* Use this function when you need to:
|
|
7
|
+
* - Create consistent partition key patterns with variable parts
|
|
8
|
+
* - Generate partition keys that follow a specific format
|
|
9
|
+
* - Ensure type safety for partition key parameters
|
|
10
|
+
* - Require all parameters to be provided
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Define a partition key template
|
|
15
|
+
* const pk = partitionKey`country#${"country"}#enclosure#${"enclosure"}`;
|
|
16
|
+
*
|
|
17
|
+
* // Generate a partition key (all parameters required)
|
|
18
|
+
* const key = pk({ country: "NZ", enclosure: "A1" });
|
|
19
|
+
* // Result: "country#NZ#enclosure#A1"
|
|
20
|
+
*
|
|
21
|
+
* // Type checking ensures all parameters are provided
|
|
22
|
+
* const invalidKey = pk({ country: "NZ" }); // TypeScript error
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param strings - The static parts of the template string
|
|
26
|
+
* @param keys - The dynamic parts of the template string that will be replaced with values
|
|
27
|
+
*
|
|
28
|
+
* @returns A function that accepts an object with the dynamic values and returns the formatted partition key
|
|
29
|
+
*/
|
|
30
|
+
declare function partitionKey<T extends readonly string[]>(strings: TemplateStringsArray, ...keys: T): (params: StrictGenerateType<T>) => string;
|
|
31
|
+
|
|
32
|
+
export { type StrictGenerateType, partitionKey };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/utils/partition-key-template.ts
|
|
2
|
+
function partitionKey(strings, ...keys) {
|
|
3
|
+
return (params) => {
|
|
4
|
+
let result = strings[0] ?? "";
|
|
5
|
+
for (let i = 0; i < keys.length; i++) {
|
|
6
|
+
const key = keys[i];
|
|
7
|
+
if (key) {
|
|
8
|
+
result += params[key] + (strings[i + 1] ?? "");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { partitionKey };
|
|
16
|
+
//# sourceMappingURL=partition-key-template.js.map
|
|
17
|
+
//# sourceMappingURL=partition-key-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/partition-key-template.ts"],"names":[],"mappings":";AA8BO,SAAS,YAAA,CACd,YACG,IACwC,EAAA;AAC3C,EAAA,OAAO,CAAC,MAAW,KAAA;AACjB,IAAI,IAAA,MAAA,GAAS,OAAQ,CAAA,CAAC,CAAK,IAAA,EAAA;AAE3B,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,CAAK,QAAQ,CAAK,EAAA,EAAA;AACpC,MAAM,MAAA,GAAA,GAAM,KAAK,CAAC,CAAA;AAClB,MAAA,IAAI,GAAK,EAAA;AACP,QAAA,MAAA,IAAU,OAAO,GAAgB,CAAA,IAAK,OAAQ,CAAA,CAAA,GAAI,CAAC,CAAK,IAAA,EAAA,CAAA;AAAA;AAC1D;AAGF,IAAO,OAAA,MAAA;AAAA,GACT;AACF","file":"partition-key-template.js","sourcesContent":["export type StrictGenerateType<T extends readonly string[]> = {\n [K in T[number]]: string;\n};\n\n/**\n * Creates a template function for generating DynamoDB partition keys with dynamic values.\n * Use this function when you need to:\n * - Create consistent partition key patterns with variable parts\n * - Generate partition keys that follow a specific format\n * - Ensure type safety for partition key parameters\n * - Require all parameters to be provided\n *\n * @example\n * ```ts\n * // Define a partition key template\n * const pk = partitionKey`country#${\"country\"}#enclosure#${\"enclosure\"}`;\n *\n * // Generate a partition key (all parameters required)\n * const key = pk({ country: \"NZ\", enclosure: \"A1\" });\n * // Result: \"country#NZ#enclosure#A1\"\n *\n * // Type checking ensures all parameters are provided\n * const invalidKey = pk({ country: \"NZ\" }); // TypeScript error\n * ```\n *\n * @param strings - The static parts of the template string\n * @param keys - The dynamic parts of the template string that will be replaced with values\n *\n * @returns A function that accepts an object with the dynamic values and returns the formatted partition key\n */\nexport function partitionKey<T extends readonly string[]>(\n strings: TemplateStringsArray,\n ...keys: T\n): (params: StrictGenerateType<T>) => string {\n return (params) => {\n let result = strings[0] ?? \"\";\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (key) {\n result += params[key as T[number]] + (strings[i + 1] ?? \"\");\n }\n }\n\n return result;\n };\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/sort-key-template.ts
|
|
4
|
+
function sortKey(strings, ...keys) {
|
|
5
|
+
return (params) => {
|
|
6
|
+
let result = strings[0] ?? "";
|
|
7
|
+
for (let i = 0; i < keys.length; i++) {
|
|
8
|
+
const key = keys[i];
|
|
9
|
+
if (key && params && key in params) {
|
|
10
|
+
result += params[key] + (strings[i + 1] ?? "");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.sortKey = sortKey;
|
|
18
|
+
//# sourceMappingURL=sort-key-template.cjs.map
|
|
19
|
+
//# sourceMappingURL=sort-key-template.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/sort-key-template.ts"],"names":[],"mappings":";;;AAqCO,SAAS,OAAA,CACd,YACG,IACkC,EAAA;AACrC,EAAA,OAAO,CAAC,MAAW,KAAA;AACjB,IAAI,IAAA,MAAA,GAAS,OAAQ,CAAA,CAAC,CAAK,IAAA,EAAA;AAE3B,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,CAAK,QAAQ,CAAK,EAAA,EAAA;AACpC,MAAM,MAAA,GAAA,GAAM,KAAK,CAAC,CAAA;AAElB,MAAI,IAAA,GAAA,IAAO,MAAU,IAAA,GAAA,IAAO,MAAQ,EAAA;AAClC,QAAA,MAAA,IAAU,OAAO,GAAG,CAAA,IAAK,OAAQ,CAAA,CAAA,GAAI,CAAC,CAAK,IAAA,EAAA,CAAA;AAAA;AAC7C;AAGF,IAAO,OAAA,MAAA;AAAA,GACT;AACF","file":"sort-key-template.cjs","sourcesContent":["export type GenerateType<T extends readonly string[], U extends string = never> = T extends [infer F, ...infer R]\n ? F extends string\n ? R extends string[]\n ? ({ [K in F | U]: string | number } & Partial<Record<Exclude<T[number], F | U>, never>>) | GenerateType<R, F | U>\n : never\n : never\n : never;\n\n/**\n * Creates a template function for generating DynamoDB sort keys with dynamic values.\n * Use this function when you need to:\n * - Create consistent sort key patterns with variable parts\n * - Generate sort keys that follow a specific format\n * - Ensure type safety for sort key parameters\n *\n * @example\n * ```ts\n * // Define a sort key template\n * const sk = sortKey`country#${\"country\"}#enclosure#${\"enclosure\"}#diet#${\"diet\"}`;\n *\n * // Generate a sort key with partial parameters\n * const templatedString = sk({ country: \"NZ\", enclosure: \"A1\" });\n * // Result: \"country#NZ#enclosure#A1#diet#\"\n *\n * // Generate a complete sort key\n * const fullKey = sk({ country: \"NZ\", enclosure: \"A1\", diet: \"carnivore\" });\n * // Result: \"country#NZ#enclosure#A1#diet#carnivore\"\n *\n * // Type checking ensures only valid parameters are used\n * const invalidKey = sk({ country: \"NZ\", invalid: \"value\" }); // TypeScript error\n * ```\n *\n * @param strings - The static parts of the template string\n * @param keys - The dynamic parts of the template string that will be replaced with values\n *\n * @returns A function that accepts an object with the dynamic values and returns the formatted sort key\n */\nexport function sortKey<T extends readonly string[]>(\n strings: TemplateStringsArray,\n ...keys: T\n): (params: GenerateType<T>) => string {\n return (params) => {\n let result = strings[0] ?? \"\";\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n\n if (key && params && key in params) {\n result += params[key] + (strings[i + 1] ?? \"\");\n }\n }\n\n return result;\n };\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type GenerateType<T extends readonly string[], U extends string = never> = T extends [infer F, ...infer R] ? F extends string ? R extends string[] ? ({
|
|
2
|
+
[K in F | U]: string | number;
|
|
3
|
+
} & Partial<Record<Exclude<T[number], F | U>, never>>) | GenerateType<R, F | U> : never : never : never;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a template function for generating DynamoDB sort keys with dynamic values.
|
|
6
|
+
* Use this function when you need to:
|
|
7
|
+
* - Create consistent sort key patterns with variable parts
|
|
8
|
+
* - Generate sort keys that follow a specific format
|
|
9
|
+
* - Ensure type safety for sort key parameters
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Define a sort key template
|
|
14
|
+
* const sk = sortKey`country#${"country"}#enclosure#${"enclosure"}#diet#${"diet"}`;
|
|
15
|
+
*
|
|
16
|
+
* // Generate a sort key with partial parameters
|
|
17
|
+
* const templatedString = sk({ country: "NZ", enclosure: "A1" });
|
|
18
|
+
* // Result: "country#NZ#enclosure#A1#diet#"
|
|
19
|
+
*
|
|
20
|
+
* // Generate a complete sort key
|
|
21
|
+
* const fullKey = sk({ country: "NZ", enclosure: "A1", diet: "carnivore" });
|
|
22
|
+
* // Result: "country#NZ#enclosure#A1#diet#carnivore"
|
|
23
|
+
*
|
|
24
|
+
* // Type checking ensures only valid parameters are used
|
|
25
|
+
* const invalidKey = sk({ country: "NZ", invalid: "value" }); // TypeScript error
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param strings - The static parts of the template string
|
|
29
|
+
* @param keys - The dynamic parts of the template string that will be replaced with values
|
|
30
|
+
*
|
|
31
|
+
* @returns A function that accepts an object with the dynamic values and returns the formatted sort key
|
|
32
|
+
*/
|
|
33
|
+
declare function sortKey<T extends readonly string[]>(strings: TemplateStringsArray, ...keys: T): (params: GenerateType<T>) => string;
|
|
34
|
+
|
|
35
|
+
export { type GenerateType, sortKey };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type GenerateType<T extends readonly string[], U extends string = never> = T extends [infer F, ...infer R] ? F extends string ? R extends string[] ? ({
|
|
2
|
+
[K in F | U]: string | number;
|
|
3
|
+
} & Partial<Record<Exclude<T[number], F | U>, never>>) | GenerateType<R, F | U> : never : never : never;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a template function for generating DynamoDB sort keys with dynamic values.
|
|
6
|
+
* Use this function when you need to:
|
|
7
|
+
* - Create consistent sort key patterns with variable parts
|
|
8
|
+
* - Generate sort keys that follow a specific format
|
|
9
|
+
* - Ensure type safety for sort key parameters
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Define a sort key template
|
|
14
|
+
* const sk = sortKey`country#${"country"}#enclosure#${"enclosure"}#diet#${"diet"}`;
|
|
15
|
+
*
|
|
16
|
+
* // Generate a sort key with partial parameters
|
|
17
|
+
* const templatedString = sk({ country: "NZ", enclosure: "A1" });
|
|
18
|
+
* // Result: "country#NZ#enclosure#A1#diet#"
|
|
19
|
+
*
|
|
20
|
+
* // Generate a complete sort key
|
|
21
|
+
* const fullKey = sk({ country: "NZ", enclosure: "A1", diet: "carnivore" });
|
|
22
|
+
* // Result: "country#NZ#enclosure#A1#diet#carnivore"
|
|
23
|
+
*
|
|
24
|
+
* // Type checking ensures only valid parameters are used
|
|
25
|
+
* const invalidKey = sk({ country: "NZ", invalid: "value" }); // TypeScript error
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param strings - The static parts of the template string
|
|
29
|
+
* @param keys - The dynamic parts of the template string that will be replaced with values
|
|
30
|
+
*
|
|
31
|
+
* @returns A function that accepts an object with the dynamic values and returns the formatted sort key
|
|
32
|
+
*/
|
|
33
|
+
declare function sortKey<T extends readonly string[]>(strings: TemplateStringsArray, ...keys: T): (params: GenerateType<T>) => string;
|
|
34
|
+
|
|
35
|
+
export { type GenerateType, sortKey };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/utils/sort-key-template.ts
|
|
2
|
+
function sortKey(strings, ...keys) {
|
|
3
|
+
return (params) => {
|
|
4
|
+
let result = strings[0] ?? "";
|
|
5
|
+
for (let i = 0; i < keys.length; i++) {
|
|
6
|
+
const key = keys[i];
|
|
7
|
+
if (key && params && key in params) {
|
|
8
|
+
result += params[key] + (strings[i + 1] ?? "");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { sortKey };
|
|
16
|
+
//# sourceMappingURL=sort-key-template.js.map
|
|
17
|
+
//# sourceMappingURL=sort-key-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/sort-key-template.ts"],"names":[],"mappings":";AAqCO,SAAS,OAAA,CACd,YACG,IACkC,EAAA;AACrC,EAAA,OAAO,CAAC,MAAW,KAAA;AACjB,IAAI,IAAA,MAAA,GAAS,OAAQ,CAAA,CAAC,CAAK,IAAA,EAAA;AAE3B,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,CAAK,QAAQ,CAAK,EAAA,EAAA;AACpC,MAAM,MAAA,GAAA,GAAM,KAAK,CAAC,CAAA;AAElB,MAAI,IAAA,GAAA,IAAO,MAAU,IAAA,GAAA,IAAO,MAAQ,EAAA;AAClC,QAAA,MAAA,IAAU,OAAO,GAAG,CAAA,IAAK,OAAQ,CAAA,CAAA,GAAI,CAAC,CAAK,IAAA,EAAA,CAAA;AAAA;AAC7C;AAGF,IAAO,OAAA,MAAA;AAAA,GACT;AACF","file":"sort-key-template.js","sourcesContent":["export type GenerateType<T extends readonly string[], U extends string = never> = T extends [infer F, ...infer R]\n ? F extends string\n ? R extends string[]\n ? ({ [K in F | U]: string | number } & Partial<Record<Exclude<T[number], F | U>, never>>) | GenerateType<R, F | U>\n : never\n : never\n : never;\n\n/**\n * Creates a template function for generating DynamoDB sort keys with dynamic values.\n * Use this function when you need to:\n * - Create consistent sort key patterns with variable parts\n * - Generate sort keys that follow a specific format\n * - Ensure type safety for sort key parameters\n *\n * @example\n * ```ts\n * // Define a sort key template\n * const sk = sortKey`country#${\"country\"}#enclosure#${\"enclosure\"}#diet#${\"diet\"}`;\n *\n * // Generate a sort key with partial parameters\n * const templatedString = sk({ country: \"NZ\", enclosure: \"A1\" });\n * // Result: \"country#NZ#enclosure#A1#diet#\"\n *\n * // Generate a complete sort key\n * const fullKey = sk({ country: \"NZ\", enclosure: \"A1\", diet: \"carnivore\" });\n * // Result: \"country#NZ#enclosure#A1#diet#carnivore\"\n *\n * // Type checking ensures only valid parameters are used\n * const invalidKey = sk({ country: \"NZ\", invalid: \"value\" }); // TypeScript error\n * ```\n *\n * @param strings - The static parts of the template string\n * @param keys - The dynamic parts of the template string that will be replaced with values\n *\n * @returns A function that accepts an object with the dynamic values and returns the formatted sort key\n */\nexport function sortKey<T extends readonly string[]>(\n strings: TemplateStringsArray,\n ...keys: T\n): (params: GenerateType<T>) => string {\n return (params) => {\n let result = strings[0] ?? \"\";\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n\n if (key && params && key in params) {\n result += params[key] + (strings[i + 1] ?? \"\");\n }\n }\n\n return result;\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,16 +1,101 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyno-table",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-0",
|
|
4
4
|
"description": "A TypeScript library to simplify working with DynamoDB",
|
|
5
|
-
"main": "dist/index.
|
|
6
|
-
"
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
7
8
|
"type": "module",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./table": {
|
|
16
|
+
"types": "./dist/table.d.ts",
|
|
17
|
+
"import": "./dist/table.js",
|
|
18
|
+
"require": "./dist/table.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./entity": {
|
|
21
|
+
"types": "./dist/entity.d.ts",
|
|
22
|
+
"import": "./dist/entity.js",
|
|
23
|
+
"require": "./dist/entity.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./conditions": {
|
|
26
|
+
"types": "./dist/conditions.d.ts",
|
|
27
|
+
"import": "./dist/conditions.js",
|
|
28
|
+
"require": "./dist/conditions.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./types": {
|
|
31
|
+
"types": "./dist/types.d.ts",
|
|
32
|
+
"import": "./dist/types.js",
|
|
33
|
+
"require": "./dist/types.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./standard-schema": {
|
|
36
|
+
"types": "./dist/standard-schema.d.ts",
|
|
37
|
+
"import": "./dist/standard-schema.js",
|
|
38
|
+
"require": "./dist/standard-schema.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./utils/partition-key-template": {
|
|
41
|
+
"types": "./dist/utils/partition-key-template.d.ts",
|
|
42
|
+
"import": "./dist/utils/partition-key-template.js",
|
|
43
|
+
"require": "./dist/utils/partition-key-template.cjs"
|
|
44
|
+
},
|
|
45
|
+
"./utils/sort-key-template": {
|
|
46
|
+
"types": "./dist/utils/sort-key-template.d.ts",
|
|
47
|
+
"import": "./dist/utils/sort-key-template.js",
|
|
48
|
+
"require": "./dist/utils/sort-key-template.cjs"
|
|
49
|
+
},
|
|
50
|
+
"./builders/query-builder": {
|
|
51
|
+
"types": "./dist/builders/query-builder.d.ts",
|
|
52
|
+
"import": "./dist/builders/query-builder.js",
|
|
53
|
+
"require": "./dist/builders/query-builder.cjs"
|
|
54
|
+
},
|
|
55
|
+
"./builders/paginator": {
|
|
56
|
+
"types": "./dist/builders/paginator.d.ts",
|
|
57
|
+
"import": "./dist/builders/paginator.js",
|
|
58
|
+
"require": "./dist/builders/paginator.cjs"
|
|
59
|
+
},
|
|
60
|
+
"./builders/put-builder": {
|
|
61
|
+
"types": "./dist/builders/put-builder.d.ts",
|
|
62
|
+
"import": "./dist/builders/put-builder.js",
|
|
63
|
+
"require": "./dist/builders/put-builder.cjs"
|
|
64
|
+
},
|
|
65
|
+
"./builders/update-builder": {
|
|
66
|
+
"types": "./dist/builders/update-builder.d.ts",
|
|
67
|
+
"import": "./dist/builders/update-builder.js",
|
|
68
|
+
"require": "./dist/builders/update-builder.cjs"
|
|
69
|
+
},
|
|
70
|
+
"./builders/delete-builder": {
|
|
71
|
+
"types": "./dist/builders/delete-builder.d.ts",
|
|
72
|
+
"import": "./dist/builders/delete-builder.js",
|
|
73
|
+
"require": "./dist/builders/delete-builder.cjs"
|
|
74
|
+
},
|
|
75
|
+
"./builders/transaction-builder": {
|
|
76
|
+
"types": "./dist/builders/transaction-builder.d.ts",
|
|
77
|
+
"import": "./dist/builders/transaction-builder.js",
|
|
78
|
+
"require": "./dist/builders/transaction-builder.cjs"
|
|
79
|
+
},
|
|
80
|
+
"./builders/condition-check-builder": {
|
|
81
|
+
"types": "./dist/builders/condition-check-builder.d.ts",
|
|
82
|
+
"import": "./dist/builders/condition-check-builder.js",
|
|
83
|
+
"require": "./dist/builders/condition-check-builder.cjs"
|
|
12
84
|
}
|
|
13
85
|
},
|
|
86
|
+
"scripts": {
|
|
87
|
+
"build": "tsup --config tsup.config.ts",
|
|
88
|
+
"clean": "rm -rf dist",
|
|
89
|
+
"test": "vitest run",
|
|
90
|
+
"test:w": "vitest watch",
|
|
91
|
+
"test:int": "vitest --config vitest.integration.ts",
|
|
92
|
+
"local:setup": "npx tsx -e 'import(\"./tests/setup-test-table.ts\").then(m => m.createTestTable())'",
|
|
93
|
+
"local:teardown": "npx tsx -e 'import(\"./tests/setup-test-table.ts\").then(m => m.deleteTestTable())'",
|
|
94
|
+
"lint": "biome lint",
|
|
95
|
+
"check-types": "tsc --noEmit",
|
|
96
|
+
"ddb:start": "docker compose up -d",
|
|
97
|
+
"circular": "npx madge --circular --ts-config ./tsconfig.json --extensions ts,tsx src/"
|
|
98
|
+
},
|
|
14
99
|
"keywords": [
|
|
15
100
|
"dynamodb",
|
|
16
101
|
"aws",
|
|
@@ -26,11 +111,11 @@
|
|
|
26
111
|
"devDependencies": {
|
|
27
112
|
"@babel/preset-typescript": "^7.26.0",
|
|
28
113
|
"@biomejs/biome": "1.9.4",
|
|
29
|
-
"@types/node": "^20.
|
|
30
|
-
"rimraf": "^5.0.
|
|
31
|
-
"tsup": "^8.
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"vitest": "
|
|
114
|
+
"@types/node": "^20.17.11",
|
|
115
|
+
"rimraf": "^5.0.10",
|
|
116
|
+
"tsup": "^8.3.5",
|
|
117
|
+
"typescript": "^5.7.2",
|
|
118
|
+
"vitest": "3.0.5"
|
|
34
119
|
},
|
|
35
120
|
"peerDependencies": {
|
|
36
121
|
"@aws-sdk/client-dynamodb": "^3.0.0",
|
|
@@ -39,15 +124,5 @@
|
|
|
39
124
|
"files": [
|
|
40
125
|
"dist"
|
|
41
126
|
],
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
"clean": "rm -rf dist",
|
|
45
|
-
"test": "vitest run",
|
|
46
|
-
"test:w": "vitest watch",
|
|
47
|
-
"test:int": "vitest --config vitest.integration.ts",
|
|
48
|
-
"lint": "biome lint",
|
|
49
|
-
"check-types": "tsc --noEmit",
|
|
50
|
-
"ddb:start": "docker compose up -d dynamodb",
|
|
51
|
-
"circular": "npx madge --circular --ts-config ./tsconfig.json --extensions ts,tsx src/"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
127
|
+
"packageManager": "pnpm@10.5.2"
|
|
128
|
+
}
|