@contember/client-content-generator 2.0.0-alpha.3 → 2.0.0-alpha.30

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 (92) hide show
  1. package/api-extractor.json +3 -0
  2. package/dist/development/generate.cjs +1 -2
  3. package/dist/development/generate.cjs.map +1 -1
  4. package/dist/development/generate.js +1 -2
  5. package/dist/development/generate.js.map +1 -1
  6. package/dist/development/index.cjs +4 -4
  7. package/dist/development/index.js +4 -4
  8. package/dist/development/src/ContemberClientGenerator.cjs.map +1 -0
  9. package/dist/development/src/ContemberClientGenerator.js.map +1 -0
  10. package/dist/development/{EntityTypeSchemaGenerator.cjs → src/EntityTypeSchemaGenerator.cjs} +3 -2
  11. package/dist/development/src/EntityTypeSchemaGenerator.cjs.map +1 -0
  12. package/dist/development/{EntityTypeSchemaGenerator.js → src/EntityTypeSchemaGenerator.js} +3 -2
  13. package/dist/development/src/EntityTypeSchemaGenerator.js.map +1 -0
  14. package/dist/development/src/EnumTypeSchemaGenerator.cjs +22 -0
  15. package/dist/development/src/EnumTypeSchemaGenerator.cjs.map +1 -0
  16. package/dist/development/src/EnumTypeSchemaGenerator.js +22 -0
  17. package/dist/development/src/EnumTypeSchemaGenerator.js.map +1 -0
  18. package/dist/{production → development/src}/NameSchemaGenerator.cjs +3 -0
  19. package/dist/development/src/NameSchemaGenerator.cjs.map +1 -0
  20. package/dist/{production → development/src}/NameSchemaGenerator.js +3 -0
  21. package/dist/development/src/NameSchemaGenerator.js.map +1 -0
  22. package/dist/development/src/utils.cjs +6 -0
  23. package/dist/development/src/utils.cjs.map +1 -0
  24. package/dist/development/src/utils.js +6 -0
  25. package/dist/development/src/utils.js.map +1 -0
  26. package/dist/production/generate.cjs +1 -2
  27. package/dist/production/generate.cjs.map +1 -1
  28. package/dist/production/generate.js +1 -2
  29. package/dist/production/generate.js.map +1 -1
  30. package/dist/production/index.cjs +4 -4
  31. package/dist/production/index.js +4 -4
  32. package/dist/production/src/ContemberClientGenerator.cjs.map +1 -0
  33. package/dist/production/src/ContemberClientGenerator.js.map +1 -0
  34. package/dist/production/{EntityTypeSchemaGenerator.cjs → src/EntityTypeSchemaGenerator.cjs} +3 -2
  35. package/dist/production/src/EntityTypeSchemaGenerator.cjs.map +1 -0
  36. package/dist/production/{EntityTypeSchemaGenerator.js → src/EntityTypeSchemaGenerator.js} +3 -2
  37. package/dist/production/src/EntityTypeSchemaGenerator.js.map +1 -0
  38. package/dist/production/src/EnumTypeSchemaGenerator.cjs +22 -0
  39. package/dist/production/src/EnumTypeSchemaGenerator.cjs.map +1 -0
  40. package/dist/production/src/EnumTypeSchemaGenerator.js +22 -0
  41. package/dist/production/src/EnumTypeSchemaGenerator.js.map +1 -0
  42. package/dist/{development → production/src}/NameSchemaGenerator.cjs +3 -0
  43. package/dist/production/src/NameSchemaGenerator.cjs.map +1 -0
  44. package/dist/{development → production/src}/NameSchemaGenerator.js +3 -0
  45. package/dist/production/src/NameSchemaGenerator.js.map +1 -0
  46. package/dist/production/src/utils.cjs +6 -0
  47. package/dist/production/src/utils.cjs.map +1 -0
  48. package/dist/production/src/utils.js +6 -0
  49. package/dist/production/src/utils.js.map +1 -0
  50. package/dist/types/EntityTypeSchemaGenerator.d.ts.map +1 -1
  51. package/dist/types/EnumTypeSchemaGenerator.d.ts.map +1 -1
  52. package/dist/types/NameSchemaGenerator.d.ts.map +1 -1
  53. package/dist/types/tsconfig.tsbuildinfo +1 -1
  54. package/dist/types/utils.d.ts +2 -0
  55. package/dist/types/utils.d.ts.map +1 -0
  56. package/package.json +11 -17
  57. package/src/EntityTypeSchemaGenerator.ts +4 -2
  58. package/src/EnumTypeSchemaGenerator.ts +8 -3
  59. package/src/NameSchemaGenerator.ts +3 -0
  60. package/src/tsconfig.json +3 -1
  61. package/src/utils.ts +3 -0
  62. package/tests/generateEnittyTypes.test.ts +303 -0
  63. package/tests/generateEnumTypes.test.ts +28 -0
  64. package/tests/schemas.ts +73 -0
  65. package/tests/tsconfig.json +11 -0
  66. package/tsconfig.json +8 -0
  67. package/tsdoc.json +6 -0
  68. package/vitest.config.ts +3 -0
  69. package/dist/development/ContemberClientGenerator.cjs.map +0 -1
  70. package/dist/development/ContemberClientGenerator.js.map +0 -1
  71. package/dist/development/EntityTypeSchemaGenerator.cjs.map +0 -1
  72. package/dist/development/EntityTypeSchemaGenerator.js.map +0 -1
  73. package/dist/development/EnumTypeSchemaGenerator.cjs +0 -14
  74. package/dist/development/EnumTypeSchemaGenerator.cjs.map +0 -1
  75. package/dist/development/EnumTypeSchemaGenerator.js +0 -14
  76. package/dist/development/EnumTypeSchemaGenerator.js.map +0 -1
  77. package/dist/development/NameSchemaGenerator.cjs.map +0 -1
  78. package/dist/development/NameSchemaGenerator.js.map +0 -1
  79. package/dist/production/ContemberClientGenerator.cjs.map +0 -1
  80. package/dist/production/ContemberClientGenerator.js.map +0 -1
  81. package/dist/production/EntityTypeSchemaGenerator.cjs.map +0 -1
  82. package/dist/production/EntityTypeSchemaGenerator.js.map +0 -1
  83. package/dist/production/EnumTypeSchemaGenerator.cjs +0 -14
  84. package/dist/production/EnumTypeSchemaGenerator.cjs.map +0 -1
  85. package/dist/production/EnumTypeSchemaGenerator.js +0 -14
  86. package/dist/production/EnumTypeSchemaGenerator.js.map +0 -1
  87. package/dist/production/NameSchemaGenerator.cjs.map +0 -1
  88. package/dist/production/NameSchemaGenerator.js.map +0 -1
  89. /package/dist/development/{ContemberClientGenerator.cjs → src/ContemberClientGenerator.cjs} +0 -0
  90. /package/dist/development/{ContemberClientGenerator.js → src/ContemberClientGenerator.js} +0 -0
  91. /package/dist/production/{ContemberClientGenerator.cjs → src/ContemberClientGenerator.cjs} +0 -0
  92. /package/dist/production/{ContemberClientGenerator.js → src/ContemberClientGenerator.js} +0 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../build/api-extractor.json"
3
+ }
@@ -1,8 +1,7 @@
1
- #!/usr/bin/env node
2
1
  "use strict";
3
2
  const fs = require("node:fs/promises");
4
3
  const node_path = require("node:path");
5
- const ContemberClientGenerator = require("./ContemberClientGenerator.cjs");
4
+ const ContemberClientGenerator = require("./src/ContemberClientGenerator.cjs");
6
5
  function _interopNamespaceDefault(e) {
7
6
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
7
  if (e) {
@@ -1 +1 @@
1
- {"version":3,"file":"generate.cjs","sources":["../../src/generate.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { resolve, join } from 'node:path'\nimport { ContemberClientGenerator } from './ContemberClientGenerator';\n\n(async () => {\n\tconst schemaPath = process.argv[2]\n\tconst outDir = process.argv[3]\n\n\tif (!schemaPath || !outDir) {\n\t\tconsole.error(`Usage:\n\nFrom file:\nyarn contember-client-generator <schema.json> <out-dir>\n\nFrom stdin:\nyarn run --silent contember project:print-schema --format=schema | yarn contember-client-generator - <out-dir>\n`)\n\t\tprocess.exit(1)\n\t}\n\n\tconst sourceData = await (async () => {\n\t\tif (schemaPath === '-') {\n\t\t\tif (process.stdin.isTTY) {\n\t\t\t\tthrow new Error('Cannot read from stdin in TTY mode')\n\t\t\t}\n\t\t\tconst buffer = []\n\t\t\tfor await (const chunk of process.stdin) {\n\t\t\t\tbuffer.push(chunk)\n\t\t\t}\n\t\t\treturn Buffer.concat(buffer).toString('utf8')\n\t\t}\n\t\treturn await fs.readFile(resolve(process.cwd(), process.argv[2]), 'utf8')\n\t})()\n\n\tconst source = JSON.parse(sourceData)\n\n\tconst dir = resolve(process.cwd(), process.argv[3])\n\tconst generator = new ContemberClientGenerator()\n\tconst result = generator.generate(source.model)\n\tawait fs.mkdir(dir, { recursive: true })\n\tfor (const [name, content] of Object.entries(result)) {\n\t\tawait fs.writeFile(join(dir, name), content, 'utf8')\n\t}\n})().catch(e => {\n\tconsole.error(e)\n\tprocess.exit(1)\n})\n\n"],"names":["fs","resolve","ContemberClientGenerator","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;CAIC,YAAY;AACN,QAAA,aAAa,QAAQ,KAAK,CAAC;AAC3B,QAAA,SAAS,QAAQ,KAAK,CAAC;AAEzB,MAAA,CAAC,cAAc,CAAC,QAAQ;AAC3B,YAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAOf;AACC,YAAQ,KAAK,CAAC;AAAA,EACf;AAEM,QAAA,aAAa,OAAO,YAAY;AACrC,QAAI,eAAe,KAAK;AACnB,UAAA,QAAQ,MAAM,OAAO;AAClB,cAAA,IAAI,MAAM,oCAAoC;AAAA,MACrD;AACA,YAAM,SAAS,CAAA;AACE,uBAAA,SAAS,QAAQ,OAAO;AACxC,eAAO,KAAK,KAAK;AAAA,MAClB;AACA,aAAO,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM;AAAA,IAC7C;AACA,WAAO,MAAMA,cAAG,SAASC,UAAAA,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,GAAG,MAAM;AAAA,EAAA;AAGnE,QAAA,SAAS,KAAK,MAAM,UAAU;AAE9B,QAAA,MAAMA,kBAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC;AAC5C,QAAA,YAAY,IAAIC,yBAAAA;AACtB,QAAM,SAAS,UAAU,SAAS,OAAO,KAAK;AAC9C,QAAMF,cAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AACvC,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrD,UAAMA,cAAG,UAAUG,eAAK,KAAK,IAAI,GAAG,SAAS,MAAM;AAAA,EACpD;AACD,KAAK,MAAM,CAAK,MAAA;AACf,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AACf,CAAC;"}
1
+ {"version":3,"file":"generate.cjs","sources":["../../../packages/client-content-generator/src/generate.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { resolve, join } from 'node:path'\nimport { ContemberClientGenerator } from './ContemberClientGenerator';\n\n(async () => {\n\tconst schemaPath = process.argv[2]\n\tconst outDir = process.argv[3]\n\n\tif (!schemaPath || !outDir) {\n\t\tconsole.error(`Usage:\n\nFrom file:\nyarn contember-client-generator <schema.json> <out-dir>\n\nFrom stdin:\nyarn run --silent contember project:print-schema --format=schema | yarn contember-client-generator - <out-dir>\n`)\n\t\tprocess.exit(1)\n\t}\n\n\tconst sourceData = await (async () => {\n\t\tif (schemaPath === '-') {\n\t\t\tif (process.stdin.isTTY) {\n\t\t\t\tthrow new Error('Cannot read from stdin in TTY mode')\n\t\t\t}\n\t\t\tconst buffer = []\n\t\t\tfor await (const chunk of process.stdin) {\n\t\t\t\tbuffer.push(chunk)\n\t\t\t}\n\t\t\treturn Buffer.concat(buffer).toString('utf8')\n\t\t}\n\t\treturn await fs.readFile(resolve(process.cwd(), process.argv[2]), 'utf8')\n\t})()\n\n\tconst source = JSON.parse(sourceData)\n\n\tconst dir = resolve(process.cwd(), process.argv[3])\n\tconst generator = new ContemberClientGenerator()\n\tconst result = generator.generate(source.model)\n\tawait fs.mkdir(dir, { recursive: true })\n\tfor (const [name, content] of Object.entries(result)) {\n\t\tawait fs.writeFile(join(dir, name), content, 'utf8')\n\t}\n})().catch(e => {\n\tconsole.error(e)\n\tprocess.exit(1)\n})\n\n"],"names":["fs","resolve","ContemberClientGenerator","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;CAIC,YAAY;AACN,QAAA,aAAa,QAAQ,KAAK,CAAC;AAC3B,QAAA,SAAS,QAAQ,KAAK,CAAC;AAEzB,MAAA,CAAC,cAAc,CAAC,QAAQ;AAC3B,YAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAOf;AACC,YAAQ,KAAK,CAAC;AAAA,EACf;AAEM,QAAA,aAAa,OAAO,YAAY;AACrC,QAAI,eAAe,KAAK;AACnB,UAAA,QAAQ,MAAM,OAAO;AAClB,cAAA,IAAI,MAAM,oCAAoC;AAAA,MACrD;AACA,YAAM,SAAS,CAAA;AACE,uBAAA,SAAS,QAAQ,OAAO;AACxC,eAAO,KAAK,KAAK;AAAA,MAClB;AACA,aAAO,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM;AAAA,IAC7C;AACA,WAAO,MAAMA,cAAG,SAASC,UAAAA,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,GAAG,MAAM;AAAA,EAAA;AAGnE,QAAA,SAAS,KAAK,MAAM,UAAU;AAE9B,QAAA,MAAMA,kBAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC;AAC5C,QAAA,YAAY,IAAIC,yBAAAA;AACtB,QAAM,SAAS,UAAU,SAAS,OAAO,KAAK;AAC9C,QAAMF,cAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AACvC,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrD,UAAMA,cAAG,UAAUG,eAAK,KAAK,IAAI,GAAG,SAAS,MAAM;AAAA,EACpD;AACD,KAAK,MAAM,CAAK,MAAA;AACf,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AACf,CAAC;"}
@@ -1,7 +1,6 @@
1
- #!/usr/bin/env node
2
1
  import * as fs from "node:fs/promises";
3
2
  import { resolve, join } from "node:path";
4
- import { ContemberClientGenerator } from "./ContemberClientGenerator.js";
3
+ import { ContemberClientGenerator } from "./src/ContemberClientGenerator.js";
5
4
  (async () => {
6
5
  const schemaPath = process.argv[2];
7
6
  const outDir = process.argv[3];
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sources":["../../src/generate.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { resolve, join } from 'node:path'\nimport { ContemberClientGenerator } from './ContemberClientGenerator';\n\n(async () => {\n\tconst schemaPath = process.argv[2]\n\tconst outDir = process.argv[3]\n\n\tif (!schemaPath || !outDir) {\n\t\tconsole.error(`Usage:\n\nFrom file:\nyarn contember-client-generator <schema.json> <out-dir>\n\nFrom stdin:\nyarn run --silent contember project:print-schema --format=schema | yarn contember-client-generator - <out-dir>\n`)\n\t\tprocess.exit(1)\n\t}\n\n\tconst sourceData = await (async () => {\n\t\tif (schemaPath === '-') {\n\t\t\tif (process.stdin.isTTY) {\n\t\t\t\tthrow new Error('Cannot read from stdin in TTY mode')\n\t\t\t}\n\t\t\tconst buffer = []\n\t\t\tfor await (const chunk of process.stdin) {\n\t\t\t\tbuffer.push(chunk)\n\t\t\t}\n\t\t\treturn Buffer.concat(buffer).toString('utf8')\n\t\t}\n\t\treturn await fs.readFile(resolve(process.cwd(), process.argv[2]), 'utf8')\n\t})()\n\n\tconst source = JSON.parse(sourceData)\n\n\tconst dir = resolve(process.cwd(), process.argv[3])\n\tconst generator = new ContemberClientGenerator()\n\tconst result = generator.generate(source.model)\n\tawait fs.mkdir(dir, { recursive: true })\n\tfor (const [name, content] of Object.entries(result)) {\n\t\tawait fs.writeFile(join(dir, name), content, 'utf8')\n\t}\n})().catch(e => {\n\tconsole.error(e)\n\tprocess.exit(1)\n})\n\n"],"names":[],"mappings":";;;;CAIC,YAAY;AACN,QAAA,aAAa,QAAQ,KAAK,CAAC;AAC3B,QAAA,SAAS,QAAQ,KAAK,CAAC;AAEzB,MAAA,CAAC,cAAc,CAAC,QAAQ;AAC3B,YAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAOf;AACC,YAAQ,KAAK,CAAC;AAAA,EACf;AAEM,QAAA,aAAa,OAAO,YAAY;AACrC,QAAI,eAAe,KAAK;AACnB,UAAA,QAAQ,MAAM,OAAO;AAClB,cAAA,IAAI,MAAM,oCAAoC;AAAA,MACrD;AACA,YAAM,SAAS,CAAA;AACE,uBAAA,SAAS,QAAQ,OAAO;AACxC,eAAO,KAAK,KAAK;AAAA,MAClB;AACA,aAAO,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM;AAAA,IAC7C;AACA,WAAO,MAAM,GAAG,SAAS,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,GAAG,MAAM;AAAA,EAAA;AAGnE,QAAA,SAAS,KAAK,MAAM,UAAU;AAE9B,QAAA,MAAM,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC;AAC5C,QAAA,YAAY,IAAI;AACtB,QAAM,SAAS,UAAU,SAAS,OAAO,KAAK;AAC9C,QAAM,GAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AACvC,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrD,UAAM,GAAG,UAAU,KAAK,KAAK,IAAI,GAAG,SAAS,MAAM;AAAA,EACpD;AACD,KAAK,MAAM,CAAK,MAAA;AACf,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AACf,CAAC;"}
1
+ {"version":3,"file":"generate.js","sources":["../../../packages/client-content-generator/src/generate.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { resolve, join } from 'node:path'\nimport { ContemberClientGenerator } from './ContemberClientGenerator';\n\n(async () => {\n\tconst schemaPath = process.argv[2]\n\tconst outDir = process.argv[3]\n\n\tif (!schemaPath || !outDir) {\n\t\tconsole.error(`Usage:\n\nFrom file:\nyarn contember-client-generator <schema.json> <out-dir>\n\nFrom stdin:\nyarn run --silent contember project:print-schema --format=schema | yarn contember-client-generator - <out-dir>\n`)\n\t\tprocess.exit(1)\n\t}\n\n\tconst sourceData = await (async () => {\n\t\tif (schemaPath === '-') {\n\t\t\tif (process.stdin.isTTY) {\n\t\t\t\tthrow new Error('Cannot read from stdin in TTY mode')\n\t\t\t}\n\t\t\tconst buffer = []\n\t\t\tfor await (const chunk of process.stdin) {\n\t\t\t\tbuffer.push(chunk)\n\t\t\t}\n\t\t\treturn Buffer.concat(buffer).toString('utf8')\n\t\t}\n\t\treturn await fs.readFile(resolve(process.cwd(), process.argv[2]), 'utf8')\n\t})()\n\n\tconst source = JSON.parse(sourceData)\n\n\tconst dir = resolve(process.cwd(), process.argv[3])\n\tconst generator = new ContemberClientGenerator()\n\tconst result = generator.generate(source.model)\n\tawait fs.mkdir(dir, { recursive: true })\n\tfor (const [name, content] of Object.entries(result)) {\n\t\tawait fs.writeFile(join(dir, name), content, 'utf8')\n\t}\n})().catch(e => {\n\tconsole.error(e)\n\tprocess.exit(1)\n})\n\n"],"names":[],"mappings":";;;CAIC,YAAY;AACN,QAAA,aAAa,QAAQ,KAAK,CAAC;AAC3B,QAAA,SAAS,QAAQ,KAAK,CAAC;AAEzB,MAAA,CAAC,cAAc,CAAC,QAAQ;AAC3B,YAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAOf;AACC,YAAQ,KAAK,CAAC;AAAA,EACf;AAEM,QAAA,aAAa,OAAO,YAAY;AACrC,QAAI,eAAe,KAAK;AACnB,UAAA,QAAQ,MAAM,OAAO;AAClB,cAAA,IAAI,MAAM,oCAAoC;AAAA,MACrD;AACA,YAAM,SAAS,CAAA;AACE,uBAAA,SAAS,QAAQ,OAAO;AACxC,eAAO,KAAK,KAAK;AAAA,MAClB;AACA,aAAO,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM;AAAA,IAC7C;AACA,WAAO,MAAM,GAAG,SAAS,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,GAAG,MAAM;AAAA,EAAA;AAGnE,QAAA,SAAS,KAAK,MAAM,UAAU;AAE9B,QAAA,MAAM,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC;AAC5C,QAAA,YAAY,IAAI;AACtB,QAAM,SAAS,UAAU,SAAS,OAAO,KAAK;AAC9C,QAAM,GAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AACvC,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrD,UAAM,GAAG,UAAU,KAAK,KAAK,IAAI,GAAG,SAAS,MAAM;AAAA,EACpD;AACD,KAAK,MAAM,CAAK,MAAA;AACf,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AACf,CAAC;"}
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const ContemberClientGenerator = require("./ContemberClientGenerator.cjs");
4
- const EntityTypeSchemaGenerator = require("./EntityTypeSchemaGenerator.cjs");
5
- const EnumTypeSchemaGenerator = require("./EnumTypeSchemaGenerator.cjs");
6
- const NameSchemaGenerator = require("./NameSchemaGenerator.cjs");
3
+ const ContemberClientGenerator = require("./src/ContemberClientGenerator.cjs");
4
+ const EntityTypeSchemaGenerator = require("./src/EntityTypeSchemaGenerator.cjs");
5
+ const EnumTypeSchemaGenerator = require("./src/EnumTypeSchemaGenerator.cjs");
6
+ const NameSchemaGenerator = require("./src/NameSchemaGenerator.cjs");
7
7
  exports.ContemberClientGenerator = ContemberClientGenerator.ContemberClientGenerator;
8
8
  exports.EntityTypeSchemaGenerator = EntityTypeSchemaGenerator.EntityTypeSchemaGenerator;
9
9
  exports.EnumTypeSchemaGenerator = EnumTypeSchemaGenerator.EnumTypeSchemaGenerator;
@@ -1,7 +1,7 @@
1
- import { ContemberClientGenerator } from "./ContemberClientGenerator.js";
2
- import { EntityTypeSchemaGenerator } from "./EntityTypeSchemaGenerator.js";
3
- import { EnumTypeSchemaGenerator } from "./EnumTypeSchemaGenerator.js";
4
- import { NameSchemaGenerator } from "./NameSchemaGenerator.js";
1
+ import { ContemberClientGenerator } from "./src/ContemberClientGenerator.js";
2
+ import { EntityTypeSchemaGenerator } from "./src/EntityTypeSchemaGenerator.js";
3
+ import { EnumTypeSchemaGenerator } from "./src/EnumTypeSchemaGenerator.js";
4
+ import { NameSchemaGenerator } from "./src/NameSchemaGenerator.js";
5
5
  export {
6
6
  ContemberClientGenerator,
7
7
  EntityTypeSchemaGenerator,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContemberClientGenerator.cjs","sources":["../../../../packages/client-content-generator/src/ContemberClientGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { EnumTypeSchemaGenerator } from './EnumTypeSchemaGenerator'\nimport { EntityTypeSchemaGenerator } from './EntityTypeSchemaGenerator'\nimport { NameSchemaGenerator } from './NameSchemaGenerator'\n\n\nexport class ContemberClientGenerator {\n\tconstructor(\n\t\tprivate readonly nameSchemaGenerator: NameSchemaGenerator = new NameSchemaGenerator(),\n\t\tprivate readonly enumTypeSchemaGenerator: EnumTypeSchemaGenerator = new EnumTypeSchemaGenerator(),\n\t\tprivate readonly entityTypeSchemaGenerator: EntityTypeSchemaGenerator = new EntityTypeSchemaGenerator(),\n\t) {\n\t}\n\n\tgenerate(model: Model.Schema): Record<string, string> {\n\t\tconst nameSchema = this.nameSchemaGenerator.generate(model)\n\t\tconst enumTypeSchema = this.enumTypeSchemaGenerator.generate(model)\n\t\tconst entityTypeSchema = this.entityTypeSchemaGenerator.generate(model)\n\n\t\tconst namesCode = `import { SchemaNames } from '@contember/client-content'\nexport const ContemberClientNames: SchemaNames = ` + JSON.stringify(nameSchema, null, 2)\n\n\t\tconst indexCode = `\nimport { ContemberClientNames } from './names'\nimport type { ContemberClientSchema } from './entities'\nimport { ContentQueryBuilder, TypedContentQueryBuilder, TypedEntitySelection } from '@contember/client-content'\nexport * from './names'\nexport * from './enums'\nexport * from './entities'\n\nexport const queryBuilder = new ContentQueryBuilder(ContemberClientNames) as unknown as TypedContentQueryBuilder<ContemberClientSchema>\n\nexport type FragmentOf<EntityName extends keyof ContemberClientSchema['entities'] & string, Data = unknown> =\nTypedEntitySelection<ContemberClientSchema, EntityName, ContemberClientSchema['entities'][EntityName], Data>\n\nexport type FragmentType<T extends TypedEntitySelection<any, any, any, any> = any> =\nT extends TypedEntitySelection<any, any, any, infer TFields>\n\t? TFields\n\t: never\n`\n\t\treturn {\n\t\t\t'names.ts': namesCode,\n\t\t\t'enums.ts': enumTypeSchema,\n\t\t\t'entities.ts': entityTypeSchema,\n\t\t\t'index.ts': indexCode,\n\t\t}\n\t}\n}\n"],"names":["NameSchemaGenerator","EnumTypeSchemaGenerator","EntityTypeSchemaGenerator"],"mappings":";;;;;AAMO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBAA2C,IAAIA,oBAAAA,uBAC/C,0BAAmD,IAAIC,wBAAAA,2BACvD,4BAAuD,IAAIC,0BAAAA,6BAC3E;AAHgB,SAAA,sBAAA;AACA,SAAA,0BAAA;AACA,SAAA,4BAAA;AAAA,EAElB;AAAA,EAEA,SAAS,OAA6C;AACrD,UAAM,aAAa,KAAK,oBAAoB,SAAS,KAAK;AAC1D,UAAM,iBAAiB,KAAK,wBAAwB,SAAS,KAAK;AAClE,UAAM,mBAAmB,KAAK,0BAA0B,SAAS,KAAK;AAEtE,UAAM,YAAY;AAAA,qDACiC,KAAK,UAAU,YAAY,MAAM,CAAC;AAErF,UAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBX,WAAA;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,YAAY;AAAA,IAAA;AAAA,EAEd;AACD;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContemberClientGenerator.js","sources":["../../../../packages/client-content-generator/src/ContemberClientGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { EnumTypeSchemaGenerator } from './EnumTypeSchemaGenerator'\nimport { EntityTypeSchemaGenerator } from './EntityTypeSchemaGenerator'\nimport { NameSchemaGenerator } from './NameSchemaGenerator'\n\n\nexport class ContemberClientGenerator {\n\tconstructor(\n\t\tprivate readonly nameSchemaGenerator: NameSchemaGenerator = new NameSchemaGenerator(),\n\t\tprivate readonly enumTypeSchemaGenerator: EnumTypeSchemaGenerator = new EnumTypeSchemaGenerator(),\n\t\tprivate readonly entityTypeSchemaGenerator: EntityTypeSchemaGenerator = new EntityTypeSchemaGenerator(),\n\t) {\n\t}\n\n\tgenerate(model: Model.Schema): Record<string, string> {\n\t\tconst nameSchema = this.nameSchemaGenerator.generate(model)\n\t\tconst enumTypeSchema = this.enumTypeSchemaGenerator.generate(model)\n\t\tconst entityTypeSchema = this.entityTypeSchemaGenerator.generate(model)\n\n\t\tconst namesCode = `import { SchemaNames } from '@contember/client-content'\nexport const ContemberClientNames: SchemaNames = ` + JSON.stringify(nameSchema, null, 2)\n\n\t\tconst indexCode = `\nimport { ContemberClientNames } from './names'\nimport type { ContemberClientSchema } from './entities'\nimport { ContentQueryBuilder, TypedContentQueryBuilder, TypedEntitySelection } from '@contember/client-content'\nexport * from './names'\nexport * from './enums'\nexport * from './entities'\n\nexport const queryBuilder = new ContentQueryBuilder(ContemberClientNames) as unknown as TypedContentQueryBuilder<ContemberClientSchema>\n\nexport type FragmentOf<EntityName extends keyof ContemberClientSchema['entities'] & string, Data = unknown> =\nTypedEntitySelection<ContemberClientSchema, EntityName, ContemberClientSchema['entities'][EntityName], Data>\n\nexport type FragmentType<T extends TypedEntitySelection<any, any, any, any> = any> =\nT extends TypedEntitySelection<any, any, any, infer TFields>\n\t? TFields\n\t: never\n`\n\t\treturn {\n\t\t\t'names.ts': namesCode,\n\t\t\t'enums.ts': enumTypeSchema,\n\t\t\t'entities.ts': entityTypeSchema,\n\t\t\t'index.ts': indexCode,\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;AAMO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBAA2C,IAAI,uBAC/C,0BAAmD,IAAI,2BACvD,4BAAuD,IAAI,6BAC3E;AAHgB,SAAA,sBAAA;AACA,SAAA,0BAAA;AACA,SAAA,4BAAA;AAAA,EAElB;AAAA,EAEA,SAAS,OAA6C;AACrD,UAAM,aAAa,KAAK,oBAAoB,SAAS,KAAK;AAC1D,UAAM,iBAAiB,KAAK,wBAAwB,SAAS,KAAK;AAClE,UAAM,mBAAmB,KAAK,0BAA0B,SAAS,KAAK;AAEtE,UAAM,YAAY;AAAA,qDACiC,KAAK,UAAU,YAAY,MAAM,CAAC;AAErF,UAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBX,WAAA;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,YAAY;AAAA,IAAA;AAAA,EAEd;AACD;"}
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const schema = require("@contember/schema");
4
4
  const schemaUtils = require("@contember/schema-utils");
5
+ const utils = require("./utils.cjs");
5
6
  class EntityTypeSchemaGenerator {
6
7
  generate(model) {
7
8
  let code = "";
8
9
  for (const enumName of Object.keys(model.enums)) {
9
- code += `import type { ${enumName} } from './enums'
10
+ code += `import type { ${utils.getEnumTypeName(enumName)} } from './enums'
10
11
  `;
11
12
  }
12
13
  code += `
@@ -130,7 +131,7 @@ const uniqueType = (model, entity, field) => {
130
131
  const columnToTsType = (column) => {
131
132
  switch (column.type) {
132
133
  case schema.Model.ColumnType.Enum:
133
- return column.columnType;
134
+ return utils.getEnumTypeName(column.columnType);
134
135
  case schema.Model.ColumnType.String:
135
136
  return "string";
136
137
  case schema.Model.ColumnType.Int:
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityTypeSchemaGenerator.cjs","sources":["../../../../packages/client-content-generator/src/EntityTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor, acceptFieldVisitor } from '@contember/schema-utils'\n\nimport { getEnumTypeName } from './utils'\n\nexport class EntityTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `import type { ${getEnumTypeName(enumName)} } from './enums'\\n`\n\t\t}\n\n\t\tcode += `\nexport type JSONPrimitive = string | number | boolean | null\nexport type JSONValue = JSONPrimitive | JSONObject | JSONArray\nexport type JSONObject = { readonly [K in string]?: JSONValue }\nexport type JSONArray = readonly JSONValue[]\n\n`\n\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += this.generateTypeEntityCode(model, entity)\n\t\t}\n\t\tcode += '\\n'\n\t\tcode += `export type ContemberClientEntities = {\\n`\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += `\\t${entity.name}: ${entity.name}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\tcode += `export type ContemberClientSchema = {\\n`\n\t\tcode += '\\tentities: ContemberClientEntities\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate generateTypeEntityCode(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = `export type ${entity.name} <OverRelation extends string | never = never> = {\\n`\n\t\tcode += '\\tname: \\'' + entity.name + '\\'\\n'\n\t\tcode += '\\tunique:\\n'\n\t\tcode += this.formatUniqueFields(model, entity)\n\t\tlet columnsCode = ''\n\t\tlet hasOneCode = ''\n\t\tlet hasManyCode = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitHasMany: ctx => {\n\t\t\t\thasManyCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}${ctx.targetRelation?.type === Model.RelationType.ManyHasOne ? `<'${ctx.targetRelation.name}'>` : ''}\\n`\n\t\t\t},\n\t\t\tvisitHasOne: ctx => {\n\t\t\t\thasOneCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}\\n`\n\t\t\t},\n\t\t\tvisitColumn: ctx => {\n\t\t\t\tcolumnsCode += `\\t\\t${ctx.column.name}: ${columnToTsType(ctx.column)}${ctx.column.nullable ? ` | null` : ''}\\n`\n\t\t\t},\n\t\t})\n\n\t\tcode += '\\tcolumns: {\\n'\n\t\tcode += columnsCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasOne: {\\n'\n\t\tcode += hasOneCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasMany: {\\n'\n\t\tcode += hasManyCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasManyBy: {\\n'\n\t\tcode += this.formatReducedFields(model, entity)\n\t\tcode += '\\t}\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate formatReducedFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitOneHasMany: ({ entity, relation, targetEntity, targetRelation }) => {\n\t\t\t\tif (!targetRelation) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst uniqueConstraints = getFieldsForUniqueWhere(model, targetEntity)\n\t\t\t\tconst composedUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 2) //todo support all uniques\n\t\t\t\t\t.filter(fields => fields.includes(targetRelation.name))\n\t\t\t\t\t.map(fields => fields.filter(it => it !== targetRelation.name))\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\tconst singleUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 1 && fields[0] !== targetEntity.primary)\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\t\t.filter(it => it !== targetRelation.name)\n\n\t\t\t\t;[...composedUnique, ...singleUnique].forEach(fieldName => {\n\t\t\t\t\tconst capitalizeFirstLetter = (value: string) => {\n\t\t\t\t\t\treturn value.charAt(0).toUpperCase() + value.slice(1)\n\t\t\t\t\t}\n\t\t\t\t\tconst name = `${relation.name}By${capitalizeFirstLetter(fieldName)}`\n\n\t\t\t\t\tconst targetUnique = targetEntity.fields[fieldName]\n\n\t\t\t\t\tcode += `\\t\\t${name}: { entity: ${targetEntity.name}; by: {${fieldName}: ${uniqueType(model, targetEntity, targetUnique)}} }\\n`\n\n\t\t\t\t})\n\t\t\t},\n\t\t\tvisitColumn: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyOwning: () => {\n\t\t\t},\n\t\t\tvisitManyHasOne: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneInverse: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneOwning: () => {\n\t\t\t},\n\t\t})\n\t\treturn code\n\t}\n\n\tprivate formatUniqueFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tconst fields = getFieldsForUniqueWhere(model, entity)\n\t\tlet code = ''\n\t\tfor (const field of fields) {\n\t\t\tcode += '\\t\\t| Omit<{ '\n\t\t\tcode += field.map(it => `${it}: ${uniqueType(model, entity, entity.fields[it])}`).join(', ')\n\t\t\tcode += '}, OverRelation>\\n'\n\t\t}\n\t\treturn code\n\t}\n}\n\n\nconst uniqueType = (model: Model.Schema, entity: Model.Entity, field: Model.AnyField): string => {\n\treturn acceptFieldVisitor(model, entity, field, {\n\t\tvisitColumn: ctx => {\n\t\t\treturn columnToTsType(ctx.column)\n\t\t},\n\t\tvisitRelation: ctx => {\n\t\t\treturn ctx.targetEntity.name + `['unique']`\n\t\t},\n\t})\n}\n\n\nconst columnToTsType = (column: Model.AnyColumn): string => {\n\tswitch (column.type) {\n\t\tcase Model.ColumnType.Enum:\n\t\t\treturn getEnumTypeName(column.columnType)\n\t\tcase Model.ColumnType.String:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Int:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Double:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Bool:\n\t\t\treturn 'boolean'\n\t\tcase Model.ColumnType.DateTime:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Date:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Json:\n\t\t\treturn 'JSONValue'\n\t\tcase Model.ColumnType.Uuid:\n\t\t\treturn 'string'\n\t\tdefault:\n\t\t\t((_: never) => {\n\t\t\t\tthrow new Error(`Unknown type ${_}`)\n\t\t\t})(column.type)\n\t}\n}\n\nconst getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (readonly string[])[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...Object.values(entity.unique).map(it => it.fields), ...relations]\n}\n"],"names":["getEnumTypeName","acceptEveryFieldVisitor","Model","entity","acceptFieldVisitor","schema"],"mappings":";;;;;AAKO,MAAM,0BAA0B;AAAA,EACtC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACX,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AACxC,cAAA,iBAAiBA,MAAgB,gBAAA,QAAQ,CAAC;AAAA;AAAA,IACnD;AAEQ,YAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AAC3C,cAAA,KAAK,uBAAuB,OAAO,MAAM;AAAA,IAClD;AACQ,YAAA;AACA,YAAA;AAAA;AACR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AACnD,cAAQ,IAAK,OAAO,IAAI,KAAK,OAAO,IAAI;AAAA;AAAA,IACzC;AACQ,YAAA;AACA,YAAA;AAAA;AACA,YAAA;AACA,YAAA;AACD,WAAA;AAAA,EACR;AAAA,EAEQ,uBAAuB,OAAqB,QAA8B;AAC7E,QAAA,OAAO,eAAe,OAAO,IAAI;AAAA;AAC7B,YAAA,aAAe,OAAO,OAAO;AAC7B,YAAA;AACA,YAAA,KAAK,mBAAmB,OAAO,MAAM;AAC7C,QAAI,cAAc;AAClB,QAAI,aAAa;AACjB,QAAI,cAAc;AAClBC,gBAAA,wBAAwB,OAAO,QAAQ;AAAA,MACtC,cAAc,CAAO,QAAA;AACL,uBAAA,KAAO,IAA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,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC7F;;"}
@@ -1,10 +1,11 @@
1
1
  import { Model } from "@contember/schema";
2
2
  import { acceptEveryFieldVisitor, acceptFieldVisitor } from "@contember/schema-utils";
3
+ import { getEnumTypeName } from "./utils.js";
3
4
  class EntityTypeSchemaGenerator {
4
5
  generate(model) {
5
6
  let code = "";
6
7
  for (const enumName of Object.keys(model.enums)) {
7
- code += `import type { ${enumName} } from './enums'
8
+ code += `import type { ${getEnumTypeName(enumName)} } from './enums'
8
9
  `;
9
10
  }
10
11
  code += `
@@ -128,7 +129,7 @@ const uniqueType = (model, entity, field) => {
128
129
  const columnToTsType = (column) => {
129
130
  switch (column.type) {
130
131
  case Model.ColumnType.Enum:
131
- return column.columnType;
132
+ return getEnumTypeName(column.columnType);
132
133
  case Model.ColumnType.String:
133
134
  return "string";
134
135
  case Model.ColumnType.Int:
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityTypeSchemaGenerator.js","sources":["../../../../packages/client-content-generator/src/EntityTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor, acceptFieldVisitor } from '@contember/schema-utils'\n\nimport { getEnumTypeName } from './utils'\n\nexport class EntityTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `import type { ${getEnumTypeName(enumName)} } from './enums'\\n`\n\t\t}\n\n\t\tcode += `\nexport type JSONPrimitive = string | number | boolean | null\nexport type JSONValue = JSONPrimitive | JSONObject | JSONArray\nexport type JSONObject = { readonly [K in string]?: JSONValue }\nexport type JSONArray = readonly JSONValue[]\n\n`\n\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += this.generateTypeEntityCode(model, entity)\n\t\t}\n\t\tcode += '\\n'\n\t\tcode += `export type ContemberClientEntities = {\\n`\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += `\\t${entity.name}: ${entity.name}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\tcode += `export type ContemberClientSchema = {\\n`\n\t\tcode += '\\tentities: ContemberClientEntities\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate generateTypeEntityCode(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = `export type ${entity.name} <OverRelation extends string | never = never> = {\\n`\n\t\tcode += '\\tname: \\'' + entity.name + '\\'\\n'\n\t\tcode += '\\tunique:\\n'\n\t\tcode += this.formatUniqueFields(model, entity)\n\t\tlet columnsCode = ''\n\t\tlet hasOneCode = ''\n\t\tlet hasManyCode = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitHasMany: ctx => {\n\t\t\t\thasManyCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}${ctx.targetRelation?.type === Model.RelationType.ManyHasOne ? `<'${ctx.targetRelation.name}'>` : ''}\\n`\n\t\t\t},\n\t\t\tvisitHasOne: ctx => {\n\t\t\t\thasOneCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}\\n`\n\t\t\t},\n\t\t\tvisitColumn: ctx => {\n\t\t\t\tcolumnsCode += `\\t\\t${ctx.column.name}: ${columnToTsType(ctx.column)}${ctx.column.nullable ? ` | null` : ''}\\n`\n\t\t\t},\n\t\t})\n\n\t\tcode += '\\tcolumns: {\\n'\n\t\tcode += columnsCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasOne: {\\n'\n\t\tcode += hasOneCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasMany: {\\n'\n\t\tcode += hasManyCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasManyBy: {\\n'\n\t\tcode += this.formatReducedFields(model, entity)\n\t\tcode += '\\t}\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate formatReducedFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitOneHasMany: ({ entity, relation, targetEntity, targetRelation }) => {\n\t\t\t\tif (!targetRelation) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst uniqueConstraints = getFieldsForUniqueWhere(model, targetEntity)\n\t\t\t\tconst composedUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 2) //todo support all uniques\n\t\t\t\t\t.filter(fields => fields.includes(targetRelation.name))\n\t\t\t\t\t.map(fields => fields.filter(it => it !== targetRelation.name))\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\tconst singleUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 1 && fields[0] !== targetEntity.primary)\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\t\t.filter(it => it !== targetRelation.name)\n\n\t\t\t\t;[...composedUnique, ...singleUnique].forEach(fieldName => {\n\t\t\t\t\tconst capitalizeFirstLetter = (value: string) => {\n\t\t\t\t\t\treturn value.charAt(0).toUpperCase() + value.slice(1)\n\t\t\t\t\t}\n\t\t\t\t\tconst name = `${relation.name}By${capitalizeFirstLetter(fieldName)}`\n\n\t\t\t\t\tconst targetUnique = targetEntity.fields[fieldName]\n\n\t\t\t\t\tcode += `\\t\\t${name}: { entity: ${targetEntity.name}; by: {${fieldName}: ${uniqueType(model, targetEntity, targetUnique)}} }\\n`\n\n\t\t\t\t})\n\t\t\t},\n\t\t\tvisitColumn: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyOwning: () => {\n\t\t\t},\n\t\t\tvisitManyHasOne: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneInverse: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneOwning: () => {\n\t\t\t},\n\t\t})\n\t\treturn code\n\t}\n\n\tprivate formatUniqueFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tconst fields = getFieldsForUniqueWhere(model, entity)\n\t\tlet code = ''\n\t\tfor (const field of fields) {\n\t\t\tcode += '\\t\\t| Omit<{ '\n\t\t\tcode += field.map(it => `${it}: ${uniqueType(model, entity, entity.fields[it])}`).join(', ')\n\t\t\tcode += '}, OverRelation>\\n'\n\t\t}\n\t\treturn code\n\t}\n}\n\n\nconst uniqueType = (model: Model.Schema, entity: Model.Entity, field: Model.AnyField): string => {\n\treturn acceptFieldVisitor(model, entity, field, {\n\t\tvisitColumn: ctx => {\n\t\t\treturn columnToTsType(ctx.column)\n\t\t},\n\t\tvisitRelation: ctx => {\n\t\t\treturn ctx.targetEntity.name + `['unique']`\n\t\t},\n\t})\n}\n\n\nconst columnToTsType = (column: Model.AnyColumn): string => {\n\tswitch (column.type) {\n\t\tcase Model.ColumnType.Enum:\n\t\t\treturn getEnumTypeName(column.columnType)\n\t\tcase Model.ColumnType.String:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Int:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Double:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Bool:\n\t\t\treturn 'boolean'\n\t\tcase Model.ColumnType.DateTime:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Date:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Json:\n\t\t\treturn 'JSONValue'\n\t\tcase Model.ColumnType.Uuid:\n\t\t\treturn 'string'\n\t\tdefault:\n\t\t\t((_: never) => {\n\t\t\t\tthrow new Error(`Unknown type ${_}`)\n\t\t\t})(column.type)\n\t}\n}\n\nconst getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (readonly string[])[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...Object.values(entity.unique).map(it => it.fields), ...relations]\n}\n"],"names":["entity"],"mappings":";;;AAKO,MAAM,0BAA0B;AAAA,EACtC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACX,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AACxC,cAAA,iBAAiB,gBAAgB,QAAQ,CAAC;AAAA;AAAA,IACnD;AAEQ,YAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AAC3C,cAAA,KAAK,uBAAuB,OAAO,MAAM;AAAA,IAClD;AACQ,YAAA;AACA,YAAA;AAAA;AACR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AACnD,cAAQ,IAAK,OAAO,IAAI,KAAK,OAAO,IAAI;AAAA;AAAA,IACzC;AACQ,YAAA;AACA,YAAA;AAAA;AACA,YAAA;AACA,YAAA;AACD,WAAA;AAAA,EACR;AAAA,EAEQ,uBAAuB,OAAqB,QAA8B;AAC7E,QAAA,OAAO,eAAe,OAAO,IAAI;AAAA;AAC7B,YAAA,aAAe,OAAO,OAAO;AAC7B,YAAA;AACA,YAAA,KAAK,mBAAmB,OAAO,MAAM;AAC7C,QAAI,cAAc;AAClB,QAAI,aAAa;AACjB,QAAI,cAAc;AAClB,4BAAwB,OAAO,QAAQ;AAAA,MACtC,cAAc,CAAO,QAAA;AACL,uBAAA,KAAO,IAAI,SAAS,IAAI,KAAK,IAAI,aAAa,IAAI,GAAG,IAAI,gBAAgB,SAAS,MAAM,aAAa,aAAa,KAAK,IAAI,eAAe,IAAI,OAAO,EAAE;AAAA;AAAA,MACvK;AAAA,MACA,aAAa,CAAO,QAAA;AACnB,sBAAc,KAAO,IAAI,SAAS,IAAI,KAAK,IAAI,aAAa,IAAI;AAAA;AA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AW;AACd,aAAA;AAAA,IACR,KAAK,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAK,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAK,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAK,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAK,MAAM,WAAW;AACd,aAAA;AAAA,IACR;AACC,OAAC,CAAC,MAAa;AACd,cAAM,IAAI,MAAM,gBAAgB,CAAC,EAAE;AAAA,MAAA,GACjC,OAAO,IAAI;AAAA,EAChB;AACD;AAEA,MAAM,0BAA0B,CAAC,QAAsB,WAAyD;AAC/G,QAAM,YAAY,OAAO;AAAA,IACxB,wBAA8C,QAAQ,QAAQ;AAAA,MAC7D,aAAa,MAAM;AAAA,MACnB,yBAAyB,MAAM;AAAA,MAC/B,wBAAwB,MAAM;AAAA,MAC9B,iBAAiB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,MACjD,iBAAiB,MAAM;AAAA,MACvB,uBAAuB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,MACvD,sBAAsB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,IAAA,CACtD;AAAA,IACA,OAAO,CAAC,OAAuB,CAAC,CAAC,EAAE;AAErC,SAAO,CAAC,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM,EAAE,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC7F;"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils = require("./utils.cjs");
4
+ class EnumTypeSchemaGenerator {
5
+ generate(model) {
6
+ let code = "";
7
+ for (const [enumName, values] of Object.entries(model.enums)) {
8
+ code += `export type ${utils.getEnumTypeName(enumName)} = ${values.map((it) => "\n | " + JSON.stringify(it)).join("")}
9
+ `;
10
+ }
11
+ code += `export type ContemberClientEnums = {
12
+ `;
13
+ for (const enumName of Object.keys(model.enums)) {
14
+ code += ` ${enumName}: ${utils.getEnumTypeName(enumName)}
15
+ `;
16
+ }
17
+ code += "}\n\n";
18
+ return code;
19
+ }
20
+ }
21
+ exports.EnumTypeSchemaGenerator = EnumTypeSchemaGenerator;
22
+ //# sourceMappingURL=EnumTypeSchemaGenerator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnumTypeSchemaGenerator.cjs","sources":["../../../../packages/client-content-generator/src/EnumTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { getEnumTypeName } from './utils'\n\nexport class EnumTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const [enumName, values] of Object.entries(model.enums)) {\n\t\t\tcode += `export type ${getEnumTypeName(enumName)} = ${values.map(it => '\\n\\t | ' + JSON.stringify(it)).join('')}\\n`\n\t\t}\n\t\tcode += `export type ContemberClientEnums = {\\n`\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `\\t${enumName}: ${getEnumTypeName(enumName)}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\treturn code\n\t}\n}\n"],"names":["getEnumTypeName"],"mappings":";;;AAGO,MAAM,wBAAwB;AAAA,EACpC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACA,eAAA,CAAC,UAAU,MAAM,KAAK,OAAO,QAAQ,MAAM,KAAK,GAAG;AAC7D,cAAQ,eAAeA,MAAgB,gBAAA,QAAQ,CAAC,MAAM,OAAO,IAAI,CAAA,OAAM,WAAY,KAAK,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAAA;AAAA,IAChH;AACQ,YAAA;AAAA;AACR,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AAChD,cAAQ,IAAK,QAAQ,KAAKA,MAAAA,gBAAgB,QAAQ,CAAC;AAAA;AAAA,IACpD;AACQ,YAAA;AACD,WAAA;AAAA,EACR;AACD;;"}
@@ -0,0 +1,22 @@
1
+ import { getEnumTypeName } from "./utils.js";
2
+ class EnumTypeSchemaGenerator {
3
+ generate(model) {
4
+ let code = "";
5
+ for (const [enumName, values] of Object.entries(model.enums)) {
6
+ code += `export type ${getEnumTypeName(enumName)} = ${values.map((it) => "\n | " + JSON.stringify(it)).join("")}
7
+ `;
8
+ }
9
+ code += `export type ContemberClientEnums = {
10
+ `;
11
+ for (const enumName of Object.keys(model.enums)) {
12
+ code += ` ${enumName}: ${getEnumTypeName(enumName)}
13
+ `;
14
+ }
15
+ code += "}\n\n";
16
+ return code;
17
+ }
18
+ }
19
+ export {
20
+ EnumTypeSchemaGenerator
21
+ };
22
+ //# sourceMappingURL=EnumTypeSchemaGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnumTypeSchemaGenerator.js","sources":["../../../../packages/client-content-generator/src/EnumTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { getEnumTypeName } from './utils'\n\nexport class EnumTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const [enumName, values] of Object.entries(model.enums)) {\n\t\t\tcode += `export type ${getEnumTypeName(enumName)} = ${values.map(it => '\\n\\t | ' + JSON.stringify(it)).join('')}\\n`\n\t\t}\n\t\tcode += `export type ContemberClientEnums = {\\n`\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `\\t${enumName}: ${getEnumTypeName(enumName)}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\treturn code\n\t}\n}\n"],"names":[],"mappings":";AAGO,MAAM,wBAAwB;AAAA,EACpC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACA,eAAA,CAAC,UAAU,MAAM,KAAK,OAAO,QAAQ,MAAM,KAAK,GAAG;AAC7D,cAAQ,eAAe,gBAAgB,QAAQ,CAAC,MAAM,OAAO,IAAI,CAAA,OAAM,WAAY,KAAK,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAAA;AAAA,IAChH;AACQ,YAAA;AAAA;AACR,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AAChD,cAAQ,IAAK,QAAQ,KAAK,gBAAgB,QAAQ,CAAC;AAAA;AAAA,IACpD;AACQ,YAAA;AACD,WAAA;AAAA,EACR;AACD;"}
@@ -30,6 +30,9 @@ class NameSchemaGenerator {
30
30
  });
31
31
  return [entity.name, { name: entity.name, fields, scalars }];
32
32
  })
33
+ ),
34
+ enums: Object.fromEntries(
35
+ Object.entries(model.enums).map(([name, enumType]) => [name, enumType])
33
36
  )
34
37
  };
35
38
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NameSchemaGenerator.cjs","sources":["../../../../packages/client-content-generator/src/NameSchemaGenerator.ts"],"sourcesContent":["import { SchemaNames, SchemaEntityNames } from '@contember/client-content'\nimport { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor } from '@contember/schema-utils'\n\nexport class NameSchemaGenerator {\n\tgenerate(model: Model.Schema): SchemaNames {\n\t\treturn {\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tObject.values(model.entities).map(entity => {\n\t\t\t\t\tconst fields: Record<string, SchemaEntityNames<any>['fields'][string]> = {}\n\t\t\t\t\tconst scalars: string[] = []\n\n\t\t\t\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\t\t\t\tvisitHasOne: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'one',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitHasMany: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'many',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitColumn: ctx => {\n\t\t\t\t\t\t\tscalars.push(ctx.column.name)\n\t\t\t\t\t\t\tfields[ctx.column.name] = {\n\t\t\t\t\t\t\t\ttype: 'column',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\n\t\t\t\t\treturn [entity.name, { name: entity.name, fields, scalars }]\n\t\t\t\t}),\n\t\t\t),\n\t\t\tenums: Object.fromEntries(\n\t\t\t\tObject.entries(model.enums).map(([name, enumType]) => [name, enumType]),\n\t\t\t),\n\t\t}\n\t}\n}\n\n\n"],"names":["acceptEveryFieldVisitor"],"mappings":";;;AAIO,MAAM,oBAAoB;AAAA,EAChC,SAAS,OAAkC;AACnC,WAAA;AAAA,MACN,UAAU,OAAO;AAAA,QAChB,OAAO,OAAO,MAAM,QAAQ,EAAE,IAAI,CAAU,WAAA;AAC3C,gBAAM,SAAmE,CAAA;AACzE,gBAAM,UAAoB,CAAA;AAE1BA,sBAAA,wBAAwB,OAAO,QAAQ;AAAA,YACtC,aAAa,CAAO,QAAA;AACZ,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,cAAc,CAAO,QAAA;AACb,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,aAAa,CAAO,QAAA;AACX,sBAAA,KAAK,IAAI,OAAO,IAAI;AACrB,qBAAA,IAAI,OAAO,IAAI,IAAI;AAAA,gBACzB,MAAM;AAAA,cAAA;AAAA,YAER;AAAA,UAAA,CACA;AAEM,iBAAA,CAAC,OAAO,MAAM,EAAE,MAAM,OAAO,MAAM,QAAQ,QAAA,CAAS;AAAA,QAAA,CAC3D;AAAA,MACF;AAAA,MACA,OAAO,OAAO;AAAA,QACb,OAAO,QAAQ,MAAM,KAAK,EAAE,IAAI,CAAC,CAAC,MAAM,QAAQ,MAAM,CAAC,MAAM,QAAQ,CAAC;AAAA,MACvE;AAAA,IAAA;AAAA,EAEF;AACD;;"}
@@ -28,6 +28,9 @@ class NameSchemaGenerator {
28
28
  });
29
29
  return [entity.name, { name: entity.name, fields, scalars }];
30
30
  })
31
+ ),
32
+ enums: Object.fromEntries(
33
+ Object.entries(model.enums).map(([name, enumType]) => [name, enumType])
31
34
  )
32
35
  };
33
36
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NameSchemaGenerator.js","sources":["../../../../packages/client-content-generator/src/NameSchemaGenerator.ts"],"sourcesContent":["import { SchemaNames, SchemaEntityNames } from '@contember/client-content'\nimport { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor } from '@contember/schema-utils'\n\nexport class NameSchemaGenerator {\n\tgenerate(model: Model.Schema): SchemaNames {\n\t\treturn {\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tObject.values(model.entities).map(entity => {\n\t\t\t\t\tconst fields: Record<string, SchemaEntityNames<any>['fields'][string]> = {}\n\t\t\t\t\tconst scalars: string[] = []\n\n\t\t\t\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\t\t\t\tvisitHasOne: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'one',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitHasMany: ctx => {\n\t\t\t\t\t\t\tfields[ctx.relation.name] = {\n\t\t\t\t\t\t\t\ttype: 'many',\n\t\t\t\t\t\t\t\tentity: ctx.targetEntity.name,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvisitColumn: ctx => {\n\t\t\t\t\t\t\tscalars.push(ctx.column.name)\n\t\t\t\t\t\t\tfields[ctx.column.name] = {\n\t\t\t\t\t\t\t\ttype: 'column',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\n\t\t\t\t\treturn [entity.name, { name: entity.name, fields, scalars }]\n\t\t\t\t}),\n\t\t\t),\n\t\t\tenums: Object.fromEntries(\n\t\t\t\tObject.entries(model.enums).map(([name, enumType]) => [name, enumType]),\n\t\t\t),\n\t\t}\n\t}\n}\n\n\n"],"names":[],"mappings":";AAIO,MAAM,oBAAoB;AAAA,EAChC,SAAS,OAAkC;AACnC,WAAA;AAAA,MACN,UAAU,OAAO;AAAA,QAChB,OAAO,OAAO,MAAM,QAAQ,EAAE,IAAI,CAAU,WAAA;AAC3C,gBAAM,SAAmE,CAAA;AACzE,gBAAM,UAAoB,CAAA;AAE1B,kCAAwB,OAAO,QAAQ;AAAA,YACtC,aAAa,CAAO,QAAA;AACZ,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,cAAc,CAAO,QAAA;AACb,qBAAA,IAAI,SAAS,IAAI,IAAI;AAAA,gBAC3B,MAAM;AAAA,gBACN,QAAQ,IAAI,aAAa;AAAA,cAAA;AAAA,YAE3B;AAAA,YACA,aAAa,CAAO,QAAA;AACX,sBAAA,KAAK,IAAI,OAAO,IAAI;AACrB,qBAAA,IAAI,OAAO,IAAI,IAAI;AAAA,gBACzB,MAAM;AAAA,cAAA;AAAA,YAER;AAAA,UAAA,CACA;AAEM,iBAAA,CAAC,OAAO,MAAM,EAAE,MAAM,OAAO,MAAM,QAAQ,QAAA,CAAS;AAAA,QAAA,CAC3D;AAAA,MACF;AAAA,MACA,OAAO,OAAO;AAAA,QACb,OAAO,QAAQ,MAAM,KAAK,EAAE,IAAI,CAAC,CAAC,MAAM,QAAQ,MAAM,CAAC,MAAM,QAAQ,CAAC;AAAA,MACvE;AAAA,IAAA;AAAA,EAEF;AACD;"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const upperCaseFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
4
+ const getEnumTypeName = (enumName) => upperCaseFirstLetter(enumName);
5
+ exports.getEnumTypeName = getEnumTypeName;
6
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sources":["../../../../packages/client-content-generator/src/utils.ts"],"sourcesContent":["const upperCaseFirstLetter = (str: string): string => str.charAt(0).toUpperCase() + str.slice(1)\n\nexport const getEnumTypeName = (enumName: string): string => upperCaseFirstLetter(enumName)\n"],"names":[],"mappings":";;AAAA,MAAM,uBAAuB,CAAC,QAAwB,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAExF,MAAM,kBAAkB,CAAC,aAA6B,qBAAqB,QAAQ;;"}
@@ -0,0 +1,6 @@
1
+ const upperCaseFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
2
+ const getEnumTypeName = (enumName) => upperCaseFirstLetter(enumName);
3
+ export {
4
+ getEnumTypeName
5
+ };
6
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../../packages/client-content-generator/src/utils.ts"],"sourcesContent":["const upperCaseFirstLetter = (str: string): string => str.charAt(0).toUpperCase() + str.slice(1)\n\nexport const getEnumTypeName = (enumName: string): string => upperCaseFirstLetter(enumName)\n"],"names":[],"mappings":"AAAA,MAAM,uBAAuB,CAAC,QAAwB,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAExF,MAAM,kBAAkB,CAAC,aAA6B,qBAAqB,QAAQ;"}
@@ -1,8 +1,7 @@
1
- #!/usr/bin/env node
2
1
  "use strict";
3
2
  const fs = require("node:fs/promises");
4
3
  const node_path = require("node:path");
5
- const ContemberClientGenerator = require("./ContemberClientGenerator.cjs");
4
+ const ContemberClientGenerator = require("./src/ContemberClientGenerator.cjs");
6
5
  function _interopNamespaceDefault(e) {
7
6
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
7
  if (e) {
@@ -1 +1 @@
1
- {"version":3,"file":"generate.cjs","sources":["../../src/generate.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { resolve, join } from 'node:path'\nimport { ContemberClientGenerator } from './ContemberClientGenerator';\n\n(async () => {\n\tconst schemaPath = process.argv[2]\n\tconst outDir = process.argv[3]\n\n\tif (!schemaPath || !outDir) {\n\t\tconsole.error(`Usage:\n\nFrom file:\nyarn contember-client-generator <schema.json> <out-dir>\n\nFrom stdin:\nyarn run --silent contember project:print-schema --format=schema | yarn contember-client-generator - <out-dir>\n`)\n\t\tprocess.exit(1)\n\t}\n\n\tconst sourceData = await (async () => {\n\t\tif (schemaPath === '-') {\n\t\t\tif (process.stdin.isTTY) {\n\t\t\t\tthrow new Error('Cannot read from stdin in TTY mode')\n\t\t\t}\n\t\t\tconst buffer = []\n\t\t\tfor await (const chunk of process.stdin) {\n\t\t\t\tbuffer.push(chunk)\n\t\t\t}\n\t\t\treturn Buffer.concat(buffer).toString('utf8')\n\t\t}\n\t\treturn await fs.readFile(resolve(process.cwd(), process.argv[2]), 'utf8')\n\t})()\n\n\tconst source = JSON.parse(sourceData)\n\n\tconst dir = resolve(process.cwd(), process.argv[3])\n\tconst generator = new ContemberClientGenerator()\n\tconst result = generator.generate(source.model)\n\tawait fs.mkdir(dir, { recursive: true })\n\tfor (const [name, content] of Object.entries(result)) {\n\t\tawait fs.writeFile(join(dir, name), content, 'utf8')\n\t}\n})().catch(e => {\n\tconsole.error(e)\n\tprocess.exit(1)\n})\n\n"],"names":["fs","resolve","ContemberClientGenerator","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;CAIC,YAAY;AACN,QAAA,aAAa,QAAQ,KAAK,CAAC;AAC3B,QAAA,SAAS,QAAQ,KAAK,CAAC;AAEzB,MAAA,CAAC,cAAc,CAAC,QAAQ;AAC3B,YAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAOf;AACC,YAAQ,KAAK,CAAC;AAAA,EACf;AAEM,QAAA,aAAa,OAAO,YAAY;AACrC,QAAI,eAAe,KAAK;AACnB,UAAA,QAAQ,MAAM,OAAO;AAClB,cAAA,IAAI,MAAM,oCAAoC;AAAA,MACrD;AACA,YAAM,SAAS,CAAA;AACE,uBAAA,SAAS,QAAQ,OAAO;AACxC,eAAO,KAAK,KAAK;AAAA,MAClB;AACA,aAAO,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM;AAAA,IAC7C;AACA,WAAO,MAAMA,cAAG,SAASC,UAAAA,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,GAAG,MAAM;AAAA,EAAA;AAGnE,QAAA,SAAS,KAAK,MAAM,UAAU;AAE9B,QAAA,MAAMA,kBAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC;AAC5C,QAAA,YAAY,IAAIC,yBAAAA;AACtB,QAAM,SAAS,UAAU,SAAS,OAAO,KAAK;AAC9C,QAAMF,cAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AACvC,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrD,UAAMA,cAAG,UAAUG,eAAK,KAAK,IAAI,GAAG,SAAS,MAAM;AAAA,EACpD;AACD,KAAK,MAAM,CAAK,MAAA;AACf,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AACf,CAAC;"}
1
+ {"version":3,"file":"generate.cjs","sources":["../../../packages/client-content-generator/src/generate.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { resolve, join } from 'node:path'\nimport { ContemberClientGenerator } from './ContemberClientGenerator';\n\n(async () => {\n\tconst schemaPath = process.argv[2]\n\tconst outDir = process.argv[3]\n\n\tif (!schemaPath || !outDir) {\n\t\tconsole.error(`Usage:\n\nFrom file:\nyarn contember-client-generator <schema.json> <out-dir>\n\nFrom stdin:\nyarn run --silent contember project:print-schema --format=schema | yarn contember-client-generator - <out-dir>\n`)\n\t\tprocess.exit(1)\n\t}\n\n\tconst sourceData = await (async () => {\n\t\tif (schemaPath === '-') {\n\t\t\tif (process.stdin.isTTY) {\n\t\t\t\tthrow new Error('Cannot read from stdin in TTY mode')\n\t\t\t}\n\t\t\tconst buffer = []\n\t\t\tfor await (const chunk of process.stdin) {\n\t\t\t\tbuffer.push(chunk)\n\t\t\t}\n\t\t\treturn Buffer.concat(buffer).toString('utf8')\n\t\t}\n\t\treturn await fs.readFile(resolve(process.cwd(), process.argv[2]), 'utf8')\n\t})()\n\n\tconst source = JSON.parse(sourceData)\n\n\tconst dir = resolve(process.cwd(), process.argv[3])\n\tconst generator = new ContemberClientGenerator()\n\tconst result = generator.generate(source.model)\n\tawait fs.mkdir(dir, { recursive: true })\n\tfor (const [name, content] of Object.entries(result)) {\n\t\tawait fs.writeFile(join(dir, name), content, 'utf8')\n\t}\n})().catch(e => {\n\tconsole.error(e)\n\tprocess.exit(1)\n})\n\n"],"names":["fs","resolve","ContemberClientGenerator","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;CAIC,YAAY;AACN,QAAA,aAAa,QAAQ,KAAK,CAAC;AAC3B,QAAA,SAAS,QAAQ,KAAK,CAAC;AAEzB,MAAA,CAAC,cAAc,CAAC,QAAQ;AAC3B,YAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAOf;AACC,YAAQ,KAAK,CAAC;AAAA,EACf;AAEM,QAAA,aAAa,OAAO,YAAY;AACrC,QAAI,eAAe,KAAK;AACnB,UAAA,QAAQ,MAAM,OAAO;AAClB,cAAA,IAAI,MAAM,oCAAoC;AAAA,MACrD;AACA,YAAM,SAAS,CAAA;AACE,uBAAA,SAAS,QAAQ,OAAO;AACxC,eAAO,KAAK,KAAK;AAAA,MAClB;AACA,aAAO,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM;AAAA,IAC7C;AACA,WAAO,MAAMA,cAAG,SAASC,UAAAA,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,GAAG,MAAM;AAAA,EAAA;AAGnE,QAAA,SAAS,KAAK,MAAM,UAAU;AAE9B,QAAA,MAAMA,kBAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC;AAC5C,QAAA,YAAY,IAAIC,yBAAAA;AACtB,QAAM,SAAS,UAAU,SAAS,OAAO,KAAK;AAC9C,QAAMF,cAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AACvC,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrD,UAAMA,cAAG,UAAUG,eAAK,KAAK,IAAI,GAAG,SAAS,MAAM;AAAA,EACpD;AACD,KAAK,MAAM,CAAK,MAAA;AACf,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AACf,CAAC;"}
@@ -1,7 +1,6 @@
1
- #!/usr/bin/env node
2
1
  import * as fs from "node:fs/promises";
3
2
  import { resolve, join } from "node:path";
4
- import { ContemberClientGenerator } from "./ContemberClientGenerator.js";
3
+ import { ContemberClientGenerator } from "./src/ContemberClientGenerator.js";
5
4
  (async () => {
6
5
  const schemaPath = process.argv[2];
7
6
  const outDir = process.argv[3];
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sources":["../../src/generate.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { resolve, join } from 'node:path'\nimport { ContemberClientGenerator } from './ContemberClientGenerator';\n\n(async () => {\n\tconst schemaPath = process.argv[2]\n\tconst outDir = process.argv[3]\n\n\tif (!schemaPath || !outDir) {\n\t\tconsole.error(`Usage:\n\nFrom file:\nyarn contember-client-generator <schema.json> <out-dir>\n\nFrom stdin:\nyarn run --silent contember project:print-schema --format=schema | yarn contember-client-generator - <out-dir>\n`)\n\t\tprocess.exit(1)\n\t}\n\n\tconst sourceData = await (async () => {\n\t\tif (schemaPath === '-') {\n\t\t\tif (process.stdin.isTTY) {\n\t\t\t\tthrow new Error('Cannot read from stdin in TTY mode')\n\t\t\t}\n\t\t\tconst buffer = []\n\t\t\tfor await (const chunk of process.stdin) {\n\t\t\t\tbuffer.push(chunk)\n\t\t\t}\n\t\t\treturn Buffer.concat(buffer).toString('utf8')\n\t\t}\n\t\treturn await fs.readFile(resolve(process.cwd(), process.argv[2]), 'utf8')\n\t})()\n\n\tconst source = JSON.parse(sourceData)\n\n\tconst dir = resolve(process.cwd(), process.argv[3])\n\tconst generator = new ContemberClientGenerator()\n\tconst result = generator.generate(source.model)\n\tawait fs.mkdir(dir, { recursive: true })\n\tfor (const [name, content] of Object.entries(result)) {\n\t\tawait fs.writeFile(join(dir, name), content, 'utf8')\n\t}\n})().catch(e => {\n\tconsole.error(e)\n\tprocess.exit(1)\n})\n\n"],"names":[],"mappings":";;;;CAIC,YAAY;AACN,QAAA,aAAa,QAAQ,KAAK,CAAC;AAC3B,QAAA,SAAS,QAAQ,KAAK,CAAC;AAEzB,MAAA,CAAC,cAAc,CAAC,QAAQ;AAC3B,YAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAOf;AACC,YAAQ,KAAK,CAAC;AAAA,EACf;AAEM,QAAA,aAAa,OAAO,YAAY;AACrC,QAAI,eAAe,KAAK;AACnB,UAAA,QAAQ,MAAM,OAAO;AAClB,cAAA,IAAI,MAAM,oCAAoC;AAAA,MACrD;AACA,YAAM,SAAS,CAAA;AACE,uBAAA,SAAS,QAAQ,OAAO;AACxC,eAAO,KAAK,KAAK;AAAA,MAClB;AACA,aAAO,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM;AAAA,IAC7C;AACA,WAAO,MAAM,GAAG,SAAS,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,GAAG,MAAM;AAAA,EAAA;AAGnE,QAAA,SAAS,KAAK,MAAM,UAAU;AAE9B,QAAA,MAAM,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC;AAC5C,QAAA,YAAY,IAAI;AACtB,QAAM,SAAS,UAAU,SAAS,OAAO,KAAK;AAC9C,QAAM,GAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AACvC,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrD,UAAM,GAAG,UAAU,KAAK,KAAK,IAAI,GAAG,SAAS,MAAM;AAAA,EACpD;AACD,KAAK,MAAM,CAAK,MAAA;AACf,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AACf,CAAC;"}
1
+ {"version":3,"file":"generate.js","sources":["../../../packages/client-content-generator/src/generate.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { resolve, join } from 'node:path'\nimport { ContemberClientGenerator } from './ContemberClientGenerator';\n\n(async () => {\n\tconst schemaPath = process.argv[2]\n\tconst outDir = process.argv[3]\n\n\tif (!schemaPath || !outDir) {\n\t\tconsole.error(`Usage:\n\nFrom file:\nyarn contember-client-generator <schema.json> <out-dir>\n\nFrom stdin:\nyarn run --silent contember project:print-schema --format=schema | yarn contember-client-generator - <out-dir>\n`)\n\t\tprocess.exit(1)\n\t}\n\n\tconst sourceData = await (async () => {\n\t\tif (schemaPath === '-') {\n\t\t\tif (process.stdin.isTTY) {\n\t\t\t\tthrow new Error('Cannot read from stdin in TTY mode')\n\t\t\t}\n\t\t\tconst buffer = []\n\t\t\tfor await (const chunk of process.stdin) {\n\t\t\t\tbuffer.push(chunk)\n\t\t\t}\n\t\t\treturn Buffer.concat(buffer).toString('utf8')\n\t\t}\n\t\treturn await fs.readFile(resolve(process.cwd(), process.argv[2]), 'utf8')\n\t})()\n\n\tconst source = JSON.parse(sourceData)\n\n\tconst dir = resolve(process.cwd(), process.argv[3])\n\tconst generator = new ContemberClientGenerator()\n\tconst result = generator.generate(source.model)\n\tawait fs.mkdir(dir, { recursive: true })\n\tfor (const [name, content] of Object.entries(result)) {\n\t\tawait fs.writeFile(join(dir, name), content, 'utf8')\n\t}\n})().catch(e => {\n\tconsole.error(e)\n\tprocess.exit(1)\n})\n\n"],"names":[],"mappings":";;;CAIC,YAAY;AACN,QAAA,aAAa,QAAQ,KAAK,CAAC;AAC3B,QAAA,SAAS,QAAQ,KAAK,CAAC;AAEzB,MAAA,CAAC,cAAc,CAAC,QAAQ;AAC3B,YAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAOf;AACC,YAAQ,KAAK,CAAC;AAAA,EACf;AAEM,QAAA,aAAa,OAAO,YAAY;AACrC,QAAI,eAAe,KAAK;AACnB,UAAA,QAAQ,MAAM,OAAO;AAClB,cAAA,IAAI,MAAM,oCAAoC;AAAA,MACrD;AACA,YAAM,SAAS,CAAA;AACE,uBAAA,SAAS,QAAQ,OAAO;AACxC,eAAO,KAAK,KAAK;AAAA,MAClB;AACA,aAAO,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM;AAAA,IAC7C;AACA,WAAO,MAAM,GAAG,SAAS,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,GAAG,MAAM;AAAA,EAAA;AAGnE,QAAA,SAAS,KAAK,MAAM,UAAU;AAE9B,QAAA,MAAM,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC;AAC5C,QAAA,YAAY,IAAI;AACtB,QAAM,SAAS,UAAU,SAAS,OAAO,KAAK;AAC9C,QAAM,GAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AACvC,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrD,UAAM,GAAG,UAAU,KAAK,KAAK,IAAI,GAAG,SAAS,MAAM;AAAA,EACpD;AACD,KAAK,MAAM,CAAK,MAAA;AACf,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AACf,CAAC;"}
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const ContemberClientGenerator = require("./ContemberClientGenerator.cjs");
4
- const EntityTypeSchemaGenerator = require("./EntityTypeSchemaGenerator.cjs");
5
- const EnumTypeSchemaGenerator = require("./EnumTypeSchemaGenerator.cjs");
6
- const NameSchemaGenerator = require("./NameSchemaGenerator.cjs");
3
+ const ContemberClientGenerator = require("./src/ContemberClientGenerator.cjs");
4
+ const EntityTypeSchemaGenerator = require("./src/EntityTypeSchemaGenerator.cjs");
5
+ const EnumTypeSchemaGenerator = require("./src/EnumTypeSchemaGenerator.cjs");
6
+ const NameSchemaGenerator = require("./src/NameSchemaGenerator.cjs");
7
7
  exports.ContemberClientGenerator = ContemberClientGenerator.ContemberClientGenerator;
8
8
  exports.EntityTypeSchemaGenerator = EntityTypeSchemaGenerator.EntityTypeSchemaGenerator;
9
9
  exports.EnumTypeSchemaGenerator = EnumTypeSchemaGenerator.EnumTypeSchemaGenerator;
@@ -1,7 +1,7 @@
1
- import { ContemberClientGenerator } from "./ContemberClientGenerator.js";
2
- import { EntityTypeSchemaGenerator } from "./EntityTypeSchemaGenerator.js";
3
- import { EnumTypeSchemaGenerator } from "./EnumTypeSchemaGenerator.js";
4
- import { NameSchemaGenerator } from "./NameSchemaGenerator.js";
1
+ import { ContemberClientGenerator } from "./src/ContemberClientGenerator.js";
2
+ import { EntityTypeSchemaGenerator } from "./src/EntityTypeSchemaGenerator.js";
3
+ import { EnumTypeSchemaGenerator } from "./src/EnumTypeSchemaGenerator.js";
4
+ import { NameSchemaGenerator } from "./src/NameSchemaGenerator.js";
5
5
  export {
6
6
  ContemberClientGenerator,
7
7
  EntityTypeSchemaGenerator,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContemberClientGenerator.cjs","sources":["../../../../packages/client-content-generator/src/ContemberClientGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { EnumTypeSchemaGenerator } from './EnumTypeSchemaGenerator'\nimport { EntityTypeSchemaGenerator } from './EntityTypeSchemaGenerator'\nimport { NameSchemaGenerator } from './NameSchemaGenerator'\n\n\nexport class ContemberClientGenerator {\n\tconstructor(\n\t\tprivate readonly nameSchemaGenerator: NameSchemaGenerator = new NameSchemaGenerator(),\n\t\tprivate readonly enumTypeSchemaGenerator: EnumTypeSchemaGenerator = new EnumTypeSchemaGenerator(),\n\t\tprivate readonly entityTypeSchemaGenerator: EntityTypeSchemaGenerator = new EntityTypeSchemaGenerator(),\n\t) {\n\t}\n\n\tgenerate(model: Model.Schema): Record<string, string> {\n\t\tconst nameSchema = this.nameSchemaGenerator.generate(model)\n\t\tconst enumTypeSchema = this.enumTypeSchemaGenerator.generate(model)\n\t\tconst entityTypeSchema = this.entityTypeSchemaGenerator.generate(model)\n\n\t\tconst namesCode = `import { SchemaNames } from '@contember/client-content'\nexport const ContemberClientNames: SchemaNames = ` + JSON.stringify(nameSchema, null, 2)\n\n\t\tconst indexCode = `\nimport { ContemberClientNames } from './names'\nimport type { ContemberClientSchema } from './entities'\nimport { ContentQueryBuilder, TypedContentQueryBuilder, TypedEntitySelection } from '@contember/client-content'\nexport * from './names'\nexport * from './enums'\nexport * from './entities'\n\nexport const queryBuilder = new ContentQueryBuilder(ContemberClientNames) as unknown as TypedContentQueryBuilder<ContemberClientSchema>\n\nexport type FragmentOf<EntityName extends keyof ContemberClientSchema['entities'] & string, Data = unknown> =\nTypedEntitySelection<ContemberClientSchema, EntityName, ContemberClientSchema['entities'][EntityName], Data>\n\nexport type FragmentType<T extends TypedEntitySelection<any, any, any, any> = any> =\nT extends TypedEntitySelection<any, any, any, infer TFields>\n\t? TFields\n\t: never\n`\n\t\treturn {\n\t\t\t'names.ts': namesCode,\n\t\t\t'enums.ts': enumTypeSchema,\n\t\t\t'entities.ts': entityTypeSchema,\n\t\t\t'index.ts': indexCode,\n\t\t}\n\t}\n}\n"],"names":["NameSchemaGenerator","EnumTypeSchemaGenerator","EntityTypeSchemaGenerator"],"mappings":";;;;;AAMO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBAA2C,IAAIA,oBAAAA,uBAC/C,0BAAmD,IAAIC,wBAAAA,2BACvD,4BAAuD,IAAIC,0BAAAA,6BAC3E;AAHgB,SAAA,sBAAA;AACA,SAAA,0BAAA;AACA,SAAA,4BAAA;AAAA,EAElB;AAAA,EAEA,SAAS,OAA6C;AACrD,UAAM,aAAa,KAAK,oBAAoB,SAAS,KAAK;AAC1D,UAAM,iBAAiB,KAAK,wBAAwB,SAAS,KAAK;AAClE,UAAM,mBAAmB,KAAK,0BAA0B,SAAS,KAAK;AAEtE,UAAM,YAAY;AAAA,qDACiC,KAAK,UAAU,YAAY,MAAM,CAAC;AAErF,UAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBX,WAAA;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,YAAY;AAAA,IAAA;AAAA,EAEd;AACD;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContemberClientGenerator.js","sources":["../../../../packages/client-content-generator/src/ContemberClientGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { EnumTypeSchemaGenerator } from './EnumTypeSchemaGenerator'\nimport { EntityTypeSchemaGenerator } from './EntityTypeSchemaGenerator'\nimport { NameSchemaGenerator } from './NameSchemaGenerator'\n\n\nexport class ContemberClientGenerator {\n\tconstructor(\n\t\tprivate readonly nameSchemaGenerator: NameSchemaGenerator = new NameSchemaGenerator(),\n\t\tprivate readonly enumTypeSchemaGenerator: EnumTypeSchemaGenerator = new EnumTypeSchemaGenerator(),\n\t\tprivate readonly entityTypeSchemaGenerator: EntityTypeSchemaGenerator = new EntityTypeSchemaGenerator(),\n\t) {\n\t}\n\n\tgenerate(model: Model.Schema): Record<string, string> {\n\t\tconst nameSchema = this.nameSchemaGenerator.generate(model)\n\t\tconst enumTypeSchema = this.enumTypeSchemaGenerator.generate(model)\n\t\tconst entityTypeSchema = this.entityTypeSchemaGenerator.generate(model)\n\n\t\tconst namesCode = `import { SchemaNames } from '@contember/client-content'\nexport const ContemberClientNames: SchemaNames = ` + JSON.stringify(nameSchema, null, 2)\n\n\t\tconst indexCode = `\nimport { ContemberClientNames } from './names'\nimport type { ContemberClientSchema } from './entities'\nimport { ContentQueryBuilder, TypedContentQueryBuilder, TypedEntitySelection } from '@contember/client-content'\nexport * from './names'\nexport * from './enums'\nexport * from './entities'\n\nexport const queryBuilder = new ContentQueryBuilder(ContemberClientNames) as unknown as TypedContentQueryBuilder<ContemberClientSchema>\n\nexport type FragmentOf<EntityName extends keyof ContemberClientSchema['entities'] & string, Data = unknown> =\nTypedEntitySelection<ContemberClientSchema, EntityName, ContemberClientSchema['entities'][EntityName], Data>\n\nexport type FragmentType<T extends TypedEntitySelection<any, any, any, any> = any> =\nT extends TypedEntitySelection<any, any, any, infer TFields>\n\t? TFields\n\t: never\n`\n\t\treturn {\n\t\t\t'names.ts': namesCode,\n\t\t\t'enums.ts': enumTypeSchema,\n\t\t\t'entities.ts': entityTypeSchema,\n\t\t\t'index.ts': indexCode,\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;AAMO,MAAM,yBAAyB;AAAA,EACrC,YACkB,sBAA2C,IAAI,uBAC/C,0BAAmD,IAAI,2BACvD,4BAAuD,IAAI,6BAC3E;AAHgB,SAAA,sBAAA;AACA,SAAA,0BAAA;AACA,SAAA,4BAAA;AAAA,EAElB;AAAA,EAEA,SAAS,OAA6C;AACrD,UAAM,aAAa,KAAK,oBAAoB,SAAS,KAAK;AAC1D,UAAM,iBAAiB,KAAK,wBAAwB,SAAS,KAAK;AAClE,UAAM,mBAAmB,KAAK,0BAA0B,SAAS,KAAK;AAEtE,UAAM,YAAY;AAAA,qDACiC,KAAK,UAAU,YAAY,MAAM,CAAC;AAErF,UAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBX,WAAA;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,YAAY;AAAA,IAAA;AAAA,EAEd;AACD;"}
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const schema = require("@contember/schema");
4
4
  const schemaUtils = require("@contember/schema-utils");
5
+ const utils = require("./utils.cjs");
5
6
  class EntityTypeSchemaGenerator {
6
7
  generate(model) {
7
8
  let code = "";
8
9
  for (const enumName of Object.keys(model.enums)) {
9
- code += `import type { ${enumName} } from './enums'
10
+ code += `import type { ${utils.getEnumTypeName(enumName)} } from './enums'
10
11
  `;
11
12
  }
12
13
  code += `
@@ -130,7 +131,7 @@ const uniqueType = (model, entity, field) => {
130
131
  const columnToTsType = (column) => {
131
132
  switch (column.type) {
132
133
  case schema.Model.ColumnType.Enum:
133
- return column.columnType;
134
+ return utils.getEnumTypeName(column.columnType);
134
135
  case schema.Model.ColumnType.String:
135
136
  return "string";
136
137
  case schema.Model.ColumnType.Int:
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityTypeSchemaGenerator.cjs","sources":["../../../../packages/client-content-generator/src/EntityTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor, acceptFieldVisitor } from '@contember/schema-utils'\n\nimport { getEnumTypeName } from './utils'\n\nexport class EntityTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `import type { ${getEnumTypeName(enumName)} } from './enums'\\n`\n\t\t}\n\n\t\tcode += `\nexport type JSONPrimitive = string | number | boolean | null\nexport type JSONValue = JSONPrimitive | JSONObject | JSONArray\nexport type JSONObject = { readonly [K in string]?: JSONValue }\nexport type JSONArray = readonly JSONValue[]\n\n`\n\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += this.generateTypeEntityCode(model, entity)\n\t\t}\n\t\tcode += '\\n'\n\t\tcode += `export type ContemberClientEntities = {\\n`\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += `\\t${entity.name}: ${entity.name}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\tcode += `export type ContemberClientSchema = {\\n`\n\t\tcode += '\\tentities: ContemberClientEntities\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate generateTypeEntityCode(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = `export type ${entity.name} <OverRelation extends string | never = never> = {\\n`\n\t\tcode += '\\tname: \\'' + entity.name + '\\'\\n'\n\t\tcode += '\\tunique:\\n'\n\t\tcode += this.formatUniqueFields(model, entity)\n\t\tlet columnsCode = ''\n\t\tlet hasOneCode = ''\n\t\tlet hasManyCode = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitHasMany: ctx => {\n\t\t\t\thasManyCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}${ctx.targetRelation?.type === Model.RelationType.ManyHasOne ? `<'${ctx.targetRelation.name}'>` : ''}\\n`\n\t\t\t},\n\t\t\tvisitHasOne: ctx => {\n\t\t\t\thasOneCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}\\n`\n\t\t\t},\n\t\t\tvisitColumn: ctx => {\n\t\t\t\tcolumnsCode += `\\t\\t${ctx.column.name}: ${columnToTsType(ctx.column)}${ctx.column.nullable ? ` | null` : ''}\\n`\n\t\t\t},\n\t\t})\n\n\t\tcode += '\\tcolumns: {\\n'\n\t\tcode += columnsCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasOne: {\\n'\n\t\tcode += hasOneCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasMany: {\\n'\n\t\tcode += hasManyCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasManyBy: {\\n'\n\t\tcode += this.formatReducedFields(model, entity)\n\t\tcode += '\\t}\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate formatReducedFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitOneHasMany: ({ entity, relation, targetEntity, targetRelation }) => {\n\t\t\t\tif (!targetRelation) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst uniqueConstraints = getFieldsForUniqueWhere(model, targetEntity)\n\t\t\t\tconst composedUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 2) //todo support all uniques\n\t\t\t\t\t.filter(fields => fields.includes(targetRelation.name))\n\t\t\t\t\t.map(fields => fields.filter(it => it !== targetRelation.name))\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\tconst singleUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 1 && fields[0] !== targetEntity.primary)\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\t\t.filter(it => it !== targetRelation.name)\n\n\t\t\t\t;[...composedUnique, ...singleUnique].forEach(fieldName => {\n\t\t\t\t\tconst capitalizeFirstLetter = (value: string) => {\n\t\t\t\t\t\treturn value.charAt(0).toUpperCase() + value.slice(1)\n\t\t\t\t\t}\n\t\t\t\t\tconst name = `${relation.name}By${capitalizeFirstLetter(fieldName)}`\n\n\t\t\t\t\tconst targetUnique = targetEntity.fields[fieldName]\n\n\t\t\t\t\tcode += `\\t\\t${name}: { entity: ${targetEntity.name}; by: {${fieldName}: ${uniqueType(model, targetEntity, targetUnique)}} }\\n`\n\n\t\t\t\t})\n\t\t\t},\n\t\t\tvisitColumn: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyOwning: () => {\n\t\t\t},\n\t\t\tvisitManyHasOne: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneInverse: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneOwning: () => {\n\t\t\t},\n\t\t})\n\t\treturn code\n\t}\n\n\tprivate formatUniqueFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tconst fields = getFieldsForUniqueWhere(model, entity)\n\t\tlet code = ''\n\t\tfor (const field of fields) {\n\t\t\tcode += '\\t\\t| Omit<{ '\n\t\t\tcode += field.map(it => `${it}: ${uniqueType(model, entity, entity.fields[it])}`).join(', ')\n\t\t\tcode += '}, OverRelation>\\n'\n\t\t}\n\t\treturn code\n\t}\n}\n\n\nconst uniqueType = (model: Model.Schema, entity: Model.Entity, field: Model.AnyField): string => {\n\treturn acceptFieldVisitor(model, entity, field, {\n\t\tvisitColumn: ctx => {\n\t\t\treturn columnToTsType(ctx.column)\n\t\t},\n\t\tvisitRelation: ctx => {\n\t\t\treturn ctx.targetEntity.name + `['unique']`\n\t\t},\n\t})\n}\n\n\nconst columnToTsType = (column: Model.AnyColumn): string => {\n\tswitch (column.type) {\n\t\tcase Model.ColumnType.Enum:\n\t\t\treturn getEnumTypeName(column.columnType)\n\t\tcase Model.ColumnType.String:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Int:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Double:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Bool:\n\t\t\treturn 'boolean'\n\t\tcase Model.ColumnType.DateTime:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Date:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Json:\n\t\t\treturn 'JSONValue'\n\t\tcase Model.ColumnType.Uuid:\n\t\t\treturn 'string'\n\t\tdefault:\n\t\t\t((_: never) => {\n\t\t\t\tthrow new Error(`Unknown type ${_}`)\n\t\t\t})(column.type)\n\t}\n}\n\nconst getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (readonly string[])[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...Object.values(entity.unique).map(it => it.fields), ...relations]\n}\n"],"names":["getEnumTypeName","acceptEveryFieldVisitor","Model","entity","acceptFieldVisitor","schema"],"mappings":";;;;;AAKO,MAAM,0BAA0B;AAAA,EACtC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACX,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AACxC,cAAA,iBAAiBA,MAAgB,gBAAA,QAAQ,CAAC;AAAA;AAAA,IACnD;AAEQ,YAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AAC3C,cAAA,KAAK,uBAAuB,OAAO,MAAM;AAAA,IAClD;AACQ,YAAA;AACA,YAAA;AAAA;AACR,eAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AACnD,cAAQ,IAAK,OAAO,IAAI,KAAK,OAAO,IAAI;AAAA;AAAA,IACzC;AACQ,YAAA;AACA,YAAA;AAAA;AACA,YAAA;AACA,YAAA;AACD,WAAA;AAAA,EACR;AAAA,EAEQ,uBAAuB,OAAqB,QAA8B;AAC7E,QAAA,OAAO,eAAe,OAAO,IAAI;AAAA;AAC7B,YAAA,aAAe,OAAO,OAAO;AAC7B,YAAA;AACA,YAAA,KAAK,mBAAmB,OAAO,MAAM;AAC7C,QAAI,cAAc;AAClB,QAAI,aAAa;AACjB,QAAI,cAAc;AAClBC,gBAAA,wBAAwB,OAAO,QAAQ;AAAA,MACtC,cAAc,CAAO,QAAA;AACL,uBAAA,KAAO,IAAI,SAAS,IAAI,KAAK,IAAI,aAAa,IAAI,GAAG,IAAI,gBAAgB,SAASC,OAAA,MAAM,aAAa,aAAa,KAAK,IAAI,eAAe,IAAI,OAAO,EAAE;AAAA;AAAA,MACvK;AAAA,MACA,a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UAAU;AAAA,IACzC,KAAKE,OAAAA,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAKA,OAAAA,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAKA,OAAAA,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAKA,OAAAA,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAKA,OAAAA,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAKA,OAAAA,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAKA,OAAAA,MAAM,WAAW;AACd,aAAA;AAAA,IACR,KAAKA,OAAAA,MAAM,WAAW;AACd,aAAA;AAAA,IACR;AACC,OAAC,CAAC,MAAa;AACd,cAAM,IAAI,MAAM,gBAAgB,CAAC,EAAE;AAAA,MAAA,GACjC,OAAO,IAAI;AAAA,EAChB;AACD;AAEA,MAAM,0BAA0B,CAACG,SAAsB,WAAyD;AAC/G,QAAM,YAAY,OAAO;AAAA,IACxBJ,YAAA,wBAA8CI,SAAQ,QAAQ;AAAA,MAC7D,aAAa,MAAM;AAAA,MACnB,yBAAyB,MAAM;AAAA,MAC/B,wBAAwB,MAAM;AAAA,MAC9B,iBAAiB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,MACjD,iBAAiB,MAAM;AAAA,MACvB,uBAAuB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,MACvD,sBAAsB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,IAAA,CACtD;AAAA,IACA,OAAO,CAAC,OAAuB,CAAC,CAAC,EAAE;AAErC,SAAO,CAAC,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM,EAAE,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC7F;;"}
@@ -1,10 +1,11 @@
1
1
  import { Model } from "@contember/schema";
2
2
  import { acceptEveryFieldVisitor, acceptFieldVisitor } from "@contember/schema-utils";
3
+ import { getEnumTypeName } from "./utils.js";
3
4
  class EntityTypeSchemaGenerator {
4
5
  generate(model) {
5
6
  let code = "";
6
7
  for (const enumName of Object.keys(model.enums)) {
7
- code += `import type { ${enumName} } from './enums'
8
+ code += `import type { ${getEnumTypeName(enumName)} } from './enums'
8
9
  `;
9
10
  }
10
11
  code += `
@@ -128,7 +129,7 @@ const uniqueType = (model, entity, field) => {
128
129
  const columnToTsType = (column) => {
129
130
  switch (column.type) {
130
131
  case Model.ColumnType.Enum:
131
- return column.columnType;
132
+ return getEnumTypeName(column.columnType);
132
133
  case Model.ColumnType.String:
133
134
  return "string";
134
135
  case Model.ColumnType.Int:
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityTypeSchemaGenerator.js","sources":["../../../../packages/client-content-generator/src/EntityTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { acceptEveryFieldVisitor, acceptFieldVisitor } from '@contember/schema-utils'\n\nimport { getEnumTypeName } from './utils'\n\nexport class EntityTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `import type { ${getEnumTypeName(enumName)} } from './enums'\\n`\n\t\t}\n\n\t\tcode += `\nexport type JSONPrimitive = string | number | boolean | null\nexport type JSONValue = JSONPrimitive | JSONObject | JSONArray\nexport type JSONObject = { readonly [K in string]?: JSONValue }\nexport type JSONArray = readonly JSONValue[]\n\n`\n\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += this.generateTypeEntityCode(model, entity)\n\t\t}\n\t\tcode += '\\n'\n\t\tcode += `export type ContemberClientEntities = {\\n`\n\t\tfor (const entity of Object.values(model.entities)) {\n\t\t\tcode += `\\t${entity.name}: ${entity.name}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\tcode += `export type ContemberClientSchema = {\\n`\n\t\tcode += '\\tentities: ContemberClientEntities\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate generateTypeEntityCode(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = `export type ${entity.name} <OverRelation extends string | never = never> = {\\n`\n\t\tcode += '\\tname: \\'' + entity.name + '\\'\\n'\n\t\tcode += '\\tunique:\\n'\n\t\tcode += this.formatUniqueFields(model, entity)\n\t\tlet columnsCode = ''\n\t\tlet hasOneCode = ''\n\t\tlet hasManyCode = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitHasMany: ctx => {\n\t\t\t\thasManyCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}${ctx.targetRelation?.type === Model.RelationType.ManyHasOne ? `<'${ctx.targetRelation.name}'>` : ''}\\n`\n\t\t\t},\n\t\t\tvisitHasOne: ctx => {\n\t\t\t\thasOneCode += `\\t\\t${ctx.relation.name}: ${ctx.targetEntity.name}\\n`\n\t\t\t},\n\t\t\tvisitColumn: ctx => {\n\t\t\t\tcolumnsCode += `\\t\\t${ctx.column.name}: ${columnToTsType(ctx.column)}${ctx.column.nullable ? ` | null` : ''}\\n`\n\t\t\t},\n\t\t})\n\n\t\tcode += '\\tcolumns: {\\n'\n\t\tcode += columnsCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasOne: {\\n'\n\t\tcode += hasOneCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasMany: {\\n'\n\t\tcode += hasManyCode\n\t\tcode += '\\t}\\n'\n\t\tcode += '\\thasManyBy: {\\n'\n\t\tcode += this.formatReducedFields(model, entity)\n\t\tcode += '\\t}\\n'\n\t\tcode += '}\\n'\n\t\treturn code\n\t}\n\n\tprivate formatReducedFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tlet code = ''\n\t\tacceptEveryFieldVisitor(model, entity, {\n\t\t\tvisitOneHasMany: ({ entity, relation, targetEntity, targetRelation }) => {\n\t\t\t\tif (!targetRelation) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst uniqueConstraints = getFieldsForUniqueWhere(model, targetEntity)\n\t\t\t\tconst composedUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 2) //todo support all uniques\n\t\t\t\t\t.filter(fields => fields.includes(targetRelation.name))\n\t\t\t\t\t.map(fields => fields.filter(it => it !== targetRelation.name))\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\tconst singleUnique = uniqueConstraints\n\t\t\t\t\t.filter(fields => fields.length === 1 && fields[0] !== targetEntity.primary)\n\t\t\t\t\t.map(fields => fields[0])\n\t\t\t\t\t.filter(it => it !== targetRelation.name)\n\n\t\t\t\t;[...composedUnique, ...singleUnique].forEach(fieldName => {\n\t\t\t\t\tconst capitalizeFirstLetter = (value: string) => {\n\t\t\t\t\t\treturn value.charAt(0).toUpperCase() + value.slice(1)\n\t\t\t\t\t}\n\t\t\t\t\tconst name = `${relation.name}By${capitalizeFirstLetter(fieldName)}`\n\n\t\t\t\t\tconst targetUnique = targetEntity.fields[fieldName]\n\n\t\t\t\t\tcode += `\\t\\t${name}: { entity: ${targetEntity.name}; by: {${fieldName}: ${uniqueType(model, targetEntity, targetUnique)}} }\\n`\n\n\t\t\t\t})\n\t\t\t},\n\t\t\tvisitColumn: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: () => {\n\t\t\t},\n\t\t\tvisitManyHasManyOwning: () => {\n\t\t\t},\n\t\t\tvisitManyHasOne: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneInverse: () => {\n\t\t\t},\n\t\t\tvisitOneHasOneOwning: () => {\n\t\t\t},\n\t\t})\n\t\treturn code\n\t}\n\n\tprivate formatUniqueFields(model: Model.Schema, entity: Model.Entity): string {\n\t\tconst fields = getFieldsForUniqueWhere(model, entity)\n\t\tlet code = ''\n\t\tfor (const field of fields) {\n\t\t\tcode += '\\t\\t| Omit<{ '\n\t\t\tcode += field.map(it => `${it}: ${uniqueType(model, entity, entity.fields[it])}`).join(', ')\n\t\t\tcode += '}, OverRelation>\\n'\n\t\t}\n\t\treturn code\n\t}\n}\n\n\nconst uniqueType = (model: Model.Schema, entity: Model.Entity, field: Model.AnyField): string => {\n\treturn acceptFieldVisitor(model, entity, field, {\n\t\tvisitColumn: ctx => {\n\t\t\treturn columnToTsType(ctx.column)\n\t\t},\n\t\tvisitRelation: ctx => {\n\t\t\treturn ctx.targetEntity.name + `['unique']`\n\t\t},\n\t})\n}\n\n\nconst columnToTsType = (column: Model.AnyColumn): string => {\n\tswitch (column.type) {\n\t\tcase Model.ColumnType.Enum:\n\t\t\treturn getEnumTypeName(column.columnType)\n\t\tcase Model.ColumnType.String:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Int:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Double:\n\t\t\treturn 'number'\n\t\tcase Model.ColumnType.Bool:\n\t\t\treturn 'boolean'\n\t\tcase Model.ColumnType.DateTime:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Date:\n\t\t\treturn 'string'\n\t\tcase Model.ColumnType.Json:\n\t\t\treturn 'JSONValue'\n\t\tcase Model.ColumnType.Uuid:\n\t\t\treturn 'string'\n\t\tdefault:\n\t\t\t((_: never) => {\n\t\t\t\tthrow new Error(`Unknown type ${_}`)\n\t\t\t})(column.type)\n\t}\n}\n\nconst getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (readonly string[])[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...Object.values(entity.unique).map(it => it.fields), ...relations]\n}\n"],"names":["entity"],"m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,WAAW;AACd,aAAA;AAAA,IACR,KAAK,MAAM,WAAW;AACd,aAAA;AAAA,IACR;AACC,OAAC,CAAC,MAAa;AACd,cAAM,IAAI,MAAM,gBAAgB,CAAC,EAAE;AAAA,MAAA,GACjC,OAAO,IAAI;AAAA,EAChB;AACD;AAEA,MAAM,0BAA0B,CAAC,QAAsB,WAAyD;AAC/G,QAAM,YAAY,OAAO;AAAA,IACxB,wBAA8C,QAAQ,QAAQ;AAAA,MAC7D,aAAa,MAAM;AAAA,MACnB,yBAAyB,MAAM;AAAA,MAC/B,wBAAwB,MAAM;AAAA,MAC9B,iBAAiB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,MACjD,iBAAiB,MAAM;AAAA,MACvB,uBAAuB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,MACvD,sBAAsB,CAAC,EAAE,SAAe,MAAA,CAAC,SAAS,IAAI;AAAA,IAAA,CACtD;AAAA,IACA,OAAO,CAAC,OAAuB,CAAC,CAAC,EAAE;AAErC,SAAO,CAAC,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM,EAAE,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC7F;"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils = require("./utils.cjs");
4
+ class EnumTypeSchemaGenerator {
5
+ generate(model) {
6
+ let code = "";
7
+ for (const [enumName, values] of Object.entries(model.enums)) {
8
+ code += `export type ${utils.getEnumTypeName(enumName)} = ${values.map((it) => "\n | " + JSON.stringify(it)).join("")}
9
+ `;
10
+ }
11
+ code += `export type ContemberClientEnums = {
12
+ `;
13
+ for (const enumName of Object.keys(model.enums)) {
14
+ code += ` ${enumName}: ${utils.getEnumTypeName(enumName)}
15
+ `;
16
+ }
17
+ code += "}\n\n";
18
+ return code;
19
+ }
20
+ }
21
+ exports.EnumTypeSchemaGenerator = EnumTypeSchemaGenerator;
22
+ //# sourceMappingURL=EnumTypeSchemaGenerator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnumTypeSchemaGenerator.cjs","sources":["../../../../packages/client-content-generator/src/EnumTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { getEnumTypeName } from './utils'\n\nexport class EnumTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const [enumName, values] of Object.entries(model.enums)) {\n\t\t\tcode += `export type ${getEnumTypeName(enumName)} = ${values.map(it => '\\n\\t | ' + JSON.stringify(it)).join('')}\\n`\n\t\t}\n\t\tcode += `export type ContemberClientEnums = {\\n`\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `\\t${enumName}: ${getEnumTypeName(enumName)}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\treturn code\n\t}\n}\n"],"names":["getEnumTypeName"],"mappings":";;;AAGO,MAAM,wBAAwB;AAAA,EACpC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACA,eAAA,CAAC,UAAU,MAAM,KAAK,OAAO,QAAQ,MAAM,KAAK,GAAG;AAC7D,cAAQ,eAAeA,MAAgB,gBAAA,QAAQ,CAAC,MAAM,OAAO,IAAI,CAAA,OAAM,WAAY,KAAK,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAAA;AAAA,IAChH;AACQ,YAAA;AAAA;AACR,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AAChD,cAAQ,IAAK,QAAQ,KAAKA,MAAAA,gBAAgB,QAAQ,CAAC;AAAA;AAAA,IACpD;AACQ,YAAA;AACD,WAAA;AAAA,EACR;AACD;;"}
@@ -0,0 +1,22 @@
1
+ import { getEnumTypeName } from "./utils.js";
2
+ class EnumTypeSchemaGenerator {
3
+ generate(model) {
4
+ let code = "";
5
+ for (const [enumName, values] of Object.entries(model.enums)) {
6
+ code += `export type ${getEnumTypeName(enumName)} = ${values.map((it) => "\n | " + JSON.stringify(it)).join("")}
7
+ `;
8
+ }
9
+ code += `export type ContemberClientEnums = {
10
+ `;
11
+ for (const enumName of Object.keys(model.enums)) {
12
+ code += ` ${enumName}: ${getEnumTypeName(enumName)}
13
+ `;
14
+ }
15
+ code += "}\n\n";
16
+ return code;
17
+ }
18
+ }
19
+ export {
20
+ EnumTypeSchemaGenerator
21
+ };
22
+ //# sourceMappingURL=EnumTypeSchemaGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnumTypeSchemaGenerator.js","sources":["../../../../packages/client-content-generator/src/EnumTypeSchemaGenerator.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { getEnumTypeName } from './utils'\n\nexport class EnumTypeSchemaGenerator {\n\tgenerate(model: Model.Schema): string {\n\t\tlet code = ''\n\t\tfor (const [enumName, values] of Object.entries(model.enums)) {\n\t\t\tcode += `export type ${getEnumTypeName(enumName)} = ${values.map(it => '\\n\\t | ' + JSON.stringify(it)).join('')}\\n`\n\t\t}\n\t\tcode += `export type ContemberClientEnums = {\\n`\n\t\tfor (const enumName of Object.keys(model.enums)) {\n\t\t\tcode += `\\t${enumName}: ${getEnumTypeName(enumName)}\\n`\n\t\t}\n\t\tcode += '}\\n\\n'\n\t\treturn code\n\t}\n}\n"],"names":[],"mappings":";AAGO,MAAM,wBAAwB;AAAA,EACpC,SAAS,OAA6B;AACrC,QAAI,OAAO;AACA,eAAA,CAAC,UAAU,MAAM,KAAK,OAAO,QAAQ,MAAM,KAAK,GAAG;AAC7D,cAAQ,eAAe,gBAAgB,QAAQ,CAAC,MAAM,OAAO,IAAI,CAAA,OAAM,WAAY,KAAK,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAAA;AAAA,IAChH;AACQ,YAAA;AAAA;AACR,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AAChD,cAAQ,IAAK,QAAQ,KAAK,gBAAgB,QAAQ,CAAC;AAAA;AAAA,IACpD;AACQ,YAAA;AACD,WAAA;AAAA,EACR;AACD;"}