sasat 0.19.8 → 0.19.10

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.
@@ -3,7 +3,6 @@ import { camelize } from '../../../util/stringUtil.js';
3
3
  import { defaultColumnOption, } from '../../../migration/serialized/serializedColumn.js';
4
4
  import { getDefaultGqlOption } from '../../../migration/data/GQLOption.js';
5
5
  import { columnTypeToGqlPrimitive } from '../../../generatorv2/scripts/columnToGqlType.js';
6
- import { GqlPrimitive } from '../../../generatorv2/scripts/gqlTypes.js';
7
6
  const splitArray = (array, callback) => {
8
7
  const indexes = [];
9
8
  array.forEach((it, i) => {
@@ -94,8 +93,8 @@ export class CreateTableParser {
94
93
  if (next.kind === 'NULL')
95
94
  return undefined;
96
95
  if (next.kind === TokenKind.Number ||
97
- gqlType === GqlPrimitive.Float ||
98
- gqlType === GqlPrimitive.Int)
96
+ gqlType === 'Float' ||
97
+ gqlType === 'Int')
99
98
  return +next.value;
100
99
  if (next.kind === TokenKind.String)
101
100
  return next.value;
@@ -64,7 +64,7 @@ const makeUpdateInput = (node) => {
64
64
  };
65
65
  const makeQueryTypeDef = (entity, query) => {
66
66
  const args = getArgs(query, entity);
67
- return tsg.propertyAssign(query.type === 'primary' ? entity.primaryQueryName() : query.name, typeFieldDefinitionToTsg({
67
+ return tsg.propertyAssign(query.type === 'primary' ? entity.name.lowerCase() : query.name, typeFieldDefinitionToTsg({
68
68
  return: GQLString.type({
69
69
  typeName: entity.name.name,
70
70
  entity: true,
@@ -1,2 +1,2 @@
1
1
  import { RootNode } from '../../nodes/rootNode.js';
2
- export declare const generateUserDefinedCondition: (root: RootNode, content: string) => string;
2
+ export declare const generateUserDefinedCondition: (root: RootNode, content: string) => string | null;
@@ -6,7 +6,10 @@ const { createSourceFile, ScriptTarget, SyntaxKind } = typescript;
6
6
  const isImported = (sourceFile, type, paths) => {
7
7
  const importDeclarations = sourceFile.statements.filter(it => it.kind === SyntaxKind.ImportDeclaration);
8
8
  return importDeclarations.some(it => {
9
- if (!paths.includes(it.moduleSpecifier.getText(sourceFile)))
9
+ if (!paths.some(path => {
10
+ const text = it.moduleSpecifier.getText(sourceFile);
11
+ return `'${path}'` === text || `"${path}"` === text;
12
+ }))
10
13
  return false;
11
14
  const binding = it.importClause?.namedBindings;
12
15
  if (binding?.kind !== SyntaxKind.NamedImports)
@@ -17,17 +20,6 @@ const isImported = (sourceFile, type, paths) => {
17
20
  });
18
21
  };
19
22
  export const generateUserDefinedCondition = (root, content) => {
20
- const sourceFile = createSourceFile('conditions.ts', content, ScriptTarget.ESNext);
21
- sourceFile.getChildren().map(it => it);
22
- const exportedVariables = sourceFile.statements.filter(it => it.kind === SyntaxKind.VariableStatement &&
23
- it.modifiers?.some(it => it.kind === SyntaxKind.ExportKeyword));
24
- const contextImported = isImported(sourceFile, 'GQLContext', [
25
- '"./context"',
26
- '"./context.js"',
27
- ]);
28
- const customConditionImported = isImported(sourceFile, 'CustomCondition', [
29
- '"sasat"',
30
- ]);
31
23
  const customConditionNames = unique(root.entities.flatMap(it => [
32
24
  ...it.references.flatMap(it => it.joinCondition
33
25
  .filter(it => it.kind === 'custom')
@@ -36,6 +28,19 @@ export const generateUserDefinedCondition = (root, content) => {
36
28
  .filter(it => it.kind === 'custom')
37
29
  .map(it => it.conditionName)),
38
30
  ]));
31
+ if (customConditionNames.length === 0)
32
+ return null;
33
+ const sourceFile = createSourceFile('conditions.ts', content, ScriptTarget.ESNext);
34
+ sourceFile.getChildren().map(it => it);
35
+ const exportedVariables = sourceFile.statements.filter(it => it.kind === SyntaxKind.VariableStatement &&
36
+ it.modifiers?.some(it => it.kind === SyntaxKind.ExportKeyword));
37
+ const contextImported = isImported(sourceFile, 'GQLContext', [
38
+ './context',
39
+ './context.js',
40
+ ]);
41
+ const customConditionImported = isImported(sourceFile, 'CustomCondition', [
42
+ 'sasat',
43
+ ]);
39
44
  const statements = [];
40
45
  customConditionNames.forEach(conditionName => {
41
46
  const exists = exportedVariables.some(it => {
@@ -17,5 +17,5 @@ export declare class TsCodegen_v2 {
17
17
  generateGQLContext: (root: RootNode) => string;
18
18
  generateFiles: (root: RootNode) => FileData[];
19
19
  generateOnceFiles: () => FileData[];
20
- generateConditions: (root: RootNode, currentFile: string) => string;
20
+ generateConditions: (root: RootNode, currentFile: string) => string | null;
21
21
  }
@@ -5,7 +5,6 @@ import { mkDirIfNotExist, writeFileIfNotExist } from '../util/fsUtil.js';
5
5
  import { TsCodegen_v2 } from './codegen/tscodegen_v2.js';
6
6
  import { parse } from './parse.js';
7
7
  import { Directory } from './directory.js';
8
- import { readFileSync, writeFileSync } from 'fs';
9
8
  const { emptyDir, writeFile } = fs;
10
9
  export class CodeGen_v2 {
11
10
  constructor(store) {
@@ -70,8 +69,11 @@ export class CodeGen_v2 {
70
69
  }
71
70
  async generateCondition(rootNode) {
72
71
  const filePath = this.getFullPath(this.outDir, 'conditions');
73
- await writeFileIfNotExist(filePath, '');
74
- const content = readFileSync(filePath).toString();
75
- writeFileSync(filePath, this.codeGen.generateConditions(rootNode, content));
72
+ const content = fs.existsSync(filePath)
73
+ ? fs.readFileSync(filePath).toString()
74
+ : '';
75
+ const nextContent = this.codeGen.generateConditions(rootNode, content);
76
+ if (nextContent)
77
+ fs.writeFileSync(filePath, nextContent);
76
78
  }
77
79
  }
@@ -4,7 +4,7 @@ import { Table, TableHandler } from '../../migration/serializable/table.js';
4
4
  import { ReferenceColumn } from '../../migration/serializable/column.js';
5
5
  import { SerializedColumn } from '../../migration/serialized/serializedColumn.js';
6
6
  import { EntityName } from './entityName.js';
7
- import { GqlPrimitive } from '../scripts/gqlTypes.js';
7
+ import { GQLPrimitive } from '../scripts/gqlTypes.js';
8
8
  import { VirtualRelation } from '../../migration/data/virtualRelation.js';
9
9
  import { JoinConditionNode } from './JoinConditionNode.js';
10
10
  import { GQLQuery } from '../../migration/data/GQLOption.js';
@@ -57,7 +57,7 @@ export declare type SubTypeNode = {
57
57
  export declare type FieldNode = {
58
58
  fieldName: string;
59
59
  columnName: string;
60
- gqlType: GqlPrimitive | string;
60
+ gqlType: GQLPrimitive | string;
61
61
  dbType: DBColumnTypes;
62
62
  isNullable: boolean;
63
63
  isArray: boolean;
@@ -84,6 +84,6 @@ declare type PrimitiveParameterNode = {
84
84
  fieldName: string;
85
85
  columnName: string;
86
86
  dbtype: DBColumnTypes;
87
- gqltype: GqlPrimitive;
87
+ gqltype: GQLPrimitive;
88
88
  };
89
89
  export {};
@@ -1,6 +1,6 @@
1
1
  import { ArgNode, TypeNode } from './typeNode.js';
2
2
  import { EntityName } from './entityName.js';
3
- import { GqlPrimitive } from '../scripts/gqlTypes.js';
3
+ import { GQLPrimitive } from '../scripts/gqlTypes.js';
4
4
  declare type MutationType = 'create' | 'delete' | 'update';
5
5
  export declare type SubscriptionNode = {
6
6
  gqlEnabled: boolean;
@@ -14,6 +14,6 @@ export declare type SubscriptionNode = {
14
14
  };
15
15
  export declare type SubscriptionFilterNode = {
16
16
  field: string;
17
- gqlType: GqlPrimitive;
17
+ gqlType: GQLPrimitive;
18
18
  };
19
19
  export {};
@@ -1,5 +1,4 @@
1
1
  import { DBColumnTypes } from '../../migration/column/columnTypes.js';
2
- import { GqlPrimitive } from '../scripts/gqlTypes.js';
3
2
  export const makeMutationNodes = (store) => {
4
3
  return store.tables.flatMap(makeTableMutationNodes);
5
4
  };
@@ -56,7 +55,7 @@ const makeUpdateMutationNode = (table) => {
56
55
  mutationName: `update${table.getEntityName().name}`,
57
56
  refetch: !table.gqlOption.mutation.update.noReFetch,
58
57
  returnType: {
59
- typeName: noRefetch ? GqlPrimitive.Boolean : table.getEntityName().name,
58
+ typeName: noRefetch ? 'Boolean' : table.getEntityName().name,
60
59
  dbType: noRefetch
61
60
  ? DBColumnTypes.boolean
62
61
  : undefined,
@@ -87,7 +86,7 @@ const makeDeleteMutationNode = (table) => {
87
86
  identifyFields: table.getPrimaryKeyColumns().map(it => it.fieldName()),
88
87
  refetch: false,
89
88
  returnType: {
90
- typeName: GqlPrimitive.Boolean,
89
+ typeName: 'Boolean',
91
90
  dbType: DBColumnTypes.boolean,
92
91
  nullable: false,
93
92
  array: false,
@@ -1,3 +1,3 @@
1
- import { GqlPrimitive } from './gqlTypes.js';
1
+ import { GQLPrimitive } from './gqlTypes.js';
2
2
  import { DBColumnTypes } from '../../migration/column/columnTypes.js';
3
- export declare const columnTypeToGqlPrimitive: (type: DBColumnTypes) => GqlPrimitive;
3
+ export declare const columnTypeToGqlPrimitive: (type: DBColumnTypes) => GQLPrimitive;
@@ -1,4 +1,3 @@
1
- import { GqlPrimitive } from './gqlTypes.js';
2
1
  import { DBColumnTypes } from '../../migration/column/columnTypes.js';
3
2
  export const columnTypeToGqlPrimitive = (type) => {
4
3
  switch (type) {
@@ -9,10 +8,10 @@ export const columnTypeToGqlPrimitive = (type) => {
9
8
  case DBColumnTypes.bigInt:
10
9
  case DBColumnTypes.decimal:
11
10
  case DBColumnTypes.year:
12
- return GqlPrimitive.Int;
11
+ return 'Int';
13
12
  case DBColumnTypes.float:
14
13
  case DBColumnTypes.double:
15
- return GqlPrimitive.Float;
14
+ return 'Float';
16
15
  case DBColumnTypes.char:
17
16
  case DBColumnTypes.varchar:
18
17
  case DBColumnTypes.text:
@@ -20,8 +19,8 @@ export const columnTypeToGqlPrimitive = (type) => {
20
19
  case DBColumnTypes.date:
21
20
  case DBColumnTypes.dateTime:
22
21
  case DBColumnTypes.timestamp:
23
- return GqlPrimitive.String;
22
+ return 'String';
24
23
  case DBColumnTypes.boolean:
25
- return GqlPrimitive.Boolean;
24
+ return 'Boolean';
26
25
  }
27
26
  };
@@ -1,7 +1,2 @@
1
- export declare enum GqlPrimitive {
2
- Int = "Int",
3
- Float = "Float",
4
- String = "String",
5
- Boolean = "Boolean"
6
- }
7
- export declare const toTsType: (type: 'Int' | 'String' | 'Float' | string) => string;
1
+ export declare type GQLPrimitive = 'Int' | 'Float' | 'String' | 'Boolean';
2
+ export declare const toTsType: (type: GQLPrimitive | string) => string;
@@ -1,10 +1,3 @@
1
- export var GqlPrimitive;
2
- (function (GqlPrimitive) {
3
- GqlPrimitive["Int"] = "Int";
4
- GqlPrimitive["Float"] = "Float";
5
- GqlPrimitive["String"] = "String";
6
- GqlPrimitive["Boolean"] = "Boolean";
7
- })(GqlPrimitive || (GqlPrimitive = {}));
8
1
  export const toTsType = (type) => {
9
2
  switch (type) {
10
3
  case 'Int':
@@ -12,6 +5,8 @@ export const toTsType = (type) => {
12
5
  return 'number';
13
6
  case 'String':
14
7
  return 'string';
8
+ case 'Boolean':
9
+ return 'boolean';
15
10
  default:
16
11
  return type;
17
12
  }
@@ -2,7 +2,7 @@ import { DBColumnTypes } from '../column/columnTypes.js';
2
2
  import { Serializable } from './serializable.js';
3
3
  import { Reference, SerializedColumn, SerializedNormalColumn, SerializedReferenceColumn } from '../serialized/serializedColumn.js';
4
4
  import { Table } from './table.js';
5
- import { GqlPrimitive } from '../../generatorv2/scripts/gqlTypes.js';
5
+ import { GQLPrimitive } from '../../generatorv2/scripts/gqlTypes.js';
6
6
  export interface Column extends Serializable<SerializedColumn> {
7
7
  fieldName(): string;
8
8
  columnName(): string;
@@ -11,7 +11,7 @@ export interface Column extends Serializable<SerializedColumn> {
11
11
  isReference(): this is ReferenceColumn;
12
12
  isNullable(): boolean;
13
13
  tsType(): string;
14
- gqlType(): GqlPrimitive;
14
+ gqlType(): GQLPrimitive;
15
15
  isNullableOnCreate(): boolean;
16
16
  }
17
17
  export declare class BaseColumn implements Column {
@@ -22,7 +22,7 @@ export declare class BaseColumn implements Column {
22
22
  columnName(): string;
23
23
  dataType(): DBColumnTypes;
24
24
  tsType(): string;
25
- gqlType(): GqlPrimitive;
25
+ gqlType(): GQLPrimitive;
26
26
  isNullable(): boolean;
27
27
  isNullableOnCreate(): boolean;
28
28
  isReference(): this is ReferenceColumn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sasat",
3
- "version": "0.19.8",
3
+ "version": "0.19.10",
4
4
  "repository": "https://github.com/nin138/sasat.git",
5
5
  "author": "nin138 <ninian138@gmail.com>",
6
6
  "license": "MIT",