Skip to content

Commit

Permalink
4.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniopresto committed Aug 16, 2024
1 parent fd360f1 commit 30e5fa3
Show file tree
Hide file tree
Showing 29 changed files with 370 additions and 488 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powership",
"version": "4.0.7",
"version": "4.0.9",
"private": true,
"scripts": {
"pack": "run-s pack:*",
Expand Down Expand Up @@ -34,6 +34,7 @@
"@types/shelljs": "0.8.11",
"@typescript-eslint/eslint-plugin": "4.15.2",
"@typescript-eslint/parser": "4.15.2",
"bun-safe": "1.0.7",
"bun-types": "1.0.26",
"conditional-type-checks": "1.0.6",
"eslint": "7.20.0",
Expand All @@ -48,15 +49,14 @@
"prettier": "2.4.0",
"prettier-plugin-multiline-arrays": "^1.1.3",
"rimraf": "3.0.2",
"runmate": "latest",
"semver": "7.5.2",
"shelljs": "0.8.5",
"ts-jest": "29.1.2",
"ts-node": "10.9.1",
"runmate": "latest",
"typedoc": "0.23.24",
"typedoc-plugin-markdown": "3.14.0",
"typescript": "4.8.2",
"bun-safe": "1.0.7",
"semver": "7.5.2",
"typedoc": "0.23.24",
"zx": "7.2.3"
},
"xworkspaces": [
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/accounts",
"version": "4.0.7",
"version": "4.0.9",
"description": "Powership accounts",
"type": "module",
"main": "./out/index.cjs",
Expand Down
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": "4.0.7",
"version": "4.0.9",
"main": "./out/index.js",
"sideEffects": false,
"typings": "./out/index.d.ts",
Expand Down
25 changes: 7 additions & 18 deletions packages/boilerplate/babel-config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ const browserConfig = {
useBuiltIns: 'entry',
corejs: '3.22',
targets: {
browsers: [
"last 1 versions",
"not dead",
"not < 50%"
]
browsers: ['last 1 versions', 'not dead', 'not < 50%'],
},
};

Expand All @@ -43,10 +39,6 @@ const envConfig = {
'module-browser': {
...browserConfig,
modules: false,
targets: {
...browserConfig.targets,
esmodules: true,
},
},

node: {
Expand All @@ -56,8 +48,11 @@ const envConfig = {
'module-node': {
...nodeConfig,
modules: false,
},

module: {
modules: false,
targets: {
...nodeConfig.targets,
esmodules: true,
},
},
Expand All @@ -66,10 +61,7 @@ const envConfig = {
module.exports = function (api) {
api.cache(true);

const presets = [
'@babel/preset-typescript', //
['@babel/preset-env', envConfig],
];
const presets = ['@babel/preset-typescript', ['@babel/preset-env', envConfig]];

const plugins = [
['babel-plugin-add-import-extension', { extension: destinationExtension, replace: true }],
Expand All @@ -94,9 +86,6 @@ module.exports = function (api) {
return {
presets,
plugins,
ignore: [
/node_modules/,
'**/__tests__', //
],
ignore: [/node_modules/, '**/__tests__'],
};
};
2 changes: 1 addition & 1 deletion packages/boilerplate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/boilerplate",
"version": "4.0.7",
"version": "4.0.9",
"author": "antoniopresto <[email protected]>",
"sideEffects": false,
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/entity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/entity",
"version": "4.0.7",
"version": "4.0.9",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/index.mjs",
Expand Down
4 changes: 2 additions & 2 deletions packages/entity/setupTests.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { MongoMemoryServer } = require('mongodb-memory-server-core');
// const { MongoMemoryServer } = require('mongodb-memory-server-core');

process.env.LOG_LEVEL = '1';
process.env.NODE_ENV = 'test';
process.env.IS_LOCAL = 'true';

beforeAll(async () => {
// ensure mongo bins are downloaded
await MongoMemoryServer.create();
// await MongoMemoryServer.create();
});
248 changes: 124 additions & 124 deletions packages/entity/src/__tests__/Aliases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,130 @@ import { tupleEnum } from '@powership/utils';
import { createEntity } from '../Entity';

describe('Aliases', () => {
const AccountType = createType('Account', {
object: {
username: 'string',
providers: { string: {}, list: true, optional: true },
},
} as const);

const accessTypesEnum = tupleEnum('phone', 'email', 'oauth', 'custom');

const AccessTypeBase = createSchema({
createdAt: { date: { autoCreate: true } },
meta: 'record?',
updatedAt: { date: { autoCreate: true } },
} as const);

const AccessTypeSchema = createType({
union: [
{
object: {
...AccessTypeBase.definition,
kind: { literal: accessTypesEnum.phone },
value: accessTypesEnum.phone,
verified: 'boolean',
},
},

{
object: {
...AccessTypeBase.definition,
kind: { literal: accessTypesEnum.email },
value: accessTypesEnum.email,
verified: 'boolean',
},
},

{
object: {
...AccessTypeBase.definition,
kind: { literal: accessTypesEnum.oauth },
provider: { description: 'Provider name', string: {} },
authToken: 'string',
value: { alias: 'provider' },
},
},

{
object: {
...AccessTypeBase.definition,
kind: { literal: accessTypesEnum.custom },
meta: 'record',
value: 'string',
},
},
],
} as const);

type AccessType = Infer<typeof AccessTypeSchema>;

const UserType = AccountType.clone((t) =>
t
.extendObjectDefinition({
firstName: 'string',
lastName: 'string',
access: { array: { of: AccessTypeSchema } },
email: {
alias: {
type: 'email',
aggregate: [
{ $pick: 'access' }, //
{ $sort: { createdAt: -1 } },
{ $matchOne: { kind: 'email' } },
{ $pick: 'value' }, //
],
},
},

phone: {
description: 'First user phone',
optional: true,
alias: {
type: 'phone',
aggregate: [
{ $pick: 'access' }, //
{ $sort: { createdAt: -1 } },
{ $matchOne: { kind: 'phone' } },
{ $pick: 'value' }, //
],
},
},
})
.graphType('User')
);

function _getEntity(transporter: MongoTransporter) {
return createEntity({
name: 'User',
transporter,
type: UserType,
indexes: [
{
name: '_id',
PK: ['.username'],
},
],
});
}

function userMock() {
const access: AccessType = {
kind: 'email',
value: '[email protected]',
updatedAt: new Date(),
createdAt: new Date(),
verified: false,
};

return UserType.parse({
firstName: 'antonio',
lastName: 'Silva',
username: 'antonio',
access: [access],
});
}

let mockApp: AppMock;
let transporter: MongoTransporter;

Expand Down Expand Up @@ -233,127 +357,3 @@ describe('Aliases', () => {
});
});
});

export const AccountType = createType('Account', {
object: {
username: 'string',
providers: { string: {}, list: true, optional: true },
},
} as const);

const accessTypesEnum = tupleEnum('phone', 'email', 'oauth', 'custom');

const AccessTypeBase = createSchema({
createdAt: { date: { autoCreate: true } },
meta: 'record?',
updatedAt: { date: { autoCreate: true } },
} as const);

const AccessTypeSchema = createType({
union: [
{
object: {
...AccessTypeBase.definition,
kind: { literal: accessTypesEnum.phone },
value: accessTypesEnum.phone,
verified: 'boolean',
},
},

{
object: {
...AccessTypeBase.definition,
kind: { literal: accessTypesEnum.email },
value: accessTypesEnum.email,
verified: 'boolean',
},
},

{
object: {
...AccessTypeBase.definition,
kind: { literal: accessTypesEnum.oauth },
provider: { description: 'Provider name', string: {} },
authToken: 'string',
value: { alias: 'provider' },
},
},

{
object: {
...AccessTypeBase.definition,
kind: { literal: accessTypesEnum.custom },
meta: 'record',
value: 'string',
},
},
],
} as const);

type AccessType = Infer<typeof AccessTypeSchema>;

const UserType = AccountType.clone((t) =>
t
.extendObjectDefinition({
firstName: 'string',
lastName: 'string',
access: { array: { of: AccessTypeSchema } },
email: {
alias: {
type: 'email',
aggregate: [
{ $pick: 'access' }, //
{ $sort: { createdAt: -1 } },
{ $matchOne: { kind: 'email' } },
{ $pick: 'value' }, //
],
},
},

phone: {
description: 'First user phone',
optional: true,
alias: {
type: 'phone',
aggregate: [
{ $pick: 'access' }, //
{ $sort: { createdAt: -1 } },
{ $matchOne: { kind: 'phone' } },
{ $pick: 'value' }, //
],
},
},
})
.graphType('User')
);

function _getEntity(transporter: MongoTransporter) {
return createEntity({
name: 'User',
transporter,
type: UserType,
indexes: [
{
name: '_id',
PK: ['.username'],
},
],
});
}

function userMock() {
const access: AccessType = {
kind: 'email',
value: '[email protected]',
updatedAt: new Date(),
createdAt: new Date(),
verified: false,
};

return UserType.parse({
firstName: 'antonio',
lastName: 'Silva',
username: 'antonio',
access: [access],
});
}
Loading

0 comments on commit 30e5fa3

Please sign in to comment.