@smartive/graphql-magic 8.1.0 → 8.1.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.
Files changed (55) hide show
  1. package/.eslintrc +1 -1
  2. package/CHANGELOG.md +3 -3
  3. package/dist/bin/gqm.cjs +1099 -1099
  4. package/dist/cjs/index.cjs +2 -521
  5. package/dist/esm/index.d.ts +0 -1
  6. package/dist/esm/index.js +0 -1
  7. package/dist/esm/index.js.map +1 -1
  8. package/package.json +3 -3
  9. package/src/bin/{gqm.ts → gqm/gqm.ts} +8 -8
  10. package/src/{gqm → bin/gqm}/parse-models.ts +1 -1
  11. package/src/{gqm → bin/gqm}/visitor.ts +1 -1
  12. package/src/index.ts +0 -1
  13. package/tsconfig.eslint.json +4 -0
  14. package/tsconfig.json +1 -1
  15. package/dist/esm/bin/gqm.d.ts +0 -2
  16. package/dist/esm/bin/gqm.js +0 -121
  17. package/dist/esm/bin/gqm.js.map +0 -1
  18. package/dist/esm/gqm/codegen.d.ts +0 -2
  19. package/dist/esm/gqm/codegen.js +0 -46
  20. package/dist/esm/gqm/codegen.js.map +0 -1
  21. package/dist/esm/gqm/index.d.ts +0 -9
  22. package/dist/esm/gqm/index.js +0 -11
  23. package/dist/esm/gqm/index.js.map +0 -1
  24. package/dist/esm/gqm/parse-knexfile.d.ts +0 -2
  25. package/dist/esm/gqm/parse-knexfile.js +0 -19
  26. package/dist/esm/gqm/parse-knexfile.js.map +0 -1
  27. package/dist/esm/gqm/parse-models.d.ts +0 -2
  28. package/dist/esm/gqm/parse-models.js +0 -19
  29. package/dist/esm/gqm/parse-models.js.map +0 -1
  30. package/dist/esm/gqm/readline.d.ts +0 -1
  31. package/dist/esm/gqm/readline.js +0 -14
  32. package/dist/esm/gqm/readline.js.map +0 -1
  33. package/dist/esm/gqm/settings.d.ts +0 -9
  34. package/dist/esm/gqm/settings.js +0 -98
  35. package/dist/esm/gqm/settings.js.map +0 -1
  36. package/dist/esm/gqm/static-eval.d.ts +0 -3
  37. package/dist/esm/gqm/static-eval.js +0 -188
  38. package/dist/esm/gqm/static-eval.js.map +0 -1
  39. package/dist/esm/gqm/templates.d.ts +0 -4
  40. package/dist/esm/gqm/templates.js +0 -62
  41. package/dist/esm/gqm/templates.js.map +0 -1
  42. package/dist/esm/gqm/utils.d.ts +0 -2
  43. package/dist/esm/gqm/utils.js +0 -22
  44. package/dist/esm/gqm/utils.js.map +0 -1
  45. package/dist/esm/gqm/visitor.d.ts +0 -8
  46. package/dist/esm/gqm/visitor.js +0 -15
  47. package/dist/esm/gqm/visitor.js.map +0 -1
  48. package/src/gqm/index.ts +0 -11
  49. /package/src/{gqm → bin/gqm}/codegen.ts +0 -0
  50. /package/src/{gqm → bin/gqm}/parse-knexfile.ts +0 -0
  51. /package/src/{gqm → bin/gqm}/readline.ts +0 -0
  52. /package/src/{gqm → bin/gqm}/settings.ts +0 -0
  53. /package/src/{gqm → bin/gqm}/static-eval.ts +0 -0
  54. /package/src/{gqm → bin/gqm}/templates.ts +0 -0
  55. /package/src/{gqm → bin/gqm}/utils.ts +0 -0
@@ -30,15 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var src_exports = {};
31
31
  __export(src_exports, {
32
32
  AliasGenerator: () => AliasGenerator,
33
- CLIENT_CODEGEN: () => CLIENT_CODEGEN,
34
- EMPTY_MODELS: () => EMPTY_MODELS,
35
33
  Enum: () => Enum,
36
34
  ForbiddenError: () => ForbiddenError,
37
- GRAPHQL_CODEGEN: () => GRAPHQL_CODEGEN,
38
35
  GraphQLError: () => GraphQLError,
39
36
  ID_ALIAS: () => ID_ALIAS,
40
- KNEXFILE: () => KNEXFILE,
41
- KNEXFILE_PATH: () => KNEXFILE_PATH,
42
37
  MigrationGenerator: () => MigrationGenerator,
43
38
  NotFoundError: () => NotFoundError,
44
39
  PermissionError: () => PermissionError,
@@ -58,16 +53,12 @@ __export(src_exports, {
58
53
  displayField: () => displayField,
59
54
  document: () => document,
60
55
  enm: () => enm,
61
- ensureFileExists: () => ensureFileExists,
62
56
  execute: () => execute,
63
57
  fieldType: () => fieldType,
64
58
  fields: () => fields,
65
- findDeclarationInFile: () => findDeclarationInFile,
66
59
  generate: () => generate,
67
60
  generateDBModels: () => generateDBModels,
68
61
  generateDefinitions: () => generateDefinitions,
69
- generateGraphqlApiTypes: () => generateGraphqlApiTypes,
70
- generateGraphqlClientTypes: () => generateGraphqlClientTypes,
71
62
  generateKnexTables: () => generateKnexTables,
72
63
  generateMutations: () => generateMutations,
73
64
  generatePermissions: () => generatePermissions,
@@ -98,8 +89,6 @@ __export(src_exports, {
98
89
  getResolverNode: () => getResolverNode,
99
90
  getResolvers: () => getResolvers,
100
91
  getRootFieldNode: () => getRootFieldNode,
101
- getSetting: () => getSetting,
102
- getSettings: () => getSettings,
103
92
  getSimpleFields: () => getSimpleFields,
104
93
  getString: () => getString,
105
94
  getType: () => getType,
@@ -150,25 +139,19 @@ __export(src_exports, {
150
139
  not: () => not,
151
140
  object: () => object,
152
141
  ors: () => ors,
153
- parseKnexfile: () => parseKnexfile,
154
- parseModels: () => parseModels,
155
142
  printSchema: () => printSchema,
156
143
  printSchemaFromDocument: () => printSchemaFromDocument,
157
144
  printSchemaFromModels: () => printSchemaFromModels,
158
145
  queryRelations: () => queryRelations,
159
146
  queryResolver: () => queryResolver,
160
- readLine: () => readLine,
161
147
  resolve: () => resolve,
162
148
  retry: () => retry,
163
149
  scalar: () => scalar,
164
- staticEval: () => staticEval,
165
150
  summon: () => summon,
166
151
  summonByKey: () => summonByKey,
167
152
  summonByName: () => summonByName,
168
153
  typeToField: () => typeToField,
169
- value: () => value,
170
- visit: () => visit,
171
- writeToFile: () => writeToFile
154
+ value: () => value
172
155
  });
173
156
  module.exports = __toCommonJS(src_exports);
174
157
 
@@ -721,491 +704,6 @@ var generateKnexTables = (rawModels) => {
721
704
  return writer.toString();
722
705
  };
723
706
 
724
- // src/gqm/codegen.ts
725
- var import_cli = require("@graphql-codegen/cli");
726
-
727
- // src/gqm/settings.ts
728
- var import_fs = require("fs");
729
- var import_path = require("path");
730
-
731
- // src/gqm/readline.ts
732
- var import_readline = __toESM(require("readline"), 1);
733
- var readLine = (prompt) => {
734
- const rl = import_readline.default.createInterface({
735
- input: process.stdin,
736
- output: process.stdout
737
- });
738
- return new Promise((resolve2) => {
739
- rl.question(prompt, (answer) => {
740
- rl.close();
741
- resolve2(answer);
742
- });
743
- });
744
- };
745
-
746
- // src/gqm/templates.ts
747
- var EMPTY_MODELS = `
748
- import { RawModels, getModels } from '@smartive/graphql-magic';
749
-
750
- export const rawModels: RawModels = [
751
- {
752
- kind: 'entity',
753
- name: 'User',
754
- fields: []
755
- },
756
- ]
757
-
758
- export const models = getModels(rawModels);
759
- `;
760
- var GRAPHQL_CODEGEN = (path) => `
761
- overwrite: true
762
- schema: '${path}/schema.graphql'
763
- documents: null
764
- generates:
765
- ${path}/api/index.ts:
766
- plugins:
767
- - 'typescript'
768
- - 'typescript-resolvers'
769
- - add:
770
- content: "import { DateTime } from 'luxon'"
771
- config:
772
- scalars:
773
- DateTime: DateTime
774
- `;
775
- var CLIENT_CODEGEN = (path) => `
776
- schema: ${path}/schema.graphql
777
- documents: [ './src/**/*.ts', './src/**/*.tsx' ]
778
- generates:
779
- ${path}/client/index.ts:
780
- plugins:
781
- - typescript
782
- - typescript-operations
783
- - typescript-compatibility
784
-
785
- config:
786
- preResolveTypes: true # Simplifies the generated types
787
- namingConvention: keep # Keeps naming as-is
788
- nonOptionalTypename: true # Forces \`__typename\` on all selection sets
789
- skipTypeNameForRoot: true # Don't generate __typename for root types
790
- avoidOptionals: # Avoids optionals on the level of the field
791
- field: true
792
- scalars:
793
- DateTime: string
794
- `;
795
- var KNEXFILE = `
796
- const config = {
797
- client: 'postgresql',
798
- connection: {
799
- host: process.env.DATABASE_HOST,
800
- database: process.env.DATABASE_NAME,
801
- user: process.env.DATABASE_USER,
802
- password: process.env.DATABASE_PASSWORD,
803
- },
804
- } as const;
805
-
806
- export default config;
807
- `;
808
-
809
- // src/gqm/settings.ts
810
- var SETTINGS_PATH = ".gqmrc.json";
811
- var DEFAULTS = {
812
- modelsPath: {
813
- question: "What is the models path?",
814
- defaultValue: "src/config/models.ts",
815
- init: (path) => {
816
- ensureFileExists(path, EMPTY_MODELS);
817
- }
818
- },
819
- generatedFolderPath: {
820
- question: "What is the path for generated stuff?",
821
- defaultValue: "src/generated",
822
- init: (path) => {
823
- ensureFileExists(`${path}/.gitkeep`, "");
824
- ensureFileExists(`${path}/db/.gitkeep`, "");
825
- ensureFileExists(`${path}/api/.gitkeep`, "");
826
- ensureFileExists(`${path}/client/.gitkeep`, "");
827
- ensureFileExists(`graphql-codegen.yml`, GRAPHQL_CODEGEN(path));
828
- ensureFileExists(`client-codegen.yml`, CLIENT_CODEGEN(path));
829
- }
830
- }
831
- };
832
- var initSetting = async (name2) => {
833
- const { question, defaultValue, init } = DEFAULTS[name2];
834
- const value2 = await readLine(`${question} (${defaultValue})`) || defaultValue;
835
- init(value2);
836
- return value2;
837
- };
838
- var initSettings = async () => {
839
- const settings = {};
840
- for (const name2 of Object.keys(DEFAULTS)) {
841
- settings[name2] = await initSetting(name2);
842
- }
843
- saveSettings(settings);
844
- };
845
- var saveSettings = (settings) => {
846
- writeToFile(SETTINGS_PATH, JSON.stringify(settings, null, 2));
847
- };
848
- var getSettings = async () => {
849
- if (!(0, import_fs.existsSync)(SETTINGS_PATH)) {
850
- await initSettings();
851
- }
852
- return JSON.parse((0, import_fs.readFileSync)(SETTINGS_PATH, "utf8"));
853
- };
854
- var getSetting = async (name2) => {
855
- const settings = await getSettings();
856
- if (!(name2 in settings)) {
857
- settings[name2] = await initSetting(name2);
858
- saveSettings(settings);
859
- }
860
- return settings[name2];
861
- };
862
- var ensureDirectoryExists = (filePath) => {
863
- const dir = (0, import_path.dirname)(filePath);
864
- if ((0, import_fs.existsSync)(dir)) {
865
- return true;
866
- }
867
- ensureDirectoryExists(dir);
868
- try {
869
- (0, import_fs.mkdirSync)(dir);
870
- return true;
871
- } catch (err) {
872
- if (err.code === "EEXIST") {
873
- return true;
874
- }
875
- throw err;
876
- }
877
- };
878
- var ensureFileExists = (filePath, content) => {
879
- if (!(0, import_fs.existsSync)(filePath)) {
880
- console.info(`Creating ${filePath}`);
881
- ensureDirectoryExists(filePath);
882
- (0, import_fs.writeFileSync)(filePath, content);
883
- }
884
- };
885
- var writeToFile = (filePath, content) => {
886
- ensureDirectoryExists(filePath);
887
- if ((0, import_fs.existsSync)(filePath)) {
888
- const currentContent = (0, import_fs.readFileSync)(filePath, "utf-8");
889
- if (content === currentContent) {
890
- } else {
891
- (0, import_fs.writeFileSync)(filePath, content);
892
- console.info(`${filePath} updated`);
893
- }
894
- } else {
895
- (0, import_fs.writeFileSync)(filePath, content);
896
- console.info(`Created ${filePath}`);
897
- }
898
- };
899
-
900
- // src/gqm/codegen.ts
901
- var generateGraphqlApiTypes = async () => {
902
- const generatedFolderPath = await getSetting("generatedFolderPath");
903
- await (0, import_cli.generate)({
904
- overwrite: true,
905
- schema: `${generatedFolderPath}/schema.graphql`,
906
- documents: null,
907
- generates: {
908
- [`${generatedFolderPath}/api/index.ts`]: {
909
- plugins: ["typescript", "typescript-resolvers", { add: { content: `import { DateTime } from 'luxon';` } }]
910
- }
911
- },
912
- config: {
913
- scalars: {
914
- DateTime: "DateTime"
915
- }
916
- }
917
- });
918
- };
919
- var generateGraphqlClientTypes = async () => {
920
- const generatedFolderPath = await getSetting("generatedFolderPath");
921
- await (0, import_cli.generate)({
922
- schema: `${generatedFolderPath}/schema.graphql`,
923
- documents: ["./src/**/*.ts", "./src/**/*.tsx"],
924
- generates: {
925
- [`${generatedFolderPath}/client/index.ts`]: {
926
- plugins: ["typescript", "typescript-operations", "typescript-compatibility"]
927
- }
928
- },
929
- config: {
930
- preResolveTypes: true,
931
- // Simplifies the generated types
932
- namingConvention: "keep",
933
- // Keeps naming as-is
934
- nonOptionalTypename: true,
935
- // Forces `__typename` on all selection sets
936
- skipTypeNameForRoot: true,
937
- // Don't generate __typename for root types
938
- avoidOptionals: {
939
- // Avoids optionals on the level of the field
940
- field: true
941
- },
942
- scalars: {
943
- DateTime: "string"
944
- }
945
- }
946
- });
947
- };
948
-
949
- // src/gqm/parse-knexfile.ts
950
- var import_ts_morph4 = require("ts-morph");
951
-
952
- // src/gqm/static-eval.ts
953
- var import_ts_morph2 = require("ts-morph");
954
-
955
- // src/gqm/visitor.ts
956
- var import_ts_morph = require("ts-morph");
957
- var visit = (node, context, visitor2) => {
958
- const kind = node?.getKind();
959
- if (kind in visitor2) {
960
- return visitor2[kind](node.asKindOrThrow(kind), context);
961
- }
962
- if ("unknown" in visitor2) {
963
- return visitor2.unknown(node);
964
- }
965
- console.error(node.getText());
966
- console.error(node.getParent().getText());
967
- throw new Error(
968
- `Cannot handle kind ${get(
969
- Object.entries(import_ts_morph.SyntaxKind).find(([, val]) => val === kind),
970
- 0
971
- )}`
972
- );
973
- };
974
-
975
- // src/gqm/static-eval.ts
976
- var staticEval = (node, context) => visit(node, context, visitor);
977
- var visitor = {
978
- undefined: () => void 0,
979
- [import_ts_morph2.SyntaxKind.VariableDeclaration]: (node, context) => staticEval(node.getInitializer(), context),
980
- [import_ts_morph2.SyntaxKind.ArrayLiteralExpression]: (node, context) => {
981
- const values = [];
982
- for (const value2 of node.getElements()) {
983
- if (value2.isKind(import_ts_morph2.SyntaxKind.SpreadElement)) {
984
- values.push(...staticEval(value2, context));
985
- } else {
986
- values.push(staticEval(value2, context));
987
- }
988
- }
989
- return values;
990
- },
991
- [import_ts_morph2.SyntaxKind.ObjectLiteralExpression]: (node, context) => {
992
- const result = {};
993
- for (const property of node.getProperties()) {
994
- Object.assign(result, staticEval(property, context));
995
- }
996
- return result;
997
- },
998
- [import_ts_morph2.SyntaxKind.StringLiteral]: (node) => node.getLiteralValue(),
999
- [import_ts_morph2.SyntaxKind.PropertyAssignment]: (node, context) => ({
1000
- [node.getName()]: staticEval(node.getInitializer(), context)
1001
- }),
1002
- [import_ts_morph2.SyntaxKind.ShorthandPropertyAssignment]: (node, context) => ({
1003
- [node.getName()]: staticEval(node.getNameNode(), context)
1004
- }),
1005
- [import_ts_morph2.SyntaxKind.SpreadElement]: (node, context) => staticEval(node.getExpression(), context),
1006
- [import_ts_morph2.SyntaxKind.SpreadAssignment]: (node, context) => staticEval(node.getExpression(), context),
1007
- [import_ts_morph2.SyntaxKind.Identifier]: (node, context) => {
1008
- switch (node.getText()) {
1009
- case "undefined":
1010
- return void 0;
1011
- case "process":
1012
- return process;
1013
- }
1014
- const definitionNodes = node.getDefinitionNodes();
1015
- if (!definitionNodes.length) {
1016
- throw new Error(`No definition node found for identifier ${node.getText()}.`);
1017
- }
1018
- return staticEval(definitionNodes[0], context);
1019
- },
1020
- [import_ts_morph2.SyntaxKind.ParenthesizedExpression]: (node, context) => staticEval(node.getExpression(), context),
1021
- [import_ts_morph2.SyntaxKind.AsExpression]: (node, context) => staticEval(node.getExpression(), context),
1022
- [import_ts_morph2.SyntaxKind.ConditionalExpression]: (node, context) => staticEval(node.getCondition(), context) ? staticEval(node.getWhenTrue(), context) : staticEval(node.getWhenFalse(), context),
1023
- [import_ts_morph2.SyntaxKind.TrueKeyword]: () => true,
1024
- [import_ts_morph2.SyntaxKind.FalseKeyword]: () => false,
1025
- [import_ts_morph2.SyntaxKind.NumericLiteral]: (node) => node.getLiteralValue(),
1026
- [import_ts_morph2.SyntaxKind.CallExpression]: (node, context) => {
1027
- const method = staticEval(node.getExpression(), context);
1028
- const args2 = node.getArguments().map((arg) => staticEval(arg, context));
1029
- return method(...args2);
1030
- },
1031
- [import_ts_morph2.SyntaxKind.PropertyAccessExpression]: (node, context) => {
1032
- const target = staticEval(node.getExpression(), context);
1033
- const property = target[node.getName()];
1034
- if (typeof property === "function") {
1035
- if (Array.isArray(target)) {
1036
- switch (node.getName()) {
1037
- case "map":
1038
- case "flatMap":
1039
- case "includes":
1040
- case "some":
1041
- case "find":
1042
- case "filter":
1043
- return target[node.getName()].bind(target);
1044
- }
1045
- } else if (typeof target === "string") {
1046
- const name2 = node.getName();
1047
- switch (name2) {
1048
- case "slice":
1049
- case "toUpperCase":
1050
- case "toLowerCase":
1051
- return target[name2].bind(target);
1052
- }
1053
- }
1054
- throw new Error(`Cannot handle method ${node.getName()} on type ${typeof target}`);
1055
- }
1056
- return property;
1057
- },
1058
- [import_ts_morph2.SyntaxKind.ArrowFunction]: (node, context) => {
1059
- return (...args2) => {
1060
- const parameters = {};
1061
- let i = 0;
1062
- for (const parameter of node.getParameters()) {
1063
- parameters[parameter.getName()] = args2[i];
1064
- i++;
1065
- }
1066
- return staticEval(node.getBody(), { ...context, ...parameters });
1067
- };
1068
- },
1069
- [import_ts_morph2.SyntaxKind.Block]: (node, context) => {
1070
- for (const statement of node.getStatements()) {
1071
- return staticEval(statement, context);
1072
- }
1073
- },
1074
- [import_ts_morph2.SyntaxKind.CaseClause]: (node, context) => {
1075
- const statements = node.getStatements();
1076
- if (statements.length !== 1) {
1077
- console.error(node.getText());
1078
- throw new Error(`Can only handle code blocks with 1 statement.`);
1079
- }
1080
- return staticEval(statements[0], context);
1081
- },
1082
- [import_ts_morph2.SyntaxKind.DefaultClause]: (node, context) => {
1083
- const statements = node.getStatements();
1084
- if (statements.length !== 1) {
1085
- console.error(node.getText());
1086
- throw new Error(`Can only handle code blocks with exactly 1 statement.`);
1087
- }
1088
- return staticEval(statements[0], context);
1089
- },
1090
- [import_ts_morph2.SyntaxKind.ReturnStatement]: (node, context) => {
1091
- return staticEval(node.getExpression(), context);
1092
- },
1093
- [import_ts_morph2.SyntaxKind.SwitchStatement]: (node, context) => {
1094
- const value2 = staticEval(node.getExpression(), context);
1095
- let active = false;
1096
- for (const clause of node.getCaseBlock().getClauses()) {
1097
- switch (clause.getKind()) {
1098
- case import_ts_morph2.SyntaxKind.DefaultClause:
1099
- return staticEval(clause, context);
1100
- case import_ts_morph2.SyntaxKind.CaseClause: {
1101
- const caseClause = clause.asKindOrThrow(import_ts_morph2.SyntaxKind.CaseClause);
1102
- if (caseClause.getStatements().length && active) {
1103
- return staticEval(clause, context);
1104
- }
1105
- const caseValue = staticEval(caseClause.getExpression(), context);
1106
- if (value2 === caseValue) {
1107
- active = true;
1108
- if (caseClause.getStatements().length) {
1109
- return staticEval(clause, context);
1110
- }
1111
- }
1112
- }
1113
- }
1114
- }
1115
- },
1116
- [import_ts_morph2.SyntaxKind.Parameter]: (node, context) => context[node.getName()],
1117
- [import_ts_morph2.SyntaxKind.BinaryExpression]: (node, context) => {
1118
- switch (node.getOperatorToken().getKind()) {
1119
- case import_ts_morph2.SyntaxKind.EqualsEqualsEqualsToken:
1120
- return staticEval(node.getLeft(), context) === staticEval(node.getRight(), context);
1121
- case import_ts_morph2.SyntaxKind.BarBarToken:
1122
- return staticEval(node.getLeft(), context) || staticEval(node.getRight(), context);
1123
- default:
1124
- throw new Error(`Cannot handle operator of kind ${node.getOperatorToken().getKindName()}`);
1125
- }
1126
- },
1127
- [import_ts_morph2.SyntaxKind.SatisfiesExpression]: (node, context) => staticEval(node.getExpression(), context),
1128
- [import_ts_morph2.SyntaxKind.TemplateExpression]: (node, context) => node.getHead().getLiteralText() + node.getTemplateSpans().map((span) => staticEval(span.getExpression(), context) + staticEval(span.getLiteral(), context)).join(""),
1129
- [import_ts_morph2.SyntaxKind.TemplateTail]: (node) => node.getLiteralText(),
1130
- [import_ts_morph2.SyntaxKind.TemplateMiddle]: (node) => node.getLiteralText(),
1131
- [import_ts_morph2.SyntaxKind.PrefixUnaryExpression]: (node, context) => {
1132
- switch (node.getOperatorToken()) {
1133
- case import_ts_morph2.SyntaxKind.PlusToken:
1134
- return +staticEval(node.getOperand(), context);
1135
- case import_ts_morph2.SyntaxKind.MinusToken:
1136
- return -staticEval(node.getOperand(), context);
1137
- case import_ts_morph2.SyntaxKind.TildeToken:
1138
- return ~staticEval(node.getOperand(), context);
1139
- case import_ts_morph2.SyntaxKind.ExclamationToken:
1140
- return !staticEval(node.getOperand(), context);
1141
- case import_ts_morph2.SyntaxKind.PlusPlusToken:
1142
- case import_ts_morph2.SyntaxKind.MinusMinusToken:
1143
- throw new Error(`Cannot handle assignments.`);
1144
- }
1145
- },
1146
- [import_ts_morph2.SyntaxKind.ElementAccessExpression]: (node, context) => {
1147
- const target = staticEval(node.getExpression(), context);
1148
- const argument = staticEval(node.getArgumentExpression(), context);
1149
- return target[argument];
1150
- },
1151
- [import_ts_morph2.SyntaxKind.NoSubstitutionTemplateLiteral]: (node) => node.getLiteralValue()
1152
- };
1153
-
1154
- // src/gqm/utils.ts
1155
- var import_ts_morph3 = require("ts-morph");
1156
- var findDeclarationInFile = (sourceFile, name2) => {
1157
- const syntaxList = sourceFile.getChildrenOfKind(import_ts_morph3.SyntaxKind.SyntaxList)[0];
1158
- if (!syntaxList) {
1159
- throw new Error("No SyntaxList");
1160
- }
1161
- const declaration = findDeclaration(syntaxList, name2);
1162
- if (!declaration) {
1163
- throw new Error(`No ${name2} declaration`);
1164
- }
1165
- return declaration;
1166
- };
1167
- var findDeclaration = (syntaxList, name2) => {
1168
- for (const variableStatement of syntaxList.getChildrenOfKind(import_ts_morph3.SyntaxKind.VariableStatement)) {
1169
- for (const declaration of variableStatement.getDeclarationList().getDeclarations()) {
1170
- if (declaration.getName() === name2) {
1171
- return declaration;
1172
- }
1173
- }
1174
- }
1175
- };
1176
-
1177
- // src/gqm/parse-knexfile.ts
1178
- var KNEXFILE_PATH = `knexfile.ts`;
1179
- var parseKnexfile = async () => {
1180
- const project = new import_ts_morph4.Project({
1181
- manipulationSettings: {
1182
- indentationText: import_ts_morph4.IndentationText.TwoSpaces
1183
- }
1184
- });
1185
- ensureFileExists(KNEXFILE_PATH, KNEXFILE);
1186
- const sourceFile = project.addSourceFileAtPath(KNEXFILE_PATH);
1187
- const configDeclaration = findDeclarationInFile(sourceFile, "config");
1188
- const config = staticEval(configDeclaration, {});
1189
- return config;
1190
- };
1191
-
1192
- // src/gqm/parse-models.ts
1193
- var import_ts_morph5 = require("ts-morph");
1194
- var parseModels = async () => {
1195
- const project = new import_ts_morph5.Project({
1196
- manipulationSettings: {
1197
- indentationText: import_ts_morph5.IndentationText.TwoSpaces
1198
- }
1199
- });
1200
- const modelsPath = await getSetting("modelsPath");
1201
- const sourceFile = project.addSourceFileAtPath(modelsPath);
1202
- const modelsDeclaration = findDeclarationInFile(sourceFile, "rawModels");
1203
- const rawModels = staticEval(modelsDeclaration, {});
1204
- const generatedFolderPath = await getSetting("generatedFolderPath");
1205
- writeToFile(`${generatedFolderPath}/models.json`, JSON.stringify(rawModels, null, 2));
1206
- return rawModels;
1207
- };
1208
-
1209
707
  // src/migrations/generate.ts
1210
708
  var import_code_block_writer2 = __toESM(require("code-block-writer"), 1);
1211
709
  var import_knex_schema_inspector = require("knex-schema-inspector");
@@ -3261,15 +2759,10 @@ var printSchemaFromModels = (models) => printSchema((0, import_graphql5.buildAST
3261
2759
  // Annotate the CommonJS export names for ESM import in node:
3262
2760
  0 && (module.exports = {
3263
2761
  AliasGenerator,
3264
- CLIENT_CODEGEN,
3265
- EMPTY_MODELS,
3266
2762
  Enum,
3267
2763
  ForbiddenError,
3268
- GRAPHQL_CODEGEN,
3269
2764
  GraphQLError,
3270
2765
  ID_ALIAS,
3271
- KNEXFILE,
3272
- KNEXFILE_PATH,
3273
2766
  MigrationGenerator,
3274
2767
  NotFoundError,
3275
2768
  PermissionError,
@@ -3289,16 +2782,12 @@ var printSchemaFromModels = (models) => printSchema((0, import_graphql5.buildAST
3289
2782
  displayField,
3290
2783
  document,
3291
2784
  enm,
3292
- ensureFileExists,
3293
2785
  execute,
3294
2786
  fieldType,
3295
2787
  fields,
3296
- findDeclarationInFile,
3297
2788
  generate,
3298
2789
  generateDBModels,
3299
2790
  generateDefinitions,
3300
- generateGraphqlApiTypes,
3301
- generateGraphqlClientTypes,
3302
2791
  generateKnexTables,
3303
2792
  generateMutations,
3304
2793
  generatePermissions,
@@ -3329,8 +2818,6 @@ var printSchemaFromModels = (models) => printSchema((0, import_graphql5.buildAST
3329
2818
  getResolverNode,
3330
2819
  getResolvers,
3331
2820
  getRootFieldNode,
3332
- getSetting,
3333
- getSettings,
3334
2821
  getSimpleFields,
3335
2822
  getString,
3336
2823
  getType,
@@ -3381,23 +2868,17 @@ var printSchemaFromModels = (models) => printSchema((0, import_graphql5.buildAST
3381
2868
  not,
3382
2869
  object,
3383
2870
  ors,
3384
- parseKnexfile,
3385
- parseModels,
3386
2871
  printSchema,
3387
2872
  printSchemaFromDocument,
3388
2873
  printSchemaFromModels,
3389
2874
  queryRelations,
3390
2875
  queryResolver,
3391
- readLine,
3392
2876
  resolve,
3393
2877
  retry,
3394
2878
  scalar,
3395
- staticEval,
3396
2879
  summon,
3397
2880
  summonByKey,
3398
2881
  summonByName,
3399
2882
  typeToField,
3400
- value,
3401
- visit,
3402
- writeToFile
2883
+ value
3403
2884
  });
@@ -1,7 +1,6 @@
1
1
  export * from './api';
2
2
  export * from './client';
3
3
  export * from './db';
4
- export * from './gqm';
5
4
  export * from './migrations';
6
5
  export * from './models';
7
6
  export * from './permissions';
package/dist/esm/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
  export * from './api';
3
3
  export * from './client';
4
4
  export * from './db';
5
- export * from './gqm';
6
5
  export * from './migrations';
7
6
  export * from './models';
8
7
  export * from './permissions';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,iCAAiC;AAEjC,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,iCAAiC;AAEjC,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartive/graphql-magic",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "description": "",
5
5
  "source": "src/index.ts",
6
6
  "type": "module",
@@ -28,7 +28,7 @@
28
28
  "build": "npm run build:esm && npm run build:cjs && npm run build:bin",
29
29
  "build:esm": "tsc",
30
30
  "build:cjs": "esbuild src/index.ts --bundle --platform=node --outdir=dist/cjs --out-extension:.js=.cjs --format=cjs --packages=external",
31
- "build:bin": "esbuild src/bin/gqm.ts --bundle --platform=node --outdir=dist/bin --out-extension:.js=.cjs --format=cjs --packages=external"
31
+ "build:bin": "esbuild src/bin/gqm/gqm.ts --bundle --platform=node --outdir=dist/bin --out-extension:.js=.cjs --format=cjs --packages=external"
32
32
  },
33
33
  "bin": {
34
34
  "gqm": "dist/bin/gqm.cjs"
@@ -65,7 +65,7 @@
65
65
  "@smartive/eslint-config": "3.2.0",
66
66
  "@smartive/prettier-config": "3.1.2",
67
67
  "@types/jest": "29.5.4",
68
- "@types/lodash": "4.14.197",
68
+ "@types/lodash": "4.14.198",
69
69
  "@types/luxon": "3.3.2",
70
70
  "@types/uuid": "9.0.3",
71
71
  "create-ts-index": "1.14.0",