New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dendronhq/common-server

Package Overview
Dependencies
Maintainers
1
Versions
438
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dendronhq/common-server - npm Package Compare versions

Comparing version

to
0.101.0

2

lib/etc.d.ts
export declare class NodeJSUtils {
static getVersionFromPkg(): string;
static getVersionFromPkg(): string | undefined;
}

@@ -4,0 +4,0 @@ export declare type WebViewThemeMap = {

@@ -8,8 +8,22 @@ "use strict";

const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const filesv2_1 = require("./filesv2");
class NodeJSUtils {
static getVersionFromPkg() {
const pkgJSON = fs_extra_1.default.readJSONSync(path_1.default.join((0, filesv2_1.goUpTo)({ base: __dirname, fname: "package.json" }), "package.json"));
return `${pkgJSON.version}`;
const packageJsonPath = (0, filesv2_1.findUpTo)({
base: __dirname,
fname: "package.json",
maxLvl: 5,
});
if (!packageJsonPath)
return undefined;
try {
const pkgJSON = fs_extra_1.default.readJSONSync(packageJsonPath);
if (!(pkgJSON === null || pkgJSON === void 0 ? void 0 : pkgJSON.version))
return undefined;
return `${pkgJSON.version}`;
}
catch {
// There may be errors if we couldn't read the file
return undefined;
}
}

@@ -16,0 +30,0 @@ }

@@ -1,2 +0,2 @@

import { DEngineClient, NoteProps, SchemaTemplate } from "@dendronhq/common-all";
import { DEngineClient, NoteProps, RespV3 } from "@dendronhq/common-all";
export declare class TemplateUtils {

@@ -16,9 +16,18 @@ /** The props of a template note that will get copied over when the template is applied. */

/**
* Try to get a template if note has a matching schema
* that also defines a template
* Given a note that has a schema:
* - Find template specified by schema
* - If there is no template found, return false
* - Find note by template name and apply callback `pickNote` to list of notes
* - Apply template note returned by callback to note and return true if applied successfully
* If note does not have a schema, return false
*
* @param note: note to apply template to. This modifies the note body
* @param pickNote: cb to pick note from list of possible template notes (can also be empty)
* @returns boolean of whether template has been applied or not
*/
static tryGetTemplateFromMatchingSchema({ note, engine, }: {
static findAndApplyTemplate({ note, engine, pickNote, }: {
note: NoteProps;
engine: DEngineClient;
}): SchemaTemplate | undefined;
pickNote: (choices: NoteProps[]) => Promise<RespV3<NoteProps | undefined>>;
}): Promise<RespV3<boolean>>;
static applyHBTemplate({ templateNote, targetNote, }: {

@@ -39,4 +48,5 @@ templateNote: NoteProps;

getDayOfWeek: number;
match: number;
};
};
}

@@ -89,2 +89,9 @@ "use strict";

},
match: (text, pattern) => {
const out = text.match(new RegExp(pattern, "i"));
if (out) {
return out[0];
}
return false;
},
};

@@ -110,6 +117,14 @@ class TemplateUtils {

/**
* Try to get a template if note has a matching schema
* that also defines a template
* Given a note that has a schema:
* - Find template specified by schema
* - If there is no template found, return false
* - Find note by template name and apply callback `pickNote` to list of notes
* - Apply template note returned by callback to note and return true if applied successfully
* If note does not have a schema, return false
*
* @param note: note to apply template to. This modifies the note body
* @param pickNote: cb to pick note from list of possible template notes (can also be empty)
* @returns boolean of whether template has been applied or not
*/
static tryGetTemplateFromMatchingSchema({ note, engine, }) {
static async findAndApplyTemplate({ note, engine, pickNote, }) {
var _a;

@@ -120,3 +135,37 @@ const maybeSchema = common_all_1.SchemaUtils.getSchemaFromNote({

});
return maybeSchema === null || maybeSchema === void 0 ? void 0 : maybeSchema.schemas[(_a = note.schema) === null || _a === void 0 ? void 0 : _a.schemaId].data.template;
const maybeTemplate = maybeSchema === null || maybeSchema === void 0 ? void 0 : maybeSchema.schemas[(_a = note.schema) === null || _a === void 0 ? void 0 : _a.schemaId].data.template;
let maybeVault;
if (maybeTemplate) {
// Support xvault template
const { link: fname, vaultName } = (0, common_all_1.parseDendronURI)(maybeTemplate === null || maybeTemplate === void 0 ? void 0 : maybeTemplate.id);
// If vault is specified, lookup by template id + vault
if (!lodash_1.default.isUndefined(vaultName)) {
maybeVault = common_all_1.VaultUtils.getVaultByName({
vname: vaultName,
vaults: engine.vaults,
});
// If vault is not found, skip lookup through rest of notes and return error
if (lodash_1.default.isUndefined(maybeVault)) {
return {
error: new common_all_1.DendronError({
message: `No vault found for ${vaultName}`,
}),
};
}
}
const maybeNotes = await engine.findNotes({ fname, vault: maybeVault });
const maybeTemplateNote = await pickNote(maybeNotes);
if (maybeTemplateNote.error) {
return { error: maybeTemplateNote.error };
}
if (maybeTemplateNote.data) {
TemplateUtils.applyTemplate({
templateNote: maybeTemplateNote.data,
targetNote: note,
engine,
});
return { data: true };
}
}
return { data: false };
}

@@ -158,6 +207,7 @@ static applyHBTemplate({ templateNote, targetNote, }) {

static genTrackPayload(templateNote) {
var _a, _b, _c;
var _a, _b, _c, _d;
const fnameToDate = ((_a = templateNote.body.match(/\{\{\s+fnameToDate[^}]+\}\}/)) === null || _a === void 0 ? void 0 : _a.length) || 0;
const eq = ((_b = templateNote.body.match(/\{\{\s+eq[^}]+\}\}/)) === null || _b === void 0 ? void 0 : _b.length) || 0;
const getDayOfWeek = ((_c = templateNote.body.match(/\{\{\s+getDayOfWeek[^}]+\}\}/)) === null || _c === void 0 ? void 0 : _c.length) || 0;
const match = ((_d = templateNote.body.match(/\{\{\s+match[^}]+\}\}/)) === null || _d === void 0 ? void 0 : _d.length) || 0;
return {

@@ -168,2 +218,3 @@ helperStats: {

getDayOfWeek,
match,
},

@@ -170,0 +221,0 @@ };

{
"name": "@dendronhq/common-server",
"version": "0.100.1",
"version": "0.101.0",
"description": "common-server",

@@ -40,3 +40,3 @@ "license": "GPLv3",

"dependencies": {
"@dendronhq/common-all": "^0.100.1",
"@dendronhq/common-all": "^0.101.0",
"@sentry/integrations": "^6.13.3",

@@ -90,3 +90,3 @@ "@sentry/node": "^6.13.3",

},
"gitHead": "ed07cb14af7c63507a72cd08cfa49ec29d597b4a"
"gitHead": "ebe807957fed7ea42ad7cb3fb4bf4a1ca8adb3e2"
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet