sasat 0.18.0 → 0.18.2

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.
@@ -1,5 +1,5 @@
1
1
  import { TsCode } from '../../abstruct/tsCode.js';
2
- import { TsType } from "./type.js";
2
+ import { TsType } from './type.js';
3
3
  export declare class IntersectionType extends TsCode {
4
4
  private readonly types;
5
5
  constructor(...types: Array<TsType>);
@@ -20,7 +20,11 @@ export class GeneratedRepositoryGenerator {
20
20
  generate() {
21
21
  const node = this.node;
22
22
  const entityPath = Directory.entityPath(Directory.paths.generatedDataSource.db, node.entityName);
23
- return new TsFile(tsg.typeAlias('QueryResult', tsg.intersectionType(tsg.typeRef('Partial', [tsg.typeRef(node.entityName.entityWithRelationTypeName()).importFrom(Directory.generatedPath(Directory.paths.generatedDataSource.db, 'relationMap'))]), node.entityName.identifiableTypeReference(Directory.paths.generatedDataSource.db))), new Class(node.entityName.generatedDataSourceName())
23
+ return new TsFile(tsg.typeAlias('QueryResult', tsg.intersectionType(tsg.typeRef('Partial', [
24
+ tsg
25
+ .typeRef(node.entityName.entityWithRelationTypeName())
26
+ .importFrom(Directory.generatedPath(Directory.paths.generatedDataSource.db, 'relationMap')),
27
+ ]), node.entityName.identifiableTypeReference(Directory.paths.generatedDataSource.db))), new Class(node.entityName.generatedDataSourceName())
24
28
  .export()
25
29
  .abstract()
26
30
  .extends(new ExtendsClause(tsg.typeRef('BaseDBDataSource', [
@@ -32,7 +36,7 @@ export class GeneratedRepositoryGenerator {
32
36
  .typeRef(node.entityName.identifiableInterfaceName())
33
37
  .importFrom(entityPath),
34
38
  node.entityName.fieldTypeRef(Directory.paths.generatedDataSource.db),
35
- tsg.typeRef('QueryResult')
39
+ tsg.typeRef('QueryResult'),
36
40
  ])).addImport(['BaseDBDataSource'], Directory.basePath(Directory.paths.generatedDataSource.db, 'baseDBDataSource')))
37
41
  .addProperty(...this.properties(node))
38
42
  .addMethod(this.getDefaultValueMethod(node), ...this.findMethods(node))).disableEsLint();
@@ -111,7 +115,8 @@ export class GeneratedRepositoryGenerator {
111
115
  new Parameter(`fields?`, tsg
112
116
  .typeRef(`${node.entityName}Fields`)
113
117
  .importFrom(Directory.generatedPath(Directory.paths.generatedDataSource.db, 'fields'))),
114
- tsg.parameter('options?', it.returnType.isArray ? tsg.typeRef('QueryOptions').importFrom('sasat')
118
+ tsg.parameter('options?', it.returnType.isArray
119
+ ? tsg.typeRef('QueryOptions').importFrom('sasat')
115
120
  : tsg.typeRef('Omit', [
116
121
  tsg.typeRef('QueryOptions').importFrom('sasat'),
117
122
  tsg.typeRef('"offset" | "limit" | "sort"'),
@@ -9,22 +9,22 @@ export class EntityGenerator {
9
9
  }
10
10
  entity() {
11
11
  return tsg
12
- .interface(this.node.entityName.name)
13
- .extends(tsg.extends(tsg.typeRef('EntityType').importFrom('sasat')))
14
- .addProperties(this.node.fields.map(it => it.toPropertySignature()))
12
+ .typeAlias(this.node.entityName.name, tsg.typeLiteral(this.node.fields.map(it => it.toPropertySignature())))
15
13
  .export();
16
14
  }
17
15
  creatable() {
16
+ const onCreateRequiredFields = this.node.onCreateRequiredFields();
18
17
  return tsg
19
- .typeAlias(this.node.entityName.creatableInterface(), tsg.intersectionType(tsg.typeLiteral(this.node
20
- .onCreateRequiredFields()
21
- .map(it => it.toPropertySignature())), tsg.typeRef(this.node.entityName.name).partial()))
18
+ .typeAlias(this.node.entityName.creatableInterface(), onCreateRequiredFields.length === 0
19
+ ? tsg.typeRef(this.node.entityName.name).partial()
20
+ : tsg.intersectionType(tsg.typeLiteral(this.node
21
+ .onCreateRequiredFields()
22
+ .map(it => it.toPropertySignature())), tsg.typeRef(this.node.entityName.name).partial()))
22
23
  .export();
23
24
  }
24
25
  identifiable() {
25
26
  return tsg
26
- .interface(this.node.entityName.identifiableInterfaceName())
27
- .addProperties(this.node.identifiableFields().map(it => it.toPropertySignature()))
27
+ .typeAlias(this.node.entityName.identifiableInterfaceName(), tsg.typeLiteral(this.node.identifiableFields().map(it => it.toPropertySignature())))
28
28
  .export();
29
29
  }
30
30
  }
@@ -6,20 +6,20 @@ export class FieldGenerator {
6
6
  return new TsFile(...root
7
7
  .entities()
8
8
  .map(it => tsg
9
- .typeAlias(`${it.entityName}Fields`, tsg.intersectionType(tsg.typeRef('Fields').importFrom('sasat'), this.typeLiteral(it)))
9
+ .typeAlias(`${it.entityName}Fields`, tsg
10
+ .typeRef('Fields', [
11
+ it.entityName.getTypeReference(Directory.paths.generated),
12
+ this.typeLiteral(it),
13
+ ])
14
+ .importFrom('sasat'))
10
15
  .export())).disableEsLint();
11
16
  }
12
17
  typeLiteral(entity) {
13
18
  return tsg.typeLiteral([
14
- tsg.propertySignature('fields', tsg.arrayType(tsg
15
- .typeRef(`keyof ${entity.entityName}`)
16
- .addImport([entity.entityName.name], Directory.entityPath(Directory.paths.generated, entity.entityName)))),
17
- tsg.propertySignature('relations?', tsg.typeLiteral([
18
- ...entity.relations.map(it => tsg.propertySignature(`${it.refPropertyName()}?`, tsg.typeRef(`${it.to.entityName}Fields`))),
19
- ...entity
20
- .findReferencedRelations()
21
- .map(it => tsg.propertySignature(`${it.referencedByPropertyName()}?`, tsg.typeRef(`${it.parent.entityName}Fields`))),
22
- ])),
19
+ ...entity.relations.map(it => tsg.propertySignature(`${it.refPropertyName()}?`, tsg.typeRef(`${it.to.entityName}Fields`))),
20
+ ...entity
21
+ .findReferencedRelations()
22
+ .map(it => tsg.propertySignature(`${it.referencedByPropertyName()}?`, tsg.typeRef(`${it.parent.entityName}Fields`))),
23
23
  ]);
24
24
  }
25
25
  }
@@ -9,7 +9,9 @@ import { FindMethodNode } from '../../../parser/node/findMethod.js';
9
9
  export class ResolverGenerator {
10
10
  constructor() {
11
11
  this.entityResolver = (node) => {
12
- return tsg.propertyAssign(node.entityName.name, tsg.object(...node.relations.filter(it => it.to.gqlOption.enabled).map(relation => this.relationProperty(relation)), ...node
12
+ return tsg.propertyAssign(node.entityName.name, tsg.object(...node.relations
13
+ .filter(it => it.to.gqlOption.enabled)
14
+ .map(relation => this.relationProperty(relation)), ...node
13
15
  .findReferencedRelations()
14
16
  .filter(it => it.from.gqlOption.enabled)
15
17
  .map(relation => this.referencedByProperty(relation))));
@@ -54,6 +56,9 @@ export class ResolverGenerator {
54
56
  ];
55
57
  if (hasSubscription)
56
58
  properties.push(new PropertyAssignment('Subscription', new Identifier('subscription').importFrom('./subscription')));
57
- return new TsFile(new VariableDeclaration('const', new Identifier('resolvers'), new ObjectLiteral(...properties, new SpreadAssignment(new ObjectLiteral(...root.entities().filter(it => it.gqlEnabled()).map(this.entityResolver))))).export()).disableEsLint();
59
+ return new TsFile(new VariableDeclaration('const', new Identifier('resolvers'), new ObjectLiteral(...properties, new SpreadAssignment(new ObjectLiteral(...root
60
+ .entities()
61
+ .filter(it => it.gqlEnabled())
62
+ .map(this.entityResolver))))).export()).disableEsLint();
58
63
  }
59
64
  }
@@ -4,7 +4,10 @@ import { tsg } from '../code/factory.js';
4
4
  import { MutationNode } from '../../../parser/node/gql/mutationNode.js';
5
5
  export class TypeDefGenerator {
6
6
  generate(root) {
7
- const typeDefs = root.entities().filter(it => it.gqlEnabled()).flatMap(it => it.allTypeDefs());
7
+ const typeDefs = root
8
+ .entities()
9
+ .filter(it => it.gqlEnabled())
10
+ .flatMap(it => it.allTypeDefs());
8
11
  const types = [
9
12
  ...this.createTypes(typeDefs),
10
13
  this.createQuery(root.queries()),
@@ -12,7 +12,9 @@ export class RelationMapGenerator {
12
12
  .export();
13
13
  }
14
14
  referencedRelationType(node) {
15
- const type = tsg.intersectionType(tsg.typeRef('Partial', [node.parent.entityName.getTypeReference(Directory.paths.generated)]), node.parent.entityName.identifiableTypeReference(Directory.paths.generated));
15
+ const type = tsg.intersectionType(tsg.typeRef('Partial', [
16
+ node.parent.entityName.getTypeReference(Directory.paths.generated),
17
+ ]), node.parent.entityName.identifiableTypeReference(Directory.paths.generated));
16
18
  return tsg.propertySignature(node.referencedByPropertyName(), node.relation === 'Many' ? tsg.arrayType(type) : type);
17
19
  }
18
20
  entityRelationType(node) {
@@ -29,7 +29,7 @@ export abstract class BaseDBDataSource<
29
29
  Entity extends EntityType,
30
30
  Creatable,
31
31
  Identifiable,
32
- EntityFields extends Fields,
32
+ EntityFields extends Fields<Entity>,
33
33
  QueryResult extends Partial<Entity> & Identifiable,
34
34
  > extends SasatDBDatasource<Entity, Creatable, Identifiable, EntityFields, QueryResult> {
35
35
  protected relationMap = relationMap;
@@ -6,14 +6,9 @@ export class EntityNode {
6
6
  this.repository = repository;
7
7
  this.entityName = table.getEntityName();
8
8
  this.fields = table.columns.map(column => FieldNode.fromColumn(column, table));
9
- this.relations = table
10
- .getReferenceColumns()
11
- .map(it => {
12
- const targetTable = table.store
13
- .table(it.data.reference.targetTable);
14
- return RelationNode.fromReference(this, it, targetTable
15
- .column(it.data.reference.targetColumn)
16
- .fieldName(), targetTable.gqlOption);
9
+ this.relations = table.getReferenceColumns().map(it => {
10
+ const targetTable = table.store.table(it.data.reference.targetTable);
11
+ return RelationNode.fromReference(this, it, targetTable.column(it.data.reference.targetColumn).fieldName(), targetTable.gqlOption);
17
12
  });
18
13
  }
19
14
  field(fieldName) {
@@ -5,7 +5,9 @@ export class TypeDefNode {
5
5
  this.params = params;
6
6
  }
7
7
  static new(entity) {
8
- const reference = entity.relations.filter(it => it.to.gqlOption.enabled).map(rel => new ParameterNode(rel.refPropertyName(), rel.refType()));
8
+ const reference = entity.relations
9
+ .filter(it => it.to.gqlOption.enabled)
10
+ .map(rel => new ParameterNode(rel.refPropertyName(), rel.refType()));
9
11
  const referencedBy = entity
10
12
  .findReferencedRelations()
11
13
  .filter(it => it.from.gqlOption.enabled)
@@ -3,7 +3,7 @@ import { EntityNode } from './entityNode.js';
3
3
  import { ReferenceColumn } from '../../migration/serializable/column.js';
4
4
  import { EntityName } from './entityName.js';
5
5
  import { Relation } from '../../migration/data/relation.js';
6
- import { GQLOption } from "../../migration/data/GQLOption.js";
6
+ import { GQLOption } from '../../migration/data/GQLOption.js';
7
7
  declare type From = {
8
8
  field: string;
9
9
  columnName: string;
@@ -5,7 +5,7 @@ import { QueryNode } from './gql/queryNode.js';
5
5
  import { MutationNode } from './gql/mutationNode.js';
6
6
  import { TableHandler } from '../../migration/serializable/table.js';
7
7
  import { EntityName } from './entityName.js';
8
- import { GQLOption } from "../../migration/data/GQLOption.js";
8
+ import { GQLOption } from '../../migration/data/GQLOption.js';
9
9
  export declare class RepositoryNode {
10
10
  readonly root: RootNode;
11
11
  readonly tableName: string;
@@ -1,6 +1,6 @@
1
1
  import { QueryNode } from '../node/gql/queryNode.js';
2
2
  import { TableHandler } from '../../migration/serializable/table.js';
3
- import { GQLOption } from "../../migration/data/GQLOption.js";
3
+ import { GQLOption } from '../../migration/data/GQLOption.js';
4
4
  export declare class QueryNodeFactory {
5
5
  create(table: TableHandler, gqlOption: GQLOption): QueryNode[];
6
6
  private listQuery;
@@ -1,6 +1,6 @@
1
1
  import { lowercaseFirstLetter, plural } from '../../util/stringUtil.js';
2
2
  import { QueryNode } from '../node/gql/queryNode.js';
3
- import { EntityTypeNode, ListQueryOptionTypeNode, } from '../node/typeNode.js';
3
+ import { EntityTypeNode, ListQueryOptionTypeNode } from '../node/typeNode.js';
4
4
  import { ParameterNode } from '../node/parameterNode.js';
5
5
  import { FindMethodNode } from '../node/findMethod.js';
6
6
  export class QueryNodeFactory {
@@ -17,7 +17,9 @@ export class QueryNodeFactory {
17
17
  return result;
18
18
  }
19
19
  listQuery(table, listQueryType) {
20
- return new QueryNode(lowercaseFirstLetter(plural(table.getEntityName().name)), 'find', listQueryType === 'paging' ? [new ParameterNode('option', new ListQueryOptionTypeNode())] : [], new EntityTypeNode(table.getEntityName(), true, false), true, listQueryType);
20
+ return new QueryNode(lowercaseFirstLetter(plural(table.getEntityName().name)), 'find', listQueryType === 'paging'
21
+ ? [new ParameterNode('option', new ListQueryOptionTypeNode())]
22
+ : [], new EntityTypeNode(table.getEntityName(), true, false), true, listQueryType);
21
23
  }
22
24
  primaryQuery(table) {
23
25
  const primaryKeys = table.primaryKey.map(it => table.column(it).fieldName());
@@ -1,5 +1,5 @@
1
1
  import { QueryNodeKind, } from './query/query.js';
2
- import { nonNullable } from "../util.js";
2
+ import { nonNullable } from '../util.js';
3
3
  const compound = (expr, operator) => {
4
4
  return expr.filter(nonNullable).reduce((acc, current) => ({
5
5
  kind: QueryNodeKind.CompoundExpr,
@@ -3,7 +3,7 @@ import { QueryResolveInfo } from './sql/hydrate.js';
3
3
  import { Fields } from '../../field.js';
4
4
  export declare type RelationInfo = {
5
5
  table: string;
6
- on: (parentTableAlias: string, childTableAlias: string, context?: any) => BooleanValueExpression;
6
+ on: (parentTableAlias: string, childTableAlias: string, context?: unknown) => BooleanValueExpression;
7
7
  relation: 'One' | 'OneOrZero' | 'Many';
8
8
  };
9
9
  export declare type RelationMap = {
@@ -19,4 +19,4 @@ export declare type TableInfo = {
19
19
  };
20
20
  };
21
21
  };
22
- export declare const createQueryResolveInfo: (tableName: string, fields: Fields, map: RelationMap, tableInfo: TableInfo) => QueryResolveInfo;
22
+ export declare const createQueryResolveInfo: (tableName: string, fields: Fields<unknown>, map: RelationMap, tableInfo: TableInfo) => QueryResolveInfo;
@@ -1,5 +1,5 @@
1
1
  import { Query } from './query.js';
2
2
  import { RelationMap } from './createQueryResolveInfo.js';
3
3
  import { Fields } from '../../field.js';
4
- export declare const fieldToQuery: (tableName: string, fields: Fields, map: RelationMap) => Pick<Query, 'select' | 'from'>;
5
- export declare const createPagingInnerQuery: (tableName: string, fields: Fields, len: number, offset: number) => Query;
4
+ export declare const fieldToQuery: (tableName: string, fields: Fields<unknown>, map: RelationMap) => Pick<Query, 'select' | 'from'>;
5
+ export declare const createPagingInnerQuery: (tableName: string, fields: Fields<unknown>, len: number, offset: number) => Query;
@@ -1,5 +1,5 @@
1
- export declare type Fields = {
2
- fields: string[];
3
- relations?: Record<string, Fields | undefined>;
1
+ export declare type Fields<Entity, Relation = Record<string, unknown>> = {
2
+ fields: Array<keyof Entity & string>;
3
+ relations?: Relation;
4
4
  tableAlias?: string;
5
5
  };
@@ -1,3 +1,3 @@
1
1
  import { GraphQLResolveInfo } from 'graphql';
2
2
  import { Fields } from './field.js';
3
- export declare const gqlResolveInfoToField: (info: GraphQLResolveInfo) => Fields;
3
+ export declare const gqlResolveInfoToField: (info: GraphQLResolveInfo) => Fields<unknown>;
@@ -23,7 +23,7 @@ export declare type QueryOptions = {
23
23
  offset?: number;
24
24
  lock?: LockMode;
25
25
  };
26
- export declare abstract class SasatDBDatasource<Entity extends EntityType, Creatable, Identifiable, EntityFields extends Fields, QueryResult extends Partial<Entity> & Identifiable> implements Repository<Entity, Creatable, Identifiable> {
26
+ export declare abstract class SasatDBDatasource<Entity extends EntityType, Creatable, Identifiable, EntityFields extends Fields<Entity>, QueryResult extends Partial<Entity> & Identifiable> implements Repository<Entity, Creatable, Identifiable> {
27
27
  protected client: SQLExecutor;
28
28
  protected abstract relationMap: RelationMap;
29
29
  protected abstract tableInfo: TableInfo;
@@ -39,7 +39,7 @@ export declare abstract class SasatDBDatasource<Entity extends EntityType, Creat
39
39
  create(entity: Creatable): Promise<Entity>;
40
40
  update(entity: Identifiable & Partial<Entity>): Promise<CommandResponse>;
41
41
  delete(entity: Identifiable): Promise<CommandResponse>;
42
- first(fields?: EntityFields, option?: Omit<QueryOptions, 'limit' | 'offset'>, context?: any): Promise<QueryResult | null>;
42
+ first(fields?: EntityFields, option?: Omit<QueryOptions, 'limit' | 'offset'>, context?: unknown): Promise<QueryResult | null>;
43
43
  find(fields?: EntityFields, options?: QueryOptions, context?: unknown): Promise<QueryResult[]>;
44
44
  findPageable(paging: {
45
45
  numberOfItem: number;
@@ -61,7 +61,7 @@ export class SasatDBDatasource {
61
61
  async findPageable(paging, fields = { fields: this.fields }, options, context) {
62
62
  const query = createPagingFieldQuery({
63
63
  baseTableName: this.tableName,
64
- fields,
64
+ fields: fields,
65
65
  tableInfo: this.tableInfo,
66
66
  relationMap: this.relationMap,
67
67
  pagingOption: paging,
@@ -4,22 +4,22 @@ import { RelationMap, TableInfo } from '../dsl/query/createQueryResolveInfo.js';
4
4
  import { Fields } from '../field.js';
5
5
  import { QueryResolveInfo } from '../dsl/query/sql/hydrate.js';
6
6
  import { ListQueryOption, QueryOptions } from '../sasatDBDatasource.js';
7
- export declare const createQuery: (baseTableName: string, fields: Fields, options: QueryOptions | undefined, tableInfo: TableInfo, relationMap: RelationMap, context?: any) => Query;
7
+ export declare const createQuery: (baseTableName: string, fields: Fields<unknown>, options: QueryOptions | undefined, tableInfo: TableInfo, relationMap: RelationMap, context?: unknown) => Query;
8
8
  declare type PagingOption = ListQueryOption & {
9
9
  where?: BooleanValueExpression;
10
10
  };
11
- export declare const createPagingInnerQuery: (tableName: string, tableAlias: string, fields: Fields, option: PagingOption, tableInfo: TableInfo) => Query;
11
+ export declare const createPagingInnerQuery: (tableName: string, tableAlias: string, fields: Fields<unknown>, option: PagingOption, tableInfo: TableInfo) => Query;
12
12
  export declare const runQuery: (client: SQLExecutor, query: Query, resolveInfo: QueryResolveInfo) => Promise<unknown[]>;
13
13
  declare type CreatePagingFieldQueryArg = {
14
14
  baseTableName: string;
15
- fields: Fields;
15
+ fields: Fields<unknown>;
16
16
  tableInfo: TableInfo;
17
17
  relationMap: RelationMap;
18
18
  queryOption?: QueryOptions;
19
19
  pagingOption: ListQueryOption & {
20
20
  where?: BooleanValueExpression;
21
21
  };
22
- context?: any;
22
+ context?: unknown;
23
23
  };
24
24
  export declare const createPagingFieldQuery: ({ baseTableName, fields, queryOption, pagingOption, tableInfo, relationMap, context, }: CreatePagingFieldQueryArg) => Query;
25
25
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sasat",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "repository": "https://github.com/yanokunpei/sasat.git",
5
5
  "author": "yanokunpei <ninian138@gmail.com>",
6
6
  "license": "MIT",