Skip to content

feat(pulumi-aws): sync system input #4575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 39 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5b7be06
wip
brunozoric Mar 24, 2025
fb6e142
wip
brunozoric Mar 24, 2025
f0dd48a
wip
brunozoric Mar 26, 2025
358a6ec
wip
brunozoric Apr 7, 2025
48691bb
wip
brunozoric Apr 8, 2025
70ac343
wip(pulumi-aws): attach sync system to webiny system
brunozoric Apr 8, 2025
4535ec8
feat(pulumi-aws): attach sync system to webiny system
brunozoric Apr 9, 2025
bc1f3aa
wip(api-sync-system): begin with sync system api
brunozoric Apr 11, 2025
c000ce8
wip(api-sync-system): handler converter
brunozoric Apr 11, 2025
d5a40cf
wip(api-sync-system): command converter
brunozoric Apr 14, 2025
755f359
refactor(api-sync-system): command converter
brunozoric Apr 14, 2025
11dc7fa
wip
brunozoric Apr 17, 2025
80ae22e
wip
brunozoric Apr 22, 2025
2ba5892
refactor(api-sync-system): resolver
brunozoric Apr 24, 2025
006b91b
test(api-sync-system): wip
brunozoric Apr 25, 2025
5a61e2f
fix: use ts-jest-resolver
Pavel910 Apr 25, 2025
1142dfd
test(api-sync-system): wip
brunozoric Apr 25, 2025
c9bdf01
test(api-sync-system): wip
brunozoric Apr 28, 2025
3ef8757
test(api-sync-system): sync
brunozoric Apr 28, 2025
09b1dc8
test(api-sync-system): resolver wip
brunozoric Apr 29, 2025
49fdaa8
test(api-sync-system): resolver wip
brunozoric Apr 29, 2025
4e577ab
fix(api-sync-system): sync must send table name and type
brunozoric Apr 30, 2025
59dc5b6
wip
brunozoric May 5, 2025
b644a27
fix(api-sync-system): build
brunozoric May 15, 2025
2b9fcc0
fix(api-sync-system): build
brunozoric May 15, 2025
71dd6af
fix: sync dependencies
brunozoric May 15, 2025
efe5442
fix: sync dependencies
brunozoric May 15, 2025
3f73c57
fix(api-sync-system): tests wip
brunozoric May 15, 2025
c470cc4
test(api-sync-system): deployment
brunozoric May 15, 2025
9e0468c
test(api-sync-system): bundler
brunozoric May 15, 2025
cc39c56
test(api-sync-system): command handler
brunozoric May 16, 2025
509d40b
test(api-sync-system): data
brunozoric May 16, 2025
c10a554
test(api-sync-system): fetcher
brunozoric May 16, 2025
db913ba
test(api-sync-system): ingestor
brunozoric May 16, 2025
611d9bc
test(api-sync-system): storer
brunozoric May 19, 2025
0f57ed4
fix(cli): references
brunozoric May 19, 2025
1c7079b
test(api-sync-system): record handler
brunozoric May 20, 2025
797cdbe
fix: deploy resolver
brunozoric May 20, 2025
f9285ce
wip: resolver
brunozoric May 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/api/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@webiny/api-security-cognito": "0.0.0",
"@webiny/api-security-so-ddb": "0.0.0",
"@webiny/api-serverless-cms": "0.0.0",
"@webiny/api-sync-system": "0.0.0",
"@webiny/api-tenancy": "0.0.0",
"@webiny/api-tenancy-so-ddb": "0.0.0",
"@webiny/api-tenant-manager": "0.0.0",
Expand Down
18 changes: 18 additions & 0 deletions apps/api/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,30 @@ import { createLogger } from "@webiny/api-log";

import scaffoldsPlugins from "./plugins/scaffolds";
import { extensions } from "./extensions";
/**
* #### TESTING sync system
*/
import { createSyncSystem } from "@webiny/api-sync-system";

const debug = process.env.DEBUG === "true";
const documentClient = getDocumentClient();

const syncSystem = createSyncSystem({
documentClient,
system: {
env: process.env.WEBINY_ENV,
variant: process.env.WEBINY_ENV_VARIANT,
region: process.env.AWS_REGION,
version: process.env.WEBINY_VERSION
}
});
/**
* ####
*/

export const handler = createHandler({
plugins: [
syncSystem.plugins(),
createBenchmarkEnablePlugin(),
createWcpContext(),
createWcpGraphQL(),
Expand Down
4 changes: 3 additions & 1 deletion apps/api/graphql/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@
"@webiny/api-websockets/*": ["../../../packages/api-websockets/src/*"],
"@webiny/api-websockets": ["../../../packages/api-websockets/src"],
"@webiny/api-log/*": ["../../../packages/api-log/src/*"],
"@webiny/api-log": ["../../../packages/api-log/src"]
"@webiny/api-log": ["../../../packages/api-log/src"],
"@webiny/api-sync-system/*": ["../../../packages/api-sync-system/src/*"],
"@webiny/api-sync-system": ["../../../packages/api-sync-system/src"]
},
"baseUrl": "."
}
Expand Down
1 change: 1 addition & 0 deletions apps/sync/resolver/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@webiny/project-utils").createBabelConfigForNode({ path: __dirname });
27 changes: 27 additions & 0 deletions apps/sync/resolver/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const base = require("../../../jest.config.base");
const { log } = require("@webiny/cli/utils");
const { getStackOutput } = require("@webiny/cli-plugin-deploy-pulumi/utils");

const TEST_TYPE = process.env.TEST_TYPE;
const DEPLOY_ENVIRONMENT = "dev";

if (TEST_TYPE !== "unit") {
log.info(`${log.info.hl("apps/sync/input")}: Assigning environment variables...`);
const stackOutput = getStackOutput({ folder: "apps/sync", env: DEPLOY_ENVIRONMENT });

if (stackOutput) {
Object.assign(process.env, {
AWS_REGION: stackOutput.region,
DB_TABLE: stackOutput.dynamoDbTable,
API_URL: stackOutput.apiUrl,
TEST_RUN_ID: new Date().getTime()
});
log.success("Environment variables successfully assigned.");
} else {
log.warning(`Could not assign environment variables.`);
}
console.log();
}

// Finally, export Jest config to be used while tests are being run.
module.exports = { ...base({ path: __dirname }) };
16 changes: 16 additions & 0 deletions apps/sync/resolver/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "sync-system-resolver",
"version": "0.1.0",
"scripts": {
"build": "yarn webiny run build",
"watch": "yarn webiny run watch"
},
"dependencies": {
"@webiny/cli": "0.0.0",
"@webiny/api-sync-system": "0.0.0",
"@webiny/project-utils": "0.0.0"
},
"devDependencies": {
"@webiny/cli-plugin-deploy-pulumi": "0.0.0"
}
}
12 changes: 12 additions & 0 deletions apps/sync/resolver/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createResolverHandler } from "@webiny/api-sync-system";
import { getDocumentClient } from "@webiny/project-utils/testing/dynamodb/index.js";

const debug = process.env.DEBUG === "true";

export const handler = createResolverHandler({
plugins: [],
debug,
createDocumentClient: params => {
return getDocumentClient(params);
}
});
17 changes: 17 additions & 0 deletions apps/sync/resolver/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../../tsconfig.json",
"include": ["src"],
"references": [
{
"path": "../../../packages/api-sync-system/tsconfig.build.json"
}
],
"compilerOptions": {
"paths": {
"~/*": ["./src/*"],
"@webiny/api-sync-system/*": ["../../../packages/api-sync-system/src/*"],
"@webiny/api-sync-system": ["../../../packages/api-sync-system/src"]
},
"baseUrl": "."
}
}
8 changes: 8 additions & 0 deletions apps/sync/resolver/webiny.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createBuildFunction, createWatchFunction } from "@webiny/project-utils";

export default {
commands: {
build: createBuildFunction({ cwd: __dirname }),
watch: createWatchFunction({ cwd: __dirname })
}
};
5 changes: 5 additions & 0 deletions apps/sync/webiny.application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createSyncSystemApp } from "@webiny/serverless-cms-aws";

export default createSyncSystemApp({
pulumiResourceNamePrefix: "wby-"
});
1 change: 1 addition & 0 deletions jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = function ({ path }, presets = []) {
tsPreset,
{
displayName: name,
resolver: "ts-jest-resolver",
modulePaths: [`${path}/src`],
testMatch: [`${path}/**/*${type}.test.[jt]s?(x)`],
transform: {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@lexical/utils": "0.23.1",
"@octokit/rest": "^20.0.2",
"@types/fs-extra": "^11.0.4",
"@types/hoist-non-react-statics": "^3.3.5",
"@types/jest": "^29.5.14",
"@types/node": "^20.17.10",
"@types/prettier": "^2.7.3",
Expand Down Expand Up @@ -130,6 +131,7 @@
"semver": "^7.6.3",
"ts-expect": "^1.3.0",
"ts-jest": "29.1.5",
"ts-jest-resolver": "^2.0.1",
"ts-node": "^10.9.2",
"type-fest": "4.14.0",
"typescript": "5.3.3",
Expand Down Expand Up @@ -266,9 +268,6 @@
"@material/base@^14.0.0": "patch:@material/base@npm%3A14.0.0#./.yarn/patches/@material-base-npm-14.0.0-36e0a55c42.patch"
},
"packageManager": "[email protected]",
"dependencies": {
"@types/hoist-non-react-statics": "^3.3.5"
},
"engines": {
"node": ">=20.0.0"
}
Expand Down
1 change: 1 addition & 0 deletions packages/api-sync-system/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@webiny/project-utils").createBabelConfigForNode({ path: __dirname });
21 changes: 21 additions & 0 deletions packages/api-sync-system/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Webiny

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions packages/api-sync-system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @webiny/api-sync-system
[![](https://img.shields.io/npm/dw/@webiny/api-sync-system.svg)](https://www.npmjs.com/package/@webiny/api-sync-system)
[![](https://img.shields.io/npm/v/@webiny/api-sync-system.svg)](https://www.npmjs.com/package/@webiny/api-sync-system)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

## Install
```
yarn add @webiny/api-sync-system
```
26 changes: 26 additions & 0 deletions packages/api-sync-system/__tests__/mocks/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { CommandBundle } from "~/resolver/app/bundler/CommandBundle";
import { createMockDeployment } from "~tests/mocks/deployments.js";
import { createRegularMockTable } from "~tests/mocks/table.js";
import type { IBaseBundleParams } from "~/resolver/app/bundler/BaseBundle.js";
import { IIngestorResultItem } from "~/resolver/app/ingestor/types.js";

export interface ICreateMockBundleParams
extends Partial<Pick<IBaseBundleParams, "source" | "table">> {
items: IIngestorResultItem[];
}

export const createMockCommandPutBundle = (params: ICreateMockBundleParams) => {
return new CommandBundle({
command: "put",
source: params?.source || createMockDeployment(),
table: params?.table || createRegularMockTable()
});
};

export const createMockCommandDeleteBundle = (params: ICreateMockBundleParams) => {
return new CommandBundle({
command: "delete",
source: params?.source || createMockDeployment(),
table: params?.table || createRegularMockTable()
});
};
24 changes: 24 additions & 0 deletions packages/api-sync-system/__tests__/mocks/bundler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createBundler } from "~/resolver/app/bundler/Bundler.js";
import { createBundles } from "~/resolver/app/bundler/Bundles.js";
import { createCommandBundle } from "~/resolver/app/bundler/CommandBundle.js";
import { createTableBundle } from "~/resolver/app/bundler/TableBundle.js";

export const createMockCommandBundler = () => {
return createBundler({
createBundles: () => {
return createBundles({
createBundle: createCommandBundle
});
}
});
};

export const createMockTableBundler = () => {
return createBundler({
createBundles: () => {
return createBundles({
createBundle: createTableBundle
});
}
});
};
3 changes: 3 additions & 0 deletions packages/api-sync-system/__tests__/mocks/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const DYNAMODB_REGULAR = "regular";
export const DYNAMODB_ELASTICSEARCH = "elasticsearch";
export const DYNAMODB_LOG = "log";
32 changes: 32 additions & 0 deletions packages/api-sync-system/__tests__/mocks/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Context } from "@webiny/api/Context";
import type { Context as ContextType } from "~/types";
import type { Reply as FastifyReply, Request as FastifyRequest } from "@webiny/handler/types.js";

export const createMockContext = () => {
const request = {} as FastifyRequest;
const sent: unknown[] = [];
const send = jest.fn();

const reply = {
send: (data: unknown) => {
sent.push(data);
return send(data);
}
} as unknown as FastifyReply;
const context = new Context({
plugins: [],
WEBINY_VERSION: process.env.WEBINY_VERSION as string
}) as unknown as ContextType;

return {
context,
request,
reply,
getSent: () => {
return sent;
},
getSend: () => {
return send;
}
};
};
Loading
Loading