@hubspot/project-parsing-lib 0.1.11 → 0.2.0-beta.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/project-parsing-lib",
3
- "version": "0.1.11",
3
+ "version": "0.2.0-beta.0",
4
4
  "description": "Parsing library for converting projects directory structures to their intermediate representation",
5
5
  "license": "Apache-2.0",
6
6
  "main": "src/index.js",
package/src/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { IntermediateRepresentation, IntermediateRepresentationNode, IntermediateRepresentationLocalDev, TranslationContext, TranslationOptions, IntermediateRepresentationNodeLocalDev } from './lib/types';
2
+ import { ValidateFunction, AnySchema, ErrorObject } from 'ajv/dist/2020';
2
3
  export declare function translate(translationContext: TranslationContext, translationOptions?: TranslationOptions): Promise<IntermediateRepresentation>;
3
4
  export declare function translateForLocalDev(translationContext: TranslationContext): Promise<IntermediateRepresentationLocalDev>;
4
5
  export { isTranslationError } from './lib/errors';
@@ -7,3 +8,9 @@ export { migrate } from './lib/migrate';
7
8
  export { validateUid } from './lib/uid';
8
9
  export { mapToUserFriendlyName, mapToInternalType } from './lib/transform';
9
10
  export { getIntermediateRepresentationSchema } from './lib/schemas';
11
+ export { createAjvInstance } from './lib/validation';
12
+ export { ValidateFunction, AnySchema, ErrorObject };
13
+ export { metafileExtension, hsProjectJsonFilename } from './lib/constants';
14
+ export { Components } from './lib/types';
15
+ export { AjvErrorKeyword } from './lib/errors';
16
+ export { getInvalidJsonError, getMissingTypeError, getMissingConfigError, getMissingAccountIdError, getMissingRequiredFieldError, getFailedToFetchSchemasError, getUnsupportedTypeError, } from './lang/copy';
package/src/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getIntermediateRepresentationSchema = exports.mapToInternalType = exports.mapToUserFriendlyName = exports.validateUid = exports.migrate = exports.isTranslationError = void 0;
6
+ exports.getUnsupportedTypeError = exports.getFailedToFetchSchemasError = exports.getMissingRequiredFieldError = exports.getMissingAccountIdError = exports.getMissingConfigError = exports.getMissingTypeError = exports.getInvalidJsonError = exports.AjvErrorKeyword = exports.hsProjectJsonFilename = exports.metafileExtension = exports.createAjvInstance = exports.getIntermediateRepresentationSchema = exports.mapToInternalType = exports.mapToUserFriendlyName = exports.validateUid = exports.migrate = exports.isTranslationError = void 0;
7
7
  exports.translate = translate;
8
8
  exports.translateForLocalDev = translateForLocalDev;
9
9
  const files_1 = require("./lib/files");
@@ -57,3 +57,18 @@ Object.defineProperty(exports, "mapToUserFriendlyName", { enumerable: true, get:
57
57
  Object.defineProperty(exports, "mapToInternalType", { enumerable: true, get: function () { return transform_2.mapToInternalType; } });
58
58
  var schemas_1 = require("./lib/schemas");
59
59
  Object.defineProperty(exports, "getIntermediateRepresentationSchema", { enumerable: true, get: function () { return schemas_1.getIntermediateRepresentationSchema; } });
60
+ var validation_2 = require("./lib/validation");
61
+ Object.defineProperty(exports, "createAjvInstance", { enumerable: true, get: function () { return validation_2.createAjvInstance; } });
62
+ var constants_1 = require("./lib/constants");
63
+ Object.defineProperty(exports, "metafileExtension", { enumerable: true, get: function () { return constants_1.metafileExtension; } });
64
+ Object.defineProperty(exports, "hsProjectJsonFilename", { enumerable: true, get: function () { return constants_1.hsProjectJsonFilename; } });
65
+ var errors_2 = require("./lib/errors");
66
+ Object.defineProperty(exports, "AjvErrorKeyword", { enumerable: true, get: function () { return errors_2.AjvErrorKeyword; } });
67
+ var copy_2 = require("./lang/copy");
68
+ Object.defineProperty(exports, "getInvalidJsonError", { enumerable: true, get: function () { return copy_2.getInvalidJsonError; } });
69
+ Object.defineProperty(exports, "getMissingTypeError", { enumerable: true, get: function () { return copy_2.getMissingTypeError; } });
70
+ Object.defineProperty(exports, "getMissingConfigError", { enumerable: true, get: function () { return copy_2.getMissingConfigError; } });
71
+ Object.defineProperty(exports, "getMissingAccountIdError", { enumerable: true, get: function () { return copy_2.getMissingAccountIdError; } });
72
+ Object.defineProperty(exports, "getMissingRequiredFieldError", { enumerable: true, get: function () { return copy_2.getMissingRequiredFieldError; } });
73
+ Object.defineProperty(exports, "getFailedToFetchSchemasError", { enumerable: true, get: function () { return copy_2.getFailedToFetchSchemasError; } });
74
+ Object.defineProperty(exports, "getUnsupportedTypeError", { enumerable: true, get: function () { return copy_2.getUnsupportedTypeError; } });
@@ -27,6 +27,13 @@ export declare const errorMessages: {
27
27
  wrongDirectoryForComponent: (directory: string, componentType: string, componentMetadata: ComponentMetadata, correctDir: string) => string;
28
28
  };
29
29
  };
30
+ export declare function getInvalidJsonError(): string;
31
+ export declare function getMissingTypeError(): string;
32
+ export declare function getMissingConfigError(): string;
33
+ export declare function getMissingAccountIdError(): string;
34
+ export declare function getMissingRequiredFieldError(field: string): string;
35
+ export declare function getFailedToFetchSchemasError(): string;
36
+ export declare function getUnsupportedTypeError(type: string): string;
30
37
  export declare const logMessages: {
31
38
  files: {
32
39
  skippingPath: (path: string) => string;
package/src/lang/copy.js CHANGED
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logMessages = exports.errorMessages = void 0;
4
+ exports.getInvalidJsonError = getInvalidJsonError;
5
+ exports.getMissingTypeError = getMissingTypeError;
6
+ exports.getMissingConfigError = getMissingConfigError;
7
+ exports.getMissingAccountIdError = getMissingAccountIdError;
8
+ exports.getMissingRequiredFieldError = getMissingRequiredFieldError;
9
+ exports.getFailedToFetchSchemasError = getFailedToFetchSchemasError;
10
+ exports.getUnsupportedTypeError = getUnsupportedTypeError;
4
11
  const constants_1 = require("../lib/constants");
5
12
  const transform_1 = require("../lib/transform");
6
13
  exports.errorMessages = {
@@ -31,6 +38,27 @@ exports.errorMessages = {
31
38
  wrongDirectoryForComponent: (directory, componentType, componentMetadata, correctDir) => `The directory '${directory}' is incorrect for type '${componentType}'. ${componentMetadata.userFriendlyName} ${componentMetadata.userFriendlyTypePlural} should only be placed in the '${correctDir}' directory`,
32
39
  },
33
40
  };
41
+ function getInvalidJsonError() {
42
+ return exports.errorMessages.validation.invalidJson;
43
+ }
44
+ function getMissingTypeError() {
45
+ return exports.errorMessages.validation.missingType;
46
+ }
47
+ function getMissingConfigError() {
48
+ return exports.errorMessages.validation.missingConfig;
49
+ }
50
+ function getMissingAccountIdError() {
51
+ return exports.errorMessages.api.accountIdIsRequiredToFetchSchemas;
52
+ }
53
+ function getMissingRequiredFieldError(field) {
54
+ return exports.errorMessages.validation.missingRequiredField(field);
55
+ }
56
+ function getFailedToFetchSchemasError() {
57
+ return exports.errorMessages.api.failedToFetchSchemas;
58
+ }
59
+ function getUnsupportedTypeError(type) {
60
+ return exports.errorMessages.validation.unsupportedType(type);
61
+ }
34
62
  exports.logMessages = {
35
63
  files: {
36
64
  skippingPath: (path) => `Skipping ${path} as it is not in a valid directory`,
@@ -27,6 +27,7 @@ export declare const Components: Record<string, ComponentMetadata>;
27
27
  export declare const userFacingToInternalType: Record<string, string>;
28
28
  export declare const internalTypeToUserFacing: Record<string, string>;
29
29
  export declare const metafileExtension = "-hsmeta.json";
30
+ export declare const hsProjectJsonFilename = "hsproject.json";
30
31
  export declare const packageJson = "package.json";
31
32
  export declare const packageLockJson = "package-lock.json";
32
33
  export declare const allowedAppSubComponentsDirs: string[];
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.allowedSubComponentDirectories = exports.allowedComponentDirectories = exports.ProjectStructure = exports.allowedThemeSubComponentsDirs = exports.allowedAppSubComponentsDirs = exports.packageLockJson = exports.packageJson = exports.metafileExtension = exports.internalTypeToUserFacing = exports.userFacingToInternalType = exports.Components = exports.AutoGeneratedComponentTypes = exports.AppFunctionsPackageKey = exports.WorkflowActionsKey = exports.WebhooksKey = exports.VideoConferencingKey = exports.TimelineEventsKey = exports.MediaBridgeKey = exports.MarketingEventsKey = exports.SettingsKey = exports.CardsKey = exports.CallingKey = exports.AppObjectAssociationKey = exports.AppObjectKey = exports.AppFunctionsKey = exports.ThemeKey = exports.AppKey = void 0;
36
+ exports.allowedSubComponentDirectories = exports.allowedComponentDirectories = exports.ProjectStructure = exports.allowedThemeSubComponentsDirs = exports.allowedAppSubComponentsDirs = exports.packageLockJson = exports.packageJson = exports.hsProjectJsonFilename = exports.metafileExtension = exports.internalTypeToUserFacing = exports.userFacingToInternalType = exports.Components = exports.AutoGeneratedComponentTypes = exports.AppFunctionsPackageKey = exports.WorkflowActionsKey = exports.WebhooksKey = exports.VideoConferencingKey = exports.TimelineEventsKey = exports.MediaBridgeKey = exports.MarketingEventsKey = exports.SettingsKey = exports.CardsKey = exports.CallingKey = exports.AppObjectAssociationKey = exports.AppObjectKey = exports.AppFunctionsKey = exports.ThemeKey = exports.AppKey = void 0;
37
37
  // Top Level Component types
38
38
  const path = __importStar(require("path"));
39
39
  // Component types
@@ -159,6 +159,7 @@ exports.userFacingToInternalType = {
159
159
  };
160
160
  exports.internalTypeToUserFacing = Object.fromEntries(Object.entries(exports.userFacingToInternalType).map(([key, value]) => [value, key]));
161
161
  exports.metafileExtension = '-hsmeta.json';
162
+ exports.hsProjectJsonFilename = 'hsproject.json';
162
163
  exports.packageJson = 'package.json';
163
164
  exports.packageLockJson = 'package-lock.json';
164
165
  function getSubComponentDirsForParentType(parentComponent) {
@@ -8,3 +8,24 @@ export declare class TranslationError extends Error {
8
8
  constructor(message: string, transformations: Transformation[], errors: (ErrorObject[] | null | undefined)[], translationContext: TranslationContext);
9
9
  toString(): string;
10
10
  }
11
+ export declare const AjvErrorKeyword: {
12
+ AdditionalItems: string;
13
+ AdditionalProperties: string;
14
+ Dependencies: string;
15
+ Enum: string;
16
+ ExclusiveMaximum: string;
17
+ ExclusiveMinimum: string;
18
+ Maximum: string;
19
+ MaxItems: string;
20
+ MaxLength: string;
21
+ MaxProperties: string;
22
+ Minimum: string;
23
+ MinItems: string;
24
+ MinLength: string;
25
+ MinProperties: string;
26
+ MultipleOf: string;
27
+ OneOf: string;
28
+ Pattern: string;
29
+ Required: string;
30
+ Type: string;
31
+ };
package/src/lib/errors.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TranslationError = void 0;
6
+ exports.AjvErrorKeyword = exports.TranslationError = void 0;
7
7
  exports.isTranslationError = isTranslationError;
8
8
  exports.compileError = compileError;
9
9
  const copy_1 = require("../lang/copy");
@@ -152,3 +152,24 @@ function isEnumError(error) {
152
152
  function isTypeError(error) {
153
153
  return error.keyword === JSON_SCHEMA_VALIDATION_KEYWORDS.type;
154
154
  }
155
+ exports.AjvErrorKeyword = {
156
+ AdditionalItems: 'additionalItems',
157
+ AdditionalProperties: 'additionalProperties',
158
+ Dependencies: 'dependencies',
159
+ Enum: 'enum',
160
+ ExclusiveMaximum: 'exclusiveMaximum',
161
+ ExclusiveMinimum: 'exclusiveMinimum',
162
+ Maximum: 'maximum',
163
+ MaxItems: 'maxItems',
164
+ MaxLength: 'maxLength',
165
+ MaxProperties: 'maxProperties',
166
+ Minimum: 'minimum',
167
+ MinItems: 'minItems',
168
+ MinLength: 'minLength',
169
+ MinProperties: 'minProperties',
170
+ MultipleOf: 'multipleOf',
171
+ OneOf: 'oneOf',
172
+ Pattern: 'pattern',
173
+ Required: 'required',
174
+ Type: 'type',
175
+ };
@@ -12,22 +12,21 @@ const constants_1 = require("./constants");
12
12
  const index_1 = require("../index");
13
13
  const IR_FILENAME = 'ir.json';
14
14
  const filesDirectory = 'files';
15
- const hsProjectJsonFilename = 'hsproject.json';
16
15
  const OUTPUT_IR_FILE = 'FULL_IR.json';
17
16
  async function migrate(inputDir, outputDir) {
18
17
  if (!fs_2.default.existsSync(inputDir)) {
19
18
  throw new Error(`Input directory ${inputDir} does not exist`);
20
19
  }
21
- const hsProjectJsonPath = path_1.default.join(inputDir, hsProjectJsonFilename);
20
+ const hsProjectJsonPath = path_1.default.join(inputDir, constants_1.hsProjectJsonFilename);
22
21
  if (!fs_2.default.existsSync(hsProjectJsonPath)) {
23
- throw new Error(`hsproject.json file does not exist in ${inputDir}`);
22
+ throw new Error(`${constants_1.hsProjectJsonFilename} file does not exist in ${inputDir}`);
24
23
  }
25
24
  let hsProjectJson;
26
25
  try {
27
26
  hsProjectJson = loadJsonFile(hsProjectJsonPath);
28
27
  }
29
28
  catch (e) {
30
- throw new Error(`Error parsing hsproject.json: ${e}`);
29
+ throw new Error(`Error parsing ${constants_1.hsProjectJsonFilename}: ${e}`);
31
30
  }
32
31
  const files = await (0, fs_1.walk)(inputDir);
33
32
  const sourceCodeOutputDir = path_1.default.join(outputDir, 'src');
@@ -1,5 +1,5 @@
1
1
  import { CompiledError, IntermediateRepresentation, Transformation, TranslationContext } from './types';
2
- import { ValidateFunction } from 'ajv/dist/2020';
2
+ import Ajv, { ValidateFunction } from 'ajv/dist/2020';
3
3
  export type ValidResult = {
4
4
  valid: true;
5
5
  errors?: null;
@@ -10,4 +10,5 @@ export type ValidationResults = {
10
10
  errors?: CompiledError;
11
11
  schemaValidationErrors?: ValidateFunction['errors'];
12
12
  } | ValidResult;
13
+ export declare function createAjvInstance(): Ajv;
13
14
  export declare function validateIntermediateRepresentation(intermediateRepresentation: IntermediateRepresentation, transformation: Transformation[], translationContext: TranslationContext): Promise<ValidResult>;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createAjvInstance = createAjvInstance;
6
7
  exports.validateIntermediateRepresentation = validateIntermediateRepresentation;
7
8
  const schemas_1 = require("./schemas");
8
9
  const _2020_1 = __importDefault(require("ajv/dist/2020"));
@@ -13,6 +14,11 @@ const path_1 = __importDefault(require("path"));
13
14
  const transform_1 = require("./transform");
14
15
  const ajv_formats_1 = __importDefault(require("ajv-formats"));
15
16
  const uid_1 = require("./uid");
17
+ function createAjvInstance() {
18
+ const ajv = new _2020_1.default({ allErrors: true });
19
+ (0, ajv_formats_1.default)(ajv);
20
+ return ajv;
21
+ }
16
22
  function validateIntermediateRepresentationNode(schema, transformation, irNode, index, translationContext) {
17
23
  if (constants_1.AutoGeneratedComponentTypes.includes((0, transform_1.mapToUserFacingType)(irNode.componentType))) {
18
24
  // Skip validation for auto-generated components
@@ -26,8 +32,7 @@ function validateIntermediateRepresentationNode(schema, transformation, irNode,
26
32
  errors: (0, errors_1.compileError)(transformation[index]),
27
33
  };
28
34
  }
29
- const ajv = new _2020_1.default({ allErrors: true });
30
- (0, ajv_formats_1.default)(ajv);
35
+ const ajv = createAjvInstance();
31
36
  let shouldSkipValidation = false;
32
37
  if (!irNode.uid) {
33
38
  transformation[index].fileParseResult.errors.push(copy_1.errorMessages.validation.missingUid);