@aws/nx-plugin 1.0.0-rc.3 → 1.0.0-rc.4
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-THIRD-PARTY +66 -14
- package/generators.json +34 -0
- package/package.json +1 -1
- package/src/connection/generator.d.ts +1 -1
- package/src/connection/generator.js +19 -0
- package/src/connection/generator.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +70 -0
- package/src/preset/generator.d.ts +1 -1
- package/src/preset/generator.js +5 -1
- package/src/preset/generator.js.map +1 -1
- package/src/preset/schema.d.ts +1 -0
- package/src/preset/schema.json +5 -0
- package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +1502 -0
- package/src/ts/dynamodb/agent-connection/__snapshots__/generator.spec.ts.snap +45 -0
- package/src/ts/dynamodb/agent-connection/generator.d.ts +10 -0
- package/src/ts/dynamodb/agent-connection/generator.js +32 -0
- package/src/ts/dynamodb/agent-connection/generator.js.map +1 -0
- package/src/ts/dynamodb/agent-connection/schema.d.ts +14 -0
- package/src/ts/dynamodb/agent-connection/schema.json +22 -0
- package/src/ts/dynamodb/files/scripts/create-local-table.ts.template +161 -0
- package/src/ts/dynamodb/files/scripts/pull-image.ts.template +15 -0
- package/src/ts/dynamodb/files/scripts/start-container.ts.template +81 -0
- package/src/ts/dynamodb/files/src/client.ts.template +45 -0
- package/src/ts/dynamodb/files/src/constants.ts.template +9 -0
- package/src/ts/dynamodb/files/src/entities/example.ts.template +47 -0
- package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -0
- package/src/ts/dynamodb/files/src/gsi.ts.template +14 -0
- package/src/ts/dynamodb/files/src/index.ts.template +11 -0
- package/src/ts/dynamodb/generator.d.ts +10 -0
- package/src/ts/dynamodb/generator.js +108 -0
- package/src/ts/dynamodb/generator.js.map +1 -0
- package/src/ts/dynamodb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +45 -0
- package/src/ts/dynamodb/mcp-server-connection/generator.d.ts +10 -0
- package/src/ts/dynamodb/mcp-server-connection/generator.js +32 -0
- package/src/ts/dynamodb/mcp-server-connection/generator.js.map +1 -0
- package/src/ts/dynamodb/mcp-server-connection/schema.d.ts +14 -0
- package/src/ts/dynamodb/mcp-server-connection/schema.json +22 -0
- package/src/ts/dynamodb/schema.d.ts +14 -0
- package/src/ts/dynamodb/schema.json +52 -0
- package/src/ts/dynamodb/smithy-connection/__snapshots__/generator.spec.ts.snap +23 -0
- package/src/ts/dynamodb/smithy-connection/generator.d.ts +10 -0
- package/src/ts/dynamodb/smithy-connection/generator.js +30 -0
- package/src/ts/dynamodb/smithy-connection/generator.js.map +1 -0
- package/src/ts/dynamodb/smithy-connection/schema.d.ts +12 -0
- package/src/ts/dynamodb/smithy-connection/schema.json +18 -0
- package/src/ts/dynamodb/trpc-connection/__snapshots__/generator.spec.ts.snap +23 -0
- package/src/ts/dynamodb/trpc-connection/generator.d.ts +10 -0
- package/src/ts/dynamodb/trpc-connection/generator.js +30 -0
- package/src/ts/dynamodb/trpc-connection/generator.js.map +1 -0
- package/src/ts/dynamodb/trpc-connection/schema.d.ts +12 -0
- package/src/ts/dynamodb/trpc-connection/schema.json +18 -0
- package/src/utils/dynamodb-constructs/dynamodb-constructs.d.ts +18 -0
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js +57 -0
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -0
- package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +30 -0
- package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +105 -0
- package/src/utils/dynamodb-constructs/files/terraform/app/dynamodb/__nameKebabCase__/__nameKebabCase__.tf.template +65 -0
- package/src/utils/dynamodb-constructs/files/terraform/core/dynamodb/dynamodb.tf.template +155 -0
- package/src/utils/mcp.d.ts +25 -0
- package/src/utils/mcp.js +81 -0
- package/src/utils/mcp.js.map +1 -0
- package/src/utils/port.d.ts +6 -0
- package/src/utils/port.js +23 -2
- package/src/utils/port.js.map +1 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`ts#dynamodb mcp-server-connection generator > should add dynamodb serve-local dependency to mcp-server serve-local 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
6
|
+
"name": "my-mcp",
|
|
7
|
+
"root": "packages/my-mcp",
|
|
8
|
+
"targets": {
|
|
9
|
+
"mcp-server-serve-local": {
|
|
10
|
+
"continuous": true,
|
|
11
|
+
"dependsOn": [
|
|
12
|
+
{
|
|
13
|
+
"projects": [
|
|
14
|
+
"db",
|
|
15
|
+
],
|
|
16
|
+
"target": "serve-local",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
"executor": "nx:run-commands",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
exports[`ts#dynamodb mcp-server-connection generator > should use sourceComponent name when provided 1`] = `
|
|
26
|
+
{
|
|
27
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
28
|
+
"name": "my-mcp",
|
|
29
|
+
"root": "packages/my-mcp",
|
|
30
|
+
"targets": {
|
|
31
|
+
"custom-server-serve-local": {
|
|
32
|
+
"continuous": true,
|
|
33
|
+
"dependsOn": [
|
|
34
|
+
{
|
|
35
|
+
"projects": [
|
|
36
|
+
"db",
|
|
37
|
+
],
|
|
38
|
+
"target": "serve-local",
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
"executor": "nx:run-commands",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { Tree } from '@nx/devkit';
|
|
6
|
+
import { TsDynamoDBMcpServerConnectionGeneratorSchema } from './schema';
|
|
7
|
+
import { NxGeneratorInfo } from '../../../utils/nx';
|
|
8
|
+
export declare const TS_DYNAMODB_MCP_SERVER_CONNECTION_GENERATOR_INFO: NxGeneratorInfo;
|
|
9
|
+
export declare const tsDynamoDBMcpServerConnectionGenerator: (tree: Tree, options: TsDynamoDBMcpServerConnectionGeneratorSchema) => Promise<void>;
|
|
10
|
+
export default tsDynamoDBMcpServerConnectionGenerator;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tsDynamoDBMcpServerConnectionGenerator = exports.TS_DYNAMODB_MCP_SERVER_CONNECTION_GENERATOR_INFO = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
const devkit_1 = require("@nx/devkit");
|
|
9
|
+
const nx_1 = require("../../../utils/nx");
|
|
10
|
+
const metrics_1 = require("../../../utils/metrics");
|
|
11
|
+
const format_1 = require("../../../utils/format");
|
|
12
|
+
exports.TS_DYNAMODB_MCP_SERVER_CONNECTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
13
|
+
const tsDynamoDBMcpServerConnectionGenerator = async (tree, options) => {
|
|
14
|
+
const sourceProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.sourceProject);
|
|
15
|
+
const targetProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.targetProject);
|
|
16
|
+
const mcpServerName = options.sourceComponent?.name ?? 'mcp-server';
|
|
17
|
+
const serveLocalTarget = `${mcpServerName}-serve-local`;
|
|
18
|
+
if (sourceProject.targets?.[serveLocalTarget]) {
|
|
19
|
+
(0, nx_1.addDependencyToTargetIfNotPresent)(sourceProject, serveLocalTarget, {
|
|
20
|
+
projects: [targetProject.name],
|
|
21
|
+
target: 'serve-local',
|
|
22
|
+
});
|
|
23
|
+
(0, devkit_1.updateProjectConfiguration)(tree, sourceProject.name, sourceProject);
|
|
24
|
+
}
|
|
25
|
+
await (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [
|
|
26
|
+
exports.TS_DYNAMODB_MCP_SERVER_CONNECTION_GENERATOR_INFO,
|
|
27
|
+
]);
|
|
28
|
+
await (0, format_1.formatFilesInSubtree)(tree);
|
|
29
|
+
};
|
|
30
|
+
exports.tsDynamoDBMcpServerConnectionGenerator = tsDynamoDBMcpServerConnectionGenerator;
|
|
31
|
+
exports.default = exports.tsDynamoDBMcpServerConnectionGenerator;
|
|
32
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/dynamodb/mcp-server-connection/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAA8D;AAE9D,0CAK2B;AAC3B,oDAAyE;AACzE,kDAA6D;AAEhD,QAAA,gDAAgD,GAC3D,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,sCAAsC,GAAG,KAAK,EACzD,IAAU,EACV,OAAqD,EACtC,EAAE;IACjB,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IACF,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IAEF,MAAM,aAAa,GAAG,OAAO,CAAC,eAAe,EAAE,IAAI,IAAI,YAAY,CAAC;IACpE,MAAM,gBAAgB,GAAG,GAAG,aAAa,cAAc,CAAC;IAExD,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC9C,IAAA,sCAAiC,EAAC,aAAa,EAAE,gBAAgB,EAAE;YACjE,QAAQ,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC;YAC9B,MAAM,EAAE,aAAa;SACtB,CAAC,CAAC;QACH,IAAA,mCAA0B,EAAC,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE;QAC1C,wDAAgD;KACjD,CAAC,CAAC;IACH,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC;AA5BW,QAAA,sCAAsC,0CA4BjD;AAEF,kBAAe,8CAAsC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { ComponentMetadata } from '../../../utils/nx';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TypeScript types for options defined in schema.json
|
|
9
|
+
*/
|
|
10
|
+
export interface TsDynamoDBMcpServerConnectionGeneratorSchema {
|
|
11
|
+
sourceProject: string;
|
|
12
|
+
targetProject: string;
|
|
13
|
+
sourceComponent?: ComponentMetadata;
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#dynamodb#mcp-server-connection",
|
|
4
|
+
"title": "ts#dynamodb#mcp-server-connection",
|
|
5
|
+
"description": "Connect a ts#mcp-server to a ts#dynamodb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The project containing the ts#mcp-server to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The ts#dynamodb project to connect to"
|
|
15
|
+
},
|
|
16
|
+
"sourceComponent": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "The MCP server component name"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": ["sourceProject", "targetProject"]
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { IacOption } from '../../utils/iac';
|
|
6
|
+
|
|
7
|
+
export interface TsDynamoDBGeneratorSchema {
|
|
8
|
+
name: string;
|
|
9
|
+
directory?: string;
|
|
10
|
+
subDirectory?: string;
|
|
11
|
+
tableName?: string;
|
|
12
|
+
infra: 'dynamodb' | 'none';
|
|
13
|
+
iac: IacOption;
|
|
14
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#dynamodb",
|
|
4
|
+
"title": "ts#dynamodb",
|
|
5
|
+
"description": "Create a DynamoDB project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Name of the DynamoDB project to generate",
|
|
11
|
+
"$default": {
|
|
12
|
+
"$source": "argv",
|
|
13
|
+
"index": 0
|
|
14
|
+
},
|
|
15
|
+
"x-priority": "important",
|
|
16
|
+
"x-prompt": "What name would you like your DynamoDB project to have? i.e: MyTable"
|
|
17
|
+
},
|
|
18
|
+
"directory": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The directory to store the project in.",
|
|
21
|
+
"default": "packages",
|
|
22
|
+
"x-priority": "important",
|
|
23
|
+
"x-prompt": "Which directory do you want to create the project in?"
|
|
24
|
+
},
|
|
25
|
+
"subDirectory": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "The sub directory the project is placed in. By default this is the project name.",
|
|
28
|
+
"x-prompt": "Which sub directory do you want to create the project in? (By default this is the project name)"
|
|
29
|
+
},
|
|
30
|
+
"tableName": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"description": "The DynamoDB table name. Defaults to the project name."
|
|
33
|
+
},
|
|
34
|
+
"infra": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"enum": ["dynamodb", "none"],
|
|
37
|
+
"default": "dynamodb",
|
|
38
|
+
"description": "Infrastructure to provision for the DynamoDB table.",
|
|
39
|
+
"x-priority": "important",
|
|
40
|
+
"x-prompt": "Which infrastructure would you like to provision?"
|
|
41
|
+
},
|
|
42
|
+
"iac": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"description": "The preferred IaC provider. By default this is inherited from your initial selection.",
|
|
45
|
+
"enum": ["inherit", "cdk", "terraform"],
|
|
46
|
+
"x-priority": "important",
|
|
47
|
+
"default": "inherit",
|
|
48
|
+
"x-prompt": "Which provider would you like to manage your infrastructure? (default: Inherit)"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"required": ["name"]
|
|
52
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`ts#dynamodb smithy-connection generator > should add dynamodb serve-local dependency to smithy serve-local 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
6
|
+
"name": "api",
|
|
7
|
+
"root": "packages/api",
|
|
8
|
+
"targets": {
|
|
9
|
+
"serve-local": {
|
|
10
|
+
"continuous": true,
|
|
11
|
+
"dependsOn": [
|
|
12
|
+
{
|
|
13
|
+
"projects": [
|
|
14
|
+
"db",
|
|
15
|
+
],
|
|
16
|
+
"target": "serve-local",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
"executor": "nx:run-commands",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { Tree } from '@nx/devkit';
|
|
6
|
+
import { TsDynamoDBSmithyConnectionGeneratorSchema } from './schema';
|
|
7
|
+
import { NxGeneratorInfo } from '../../../utils/nx';
|
|
8
|
+
export declare const TS_DYNAMODB_SMITHY_CONNECTION_GENERATOR_INFO: NxGeneratorInfo;
|
|
9
|
+
export declare const tsDynamoDBSmithyConnectionGenerator: (tree: Tree, options: TsDynamoDBSmithyConnectionGeneratorSchema) => Promise<void>;
|
|
10
|
+
export default tsDynamoDBSmithyConnectionGenerator;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tsDynamoDBSmithyConnectionGenerator = exports.TS_DYNAMODB_SMITHY_CONNECTION_GENERATOR_INFO = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
const devkit_1 = require("@nx/devkit");
|
|
9
|
+
const nx_1 = require("../../../utils/nx");
|
|
10
|
+
const metrics_1 = require("../../../utils/metrics");
|
|
11
|
+
const format_1 = require("../../../utils/format");
|
|
12
|
+
exports.TS_DYNAMODB_SMITHY_CONNECTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
13
|
+
const tsDynamoDBSmithyConnectionGenerator = async (tree, options) => {
|
|
14
|
+
const sourceProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.sourceProject);
|
|
15
|
+
const targetProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.targetProject);
|
|
16
|
+
if (sourceProject.targets?.['serve-local']) {
|
|
17
|
+
(0, nx_1.addDependencyToTargetIfNotPresent)(sourceProject, 'serve-local', {
|
|
18
|
+
projects: [targetProject.name],
|
|
19
|
+
target: 'serve-local',
|
|
20
|
+
});
|
|
21
|
+
(0, devkit_1.updateProjectConfiguration)(tree, sourceProject.name, sourceProject);
|
|
22
|
+
}
|
|
23
|
+
await (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [
|
|
24
|
+
exports.TS_DYNAMODB_SMITHY_CONNECTION_GENERATOR_INFO,
|
|
25
|
+
]);
|
|
26
|
+
await (0, format_1.formatFilesInSubtree)(tree);
|
|
27
|
+
};
|
|
28
|
+
exports.tsDynamoDBSmithyConnectionGenerator = tsDynamoDBSmithyConnectionGenerator;
|
|
29
|
+
exports.default = exports.tsDynamoDBSmithyConnectionGenerator;
|
|
30
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/dynamodb/smithy-connection/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAA8D;AAE9D,0CAK2B;AAC3B,oDAAyE;AACzE,kDAA6D;AAEhD,QAAA,4CAA4C,GACvD,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,mCAAmC,GAAG,KAAK,EACtD,IAAU,EACV,OAAkD,EACnC,EAAE;IACjB,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IACF,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IAEF,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3C,IAAA,sCAAiC,EAAC,aAAa,EAAE,aAAa,EAAE;YAC9D,QAAQ,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC;YAC9B,MAAM,EAAE,aAAa;SACtB,CAAC,CAAC;QACH,IAAA,mCAA0B,EAAC,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE;QAC1C,oDAA4C;KAC7C,CAAC,CAAC;IACH,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC;AAzBW,QAAA,mCAAmC,uCAyB9C;AAEF,kBAAe,2CAAmC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TypeScript types for options defined in schema.json
|
|
8
|
+
*/
|
|
9
|
+
export interface TsDynamoDBSmithyConnectionGeneratorSchema {
|
|
10
|
+
sourceProject: string;
|
|
11
|
+
targetProject: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#dynamodb#smithy-connection",
|
|
4
|
+
"title": "ts#dynamodb#smithy-connection",
|
|
5
|
+
"description": "Connect a Smithy backend to a ts#dynamodb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The Smithy backend project to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The ts#dynamodb project to connect to"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"required": ["sourceProject", "targetProject"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`ts#dynamodb trpc-connection generator > should add dynamodb serve-local dependency to trpc serve-local 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
6
|
+
"name": "api",
|
|
7
|
+
"root": "packages/api",
|
|
8
|
+
"targets": {
|
|
9
|
+
"serve-local": {
|
|
10
|
+
"continuous": true,
|
|
11
|
+
"dependsOn": [
|
|
12
|
+
{
|
|
13
|
+
"projects": [
|
|
14
|
+
"db",
|
|
15
|
+
],
|
|
16
|
+
"target": "serve-local",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
"executor": "nx:run-commands",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { Tree } from '@nx/devkit';
|
|
6
|
+
import { TsDynamoDBTrpcConnectionGeneratorSchema } from './schema';
|
|
7
|
+
import { NxGeneratorInfo } from '../../../utils/nx';
|
|
8
|
+
export declare const TS_DYNAMODB_TRPC_CONNECTION_GENERATOR_INFO: NxGeneratorInfo;
|
|
9
|
+
export declare const tsDynamoDBTrpcConnectionGenerator: (tree: Tree, options: TsDynamoDBTrpcConnectionGeneratorSchema) => Promise<void>;
|
|
10
|
+
export default tsDynamoDBTrpcConnectionGenerator;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tsDynamoDBTrpcConnectionGenerator = exports.TS_DYNAMODB_TRPC_CONNECTION_GENERATOR_INFO = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
const devkit_1 = require("@nx/devkit");
|
|
9
|
+
const nx_1 = require("../../../utils/nx");
|
|
10
|
+
const metrics_1 = require("../../../utils/metrics");
|
|
11
|
+
const format_1 = require("../../../utils/format");
|
|
12
|
+
exports.TS_DYNAMODB_TRPC_CONNECTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
13
|
+
const tsDynamoDBTrpcConnectionGenerator = async (tree, options) => {
|
|
14
|
+
const sourceProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.sourceProject);
|
|
15
|
+
const targetProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.targetProject);
|
|
16
|
+
if (sourceProject.targets?.['serve-local']) {
|
|
17
|
+
(0, nx_1.addDependencyToTargetIfNotPresent)(sourceProject, 'serve-local', {
|
|
18
|
+
projects: [targetProject.name],
|
|
19
|
+
target: 'serve-local',
|
|
20
|
+
});
|
|
21
|
+
(0, devkit_1.updateProjectConfiguration)(tree, sourceProject.name, sourceProject);
|
|
22
|
+
}
|
|
23
|
+
await (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [
|
|
24
|
+
exports.TS_DYNAMODB_TRPC_CONNECTION_GENERATOR_INFO,
|
|
25
|
+
]);
|
|
26
|
+
await (0, format_1.formatFilesInSubtree)(tree);
|
|
27
|
+
};
|
|
28
|
+
exports.tsDynamoDBTrpcConnectionGenerator = tsDynamoDBTrpcConnectionGenerator;
|
|
29
|
+
exports.default = exports.tsDynamoDBTrpcConnectionGenerator;
|
|
30
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/dynamodb/trpc-connection/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAA8D;AAE9D,0CAK2B;AAC3B,oDAAyE;AACzE,kDAA6D;AAEhD,QAAA,0CAA0C,GACrD,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,iCAAiC,GAAG,KAAK,EACpD,IAAU,EACV,OAAgD,EACjC,EAAE;IACjB,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IACF,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IAEF,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3C,IAAA,sCAAiC,EAAC,aAAa,EAAE,aAAa,EAAE;YAC9D,QAAQ,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC;YAC9B,MAAM,EAAE,aAAa;SACtB,CAAC,CAAC;QACH,IAAA,mCAA0B,EAAC,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE;QAC1C,kDAA0C;KAC3C,CAAC,CAAC;IACH,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC;AAzBW,QAAA,iCAAiC,qCAyB5C;AAEF,kBAAe,yCAAiC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TypeScript types for options defined in schema.json
|
|
8
|
+
*/
|
|
9
|
+
export interface TsDynamoDBTrpcConnectionGeneratorSchema {
|
|
10
|
+
sourceProject: string;
|
|
11
|
+
targetProject: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#dynamodb#trpc-connection",
|
|
4
|
+
"title": "ts#dynamodb#trpc-connection",
|
|
5
|
+
"description": "Connect a ts#trpc-api project to a ts#dynamodb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The ts#trpc-api project to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The ts#dynamodb project to connect to"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"required": ["sourceProject", "targetProject"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { Tree } from '@nx/devkit';
|
|
6
|
+
import { Iac } from '../iac';
|
|
7
|
+
export interface AddDynamoDBConstructOptions {
|
|
8
|
+
projectName: string;
|
|
9
|
+
nameClassName: string;
|
|
10
|
+
nameKebabCase: string;
|
|
11
|
+
dynamoPackageAlias: string;
|
|
12
|
+
tableName: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const addDynamoDBInfra: (tree: Tree, options: AddDynamoDBConstructOptions & {
|
|
15
|
+
iac: Iac;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
export declare const addDynamoDBCdkConstructs: (tree: Tree, options: AddDynamoDBConstructOptions) => Promise<void>;
|
|
18
|
+
export declare const addDynamoDBTerraformModules: (tree: Tree, options: AddDynamoDBConstructOptions) => void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addDynamoDBTerraformModules = exports.addDynamoDBCdkConstructs = exports.addDynamoDBInfra = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
const devkit_1 = require("@nx/devkit");
|
|
9
|
+
const shared_constructs_constants_1 = require("../shared-constructs-constants");
|
|
10
|
+
const ast_1 = require("../ast");
|
|
11
|
+
const addDynamoDBInfra = async (tree, options) => {
|
|
12
|
+
if (options.iac === 'cdk') {
|
|
13
|
+
await (0, exports.addDynamoDBCdkConstructs)(tree, options);
|
|
14
|
+
}
|
|
15
|
+
else if (options.iac === 'terraform') {
|
|
16
|
+
(0, exports.addDynamoDBTerraformModules)(tree, options);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new Error(`Unsupported iac ${options.iac}`);
|
|
20
|
+
}
|
|
21
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, options.iac === 'cdk' ? shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR : shared_constructs_constants_1.SHARED_TERRAFORM_DIR, 'project.json'), (config) => {
|
|
22
|
+
if (!config.targets) {
|
|
23
|
+
config.targets = {};
|
|
24
|
+
}
|
|
25
|
+
if (!config.targets.build) {
|
|
26
|
+
config.targets.build = {};
|
|
27
|
+
}
|
|
28
|
+
config.targets.build.dependsOn = [
|
|
29
|
+
...(config.targets.build.dependsOn ?? []),
|
|
30
|
+
`${options.projectName}:build`,
|
|
31
|
+
];
|
|
32
|
+
return config;
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.addDynamoDBInfra = addDynamoDBInfra;
|
|
36
|
+
const addDynamoDBCdkConstructs = async (tree, options) => {
|
|
37
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'cdk', 'core'), (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'core'), options, {
|
|
38
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
39
|
+
});
|
|
40
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'cdk', 'app', 'dynamodb'), (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'dynamodb'), options, {
|
|
41
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
42
|
+
});
|
|
43
|
+
await (0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'core', 'index.ts'), './dynamodb.js');
|
|
44
|
+
await (0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'dynamodb', 'index.ts'), `./${options.nameKebabCase}.js`);
|
|
45
|
+
await (0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'index.ts'), './dynamodb/index.js');
|
|
46
|
+
};
|
|
47
|
+
exports.addDynamoDBCdkConstructs = addDynamoDBCdkConstructs;
|
|
48
|
+
const addDynamoDBTerraformModules = (tree, options) => {
|
|
49
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'terraform', 'core'), (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_TERRAFORM_DIR, 'src', 'core'), options, {
|
|
50
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
51
|
+
});
|
|
52
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'terraform', 'app', 'dynamodb'), (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_TERRAFORM_DIR, 'src', 'app', 'dynamodb'), options, {
|
|
53
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
exports.addDynamoDBTerraformModules = addDynamoDBTerraformModules;
|
|
57
|
+
//# sourceMappingURL=dynamodb-constructs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamodb-constructs.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/dynamodb-constructs/dynamodb-constructs.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { PACKAGE_NAME, GLOBAL_SECONDARY_INDEXES } from '<%= dynamoPackageAlias %>';
|
|
3
|
+
import { AttributeType, ProjectionType } from 'aws-cdk-lib/aws-dynamodb';
|
|
4
|
+
import {
|
|
5
|
+
DynamoDBTable,
|
|
6
|
+
DynamoDBTableProps,
|
|
7
|
+
} from '../../core/dynamodb.js';
|
|
8
|
+
|
|
9
|
+
export type <%= nameClassName %>Props = Omit<
|
|
10
|
+
DynamoDBTableProps,
|
|
11
|
+
'runtimeConfigKey'
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
export class <%= nameClassName %> extends DynamoDBTable {
|
|
15
|
+
constructor(scope: Construct, id: string, props?: <%= nameClassName %>Props) {
|
|
16
|
+
super(scope, id, {
|
|
17
|
+
...props,
|
|
18
|
+
runtimeConfigKey: PACKAGE_NAME,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
for (const gsi of GLOBAL_SECONDARY_INDEXES) {
|
|
22
|
+
this.table.addGlobalSecondaryIndex({
|
|
23
|
+
indexName: gsi.indexName,
|
|
24
|
+
partitionKey: { name: gsi.partitionKey, type: AttributeType.STRING },
|
|
25
|
+
sortKey: { name: gsi.sortKey, type: AttributeType.STRING },
|
|
26
|
+
projectionType: ProjectionType.ALL,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import {
|
|
3
|
+
AttributeType,
|
|
4
|
+
BillingMode,
|
|
5
|
+
Table,
|
|
6
|
+
TableEncryption,
|
|
7
|
+
TableProps,
|
|
8
|
+
} from 'aws-cdk-lib/aws-dynamodb';
|
|
9
|
+
import { RemovalPolicy } from 'aws-cdk-lib';
|
|
10
|
+
import { Grant, IGrantable } from 'aws-cdk-lib/aws-iam';
|
|
11
|
+
import { Key } from 'aws-cdk-lib/aws-kms';
|
|
12
|
+
import { RuntimeConfig } from './runtime-config.js';
|
|
13
|
+
|
|
14
|
+
type _DynamoDBTableProps = Omit<TableProps, 'tableName' | 'partitionKey' | 'sortKey' | 'encryption' | 'encryptionKey'>;
|
|
15
|
+
|
|
16
|
+
export interface DynamoDBTableProps extends _DynamoDBTableProps {
|
|
17
|
+
/**
|
|
18
|
+
* The DynamoDB table name. If omitted, CDK auto-generates a unique name
|
|
19
|
+
* from the stack name and construct path.
|
|
20
|
+
*/
|
|
21
|
+
readonly tableName?: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* RuntimeConfig key used under the `dynamodb` namespace.
|
|
25
|
+
*/
|
|
26
|
+
readonly runtimeConfigKey: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Whether to enable automatic key rotation on the KMS key used to encrypt the table.
|
|
30
|
+
*
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
readonly enableKeyRotation?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export abstract class DynamoDBTable extends Construct {
|
|
37
|
+
public readonly table: Table;
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
scope: Construct,
|
|
41
|
+
id: string,
|
|
42
|
+
{
|
|
43
|
+
tableName,
|
|
44
|
+
runtimeConfigKey,
|
|
45
|
+
billingMode = BillingMode.PAY_PER_REQUEST,
|
|
46
|
+
pointInTimeRecoverySpecification = { pointInTimeRecoveryEnabled: true },
|
|
47
|
+
deletionProtection = true,
|
|
48
|
+
removalPolicy = RemovalPolicy.RETAIN,
|
|
49
|
+
enableKeyRotation = true,
|
|
50
|
+
...rest
|
|
51
|
+
}: DynamoDBTableProps,
|
|
52
|
+
) {
|
|
53
|
+
super(scope, id);
|
|
54
|
+
|
|
55
|
+
const key = new Key(this, 'EncryptionKey', { enableKeyRotation });
|
|
56
|
+
|
|
57
|
+
this.table = new Table(this, runtimeConfigKey, {
|
|
58
|
+
...rest,
|
|
59
|
+
...(tableName !== undefined && { tableName }),
|
|
60
|
+
partitionKey: { name: 'pk', type: AttributeType.STRING },
|
|
61
|
+
sortKey: { name: 'sk', type: AttributeType.STRING },
|
|
62
|
+
billingMode,
|
|
63
|
+
pointInTimeRecoverySpecification,
|
|
64
|
+
deletionProtection,
|
|
65
|
+
encryptionKey: key,
|
|
66
|
+
encryption: TableEncryption.CUSTOMER_MANAGED,
|
|
67
|
+
removalPolicy,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const rc = RuntimeConfig.ensure(this);
|
|
71
|
+
rc.set('dynamodb', runtimeConfigKey, { tableName: this.table.tableName });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public grantReadData(grantee: IGrantable): Grant {
|
|
75
|
+
return this.table.grantReadData(grantee);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public grantWriteData(grantee: IGrantable): Grant {
|
|
79
|
+
return this.table.grantWriteData(grantee);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public grantReadWriteData(grantee: IGrantable): Grant {
|
|
83
|
+
return this.table.grantReadWriteData(grantee);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public grantFullAccess(grantee: IGrantable): Grant {
|
|
87
|
+
return this.table.grantFullAccess(grantee);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public grantStreamRead(grantee: IGrantable): Grant {
|
|
91
|
+
return this.table.grantStreamRead(grantee);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public grantTableListStreams(grantee: IGrantable): Grant {
|
|
95
|
+
return this.table.grantTableListStreams(grantee);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public grant(grantee: IGrantable, ...actions: string[]): Grant {
|
|
99
|
+
return this.table.grant(grantee, ...actions);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public grantStream(grantee: IGrantable, ...actions: string[]): Grant {
|
|
103
|
+
return this.table.grantStream(grantee, ...actions);
|
|
104
|
+
}
|
|
105
|
+
}
|