@technicity/data-service-generator 0.22.0 → 0.22.2-next.0

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.
@@ -111,6 +111,11 @@ async function generate(input) {
111
111
  devDependencies: {
112
112
  "@types/node": require("../../package.json").devDependencies["@types/node"],
113
113
  typescript: require("../../package.json").devDependencies.typescript
114
+ },
115
+ // Not `resolutions` because npm used for install
116
+ overrides: {
117
+ // Fix for: `Cannot find type definition file for 'glob'`
118
+ glob: ">9.0.0"
114
119
  }
115
120
  };
116
121
  const tmpDirPath = path.join(os.tmpdir(),
@@ -159,8 +164,8 @@ async function generate(input) {
159
164
  // TODO: workaround for IRuntime.d.ts not being included
160
165
  // copyFileSync hangs for some reason, so use writeFileSync + readFileSync instead
161
166
  fs.writeFileSync(path.join(tmpBuildOutputPath, "IRuntime.d.ts"), fs.existsSync(path.join(__dirname, "../runtime", "IRuntime.d.ts"))
162
- ? fs.readFileSync(path.join(__dirname, "../runtime", "IRuntime.d.ts"))
163
- : fs.readFileSync(sourceIRuntimeFilePath));
167
+ ? fs.readFileSync(path.join(__dirname, "../runtime", "IRuntime.d.ts"), "utf-8")
168
+ : fs.readFileSync(sourceIRuntimeFilePath, "utf-8"));
164
169
  if (dialect === "mysql" && input.outputSqliteSchema) {
165
170
  // Since mysql2sqlite outputs a malformed string if a column
166
171
  // has the name `enum`, temporarily change the name to something else,
@@ -371,10 +376,17 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts,
371
376
  }))).join("\n\n")}
372
377
 
373
378
  ${(await Promise.all(input.flatMap(async (x) => {
379
+ if (x.kind === "postOne") {
380
+ return getMethodSourceOnHandlerPostOne(x);
381
+ }
374
382
  if (x.kind === "patchOne") {
375
383
  const findOnes = await getFindOnes(x, specialCaseUuidColumn);
376
384
  return getMethodSourceOnHandlerPatchOne(x, findOnes);
377
385
  }
386
+ if (x.kind === "deleteOne") {
387
+ const findOnes = await getFindOnes(x, specialCaseUuidColumn);
388
+ return getMethodSourceOnHandlerDeleteOne(x, findOnes);
389
+ }
378
390
  })))
379
391
  .filter(Boolean)
380
392
  .join("\n\n")}
@@ -563,6 +575,16 @@ function getMethodSourcePostOne(x, specialCaseUuidColumn, isTransaction) {
563
575
  });
564
576
  }`;
565
577
  }
578
+ function getMethodSourceOnHandlerPostOne(x) {
579
+ return `on${(0, capitalizeFirstLetter_1.capitalizeFirstLetter)(x.methodName)}(handler:
580
+ (sdk: InstanceType<typeof SDK>, input: { data: ${x.typeDataName} },
581
+ output: Partial<${getTypeReturnName(x.table)}>,
582
+ context: TContext,
583
+ ) => Promise<void>
584
+ ): void {
585
+ this.onHandlerMap.set("${mapKindToAction(x.kind)}-${x.table}", handler);
586
+ }`;
587
+ }
566
588
  function getMethodSourcePatchOne(x, findOnes, isTransaction) {
567
589
  const param2 = `{ ${keyFields}?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }`;
568
590
  return `async ${x.methodName}<T extends ${param2}>(
@@ -593,7 +615,8 @@ function getMethodSourceOnHandlerPatchOne(x, findOnes) {
593
615
  (sdk: InstanceType<typeof SDK>, input: { $where: ${findOnes
594
616
  .map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
595
617
  .join(" | ")}, data: ${x.typeDataName} },
596
- output: Partial<${getTypeReturnName(x.table)}>
618
+ output: Partial<${getTypeReturnName(x.table)}>,
619
+ context: TContext,
597
620
  ) => Promise<void>
598
621
  ): void {
599
622
  this.onHandlerMap.set("${mapKindToAction(x.kind)}-${x.table}", handler);
@@ -643,6 +666,18 @@ function getMethodSourceDeleteOne(x, findOnes, isTransaction) {
643
666
  });
644
667
  }`;
645
668
  }
669
+ function getMethodSourceOnHandlerDeleteOne(x, findOnes) {
670
+ return `on${(0, capitalizeFirstLetter_1.capitalizeFirstLetter)(x.methodName)}(handler:
671
+ (sdk: InstanceType<typeof SDK>, input: { $where: ${findOnes
672
+ .map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
673
+ .join(" | ")}, },
674
+ output: void,
675
+ context: TContext,
676
+ ) => Promise<void>
677
+ ): void {
678
+ this.onHandlerMap.set("${mapKindToAction(x.kind)}-${x.table}", handler);
679
+ }`;
680
+ }
646
681
  function getMethodSourceDeleteList(x, isTransaction) {
647
682
  return `async ${x.methodName}(
648
683
  param1: { $where?: ${x.typeWhereName} },
@@ -29,11 +29,15 @@ export type TResolveParams = {
29
29
  }>;
30
30
  sdk?: unknown;
31
31
  };
32
- export type TOnHandler = (sdk: unknown, input: unknown, output: unknown) => Promise<void>;
32
+ export type TOnHandler = (sdk: unknown, input: unknown, output: unknown, TContext: TContext) => Promise<void>;
33
33
  export declare class EventOnHandlerError<T> extends Event {
34
34
  error: T;
35
+ resource: string;
36
+ action: TAction;
35
37
  constructor(message: string, data: ConstructorParameters<typeof Event>[1] & {
36
38
  error: T;
39
+ resource: string;
40
+ action: TAction;
37
41
  });
38
42
  }
39
43
  export type TContext = {
@@ -5,6 +5,8 @@ class EventOnHandlerError extends Event {
5
5
  constructor(message, data) {
6
6
  super(message, data);
7
7
  this.error = data.error;
8
+ this.resource = data.resource;
9
+ this.action = data.action;
8
10
  }
9
11
  }
10
12
  exports.EventOnHandlerError = EventOnHandlerError;
@@ -72,10 +72,10 @@ async function resolve(input, dbCall, formatQuery, beginTransaction, dialect, mi
72
72
  asyncLocalStorage != null &&
73
73
  asyncLocalStorage?.getStore()?.isInOnHandler !== true) {
74
74
  return p.then((output) => asyncLocalStorage
75
- .run({ isInOnHandler: true }, async () => onHandler(input.sdk, { ...input.args, data: input.data }, output))
75
+ .run({ isInOnHandler: true }, async () => onHandler(input.sdk, { ...input.args, data: input.data }, output, context))
76
76
  .then(() => output)
77
77
  .catch((error) => {
78
- input.eventTarget.dispatchEvent(new IRuntime_1.EventOnHandlerError("error", { error }));
78
+ input.eventTarget.dispatchEvent(new IRuntime_1.EventOnHandlerError("error", { error, resource: input.resource, action: input.action }));
79
79
  return output;
80
80
  }));
81
81
  }
@@ -90,10 +90,10 @@ async function resolve(input, dbCall, formatQuery, beginTransaction, dialect, mi
90
90
  asyncLocalStorage != null &&
91
91
  asyncLocalStorage?.getStore()?.isInOnHandler !== true) {
92
92
  return p.then((output) => asyncLocalStorage
93
- .run({ isInOnHandler: true }, async () => onHandler(input.sdk, { ...input.args, data: input.data }, output))
93
+ .run({ isInOnHandler: true }, async () => onHandler(input.sdk, { ...input.args, data: input.data }, output, context))
94
94
  .then(() => output)
95
95
  .catch((error) => {
96
- input.eventTarget.dispatchEvent(new IRuntime_1.EventOnHandlerError("error", { error }));
96
+ input.eventTarget.dispatchEvent(new IRuntime_1.EventOnHandlerError("error", { error, resource: input.resource, action: input.action }));
97
97
  return output;
98
98
  }));
99
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.22.0",
3
+ "version": "0.22.2-next.0",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -47,6 +47,6 @@
47
47
  "typescript": "5.5.2"
48
48
  },
49
49
  "resolutions": {
50
- "tar-fs": "2.1.2"
50
+ "tar-fs": "2.1.3"
51
51
  }
52
52
  }