scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
140 lines • 3.33 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var keychain_exports = {};
__export(keychain_exports, {
MockKeychain: () => MockKeychain
});
module.exports = __toCommonJS(keychain_exports);
var import_scriptable_abstract = require("scriptable-abstract");
const DEFAULT_STATE = {
items: /* @__PURE__ */ new Map(),
accessGroups: [],
lastAccess: null
};
class MockKeychain extends import_scriptable_abstract.AbsKeychain {
static get instance() {
return super.instance;
}
constructor() {
super(DEFAULT_STATE);
}
/**
* @inheritdoc
*/
set(key, value) {
this.setState((state) => {
const items = new Map(state.items);
items.set(key, value);
return {
...state,
items,
lastAccess: /* @__PURE__ */ new Date()
};
});
}
/**
* @inheritdoc
*/
get(key) {
const value = this.state.items.get(key);
if (value === void 0) {
throw new Error(`No value found for key: ${key}`);
}
this.setState({ lastAccess: /* @__PURE__ */ new Date() });
return value;
}
/**
* @inheritdoc
*/
remove(key) {
this.setState((state) => {
const items = new Map(state.items);
items.delete(key);
return {
...state,
items,
lastAccess: /* @__PURE__ */ new Date()
};
});
}
/**
* @inheritdoc
*/
contains(key) {
return this.state.items.has(key);
}
/**
* @inheritdoc
*/
get accessGroup() {
return this.state.accessGroups[this.state.accessGroups.length - 1] ?? null;
}
/**
* @inheritdoc
*/
set accessGroup(group) {
if (group === null) {
this.setState((state) => ({
...state,
accessGroups: state.accessGroups.slice(0, -1)
}));
} else {
this.setState((state) => ({
...state,
accessGroups: [...state.accessGroups, group]
}));
}
}
/**
* @additional
* Get all stored keys
*/
getKeys() {
return Array.from(this.state.items.keys());
}
/**
* @additional
* Get all access groups
*/
getAccessGroups() {
return [...this.state.accessGroups];
}
/**
* @additional
* Get last access time
*/
getLastAccess() {
return this.state.lastAccess;
}
/**
* @additional
* Clear all stored items
*/
clear() {
this.setState({
items: /* @__PURE__ */ new Map(),
accessGroups: [],
lastAccess: /* @__PURE__ */ new Date()
});
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockKeychain
});
//# sourceMappingURL=keychain.js.map