@intrig/core 0.0.15-21 → 0.0.15-23

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 (2) hide show
  1. package/main.js +100 -45
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -2845,7 +2845,8 @@ rest_resource_data_ts_decorate([
2845
2845
  ], Variable.prototype, "in", void 0);
2846
2846
  rest_resource_data_ts_decorate([
2847
2847
  (0,swagger.ApiProperty)({
2848
- description: 'Reference of the variable'
2848
+ description: 'Reference of the variable',
2849
+ required: false
2849
2850
  }),
2850
2851
  rest_resource_data_ts_metadata("design:type", String)
2851
2852
  ], Variable.prototype, "ref", void 0);
@@ -3234,13 +3235,18 @@ function jsonLiteral(path) {
3234
3235
 
3235
3236
  ;// ../../lib/common/src/lib/template/template-util.ts
3236
3237
  function getVariableName(ref) {
3238
+ if (!ref) return undefined;
3237
3239
  return ref.split('/').pop();
3238
3240
  }
3239
3241
  function getVariableImports(variables, source, prefix) {
3240
- return variables.map((a)=>getVariableName(a.ref)).map((ref)=>`import { ${ref} } from "${prefix}/${source}/components/schemas/${ref}"`).join("\n");
3242
+ return variables.filter((a)=>a.ref) // Skip variables without schema refs
3243
+ .map((a)=>getVariableName(a.ref)).filter((ref)=>!!ref).map((ref)=>`import { ${ref} } from "${prefix}/${source}/components/schemas/${ref}"`).join("\n");
3241
3244
  }
3242
3245
  function getVariableTypes(variables) {
3243
- return variables.map((p)=>`${p.name}${p.in === "path" ? "" : "?"}: ${getVariableName(p.ref)}`).join("\n");
3246
+ return variables.map((p)=>{
3247
+ const typeName = getVariableName(p.ref) ?? 'any'; // Use 'any' for inline schemas
3248
+ return `${p.name}${p.in === "path" ? "" : "?"}: ${typeName}`;
3249
+ }).join("\n");
3244
3250
  }
3245
3251
  function isParamMandatory(variables) {
3246
3252
  return variables.some((a)=>a.in === 'path');
@@ -7621,6 +7627,17 @@ var external_node_crypto_ = __webpack_require__(1273);
7621
7627
 
7622
7628
 
7623
7629
 
7630
+ // HTTP methods to process during normalization
7631
+ const HTTP_METHODS = [
7632
+ 'get',
7633
+ 'post',
7634
+ 'put',
7635
+ 'delete',
7636
+ 'patch',
7637
+ 'options',
7638
+ 'head',
7639
+ 'trace'
7640
+ ];
7624
7641
  // Utility to generate type names
7625
7642
  function generateTypeName(operationOb, postFix) {
7626
7643
  return [
@@ -7649,12 +7666,7 @@ function registerTags(spec) {
7649
7666
  for (const pathItem of Object.values(paths)){
7650
7667
  const pathItemObject = pathItem;
7651
7668
  for (const [method, operation] of Object.entries(pathItemObject)){
7652
- if ([
7653
- "get",
7654
- "post",
7655
- "put",
7656
- "delete"
7657
- ].includes(method.toLowerCase())) {
7669
+ if (HTTP_METHODS.includes(method.toLowerCase())) {
7658
7670
  const operationOb = operation;
7659
7671
  operationOb.tags?.forEach((tag)=>{
7660
7672
  draft.tags = draft.tags ?? [];
@@ -7676,12 +7688,7 @@ function generateOperationIds(spec) {
7676
7688
  for (const [path, pathItem] of Object.entries(paths)){
7677
7689
  const pathItemObject = pathItem;
7678
7690
  for (const [method, operation] of Object.entries(pathItemObject)){
7679
- if ([
7680
- "get",
7681
- "post",
7682
- "put",
7683
- "delete"
7684
- ].includes(method.toLowerCase())) {
7691
+ if (HTTP_METHODS.includes(method.toLowerCase())) {
7685
7692
  const operationOb = operation;
7686
7693
  if (!operationOb.operationId) {
7687
7694
  operationOb.operationId = camelCase(`${method.toLowerCase()}_${path.replace("/", "_")}`);
@@ -7699,12 +7706,7 @@ function normalizeParameters(spec) {
7699
7706
  for (const pathItem of Object.values(paths)){
7700
7707
  const pathItemObject = pathItem;
7701
7708
  for (const [method, operation] of Object.entries(pathItemObject)){
7702
- if ([
7703
- "get",
7704
- "post",
7705
- "put",
7706
- "delete"
7707
- ].includes(method.toLowerCase())) {
7709
+ if (HTTP_METHODS.includes(method.toLowerCase())) {
7708
7710
  const operationOb = operation;
7709
7711
  if (operationOb.parameters) {
7710
7712
  operationOb.parameters = operationOb.parameters.map(doDeref).map((a)=>a);
@@ -7733,12 +7735,7 @@ function normalizeRequestBodies(spec) {
7733
7735
  for (const pathItem of Object.values(paths)){
7734
7736
  const pathItemObject = pathItem;
7735
7737
  for (const [method, operation] of Object.entries(pathItemObject)){
7736
- if ([
7737
- "get",
7738
- "post",
7739
- "put",
7740
- "delete"
7741
- ].includes(method.toLowerCase())) {
7738
+ if (HTTP_METHODS.includes(method.toLowerCase())) {
7742
7739
  const operationOb = operation;
7743
7740
  if (operationOb.requestBody) {
7744
7741
  const requestBody = doDeref(operationOb.requestBody);
@@ -7774,12 +7771,7 @@ function normalizeCallbacks(spec) {
7774
7771
  for (const pathItem of Object.values(paths)){
7775
7772
  const pathItemObject = pathItem;
7776
7773
  for (const [method, operation] of Object.entries(pathItemObject)){
7777
- if ([
7778
- "get",
7779
- "post",
7780
- "put",
7781
- "delete"
7782
- ].includes(method.toLowerCase())) {
7774
+ if (HTTP_METHODS.includes(method.toLowerCase())) {
7783
7775
  const operationOb = operation;
7784
7776
  if (operationOb.callbacks) {
7785
7777
  operationOb.callbacks = Object.fromEntries(Object.entries(operationOb.callbacks).map(([k, v])=>[
@@ -7800,12 +7792,7 @@ function normalizeResponses(spec) {
7800
7792
  for (const pathItem of Object.values(paths)){
7801
7793
  const pathItemObject = pathItem;
7802
7794
  for (const [method, operation] of Object.entries(pathItemObject)){
7803
- if ([
7804
- "get",
7805
- "post",
7806
- "put",
7807
- "delete"
7808
- ].includes(method.toLowerCase())) {
7795
+ if (HTTP_METHODS.includes(method.toLowerCase())) {
7809
7796
  const operationOb = operation;
7810
7797
  if (operationOb.responses) {
7811
7798
  operationOb.responses = Object.fromEntries(Object.entries(operationOb.responses).map(([k, v])=>[
@@ -7900,19 +7887,66 @@ class ExtractRequestsService {
7900
7887
  this.logger.debug(`Processing ${pathCount} paths from OpenAPI spec`);
7901
7888
  const requests = [];
7902
7889
  const skippedEndpoints = [];
7890
+ const httpMethods = [
7891
+ 'get',
7892
+ 'put',
7893
+ 'post',
7894
+ 'delete',
7895
+ 'options',
7896
+ 'head',
7897
+ 'patch',
7898
+ 'trace'
7899
+ ];
7903
7900
  for (const [path, pathData] of Object.entries(spec.paths)){
7904
7901
  this.logger.debug(`Processing path: ${path}`);
7902
+ // Extract path-level parameters
7903
+ const pathItem = pathData;
7904
+ const pathLevelParams = (pathItem.parameters ?? []).map((p)=>deref(spec)(p)).filter((p)=>!!p);
7905
7905
  for (const [method, methodData] of Object.entries(pathData)){
7906
+ // Skip non-HTTP method properties (parameters, summary, description, servers, $ref)
7907
+ if (!httpMethods.includes(method.toLowerCase())) {
7908
+ continue;
7909
+ }
7906
7910
  const operation = deref(spec)(methodData);
7907
7911
  if (this.isOperationObject(operation)) {
7908
7912
  this.logger.debug(`Processing operation: ${method.toUpperCase()} ${path} (${operation.operationId})`);
7909
- const variables = operation.parameters?.map((p)=>p)?.map((param)=>{
7913
+ // Merge path-level and operation-level parameters (operation params override path params)
7914
+ const operationParams = (operation.parameters ?? []).map((p)=>deref(spec)(p)).filter((p)=>!!p);
7915
+ const mergedParams = [
7916
+ ...pathLevelParams
7917
+ ];
7918
+ for (const opParam of operationParams){
7919
+ const existingIndex = mergedParams.findIndex((p)=>p.name === opParam.name && p.in === opParam.in);
7920
+ if (existingIndex >= 0) {
7921
+ mergedParams[existingIndex] = opParam; // Override path-level param
7922
+ } else {
7923
+ mergedParams.push(opParam);
7924
+ }
7925
+ }
7926
+ const variables = mergedParams.map((param)=>{
7910
7927
  return {
7911
7928
  name: param.name,
7912
7929
  in: param.in,
7913
- ref: isRef(param.schema) ? param.schema.$ref : "any"
7930
+ // Use undefined for inline schemas instead of "any" to avoid reserved keyword issues
7931
+ ref: isRef(param.schema) ? param.schema.$ref : undefined
7914
7932
  };
7915
- }) ?? [];
7933
+ });
7934
+ // Auto-detect path parameters from URL that are missing from parameters array
7935
+ // This handles incomplete swagger specs where {param} is in URL but not defined in parameters
7936
+ const pathParamRegex = /\{([^}]+)\}/g;
7937
+ let match;
7938
+ while((match = pathParamRegex.exec(path)) !== null){
7939
+ const paramName = match[1];
7940
+ const alreadyDefined = variables.some((v)=>v.name === paramName && v.in === 'path');
7941
+ if (!alreadyDefined) {
7942
+ this.logger.debug(`Auto-detected missing path parameter '${paramName}' from URL: ${path}`);
7943
+ variables.push({
7944
+ name: paramName,
7945
+ in: 'path',
7946
+ ref: undefined // No schema available, will use 'any' type
7947
+ });
7948
+ }
7949
+ }
7916
7950
  let params = {
7917
7951
  paths: [
7918
7952
  operation.tags?.[0]
@@ -10565,7 +10599,7 @@ function search_service_ts_metadata(k, v) {
10565
10599
  };
10566
10600
  /**
10567
10601
  * HTTP methods recognized for method-only search
10568
- */ const HTTP_METHODS = [
10602
+ */ const search_service_HTTP_METHODS = [
10569
10603
  'GET',
10570
10604
  'POST',
10571
10605
  'PUT',
@@ -10943,7 +10977,7 @@ class SearchService {
10943
10977
  }
10944
10978
  // Handle HTTP method-only query (e.g., "GET", "POST")
10945
10979
  const upperQuery = trimmed.toUpperCase();
10946
- if (HTTP_METHODS.includes(upperQuery)) {
10980
+ if (search_service_HTTP_METHODS.includes(upperQuery)) {
10947
10981
  return this.countAllWithFilters({
10948
10982
  ...opts,
10949
10983
  method: upperQuery
@@ -10973,7 +11007,7 @@ class SearchService {
10973
11007
  }
10974
11008
  // Handle HTTP method-only query (e.g., "GET", "POST")
10975
11009
  const upperQuery = trimmed.toUpperCase();
10976
- if (HTTP_METHODS.includes(upperQuery)) {
11010
+ if (search_service_HTTP_METHODS.includes(upperQuery)) {
10977
11011
  return this.listAllWithFilters({
10978
11012
  ...opts,
10979
11013
  method: upperQuery
@@ -19566,6 +19600,27 @@ async function bootstrapDaemon() {
19566
19600
  const discovery = app.get(DiscoveryService);
19567
19601
  const intrigConfig = app.get(IntrigConfigService).get();
19568
19602
  discovery.register(actualPort, url, intrigConfig.generator);
19603
+ // Handle crashes and cleanup discovery file
19604
+ let isCleaningUp = false;
19605
+ const cleanupAndExit = (reason, err)=>{
19606
+ if (isCleaningUp) return; // Prevent re-entrancy
19607
+ isCleaningUp = true;
19608
+ logger?.error(`Daemon crash (${reason}):`, err?.stack || err);
19609
+ // Synchronously cleanup discovery file - don't rely on async app.close()
19610
+ try {
19611
+ discovery.onApplicationShutdown(reason);
19612
+ } catch (cleanupErr) {
19613
+ logger?.error('Failed to cleanup discovery file:', cleanupErr);
19614
+ }
19615
+ // Give logs time to flush, then exit
19616
+ setImmediate(()=>process.exit(1));
19617
+ };
19618
+ process.on('uncaughtException', (err)=>{
19619
+ cleanupAndExit('uncaughtException', err);
19620
+ });
19621
+ process.on('unhandledRejection', (reason)=>{
19622
+ cleanupAndExit('unhandledRejection', reason instanceof Error ? reason : new Error(String(reason)));
19623
+ });
19569
19624
  logger?.log(`🚀 Application is running on: ${url}/${globalPrefix}`);
19570
19625
  logger?.log(`📖 Swagger docs available at: ${url}/docs`);
19571
19626
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intrig/core",
3
- "version": "0.0.15-21",
3
+ "version": "0.0.15-23",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {