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

haystack-codegen

Package Overview
Dependencies
Maintainers
15
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

haystack-codegen - npm Package Compare versions

Comparing version 0.24.0 to 0.25.0

96

dist/CodeGenerator.js

@@ -5,14 +5,2 @@ "use strict";

*/
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _CodeGenerator_names, _CodeGenerator_namespace, _CodeGenerator_typeGuardOptions, _CodeGenerator_nameToDefCache;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -44,2 +32,18 @@ exports.CodeGenerator = exports.TypeGuardOptions = void 0;

/**
* The def names.
*/
#names;
/**
* The defs namespace.
*/
#namespace;
/**
* Typeguard options.
*/
#typeGuardOptions;
/**
* A name to def cache.
*/
#nameToDefCache = {};
/**
* Construct a new code generator.

@@ -51,28 +55,5 @@ *

constructor({ names, namespace, typeGuardOptions, }) {
/**
* The def names.
*/
_CodeGenerator_names.set(this, void 0);
/**
* The defs namespace.
*/
_CodeGenerator_namespace.set(this, void 0);
/**
* Typeguard options.
*/
_CodeGenerator_typeGuardOptions.set(this, void 0);
/**
* A name to def cache.
*/
_CodeGenerator_nameToDefCache.set(this, {}
/**
* Construct a new code generator.
*
* @param names The names of the defs to generate the code for.
* @param namespace The defs namespace.
*/
);
__classPrivateFieldSet(this, _CodeGenerator_names, names, "f");
__classPrivateFieldSet(this, _CodeGenerator_namespace, namespace, "f");
__classPrivateFieldSet(this, _CodeGenerator_typeGuardOptions, typeGuardOptions, "f");
this.#names = names;
this.#namespace = namespace;
this.#typeGuardOptions = typeGuardOptions;
}

@@ -86,5 +67,5 @@ /**

const doc = new DocNode_1.DocNode();
__classPrivateFieldSet(this, _CodeGenerator_nameToDefCache, {}, "f");
this.#nameToDefCache = {};
for (const name of this.sortNamesAndFeatures()) {
if (!__classPrivateFieldGet(this, _CodeGenerator_namespace, "f").has(name)) {
if (!this.#namespace.has(name)) {
throw new Error(`Could not find def for ${name}`);

@@ -104,3 +85,3 @@ }

// names (duplicates). Therefore process non-feature defs first.
const names = this.removeDuplicates(__classPrivateFieldGet(this, _CodeGenerator_names, "f"));
const names = this.removeDuplicates(this.#names);
const features = [];

@@ -121,4 +102,4 @@ for (let i = names.length; i >= 0; --i) {

addInterface(name, doc) {
const tags = __classPrivateFieldGet(this, _CodeGenerator_namespace, "f").tags(name);
const def = __classPrivateFieldGet(this, _CodeGenerator_namespace, "f").byName(name);
const tags = this.#namespace.tags(name);
const def = this.#namespace.byName(name);
if (def) {

@@ -129,3 +110,3 @@ this.addLib(def, doc);

def: name,
name: (0, util_1.makeTypeName)(name, __classPrivateFieldGet(this, _CodeGenerator_nameToDefCache, "f")),
name: (0, util_1.makeTypeName)(name, this.#nameToDefCache),
doc: def?.get('doc')?.value ?? '',

@@ -143,4 +124,4 @@ });

!CodeGenerator.isDefFromCorePh(def)) {
if (__classPrivateFieldGet(this, _CodeGenerator_typeGuardOptions, "f") === TypeGuardOptions.all ||
__classPrivateFieldGet(this, _CodeGenerator_namespace, "f").fitsEntity(name)) {
if (this.#typeGuardOptions === TypeGuardOptions.all ||
this.#namespace.fitsEntity(name)) {
this.addTypeGuard(name, doc);

@@ -160,3 +141,3 @@ }

if ((0, haystack_core_1.valueIsKind)(lib, haystack_core_1.Kind.Symbol)) {
const libDef = __classPrivateFieldGet(this, _CodeGenerator_namespace, "f").get(lib);
const libDef = this.#namespace.get(lib);
if (libDef) {

@@ -184,4 +165,4 @@ doc.libs.addLib(libDef);

addExtends(name, doc, intNode) {
for (const sup of __classPrivateFieldGet(this, _CodeGenerator_namespace, "f").superTypesOf(name)) {
intNode.extend.push((0, util_1.makeTypeName)(sup.defName, __classPrivateFieldGet(this, _CodeGenerator_nameToDefCache, "f")));
for (const sup of this.#namespace.superTypesOf(name)) {
intNode.extend.push((0, util_1.makeTypeName)(sup.defName, this.#nameToDefCache));
this.addInterface(sup.defName, doc);

@@ -200,3 +181,3 @@ }

const tagSet = new Set();
const def = __classPrivateFieldGet(this, _CodeGenerator_namespace, "f").byName(name);
const def = this.#namespace.byName(name);
if (def.get('mandatory')?.equals(haystack_core_1.HMarker.make())) {

@@ -206,3 +187,3 @@ this.addValueNode(def, tagSet, intNode, /*optional*/ false);

for (const tag of tags) {
for (const tagOn of __classPrivateFieldGet(this, _CodeGenerator_namespace, "f").tagOn(tag.defName)) {
for (const tagOn of this.#namespace.tagOn(tag.defName)) {
if (tagOn.defName === name) {

@@ -220,3 +201,3 @@ const optional = !tag

!tagSet.has(tag)) {
const kind = __classPrivateFieldGet(this, _CodeGenerator_namespace, "f").defToKind(tag.defName);
const kind = this.#namespace.defToKind(tag.defName);
if (kind) {

@@ -246,7 +227,7 @@ tagSet.add(tag);

// Currently only support generic types for lists.
const genericOf = (__classPrivateFieldGet(this, _CodeGenerator_namespace, "f").defToKind(tag.defName) === haystack_core_1.Kind.List &&
const genericOf = (this.#namespace.defToKind(tag.defName) === haystack_core_1.Kind.List &&
tag.get('of')?.value) ||
'';
if (genericOf) {
const genericKind = __classPrivateFieldGet(this, _CodeGenerator_namespace, "f").defToKind(genericOf);
const genericKind = this.#namespace.defToKind(genericOf);
if (genericKind) {

@@ -272,3 +253,3 @@ typeInfo = {

return kind === haystack_core_1.Kind.Dict && name !== 'dict'
? (0, util_1.makeTypeName)(name, __classPrivateFieldGet(this, _CodeGenerator_nameToDefCache, "f"))
? (0, util_1.makeTypeName)(name, this.#nameToDefCache)
: (0, util_1.convertKindToCtorName)(kind);

@@ -288,3 +269,3 @@ }

}
const featureDef = __classPrivateFieldGet(this, _CodeGenerator_namespace, "f").byName(feature);
const featureDef = this.#namespace.byName(feature);
doc.addNamespace(new NamespaceNode_1.NamespaceNode(feature ?? '', intNode, featureDef?.get('doc')?.value ?? ''));

@@ -299,3 +280,3 @@ }

addTypeGuard(name, doc) {
doc.addTypeGuard(new TypeGuardNode_1.TypeGuardNode(name, (0, util_1.makeTypeName)(name, __classPrivateFieldGet(this, _CodeGenerator_nameToDefCache, "f"))));
doc.addTypeGuard(new TypeGuardNode_1.TypeGuardNode(name, (0, util_1.makeTypeName)(name, this.#nameToDefCache)));
}

@@ -324,2 +305,1 @@ /**

exports.CodeGenerator = CodeGenerator;
_CodeGenerator_names = new WeakMap(), _CodeGenerator_namespace = new WeakMap(), _CodeGenerator_typeGuardOptions = new WeakMap(), _CodeGenerator_nameToDefCache = new WeakMap();

@@ -19,5 +19,3 @@ "use strict";

class DocHeaderNode {
constructor() {
this.newLines = 1;
}
newLines = 1;
generateCode(out) {

@@ -24,0 +22,0 @@ out('/*');

@@ -5,8 +5,2 @@ "use strict";

*/
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _DocNode_nodes;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -24,17 +18,15 @@ exports.DocNode = void 0;

class DocNode {
constructor() {
this.newLines = 0;
this.header = new DocHeaderNode_1.DocHeaderNode();
this.import = new HaystackCoreImportNode_1.HaystackCoreImportNode();
this.libs = new LibsNode_1.LibsNode();
_DocNode_nodes.set(this, new Map());
}
newLines = 0;
header = new DocHeaderNode_1.DocHeaderNode();
import = new HaystackCoreImportNode_1.HaystackCoreImportNode();
libs = new LibsNode_1.LibsNode();
#nodes = new Map();
addInterface(intNode) {
__classPrivateFieldGet(this, _DocNode_nodes, "f").set(intNode.name, intNode);
this.#nodes.set(intNode.name, intNode);
}
addNamespace(nsNode) {
__classPrivateFieldGet(this, _DocNode_nodes, "f").set(`${nsNode.name}:${nsNode.intNode.name}`, nsNode);
this.#nodes.set(`${nsNode.name}:${nsNode.intNode.name}`, nsNode);
}
addTypeGuard(tgNode) {
__classPrivateFieldGet(this, _DocNode_nodes, "f").set(`tg-${tgNode.name}`, tgNode);
this.#nodes.set(`tg-${tgNode.name}`, tgNode);
}

@@ -47,7 +39,7 @@ generateCode(out) {

this.libs,
...__classPrivateFieldGet(this, _DocNode_nodes, "f").values(),
...this.#nodes.values(),
]);
}
addAllValuesToImport() {
const nodes = __classPrivateFieldGet(this, _DocNode_nodes, "f");
const nodes = this.#nodes;
const imp = this.import;

@@ -65,2 +57,1 @@ if (nodes.size) {

exports.DocNode = DocNode;
_DocNode_nodes = new WeakMap();

@@ -11,5 +11,5 @@ "use strict";

class HaystackCoreImportNode {
types = new Set();
newLines = 1;
constructor(types = []) {
this.types = new Set();
this.newLines = 1;
for (const type of types) {

@@ -16,0 +16,0 @@ this.types.add(type);

@@ -12,4 +12,9 @@ "use strict";

class InterfaceNode {
def;
name;
doc;
extend;
values;
newLines = 1;
constructor({ def, name, doc, extend, values, }) {
this.newLines = 1;
this.def = def;

@@ -16,0 +21,0 @@ this.name = name;

@@ -12,8 +12,15 @@ "use strict";

class InterfaceValueNode {
name;
doc;
type;
kind;
genericType;
genericKind;
optional;
/**
* The number of new lines after this node is set dynamically depending on its
* position in the parent interface.
*/
newLines = 1;
constructor({ name, type, kind, doc, genericType, genericKind, optional, }) {
/**
* The number of new lines after this node is set dynamically depending on its
* position in the parent interface.
*/
this.newLines = 1;
this.name = name;

@@ -20,0 +27,0 @@ this.type = type;

@@ -5,8 +5,2 @@ "use strict";

*/
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _LibsNode_libs;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -18,8 +12,6 @@ exports.LibsNode = void 0;

class LibsNode {
constructor() {
this.newLines = 1;
_LibsNode_libs.set(this, new Set());
}
newLines = 1;
#libs = new Set();
generateCode(out) {
const libs = [...__classPrivateFieldGet(this, _LibsNode_libs, "f")];
const libs = [...this.#libs];
out('/**');

@@ -47,6 +39,5 @@ out(' * Libraries used for code generation.');

addLib(lib) {
__classPrivateFieldGet(this, _LibsNode_libs, "f").add(lib);
this.#libs.add(lib);
}
}
exports.LibsNode = LibsNode;
_LibsNode_libs = new WeakMap();

@@ -12,4 +12,7 @@ "use strict";

class NamespaceNode {
name;
intNode;
doc;
newLines = 2;
constructor(name, intNode, doc) {
this.newLines = 2;
this.name = name;

@@ -16,0 +19,0 @@ this.intNode = intNode;

@@ -12,5 +12,7 @@ "use strict";

class TypeGuardNode {
def;
name;
newLines = 1;
types = ['HNamespace'];
constructor(def, name) {
this.newLines = 1;
this.types = ['HNamespace'];
this.def = def;

@@ -17,0 +19,0 @@ this.name = name;

@@ -15,3 +15,3 @@ {

"email": "support@j2inn.com",
"version": "0.24.0",
"version": "0.25.0",
"module": "dist/index.es.js",

@@ -77,4 +77,4 @@ "main": "dist/index.js",

"commander": "^9.4.0",
"haystack-core": "^2.0.50",
"haystack-nclient": "^3.0.38",
"haystack-core": "^2.0.51",
"haystack-nclient": "^3.0.39",
"node-fetch": "^2.6.5"

@@ -81,0 +81,0 @@ },

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