@qbraid-core/fs 0.11.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/README.md +44 -0
- package/dist/src/client.d.ts +6 -0
- package/dist/src/client.js +87 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/config.d.ts +40 -0
- package/dist/src/config.js +185 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/context.d.ts +22 -0
- package/dist/src/context.js +92 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/ibm-config.d.ts +24 -0
- package/dist/src/ibm-config.js +98 -0
- package/dist/src/ibm-config.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +22 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @qbraid-core/fs
|
|
2
|
+
|
|
3
|
+
File system utilities for qBraid Cloud Services.
|
|
4
|
+
|
|
5
|
+
This package provides file system-based configuration management and utilities that are separated from the main base package to enable frontend compatibility.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- `QbraidConfigManager`: Manages qBraid configuration files
|
|
10
|
+
- `IbmConfigManager` : Manage IBM Quantum Platform configuration
|
|
11
|
+
- `ConfigManager`: Abstract base class for configuration management
|
|
12
|
+
- `ensureDirectory`: Directory management utilities
|
|
13
|
+
- File system context managers
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @qbraid-core/fs
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### QbraidConfigManager
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { QbraidConfigManager } from '@qbraid-core/fs';
|
|
27
|
+
|
|
28
|
+
const configManager = new QbraidConfigManager();
|
|
29
|
+
const apiKey = configManager.getApiKey();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### IBMConfigManager
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { IBMConfigManager } from '@qbraid-core/fs';
|
|
36
|
+
|
|
37
|
+
const ibmConfig = new IBMConfigManager();
|
|
38
|
+
const apiKey = ibmConfig.getApiKey();
|
|
39
|
+
const serviceCrn = ibmConfig.getServiceCRN();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Note
|
|
43
|
+
|
|
44
|
+
This package requires Node.js environment with file system access. It is not compatible with browser environments.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { QbraidSession } from '@qbraid-core/base';
|
|
2
|
+
/**
|
|
3
|
+
* Check if the current process is running inside qBraid Lab.
|
|
4
|
+
* This function creates a temporary file and checks if it's mounted in the lab environment.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isRunningInLab(session: QbraidSession): Promise<boolean>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025, qBraid Development Team
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.isRunningInLab = isRunningInLab;
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const config_1 = require("./config");
|
|
42
|
+
const context_1 = require("./context");
|
|
43
|
+
/**
|
|
44
|
+
* Check if the current process is running inside qBraid Lab.
|
|
45
|
+
* This function creates a temporary file and checks if it's mounted in the lab environment.
|
|
46
|
+
*/
|
|
47
|
+
async function isRunningInLab(session) {
|
|
48
|
+
try {
|
|
49
|
+
const utcDatetime = new Date();
|
|
50
|
+
const formattedTime = utcDatetime.toISOString().replace(/[-:]/g, '').replace(/\..+/, '');
|
|
51
|
+
const configDir = path.join(config_1.USER_CONFIG_PATH, '..', 'certs');
|
|
52
|
+
const filepath = path.join(configDir, formattedTime);
|
|
53
|
+
let fileCreated = false;
|
|
54
|
+
return await (0, context_1.ensureDirectory)(configDir, false, async () => {
|
|
55
|
+
try {
|
|
56
|
+
// Create empty file with proper error handling
|
|
57
|
+
await fs.promises.writeFile(filepath, '').catch((error) => {
|
|
58
|
+
console.error(`Failed to create test file: ${error.message}`);
|
|
59
|
+
throw error;
|
|
60
|
+
});
|
|
61
|
+
fileCreated = true;
|
|
62
|
+
const response = await session.client.get(`/lab/is-mounted/${formattedTime}`);
|
|
63
|
+
return Boolean(response.data?.isMounted);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
if (fileCreated) {
|
|
67
|
+
try {
|
|
68
|
+
await fs.promises.unlink(filepath);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (error instanceof Error) {
|
|
72
|
+
console.error(`Failed to cleanup test file ${filepath}: ${error.message}`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
console.error(`Failed to cleanup test file ${filepath}: Unknown error`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error('Error in isRunningInLab:', error instanceof Error ? error.message : 'Unknown error');
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcvB,wCA2CC;AAvDD,uCAAyB;AACzB,2CAA6B;AAI7B,qCAA4C;AAC5C,uCAA4C;AAE5C;;;GAGG;AACI,KAAK,UAAU,cAAc,CAAC,OAAsB;IACzD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAEzF,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,yBAAgB,EAAE,IAAI,EAAE,OAAO,C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,KAAK,CACX,0BAA0B,EAC1B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CACzD,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AuthData, DEFAULT_CONFIG, ConfigData, ConfigManager as BaseConfigManager } from '@qbraid-core/base';
|
|
2
|
+
export declare const DEFAULT_CONFIG_PATH: string;
|
|
3
|
+
export declare const USER_CONFIG_PATH: string;
|
|
4
|
+
export { DEFAULT_CONFIG, ConfigData };
|
|
5
|
+
/**
|
|
6
|
+
* Filesystem-enabled configuration manager.
|
|
7
|
+
* Provides concrete implementation of the base ConfigManager with file I/O operations.
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class FsConfigManager<T> extends BaseConfigManager<T> {
|
|
10
|
+
protected ensureConfigFileExists(): void;
|
|
11
|
+
loadConfig(): T;
|
|
12
|
+
saveConfig(): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Filesystem-enabled qBraid configuration manager.
|
|
16
|
+
* Provides all the functionality of the base QbraidConfigManager plus file I/O operations.
|
|
17
|
+
*/
|
|
18
|
+
export declare class QbraidConfigManager extends FsConfigManager<ConfigData> {
|
|
19
|
+
constructor(filePath?: string);
|
|
20
|
+
protected parseConfig(content: string): ConfigData;
|
|
21
|
+
protected stringifyConfig(config: ConfigData): string;
|
|
22
|
+
protected getDefaultConfig(): ConfigData;
|
|
23
|
+
private initializeDefaultConfig;
|
|
24
|
+
private deepMerge;
|
|
25
|
+
getSection(section: string): Record<string, string> | undefined;
|
|
26
|
+
getValue(section: string, key: string): string | undefined;
|
|
27
|
+
setValue(section: string, key: string, value: string): void;
|
|
28
|
+
updateConfig(newConfig: ConfigData): void;
|
|
29
|
+
removeSection(section: string): void;
|
|
30
|
+
removeValue(section: string, key: string): void;
|
|
31
|
+
getApiKey(): string;
|
|
32
|
+
setApiKey(apiKey: string): void;
|
|
33
|
+
getRefreshToken(): string;
|
|
34
|
+
setRefreshToken(refreshToken: string): void;
|
|
35
|
+
getEmail(): string;
|
|
36
|
+
setEmail(email: string): void;
|
|
37
|
+
getUrl(): string;
|
|
38
|
+
setUrl(url: string): void;
|
|
39
|
+
getAuthData(): AuthData;
|
|
40
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025, qBraid Development Team
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.QbraidConfigManager = exports.FsConfigManager = exports.DEFAULT_CONFIG = exports.USER_CONFIG_PATH = exports.DEFAULT_CONFIG_PATH = void 0;
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const os = __importStar(require("os"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const base_1 = require("@qbraid-core/base");
|
|
43
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG", { enumerable: true, get: function () { return base_1.DEFAULT_CONFIG; } });
|
|
44
|
+
const ini = __importStar(require("ini"));
|
|
45
|
+
exports.DEFAULT_CONFIG_PATH = path.join(os.homedir(), '.qbraid', 'qbraidrc');
|
|
46
|
+
exports.USER_CONFIG_PATH = process.env.QBRAID_CONFIG_FILE || exports.DEFAULT_CONFIG_PATH;
|
|
47
|
+
/**
|
|
48
|
+
* Filesystem-enabled configuration manager.
|
|
49
|
+
* Provides concrete implementation of the base ConfigManager with file I/O operations.
|
|
50
|
+
*/
|
|
51
|
+
class FsConfigManager extends base_1.ConfigManager {
|
|
52
|
+
ensureConfigFileExists() {
|
|
53
|
+
console.log('Checking config path:', this.configPath);
|
|
54
|
+
if (!fs.existsSync(this.configPath)) {
|
|
55
|
+
const dirPath = path.dirname(this.configPath);
|
|
56
|
+
if (!fs.existsSync(dirPath)) {
|
|
57
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
58
|
+
}
|
|
59
|
+
fs.writeFileSync(this.configPath, '', 'utf-8');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
loadConfig() {
|
|
63
|
+
try {
|
|
64
|
+
if (fs.existsSync(this.configPath)) {
|
|
65
|
+
const fileContent = fs.readFileSync(this.configPath, 'utf-8');
|
|
66
|
+
return this.parseConfig(fileContent);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
console.warn(`Config file not found at ${this.configPath}. Initializing with default config.`);
|
|
70
|
+
return this.getDefaultConfig();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error instanceof Error) {
|
|
75
|
+
console.error(`Error loading config file: ${error.message}`);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
console.error(`An unknown error occurred while loading the config file.`);
|
|
79
|
+
}
|
|
80
|
+
return this.getDefaultConfig();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
saveConfig() {
|
|
84
|
+
this.ensureConfigFileExists();
|
|
85
|
+
try {
|
|
86
|
+
const configString = this.stringifyConfig(this.config);
|
|
87
|
+
fs.writeFileSync(this.configPath, configString, 'utf-8');
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error(`Error saving config file: ${error}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.FsConfigManager = FsConfigManager;
|
|
95
|
+
/**
|
|
96
|
+
* Filesystem-enabled qBraid configuration manager.
|
|
97
|
+
* Provides all the functionality of the base QbraidConfigManager plus file I/O operations.
|
|
98
|
+
*/
|
|
99
|
+
class QbraidConfigManager extends FsConfigManager {
|
|
100
|
+
constructor(filePath = exports.USER_CONFIG_PATH) {
|
|
101
|
+
super(filePath);
|
|
102
|
+
this.initializeDefaultConfig();
|
|
103
|
+
}
|
|
104
|
+
parseConfig(content) {
|
|
105
|
+
return ini.parse(content);
|
|
106
|
+
}
|
|
107
|
+
stringifyConfig(config) {
|
|
108
|
+
return ini.stringify(config);
|
|
109
|
+
}
|
|
110
|
+
getDefaultConfig() {
|
|
111
|
+
return base_1.DEFAULT_CONFIG;
|
|
112
|
+
}
|
|
113
|
+
initializeDefaultConfig() {
|
|
114
|
+
const currentConfig = this.getConfig();
|
|
115
|
+
const mergedConfig = this.deepMerge(base_1.DEFAULT_CONFIG, currentConfig);
|
|
116
|
+
this.updateConfig(mergedConfig);
|
|
117
|
+
}
|
|
118
|
+
deepMerge(target, source) {
|
|
119
|
+
const output = { ...target };
|
|
120
|
+
Object.keys(source).forEach(key => {
|
|
121
|
+
if (typeof source[key] === 'object' && source[key] !== null) {
|
|
122
|
+
output[key] = output[key] ? { ...output[key], ...source[key] } : { ...source[key] };
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return output;
|
|
126
|
+
}
|
|
127
|
+
// Configuration access methods (same as base implementation)
|
|
128
|
+
getSection(section) {
|
|
129
|
+
return this.config[section];
|
|
130
|
+
}
|
|
131
|
+
getValue(section, key) {
|
|
132
|
+
return this.config[section]?.[key];
|
|
133
|
+
}
|
|
134
|
+
setValue(section, key, value) {
|
|
135
|
+
if (!this.config[section]) {
|
|
136
|
+
this.config[section] = {};
|
|
137
|
+
}
|
|
138
|
+
this.config[section][key] = value;
|
|
139
|
+
}
|
|
140
|
+
updateConfig(newConfig) {
|
|
141
|
+
this.config = { ...this.config, ...newConfig };
|
|
142
|
+
}
|
|
143
|
+
removeSection(section) {
|
|
144
|
+
delete this.config[section];
|
|
145
|
+
}
|
|
146
|
+
removeValue(section, key) {
|
|
147
|
+
if (this.config[section]) {
|
|
148
|
+
delete this.config[section][key];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// qBraid-specific configuration methods (same as base implementation)
|
|
152
|
+
getApiKey() {
|
|
153
|
+
return this.getValue('default', 'api-key') || '';
|
|
154
|
+
}
|
|
155
|
+
setApiKey(apiKey) {
|
|
156
|
+
this.setValue('default', 'api-key', apiKey);
|
|
157
|
+
}
|
|
158
|
+
getRefreshToken() {
|
|
159
|
+
return this.getValue('default', 'refresh-token') || '';
|
|
160
|
+
}
|
|
161
|
+
setRefreshToken(refreshToken) {
|
|
162
|
+
this.setValue('default', 'refresh-token', refreshToken);
|
|
163
|
+
}
|
|
164
|
+
getEmail() {
|
|
165
|
+
return this.getValue('default', 'email') || '';
|
|
166
|
+
}
|
|
167
|
+
setEmail(email) {
|
|
168
|
+
this.setValue('default', 'email', email);
|
|
169
|
+
}
|
|
170
|
+
getUrl() {
|
|
171
|
+
return this.getValue('default', 'url') || base_1.DEFAULT_CONFIG.default.url;
|
|
172
|
+
}
|
|
173
|
+
setUrl(url) {
|
|
174
|
+
this.setValue('default', 'url', url);
|
|
175
|
+
}
|
|
176
|
+
getAuthData() {
|
|
177
|
+
return {
|
|
178
|
+
apiKey: this.getApiKey(),
|
|
179
|
+
refreshToken: this.getRefreshToken(),
|
|
180
|
+
email: this.getEmail(),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.QbraidConfigManager = QbraidConfigManager;
|
|
185
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEvB,uCAAyB;AACzB,uCAAyB;AACzB,2CAA6B;AAE7B,4CAK2B;AAOlB,+FAVP,qBAAc,OAUO;AANvB,yCAA2B;AAEd,QAAA,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACrE,QAAA,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,2BAAmB,CAAC;AAKtF;;;GAGG;AACH,MAAsB,eAAmB,SAAQ,oBAAoB;IACzD,sBAAsB;QAC9B,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACpC,MAAM,OAAO,GAAG,IA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,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAEM,eAAe;QACpB,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC;IACzD,CAAC;IAEM,eAAe,CAAC,YAAoB;QACzC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;IAC1D,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IACjD,CAAC;IAEM,QAAQ,CAAC,KAAa;QAC3B,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,qBAAc,CAAC,OAAO,CAAC,GAAG,CAAC;IACvE,CAAC;IAEM,MAAM,CAAC,GAAW;QACvB,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IAEM,WAAW;QAChB,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE;YACxB,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE;SACvB,CAAC;IACJ,CAAC;CACF;AAxGD,kDAwGC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for a disposable resource that can be cleaned up
|
|
3
|
+
*/
|
|
4
|
+
interface Disposable {
|
|
5
|
+
dispose(): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Utility function to handle resource management similar to Python's context manager
|
|
9
|
+
* @param resource A disposable resource with init and dispose methods
|
|
10
|
+
* @param fn The function to execute with the managed resource
|
|
11
|
+
*/
|
|
12
|
+
export declare function using<T extends Disposable, R>(resource: T & {
|
|
13
|
+
init(): Promise<void>;
|
|
14
|
+
}, fn: (resource: T) => Promise<R>): Promise<R>;
|
|
15
|
+
/**
|
|
16
|
+
* Ensures a directory exists during the execution of a function and optionally cleans it up
|
|
17
|
+
* @param dirPath Path to the directory
|
|
18
|
+
* @param removeIfCreated Whether to remove the directory if it was created by this function
|
|
19
|
+
* @param fn Function to execute while directory is guaranteed to exist
|
|
20
|
+
*/
|
|
21
|
+
export declare function ensureDirectory<R>(dirPath: string, removeIfCreated: boolean, fn: () => Promise<R>): Promise<R>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025, qBraid Development Team
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.using = using;
|
|
39
|
+
exports.ensureDirectory = ensureDirectory;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
/**
|
|
43
|
+
* Class to manage directory creation and cleanup
|
|
44
|
+
*/
|
|
45
|
+
class DirectoryManager {
|
|
46
|
+
existed;
|
|
47
|
+
path;
|
|
48
|
+
removeIfCreated;
|
|
49
|
+
constructor(dirPath, removeIfCreated) {
|
|
50
|
+
this.path = dirPath;
|
|
51
|
+
this.removeIfCreated = removeIfCreated;
|
|
52
|
+
this.existed = fs.existsSync(dirPath);
|
|
53
|
+
}
|
|
54
|
+
async init() {
|
|
55
|
+
if (!this.existed) {
|
|
56
|
+
await fs.promises.mkdir(this.path, { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async dispose() {
|
|
60
|
+
if (!this.existed && this.removeIfCreated) {
|
|
61
|
+
const files = await fs.promises.readdir(this.path);
|
|
62
|
+
for (const file of files) {
|
|
63
|
+
await fs.promises.unlink(path.join(this.path, file));
|
|
64
|
+
}
|
|
65
|
+
await fs.promises.rmdir(this.path);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Utility function to handle resource management similar to Python's context manager
|
|
71
|
+
* @param resource A disposable resource with init and dispose methods
|
|
72
|
+
* @param fn The function to execute with the managed resource
|
|
73
|
+
*/
|
|
74
|
+
async function using(resource, fn) {
|
|
75
|
+
await resource.init();
|
|
76
|
+
try {
|
|
77
|
+
return await fn(resource);
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
await resource.dispose();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Ensures a directory exists during the execution of a function and optionally cleans it up
|
|
85
|
+
* @param dirPath Path to the directory
|
|
86
|
+
* @param removeIfCreated Whether to remove the directory if it was created by this function
|
|
87
|
+
* @param fn Function to execute while directory is guaranteed to exist
|
|
88
|
+
*/
|
|
89
|
+
async function ensureDirectory(dirPath, removeIfCreated, fn) {
|
|
90
|
+
return using(new DirectoryManager(dirPath, removeIfCreated), async () => await fn());
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDvB,sBAUC;AAQD,0CAMC;AAtED,uCAAyB;AACzB,2CAA6B;AAS7B;;GAEG;AACH,MAAM,gBAAgB;IACZ,OAAO,CAAU;IACjB,IAAI,CAAS;IACb,eAAe,CAAU;IAEjC,YAAY,OAAe,EAAE,eAAwB;QACnD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1C,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;YACvD,CAAC;YACD,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;CACF;AAED;;;;GAIG;AACI,KAAK,UAAU,KAAK,CACzB,QAAuC,EACvC,EAA+B;IAE/B,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACtB,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;YAAS,CAAC;QACT,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,eAAwB,EACxB,EAAoB;IAEpB,OAAO,KAAK,CAAC,IAAI,gBAAgB,CAAC,OAAO,EAAE,eAAe,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FsConfigManager } from './config';
|
|
2
|
+
type IBMConfigData = Record<string, Record<string, string | boolean>>;
|
|
3
|
+
export declare const DEFAULT_IBM_CONFIG_PATH: string;
|
|
4
|
+
export declare const IBM_DEFAULT_TOKEN_LIFETIME = 3600000;
|
|
5
|
+
/**
|
|
6
|
+
* Filesystem-enabled IBM Quantum configuration manager.
|
|
7
|
+
* Manages IBM Quantum Platform configuration files.
|
|
8
|
+
*/
|
|
9
|
+
export declare class IBMConfigManager extends FsConfigManager<IBMConfigData> {
|
|
10
|
+
private bearerToken;
|
|
11
|
+
private tokenFetchTime;
|
|
12
|
+
constructor(filePath?: string);
|
|
13
|
+
protected parseConfig(content: string): IBMConfigData;
|
|
14
|
+
protected stringifyConfig(config: IBMConfigData): string;
|
|
15
|
+
protected getDefaultConfig(): IBMConfigData;
|
|
16
|
+
getApiKey(): string;
|
|
17
|
+
setApiKey(apiKey: string): void;
|
|
18
|
+
getServiceCRN(): string;
|
|
19
|
+
setServiceCRN(crn: string): void;
|
|
20
|
+
getBearerToken(): string;
|
|
21
|
+
setBearerToken(token: string): void;
|
|
22
|
+
isBearerTokenExpired(): boolean;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025, qBraid Development Team
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.IBMConfigManager = exports.IBM_DEFAULT_TOKEN_LIFETIME = exports.DEFAULT_IBM_CONFIG_PATH = void 0;
|
|
39
|
+
const os = __importStar(require("os"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const config_1 = require("./config");
|
|
42
|
+
exports.DEFAULT_IBM_CONFIG_PATH = path.join(os.homedir(), '.qiskit', 'qiskit-ibm.json');
|
|
43
|
+
exports.IBM_DEFAULT_TOKEN_LIFETIME = 3600_000; // 1 hour in milliseconds
|
|
44
|
+
/**
|
|
45
|
+
* Filesystem-enabled IBM Quantum configuration manager.
|
|
46
|
+
* Manages IBM Quantum Platform configuration files.
|
|
47
|
+
*/
|
|
48
|
+
class IBMConfigManager extends config_1.FsConfigManager {
|
|
49
|
+
bearerToken = '';
|
|
50
|
+
tokenFetchTime = 0;
|
|
51
|
+
constructor(filePath) {
|
|
52
|
+
super(filePath ? filePath : exports.DEFAULT_IBM_CONFIG_PATH);
|
|
53
|
+
}
|
|
54
|
+
parseConfig(content) {
|
|
55
|
+
return JSON.parse(content);
|
|
56
|
+
}
|
|
57
|
+
stringifyConfig(config) {
|
|
58
|
+
return JSON.stringify(config, null, 2);
|
|
59
|
+
}
|
|
60
|
+
getDefaultConfig() {
|
|
61
|
+
return {
|
|
62
|
+
'default-ibm-quantum-platform': {
|
|
63
|
+
// latest IBMQ channel, ibm_cloud will be deprecated soon
|
|
64
|
+
channel: 'ibm_quantum_platform',
|
|
65
|
+
// Loading account from environment variables
|
|
66
|
+
// Ref : https://github.com/Qiskit/qiskit-ibm-runtime/tree/main?tab=readme-ov-file#loading-account-from-environment-variables
|
|
67
|
+
instance: process.env.QISKIT_IBM_INSTANCE ?? '',
|
|
68
|
+
token: process.env.QISKIT_IBM_TOKEN ?? '',
|
|
69
|
+
private_endpoint: false,
|
|
70
|
+
url: 'https://cloud.ibm.com',
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
getApiKey() {
|
|
75
|
+
return this.config['default-ibm-quantum-platform'].token;
|
|
76
|
+
}
|
|
77
|
+
setApiKey(apiKey) {
|
|
78
|
+
this.config['default-ibm-quantum-platform'].token = apiKey;
|
|
79
|
+
}
|
|
80
|
+
getServiceCRN() {
|
|
81
|
+
return this.config['default-ibm-quantum-platform'].instance;
|
|
82
|
+
}
|
|
83
|
+
setServiceCRN(crn) {
|
|
84
|
+
this.config['default-ibm-quantum-platform'].instance = crn;
|
|
85
|
+
}
|
|
86
|
+
getBearerToken() {
|
|
87
|
+
return this.bearerToken;
|
|
88
|
+
}
|
|
89
|
+
setBearerToken(token) {
|
|
90
|
+
this.bearerToken = token;
|
|
91
|
+
this.tokenFetchTime = Date.now();
|
|
92
|
+
}
|
|
93
|
+
isBearerTokenExpired() {
|
|
94
|
+
return (this.tokenFetchTime === 0 || Date.now() - this.tokenFetchTime > exports.IBM_DEFAULT_TOKEN_LIFETIME);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.IBMConfigManager = IBMConfigManager;
|
|
98
|
+
//# sourceMappingURL=ibm-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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Ac;QAC7B,IAAI,CAAC,MAAM,CAAC,8BAA8B,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC;IAC7D,CAAC;IAEM,aAAa;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,8BAA8B,CAAC,CAAC,QAAkB,CAAC;IACxE,CAAC;IAEM,aAAa,CAAC,GAAW;QAC9B,IAAI,CAAC,MAAM,CAAC,8BAA8B,CAAC,CAAC,QAAQ,GAAG,GAAG,CAAC;IAC7D,CAAC;IAEM,cAAc;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAEM,cAAc,CAAC,KAAa;QACjC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACnC,CAAC;IAEM,oBAAoB;QACzB,OAAO,CACL,IAAI,CAAC,cAAc,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,GAAG,kCAA0B,CAC3F,CAAC;IACJ,CAAC;CACF;AA9DD,4CA8DC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module fs
|
|
3
|
+
*/
|
|
4
|
+
export { isRunningInLab } from './client';
|
|
5
|
+
export { FsConfigManager, QbraidConfigManager, DEFAULT_CONFIG_PATH, USER_CONFIG_PATH, } from './config';
|
|
6
|
+
export { IBMConfigManager, DEFAULT_IBM_CONFIG_PATH } from './ibm-config';
|
|
7
|
+
export { ensureDirectory, using } from './context';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025, qBraid Development Team
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.using = exports.ensureDirectory = exports.DEFAULT_IBM_CONFIG_PATH = exports.IBMConfigManager = exports.USER_CONFIG_PATH = exports.DEFAULT_CONFIG_PATH = exports.QbraidConfigManager = exports.FsConfigManager = exports.isRunningInLab = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* @module fs
|
|
8
|
+
*/
|
|
9
|
+
var client_1 = require("./client");
|
|
10
|
+
Object.defineProperty(exports, "isRunningInLab", { enumerable: true, get: function () { return client_1.isRunningInLab; } });
|
|
11
|
+
var config_1 = require("./config");
|
|
12
|
+
Object.defineProperty(exports, "FsConfigManager", { enumerable: true, get: function () { return config_1.FsConfigManager; } });
|
|
13
|
+
Object.defineProperty(exports, "QbraidConfigManager", { enumerable: true, get: function () { return config_1.QbraidConfigManager; } });
|
|
14
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG_PATH", { enumerable: true, get: function () { return config_1.DEFAULT_CONFIG_PATH; } });
|
|
15
|
+
Object.defineProperty(exports, "USER_CONFIG_PATH", { enumerable: true, get: function () { return config_1.USER_CONFIG_PATH; } });
|
|
16
|
+
var ibm_config_1 = require("./ibm-config");
|
|
17
|
+
Object.defineProperty(exports, "IBMConfigManager", { enumerable: true, get: function () { return ibm_config_1.IBMConfigManager; } });
|
|
18
|
+
Object.defineProperty(exports, "DEFAULT_IBM_CONFIG_PATH", { enumerable: true, get: function () { return ibm_config_1.DEFAULT_IBM_CONFIG_PATH; } });
|
|
19
|
+
var context_1 = require("./context");
|
|
20
|
+
Object.defineProperty(exports, "ensureDirectory", { enumerable: true, get: function () { return context_1.ensureDirectory; } });
|
|
21
|
+
Object.defineProperty(exports, "using", { enumerable: true, get: function () { return context_1.using; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;AAEvB;;GAEG;AACH,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AACvB,mCAKkB;AAJhB,yGAAA,eAAe,OAAA;AACf,6GAAA,mBAAmB,OAAA;AACnB,6GAAA,mBAAmB,OAAA;AACnB,0GAAA,gBAAgB,OAAA;AAElB,2CAAyE;AAAhE,8GAAA,gBAAgB,OAAA;AAAE,qHAAA,uBAAuB,OAAA;AAClD,qCAAmD;AAA1C,0GAAA,eAAe,OAAA;AAAE,gGAAA,KAAK,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qbraid-core/fs",
|
|
3
|
+
"version": "0.11.0",
|
|
4
|
+
"main": "dist/src/index.js",
|
|
5
|
+
"types": "dist/src/index.d.ts",
|
|
6
|
+
"description": "File system utilities for qBraid Cloud Services.",
|
|
7
|
+
"author": "qBraid Development Team",
|
|
8
|
+
"license": "Proprietary",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/src"
|
|
11
|
+
],
|
|
12
|
+
"keywords": [
|
|
13
|
+
"qbraid",
|
|
14
|
+
"qbraid-core",
|
|
15
|
+
"qbraid-core-js",
|
|
16
|
+
"filesystem",
|
|
17
|
+
"config",
|
|
18
|
+
"file system",
|
|
19
|
+
"configuration",
|
|
20
|
+
"quantum",
|
|
21
|
+
"quantum computing"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"directory": "packages/fs",
|
|
26
|
+
"url": "git+https://github.com/qBraid/qbraid-core-js.git"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://qbraid.github.io/qbraid-core-js/modules/fs.html",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@qbraid-core/base": "0.11.0",
|
|
31
|
+
"fs": "^0.0.1-security",
|
|
32
|
+
"ini": "^5.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/ini": "^4.1.1"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"clean": "rimraf dist tsconfig.tsbuildinfo src/_version.ts src/_version.js src/*.d.ts src/*.js",
|
|
39
|
+
"lint": "eslint src",
|
|
40
|
+
"lint:fix": "eslint src --fix",
|
|
41
|
+
"format": "prettier --write \"src/**/*.{ts,json}\"",
|
|
42
|
+
"format:check": "prettier --check \"src/**/*.{ts,json}\"",
|
|
43
|
+
"docs": "typedoc"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
}
|
|
48
|
+
}
|