@ftschopp/dynatable-core 1.3.0 → 1.4.1

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/builders/batch-get/create-batch-get-builder.d.ts.map +1 -1
  3. package/dist/builders/batch-get/create-batch-get-builder.js +8 -3
  4. package/dist/builders/get/create-get-builder.d.ts.map +1 -1
  5. package/dist/builders/get/create-get-builder.js +2 -19
  6. package/dist/builders/query/create-query-builder.d.ts.map +1 -1
  7. package/dist/builders/query/create-query-builder.js +34 -3
  8. package/dist/builders/query/types.d.ts +16 -0
  9. package/dist/builders/query/types.d.ts.map +1 -1
  10. package/dist/builders/scan/create-scan-builder.d.ts.map +1 -1
  11. package/dist/builders/scan/create-scan-builder.js +42 -2
  12. package/dist/builders/scan/types.d.ts +35 -0
  13. package/dist/builders/scan/types.d.ts.map +1 -1
  14. package/dist/builders/shared/index.d.ts +1 -0
  15. package/dist/builders/shared/index.d.ts.map +1 -1
  16. package/dist/builders/shared/index.js +1 -0
  17. package/dist/builders/shared/projection.d.ts +15 -0
  18. package/dist/builders/shared/projection.d.ts.map +1 -0
  19. package/dist/builders/shared/projection.js +26 -0
  20. package/package.json +1 -1
  21. package/src/builders/batch-get/create-batch-get-builder.test.ts +30 -2
  22. package/src/builders/batch-get/create-batch-get-builder.ts +10 -3
  23. package/src/builders/get/create-get-builder.ts +1 -24
  24. package/src/builders/query/create-query-builder.test.ts +205 -1
  25. package/src/builders/query/create-query-builder.ts +40 -5
  26. package/src/builders/query/types.ts +17 -0
  27. package/src/builders/scan/create-scan-builder.test.ts +162 -6
  28. package/src/builders/scan/create-scan-builder.ts +52 -4
  29. package/src/builders/scan/types.ts +39 -0
  30. package/src/builders/shared/index.ts +1 -0
  31. package/src/builders/shared/projection.ts +28 -0
  32. package/tests/integration/instagram-clone.integration.test.ts +23 -4
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Builds a `ProjectionExpression` together with the matching
3
+ * `ExpressionAttributeNames` map so that any attribute — including
4
+ * DynamoDB reserved words like `name`, `date`, `status`, `type`, `data`,
5
+ * `count`, `size`, `value`, `time`, `year`, `source`, … — is referenced
6
+ * via a `#placeholder`.
7
+ *
8
+ * Without this indirection DynamoDB rejects the request with
9
+ * `ValidationException: Attribute name is a reserved keyword`.
10
+ */
11
+ export function buildProjectionExpression(attrs: string[]): {
12
+ ProjectionExpression: string;
13
+ ExpressionAttributeNames: Record<string, string>;
14
+ } {
15
+ const names: Record<string, string> = {};
16
+ const projectionParts: string[] = [];
17
+
18
+ attrs.forEach((attr) => {
19
+ const placeholder = `#${attr}`;
20
+ names[placeholder] = attr;
21
+ projectionParts.push(placeholder);
22
+ });
23
+
24
+ return {
25
+ ProjectionExpression: projectionParts.join(', '),
26
+ ExpressionAttributeNames: names,
27
+ };
28
+ }
@@ -346,7 +346,14 @@ describe('Should test dbParams function builder', () => {
346
346
  .dbParams();
347
347
 
348
348
  expect(params.TableName).toBe('InstagramClone');
349
- expect(params.ProjectionExpression).toBe('photoId, url, likesCount');
349
+ expect(params.ProjectionExpression).toBe('#photoId, #url, #likesCount');
350
+ expect(params.ExpressionAttributeNames).toEqual(
351
+ expect.objectContaining({
352
+ '#photoId': 'photoId',
353
+ '#url': 'url',
354
+ '#likesCount': 'likesCount',
355
+ })
356
+ );
350
357
  });
351
358
 
352
359
  test('Query Likes by photoId', async () => {
@@ -786,9 +793,16 @@ describe('Should test dbParams function builder', () => {
786
793
  .select(['username', 'photoId', 'likesCount'])
787
794
  .dbParams();
788
795
 
789
- expect(params.ProjectionExpression).toBe('username, photoId, likesCount');
796
+ expect(params.ProjectionExpression).toBe('#username, #photoId, #likesCount');
790
797
  expect(params.FilterExpression).toBe('#_type = :_type');
791
798
  expect(params.ExpressionAttributeValues).toMatchObject({ ':_type': 'Photo' });
799
+ expect(params.ExpressionAttributeNames).toEqual(
800
+ expect.objectContaining({
801
+ '#username': 'username',
802
+ '#photoId': 'photoId',
803
+ '#likesCount': 'likesCount',
804
+ })
805
+ );
792
806
  });
793
807
 
794
808
  test('SCAN Photos with limit', async () => {
@@ -838,7 +852,7 @@ describe('Should test dbParams function builder', () => {
838
852
  expect(params.FilterExpression).toMatch(/size\(#content\) > :content_size_\d+/);
839
853
  expect(params.FilterExpression).toMatch(/#_type = :_type/);
840
854
  expect(params.ExpressionAttributeValues).toMatchObject({ ':_type': 'Comment' });
841
- expect(params.ProjectionExpression).toBe('photoId, commentId, content');
855
+ expect(params.ProjectionExpression).toBe('#photoId, #commentId, #content');
842
856
  expect(params.Limit).toBe(50);
843
857
  });
844
858
 
@@ -872,7 +886,12 @@ describe('Should test dbParams function builder', () => {
872
886
  { PK: 'USER#alice', SK: 'USER#alice' },
873
887
  { PK: 'USER#bob', SK: 'USER#bob' },
874
888
  ],
875
- ProjectionExpression: 'username, name, followerCount',
889
+ ProjectionExpression: '#username, #name, #followerCount',
890
+ ExpressionAttributeNames: {
891
+ '#username': 'username',
892
+ '#name': 'name',
893
+ '#followerCount': 'followerCount',
894
+ },
876
895
  },
877
896
  });
878
897
  });