Skip to content

Commit

Permalink
v3.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniopresto committed Mar 11, 2024
1 parent e7aaef2 commit 3b0c0cc
Show file tree
Hide file tree
Showing 18 changed files with 240 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powership",
"version": "3.3.7",
"version": "3.3.9",
"private": true,
"scripts": {
"pack": "run-s pack:*",
Expand Down
10 changes: 5 additions & 5 deletions packages/accounts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/accounts",
"version": "3.3.7",
"version": "3.3.9",
"description": "Powership accounts",
"type": "module",
"main": "./out/index.cjs",
Expand Down Expand Up @@ -91,8 +91,8 @@
"peerDependencies": {
"scrypt-kdf": "*",
"jsonwebtoken": "*",
"@powership/schema": "3.3.7",
"@powership/utils": "3.3.7",
"@powership/schema": "3.3.9",
"@powership/utils": "3.3.9",
"dataloader": "*",
"plugin-hooks": "*",
"sift": "*",
Expand Down Expand Up @@ -135,7 +135,7 @@
"tsx": "*",
"ulid": "*",
"url-pattern": "*",
"@powership/transporter": "3.3.7",
"@powership/entity": "3.3.7"
"@powership/transporter": "3.3.9",
"@powership/entity": "3.3.9"
}
}
2 changes: 1 addition & 1 deletion packages/babel-plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/babel-plugins",
"version": "3.3.7",
"version": "3.3.9",
"main": "./out/index.js",
"sideEffects": false,
"typings": "./out/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/boilerplate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/boilerplate",
"version": "3.3.7",
"version": "3.3.9",
"author": "antoniopresto <[email protected]>",
"sideEffects": false,
"type": "module",
Expand Down Expand Up @@ -61,7 +61,7 @@
"ts-jest": "*",
"typedoc": "*",
"typescript": "*",
"@powership/babel-plugins": "3.3.7",
"@powership/babel-plugins": "3.3.9",
"@babel/preset-typescript": "*",
"@babel/preset-env": "*",
"@babel/plugin-transform-typescript": "*",
Expand Down
6 changes: 3 additions & 3 deletions packages/deepstate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/deepstate",
"version": "3.3.7",
"version": "3.3.9",
"main": "out/index.cjs",
"module": "out/index.mjs",
"sideEffects": false,
Expand Down Expand Up @@ -120,7 +120,7 @@
"tsx": "*",
"ulid": "*",
"url-pattern": "*",
"@powership/utils": "3.3.7",
"@powership/schema": "3.3.7"
"@powership/utils": "3.3.9",
"@powership/schema": "3.3.9"
}
}
8 changes: 4 additions & 4 deletions packages/entity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/entity",
"version": "3.3.7",
"version": "3.3.9",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/index.mjs",
Expand Down Expand Up @@ -138,8 +138,8 @@
"tsx": "*",
"ulid": "*",
"url-pattern": "*",
"@powership/utils": "3.3.7",
"@powership/schema": "3.3.7",
"@powership/transporter": "3.3.7"
"@powership/utils": "3.3.9",
"@powership/schema": "3.3.9",
"@powership/transporter": "3.3.9"
}
}
4 changes: 2 additions & 2 deletions packages/logstorm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logstorm",
"version": "3.3.7",
"version": "3.3.9",
"typings": "out",
"author": "antoniopresto <[email protected]>",
"type": "module",
Expand Down Expand Up @@ -124,6 +124,6 @@
"tsx": "*",
"ulid": "*",
"url-pattern": "*",
"@powership/utils": "3.3.7"
"@powership/utils": "3.3.9"
}
}
8 changes: 4 additions & 4 deletions packages/mongo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/mongo",
"version": "3.3.7",
"version": "3.3.9",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/index.mjs",
Expand Down Expand Up @@ -130,9 +130,9 @@
"tsx": "*",
"ulid": "*",
"url-pattern": "*",
"@powership/utils": "3.3.7",
"@powership/schema": "3.3.7",
"@powership/transporter": "3.3.7",
"@powership/utils": "3.3.9",
"@powership/schema": "3.3.9",
"@powership/transporter": "3.3.9",
"mongodb": "*"
},
"files": [
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plugin-engine",
"version": "3.3.7",
"version": "3.3.9",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/index.mjs",
Expand Down Expand Up @@ -96,9 +96,9 @@
},
"peerDependencies": {
"highlight.js": "*",
"@powership/schema": "3.3.7",
"@powership/transporter": "3.3.7",
"@powership/utils": "3.3.7",
"@powership/schema": "3.3.9",
"@powership/transporter": "3.3.9",
"@powership/utils": "3.3.9",
"dataloader": "*",
"plugin-hooks": "*",
"sift": "*",
Expand Down Expand Up @@ -141,6 +141,6 @@
"tsx": "*",
"ulid": "*",
"url-pattern": "*",
"@powership/entity": "3.3.7"
"@powership/entity": "3.3.9"
}
}
16 changes: 8 additions & 8 deletions packages/powership/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powership",
"version": "3.3.7",
"version": "3.3.9",
"author": "antoniopresto <[email protected]>",
"type": "module",
"main": "./out/index.cjs",
Expand Down Expand Up @@ -105,11 +105,11 @@
"tsconfig": "./tsconfig.module.json"
},
"peerDependencies": {
"@powership/utils": "3.3.7",
"@powership/schema": "3.3.7",
"@powership/entity": "3.3.7",
"@powership/utils": "3.3.9",
"@powership/schema": "3.3.9",
"@powership/entity": "3.3.9",
"highlight.js": "*",
"@powership/transporter": "3.3.7",
"@powership/transporter": "3.3.9",
"dataloader": "*",
"plugin-hooks": "*",
"sift": "*",
Expand Down Expand Up @@ -152,12 +152,12 @@
"tsx": "*",
"ulid": "*",
"url-pattern": "*",
"plugin-engine": "3.3.7",
"plugin-engine": "3.3.9",
"body-parser": "*",
"graphql-playground-html": "*",
"http-errors": "*",
"http-status-codes": "*",
"logstorm": "3.3.7",
"@powership/server": "3.3.7"
"logstorm": "3.3.9",
"@powership/server": "3.3.9"
}
}
6 changes: 3 additions & 3 deletions packages/runmate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "runmate",
"version": "3.3.7",
"version": "3.3.9",
"typings": "out",
"author": "antoniopresto <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -141,8 +141,8 @@
"ts-toolbelt": "*",
"ulid": "*",
"url-pattern": "*",
"@powership/utils": "3.3.7",
"logstorm": "3.3.7",
"@powership/utils": "3.3.9",
"logstorm": "3.3.9",
"@types/vorpal": "*",
"@types/glob": "*"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/schema",
"version": "3.3.7",
"version": "3.3.9",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/index.mjs",
Expand Down Expand Up @@ -144,6 +144,6 @@
"tsx": "*",
"ulid": "*",
"url-pattern": "*",
"@powership/utils": "3.3.7"
"@powership/utils": "3.3.9"
}
}
8 changes: 4 additions & 4 deletions packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/server",
"version": "3.3.7",
"version": "3.3.9",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/index.mjs",
Expand Down Expand Up @@ -114,7 +114,7 @@
"plugin-hooks": "*",
"url-pattern": "*",
"qs": "*",
"@powership/utils": "3.3.7",
"@powership/utils": "3.3.9",
"@types/dateformat": "*",
"@types/fs-extra": "*",
"@types/lodash": "*",
Expand Down Expand Up @@ -152,11 +152,11 @@
"ts-toolbelt": "*",
"tsx": "*",
"ulid": "*",
"logstorm": "3.3.7",
"logstorm": "3.3.9",
"http-status-codes": "*",
"http-errors": "*",
"graphql-playground-html": "*",
"@powership/schema": "3.3.7",
"@powership/schema": "3.3.9",
"body-parser": "*"
}
}
6 changes: 3 additions & 3 deletions packages/transporter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/transporter",
"version": "3.3.7",
"version": "3.3.9",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/index.mjs",
Expand Down Expand Up @@ -140,7 +140,7 @@
"tsx": "*",
"ulid": "*",
"url-pattern": "*",
"@powership/utils": "3.3.7",
"@powership/schema": "3.3.7"
"@powership/utils": "3.3.9",
"@powership/schema": "3.3.9"
}
}
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/utils",
"version": "3.3.7",
"version": "3.3.9",
"typings": "out",
"author": "antoniopresto <[email protected]>",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ export * from './parsePhoneNumber';
export { TU };

export * from './hey';
export * from './watchable';
89 changes: 89 additions & 0 deletions packages/utils/src/watchable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { watchable } from './watchable';

describe('watchable', () => {
test('should delay execution until accessed', async () => {
let executed = false;
const watchableFunction = watchable(() => {
executed = true;
return { message: 'Hello World' };
});

expect(executed).toBe(false);

expect(watchableFunction.message).toBe('Hello World');
expect(executed).toBe(true);
});

test('should handle promise results properly', async () => {
const asyncFunction = watchable(
() =>
new Promise<{ message: string }>((resolve) =>
setTimeout(() => resolve({ message: 'Async Hello World' }), 100)
)
);

expect(asyncFunction.then).toBeDefined();
const data = await asyncFunction;
expect(data.message).toBe('Async Hello World');
});

test('should allow access to the current value', () => {
const watchableFunction = watchable(() => {
return { message: 'Current Value' };
});

// before access
expect(watchableFunction.current()).toBeUndefined();

// force run
expect(watchableFunction.message).toBe('Current Value');

// after access
expect(watchableFunction.current()).toEqual({ message: 'Current Value' });
});

test('should throw if trying to access rejected promise', async () => {
const failingFunction = watchable(
() =>
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Failed')), 100)
)
);

let err: any = undefined;
try {
await failingFunction;
} catch (error: any) {
err = error;
}

expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('Failed');
});

test('should resolve subscribers in the order they were added', async () => {
const asyncFunction = watchable(
() =>
new Promise((resolve) =>
setTimeout(() => resolve({ value: 'Ordered' }), 100)
)
);

const results: string[] = [];

asyncFunction.then(() => results.push('first'));
asyncFunction.then(() => results.push('second'));

await new Promise((resolve) => setTimeout(resolve, 200)); // Espera a resolução

expect(results).toEqual(['first', 'second']);

expect(await asyncFunction).toEqual({
value: 'Ordered',
});

expect(await asyncFunction).toEqual({
value: 'Ordered',
});
});
});
Loading

0 comments on commit 3b0c0cc

Please sign in to comment.