@kensio/yulin 0.1.0 → 0.1.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 (57) hide show
  1. package/dist/service/cloudfront/factory/cloudfront-functions.factory.d.ts +4 -4
  2. package/dist/service/cloudfront/factory/cloudfront-functions.factory.d.ts.map +1 -1
  3. package/dist/service/cloudfront/factory/cloudfront-functions.factory.js +27 -6
  4. package/dist/service/cloudfront/factory/cloudfront-functions.factory.js.map +1 -1
  5. package/dist/service/cloudfront/index.d.ts +1 -1
  6. package/dist/service/cloudfront/index.d.ts.map +1 -1
  7. package/dist/service/cloudfront/index.js +1 -1
  8. package/dist/service/cloudfront/index.js.map +1 -1
  9. package/package.json +7 -1
  10. package/.github/workflows/pr.yml +0 -54
  11. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  12. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  13. package/.idea/jsLinters/eslint.xml +0 -6
  14. package/.idea/modules.xml +0 -8
  15. package/.idea/prettier.xml +0 -7
  16. package/.idea/vcs.xml +0 -6
  17. package/.idea/yulin.iml +0 -8
  18. package/.nvmrc +0 -1
  19. package/.prettierrc +0 -4
  20. package/eslint.config.ts +0 -222
  21. package/pnpm-workspace.yaml +0 -23
  22. package/scripts/publish.sh +0 -14
  23. package/src/command/command-handler.ts +0 -3
  24. package/src/index.ts +0 -0
  25. package/src/service/cloudfront/factory/cloudfront-functions.factory.iso.test.ts +0 -10
  26. package/src/service/cloudfront/factory/cloudfront-functions.factory.ts +0 -34
  27. package/src/service/cloudfront/index.ts +0 -13
  28. package/src/service/cloudfront/typings/cloudfront-functions.ts +0 -48
  29. package/src/service/dynamodb/command/create-table/create-table.handler.ts +0 -61
  30. package/src/service/dynamodb/command/create-table/create-table.iso.test.ts +0 -99
  31. package/src/service/dynamodb/command/describe-table/describe-table.handler.ts +0 -52
  32. package/src/service/dynamodb/command/describe-table/describe-table.iso.test.ts +0 -82
  33. package/src/service/dynamodb/command/list-tables/list-tables.handler.ts +0 -53
  34. package/src/service/dynamodb/command/list-tables/list-tables.iso.test.ts +0 -119
  35. package/src/service/dynamodb/command/put-item/put-item.handler.ts +0 -56
  36. package/src/service/dynamodb/command/put-item/put-item.iso.test.ts +0 -354
  37. package/src/service/dynamodb/dynamodb.ts +0 -60
  38. package/src/service/dynamodb/index.ts +0 -0
  39. package/src/service/dynamodb/item/dynamodb-item-attribute.iso.test.ts +0 -19
  40. package/src/service/dynamodb/item/dynamodb-item-attribute.ts +0 -116
  41. package/src/service/dynamodb/item/dynamodb-item.ts +0 -39
  42. package/src/service/dynamodb/table/dynamodb-key-schema.ts +0 -94
  43. package/src/service/dynamodb/table/dynamodb-table.iso.test.ts +0 -46
  44. package/src/service/dynamodb/table/dynamodb-table.ts +0 -75
  45. package/src/service/organizations/index.ts +0 -0
  46. package/src/service/organizations/sim-aws-account.ts +0 -36
  47. package/src/service/s3/index.ts +0 -1
  48. package/src/util/background/background.iso.test.ts +0 -74
  49. package/src/util/background/background.ts +0 -62
  50. package/src/util/brand.type.ts +0 -11
  51. package/src/util/defined.ts +0 -15
  52. package/src/util/memo/memo.iso.test.ts +0 -43
  53. package/src/util/memo/memo.ts +0 -26
  54. package/src/util/sleep.ts +0 -16
  55. package/tsconfig.build.json +0 -13
  56. package/tsconfig.json +0 -39
  57. package/vitest.config.ts +0 -50
@@ -1,46 +0,0 @@
1
- import { describe, it } from "vitest";
2
- import { CreateTableCommand } from "@aws-sdk/client-dynamodb";
3
- import { SimDynamoDbTable } from "./dynamodb-table.js";
4
- import {
5
- assertIdentical,
6
- assertInstanceOf,
7
- assertThrowsError,
8
- } from "@kensio/smartass";
9
- import { BackgroundTasks } from "../../../util/background/background.js";
10
-
11
- describe("SimDynamoDbTable", () => {
12
- it("throws when TableName is undefined", () => {
13
- const command = new CreateTableCommand({ TableName: undefined });
14
-
15
- assertThrowsError(
16
- () => new SimDynamoDbTable(command, new BackgroundTasks()),
17
- );
18
- });
19
-
20
- it("creates table with CREATING status", () => {
21
- const command = new CreateTableCommand({
22
- TableName: "test-table",
23
- KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
24
- });
25
-
26
- const table = new SimDynamoDbTable(command, new BackgroundTasks());
27
-
28
- assertIdentical(table.tableName, "test-table");
29
- assertIdentical(table.status, "CREATING");
30
- assertInstanceOf(table.creationDateTime, Date);
31
- });
32
-
33
- it("activates table", async () => {
34
- const command = new CreateTableCommand({
35
- TableName: "test-table",
36
- KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
37
- });
38
-
39
- const table = new SimDynamoDbTable(command, new BackgroundTasks());
40
- assertIdentical(table.status, "CREATING");
41
-
42
- await table.activate();
43
-
44
- assertIdentical(table.status, "ACTIVE");
45
- });
46
- });
@@ -1,75 +0,0 @@
1
- import type { Brand } from "../../../util/brand.type.js";
2
- import type { CreateTableCommand, TableStatus } from "@aws-sdk/client-dynamodb";
3
- import { DynamoDbKeySchema } from "./dynamodb-key-schema.js";
4
- import { assertDefined } from "../../../util/defined.js";
5
- import type { DynamoDbItem } from "../item/dynamodb-item.js";
6
- import type { BackgroundScheduler } from "../../../util/background/background.js";
7
-
8
- export type DynamoDbTableName = Brand<string, "DynamoDbTableName">;
9
-
10
- /**
11
- * Simulated DynamoDB Table.
12
- */
13
- export class SimDynamoDbTable {
14
- public readonly creationDateTime: Date;
15
-
16
- private readonly _tableName: DynamoDbTableName;
17
- private readonly _keySchema: DynamoDbKeySchema;
18
- private _status: TableStatus = "CREATING";
19
-
20
- private readonly items = new Map<string, DynamoDbItem>();
21
-
22
- constructor(
23
- createCommand: CreateTableCommand,
24
- private readonly background: BackgroundScheduler,
25
- ) {
26
- assertDefined(
27
- createCommand.input.TableName,
28
- "createCommand.input.TableName",
29
- );
30
- this._tableName = createCommand.input.TableName as DynamoDbTableName;
31
- this.creationDateTime = new Date();
32
-
33
- if (
34
- createCommand.input.KeySchema === undefined ||
35
- createCommand.input.KeySchema.length === 0
36
- ) {
37
- throw new Error("Table KeySchema is not defined");
38
- }
39
- this._keySchema = new DynamoDbKeySchema(createCommand.input);
40
- }
41
-
42
- /**
43
- * Simulate the table entering ACTIVE status.
44
- */
45
- activate(): Promise<void> {
46
- this._status = "ACTIVE";
47
- return Promise.resolve();
48
- }
49
-
50
- /**
51
- * Get the DynamoDB table name.
52
- */
53
- public get tableName(): DynamoDbTableName {
54
- return this._tableName;
55
- }
56
-
57
- /**
58
- * Get the current table status.
59
- */
60
- public get status(): TableStatus {
61
- return this._status;
62
- }
63
-
64
- /**
65
- * Put an item into the table.
66
- */
67
- public putItem(item: DynamoDbItem): Promise<void> {
68
- const keyString = this._keySchema.makeItemKey(item);
69
- this.background.schedule(() => {
70
- this.items.set(keyString, item);
71
- return Promise.resolve();
72
- });
73
- return Promise.resolve();
74
- }
75
- }
File without changes
@@ -1,36 +0,0 @@
1
- import {
2
- type BackgroundCompleter,
3
- type BackgroundScheduler,
4
- BackgroundTasks,
5
- } from "../../util/background/background.js";
6
- import { SimDynamoDb } from "../dynamodb/dynamodb.js";
7
- import { Memo } from "../../util/memo/memo.js";
8
-
9
- /**
10
- * Container for simulated AWS services.
11
- */
12
- export class SimAwsAccount {
13
- private readonly memo = new Memo<object>();
14
-
15
- constructor(
16
- private readonly background: BackgroundScheduler &
17
- BackgroundCompleter = new BackgroundTasks(),
18
- ) {}
19
-
20
- /**
21
- * Wait for all outstanding background tasks in this Account to complete.
22
- */
23
- async backgroundTasksComplete(): Promise<void> {
24
- await this.background.complete();
25
- }
26
-
27
- /**
28
- * Get the simulated DynamoDB service in this simulated Account.
29
- */
30
- getDynamoDb(): SimDynamoDb {
31
- return this.memo.getOrCreate(
32
- "DynamoDB",
33
- () => new SimDynamoDb(this.background),
34
- );
35
- }
36
- }
@@ -1 +0,0 @@
1
- //
@@ -1,74 +0,0 @@
1
- import { describe, it } from "vitest";
2
- import { BackgroundTasks } from "./background.js";
3
- import {
4
- assertFalse,
5
- assertIdentical,
6
- assertThrowsErrorAsync,
7
- assertTrue,
8
- } from "@kensio/smartass";
9
-
10
- describe("BackgroundTasks", () => {
11
- it("executes scheduled tasks", async () => {
12
- const tasks = new BackgroundTasks();
13
- let executed = false;
14
-
15
- tasks.schedule(async () => {
16
- await Promise.resolve();
17
- executed = true;
18
- });
19
-
20
- assertFalse(executed);
21
- await tasks.complete();
22
- assertTrue(executed);
23
- });
24
-
25
- it("tracks pending task count", async () => {
26
- const tasks = new BackgroundTasks();
27
-
28
- assertIdentical(tasks.size, 0);
29
-
30
- tasks.schedule(async () => {
31
- /* empty */
32
- });
33
- tasks.schedule(async () => {
34
- /* empty */
35
- });
36
- tasks.schedule(async () => {
37
- /* empty */
38
- });
39
-
40
- assertIdentical(tasks.size, 3);
41
- await tasks.complete();
42
- assertIdentical(tasks.size, 0);
43
- });
44
-
45
- it("handles tasks that schedule more tasks", async () => {
46
- const tasks = new BackgroundTasks();
47
- const execOrder: number[] = [];
48
-
49
- tasks.schedule(async () => {
50
- await Promise.resolve();
51
- execOrder.push(1);
52
- tasks.schedule(async () => {
53
- await Promise.resolve();
54
- execOrder.push(2);
55
- });
56
- });
57
-
58
- await tasks.complete();
59
- assertIdentical(execOrder.length, 2);
60
- assertIdentical(execOrder[0], 1);
61
- assertIdentical(execOrder[1], 2);
62
- });
63
-
64
- it("propagates task errors", async () => {
65
- const tasks = new BackgroundTasks();
66
-
67
- tasks.schedule(async () => {
68
- await Promise.resolve();
69
- throw new Error("Task failed");
70
- });
71
-
72
- await assertThrowsErrorAsync(async () => tasks.complete());
73
- });
74
- });
@@ -1,62 +0,0 @@
1
- export type BackgroundTask = () => Promise<void>;
2
-
3
- export interface BackgroundScheduler {
4
- schedule(task: BackgroundTask): void;
5
- }
6
-
7
- export interface BackgroundCompleter {
8
- complete(): Promise<void>;
9
- }
10
-
11
- /**
12
- * Simple async background tasks scheduler, to simulate asynchronous distributed
13
- * operations occurring in a non-deterministic sequence.
14
- */
15
- export class BackgroundTasks
16
- implements BackgroundScheduler, BackgroundCompleter
17
- {
18
- private readonly pending = new Set<Promise<void>>();
19
-
20
- /**
21
- * Schedule a task to happen asynchronously in the background.
22
- */
23
- schedule(task: BackgroundTask): void {
24
- const promise = new Promise<void>((resolve) => {
25
- setTimeout(resolve, Math.random());
26
- })
27
- .then(task)
28
- .then(
29
- () => {
30
- //
31
- },
32
- (error: unknown) => {
33
- // Keep the promise rejected so drain() can surface failures
34
- // deterministically.
35
- throw error;
36
- },
37
- )
38
- .finally(() => {
39
- this.pending.delete(promise);
40
- });
41
-
42
- this.pending.add(promise);
43
- }
44
-
45
- /**
46
- * Wait until all tasks currently scheduled have finished.
47
- * If tasks schedule more tasks, this will continue draining until idle.
48
- */
49
- public async complete(): Promise<void> {
50
- while (this.pending.size > 0) {
51
- // eslint-disable-next-line no-await-in-loop
52
- await Promise.all(this.pending);
53
- }
54
- }
55
-
56
- /**
57
- * See how many outstanding background tasks are scheduled.
58
- */
59
- public get size(): number {
60
- return this.pending.size;
61
- }
62
- }
@@ -1,11 +0,0 @@
1
- export type Brand<K, T extends string> = K & Record<T, never>;
2
-
3
- export type ISODateString = Brand<
4
- `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`,
5
- "ISODateString"
6
- >;
7
- declare global {
8
- interface Date {
9
- toISOString(): ISODateString;
10
- }
11
- }
@@ -1,15 +0,0 @@
1
- class RequiredValueUndefinedError extends Error {
2
- //
3
- }
4
-
5
- /**
6
- * Require that a given value is defined.
7
- */
8
- export function assertDefined<T>(
9
- value: T | undefined,
10
- description: string,
11
- ): asserts value is T {
12
- if (value === undefined) {
13
- throw new RequiredValueUndefinedError(`${description} must be defined`);
14
- }
15
- }
@@ -1,43 +0,0 @@
1
- import { describe, it } from "vitest";
2
- import { Memo } from "./memo.js";
3
- import { assertIdentical } from "@kensio/smartass";
4
-
5
- describe("Memo", () => {
6
- it("creates and caches values", () => {
7
- const memo = new Memo<string>();
8
- let callCount = 0;
9
-
10
- const value1 = memo.getOrCreate("key1", () => {
11
- callCount++;
12
- return "value1";
13
- });
14
- const value2 = memo.getOrCreate("key1", () => {
15
- callCount++;
16
- return "different";
17
- });
18
-
19
- assertIdentical(value1, "value1");
20
- assertIdentical(value2, "value1");
21
- assertIdentical(callCount, 1);
22
- });
23
-
24
- it("handles multiple keys independently", () => {
25
- const memo = new Memo<number>();
26
-
27
- const a = memo.getOrCreate("a", () => 10);
28
- const b = memo.getOrCreate("b", () => 20);
29
- const c = memo.getOrCreate("a", () => 99);
30
-
31
- assertIdentical(a, 10);
32
- assertIdentical(b, 20);
33
- assertIdentical(c, 10);
34
- });
35
-
36
- it("checks key existence", () => {
37
- const memo = new Memo<string>();
38
-
39
- assertIdentical(memo.has("key"), false);
40
- memo.getOrCreate("key", () => "value");
41
- assertIdentical(memo.has("key"), true);
42
- });
43
- });
@@ -1,26 +0,0 @@
1
- /**
2
- * Simple memoization cache.
3
- */
4
- export class Memo<T> {
5
- private readonly cache = new Map<PropertyKey, T>();
6
-
7
- /**
8
- * Returns the cached value for the given key, or creates/caches it using `factory`.
9
- */
10
- getOrCreate<V extends T>(key: PropertyKey, factory: () => V): V {
11
- if (this.cache.has(key)) {
12
- return this.cache.get(key) as V;
13
- }
14
-
15
- const value = factory();
16
- this.cache.set(key, value);
17
- return value;
18
- }
19
-
20
- /**
21
- * Returns whether the cache contains `key`.
22
- */
23
- has(key: PropertyKey): boolean {
24
- return this.cache.has(key);
25
- }
26
- }
package/src/util/sleep.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * Async sleep for an approximate number of milliseconds.
3
- */
4
- export async function sleep(ms = 0): Promise<void> {
5
- await new Promise((resolve) => {
6
- setTimeout(resolve, ms);
7
- });
8
- }
9
-
10
- /**
11
- * Sleep for a random but short length of time, e.g. to simulate asynchronous
12
- * operations completing in a non-deterministic order.
13
- */
14
- export async function jitter(): Promise<void> {
15
- await sleep(Math.random());
16
- }
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "dist",
6
- "declaration": true,
7
- "declarationMap": true,
8
- "sourceMap": true,
9
- "noEmitOnError": true
10
- },
11
- "include": ["src/**/*", "typings/**/*.d.ts"],
12
- "exclude": ["**/*.test.*", "**/*.spec.*", "test/**/*"]
13
- }
package/tsconfig.json DELETED
@@ -1,39 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2023",
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext",
6
- "lib": ["ES2023"],
7
- "types": ["node"],
8
-
9
- "allowUnreachableCode": false,
10
- "allowUnusedLabels": false,
11
- "exactOptionalPropertyTypes": true,
12
- "incremental": true,
13
- "noCheck": false,
14
- "noEmitOnError": true,
15
- "noFallthroughCasesInSwitch": true,
16
- "noImplicitOverride": true,
17
- "noImplicitReturns": true,
18
- "noPropertyAccessFromIndexSignature": true,
19
- "noUncheckedIndexedAccess": true,
20
- "noUnusedLocals": true,
21
- "noUnusedParameters": true,
22
- "strict": true,
23
-
24
- "forceConsistentCasingInFileNames": true,
25
- "isolatedModules": true,
26
- "resolveJsonModule": true,
27
- "skipLibCheck": true,
28
- "verbatimModuleSyntax": true,
29
-
30
- "declaration": true,
31
- "declarationMap": true,
32
- "removeComments": false,
33
- "sourceMap": true,
34
-
35
- "outDir": "dist",
36
- "rootDir": "."
37
- },
38
- "include": ["src/**/*", "test/**/*", "typings/**/*.d.ts"]
39
- }
package/vitest.config.ts DELETED
@@ -1,50 +0,0 @@
1
- import { fileURLToPath } from "node:url";
2
- import { configDefaults, defineConfig } from "vitest/config";
3
-
4
- export default defineConfig({
5
- resolve: {
6
- alias: {
7
- "#test": fileURLToPath(new URL("./test", import.meta.url)),
8
- },
9
- },
10
- test: {
11
- environment: "node",
12
- include: ["src/**/*.test.ts"],
13
- typecheck: {
14
- tsconfig: "./tsconfig.json",
15
- },
16
- coverage: {
17
- provider: "v8",
18
- include: ["src/**/*.ts"],
19
- exclude: [...configDefaults.exclude],
20
- reporter: ["text", "lcov"],
21
- reportsDirectory: "./test/.coverage",
22
- thresholds: {
23
- statements: 90,
24
- branches: 90,
25
- functions: 90,
26
- lines: 90,
27
- },
28
- },
29
- restoreMocks: true,
30
- testTimeout: 10_000,
31
- projects: [
32
- {
33
- extends: true,
34
- test: {
35
- name: "isolatedTests",
36
- include: ["src/**/*.iso.test.ts"],
37
- // globalSetup: ["./test/isoTestGlobalSetUp.ts"],
38
- },
39
- },
40
- {
41
- extends: true,
42
- test: {
43
- name: "localTests",
44
- include: ["src/**/*.loc.test.ts"],
45
- // globalSetup: ["./test/locTestGlobalSetUp.ts"],
46
- },
47
- },
48
- ],
49
- },
50
- });