@narrative.io/data-collaboration-sdk-ts 0.0.32 → 0.0.34

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.
@@ -1,5 +1,5 @@
1
1
  export type Attribute = PrimitiveAttribute | ArrayAttribute | ObjectAttribute;
2
- interface BaseAttribute {
2
+ export interface BaseAttribute {
3
3
  id: number;
4
4
  name: string;
5
5
  display_name?: string;
@@ -7,26 +7,25 @@ interface BaseAttribute {
7
7
  type: string;
8
8
  validations?: string[];
9
9
  }
10
- interface PrimitiveAttribute extends BaseAttribute {
10
+ export interface PrimitiveAttribute extends BaseAttribute {
11
11
  type: 'string' | 'boolean' | 'double' | 'long' | 'timestamptz';
12
12
  enum?: string[] | number[] | boolean[];
13
13
  is_join_key?: boolean;
14
14
  }
15
- type SubAttribute = Partial<Omit<Attribute, 'name' | 'id'>> & {
15
+ export type SubAttribute = Partial<Omit<Attribute, 'name' | 'id'>> & {
16
16
  type: string;
17
17
  enum?: string[] | number[] | boolean[];
18
18
  is_join_key?: boolean;
19
19
  };
20
- interface RefAttribute {
20
+ export interface RefAttribute {
21
21
  $ref: number;
22
22
  }
23
- interface ArrayAttribute extends BaseAttribute {
23
+ export interface ArrayAttribute extends BaseAttribute {
24
24
  type: 'array';
25
25
  items: SubAttribute;
26
26
  }
27
- interface ObjectAttribute extends BaseAttribute {
27
+ export interface ObjectAttribute extends BaseAttribute {
28
28
  type: 'object';
29
29
  properties: Record<string, SubAttribute | RefAttribute>;
30
30
  required?: string[];
31
31
  }
32
- export {};
@@ -1,6 +1,7 @@
1
1
  import { type ApiRecords } from '../types';
2
2
  import { BaseApi } from '../base-api';
3
- import { type Dataset, type DatasetTableSummaryAPIResponse } from './types';
3
+ import { type FilePerSnapshotResponse, type Dataset, type DatasetTableSummaryAPIResponse } from './types';
4
+ export { type FilePerSnapshotResponse, type Dataset, type DatasetTableSummaryAPIResponse };
4
5
  /**
5
6
  * @module DatasetApi
6
7
  * @description This module provides methods for fetching datasets.
@@ -42,4 +43,32 @@ export declare class DatasetApi extends BaseApi {
42
43
  const records = await getDatasetSample(datasetId, size);
43
44
  */
44
45
  getDatasetSample(datasetId: number, size?: number): Promise<ApiRecords<Record<string, string>>>;
46
+ /**
47
+ * Fetches a list of dataset files based on the provided parameters.
48
+ *
49
+ * @param {number} datasetId - The ID of the dataset to fetch files for.
50
+ * @param {number} [size] - The number of snapshots to return. Optional.
51
+ * @param {number} [offset] - The starting index of the file list. Optional.
52
+ * @param {string} [afterTimestamp] - Fetch files with a timestamp greater than or equal to the given value. Optional.
53
+ * @param {number} [fromSnapshotId] - Fetch files from the specified snapshot ID. Optional.
54
+ * @returns {Promise<FilePerSnapshotResponse>} A Promise that resolves with the fetched dataset files.
55
+ * @throws {Error} If there is an issue with the request or the response.
56
+ * @memberof DatasetApi
57
+ * @public
58
+ */
59
+ getDatasetFiles(datasetId: number, size?: number, offset?: number, afterTimestamp?: string, fromSnapshotId?: number): Promise<FilePerSnapshotResponse>;
60
+ /**
61
+ * Fetches the download URL for a specific dataset file.
62
+ *
63
+ * @param {number} datasetId - The ID of the dataset to fetch the file download URL for.
64
+ * @param {number} snapshotId - The ID of the snapshot the file is associated with.
65
+ * @param {string} fileId - The ID of the file to fetch the download URL for.
66
+ * @returns {Promise<{ download_url: string }>} A Promise that resolves with an object containing the download URL.
67
+ * @throws {Error} If there is an issue with the request or the response.
68
+ * @memberof DatasetApi
69
+ * @public
70
+ */
71
+ getDatasetFileDownloadUrl(datasetId: number, snapshotId: number, fileId: string): Promise<{
72
+ download_url: string;
73
+ }>;
45
74
  }
@@ -49,4 +49,43 @@ export class DatasetApi extends BaseApi {
49
49
  async getDatasetSample(datasetId, size = 1000) {
50
50
  return await this.get(`${resourceName}/${datasetId}/sample?size=${size}`);
51
51
  }
52
+ /**
53
+ * Fetches a list of dataset files based on the provided parameters.
54
+ *
55
+ * @param {number} datasetId - The ID of the dataset to fetch files for.
56
+ * @param {number} [size] - The number of snapshots to return. Optional.
57
+ * @param {number} [offset] - The starting index of the file list. Optional.
58
+ * @param {string} [afterTimestamp] - Fetch files with a timestamp greater than or equal to the given value. Optional.
59
+ * @param {number} [fromSnapshotId] - Fetch files from the specified snapshot ID. Optional.
60
+ * @returns {Promise<FilePerSnapshotResponse>} A Promise that resolves with the fetched dataset files.
61
+ * @throws {Error} If there is an issue with the request or the response.
62
+ * @memberof DatasetApi
63
+ * @public
64
+ */
65
+ async getDatasetFiles(datasetId, size, offset, afterTimestamp, fromSnapshotId) {
66
+ const params = new URLSearchParams();
67
+ if (size != null)
68
+ params.append('per_page', String(size));
69
+ if (offset != null)
70
+ params.append('offset', String(offset));
71
+ if (afterTimestamp != null)
72
+ params.append('timestamp.gte', afterTimestamp);
73
+ if (fromSnapshotId != null)
74
+ params.append('from_snapshot_id', String(fromSnapshotId));
75
+ return await this.get(`${resourceName}/${datasetId}/find-files?${params.toString()}`);
76
+ }
77
+ /**
78
+ * Fetches the download URL for a specific dataset file.
79
+ *
80
+ * @param {number} datasetId - The ID of the dataset to fetch the file download URL for.
81
+ * @param {number} snapshotId - The ID of the snapshot the file is associated with.
82
+ * @param {string} fileId - The ID of the file to fetch the download URL for.
83
+ * @returns {Promise<{ download_url: string }>} A Promise that resolves with an object containing the download URL.
84
+ * @throws {Error} If there is an issue with the request or the response.
85
+ * @memberof DatasetApi
86
+ * @public
87
+ */
88
+ async getDatasetFileDownloadUrl(datasetId, snapshotId, fileId) {
89
+ return await this.get(`${resourceName}/${datasetId}/snapshots/${snapshotId}/files-added/${fileId}/download`);
90
+ }
52
91
  }
@@ -10,6 +10,8 @@ export interface Dataset {
10
10
  tags: string[];
11
11
  updated_at: Date;
12
12
  write_mode: DatasetWriteMode;
13
+ last_snapshot_created_at?: string;
14
+ active_dataset_stored_bytes?: number;
13
15
  }
14
16
  export interface DatasetColumnSummary {
15
17
  id: number;
@@ -74,4 +76,18 @@ interface Schema {
74
76
  required: string[];
75
77
  primary: string;
76
78
  }
79
+ interface File {
80
+ path: string;
81
+ size: number;
82
+ }
83
+ interface Snapshot {
84
+ files: File[];
85
+ snapshot_id: number;
86
+ timestamp: string;
87
+ }
88
+ export interface FilePerSnapshotResponse {
89
+ files_per_snapshot: Snapshot[];
90
+ has_next: boolean;
91
+ next_snapshot: number | null;
92
+ }
77
93
  export {};
package/build/index.d.ts CHANGED
@@ -3,10 +3,11 @@ import { DatasetApi } from './datasets';
3
3
  import { HealthCheckApi } from './health';
4
4
  import { RosettaStoneApi } from './rosetta-stone';
5
5
  import { type Environment, type Config, type ApiRecords, type MonetaryAmount } from './types';
6
- import { type DatasetTableSummaryAPIResponse, type Dataset, type DatasetTableSummary } from './datasets/types';
6
+ import { type DatasetTableSummaryAPIResponse, type Dataset, type DatasetTableSummary, type FilePerSnapshotResponse } from './datasets/types';
7
7
  import { type HealthCheckResult } from './health/types';
8
8
  import { type SampleRecords } from './rosetta-stone/types';
9
9
  import { AttributeApi } from './attributes';
10
+ import { type Resource, ResourceApi, type BucketCreationRequest, type UpdateAccessTypeRequest } from './resources';
10
11
  import { type Attribute } from './attributes/types';
11
12
  import { PingApi } from './ping';
12
13
  import { UploadsApi } from './uploads';
@@ -17,6 +18,6 @@ import { CompanyInfoApi, type CompanyInfo } from './company-info';
17
18
  import { InstallationsApi, type Installation } from './installations';
18
19
  declare class NarrativeApi extends BaseApi {
19
20
  }
20
- interface NarrativeApi extends BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi, AttributeApi, PingApi, CompanyInfoApi, InstallationsApi, UploadsApi {
21
+ interface NarrativeApi extends BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi, AttributeApi, PingApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi {
21
22
  }
22
- export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi, type UploadsResponse, type PingStatus, type Attribute, type Environment, type Config, type ApiRecords, type Dataset, type HealthCheckResult, type SampleRecords, type DatasetTableSummary, type DatasetTableSummaryAPIResponse, type Product, type MonetaryAmount, type CompanyInfo, type Installation };
23
+ export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi, type Resource, type UploadsResponse, type PingStatus, type Attribute, type Environment, type Config, type ApiRecords, type Dataset, type HealthCheckResult, type SampleRecords, type DatasetTableSummary, type DatasetTableSummaryAPIResponse, type Product, type MonetaryAmount, type CompanyInfo, type Installation, type FilePerSnapshotResponse, type BucketCreationRequest, type UpdateAccessTypeRequest };
package/build/index.js CHANGED
@@ -4,6 +4,7 @@ import { HealthCheckApi } from './health';
4
4
  import { RosettaStoneApi } from './rosetta-stone';
5
5
  import { applyMixins } from './utils';
6
6
  import { AttributeApi } from './attributes';
7
+ import { ResourceApi } from './resources';
7
8
  import { PingApi } from './ping';
8
9
  import { UploadsApi } from './uploads';
9
10
  import { ProductsApi } from './products';
@@ -11,5 +12,5 @@ import { CompanyInfoApi } from './company-info';
11
12
  import { InstallationsApi } from './installations';
12
13
  class NarrativeApi extends BaseApi {
13
14
  }
14
- applyMixins(NarrativeApi, [BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi, AttributeApi, PingApi, CompanyInfoApi, InstallationsApi, UploadsApi]);
15
- export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi };
15
+ applyMixins(NarrativeApi, [BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi, AttributeApi, PingApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi]);
16
+ export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @fileoverview This module provides methods for fetching resources.
3
+ * @author Your Name
4
+ */
5
+ import { type ApiRecords } from '../types';
6
+ import { BaseApi } from '../base-api';
7
+ import { type Resource, type BucketCreationRequest, type UpdateAccessTypeRequest } from './types';
8
+ export { type Resource, type BucketCreationRequest, type UpdateAccessTypeRequest };
9
+ /**
10
+ * @class ResourceApi
11
+ * @extends {BaseApi}
12
+ * @description This class provides methods for fetching resources.
13
+ */
14
+ export declare class ResourceApi extends BaseApi {
15
+ /**
16
+ * @function getBuckets
17
+ * @memberof ResourceApi
18
+ * @description Fetches a list of buckets for a given datasetId.
19
+ * @returns {Promise<ApiRecords<Resource>>} A promise that resolves to the list of resources.
20
+ */
21
+ getBuckets(): Promise<ApiRecords<Resource>>;
22
+ /**
23
+ * @function createBucket
24
+ * @memberof ResourceApi
25
+ * @description Creates a new bucket.
26
+ * @param {BucketCreationRequest} request - The bucket creation request object.
27
+ * @returns {Promise<Resource>} A promise that resolves to the created resource.
28
+ */
29
+ createBucket(request: BucketCreationRequest): Promise<Resource>;
30
+ /**
31
+ * @function updateAccessType
32
+ * @memberof ResourceApi
33
+ * @description Updates the access type of a resource.
34
+ * @param {UpdateAccessTypeRequest} request - The update access type request object.
35
+ * @returns {Promise<Resource>} A promise that resolves to the updated resource.
36
+ */
37
+ updateAccessType(request: UpdateAccessTypeRequest): Promise<Resource>;
38
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @fileoverview This module provides methods for fetching resources.
3
+ * @author Your Name
4
+ */
5
+ import { BaseApi } from '../base-api';
6
+ const resourceName = 'resources';
7
+ /**
8
+ * @class ResourceApi
9
+ * @extends {BaseApi}
10
+ * @description This class provides methods for fetching resources.
11
+ */
12
+ export class ResourceApi extends BaseApi {
13
+ /**
14
+ * @function getBuckets
15
+ * @memberof ResourceApi
16
+ * @description Fetches a list of buckets for a given datasetId.
17
+ * @returns {Promise<ApiRecords<Resource>>} A promise that resolves to the list of resources.
18
+ */
19
+ async getBuckets() {
20
+ return await this.get(`${resourceName}/buckets`);
21
+ }
22
+ /**
23
+ * @function createBucket
24
+ * @memberof ResourceApi
25
+ * @description Creates a new bucket.
26
+ * @param {BucketCreationRequest} request - The bucket creation request object.
27
+ * @returns {Promise<Resource>} A promise that resolves to the created resource.
28
+ */
29
+ async createBucket(request) {
30
+ return await this.post(`${resourceName}/buckets`, request);
31
+ }
32
+ /**
33
+ * @function updateAccessType
34
+ * @memberof ResourceApi
35
+ * @description Updates the access type of a resource.
36
+ * @param {UpdateAccessTypeRequest} request - The update access type request object.
37
+ * @returns {Promise<Resource>} A promise that resolves to the updated resource.
38
+ */
39
+ async updateAccessType(request) {
40
+ return await this.post(`${resourceName}/buckets/access`, request);
41
+ }
42
+ }
@@ -0,0 +1,31 @@
1
+ export interface Resource {
2
+ id: string;
3
+ company_id: number;
4
+ auth: {
5
+ type: 'bucket_policy' | 'role';
6
+ account_id: string;
7
+ external_id?: string;
8
+ role?: string;
9
+ };
10
+ name: string;
11
+ created_at: string;
12
+ updated_at: string;
13
+ is_access_mutable: boolean;
14
+ }
15
+ export interface RoleBasedBucketAccess {
16
+ type: 'role';
17
+ external_id: string;
18
+ }
19
+ export interface PolicyBasedBucketAccess {
20
+ type: 'bucket_policy';
21
+ }
22
+ export interface UpdateAccessTypeRequest {
23
+ bucket_name: string;
24
+ new_access: BucketAccess;
25
+ }
26
+ export type BucketAccess = RoleBasedBucketAccess | PolicyBasedBucketAccess;
27
+ export interface BucketCreationRequest {
28
+ account_id: string;
29
+ resource_id: string;
30
+ access: BucketAccess;
31
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narrative.io/data-collaboration-sdk-ts",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "main": "build/index.js",
5
5
  "repository": "github:narrative-io/data-collaboration-sdk-ts",
6
6
  "source": "src/index.ts",
@@ -35,7 +35,7 @@
35
35
  "eslint-plugin-promise": "^6.1.1",
36
36
  "jest": "^29.4.3",
37
37
  "ts-jest": "^29.0.5",
38
- "typescript": "^4.9.5",
38
+ "typescript": "^5.0.2",
39
39
  "husky": "^8.0.0"
40
40
  },
41
41
  "dependencies": {