Skip to content

Commit

Permalink
Fixing up some documentation, and define a constant to specify what f…
Browse files Browse the repository at this point in the history
…eatures the importer supports.
  • Loading branch information
Ben Helleman committed Sep 16, 2024
1 parent 0362ba4 commit 18487cb
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 171 deletions.
21 changes: 11 additions & 10 deletions packages/spacecat-shared-data-access/src/dto/import-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
import { createImportJob } from '../models/importer/import-job.js';

/**
* Data Transfer Object for ImportJob
* The ImportJobDto is a helper that can convert an ImportJob object to a DynamoDB item and
* vice versa.
*/

export const ImportJobDto = {

/**
* Converts an ImportJob object into a DynamoDB item.
* @param importJob
* @returns {{duration: *, baseURL: *, failedCount: *, apiKey: *,
* options: *, successCount: *, importQueueId: *, startTime: *, id: *,
* endTime: *, status: *}}
*/
* Converts an ImportJob object into a DynamoDB item.
* @param importJob
* @returns {{duration: *, baseURL: *, failedCount: *, apiKey: *,
* options: *, successCount: *, importQueueId: *, startTime: *, id: *,
* endTime: *, status: *}}
*/
toDynamoItem: (importJob) => ({
id: importJob.getId(),
baseURL: importJob.getBaseURL(),
Expand All @@ -43,8 +43,9 @@ export const ImportJobDto = {
}),

/**
* Converts a DynamoDB item into an ImportJob object.
*/
* Converts a DynamoDB item into an ImportJob object.
* @param {object} dynamoItem - The DynamoDB item to convert.
*/
fromDynamoItem: (dynamoItem) => {
const importJobData = {
id: dynamoItem.id,
Expand Down
14 changes: 8 additions & 6 deletions packages/spacecat-shared-data-access/src/dto/import-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
import { createImportUrl } from '../models/importer/import-url.js';

/**
* Data Transfer Object for ImportUrl
* The ImportUrlDto is a helper that can convert an ImportUrl object to a DynamoDB item and
* vice versa.
*/

export const ImportUrlDto = {

/**
* Converts an importUrl object to a DynamoDB item
*/
* Converts an ImportUrl object to a DynamoDB item.
* @returns {object} The new DynamoDB item.
*/
toDynamoItem: (importUrl) => ({
id: importUrl.getId(),
jobId: importUrl.getJobId(),
Expand All @@ -32,8 +33,9 @@ export const ImportUrlDto = {
}),

/**
* Converts a DynamoDB item into an ImportUrl object
*/
* Converts a DynamoDB item into an ImportUrl object.
* @param {object} dynamoItem - The DynamoDB item to convert.
*/
fromDynamoItem: (dynamoItem) => {
const importUrlData = {
id: dynamoItem.id,
Expand Down
14 changes: 14 additions & 0 deletions packages/spacecat-shared-data-access/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,20 @@ export interface ImportUrl {
*/
getJobId: () => string;

/**
* The reason that the import of a URL failed.
*/
getReason: () => string;

/**
* The absolute path to the resource that is being imported for the given URL.
*/
getFile: () => string;

/**
* Retrieves the resulting path and filename of the imported file.
*/
getPath: () => string;
}

/**
Expand Down
9 changes: 2 additions & 7 deletions packages/spacecat-shared-data-access/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/

import { createDataAccess } from './service/index.js';
import { ImportJobStatus } from './models/importer/import-job.js';
import { ImportUrlStatus } from './models/importer/import-url.js';

export { ImportJobStatus, ImportUrlStatus, ImportOptions } from './models/importer/import-constants.js';

const TABLE_NAME_AUDITS = 'spacecat-services-audits-dev';
const TABLE_NAME_KEY_EVENTS = 'spacecat-services-key-events';
Expand Down Expand Up @@ -113,8 +113,3 @@ export default function dataAccessWrapper(fn) {
return fn(request, context);
};
}

export {
ImportJobStatus,
ImportUrlStatus,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
/**
* Supported Import Options.
*/
export const ImportOptions = {
ENABLE_JAVASCRIPT: 'enableJavascript',
PAGE_LOAD_TIMEOUT: 'pageLoadTimeout',
};

/**
* Import Job Status types.
* Any changes to this object needs to be reflected in the index.d.ts file as well.
*/
export const ImportJobStatus = {
RUNNING: 'RUNNING',
COMPLETE: 'COMPLETE',
FAILED: 'FAILED',
};

/**
* ImportURL Status types.
* Any changes to this object needs to be reflected in the index.d.ts file as well.
*/
export const ImportUrlStatus = {
PENDING: 'PENDING',
REDIRECT: 'REDIRECT',
...ImportJobStatus,
};
Loading

0 comments on commit 18487cb

Please sign in to comment.