@lark-apaas/dataloom 0.1.1-alpha.1 → 0.1.1-alpha.2

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 (49) hide show
  1. package/README.md +812 -1
  2. package/lib/DataloomClient.d.ts +3 -4
  3. package/lib/DataloomClient.d.ts.map +1 -1
  4. package/lib/DataloomClient.js +7 -2
  5. package/lib/index.d.ts +1 -1
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.js +1 -1
  8. package/lib/service/services/DataloomServiceBase.d.ts.map +1 -1
  9. package/lib/service/services/DataloomServiceBase.js +1 -1
  10. package/lib/service/services/session-service/index.d.ts.map +1 -1
  11. package/lib/service/services/session-service/index.js +26 -0
  12. package/lib/service/utils/logger.d.ts +2 -2
  13. package/lib/service/utils/logger.d.ts.map +1 -1
  14. package/lib/service/utils/types.d.ts +2 -2
  15. package/lib/service/utils/types.d.ts.map +1 -1
  16. package/lib/storage/StorageClient.d.ts +9 -2
  17. package/lib/storage/StorageClient.d.ts.map +1 -1
  18. package/lib/storage/StorageClient.js +12 -3
  19. package/lib/storage/libs/errors.d.ts +9 -3
  20. package/lib/storage/libs/errors.d.ts.map +1 -1
  21. package/lib/storage/libs/errors.js +3 -3
  22. package/lib/storage/libs/fetch.d.ts +6 -6
  23. package/lib/storage/libs/fetch.d.ts.map +1 -1
  24. package/lib/storage/libs/fetch.js +21 -2
  25. package/lib/storage/libs/helpers.d.ts +4 -4
  26. package/lib/storage/libs/helpers.d.ts.map +1 -1
  27. package/lib/storage/libs/helpers.js +27 -14
  28. package/lib/storage/libs/index.d.ts +0 -1
  29. package/lib/storage/libs/index.d.ts.map +1 -1
  30. package/lib/storage/libs/index.js +0 -1
  31. package/lib/storage/libs/types.d.ts +4 -3
  32. package/lib/storage/libs/types.d.ts.map +1 -1
  33. package/lib/storage/packages/StorageFileApi.d.ts +1 -1
  34. package/lib/storage/packages/StorageFileApi.d.ts.map +1 -1
  35. package/lib/storage/packages/StorageFileApi.js +6 -1
  36. package/lib/storage/utils/logger.d.ts +2 -2
  37. package/lib/storage/utils/logger.d.ts.map +1 -1
  38. package/lib/utils/fetch.d.ts +1 -2
  39. package/lib/utils/fetch.d.ts.map +1 -1
  40. package/lib/utils/fetch.js +1 -1
  41. package/lib/utils/slardar.d.ts +2 -0
  42. package/lib/utils/slardar.d.ts.map +1 -0
  43. package/lib/utils/slardar.js +15 -0
  44. package/lib/utils/types.d.ts +3 -2
  45. package/lib/utils/types.d.ts.map +1 -1
  46. package/package.json +4 -1
  47. package/lib/storage/packages/StorageBucketApi.d.ts +0 -121
  48. package/lib/storage/packages/StorageBucketApi.d.ts.map +0 -1
  49. package/lib/storage/packages/StorageBucketApi.js +0 -135
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/storage/utils/logger.ts"],"names":[],"mappings":"AAAA,KAAK,WAAW,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE9D,KAAK,SAAS,GAAG;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,QAAQ,SAAS,EAAE,gBAAmB,SAoBhE,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,SAAS,MAAM,EACf,UAAU;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACnD,gBAAmB,SA0BpB,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/storage/utils/logger.ts"],"names":[],"mappings":"AAAA,KAAK,WAAW,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE9D,KAAK,SAAS,GAAG;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,QAAQ,SAAS,EAAE,gBAAmB,SAoBhE,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,SAAS,MAAM,EACf,UAAU;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC3D,gBAAmB,SA0BpB,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import type RateLimiter from '../RateLimiter';
2
- type Fetch = typeof fetch;
2
+ import type { Fetch } from './types';
3
3
  export declare const resolveFetch: (customFetch?: Fetch) => Fetch;
4
4
  export declare const fetchWithAuth: (dataloomKey: string, rateLimiter?: RateLimiter, customFetch?: Fetch) => Fetch;
5
- export {};
6
5
  //# sourceMappingURL=fetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAE9C,KAAK,KAAK,GAAG,OAAO,KAAK,CAAC;AAE1B,eAAO,MAAM,YAAY,GAAI,cAAc,KAAK,KAAG,KAQlD,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,aAAa,MAAM,EACnB,cAAc,WAAW,EACzB,cAAc,KAAK,KAClB,KAyBF,CAAC"}
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,eAAO,MAAM,YAAY,GAAI,cAAc,KAAK,KAAG,KAQlD,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,aAAa,MAAM,EACnB,cAAc,WAAW,EACzB,cAAc,KAAK,KAClB,KAyBF,CAAC"}
@@ -1,7 +1,7 @@
1
1
  const resolveFetch = (customFetch)=>{
2
2
  let _fetch;
3
3
  _fetch = customFetch ? customFetch : fetch;
4
- return (...args)=>_fetch(...args);
4
+ return (input, init)=>_fetch(input, init);
5
5
  };
6
6
  const fetchWithAuth = (dataloomKey, rateLimiter, customFetch)=>{
7
7
  const resolvedFetch = resolveFetch(customFetch);
@@ -0,0 +1,2 @@
1
+ export declare const reportDataloomException: (error: unknown, extra: Record<string, unknown>) => void;
2
+ //# sourceMappingURL=slardar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slardar.d.ts","sourceRoot":"","sources":["../../src/utils/slardar.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,uBAAuB,GAClC,OAAO,OAAO,EACd,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAY/B,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { slardar } from "@lark-apaas/internal-slardar";
2
+ const toRecordString = (record)=>Object.fromEntries(Object.entries(record).filter(([, value])=>null != value).map(([key, value])=>[
3
+ key,
4
+ String(value)
5
+ ]));
6
+ const reportDataloomException = (error, extra)=>{
7
+ try {
8
+ const categories = toRecordString({
9
+ source: 'dataloom',
10
+ ...extra
11
+ });
12
+ slardar.captureException(error, categories);
13
+ } catch {}
14
+ };
15
+ export { reportDataloomException };
@@ -1,4 +1,5 @@
1
- export type Fetch = typeof fetch;
1
+ export type Fetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
2
+ export type OnError = (error: unknown, instance: unknown) => void;
2
3
  export type DataloomClientOptions = {
3
4
  global?: {
4
5
  /**
@@ -28,7 +29,7 @@ export type DataloomClientOptions = {
28
29
  /**
29
30
  * Optional. The global hook that will be called when a request fails.
30
31
  */
31
- onError?: (error: any, instance: any) => void;
32
+ onError?: OnError;
32
33
  };
33
34
  };
34
35
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC;AAEjC,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,CAAC,EAAE;QACP;;WAEG;QACH,SAAS,EAAE,MAAM,CAAC;QAClB;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;QACd;;WAEG;QACH,KAAK,CAAC,EAAE,KAAK,CAAC;QACd;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEjC;;WAEG;QACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAE5B;;WAEG;QACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAE1B;;WAEG;QACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,KAAK,IAAI,CAAC;KAC/C,CAAC;CACH,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAExF,MAAM,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;AAElE,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,CAAC,EAAE;QACP;;WAEG;QACH,SAAS,EAAE,MAAM,CAAC;QAClB;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;QACd;;WAEG;QACH,KAAK,CAAC,EAAE,KAAK,CAAC;QACd;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEjC;;WAEG;QACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAE5B;;WAEG;QACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAE1B;;WAEG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;CACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/dataloom",
3
- "version": "0.1.1-alpha.1",
3
+ "version": "0.1.1-alpha.2",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -23,6 +23,9 @@
23
23
  "check": "biome check --write",
24
24
  "lint": "eslint src --ext .js,.jsx,.ts,.tsx"
25
25
  },
26
+ "dependencies": {
27
+ "@lark-apaas/internal-slardar": "^0.0.3"
28
+ },
26
29
  "devDependencies": {
27
30
  "@biomejs/biome": "2.0.6",
28
31
  "@rslib/core": "^0.15.0",
@@ -1,121 +0,0 @@
1
- import { type StorageError } from '../libs/errors';
2
- import { type Fetch } from '../libs/fetch';
3
- import type { Bucket, BucketType, OnRequestErrorType } from '../libs/types';
4
- import type { StorageClientOptions } from '../StorageClient';
5
- export default class StorageBucketApi {
6
- protected url: string;
7
- protected headers: {
8
- [key: string]: string;
9
- };
10
- protected appId?: string;
11
- protected fetch: Fetch;
12
- protected loggerEnabled?: boolean;
13
- protected onRequestError?: (error: OnRequestErrorType) => void;
14
- constructor(url: string, headers?: {
15
- [key: string]: string;
16
- }, fetch?: Fetch, opts?: StorageClientOptions);
17
- /**
18
- * Retrieves the details of all Storage buckets within an existing project.
19
- */
20
- listBuckets(): Promise<{
21
- data: Bucket[];
22
- error: null;
23
- } | {
24
- data: null;
25
- error: StorageError;
26
- }>;
27
- /**
28
- * Retrieves the details of an existing Storage bucket.
29
- *
30
- * @param id The unique identifier of the bucket you would like to retrieve.
31
- */
32
- getBucket(id: string): Promise<{
33
- data: Bucket;
34
- error: null;
35
- } | {
36
- data: null;
37
- error: StorageError;
38
- }>;
39
- /**
40
- * Creates a new Storage bucket
41
- *
42
- * @param id A unique identifier for the bucket you are creating.
43
- * @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. By default, buckets are private.
44
- * @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
45
- * The global file size limit takes precedence over this value.
46
- * The default value is null, which doesn't set a per bucket file size limit.
47
- * @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
48
- * The default value is null, which allows files with all mime types to be uploaded.
49
- * Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
50
- * @returns newly created bucket id
51
- * @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details.
52
- * - default bucket type is `STANDARD`
53
- */
54
- createBucket(id: string, options?: {
55
- public: boolean;
56
- fileSizeLimit?: number | string | null;
57
- allowedMimeTypes?: string[] | null;
58
- type?: BucketType;
59
- }): Promise<{
60
- data: Pick<Bucket, 'name'>;
61
- error: null;
62
- } | {
63
- data: null;
64
- error: StorageError;
65
- }>;
66
- /**
67
- * Updates a Storage bucket
68
- *
69
- * @param id A unique identifier for the bucket you are updating.
70
- * @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations.
71
- * @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
72
- * The global file size limit takes precedence over this value.
73
- * The default value is null, which doesn't set a per bucket file size limit.
74
- * @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
75
- * The default value is null, which allows files with all mime types to be uploaded.
76
- * Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
77
- */
78
- updateBucket(id: string, options: {
79
- public: boolean;
80
- fileSizeLimit?: number | string | null;
81
- allowedMimeTypes?: string[] | null;
82
- }): Promise<{
83
- data: {
84
- message: string;
85
- };
86
- error: null;
87
- } | {
88
- data: null;
89
- error: StorageError;
90
- }>;
91
- /**
92
- * Removes all objects inside a single bucket.
93
- *
94
- * @param id The unique identifier of the bucket you would like to empty.
95
- */
96
- emptyBucket(id: string): Promise<{
97
- data: {
98
- message: string;
99
- };
100
- error: null;
101
- } | {
102
- data: null;
103
- error: StorageError;
104
- }>;
105
- /**
106
- * Deletes an existing bucket. A bucket can't be deleted with existing objects inside it.
107
- * You must first `empty()` the bucket.
108
- *
109
- * @param id The unique identifier of the bucket you would like to delete.
110
- */
111
- deleteBucket(id: string): Promise<{
112
- data: {
113
- message: string;
114
- };
115
- error: null;
116
- } | {
117
- data: null;
118
- error: StorageError;
119
- }>;
120
- }
121
- //# sourceMappingURL=StorageBucketApi.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StorageBucketApi.d.ts","sourceRoot":"","sources":["../../../src/storage/packages/StorageBucketApi.ts"],"names":[],"mappings":"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"}
@@ -1,135 +0,0 @@
1
- import { DEFAULT_HEADERS } from "../libs/constants.js";
2
- import { isStorageError } from "../libs/errors.js";
3
- import { get, post, put, remove } from "../libs/fetch.js";
4
- import { resolveFetch } from "../libs/helpers.js";
5
- class StorageBucketApi {
6
- constructor(url, headers = {}, fetch, opts){
7
- this.url = url;
8
- this.headers = {
9
- ...DEFAULT_HEADERS,
10
- ...headers
11
- };
12
- this.fetch = resolveFetch(fetch);
13
- this.onRequestError = opts?.onRequestError;
14
- this.appId = opts?.appId;
15
- if (opts?.enableLogger) this.loggerEnabled = true;
16
- }
17
- async listBuckets() {
18
- try {
19
- const data = await get(this.fetch, `${this.url}/bucket`, {
20
- headers: this.headers
21
- });
22
- return {
23
- data,
24
- error: null
25
- };
26
- } catch (error) {
27
- if (isStorageError(error)) return {
28
- data: null,
29
- error
30
- };
31
- throw error;
32
- }
33
- }
34
- async getBucket(id) {
35
- try {
36
- const data = await get(this.fetch, `${this.url}/bucket/${id}`, {
37
- headers: this.headers
38
- });
39
- return {
40
- data,
41
- error: null
42
- };
43
- } catch (error) {
44
- if (isStorageError(error)) return {
45
- data: null,
46
- error
47
- };
48
- throw error;
49
- }
50
- }
51
- async createBucket(id, options = {
52
- public: false
53
- }) {
54
- try {
55
- const data = await post(this.fetch, `${this.url}/bucket`, {
56
- id,
57
- name: id,
58
- type: options.type,
59
- public: options.public,
60
- file_size_limit: options.fileSizeLimit,
61
- allowed_mime_types: options.allowedMimeTypes
62
- }, {
63
- headers: this.headers
64
- });
65
- return {
66
- data,
67
- error: null
68
- };
69
- } catch (error) {
70
- if (isStorageError(error)) return {
71
- data: null,
72
- error
73
- };
74
- throw error;
75
- }
76
- }
77
- async updateBucket(id, options) {
78
- try {
79
- const data = await put(this.fetch, `${this.url}/bucket/${id}`, {
80
- id,
81
- name: id,
82
- public: options.public,
83
- file_size_limit: options.fileSizeLimit,
84
- allowed_mime_types: options.allowedMimeTypes
85
- }, {
86
- headers: this.headers
87
- });
88
- return {
89
- data,
90
- error: null
91
- };
92
- } catch (error) {
93
- if (isStorageError(error)) return {
94
- data: null,
95
- error
96
- };
97
- throw error;
98
- }
99
- }
100
- async emptyBucket(id) {
101
- try {
102
- const data = await post(this.fetch, `${this.url}/bucket/${id}/empty`, {}, {
103
- headers: this.headers
104
- });
105
- return {
106
- data,
107
- error: null
108
- };
109
- } catch (error) {
110
- if (isStorageError(error)) return {
111
- data: null,
112
- error
113
- };
114
- throw error;
115
- }
116
- }
117
- async deleteBucket(id) {
118
- try {
119
- const data = await remove(this.fetch, `${this.url}/bucket/${id}`, {}, {
120
- headers: this.headers
121
- });
122
- return {
123
- data,
124
- error: null
125
- };
126
- } catch (error) {
127
- if (isStorageError(error)) return {
128
- data: null,
129
- error
130
- };
131
- throw error;
132
- }
133
- }
134
- }
135
- export { StorageBucketApi as default };