@snowtop/ent 0.2.7 → 0.2.9

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 (61) hide show
  1. package/action/executor.js +4 -4
  2. package/action/operations.js +3 -0
  3. package/action/orchestrator.js +10 -12
  4. package/action/topological_sort.d.ts +9 -0
  5. package/action/topological_sort.js +46 -0
  6. package/core/base.d.ts +11 -4
  7. package/core/clause.d.ts +3 -5
  8. package/core/clause.js +32 -0
  9. package/core/config.d.ts +26 -2
  10. package/core/config.js +7 -1
  11. package/core/context.js +5 -12
  12. package/core/db.d.ts +12 -2
  13. package/core/db.js +102 -7
  14. package/core/dev_schema.d.ts +9 -0
  15. package/core/dev_schema.js +306 -0
  16. package/core/ent.d.ts +3 -5
  17. package/core/ent.js +22 -7
  18. package/core/extensions.d.ts +25 -0
  19. package/core/extensions.js +220 -0
  20. package/core/loaders/assoc_count_loader.js +2 -5
  21. package/core/loaders/assoc_edge_loader.js +5 -8
  22. package/core/loaders/loader.js +1 -1
  23. package/core/loaders/object_loader.js +3 -6
  24. package/core/loaders/query_loader.d.ts +2 -5
  25. package/core/loaders/query_loader.js +11 -10
  26. package/core/memoize.d.ts +1 -0
  27. package/core/memoize.js +15 -0
  28. package/core/query/custom_clause_query.js +5 -1
  29. package/core/query/query.d.ts +1 -1
  30. package/core/query/query.js +10 -7
  31. package/core/query_expression.d.ts +6 -0
  32. package/core/query_expression.js +2 -0
  33. package/core/query_impl.d.ts +19 -3
  34. package/core/query_impl.js +148 -35
  35. package/index.d.ts +5 -1
  36. package/index.js +9 -2
  37. package/package.json +1 -7
  38. package/parse_schema/parse.d.ts +2 -12
  39. package/parse_schema/parse.js +22 -41
  40. package/schema/index.d.ts +1 -1
  41. package/schema/schema.d.ts +20 -1
  42. package/scripts/custom_graphql.js +12 -5
  43. package/scripts/fix_action_exports.js +1 -1
  44. package/scripts/migrate_v0.1.js +2 -5
  45. package/scripts/move_types.js +1 -1
  46. package/scripts/parse_args.d.ts +3 -0
  47. package/scripts/parse_args.js +74 -0
  48. package/scripts/read_schema.js +2 -5
  49. package/testutils/builder.js +1 -2
  50. package/testutils/parse_sql.js +1 -1
  51. package/tsc/compilerOptions.d.ts +2 -2
  52. package/tsc/compilerOptions.js +12 -18
  53. package/tsc/move_generated.js +2 -2
  54. package/tsc/transform.d.ts +1 -1
  55. package/tsc/transform.js +16 -2
  56. package/tsc/transform_action.d.ts +1 -1
  57. package/tsc/transform_action.js +1 -1
  58. package/tsc/transform_ent.d.ts +1 -1
  59. package/tsc/transform_ent.js +1 -1
  60. package/tsc/transform_schema.d.ts +1 -1
  61. package/tsc/transform_schema.js +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -9,17 +9,11 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "@types/node": "^25.0.3",
12
- "cosmiconfig": "^9.0.0",
13
12
  "dataloader": "^2.2.3",
14
13
  "glob": "^13.0.0",
15
- "graph-data-structure": "^4.5.0",
16
14
  "js-yaml": "^4.1.1",
17
- "json5": "^2.2.3",
18
15
  "luxon": "^3.7.2",
19
- "memoizee": "^0.4.17",
20
- "minimist": "^1.2.8",
21
16
  "pg": "^8.16.3",
22
- "prettier": "^3.7.4",
23
17
  "ts-node": "^11.0.0-beta.1",
24
18
  "tsconfig-paths": "^4.2.0",
25
19
  "tslib": "^2.8.1",
@@ -1,5 +1,5 @@
1
1
  import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
2
- import { ActionField, Type, FieldMap, GlobalSchema, EdgeIndex, TransformReadBetaResult, CanViewerDo } from "../schema/schema";
2
+ import { ActionField, Type, DBExtension, FieldMap, GlobalSchema, EdgeIndex, TransformReadBetaResult, CanViewerDo } from "../schema/schema";
3
3
  export declare function processFields(src: FieldMap | Field[], patternName?: string): Promise<ProcessedField[]>;
4
4
  declare enum NullableResult {
5
5
  CONTENTS = "contents",
@@ -68,22 +68,11 @@ interface Result {
68
68
  schemas: schemasDict;
69
69
  patterns: patternsDict;
70
70
  globalSchema?: ProcessedGlobalSchema;
71
- config?: {
72
- rome?: BiomeConfig;
73
- };
74
71
  }
75
72
  declare type PotentialSchemas = {
76
73
  [key: string]: any;
77
74
  };
78
75
  export declare function parseSchema(potentialSchemas: PotentialSchemas, globalSchema?: GlobalSchema): Promise<Result>;
79
- interface BiomeConfig {
80
- indentStyle?: string;
81
- lineWidth?: number;
82
- indentSize?: number;
83
- quoteStyle?: string;
84
- quoteProperties?: string;
85
- trailingComma?: string;
86
- }
87
76
  interface ProcessedGlobalSchema {
88
77
  globalEdges: ProcessedAssocEdge[];
89
78
  extraEdgeFields: ProcessedField[];
@@ -91,5 +80,6 @@ interface ProcessedGlobalSchema {
91
80
  init?: boolean;
92
81
  transformsEdges?: boolean;
93
82
  globalFields?: ProcessedField[];
83
+ dbExtensions?: DBExtension[];
94
84
  }
95
85
  export {};
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processFields = processFields;
4
4
  exports.parseSchema = parseSchema;
5
- const cosmiconfig_1 = require("cosmiconfig");
6
5
  const const_1 = require("../core/const");
7
6
  const global_schema_1 = require("../core/global_schema");
8
7
  async function processFields(src, patternName) {
@@ -448,53 +447,31 @@ async function parseSchema(potentialSchemas, globalSchema) {
448
447
  }
449
448
  schemas[key] = processedSchema;
450
449
  }
451
- const biome = translatePrettier();
452
450
  return {
453
451
  schemas,
454
452
  patterns: processPatterns.patternsDict,
455
453
  globalSchema: parsedGlobalSchema,
456
- config: {
457
- rome: biome,
458
- },
459
454
  };
460
455
  }
461
- function translatePrettier() {
462
- const r = (0, cosmiconfig_1.cosmiconfigSync)("prettier").search();
463
- if (!r) {
464
- return;
465
- }
466
- const ret = {};
467
- if (r.config.printWidth !== undefined) {
468
- ret.lineWidth = parseInt(r.config.printWidth);
469
- }
470
- if (r.config.useTabs) {
471
- ret.indentStyle = "tab";
472
- }
473
- else {
474
- ret.indentStyle = "space";
475
- }
476
- if (r.config.tabWidth !== undefined) {
477
- ret.indentSize = parseInt(r.config.tabWidth);
478
- }
479
- if (r.config.singleQuote) {
480
- ret.quoteStyle = "single";
481
- }
482
- else {
483
- ret.quoteStyle = "double";
484
- }
485
- if (r.config.quoteProps !== undefined) {
486
- if (r.config.quoteProps === "consistent") {
487
- // biome doesn't support this
488
- ret.quoteProperties = "as-needed";
489
- }
490
- else {
491
- ret.quoteProperties = r.config.quoteProps;
492
- }
456
+ function normalizeProvisionedBy(extension) {
457
+ if (extension.provisionedBy === "ent" ||
458
+ extension.provisionedBy === "external") {
459
+ return extension.provisionedBy;
493
460
  }
494
- if (r.config.trailingComma !== undefined) {
495
- ret.trailingComma = r.config.trailingComma;
461
+ if (extension.provisionedBy) {
462
+ throw new Error(`invalid provisionedBy ${extension.provisionedBy} for db extension ${extension.name}`);
496
463
  }
497
- return ret;
464
+ return "ent";
465
+ }
466
+ function processDBExtensions(src) {
467
+ return src
468
+ .map((extension) => ({
469
+ ...extension,
470
+ provisionedBy: normalizeProvisionedBy(extension),
471
+ runtimeSchemas: extension.runtimeSchemas || [],
472
+ dropCascade: extension.dropCascade === true,
473
+ }))
474
+ .sort((lhs, rhs) => lhs.name.localeCompare(rhs.name));
498
475
  }
499
476
  async function parseGlobalSchema(s) {
500
477
  const ret = {
@@ -504,7 +481,8 @@ async function parseGlobalSchema(s) {
504
481
  !!s.edgeIndices ||
505
482
  s.transformEdgeRead !== undefined ||
506
483
  s.transformEdgeWrite !== undefined ||
507
- s.fields !== undefined,
484
+ s.fields !== undefined ||
485
+ !!s.dbExtensions?.length,
508
486
  transformsEdges: !!s.transformEdgeRead || !!s.transformEdgeWrite,
509
487
  };
510
488
  if (s.extraEdgeFields) {
@@ -519,5 +497,8 @@ async function parseGlobalSchema(s) {
519
497
  if (s.fields) {
520
498
  ret.globalFields = await processFields(s.fields);
521
499
  }
500
+ if (s.dbExtensions) {
501
+ ret.dbExtensions = processDBExtensions(s.dbExtensions);
502
+ }
522
503
  return ret;
523
504
  }
package/schema/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Schema from "./schema";
2
2
  export { Schema };
3
- export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, getFieldsWithPrivacy, getFieldsWithEditPrivacy, getStorageKey, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, EdgeIndex, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, EdgeUpdateOperation, TransformedEdgeUpdateOperation, getTransformedReadClause, getObjectLoaderProperties, GlobalSchema, ActionField, } from "./schema";
3
+ export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, getFieldsWithPrivacy, getFieldsWithEditPrivacy, getStorageKey, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, EdgeIndex, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, EdgeUpdateOperation, TransformedEdgeUpdateOperation, getTransformedReadClause, getObjectLoaderProperties, GlobalSchema, DBExtension, ActionField, } from "./schema";
4
4
  export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, EntSchema, EntSchemaWithTZ, SchemaConfig, } from "./base_schema";
5
5
  export * from "./field";
6
6
  export * from "./json_field";
@@ -13,6 +13,15 @@ interface FieldInfo {
13
13
  export type FieldInfoMap = {
14
14
  [key: string]: FieldInfo;
15
15
  };
16
+ export interface DBExtension {
17
+ name: string;
18
+ provisionedBy?: "ent" | "external";
19
+ version?: string;
20
+ installSchema?: string;
21
+ runtimeSchemas?: string[];
22
+ dropCascade?: boolean;
23
+ [x: string]: any;
24
+ }
16
25
  export interface GlobalSchema {
17
26
  edges?: Edge[];
18
27
  extraEdgeFields?: FieldMap;
@@ -20,6 +29,7 @@ export interface GlobalSchema {
20
29
  transformEdgeRead?: () => Clause;
21
30
  transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
22
31
  fields?: FieldMap;
32
+ dbExtensions?: DBExtension[];
23
33
  }
24
34
  type FieldOverride = Pick<FieldOptions, "nullable" | "storageKey" | "serverDefault" | "unique" | "hideFromGraphQL" | "graphqlName" | "index" | "indexConcurrently" | "indexWhere">;
25
35
  export type FieldOverrideMap = {
@@ -186,6 +196,8 @@ export interface Type {
186
196
  deprecatedIntEnumMap?: IntEnumMap;
187
197
  disableUnknownType?: boolean;
188
198
  globalType?: string;
199
+ postgresType?: string;
200
+ dbExtension?: string;
189
201
  importType?: DeprecatedImportType;
190
202
  subFields?: FieldMap;
191
203
  unionFields?: FieldMap;
@@ -361,9 +373,16 @@ export interface Index {
361
373
  columns: string[];
362
374
  unique?: boolean;
363
375
  fulltext?: FullText;
364
- indexType?: "gin" | "btree";
376
+ indexType?: string;
365
377
  concurrently?: boolean;
366
378
  where?: string;
379
+ ops?: {
380
+ [column: string]: string;
381
+ };
382
+ indexParams?: {
383
+ [key: string]: string | number | boolean;
384
+ };
385
+ dbExtension?: string;
367
386
  [x: string]: any;
368
387
  }
369
388
  export interface EdgeIndex extends Omit<Index, "name"> {
@@ -38,20 +38,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  const glob = __importStar(require("glob"));
41
- const json5_1 = __importDefault(require("json5"));
42
- const minimist_1 = __importDefault(require("minimist"));
43
41
  const path = __importStar(require("path"));
44
42
  const fs = __importStar(require("fs"));
43
+ const typescript_1 = __importDefault(require("typescript"));
45
44
  const graphql_1 = require("../graphql/graphql");
46
45
  const readline = __importStar(require("readline"));
47
46
  const imports_1 = require("../imports");
48
47
  const process_1 = require("process");
49
48
  const child_process_1 = require("child_process");
50
49
  const const_1 = require("../core/const");
50
+ const { parseArgs } = require("./parse_args");
51
51
  // need to use the GQLCapture from the package so that when we call GQLCapture.enable()
52
52
  // we're affecting the local paths as opposed to a different instance
53
53
  // life is hard
54
54
  const MODULE_PATH = const_1.GRAPHQL_PATH;
55
+ function parseJSONC(fileName, text) {
56
+ const { config, error } = typescript_1.default.parseConfigFileTextToJson(fileName, text);
57
+ if (error) {
58
+ throw new Error(typescript_1.default.flattenDiagnosticMessageText(error.messageText, "\n"));
59
+ }
60
+ return config;
61
+ }
55
62
  async function readInputs() {
56
63
  return new Promise((resolve) => {
57
64
  const rl = readline.createInterface({
@@ -195,7 +202,7 @@ async function captureDynamic(filePath, gqlCapture) {
195
202
  reject(new Error(`error code ${code} on dynamic path`));
196
203
  return;
197
204
  }
198
- let json = json5_1.default.parse(datas.join(""));
205
+ const json = parseJSONC(filePath, datas.join(""));
199
206
  processJSON(gqlCapture, json);
200
207
  resolve(undefined);
201
208
  });
@@ -228,7 +235,7 @@ async function processJSON(gqlCapture, json) {
228
235
  }
229
236
  async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
230
237
  if (jsonPath !== undefined) {
231
- let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
238
+ const json = parseJSONC(jsonPath, fs.readFileSync(jsonPath, {
232
239
  encoding: "utf8",
233
240
  }));
234
241
  processJSON(gqlCapture, json);
@@ -331,7 +338,7 @@ function findGraphQLPath(filePath) {
331
338
  // also, there should be a way to get the list of objects here that's not manual
332
339
  //echo "User\nContact\nContactEmail\nComment" | ts-node-script --log-error --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/custom_graphql.ts --path ~/code/ent/examples/simple/src/
333
340
  async function main() {
334
- const options = (0, minimist_1.default)(process.argv.slice(2));
341
+ const options = parseArgs(process.argv.slice(2));
335
342
  if (!options.path) {
336
343
  throw new Error("path required");
337
344
  }
@@ -39,7 +39,7 @@ const typescript_1 = __importStar(require("typescript"));
39
39
  class FixActionExports {
40
40
  constructor() {
41
41
  this.glob = "src/ent/**/actions/*_action.ts";
42
- this.prettierGlob = "src/ent/**/actions/*_action.ts";
42
+ this.formatGlob = "src/ent/**/actions/*_action.ts";
43
43
  }
44
44
  traverseChild(sourceFile, contents, file, node) {
45
45
  if (!(0, typescript_1.isClassDeclaration)(node)) {
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const minimist_1 = __importDefault(require("minimist"));
3
+ const { parseArgs } = require("./parse_args");
7
4
  const transform_1 = require("../tsc/transform");
8
5
  const transform_schema_1 = require("../tsc/transform_schema");
9
6
  const transform_ent_1 = require("../tsc/transform_ent");
@@ -14,7 +11,7 @@ const ast_1 = require("../tsc/ast");
14
11
  // ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/migrate_v0.1.ts --transform_schema --old_base_class BaseEntTodoSchema --new_schema_class TodoEntSchema --transform_path src/schema/patterns/base
15
12
  function main() {
16
13
  const customInfo = (0, ast_1.getCustomInfo)();
17
- const options = (0, minimist_1.default)(process.argv.slice(2));
14
+ const options = parseArgs(process.argv.slice(2));
18
15
  // install 0.1.x dependencies
19
16
  // maybe provide options to make this easier if someone wants to do this in steps to see what's happening
20
17
  if (options.move_generated) {
@@ -66,7 +66,7 @@ class GatherExportsInGeneratedTypes {
66
66
  class TransformImports {
67
67
  constructor() {
68
68
  this.glob = "src/**/*.ts";
69
- this.prettierGlob = "src/**/*.ts";
69
+ this.formatGlob = "src/**/*.ts";
70
70
  this.impsToMove = new Map();
71
71
  this.cwd = "";
72
72
  this.relative = false;
@@ -0,0 +1,3 @@
1
+ export function parseArgs(argv: any): {
2
+ _: never[];
3
+ };
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ function coerceValue(value) {
3
+ if (value === "true") {
4
+ return true;
5
+ }
6
+ if (value === "false") {
7
+ return false;
8
+ }
9
+ return value;
10
+ }
11
+ function normalizeKey(key) {
12
+ return key.replace(/-/g, "_");
13
+ }
14
+ function setOption(result, key, value) {
15
+ result[key] = value;
16
+ const normalized = normalizeKey(key);
17
+ if (normalized !== key) {
18
+ result[normalized] = value;
19
+ }
20
+ }
21
+ function parseArgs(argv) {
22
+ const result = { _: [] };
23
+ const args = argv || process.argv.slice(2);
24
+ for (let i = 0; i < args.length; i++) {
25
+ const arg = args[i];
26
+ if (arg === "--") {
27
+ result._.push(...args.slice(i + 1));
28
+ break;
29
+ }
30
+ if (!arg.startsWith("-") || arg === "-") {
31
+ result._.push(arg);
32
+ continue;
33
+ }
34
+ if (arg.startsWith("--no-")) {
35
+ setOption(result, normalizeKey(arg.slice(5)), false);
36
+ continue;
37
+ }
38
+ if (arg.startsWith("--")) {
39
+ const body = arg.slice(2);
40
+ const idx = body.indexOf("=");
41
+ if (idx !== -1) {
42
+ setOption(result, normalizeKey(body.slice(0, idx)), coerceValue(body.slice(idx + 1)));
43
+ continue;
44
+ }
45
+ const key = normalizeKey(body);
46
+ const next = args[i + 1];
47
+ if (next !== undefined && !next.startsWith("-")) {
48
+ setOption(result, key, coerceValue(next));
49
+ i++;
50
+ }
51
+ else {
52
+ setOption(result, key, true);
53
+ }
54
+ continue;
55
+ }
56
+ const shorts = arg.slice(1);
57
+ if (shorts.length === 1) {
58
+ const next = args[i + 1];
59
+ if (next !== undefined && !next.startsWith("-")) {
60
+ setOption(result, shorts, coerceValue(next));
61
+ i++;
62
+ }
63
+ else {
64
+ setOption(result, shorts, true);
65
+ }
66
+ continue;
67
+ }
68
+ for (const ch of shorts) {
69
+ setOption(result, ch, true);
70
+ }
71
+ }
72
+ return result;
73
+ }
74
+ module.exports = { parseArgs };
@@ -32,18 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
35
  Object.defineProperty(exports, "__esModule", { value: true });
39
36
  const glob = __importStar(require("glob"));
40
37
  const path = __importStar(require("path"));
41
- const minimist_1 = __importDefault(require("minimist"));
38
+ const { parseArgs } = require("./parse_args");
42
39
  const parse_1 = require("../parse_schema/parse");
43
40
  const ast_1 = require("../tsc/ast");
44
41
  const names_1 = require("../names/names");
45
42
  function main() {
46
- const options = (0, minimist_1.default)(process.argv.slice(2));
43
+ const options = parseArgs(process.argv.slice(2));
47
44
  if (!options.path) {
48
45
  throw new Error("path required");
49
46
  }
@@ -195,8 +195,7 @@ class SimpleBuilder {
195
195
  // create dynamic placeholder
196
196
  // TODO: do we need to use this as the node when there's an existingEnt
197
197
  // same for generated builders.
198
- this.placeholderID = `$ent.idPlaceholderID$ ${randomNum()}-${schema.ent
199
- ?.name}`;
198
+ this.placeholderID = `$ent.idPlaceholderID$ ${randomNum()}-${schema.ent?.name}`;
200
199
  if (this.operation === action_1.WriteOperation.Insert) {
201
200
  for (const [key, value] of fields) {
202
201
  if (key === "id" && value === "{id}") {
@@ -584,7 +584,7 @@ function parseUpdateStatement(ast, values, map, returningAll) {
584
584
  const colRef = "type" in setAny
585
585
  ? setAny
586
586
  : "column" in setAny
587
- ? setAny.column ?? setAny
587
+ ? (setAny.column ?? setAny)
588
588
  : setAny;
589
589
  const colName = typeof colRef === "string" ? colRef : getColumnFromRef(colRef);
590
590
  let value = getValueFromRegex(set.value, values);
@@ -1,7 +1,7 @@
1
1
  import ts from "typescript";
2
2
  export declare function readCompilerOptions(filePath: string): ts.CompilerOptions;
3
- export declare function getTarget(target?: string): ts.ScriptTarget;
4
- export declare function getModule(module?: string): ts.ModuleKind;
3
+ export declare function getTarget(target?: string | number): ts.ScriptTarget;
4
+ export declare function getModule(module?: string | number): ts.ModuleKind;
5
5
  export declare function getTargetFromCurrentDir(): ts.ScriptTarget;
6
6
  export declare function createSourceFile(target: ts.ScriptTarget, file: string): {
7
7
  contents: string;
@@ -42,7 +42,6 @@ exports.getModule = getModule;
42
42
  exports.getTargetFromCurrentDir = getTargetFromCurrentDir;
43
43
  exports.createSourceFile = createSourceFile;
44
44
  const fs = __importStar(require("fs"));
45
- const json5_1 = __importDefault(require("json5"));
46
45
  const typescript_1 = __importDefault(require("typescript"));
47
46
  const path = __importStar(require("path"));
48
47
  function findTSConfigFile(filePath) {
@@ -56,29 +55,21 @@ function findTSConfigFile(filePath) {
56
55
  return null;
57
56
  }
58
57
  function readCompilerOptions(filePath) {
59
- let configPath = findTSConfigFile(filePath);
58
+ const configPath = findTSConfigFile(filePath);
60
59
  if (!configPath) {
61
60
  return {};
62
61
  }
63
- let json = {};
64
- try {
65
- json = json5_1.default.parse(fs.readFileSync(configPath, {
66
- encoding: "utf8",
67
- }));
68
- }
69
- catch (e) {
62
+ const { config, error } = typescript_1.default.readConfigFile(configPath, typescript_1.default.sys.readFile);
63
+ if (error) {
70
64
  console.error("couldn't read tsconfig.json file");
65
+ return {};
71
66
  }
72
- let options = json["compilerOptions"] || {};
73
- // @ts-ignore
74
- if (options.moduleResolution === "node") {
75
- options.moduleResolution = typescript_1.default.ModuleResolutionKind.NodeJs;
76
- }
77
- options.target = getTarget(options.target);
78
- options.module = getModule(options.module);
79
- return options;
67
+ return typescript_1.default.parseJsonConfigFileContent(config, typescript_1.default.sys, path.dirname(configPath), undefined, configPath).options;
80
68
  }
81
69
  function getTarget(target) {
70
+ if (typeof target === "number") {
71
+ return target;
72
+ }
82
73
  switch (target?.toLowerCase()) {
83
74
  case "es2015":
84
75
  return typescript_1.default.ScriptTarget.ES2015;
@@ -105,6 +96,9 @@ function getTarget(target) {
105
96
  }
106
97
  }
107
98
  function getModule(module) {
99
+ if (typeof module === "number") {
100
+ return module;
101
+ }
108
102
  switch (module?.toLowerCase()) {
109
103
  case "none":
110
104
  return typescript_1.default.ModuleKind.None;
@@ -134,7 +128,7 @@ function getModule(module) {
134
128
  }
135
129
  function getTargetFromCurrentDir() {
136
130
  const options = readCompilerOptions(".");
137
- return getTarget(options.target?.toString());
131
+ return getTarget(options.target);
138
132
  }
139
133
  function createSourceFile(target, file) {
140
134
  let contents = fs.readFileSync(file).toString();
@@ -53,9 +53,9 @@ class MoveFiles {
53
53
  }
54
54
  }
55
55
  class TransformImports {
56
- constructor(glob, prettierGlob, relativeImports, checkRelativeImportsValid) {
56
+ constructor(glob, formatGlob, relativeImports, checkRelativeImportsValid) {
57
57
  this.glob = glob;
58
- this.prettierGlob = prettierGlob;
58
+ this.formatGlob = formatGlob;
59
59
  this.relativeImports = relativeImports;
60
60
  this.checkRelativeImportsValid = checkRelativeImportsValid;
61
61
  this.globOptions = {
@@ -16,7 +16,7 @@ export interface TransformFile {
16
16
  filter?(files: string[]): string[];
17
17
  fileToWrite?(file: string): string;
18
18
  postProcess?(file: string): void;
19
- prettierGlob?: string;
19
+ formatGlob?: string;
20
20
  }
21
21
  export declare function transform(transform: TransformFile): void;
22
22
  export {};
package/tsc/transform.js CHANGED
@@ -177,8 +177,22 @@ function transform(transform) {
177
177
  transform.postProcess(file);
178
178
  }
179
179
  });
180
- if (transform.prettierGlob) {
181
- (0, child_process_1.spawnSync)(`prettier`, [transform.prettierGlob, "--write"]);
180
+ if (transform.formatGlob) {
181
+ const files = glob
182
+ .sync(transform.formatGlob, transform.globOptions ?? {})
183
+ .map((f) => (typeof f === "string" ? f : f.path));
184
+ if (!files.length) {
185
+ return;
186
+ }
187
+ const result = (0, child_process_1.spawnSync)(`biome`, ["format", "--write", "--files-ignore-unknown=true", ...files], {
188
+ encoding: "utf8",
189
+ });
190
+ if (result.error) {
191
+ throw result.error;
192
+ }
193
+ if (result.status !== 0) {
194
+ throw new Error(result.stderr || "biome format failed");
195
+ }
182
196
  }
183
197
  }
184
198
  function isRequireStatement(node, sourceFile) {
@@ -4,7 +4,7 @@ import { TransformFile } from "./transform";
4
4
  export declare class TransformAction implements TransformFile {
5
5
  private customInfo;
6
6
  glob: string;
7
- prettierGlob: string;
7
+ formatGlob: string;
8
8
  constructor(customInfo: customInfo);
9
9
  traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
10
10
  node: ts.Node;
@@ -120,7 +120,7 @@ class TransformAction {
120
120
  constructor(customInfo) {
121
121
  this.customInfo = customInfo;
122
122
  this.glob = "src/ent/**/actions/**/*_action.ts";
123
- this.prettierGlob = "src/ent/**/actions/**.ts";
123
+ this.formatGlob = "src/ent/**/actions/**.ts";
124
124
  }
125
125
  traverseChild(sourceFile, contents, file, node) {
126
126
  if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
@@ -13,5 +13,5 @@ export declare class TransformEnt implements TransformFile {
13
13
  imports: Map<string, string[]>;
14
14
  node?: undefined;
15
15
  } | undefined;
16
- prettierGlob: string;
16
+ formatGlob: string;
17
17
  }
@@ -14,7 +14,7 @@ function isPrivacyPolicy(mm) {
14
14
  class TransformEnt {
15
15
  constructor() {
16
16
  this.glob = "src/ent/*.ts";
17
- this.prettierGlob = "src/ent/*.ts";
17
+ this.formatGlob = "src/ent/*.ts";
18
18
  }
19
19
  traverseChild(sourceFile, contents, file, node) {
20
20
  if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
@@ -23,5 +23,5 @@ export declare class TransformSchema implements TransformFile {
23
23
  } | undefined;
24
24
  fileToWrite(file: string): string;
25
25
  postProcess(file: string): void;
26
- prettierGlob: string;
26
+ formatGlob: string;
27
27
  }
@@ -211,7 +211,7 @@ function getConstructorElementInfo(fileContents, member, sourceFile) {
211
211
  return {
212
212
  key: "patterns",
213
213
  // remove this.addPatterns at the front, remove trailing ) at the end
214
- // if there's a trailing comma, it'll be handled by prettier
214
+ // if there's a trailing comma, it'll be handled by the formatter
215
215
  value: `[${line.slice(addPatterns.length, -1)}]`,
216
216
  comment: "",
217
217
  };
@@ -343,7 +343,7 @@ class TransformSchema {
343
343
  this.newSchemaClass = newSchemaClass;
344
344
  this.transformPath = transformPath;
345
345
  this.glob = "src/schema/*.ts";
346
- this.prettierGlob = "src/schema/*.ts";
346
+ this.formatGlob = "src/schema/*.ts";
347
347
  }
348
348
  transformSchema(className) {
349
349
  if (className === "BaseEntSchema" || className === "BaseEntSchemaWithTZ") {