Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gedit/resource

Package Overview
Dependencies
Maintainers
3
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gedit/resource - npm Package Compare versions

Comparing version 0.1.71 to 0.1.72

467

lib/browser/resource-autosave-service.js
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -25,68 +14,7 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResourceAutoSaveService = exports.ResourceAutoSaveOptions = void 0;
var inversify_1 = require("inversify");
var utils_1 = require("@gedit/utils");
var common_1 = require("../common");
const inversify_1 = require("inversify");
const utils_1 = require("@gedit/utils");
const common_1 = require("../common");
exports.ResourceAutoSaveOptions = Symbol('ResourceAutoSaveOptions');

@@ -96,5 +24,4 @@ /**

*/
var ResourceAutoSaveService = /** @class */ (function () {
function ResourceAutoSaveService(options) {
var _this = this;
let ResourceAutoSaveService = class ResourceAutoSaveService {
constructor(options) {
this.options = options;

@@ -133,7 +60,7 @@ this.autoSave = 'on';

this.toDispose.push(this.onErrorEmitter);
this.toDispose.push(utils_1.Disposable.create(function () {
_this.resource.dispose();
this.toDispose.push(utils_1.Disposable.create(() => {
this.resource.dispose();
}));
this.toDispose.push(utils_1.Disposable.create(function () { return _this.cancelSave(); }));
this.toDispose.push(utils_1.Disposable.create(function () { return _this.cancelSync(); }));
this.toDispose.push(utils_1.Disposable.create(() => this.cancelSave()));
this.toDispose.push(utils_1.Disposable.create(() => this.cancelSync()));
}

@@ -144,3 +71,3 @@ /**

*/
ResourceAutoSaveService.prototype.changeResource = function (resource) {
changeResource(resource) {
this.resource.dispose(); // clear old resource

@@ -150,30 +77,22 @@ this.resource = resource;

this.onResourceChangedEmitter.fire(resource);
};
ResourceAutoSaveService.prototype.dispose = function () {
}
dispose() {
this.toDispose.dispose();
};
Object.defineProperty(ResourceAutoSaveService.prototype, "dirty", {
get: function () {
return this._dirty;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ResourceAutoSaveService.prototype, "valid", {
get: function () {
return this._valid;
},
enumerable: false,
configurable: true
});
ResourceAutoSaveService.prototype.save = function () {
}
get dirty() {
return this._dirty;
}
get valid() {
return this._valid;
}
save() {
return this.scheduleSave();
};
}
;
ResourceAutoSaveService.prototype.cancelSave = function () {
cancelSave() {
this.saveCancellationTokenSource.cancel();
this.saveCancellationTokenSource = new utils_1.CancellationTokenSource();
return this.saveCancellationTokenSource.token;
};
ResourceAutoSaveService.prototype.setDirty = function (dirty) {
}
setDirty(dirty) {
if (dirty === this._dirty) {

@@ -187,22 +106,16 @@ return;

this.onDirtyChangedEmitter.fire(undefined);
};
ResourceAutoSaveService.prototype.markAsDirty = function () {
}
markAsDirty() {
this.setDirty(true);
this.doAutoSave();
};
ResourceAutoSaveService.prototype.cancelSync = function () {
}
cancelSync() {
this.syncCancellationTokenSource.cancel();
this.syncCancellationTokenSource = new utils_1.CancellationTokenSource();
return this.syncCancellationTokenSource.token;
};
ResourceAutoSaveService.prototype.sync = function () {
return __awaiter(this, void 0, void 0, function () {
var token;
var _this = this;
return __generator(this, function (_a) {
token = this.cancelSync();
return [2 /*return*/, this.run(function () { return _this.doSync(token); })];
});
});
};
}
async sync() {
const token = this.cancelSync();
return this.run(() => this.doSync(token));
}
/**

@@ -212,199 +125,134 @@ * 用于回退等动作相关数据重载

*/
ResourceAutoSaveService.prototype.reload = function (content) {
var _this = this;
reload(content) {
// 直接触发数据更新
this.onSyncContentEmitter.fire(content);
var token = this.cancelSave();
this.run(function () { return __awaiter(_this, void 0, void 0, function () {
var version, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (token.isCancellationRequested || !this.resource.saveContents || !this._valid) {
return [2 /*return*/];
}
version = this.resourceVersion;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, common_1.Resource.save(this.resource, { content: content, options: { encoding: this.options.encoding, version: version } }, token)];
case 2:
_a.sent();
// TODO 没有触发DidChange
console.log("-- reload (".concat(this.resource.uri.displayName, ") --"));
this.contentChanges.length = 0;
this.resourceVersion = this.resource.version;
this.setValid(true);
if (token.isCancellationRequested) {
return [2 /*return*/];
}
this.setDirty(false);
return [3 /*break*/, 4];
case 3:
e_1 = _a.sent();
this.contentChanges.length = 0;
// TODO 可能会有数据丢失
this.setValid(true);
this.setDirty(false);
if (!common_1.ResourceError.OutOfSync.is(e_1)) {
throw e_1;
}
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
const token = this.cancelSave();
this.run(async () => {
if (token.isCancellationRequested || !this.resource.saveContents || !this._valid) {
return;
}
const version = this.resourceVersion;
try {
await common_1.Resource.save(this.resource, { content, options: { encoding: this.options.encoding, version } }, token);
// TODO 没有触发DidChange
console.log(`-- reload (${this.resource.uri.displayName}) --`);
this.contentChanges.length = 0;
this.resourceVersion = this.resource.version;
this.setValid(true);
if (token.isCancellationRequested) {
return;
}
});
}); });
};
ResourceAutoSaveService.prototype.doSync = function (token) {
return __awaiter(this, void 0, void 0, function () {
var newText;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (token.isCancellationRequested) {
return [2 /*return*/];
}
return [4 /*yield*/, this.readContents()];
case 1:
newText = _a.sent();
if (token.isCancellationRequested || this._dirty) {
return [2 /*return*/];
}
this.onSyncContentEmitter.fire(newText);
this.resourceVersion = this.resource.version;
return [2 /*return*/];
this.setDirty(false);
}
catch (e) {
this.contentChanges.length = 0;
// TODO 可能会有数据丢失
this.setValid(true);
this.setDirty(false);
if (!common_1.ResourceError.OutOfSync.is(e)) {
throw e;
}
});
}
});
};
}
async doSync(token) {
if (token.isCancellationRequested) {
return;
}
const newText = await this.readContents();
if (token.isCancellationRequested || this._dirty) {
return;
}
this.onSyncContentEmitter.fire(newText);
this.resourceVersion = this.resource.version;
}
/**
* 自动保存
*/
ResourceAutoSaveService.prototype.doAutoSave = function () {
var _this = this;
doAutoSave() {
if (this.autoSave === 'on') {
var token_1 = this.cancelSave();
const token = this.cancelSave();
this.toDisposeOnAutoSave.dispose();
var handle_1 = window.setTimeout(function () {
_this.scheduleSave(token_1);
const handle = window.setTimeout(() => {
this.scheduleSave(token);
}, this.autoSaveDelay);
this.toDisposeOnAutoSave.push(utils_1.Disposable.create(function () { return window.clearTimeout(handle_1); }));
this.toDisposeOnAutoSave.push(utils_1.Disposable.create(() => window.clearTimeout(handle)));
}
};
ResourceAutoSaveService.prototype.run = function (operation) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
if (this.toDispose.disposed) {
return [2 /*return*/];
}
return [2 /*return*/, this.pendingOperation = this.pendingOperation.then(function () { return __awaiter(_this, void 0, void 0, function () {
var e_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, operation()];
case 1:
_a.sent();
return [3 /*break*/, 3];
case 2:
e_2 = _a.sent();
console.error(e_2);
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
});
}); })];
});
}
async run(operation) {
if (this.toDispose.disposed) {
return;
}
return this.pendingOperation = this.pendingOperation.then(async () => {
try {
await operation();
}
catch (e) {
console.error(e);
}
});
};
ResourceAutoSaveService.prototype.scheduleSave = function (token) {
var _this = this;
if (token === void 0) { token = this.cancelSave(); }
return this.run(function () { return _this.doSave(token); });
};
ResourceAutoSaveService.prototype.doSave = function (token) {
return __awaiter(this, void 0, void 0, function () {
var changes, version, lastChanged, content, e_3, isOutOfSync;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (token.isCancellationRequested || !this.resource.saveContents || !this._valid) {
return [2 /*return*/];
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
changes = __spreadArray([], __read(this.contentChanges), false);
if (changes.length === 0)
return [2 /*return*/];
version = this.resourceVersion;
lastChanged = changes[changes.length - 1];
content = this.options.saveAsString(lastChanged);
this.onPreSaveContentEmitter.fire({ content: content });
return [4 /*yield*/, common_1.Resource.save(this.resource, { content: content, options: { encoding: this.options.encoding, version: version } }, token)];
case 2:
_a.sent();
this.onDidSaveContentEmitter.fire(__assign(__assign({}, lastChanged), { content: content }));
console.log("-- save (".concat(this.resource.uri.displayName, ") --"));
this.contentChanges.length = 0;
this.resourceVersion = this.resource.version;
this.setValid(true);
if (token.isCancellationRequested) {
return [2 /*return*/];
}
this.setDirty(false);
return [3 /*break*/, 4];
case 3:
e_3 = _a.sent();
this.contentChanges.length = 0;
// TODO 可能会有数据丢失
this.setValid(true);
this.setDirty(false);
isOutOfSync = common_1.ResourceError.OutOfSync.is(e_3);
// 自动同步
if (isOutOfSync) {
this.sync();
}
this.onErrorEmitter.fire(e_3);
if (!isOutOfSync) {
throw e_3;
}
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
};
ResourceAutoSaveService.prototype.readContents = function () {
return __awaiter(this, void 0, void 0, function () {
var content, e_4;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.resource.readContents({ encoding: this.options.encoding })];
case 1:
content = _a.sent();
this.setValid(true);
return [2 /*return*/, content];
case 2:
e_4 = _a.sent();
this.setValid(false);
if (common_1.ResourceError.NotFound.is(e_4)) {
this.setValid(true);
return [2 /*return*/, undefined];
}
throw e_4;
case 3: return [2 /*return*/];
}
});
});
};
ResourceAutoSaveService.prototype.fireDidChangeContent = function (event) {
}
scheduleSave(token = this.cancelSave()) {
return this.run(() => this.doSave(token));
}
async doSave(token) {
if (token.isCancellationRequested || !this.resource.saveContents || !this._valid) {
return;
}
try {
const changes = [...this.contentChanges];
if (changes.length === 0)
return;
const version = this.resourceVersion;
// TODO 这里暂时只考虑全量替换, 需要优化
const lastChanged = changes[changes.length - 1];
const content = this.options.saveAsString(lastChanged);
this.onPreSaveContentEmitter.fire({ content });
await common_1.Resource.save(this.resource, { content, options: { encoding: this.options.encoding, version } }, token);
this.onDidSaveContentEmitter.fire(Object.assign(Object.assign({}, lastChanged), { content }));
console.log(`-- save (${this.resource.uri.displayName}) --`);
this.contentChanges.length = 0;
this.resourceVersion = this.resource.version;
this.setValid(true);
if (token.isCancellationRequested) {
return;
}
this.setDirty(false);
}
catch (e) {
this.contentChanges.length = 0;
// TODO 可能会有数据丢失
this.setValid(true);
this.setDirty(false);
const isOutOfSync = common_1.ResourceError.OutOfSync.is(e);
// 自动同步
if (isOutOfSync) {
this.sync();
}
this.onErrorEmitter.fire(e);
if (!isOutOfSync) {
throw e;
}
}
}
async readContents() {
try {
const content = await this.resource.readContents({ encoding: this.options.encoding });
this.setValid(true);
return content;
}
catch (e) {
this.setValid(false);
if (common_1.ResourceError.NotFound.is(e)) {
this.setValid(true);
return undefined;
}
throw e;
}
}
fireDidChangeContent(event) {
this.contentChanges.push(event);
this.markAsDirty();
};
ResourceAutoSaveService.prototype.setValid = function (valid) {
}
setValid(valid) {
if (valid === this._valid) {

@@ -415,11 +263,10 @@ return;

this.onDidChangeValidEmitter.fire(undefined);
};
ResourceAutoSaveService = __decorate([
(0, inversify_1.injectable)(),
__param(0, (0, inversify_1.inject)(exports.ResourceAutoSaveOptions)),
__metadata("design:paramtypes", [Object])
], ResourceAutoSaveService);
return ResourceAutoSaveService;
}());
}
};
ResourceAutoSaveService = __decorate([
(0, inversify_1.injectable)(),
__param(0, (0, inversify_1.inject)(exports.ResourceAutoSaveOptions)),
__metadata("design:paramtypes", [Object])
], ResourceAutoSaveService);
exports.ResourceAutoSaveService = ResourceAutoSaveService;
//# sourceMappingURL=resource-autosave-service.js.map

@@ -28,13 +28,11 @@ "use strict";

exports.ResourceContextKey = void 0;
var inversify_1 = require("inversify");
var utils_1 = require("@gedit/utils");
var browser_1 = require("@gedit/application-common/lib/browser");
var ResourceContextKey = /** @class */ (function () {
function ResourceContextKey() {
const inversify_1 = require("inversify");
const utils_1 = require("@gedit/utils");
const browser_1 = require("@gedit/application-common/lib/browser");
let ResourceContextKey = class ResourceContextKey {
get() {
const codeUri = this.resource.get();
return codeUri && new utils_1.URI(codeUri);
}
ResourceContextKey.prototype.get = function () {
var codeUri = this.resource.get();
return codeUri && new utils_1.URI(codeUri);
};
ResourceContextKey.prototype.set = function (resourceUri) {
set(resourceUri) {
this.resource.set(resourceUri && resourceUri['codeUri']);

@@ -45,4 +43,4 @@ this.resourceSchemeKey.set(resourceUri && resourceUri.scheme);

this.resourceLangId.set(resourceUri && this.getLanguageId(resourceUri));
};
ResourceContextKey.prototype.init = function () {
}
init() {
this.resource = this.contextKeyService.createKey('resource', undefined);

@@ -53,23 +51,22 @@ this.resourceSchemeKey = this.contextKeyService.createKey('resourceScheme', undefined);

this.resourceLangId = this.contextKeyService.createKey('resourceLangId', undefined);
};
}
/** should be implemented by subclasses */
ResourceContextKey.prototype.getLanguageId = function (uri) {
getLanguageId(uri) {
return undefined;
};
__decorate([
(0, inversify_1.inject)(browser_1.ContextKeyService),
__metadata("design:type", browser_1.ContextKeyService)
], ResourceContextKey.prototype, "contextKeyService", void 0);
__decorate([
(0, inversify_1.postConstruct)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ResourceContextKey.prototype, "init", null);
ResourceContextKey = __decorate([
(0, inversify_1.injectable)()
], ResourceContextKey);
return ResourceContextKey;
}());
}
};
__decorate([
(0, inversify_1.inject)(browser_1.ContextKeyService),
__metadata("design:type", browser_1.ContextKeyService)
], ResourceContextKey.prototype, "contextKeyService", void 0);
__decorate([
(0, inversify_1.postConstruct)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ResourceContextKey.prototype, "init", null);
ResourceContextKey = __decorate([
(0, inversify_1.injectable)()
], ResourceContextKey);
exports.ResourceContextKey = ResourceContextKey;
//# sourceMappingURL=resource-context-key.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var inversify_1 = require("inversify");
var resource_1 = require("../common/resource");
var resource_ref_1 = require("../common/resource-ref");
var utils_1 = require("@gedit/utils");
var resource_context_key_1 = require("./resource-context-key");
exports.default = new inversify_1.ContainerModule(function (bind) {
const inversify_1 = require("inversify");
const resource_1 = require("../common/resource");
const resource_ref_1 = require("../common/resource-ref");
const utils_1 = require("@gedit/utils");
const resource_context_key_1 = require("./resource-context-key");
exports.default = new inversify_1.ContainerModule(bind => {
bind(resource_1.DefaultResourceProvider).toSelf().inSingletonScope();
bind(resource_1.ResourceProvider).toProvider(function (context) { return function (uri) { return context.container.get(resource_1.DefaultResourceProvider).get(uri); }; });
bind(resource_1.ResourceProvider).toProvider(context => uri => context.container.get(resource_1.DefaultResourceProvider).get(uri));
bind(resource_ref_1.ResourceRefProvider).to(resource_ref_1.DefaultResourceRefProvider).inSingletonScope();

@@ -12,0 +12,0 @@ bind(resource_1.InMemoryResources).toSelf().inSingletonScope();

@@ -14,105 +14,41 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultResourceRefProvider = exports.ResourceRefProvider = exports.ResourceRefProviderContribution = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
var inversify_1 = require("inversify");
var utils_1 = require("@gedit/utils");
const inversify_1 = require("inversify");
const utils_1 = require("@gedit/utils");
exports.ResourceRefProviderContribution = Symbol('ResourceRefsProviderContribution');
exports.ResourceRefProvider = Symbol('ResourceRefProvider');
var DefaultResourceRefProvider = /** @class */ (function () {
function DefaultResourceRefProvider(contributionProvider) {
let DefaultResourceRefProvider = class DefaultResourceRefProvider {
constructor(contributionProvider) {
this.contributionProvider = contributionProvider;
}
DefaultResourceRefProvider.prototype.getProvider = function (uri) {
var e_1, _a;
try {
for (var _b = __values(this.contributionProvider.getContributions()), _c = _b.next(); !_c.done; _c = _b.next()) {
var provider = _c.value;
if (provider.canHandle(uri)) {
return provider;
}
getProvider(uri) {
for (const provider of this.contributionProvider.getContributions()) {
if (provider.canHandle(uri)) {
return provider;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return undefined;
};
DefaultResourceRefProvider.prototype.getRefInfo = function (uri, document) {
var provider = this.getProvider(uri);
}
getRefInfo(uri, document) {
const provider = this.getProvider(uri);
if (!provider)
throw new Error('Unknown resource ref provider: ' + uri);
return provider.getRefInfo(uri, document);
};
DefaultResourceRefProvider.prototype.checkErrors = function (uri, info) {
return __awaiter(this, void 0, void 0, function () {
var provider;
return __generator(this, function (_a) {
provider = this.getProvider(uri);
if (!provider)
throw new Error('Unknown resource ref provider: ' + uri);
return [2 /*return*/, provider.checkErrors(uri, info)];
});
});
};
DefaultResourceRefProvider = __decorate([
(0, inversify_1.injectable)(),
__param(0, (0, inversify_1.inject)(utils_1.ContributionProvider)),
__param(0, (0, inversify_1.named)(exports.ResourceRefProviderContribution)),
__metadata("design:paramtypes", [Object])
], DefaultResourceRefProvider);
return DefaultResourceRefProvider;
}());
}
async checkErrors(uri, info) {
const provider = this.getProvider(uri);
if (!provider)
throw new Error('Unknown resource ref provider: ' + uri);
return provider.checkErrors(uri, info);
}
};
DefaultResourceRefProvider = __decorate([
(0, inversify_1.injectable)(),
__param(0, (0, inversify_1.inject)(utils_1.ContributionProvider)),
__param(0, (0, inversify_1.named)(exports.ResourceRefProviderContribution)),
__metadata("design:paramtypes", [Object])
], DefaultResourceRefProvider);
exports.DefaultResourceRefProvider = DefaultResourceRefProvider;
//# sourceMappingURL=resource-ref.js.map

@@ -29,133 +29,50 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InMemoryResources = exports.MutableResource = exports.DefaultResourceProvider = exports.ResourceProvider = exports.ResourceResolver = exports.ResourceError = exports.Resource = void 0;
var inversify_1 = require("inversify");
var application_common_1 = require("@gedit/application-common");
var utils_1 = require("@gedit/utils");
const inversify_1 = require("inversify");
const application_common_1 = require("@gedit/application-common");
const utils_1 = require("@gedit/utils");
var Resource;
(function (Resource) {
function save(resource, context, token) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!resource.saveContents) {
return [2 /*return*/];
}
return [4 /*yield*/, trySaveContentChanges(resource, context)];
case 1:
if (_a.sent()) {
return [2 /*return*/];
}
if (token && token.isCancellationRequested) {
return [2 /*return*/];
}
return [4 /*yield*/, resource.saveContents(context.content, context.options)];
case 2:
_a.sent();
return [2 /*return*/];
}
});
});
async function save(resource, context, token) {
if (!resource.saveContents) {
return;
}
if (await trySaveContentChanges(resource, context)) {
return;
}
if (token && token.isCancellationRequested) {
return;
}
await resource.saveContents(context.content, context.options);
}
Resource.save = save;
function trySaveContentChanges(resource, context) {
return __awaiter(this, void 0, void 0, function () {
var e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!context.changes || !resource.saveContentChanges || shouldSaveContent(context)) {
return [2 /*return*/, false];
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, resource.saveContentChanges(context.changes, context.options)];
case 2:
_a.sent();
return [2 /*return*/, true];
case 3:
e_1 = _a.sent();
if (!ResourceError.NotFound.is(e_1) && !ResourceError.OutOfSync.is(e_1)) {
console.error("Failed to apply incremental changes to '".concat(resource.uri.toString(), "':"), e_1);
}
return [2 /*return*/, false];
case 4: return [2 /*return*/];
}
});
});
async function trySaveContentChanges(resource, context) {
if (!context.changes || !resource.saveContentChanges || shouldSaveContent(context)) {
return false;
}
try {
await resource.saveContentChanges(context.changes, context.options);
return true;
}
catch (e) {
if (!ResourceError.NotFound.is(e) && !ResourceError.OutOfSync.is(e)) {
console.error(`Failed to apply incremental changes to '${resource.uri.toString()}':`, e);
}
return false;
}
}
Resource.trySaveContentChanges = trySaveContentChanges;
function shouldSaveContent(_a) {
var e_2, _b;
var content = _a.content, changes = _a.changes;
function shouldSaveContent({ content, changes }) {
if (!changes) {
return true;
}
var contentChangesLength = 0;
var contentLength = content.length;
try {
for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
var change = changes_1_1.value;
contentChangesLength += JSON.stringify(change).length;
if (contentChangesLength > contentLength) {
return true;
}
let contentChangesLength = 0;
const contentLength = content.length;
for (const change of changes) {
contentChangesLength += JSON.stringify(change).length;
if (contentChangesLength > contentLength) {
return true;
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (changes_1_1 && !changes_1_1.done && (_b = changes_1.return)) _b.call(changes_1);
}
finally { if (e_2) throw e_2.error; }
}
return contentChangesLength > contentLength;

@@ -167,9 +84,9 @@ }

(function (ResourceError) {
ResourceError.NotFound = application_common_1.ApplicationError.declare(-40000, function (raw) { return raw; });
ResourceError.OutOfSync = application_common_1.ApplicationError.declare(-40001, function (raw) { return raw; });
ResourceError.NotFound = application_common_1.ApplicationError.declare(-40000, (raw) => raw);
ResourceError.OutOfSync = application_common_1.ApplicationError.declare(-40001, (raw) => raw);
})(ResourceError = exports.ResourceError || (exports.ResourceError = {}));
exports.ResourceResolver = Symbol('ResourceResolver');
exports.ResourceProvider = Symbol('ResourceProvider');
var DefaultResourceProvider = /** @class */ (function () {
function DefaultResourceProvider(resolversProvider) {
let DefaultResourceProvider = class DefaultResourceProvider {
constructor(resolversProvider) {
this.resolversProvider = resolversProvider;

@@ -180,56 +97,24 @@ }

*/
DefaultResourceProvider.prototype.get = function (uri) {
return __awaiter(this, void 0, void 0, function () {
var resolvers, resolvers_1, resolvers_1_1, resolver, err_1, e_3_1;
var e_3, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
resolvers = this.resolversProvider.getContributions();
_b.label = 1;
case 1:
_b.trys.push([1, 8, 9, 10]);
resolvers_1 = __values(resolvers), resolvers_1_1 = resolvers_1.next();
_b.label = 2;
case 2:
if (!!resolvers_1_1.done) return [3 /*break*/, 7];
resolver = resolvers_1_1.value;
_b.label = 3;
case 3:
_b.trys.push([3, 5, , 6]);
return [4 /*yield*/, resolver.resolve(uri)];
case 4: return [2 /*return*/, _b.sent()];
case 5:
err_1 = _b.sent();
return [3 /*break*/, 6];
case 6:
resolvers_1_1 = resolvers_1.next();
return [3 /*break*/, 2];
case 7: return [3 /*break*/, 10];
case 8:
e_3_1 = _b.sent();
e_3 = { error: e_3_1 };
return [3 /*break*/, 10];
case 9:
try {
if (resolvers_1_1 && !resolvers_1_1.done && (_a = resolvers_1.return)) _a.call(resolvers_1);
}
finally { if (e_3) throw e_3.error; }
return [7 /*endfinally*/];
case 10: return [2 /*return*/, Promise.reject(new Error("A resource provider for '".concat(uri.toString(), "' is not registered.")))];
}
});
});
};
DefaultResourceProvider = __decorate([
(0, inversify_1.injectable)(),
__param(0, (0, inversify_1.inject)(utils_1.ContributionProvider)),
__param(0, (0, inversify_1.named)(exports.ResourceResolver)),
__metadata("design:paramtypes", [Object])
], DefaultResourceProvider);
return DefaultResourceProvider;
}());
async get(uri) {
const resolvers = this.resolversProvider.getContributions();
for (const resolver of resolvers) {
try {
return await resolver.resolve(uri);
}
catch (err) {
// no-op
}
}
return Promise.reject(new Error(`A resource provider for '${uri.toString()}' is not registered.`));
}
};
DefaultResourceProvider = __decorate([
(0, inversify_1.injectable)(),
__param(0, (0, inversify_1.inject)(utils_1.ContributionProvider)),
__param(0, (0, inversify_1.named)(exports.ResourceResolver)),
__metadata("design:paramtypes", [Object])
], DefaultResourceProvider);
exports.DefaultResourceProvider = DefaultResourceProvider;
var MutableResource = /** @class */ (function () {
function MutableResource(uri, contents, dispose) {
class MutableResource {
constructor(uri, contents, dispose) {
this.uri = uri;

@@ -241,60 +126,48 @@ this.dispose = dispose;

}
MutableResource.prototype.readContents = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.contents];
});
});
};
MutableResource.prototype.saveContents = function (contents) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.contents = contents;
this.fireDidChangeContents();
return [2 /*return*/];
});
});
};
MutableResource.prototype.fireDidChangeContents = function () {
async readContents() {
return this.contents;
}
async saveContents(contents) {
this.contents = contents;
this.fireDidChangeContents();
}
fireDidChangeContents() {
this.onDidChangeContentsEmitter.fire(undefined);
};
return MutableResource;
}());
}
}
exports.MutableResource = MutableResource;
var InMemoryResources = /** @class */ (function () {
function InMemoryResources() {
let InMemoryResources = class InMemoryResources {
constructor() {
this.resources = new Map();
}
InMemoryResources.prototype.add = function (uri, contents) {
var _this = this;
var resourceUri = uri.toString();
add(uri, contents) {
const resourceUri = uri.toString();
if (this.resources.has(resourceUri)) {
throw new Error("Cannot add already existing in-memory resource '".concat(resourceUri, "'"));
throw new Error(`Cannot add already existing in-memory resource '${resourceUri}'`);
}
var resource = new MutableResource(uri, contents, function () { return _this.resources.delete(resourceUri); });
const resource = new MutableResource(uri, contents, () => this.resources.delete(resourceUri));
this.resources.set(resourceUri, resource);
return resource;
};
InMemoryResources.prototype.update = function (uri, contents) {
var resourceUri = uri.toString();
var resource = this.resources.get(resourceUri);
}
update(uri, contents) {
const resourceUri = uri.toString();
const resource = this.resources.get(resourceUri);
if (!resource) {
throw new Error("Cannot update non-existed in-memory resource '".concat(resourceUri, "'"));
throw new Error(`Cannot update non-existed in-memory resource '${resourceUri}'`);
}
resource.saveContents(contents);
return resource;
};
InMemoryResources.prototype.resolve = function (uri) {
var uriString = uri.toString();
}
resolve(uri) {
const uriString = uri.toString();
if (!this.resources.has(uriString)) {
throw new Error("In memory '".concat(uriString, "' resource does not exist."));
throw new Error(`In memory '${uriString}' resource does not exist.`);
}
return this.resources.get(uriString);
};
InMemoryResources = __decorate([
(0, inversify_1.injectable)()
], InMemoryResources);
return InMemoryResources;
}());
}
};
InMemoryResources = __decorate([
(0, inversify_1.injectable)()
], InMemoryResources);
exports.InMemoryResources = InMemoryResources;
//# sourceMappingURL=resource.js.map
{
"name": "@gedit/resource",
"version": "0.1.71",
"version": "0.1.72",
"license": "MIT",

@@ -12,4 +12,4 @@ "main": "lib/common/index",

"dependencies": {
"@gedit/application-common": "^0.1.68",
"@gedit/utils": "^0.1.69",
"@gedit/application-common": "^0.1.69",
"@gedit/utils": "^0.1.70",
"vscode-languageserver-protocol": "^3.15.3"

@@ -32,3 +32,3 @@ },

},
"gitHead": "1bb1a2c9de07b987e6e1c15053e7278766cbe23c"
"gitHead": "8bdf36b3a3898da871ec15be92760865fc6a182a"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc