@ms-cloudpack/config 0.27.1 → 0.27.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.
@@ -1,3 +1,12 @@
1
+ import type { UserPreferences } from '@ms-cloudpack/common-types';
1
2
  export declare const appConfigFileName = "cloudpack.config.json";
2
3
  export declare const generatedConfigFileName = "cloudpack.generated.json";
4
+ export declare const userPreferencesFileName = ".cloudpack.preferences.json";
5
+ /**
6
+ * Object with all valid keys of the UserPreferences object.
7
+ *
8
+ * (This is a mapping from key to true because TS doesn't have a good way to verify that an array
9
+ * contains all keys of a type.)
10
+ */
11
+ export declare const allUserPreferences: Readonly<Record<keyof UserPreferences, boolean>>;
3
12
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AACzD,eAAO,MAAM,uBAAuB,6BAA6B,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AACzD,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAClE,eAAO,MAAM,uBAAuB,gCAAgC,CAAC;AAErE;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,OAAO,CAAC,CAE/E,CAAC"}
package/lib/constants.js CHANGED
@@ -1,3 +1,13 @@
1
1
  export const appConfigFileName = 'cloudpack.config.json';
2
2
  export const generatedConfigFileName = 'cloudpack.generated.json';
3
+ export const userPreferencesFileName = '.cloudpack.preferences.json';
4
+ /**
5
+ * Object with all valid keys of the UserPreferences object.
6
+ *
7
+ * (This is a mapping from key to true because TS doesn't have a good way to verify that an array
8
+ * contains all keys of a type.)
9
+ */
10
+ export const allUserPreferences = {
11
+ cachePath: true,
12
+ };
3
13
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,0BAA0B,CAAC","sourcesContent":["export const appConfigFileName = 'cloudpack.config.json';\nexport const generatedConfigFileName = 'cloudpack.generated.json';\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,0BAA0B,CAAC;AAClE,MAAM,CAAC,MAAM,uBAAuB,GAAG,6BAA6B,CAAC;AAErE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAqD;IAClF,SAAS,EAAE,IAAI;CAChB,CAAC","sourcesContent":["import type { UserPreferences } from '@ms-cloudpack/common-types';\n\nexport const appConfigFileName = 'cloudpack.config.json';\nexport const generatedConfigFileName = 'cloudpack.generated.json';\nexport const userPreferencesFileName = '.cloudpack.preferences.json';\n\n/**\n * Object with all valid keys of the UserPreferences object.\n *\n * (This is a mapping from key to true because TS doesn't have a good way to verify that an array\n * contains all keys of a type.)\n */\nexport const allUserPreferences: Readonly<Record<keyof UserPreferences, boolean>> = {\n cachePath: true,\n};\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Gets the path to the cache directory.
3
+ */
4
+ export declare function getCachePath(): string;
5
+ /**
6
+ * Gets the path to the app's local cache directory.
7
+ */
8
+ export declare function getLocalCachePath(appPath: string): string;
9
+ //# sourceMappingURL=getCachePath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCachePath.d.ts","sourceRoot":"","sources":["../src/getCachePath.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,YAAY,WAE3B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,UAEhD"}
@@ -0,0 +1,15 @@
1
+ import os from 'os';
2
+ import path from 'path';
3
+ /**
4
+ * Gets the path to the cache directory.
5
+ */
6
+ export function getCachePath() {
7
+ return path.join(os.homedir(), '.cloudpack');
8
+ }
9
+ /**
10
+ * Gets the path to the app's local cache directory.
11
+ */
12
+ export function getLocalCachePath(appPath) {
13
+ return path.join(appPath, 'node_modules', '.cache', 'cloudpack');
14
+ }
15
+ //# sourceMappingURL=getCachePath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCachePath.js","sourceRoot":"","sources":["../src/getCachePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import os from 'os';\nimport path from 'path';\n\n/**\n * Gets the path to the cache directory.\n */\nexport function getCachePath() {\n return path.join(os.homedir(), '.cloudpack');\n}\n\n/**\n * Gets the path to the app's local cache directory.\n */\nexport function getLocalCachePath(appPath: string) {\n return path.join(appPath, 'node_modules', '.cache', 'cloudpack');\n}\n"]}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Path to the user-level preferences file.
3
+ */
4
+ export declare function getUserPreferencesPath(): string;
5
+ /**
6
+ * For testing only: use this folder instead of the home directory for the user preferences.
7
+ */
8
+ export declare function setMockUserPreferencesDir(newPath: string): void;
9
+ /**
10
+ * Get the currently set mock user preferences directory.
11
+ * @internal
12
+ */
13
+ export declare function _getMockUserPreferencesDir(): string | undefined;
14
+ //# sourceMappingURL=getUserPreferencesPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUserPreferencesPath.d.ts","sourceRoot":"","sources":["../src/getUserPreferencesPath.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,sBAAsB,WAErC;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,QAExD;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,uBAEzC"}
@@ -0,0 +1,24 @@
1
+ import os from 'os';
2
+ import path from 'path';
3
+ import { userPreferencesFileName } from './constants.js';
4
+ let mockUserPreferencesDir;
5
+ /**
6
+ * Path to the user-level preferences file.
7
+ */
8
+ export function getUserPreferencesPath() {
9
+ return path.join(mockUserPreferencesDir || os.homedir(), userPreferencesFileName);
10
+ }
11
+ /**
12
+ * For testing only: use this folder instead of the home directory for the user preferences.
13
+ */
14
+ export function setMockUserPreferencesDir(newPath) {
15
+ mockUserPreferencesDir = newPath;
16
+ }
17
+ /**
18
+ * Get the currently set mock user preferences directory.
19
+ * @internal
20
+ */
21
+ export function _getMockUserPreferencesDir() {
22
+ return mockUserPreferencesDir;
23
+ }
24
+ //# sourceMappingURL=getUserPreferencesPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUserPreferencesPath.js","sourceRoot":"","sources":["../src/getUserPreferencesPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,IAAI,sBAA0C,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,uBAAuB,CAAC,CAAC;AACpF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAe;IACvD,sBAAsB,GAAG,OAAO,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,sBAAsB,CAAC;AAChC,CAAC","sourcesContent":["import os from 'os';\nimport path from 'path';\nimport { userPreferencesFileName } from './constants.js';\n\nlet mockUserPreferencesDir: string | undefined;\n\n/**\n * Path to the user-level preferences file.\n */\nexport function getUserPreferencesPath() {\n return path.join(mockUserPreferencesDir || os.homedir(), userPreferencesFileName);\n}\n\n/**\n * For testing only: use this folder instead of the home directory for the user preferences.\n */\nexport function setMockUserPreferencesDir(newPath: string) {\n mockUserPreferencesDir = newPath;\n}\n\n/**\n * Get the currently set mock user preferences directory.\n * @internal\n */\nexport function _getMockUserPreferencesDir() {\n return mockUserPreferencesDir;\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,14 +1,19 @@
1
1
  export { checkMatch } from './checkMatch.js';
2
2
  export { configTemplate } from './configTemplate.js';
3
3
  export { generatedConfigFileName, appConfigFileName } from './constants.js';
4
+ export { allUserPreferences } from './constants.js';
4
5
  export { createPackageDefinitions } from './createPackageDefinitions.js';
6
+ export { getCachePath, getLocalCachePath } from './getCachePath.js';
5
7
  export { getConfigPath } from './getConfigPath.js';
8
+ export { getUserPreferencesPath, setMockUserPreferencesDir } from './getUserPreferencesPath.js';
6
9
  export { getPackageSettings } from './getPackageSettings.js';
7
10
  export { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';
8
11
  export { readConfig } from './readConfig.js';
9
12
  export { readGeneratedConfig } from './readGeneratedConfig.js';
10
13
  export { readAppConfig } from './readAppConfig.js';
14
+ export { readUserPreferences } from './readUserPreferences.js';
11
15
  export { writeGeneratedConfig } from './writeGeneratedConfig.js';
12
16
  export { writeAppConfig } from './writeAppConfig.js';
13
17
  export { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';
18
+ export { updateUserPreference } from './updateUserPreference.js';
14
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
package/lib/index.js CHANGED
@@ -1,14 +1,19 @@
1
1
  export { checkMatch } from './checkMatch.js';
2
2
  export { configTemplate } from './configTemplate.js';
3
3
  export { generatedConfigFileName, appConfigFileName } from './constants.js';
4
+ export { allUserPreferences } from './constants.js';
4
5
  export { createPackageDefinitions } from './createPackageDefinitions.js';
6
+ export { getCachePath, getLocalCachePath } from './getCachePath.js';
5
7
  export { getConfigPath } from './getConfigPath.js';
8
+ export { getUserPreferencesPath, setMockUserPreferencesDir } from './getUserPreferencesPath.js';
6
9
  export { getPackageSettings } from './getPackageSettings.js';
7
10
  export { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';
8
11
  export { readConfig } from './readConfig.js';
9
12
  export { readGeneratedConfig } from './readGeneratedConfig.js';
10
13
  export { readAppConfig } from './readAppConfig.js';
14
+ export { readUserPreferences } from './readUserPreferences.js';
11
15
  export { writeGeneratedConfig } from './writeGeneratedConfig.js';
12
16
  export { writeAppConfig } from './writeAppConfig.js';
13
17
  export { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';
18
+ export { updateUserPreference } from './updateUserPreference.js';
14
19
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC","sourcesContent":["export { checkMatch } from './checkMatch.js';\nexport { configTemplate } from './configTemplate.js';\nexport { generatedConfigFileName, appConfigFileName } from './constants.js';\nexport { createPackageDefinitions } from './createPackageDefinitions.js';\nexport { getConfigPath } from './getConfigPath.js';\nexport { getPackageSettings } from './getPackageSettings.js';\nexport { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';\nexport { readConfig } from './readConfig.js';\nexport { readGeneratedConfig } from './readGeneratedConfig.js';\nexport { readAppConfig } from './readAppConfig.js';\nexport { writeGeneratedConfig } from './writeGeneratedConfig.js';\nexport { writeAppConfig } from './writeAppConfig.js';\nexport { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export { checkMatch } from './checkMatch.js';\nexport { configTemplate } from './configTemplate.js';\nexport { generatedConfigFileName, appConfigFileName } from './constants.js';\nexport { allUserPreferences } from './constants.js';\nexport { createPackageDefinitions } from './createPackageDefinitions.js';\nexport { getCachePath, getLocalCachePath } from './getCachePath.js';\nexport { getConfigPath } from './getConfigPath.js';\nexport { getUserPreferencesPath, setMockUserPreferencesDir } from './getUserPreferencesPath.js';\nexport { getPackageSettings } from './getPackageSettings.js';\nexport { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';\nexport { readConfig } from './readConfig.js';\nexport { readGeneratedConfig } from './readGeneratedConfig.js';\nexport { readAppConfig } from './readAppConfig.js';\nexport { readUserPreferences } from './readUserPreferences.js';\nexport { writeGeneratedConfig } from './writeGeneratedConfig.js';\nexport { writeAppConfig } from './writeAppConfig.js';\nexport { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';\nexport { updateUserPreference } from './updateUserPreference.js';\n"]}
@@ -0,0 +1,6 @@
1
+ import type { UserPreferences } from '@ms-cloudpack/common-types';
2
+ /**
3
+ * Reads the user preferences file asynchronously.
4
+ */
5
+ export declare function readUserPreferences(): Promise<UserPreferences>;
6
+ //# sourceMappingURL=readUserPreferences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readUserPreferences.d.ts","sourceRoot":"","sources":["../src/readUserPreferences.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGlE;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,eAAe,CAAC,CAQpE"}
@@ -0,0 +1,13 @@
1
+ import { readJson } from '@ms-cloudpack/json-utilities';
2
+ import { getUserPreferencesPath } from './getUserPreferencesPath.js';
3
+ /**
4
+ * Reads the user preferences file asynchronously.
5
+ */
6
+ export async function readUserPreferences() {
7
+ const { $schema, ...prefs } = (await readJson(getUserPreferencesPath(), {
8
+ verbose: true,
9
+ mode: 'permissive',
10
+ })) || {};
11
+ return prefs;
12
+ }
13
+ //# sourceMappingURL=readUserPreferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readUserPreferences.js","sourceRoot":"","sources":["../src/readUserPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,GACzB,CAAC,MAAM,QAAQ,CAAyC,sBAAsB,EAAE,EAAE;QAChF,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,YAAY;KACnB,CAAC,CAAC,IAAI,EAAE,CAAC;IAEZ,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { readJson } from '@ms-cloudpack/json-utilities';\nimport type { UserPreferences } from '@ms-cloudpack/common-types';\nimport { getUserPreferencesPath } from './getUserPreferencesPath.js';\n\n/**\n * Reads the user preferences file asynchronously.\n */\nexport async function readUserPreferences(): Promise<UserPreferences> {\n const { $schema, ...prefs } =\n (await readJson<UserPreferences & { $schema?: string }>(getUserPreferencesPath(), {\n verbose: true,\n mode: 'permissive',\n })) || {};\n\n return prefs;\n}\n"]}
@@ -2,4 +2,6 @@
2
2
  export declare const generatedAppConfigSchemaUrl = "https://unpkg.com/@ms-cloudpack/common-types/schema/GeneratedConfig.json";
3
3
  /** unpkg URL for the AppConfig JSON schema */
4
4
  export declare const appConfigSchemaUrl = "https://unpkg.com/@ms-cloudpack/common-types/schema/AppConfig.json";
5
+ /** unpkg URL for the UserPreferences JSON schema */
6
+ export declare const userPreferencesSchemaUrl = "https://unpkg.com/@ms-cloudpack/common-types/schema/UserPreferences.json";
5
7
  //# sourceMappingURL=schemaUrls.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaUrls.d.ts","sourceRoot":"","sources":["../src/schemaUrls.ts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,eAAO,MAAM,2BAA2B,6EAAyC,CAAC;AAElF,8CAA8C;AAC9C,eAAO,MAAM,kBAAkB,uEAAmC,CAAC"}
1
+ {"version":3,"file":"schemaUrls.d.ts","sourceRoot":"","sources":["../src/schemaUrls.ts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,eAAO,MAAM,2BAA2B,6EAAyC,CAAC;AAElF,8CAA8C;AAC9C,eAAO,MAAM,kBAAkB,uEAAmC,CAAC;AAEnE,oDAAoD;AACpD,eAAO,MAAM,wBAAwB,6EAAyC,CAAC"}
package/lib/schemaUrls.js CHANGED
@@ -3,4 +3,6 @@ const schemaPrefix = 'https://unpkg.com/@ms-cloudpack/common-types/schema';
3
3
  export const generatedAppConfigSchemaUrl = `${schemaPrefix}/GeneratedConfig.json`;
4
4
  /** unpkg URL for the AppConfig JSON schema */
5
5
  export const appConfigSchemaUrl = `${schemaPrefix}/AppConfig.json`;
6
+ /** unpkg URL for the UserPreferences JSON schema */
7
+ export const userPreferencesSchemaUrl = `${schemaPrefix}/UserPreferences.json`;
6
8
  //# sourceMappingURL=schemaUrls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaUrls.js","sourceRoot":"","sources":["../src/schemaUrls.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,qDAAqD,CAAC;AAE3E,oDAAoD;AACpD,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,YAAY,uBAAuB,CAAC;AAElF,8CAA8C;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,YAAY,iBAAiB,CAAC","sourcesContent":["const schemaPrefix = 'https://unpkg.com/@ms-cloudpack/common-types/schema';\n\n/** unpkg URL for the GeneratedConfig JSON schema */\nexport const generatedAppConfigSchemaUrl = `${schemaPrefix}/GeneratedConfig.json`;\n\n/** unpkg URL for the AppConfig JSON schema */\nexport const appConfigSchemaUrl = `${schemaPrefix}/AppConfig.json`;\n"]}
1
+ {"version":3,"file":"schemaUrls.js","sourceRoot":"","sources":["../src/schemaUrls.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,qDAAqD,CAAC;AAE3E,oDAAoD;AACpD,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,YAAY,uBAAuB,CAAC;AAElF,8CAA8C;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,YAAY,iBAAiB,CAAC;AAEnE,oDAAoD;AACpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,YAAY,uBAAuB,CAAC","sourcesContent":["const schemaPrefix = 'https://unpkg.com/@ms-cloudpack/common-types/schema';\n\n/** unpkg URL for the GeneratedConfig JSON schema */\nexport const generatedAppConfigSchemaUrl = `${schemaPrefix}/GeneratedConfig.json`;\n\n/** unpkg URL for the AppConfig JSON schema */\nexport const appConfigSchemaUrl = `${schemaPrefix}/AppConfig.json`;\n\n/** unpkg URL for the UserPreferences JSON schema */\nexport const userPreferencesSchemaUrl = `${schemaPrefix}/UserPreferences.json`;\n"]}
@@ -0,0 +1,15 @@
1
+ import type { UserPreferences } from '@ms-cloudpack/common-types';
2
+ /**
3
+ * Validate and write an update to a user preference item.
4
+ * Creates the file if it doesn't already exist.
5
+ *
6
+ * Throws an error if the key is not a valid user preference name.
7
+ */
8
+ export declare function updateUserPreference(params: {
9
+ key: keyof UserPreferences;
10
+ /** Update `key` to `newValue` */
11
+ newValue?: string;
12
+ /** Delete `key` */
13
+ deleteValue?: boolean;
14
+ }): Promise<void>;
15
+ //# sourceMappingURL=updateUserPreference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateUserPreference.d.ts","sourceRoot":"","sources":["../src/updateUserPreference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAQlE;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE;IACjD,GAAG,EAAE,MAAM,eAAe,CAAC;IAC3B,iCAAiC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,iBAiCA"}
@@ -0,0 +1,66 @@
1
+ import { writeJson } from '@ms-cloudpack/json-utilities';
2
+ import { _getMockUserPreferencesDir, getUserPreferencesPath } from './getUserPreferencesPath.js';
3
+ import { allUserPreferences } from './constants.js';
4
+ import { readUserPreferences } from './readUserPreferences.js';
5
+ import path from 'path';
6
+ import { isFolderSync } from '@ms-cloudpack/path-utilities';
7
+ import { userPreferencesSchemaUrl } from './schemaUrls.js';
8
+ /**
9
+ * Validate and write an update to a user preference item.
10
+ * Creates the file if it doesn't already exist.
11
+ *
12
+ * Throws an error if the key is not a valid user preference name.
13
+ */
14
+ export async function updateUserPreference(params) {
15
+ const { key, deleteValue } = params;
16
+ if (process.env.JEST_WORKER_ID && !_getMockUserPreferencesDir()) {
17
+ // Prevent tests from accidentally messing with real global state...
18
+ throw new Error('Tests must call setMockUserPreferencesDir before calling updateUserPreference.');
19
+ }
20
+ // The key is user input which could potentially be invalid, despite the types.
21
+ if (!allUserPreferences[key]) {
22
+ throw new Error(`"${key}" is not a valid user preference name.`);
23
+ }
24
+ let value = params.newValue?.trim();
25
+ if (!deleteValue) {
26
+ if (value === undefined) {
27
+ throw new Error('Must specify newValue or deleteValue (this is a bug in Cloudpack)');
28
+ }
29
+ value = validateValue(key, value);
30
+ }
31
+ const newPreferences = {
32
+ ...(await readUserPreferences()),
33
+ $schema: userPreferencesSchemaUrl,
34
+ };
35
+ if (deleteValue) {
36
+ delete newPreferences[key];
37
+ }
38
+ else {
39
+ newPreferences[key] = value;
40
+ }
41
+ return writeJson(getUserPreferencesPath(), newPreferences, { update: true, mode: 'permissive' });
42
+ }
43
+ function validateValue(key, value) {
44
+ switch (key) {
45
+ case 'cachePath': {
46
+ if (!value) {
47
+ throw new Error('The cache folder cannot be empty.');
48
+ }
49
+ if (!path.isAbsolute(value)) {
50
+ throw new Error('The cache folder must be an absolute path.');
51
+ }
52
+ const parentFolder = path.dirname(value);
53
+ if (!isFolderSync(parentFolder)) {
54
+ throw new Error(`The parent folder "${parentFolder}" of the cache folder does not exist.`);
55
+ }
56
+ // The folder is valid
57
+ return value;
58
+ }
59
+ default: {
60
+ // this gives a type error if a new preference is added
61
+ const exhaustiveCheck = key;
62
+ throw new Error(`Unhandled user preference: "${exhaustiveCheck}"`);
63
+ }
64
+ }
65
+ }
66
+ //# sourceMappingURL=updateUserPreference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateUserPreference.js","sourceRoot":"","sources":["../src/updateUserPreference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAM1C;IACC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAEpC,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,CAAC,0BAA0B,EAAE,EAAE,CAAC;QAChE,oEAAoE;QACpE,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IACpG,CAAC;IAED,+EAA+E;IAC/E,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,IAAI,GAAG,wCAAwC,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;IAEpC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;QACvF,CAAC;QACD,KAAK,GAAG,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,cAAc,GAAG;QACrB,GAAG,CAAC,MAAM,mBAAmB,EAAE,CAAC;QAChC,OAAO,EAAE,wBAAwB;KAClC,CAAC;IACF,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;SAAM,CAAC;QACN,cAAc,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC9B,CAAC;IAED,OAAO,SAAS,CAAC,sBAAsB,EAAE,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;AACnG,CAAC;AAED,SAAS,aAAa,CAAC,GAA0B,EAAE,KAAa;IAC9D,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,WAAW,CAAC,CAAC,CAAC;YACjB,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;YACvD,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;YAChE,CAAC;YAED,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACzC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CAAC,sBAAsB,YAAY,uCAAuC,CAAC,CAAC;YAC7F,CAAC;YAED,sBAAsB;YACtB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;YACR,uDAAuD;YACvD,MAAM,eAAe,GAAU,GAAG,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,+BAA+B,eAAe,GAAG,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { writeJson } from '@ms-cloudpack/json-utilities';\nimport type { UserPreferences } from '@ms-cloudpack/common-types';\nimport { _getMockUserPreferencesDir, getUserPreferencesPath } from './getUserPreferencesPath.js';\nimport { allUserPreferences } from './constants.js';\nimport { readUserPreferences } from './readUserPreferences.js';\nimport path from 'path';\nimport { isFolderSync } from '@ms-cloudpack/path-utilities';\nimport { userPreferencesSchemaUrl } from './schemaUrls.js';\n\n/**\n * Validate and write an update to a user preference item.\n * Creates the file if it doesn't already exist.\n *\n * Throws an error if the key is not a valid user preference name.\n */\nexport async function updateUserPreference(params: {\n key: keyof UserPreferences;\n /** Update `key` to `newValue` */\n newValue?: string;\n /** Delete `key` */\n deleteValue?: boolean;\n}) {\n const { key, deleteValue } = params;\n\n if (process.env.JEST_WORKER_ID && !_getMockUserPreferencesDir()) {\n // Prevent tests from accidentally messing with real global state...\n throw new Error('Tests must call setMockUserPreferencesDir before calling updateUserPreference.');\n }\n\n // The key is user input which could potentially be invalid, despite the types.\n if (!allUserPreferences[key]) {\n throw new Error(`\"${key}\" is not a valid user preference name.`);\n }\n\n let value = params.newValue?.trim();\n\n if (!deleteValue) {\n if (value === undefined) {\n throw new Error('Must specify newValue or deleteValue (this is a bug in Cloudpack)');\n }\n value = validateValue(key, value);\n }\n\n const newPreferences = {\n ...(await readUserPreferences()),\n $schema: userPreferencesSchemaUrl,\n };\n if (deleteValue) {\n delete newPreferences[key];\n } else {\n newPreferences[key] = value;\n }\n\n return writeJson(getUserPreferencesPath(), newPreferences, { update: true, mode: 'permissive' });\n}\n\nfunction validateValue(key: keyof UserPreferences, value: string) {\n switch (key) {\n case 'cachePath': {\n if (!value) {\n throw new Error('The cache folder cannot be empty.');\n }\n\n if (!path.isAbsolute(value)) {\n throw new Error('The cache folder must be an absolute path.');\n }\n\n const parentFolder = path.dirname(value);\n if (!isFolderSync(parentFolder)) {\n throw new Error(`The parent folder \"${parentFolder}\" of the cache folder does not exist.`);\n }\n\n // The folder is valid\n return value;\n }\n\n default: {\n // this gives a type error if a new preference is added\n const exhaustiveCheck: never = key;\n throw new Error(`Unhandled user preference: \"${exhaustiveCheck}\"`);\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/config",
3
- "version": "0.27.1",
3
+ "version": "0.27.2",
4
4
  "description": "Configuration handling for cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,10 +14,10 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/common-types": "^0.19.0",
17
+ "@ms-cloudpack/common-types": "^0.19.1",
18
18
  "@ms-cloudpack/json-utilities": "^0.1.7",
19
- "@ms-cloudpack/package-utilities": "^10.0.0",
20
- "@ms-cloudpack/path-utilities": "^2.7.37",
19
+ "@ms-cloudpack/package-utilities": "^10.0.1",
20
+ "@ms-cloudpack/path-utilities": "^2.7.38",
21
21
  "import-meta-resolve": "^4.0.0",
22
22
  "semver": "^7.6.0"
23
23
  },