@aws-amplify/data-schema 1.23.0 → 1.24.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/cjs/ModelIndex.js +9 -0
- package/dist/cjs/ModelIndex.js.map +1 -1
- package/dist/cjs/SchemaProcessor.js +14 -4
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/esm/ModelIndex.d.ts +15 -0
- package/dist/esm/ModelIndex.mjs +9 -0
- package/dist/esm/ModelIndex.mjs.map +1 -1
- package/dist/esm/SchemaProcessor.mjs +14 -4
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/ModelIndex.ts +32 -0
- package/src/SchemaProcessor.ts +16 -2
package/dist/cjs/ModelIndex.js
CHANGED
|
@@ -10,6 +10,8 @@ function _modelIndex(partitionKeyFieldName) {
|
|
|
10
10
|
sortKeys: [],
|
|
11
11
|
indexName: '',
|
|
12
12
|
queryField: '',
|
|
13
|
+
projectionType: 'ALL',
|
|
14
|
+
nonKeyAttributes: undefined,
|
|
13
15
|
};
|
|
14
16
|
const builder = {
|
|
15
17
|
sortKeys(sortKeys) {
|
|
@@ -24,6 +26,13 @@ function _modelIndex(partitionKeyFieldName) {
|
|
|
24
26
|
data.queryField = field;
|
|
25
27
|
return this;
|
|
26
28
|
},
|
|
29
|
+
projection(type, ...args) {
|
|
30
|
+
data.projectionType = type;
|
|
31
|
+
if (type === 'INCLUDE') {
|
|
32
|
+
data.nonKeyAttributes = args[0];
|
|
33
|
+
}
|
|
34
|
+
return this;
|
|
35
|
+
},
|
|
27
36
|
...(0, util_1.brand)(brandName),
|
|
28
37
|
};
|
|
29
38
|
return { ...builder, data };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelIndex.js","sources":["../../src/ModelIndex.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.modelIndex = modelIndex;\nconst util_1 = require(\"./util\");\nconst brandName = 'modelIndexType';\nfunction _modelIndex(partitionKeyFieldName) {\n const data = {\n partitionKey: partitionKeyFieldName,\n sortKeys: [],\n indexName: '',\n queryField: '',\n };\n const builder = {\n sortKeys(sortKeys) {\n data.sortKeys = sortKeys;\n return this;\n },\n name(name) {\n data.indexName = name;\n return this;\n },\n queryField(field) {\n data.queryField = field;\n return this;\n },\n ...(0, util_1.brand)(brandName),\n };\n return { ...builder, data };\n}\nfunction modelIndex(partitionKeyFieldName) {\n return _modelIndex(partitionKeyFieldName);\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,UAAU,GAAG,UAAU;AAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;AAChC,MAAM,SAAS,GAAG,gBAAgB;AAClC,SAAS,WAAW,CAAC,qBAAqB,EAAE;AAC5C,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,YAAY,EAAE,qBAAqB;AAC3C,QAAQ,QAAQ,EAAE,EAAE;AACpB,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,EAAE;AACtB,KAAK;AACL,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,QAAQ,CAAC,QAAQ,EAAE;AAC3B,YAAY,IAAI,CAAC,QAAQ,GAAG,QAAQ;AACpC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,IAAI,CAAC,IAAI,EAAE;AACnB,YAAY,IAAI,CAAC,SAAS,GAAG,IAAI;AACjC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,UAAU,CAAC,KAAK,EAAE;AAC1B,YAAY,IAAI,CAAC,UAAU,GAAG,KAAK;AACnC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC;AACvC,KAAK;AACL,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE;AAC/B;AACA,SAAS,UAAU,CAAC,qBAAqB,EAAE;AAC3C,IAAI,OAAO,WAAW,CAAC,qBAAqB,CAAC;AAC7C;;"}
|
|
1
|
+
{"version":3,"file":"ModelIndex.js","sources":["../../src/ModelIndex.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.modelIndex = modelIndex;\nconst util_1 = require(\"./util\");\nconst brandName = 'modelIndexType';\nfunction _modelIndex(partitionKeyFieldName) {\n const data = {\n partitionKey: partitionKeyFieldName,\n sortKeys: [],\n indexName: '',\n queryField: '',\n projectionType: 'ALL',\n nonKeyAttributes: undefined,\n };\n const builder = {\n sortKeys(sortKeys) {\n data.sortKeys = sortKeys;\n return this;\n },\n name(name) {\n data.indexName = name;\n return this;\n },\n queryField(field) {\n data.queryField = field;\n return this;\n },\n projection(type, ...args) {\n data.projectionType = type;\n if (type === 'INCLUDE') {\n data.nonKeyAttributes = args[0];\n }\n return this;\n },\n ...(0, util_1.brand)(brandName),\n };\n return { ...builder, data };\n}\nfunction modelIndex(partitionKeyFieldName) {\n return _modelIndex(partitionKeyFieldName);\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,UAAU,GAAG,UAAU;AAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;AAChC,MAAM,SAAS,GAAG,gBAAgB;AAClC,SAAS,WAAW,CAAC,qBAAqB,EAAE;AAC5C,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,YAAY,EAAE,qBAAqB;AAC3C,QAAQ,QAAQ,EAAE,EAAE;AACpB,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,EAAE;AACtB,QAAQ,cAAc,EAAE,KAAK;AAC7B,QAAQ,gBAAgB,EAAE,SAAS;AACnC,KAAK;AACL,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,QAAQ,CAAC,QAAQ,EAAE;AAC3B,YAAY,IAAI,CAAC,QAAQ,GAAG,QAAQ;AACpC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,IAAI,CAAC,IAAI,EAAE;AACnB,YAAY,IAAI,CAAC,SAAS,GAAG,IAAI;AACjC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,UAAU,CAAC,KAAK,EAAE;AAC1B,YAAY,IAAI,CAAC,UAAU,GAAG,KAAK;AACnC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,UAAU,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE;AAClC,YAAY,IAAI,CAAC,cAAc,GAAG,IAAI;AACtC,YAAY,IAAI,IAAI,KAAK,SAAS,EAAE;AACpC,gBAAgB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC,CAAC;AAC/C;AACA,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC;AACvC,KAAK;AACL,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE;AAC/B;AACA,SAAS,UAAU,CAAC,qBAAqB,EAAE;AAC3C,IAAI,OAAO,WAAW,CAAC,qBAAqB,CAAC;AAC7C;;"}
|
|
@@ -735,7 +735,7 @@ const secondaryIndexDefaultQueryField = (modelName, pk, sk) => {
|
|
|
735
735
|
* and the value is an array of transformed Amplify @index directives with all supplied attributes
|
|
736
736
|
*/
|
|
737
737
|
const transformedSecondaryIndexesForModel = (modelName, secondaryIndexes, modelFields, getRefType) => {
|
|
738
|
-
const indexDirectiveWithAttributes = (partitionKey, sortKeys, indexName, queryField) => {
|
|
738
|
+
const indexDirectiveWithAttributes = (partitionKey, sortKeys, indexName, queryField, projectionType, nonKeyAttributes) => {
|
|
739
739
|
for (const keyName of [partitionKey, ...sortKeys]) {
|
|
740
740
|
const field = modelFields[keyName];
|
|
741
741
|
if (isRefField(field)) {
|
|
@@ -745,7 +745,7 @@ const transformedSecondaryIndexesForModel = (modelName, secondaryIndexes, modelF
|
|
|
745
745
|
}
|
|
746
746
|
}
|
|
747
747
|
}
|
|
748
|
-
if (!sortKeys.length && !indexName && !queryField && queryField !== null) {
|
|
748
|
+
if (!sortKeys.length && !indexName && !queryField && queryField !== null && !projectionType) {
|
|
749
749
|
return `@index(queryField: "${secondaryIndexDefaultQueryField(modelName, partitionKey)}")`;
|
|
750
750
|
}
|
|
751
751
|
const attributes = [];
|
|
@@ -764,11 +764,21 @@ const transformedSecondaryIndexesForModel = (modelName, secondaryIndexes, modelF
|
|
|
764
764
|
else {
|
|
765
765
|
attributes.push(`queryField: "${secondaryIndexDefaultQueryField(modelName, partitionKey, sortKeys)}"`);
|
|
766
766
|
}
|
|
767
|
+
// Add projection attributes if specified
|
|
768
|
+
if (projectionType && projectionType !== 'ALL') {
|
|
769
|
+
if (projectionType === 'KEYS_ONLY') {
|
|
770
|
+
attributes.push(`projection: { type: KEYS_ONLY }`);
|
|
771
|
+
}
|
|
772
|
+
else if (projectionType === 'INCLUDE' && nonKeyAttributes?.length) {
|
|
773
|
+
const nonKeyAttrsStr = nonKeyAttributes.map(attr => `"${attr}"`).join(', ');
|
|
774
|
+
attributes.push(`projection: { type: INCLUDE, nonKeyAttributes: [${nonKeyAttrsStr}] }`);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
767
777
|
return `@index(${attributes.join(', ')})`;
|
|
768
778
|
};
|
|
769
|
-
return secondaryIndexes.reduce((acc, { data: { partitionKey, sortKeys, indexName, queryField } }) => {
|
|
779
|
+
return secondaryIndexes.reduce((acc, { data: { partitionKey, sortKeys, indexName, queryField, projectionType, nonKeyAttributes } }) => {
|
|
770
780
|
acc[partitionKey] = acc[partitionKey] || [];
|
|
771
|
-
acc[partitionKey].push(indexDirectiveWithAttributes(partitionKey, sortKeys, indexName, queryField));
|
|
781
|
+
acc[partitionKey].push(indexDirectiveWithAttributes(partitionKey, sortKeys, indexName, queryField, projectionType, nonKeyAttributes));
|
|
772
782
|
return acc;
|
|
773
783
|
}, {});
|
|
774
784
|
};
|