@symbo.ls/sdk 3.2.3 → 3.2.6
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 +141 -0
- package/dist/cjs/config/environment.js +94 -10
- package/dist/cjs/index.js +152 -12
- package/dist/cjs/services/AdminService.js +351 -0
- package/dist/cjs/services/AuthService.js +738 -305
- package/dist/cjs/services/BaseService.js +158 -6
- package/dist/cjs/services/BranchService.js +484 -0
- package/dist/cjs/services/CollabService.js +439 -116
- package/dist/cjs/services/DnsService.js +340 -0
- package/dist/cjs/services/FeatureFlagService.js +175 -0
- package/dist/cjs/services/FileService.js +201 -0
- package/dist/cjs/services/IntegrationService.js +538 -0
- package/dist/cjs/services/MetricsService.js +62 -0
- package/dist/cjs/services/PaymentService.js +271 -0
- package/dist/cjs/services/PlanService.js +426 -0
- package/dist/cjs/services/ProjectService.js +1207 -0
- package/dist/cjs/services/PullRequestService.js +503 -0
- package/dist/cjs/services/ScreenshotService.js +304 -0
- package/dist/cjs/services/SubscriptionService.js +396 -0
- package/dist/cjs/services/TrackingService.js +661 -0
- package/dist/cjs/services/WaitlistService.js +148 -0
- package/dist/cjs/services/index.js +60 -4
- package/dist/cjs/state/RootStateManager.js +2 -23
- package/dist/cjs/state/rootEventBus.js +9 -0
- package/dist/cjs/utils/CollabClient.js +78 -12
- package/dist/cjs/utils/TokenManager.js +16 -3
- package/dist/cjs/utils/changePreprocessor.js +199 -0
- package/dist/cjs/utils/jsonDiff.js +46 -4
- package/dist/cjs/utils/ordering.js +309 -0
- package/dist/cjs/utils/services.js +285 -128
- package/dist/cjs/utils/validation.js +0 -3
- package/dist/esm/config/environment.js +94 -10
- package/dist/esm/index.js +47862 -18248
- package/dist/esm/services/AdminService.js +1132 -0
- package/dist/esm/services/AuthService.js +1493 -386
- package/dist/esm/services/BaseService.js +757 -6
- package/dist/esm/services/BranchService.js +1265 -0
- package/dist/esm/services/CollabService.js +24956 -16089
- package/dist/esm/services/DnsService.js +1121 -0
- package/dist/esm/services/FeatureFlagService.js +956 -0
- package/dist/esm/services/FileService.js +982 -0
- package/dist/esm/services/IntegrationService.js +1319 -0
- package/dist/esm/services/MetricsService.js +843 -0
- package/dist/esm/services/PaymentService.js +1052 -0
- package/dist/esm/services/PlanService.js +1207 -0
- package/dist/esm/services/ProjectService.js +2526 -0
- package/dist/esm/services/PullRequestService.js +1284 -0
- package/dist/esm/services/ScreenshotService.js +1085 -0
- package/dist/esm/services/SubscriptionService.js +1177 -0
- package/dist/esm/services/TrackingService.js +18454 -0
- package/dist/esm/services/WaitlistService.js +929 -0
- package/dist/esm/services/index.js +47373 -18027
- package/dist/esm/state/RootStateManager.js +11 -23
- package/dist/esm/state/rootEventBus.js +9 -0
- package/dist/esm/utils/CollabClient.js +17526 -16120
- package/dist/esm/utils/TokenManager.js +16 -3
- package/dist/esm/utils/changePreprocessor.js +542 -0
- package/dist/esm/utils/jsonDiff.js +958 -43
- package/dist/esm/utils/ordering.js +291 -0
- package/dist/esm/utils/services.js +285 -128
- package/dist/esm/utils/validation.js +116 -50
- package/dist/node/config/environment.js +94 -10
- package/dist/node/index.js +183 -16
- package/dist/node/services/AdminService.js +332 -0
- package/dist/node/services/AuthService.js +742 -310
- package/dist/node/services/BaseService.js +148 -6
- package/dist/node/services/BranchService.js +465 -0
- package/dist/node/services/CollabService.js +439 -116
- package/dist/node/services/DnsService.js +321 -0
- package/dist/node/services/FeatureFlagService.js +156 -0
- package/dist/node/services/FileService.js +182 -0
- package/dist/node/services/IntegrationService.js +519 -0
- package/dist/node/services/MetricsService.js +43 -0
- package/dist/node/services/PaymentService.js +252 -0
- package/dist/node/services/PlanService.js +407 -0
- package/dist/node/services/ProjectService.js +1188 -0
- package/dist/node/services/PullRequestService.js +484 -0
- package/dist/node/services/ScreenshotService.js +285 -0
- package/dist/node/services/SubscriptionService.js +377 -0
- package/dist/node/services/TrackingService.js +632 -0
- package/dist/node/services/WaitlistService.js +129 -0
- package/dist/node/services/index.js +60 -4
- package/dist/node/state/RootStateManager.js +2 -23
- package/dist/node/state/rootEventBus.js +9 -0
- package/dist/node/utils/CollabClient.js +77 -11
- package/dist/node/utils/TokenManager.js +16 -3
- package/dist/node/utils/changePreprocessor.js +180 -0
- package/dist/node/utils/jsonDiff.js +46 -4
- package/dist/node/utils/ordering.js +290 -0
- package/dist/node/utils/services.js +285 -128
- package/dist/node/utils/validation.js +0 -3
- package/package.json +30 -18
- package/src/config/environment.js +95 -10
- package/src/index.js +190 -23
- package/src/services/AdminService.js +374 -0
- package/src/services/AuthService.js +874 -328
- package/src/services/BaseService.js +166 -6
- package/src/services/BranchService.js +536 -0
- package/src/services/CollabService.js +557 -148
- package/src/services/DnsService.js +366 -0
- package/src/services/FeatureFlagService.js +174 -0
- package/src/services/FileService.js +213 -0
- package/src/services/IntegrationService.js +548 -0
- package/src/services/MetricsService.js +40 -0
- package/src/services/PaymentService.js +287 -0
- package/src/services/PlanService.js +468 -0
- package/src/services/ProjectService.js +1366 -0
- package/src/services/PullRequestService.js +537 -0
- package/src/services/ScreenshotService.js +258 -0
- package/src/services/SubscriptionService.js +425 -0
- package/src/services/TrackingService.js +853 -0
- package/src/services/WaitlistService.js +130 -0
- package/src/services/index.js +79 -5
- package/src/services/tests/BranchService/createBranch.test.js +153 -0
- package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
- package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
- package/src/services/tests/BranchService/listBranches.test.js +87 -0
- package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
- package/src/services/tests/BranchService/publishVersion.test.js +183 -0
- package/src/services/tests/BranchService/renameBranch.test.js +240 -0
- package/src/services/tests/BranchService/resetBranch.test.js +152 -0
- package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
- package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
- package/src/services/tests/FileService/createFileFormData.test.js +74 -0
- package/src/services/tests/FileService/getFileUrl.test.js +69 -0
- package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
- package/src/services/tests/FileService/uploadDocument.test.js +36 -0
- package/src/services/tests/FileService/uploadFile.test.js +78 -0
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
- package/src/services/tests/FileService/uploadImage.test.js +36 -0
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
- package/src/services/tests/FileService/validateFile.test.js +63 -0
- package/src/services/tests/PlanService/createPlan.test.js +104 -0
- package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
- package/src/services/tests/PlanService/deletePlan.test.js +92 -0
- package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
- package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
- package/src/services/tests/PlanService/getPlan.test.js +50 -0
- package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
- package/src/services/tests/PlanService/getPlans.test.js +53 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
- package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
- package/src/services/tests/PlanService/initializePlans.test.js +75 -0
- package/src/services/tests/PlanService/updatePlan.test.js +111 -0
- package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
- package/src/state/RootStateManager.js +37 -32
- package/src/state/rootEventBus.js +19 -0
- package/src/utils/CollabClient.js +99 -12
- package/src/utils/TokenManager.js +20 -3
- package/src/utils/changePreprocessor.js +239 -0
- package/src/utils/jsonDiff.js +40 -5
- package/src/utils/ordering.js +271 -0
- package/src/utils/services.js +306 -139
- package/src/utils/validation.js +0 -3
- package/dist/cjs/services/AIService.js +0 -155
- package/dist/cjs/services/BasedService.js +0 -1185
- package/dist/cjs/services/CoreService.js +0 -2295
- package/dist/cjs/services/SocketService.js +0 -309
- package/dist/cjs/services/SymstoryService.js +0 -571
- package/dist/cjs/utils/basedQuerys.js +0 -181
- package/dist/cjs/utils/symstoryClient.js +0 -259
- package/dist/esm/services/AIService.js +0 -185
- package/dist/esm/services/BasedService.js +0 -5262
- package/dist/esm/services/CoreService.js +0 -2827
- package/dist/esm/services/SocketService.js +0 -456
- package/dist/esm/services/SymstoryService.js +0 -7025
- package/dist/esm/utils/basedQuerys.js +0 -163
- package/dist/esm/utils/symstoryClient.js +0 -354
- package/dist/node/services/AIService.js +0 -136
- package/dist/node/services/BasedService.js +0 -1156
- package/dist/node/services/CoreService.js +0 -2266
- package/dist/node/services/SocketService.js +0 -280
- package/dist/node/services/SymstoryService.js +0 -542
- package/dist/node/utils/basedQuerys.js +0 -162
- package/dist/node/utils/symstoryClient.js +0 -230
- package/src/services/AIService.js +0 -150
- package/src/services/BasedService.js +0 -1302
- package/src/services/CoreService.js +0 -2548
- package/src/services/SocketService.js +0 -336
- package/src/services/SymstoryService.js +0 -649
- package/src/utils/basedQuerys.js +0 -164
- package/src/utils/symstoryClient.js +0 -252
|
@@ -1,571 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var SymstoryService_exports = {};
|
|
29
|
-
__export(SymstoryService_exports, {
|
|
30
|
-
SymstoryService: () => SymstoryService
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(SymstoryService_exports);
|
|
33
|
-
var import_BaseService = require("./BaseService.js");
|
|
34
|
-
var import_symstoryClient = __toESM(require("../utils/symstoryClient.js"), 1);
|
|
35
|
-
var utils = __toESM(require("@domql/utils"), 1);
|
|
36
|
-
var import_validation = require("../utils/validation.js");
|
|
37
|
-
const { deepStringify, isFunction, isObjectLike } = utils.default || utils;
|
|
38
|
-
class SymstoryService extends import_BaseService.BaseService {
|
|
39
|
-
constructor(config) {
|
|
40
|
-
super(config);
|
|
41
|
-
this._client = null;
|
|
42
|
-
this._cache = /* @__PURE__ */ new Map();
|
|
43
|
-
this._state = {};
|
|
44
|
-
this._socketService = this._context.services.socket;
|
|
45
|
-
this._undoStack = [];
|
|
46
|
-
this._redoStack = [];
|
|
47
|
-
}
|
|
48
|
-
async init() {
|
|
49
|
-
var _a, _b;
|
|
50
|
-
try {
|
|
51
|
-
const { appKey, authToken, state, socketUrl } = this._context || {};
|
|
52
|
-
if (!appKey) {
|
|
53
|
-
this._setReady(false);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
import_symstoryClient.default.init(appKey, {
|
|
57
|
-
headers: {
|
|
58
|
-
...authToken && { Authorization: `Bearer ${authToken}` }
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
this._client = import_symstoryClient.default.client;
|
|
62
|
-
this._state = this._isObject(state) ? state : {};
|
|
63
|
-
if (socketUrl) {
|
|
64
|
-
await this._socketService.init();
|
|
65
|
-
}
|
|
66
|
-
this._info = {
|
|
67
|
-
config: {
|
|
68
|
-
appKey: `${appKey.substr(0, 4)}...${appKey.substr(-4)}`,
|
|
69
|
-
hasToken: Boolean(authToken),
|
|
70
|
-
hasState: Boolean(state),
|
|
71
|
-
hasSocket: this._socketService._socket !== null,
|
|
72
|
-
socketStatus: ((_b = (_a = this._socketService._info) == null ? void 0 : _a.config) == null ? void 0 : _b.status) || "disconnected",
|
|
73
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
this._setReady();
|
|
77
|
-
} catch (error) {
|
|
78
|
-
this._setError(error);
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// publish a new version
|
|
83
|
-
async publish({ version, type = "minor" } = {}) {
|
|
84
|
-
if (version) {
|
|
85
|
-
await this._client.publishVersion(version, { type });
|
|
86
|
-
} else {
|
|
87
|
-
await this.updateData([], { type });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// get changes between versions
|
|
91
|
-
async getChanges({ versionId, versionValue, branch } = {}) {
|
|
92
|
-
return this._client.getChanges({ versionId, versionValue, branch });
|
|
93
|
-
}
|
|
94
|
-
safeStringify(obj) {
|
|
95
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
96
|
-
return JSON.stringify(obj, (key, value) => {
|
|
97
|
-
if (typeof value === "object" && value !== null) {
|
|
98
|
-
if (seen.has(value)) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
seen.add(value);
|
|
102
|
-
}
|
|
103
|
-
return value;
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
// Update project data
|
|
107
|
-
async updateData(changes, options = {}, callback) {
|
|
108
|
-
var _a;
|
|
109
|
-
this._requireReady();
|
|
110
|
-
const {
|
|
111
|
-
type = "patch",
|
|
112
|
-
message = "",
|
|
113
|
-
branch = ((_a = this._context.symstory) == null ? void 0 : _a.branch) || "main",
|
|
114
|
-
fromSocket = false,
|
|
115
|
-
quietUpdate = false,
|
|
116
|
-
isUndo,
|
|
117
|
-
isRedo
|
|
118
|
-
} = options;
|
|
119
|
-
try {
|
|
120
|
-
const { state } = this._context;
|
|
121
|
-
if ("isOld" in state && state.isOld) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const updates = changes.map((change) => ({
|
|
125
|
-
change,
|
|
126
|
-
prev: state == null ? void 0 : state.getByPath(change[1])
|
|
127
|
-
}));
|
|
128
|
-
if (state && "setPathCollection" in state && !quietUpdate) {
|
|
129
|
-
await state.setPathCollection(changes, {
|
|
130
|
-
preventUpdate: true,
|
|
131
|
-
...options
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
const filteredUpdates = updates.filter(({ change, prev }) => {
|
|
135
|
-
if (change && change.err) {
|
|
136
|
-
delete change.err;
|
|
137
|
-
}
|
|
138
|
-
if (prev && prev.err) {
|
|
139
|
-
delete prev.err;
|
|
140
|
-
}
|
|
141
|
-
return (
|
|
142
|
-
// eslint-disable-next-line no-undefined
|
|
143
|
-
change[3] !== void 0 || this.safeStringify(change[2]) !== this.safeStringify(prev)
|
|
144
|
-
);
|
|
145
|
-
});
|
|
146
|
-
if (!fromSocket && !isUndo) {
|
|
147
|
-
if (!isRedo) {
|
|
148
|
-
this._redoStack.length = 0;
|
|
149
|
-
}
|
|
150
|
-
this._undoStack.push({
|
|
151
|
-
updates: filteredUpdates,
|
|
152
|
-
options,
|
|
153
|
-
time: /* @__PURE__ */ new Date()
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
if (fromSocket) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const stringifiedData = changes.map(([action, path, change]) => {
|
|
160
|
-
if (isFunction(change)) {
|
|
161
|
-
return [action, path, (change == null ? void 0 : change.toString()) ?? change];
|
|
162
|
-
}
|
|
163
|
-
if (change && change.err) {
|
|
164
|
-
delete change.err;
|
|
165
|
-
}
|
|
166
|
-
return [
|
|
167
|
-
action,
|
|
168
|
-
path,
|
|
169
|
-
isObjectLike(change) ? deepStringify(change, Array.isArray(change) ? [] : {}) : change
|
|
170
|
-
];
|
|
171
|
-
});
|
|
172
|
-
const res = await this._context.services.core.applyProjectChanges(
|
|
173
|
-
state.projectId,
|
|
174
|
-
stringifiedData,
|
|
175
|
-
{
|
|
176
|
-
type,
|
|
177
|
-
message,
|
|
178
|
-
branch
|
|
179
|
-
}
|
|
180
|
-
);
|
|
181
|
-
if (this._socketService._socket) {
|
|
182
|
-
this._socketService.send("change", {
|
|
183
|
-
type: "update",
|
|
184
|
-
changes: stringifiedData,
|
|
185
|
-
version: res == null ? void 0 : res.value
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
if (res == null ? void 0 : res.value) {
|
|
189
|
-
this._context.symstory = {
|
|
190
|
-
...this._context.symstory,
|
|
191
|
-
version: res.value
|
|
192
|
-
};
|
|
193
|
-
if (state && "quietUpdate" in state) {
|
|
194
|
-
const { isVersionsOpen } = state;
|
|
195
|
-
if (isVersionsOpen) {
|
|
196
|
-
state.quietUpdate({ version: res.value });
|
|
197
|
-
} else {
|
|
198
|
-
state.version = res.value;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
this._cache.clear();
|
|
202
|
-
}
|
|
203
|
-
if ("__element" in this._state && isFunction(callback)) {
|
|
204
|
-
await callback.call(this._state.__element, changes, res);
|
|
205
|
-
}
|
|
206
|
-
return res;
|
|
207
|
-
} catch (error) {
|
|
208
|
-
if (isFunction(callback)) {
|
|
209
|
-
callback(error);
|
|
210
|
-
}
|
|
211
|
-
throw new Error(`Failed to update data: ${error.message}`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
async undo() {
|
|
215
|
-
if (!this._undoStack.length) {
|
|
216
|
-
throw new Error("Nothing to undo");
|
|
217
|
-
}
|
|
218
|
-
const { updates, options } = this._undoStack.pop();
|
|
219
|
-
const changes = updates.map(({ change, prev }) => [
|
|
220
|
-
change[0],
|
|
221
|
-
change[1],
|
|
222
|
-
prev
|
|
223
|
-
]);
|
|
224
|
-
this._redoStack.push({
|
|
225
|
-
updates: updates.map(({ change, prev }) => ({
|
|
226
|
-
change: [change[0], change[1], prev],
|
|
227
|
-
prev: change[2]
|
|
228
|
-
})),
|
|
229
|
-
options
|
|
230
|
-
});
|
|
231
|
-
await this.updateData(
|
|
232
|
-
changes,
|
|
233
|
-
{ ...options, isUndo: true, message: `Undo: ${options.message || ""}` },
|
|
234
|
-
() => changes
|
|
235
|
-
);
|
|
236
|
-
return changes;
|
|
237
|
-
}
|
|
238
|
-
async redo() {
|
|
239
|
-
if (!this._redoStack.length) {
|
|
240
|
-
throw new Error("Nothing to redo");
|
|
241
|
-
}
|
|
242
|
-
const { updates, options } = this._redoStack.pop();
|
|
243
|
-
const changes = updates.map(({ change, prev }) => [
|
|
244
|
-
change[0],
|
|
245
|
-
change[1],
|
|
246
|
-
prev
|
|
247
|
-
]);
|
|
248
|
-
await this.updateData(
|
|
249
|
-
changes,
|
|
250
|
-
{ ...options, isRedo: true, message: `Redo: ${options.message || ""}` },
|
|
251
|
-
() => changes
|
|
252
|
-
);
|
|
253
|
-
return changes;
|
|
254
|
-
}
|
|
255
|
-
// Delete project data
|
|
256
|
-
async deleteData(path, options = {}, callback) {
|
|
257
|
-
this._requireReady();
|
|
258
|
-
try {
|
|
259
|
-
const changes = [["delete", path]];
|
|
260
|
-
return await this.updateData(changes, options, callback);
|
|
261
|
-
} catch (error) {
|
|
262
|
-
throw new Error(`Failed to delete data: ${error.message}`);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
// Get project data
|
|
266
|
-
async getData(query, options = {}) {
|
|
267
|
-
var _a, _b, _c;
|
|
268
|
-
this._requireReady();
|
|
269
|
-
try {
|
|
270
|
-
const {
|
|
271
|
-
branch = ((_a = this._context.symstory) == null ? void 0 : _a.branch) || "main",
|
|
272
|
-
version = (_b = this._context.symstory) == null ? void 0 : _b.version,
|
|
273
|
-
bypassCache = false,
|
|
274
|
-
timeout = 3e4
|
|
275
|
-
} = options;
|
|
276
|
-
const cacheKey = !bypassCache && this._generateCacheKey(query, branch, version);
|
|
277
|
-
if (!bypassCache && cacheKey && this._cache.has(cacheKey)) {
|
|
278
|
-
return this._cache.get(cacheKey);
|
|
279
|
-
}
|
|
280
|
-
if (query && typeof query === "object") {
|
|
281
|
-
if (!query.$find && !query.$filter) {
|
|
282
|
-
throw new Error(
|
|
283
|
-
"Invalid query structure. Must include $find or $filter."
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
const controller = new AbortController();
|
|
288
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
289
|
-
try {
|
|
290
|
-
const result = await this._client.get(query, branch, version);
|
|
291
|
-
if (!bypassCache && cacheKey) {
|
|
292
|
-
(_c = this._cache) == null ? void 0 : _c.set(cacheKey, result);
|
|
293
|
-
}
|
|
294
|
-
return result;
|
|
295
|
-
} finally {
|
|
296
|
-
clearTimeout(timeoutId);
|
|
297
|
-
}
|
|
298
|
-
} catch (error) {
|
|
299
|
-
if (error.name === "AbortError") {
|
|
300
|
-
throw new Error(`Request timed out after ${options.timeout}ms`);
|
|
301
|
-
}
|
|
302
|
-
throw new Error(`Failed to get data: ${error.message}`);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
// Helper method to check if a variable is a valid object
|
|
306
|
-
_isObject(variable) {
|
|
307
|
-
return variable !== null && typeof variable === "object" && !Array.isArray(variable);
|
|
308
|
-
}
|
|
309
|
-
// Helper method to generate cache key
|
|
310
|
-
_generateCacheKey(query, branch, version) {
|
|
311
|
-
if (!query) {
|
|
312
|
-
return null;
|
|
313
|
-
}
|
|
314
|
-
return JSON.stringify({
|
|
315
|
-
query,
|
|
316
|
-
branch,
|
|
317
|
-
version
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
// Helper method to clear cache
|
|
321
|
-
clearCache() {
|
|
322
|
-
this._cache.clear();
|
|
323
|
-
}
|
|
324
|
-
// Helper method to remove specific cache entry
|
|
325
|
-
removeCacheEntry(query, branch, version) {
|
|
326
|
-
const cacheKey = this._generateCacheKey(query, branch, version);
|
|
327
|
-
if (cacheKey) {
|
|
328
|
-
this._cache.delete(cacheKey);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
// Branch Management
|
|
332
|
-
async getBranches() {
|
|
333
|
-
this._requireReady();
|
|
334
|
-
try {
|
|
335
|
-
return await this._client.getBranches();
|
|
336
|
-
} catch (error) {
|
|
337
|
-
throw new Error(`Failed to get branches: ${error.message}`);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
async createBranch(branch, options = {}) {
|
|
341
|
-
this._requireReady();
|
|
342
|
-
if (!branch) {
|
|
343
|
-
throw new Error("Branch name is required.");
|
|
344
|
-
}
|
|
345
|
-
try {
|
|
346
|
-
return await this._client.createBranch(branch, options);
|
|
347
|
-
} catch (error) {
|
|
348
|
-
throw new Error(`Failed to create branch: ${error.message}`);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
async editBranch(branch, options = {}) {
|
|
352
|
-
this._requireReady();
|
|
353
|
-
if (!branch) {
|
|
354
|
-
throw new Error("Branch name is required.");
|
|
355
|
-
}
|
|
356
|
-
try {
|
|
357
|
-
return await this._client.editBranch(branch, options);
|
|
358
|
-
} catch (error) {
|
|
359
|
-
throw new Error(`Failed to edit branch: ${error.message}`);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
async deleteBranch(branch) {
|
|
363
|
-
this._requireReady();
|
|
364
|
-
if (!branch) {
|
|
365
|
-
throw new Error("Branch name is required.");
|
|
366
|
-
}
|
|
367
|
-
try {
|
|
368
|
-
return await this._client.deleteBranch(branch);
|
|
369
|
-
} catch (error) {
|
|
370
|
-
throw new Error(`Failed to delete branch: ${error.message}`);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
async mergeBranch(branch, options = {}) {
|
|
374
|
-
this._requireReady();
|
|
375
|
-
if (!branch) {
|
|
376
|
-
throw new Error("Branch name is required.");
|
|
377
|
-
}
|
|
378
|
-
try {
|
|
379
|
-
return await this._client.mergeBranch(branch, options);
|
|
380
|
-
} catch (error) {
|
|
381
|
-
throw new Error(`Failed to merge branch: ${error.message}`);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
async restoreVersion(version, options = {}) {
|
|
385
|
-
var _a, _b;
|
|
386
|
-
this._requireReady();
|
|
387
|
-
const { branch = (_a = this._context.symstory) == null ? void 0 : _a.branch } = options;
|
|
388
|
-
version ||= (_b = this._context.symstory) == null ? void 0 : _b.version;
|
|
389
|
-
try {
|
|
390
|
-
return await this._client.restoreVersion(version, { ...options, branch });
|
|
391
|
-
} catch (error) {
|
|
392
|
-
throw new Error(`Failed to restore version: ${error.message}`);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
// Cleanup
|
|
396
|
-
destroy() {
|
|
397
|
-
this._client = null;
|
|
398
|
-
this._setReady(false);
|
|
399
|
-
}
|
|
400
|
-
// Data management methods
|
|
401
|
-
async getItem(query, options = {}) {
|
|
402
|
-
this._requireReady();
|
|
403
|
-
try {
|
|
404
|
-
return await this.getData(query, options);
|
|
405
|
-
} catch (error) {
|
|
406
|
-
throw new Error(`Failed to get item: ${error.message}`);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
async addItem(type, data, options = {}, callback) {
|
|
410
|
-
this._requireReady();
|
|
411
|
-
try {
|
|
412
|
-
import_validation.validateParams.type(type);
|
|
413
|
-
import_validation.validateParams.data(data, type);
|
|
414
|
-
const { value, ...schema } = data;
|
|
415
|
-
return await this.updateData(
|
|
416
|
-
[
|
|
417
|
-
["update", [type, data.key], value],
|
|
418
|
-
["update", ["schema", type, data.key], schema],
|
|
419
|
-
...options.additionalChanges || []
|
|
420
|
-
],
|
|
421
|
-
{
|
|
422
|
-
message: `Created ${data.key} in ${type}`,
|
|
423
|
-
...options
|
|
424
|
-
},
|
|
425
|
-
isFunction(options) ? options : callback
|
|
426
|
-
);
|
|
427
|
-
} catch (error) {
|
|
428
|
-
throw new Error(`Failed to add item: ${error.message}`);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
async addMultipleItems(items, options = {}, callback) {
|
|
432
|
-
this._requireReady();
|
|
433
|
-
const updateData = [];
|
|
434
|
-
items.forEach((item) => {
|
|
435
|
-
const [type, data] = item;
|
|
436
|
-
const { value, ...schema } = data;
|
|
437
|
-
import_validation.validateParams.type(type);
|
|
438
|
-
import_validation.validateParams.data(data, type);
|
|
439
|
-
updateData.push(
|
|
440
|
-
["update", [type, data.key], value],
|
|
441
|
-
["update", ["schema", type, data.key], schema]
|
|
442
|
-
);
|
|
443
|
-
});
|
|
444
|
-
try {
|
|
445
|
-
return await this.updateData(
|
|
446
|
-
[...updateData, ...options.additionalChanges || []],
|
|
447
|
-
{
|
|
448
|
-
message: `Created ${updateData.length} items`,
|
|
449
|
-
...options
|
|
450
|
-
},
|
|
451
|
-
isFunction(options) ? options : callback
|
|
452
|
-
);
|
|
453
|
-
} catch (error) {
|
|
454
|
-
throw new Error(`Failed to add item: ${error.message}`);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
async updateItem(type, data, options = {}, callback) {
|
|
458
|
-
this._requireReady();
|
|
459
|
-
try {
|
|
460
|
-
import_validation.validateParams.type(type);
|
|
461
|
-
import_validation.validateParams.data(data, type);
|
|
462
|
-
const { value, ...schema } = data;
|
|
463
|
-
return await this.updateData(
|
|
464
|
-
[
|
|
465
|
-
["update", [type, data.key], value],
|
|
466
|
-
["update", ["schema", type, data.key], schema]
|
|
467
|
-
],
|
|
468
|
-
{
|
|
469
|
-
message: `Updated ${data.key} in ${type}`,
|
|
470
|
-
...options
|
|
471
|
-
},
|
|
472
|
-
isFunction(options) ? options : callback
|
|
473
|
-
);
|
|
474
|
-
} catch (error) {
|
|
475
|
-
throw new Error(`Failed to update item: ${error.message}`);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
async set(path, value, options = {}, callback) {
|
|
479
|
-
this._requireReady();
|
|
480
|
-
if (!utils.isUndefined(path) || utils.isUndefined(value)) {
|
|
481
|
-
return new Error(`Path ${path} or ${value} value is not defined`);
|
|
482
|
-
}
|
|
483
|
-
try {
|
|
484
|
-
return await this.updateData(
|
|
485
|
-
[["update", path, value]],
|
|
486
|
-
{
|
|
487
|
-
message: `Updated ${utils.isArray(path) ? path.join(".") : path}`,
|
|
488
|
-
...options
|
|
489
|
-
},
|
|
490
|
-
isFunction(options) ? options : callback
|
|
491
|
-
);
|
|
492
|
-
} catch (error) {
|
|
493
|
-
throw new Error(`Failed to update item: ${error.message}`);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
async deleteItem(type, key, options = {}, callback) {
|
|
497
|
-
this._requireReady();
|
|
498
|
-
try {
|
|
499
|
-
import_validation.validateParams.type(type);
|
|
500
|
-
import_validation.validateParams.key(key, type);
|
|
501
|
-
return await this.updateData(
|
|
502
|
-
[
|
|
503
|
-
["delete", [type, key]],
|
|
504
|
-
["delete", ["schema", type, key]],
|
|
505
|
-
...options.additionalChanges || []
|
|
506
|
-
],
|
|
507
|
-
{
|
|
508
|
-
message: `Deleted ${key} from ${type}`,
|
|
509
|
-
...options
|
|
510
|
-
},
|
|
511
|
-
isFunction(options) ? options : callback
|
|
512
|
-
);
|
|
513
|
-
} catch (error) {
|
|
514
|
-
throw new Error(`Failed to delete item: ${error.message}`);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
// Helper methods
|
|
518
|
-
_createQuery(filters = []) {
|
|
519
|
-
return {
|
|
520
|
-
$find: {
|
|
521
|
-
$traverse: "children",
|
|
522
|
-
$filter: filters.filter(Boolean).map(([field, operator, value]) => ({
|
|
523
|
-
$field: field,
|
|
524
|
-
$operator: operator,
|
|
525
|
-
$value: value
|
|
526
|
-
}))
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
_checkRequiredContext() {
|
|
531
|
-
var _a, _b;
|
|
532
|
-
return Boolean(
|
|
533
|
-
((_a = this._context) == null ? void 0 : _a.appKey) && ((_b = this._context) == null ? void 0 : _b.authToken) && this._client
|
|
534
|
-
);
|
|
535
|
-
}
|
|
536
|
-
isReady() {
|
|
537
|
-
if (this._checkRequiredContext()) {
|
|
538
|
-
this._setReady(true);
|
|
539
|
-
}
|
|
540
|
-
return this._ready;
|
|
541
|
-
}
|
|
542
|
-
async switchBranch(branch) {
|
|
543
|
-
this._requireReady();
|
|
544
|
-
try {
|
|
545
|
-
this.updateContext({
|
|
546
|
-
symstory: {
|
|
547
|
-
...this._context.symstory,
|
|
548
|
-
branch,
|
|
549
|
-
version: null
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
return await this.getData();
|
|
553
|
-
} catch (error) {
|
|
554
|
-
throw new Error(`Failed to switch branch: ${error.message}`);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
async switchVersion(version) {
|
|
558
|
-
this._requireReady();
|
|
559
|
-
try {
|
|
560
|
-
this.updateContext({
|
|
561
|
-
symstory: {
|
|
562
|
-
...this._context.symstory,
|
|
563
|
-
version
|
|
564
|
-
}
|
|
565
|
-
});
|
|
566
|
-
return await this.getData();
|
|
567
|
-
} catch (error) {
|
|
568
|
-
throw new Error(`Failed to switch version: ${error.message}`);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|