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

@compas/code-gen

Package Overview
Dependencies
Maintainers
1
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@compas/code-gen - npm Package Compare versions

Comparing version 0.0.119 to 0.0.120

10

package.json
{
"name": "@compas/code-gen",
"version": "0.0.119",
"version": "0.0.120",
"description": "Generate various boring parts of your server",

@@ -18,5 +18,5 @@ "main": "./index.js",

"dependencies": {
"@compas/cli": "0.0.119",
"@compas/insight": "0.0.119",
"@compas/stdlib": "0.0.119"
"@compas/cli": "0.0.120",
"@compas/insight": "0.0.120",
"@compas/stdlib": "0.0.120"
},

@@ -44,3 +44,3 @@ "maintainers": [

},
"gitHead": "84e343f51fcddbb583e8fbd0fea576e8bc55ffb2"
"gitHead": "21e68cdcd1a9330d5841c3de9c8823295c27a61a"
}

@@ -43,3 +43,3 @@ // Generated by @compas/code-gen

/**
* @typedef {{"type": "object", "docString": string, "isOptional": boolean, "defaultValue"?: undefined|string|boolean|number, "uniqueName"?: undefined|string, "group"?: undefined|string, "name"?: undefined|string, "sql"?: undefined|{"primary": boolean, "searchable": boolean, }, "validator": {"strict": boolean, }, "shortName"?: undefined|string, "keys": Object<string, CodeGenType>, "enableQueries": boolean, "queryOptions"?: undefined|{"withSoftDeletes": boolean, "withDates": boolean, "withPrimaryKey": boolean, "isView": boolean, }, "relations": (CodeGenRelationType)[], "where"?: undefined|{"type": string, "fields": ({"key": string, "name": string, "variant": "equal"|"notEqual"|"in"|"notIn"|"greaterThan"|"lowerThan"|"isNull"|"isNotNull"|"includeNotNull"|"like"|"iLike"|"notLike", })[], }, "orderBy"?: undefined|{"type": string, "specType": string, "fields": ({"key": string, "optional": boolean, "options": ("ASC"|"DESC"|"ASC NULLS FIRST"|"ASC NULLS LAST"|"DESC NULLS FIRST"|"DESC NULLS LAST")[], })[], }, "partial"?: undefined|{"insertType": string, "updateType": string, "fields": ({"key": string, "defaultValue"?: undefined|string, "isJsonb": boolean, })[], }, }} CodeGenObjectType
* @typedef {{"type": "object", "docString": string, "isOptional": boolean, "defaultValue"?: undefined|string|boolean|number, "uniqueName"?: undefined|string, "group"?: undefined|string, "name"?: undefined|string, "sql"?: undefined|{"primary": boolean, "searchable": boolean, }, "validator": {"strict": boolean, }, "shortName"?: undefined|string, "keys": Object<string, CodeGenType>, "enableQueries": boolean, "queryOptions"?: undefined|{"withSoftDeletes": boolean, "withDates": boolean, "withPrimaryKey": boolean, "isView": boolean, }, "relations": (CodeGenRelationType)[], "where"?: undefined|{"type": string, "fields": ({"key": string, "name": string, "variant": "equal"|"notEqual"|"in"|"notIn"|"greaterThan"|"lowerThan"|"isNull"|"isNotNull"|"includeNotNull"|"like"|"iLike"|"notLike", })[], }, "orderBy"?: undefined|{"type": string, "specType": string, "fields": ({"key": string, "optional": boolean, })[], }, "partial"?: undefined|{"insertType": string, "updateType": string, "fields": ({"key": string, "defaultValue"?: undefined|string, "isJsonb": boolean, })[], }, }} CodeGenObjectType
*/

@@ -46,0 +46,0 @@ /**

@@ -6,2 +6,3 @@ import { merge } from "@compas/stdlib";

import { ObjectType } from "../../builders/ObjectType.js";
import { ReferenceType } from "../../builders/ReferenceType.js";
import { StringType } from "../../builders/StringType.js";

@@ -20,5 +21,26 @@ import { addToData } from "../../generate.js";

export function createOrderByTypes(context) {
const defaults = new StringType().optional().oneOf("foo").build();
delete defaults.oneOf;
const orderByType = new StringType("compas", "sqlOrderBy")
.oneOf("ASC", "DESC")
.build();
const orderByOptionalField = new StringType(
"compas",
"sqlOrderByOptionalField",
)
.oneOf("ASC", "DESC", "ASC NULLS FIRST", "DESC NULLS LAST")
.build();
const orderByReference = new ReferenceType("compas", "sqlOrderBy")
.optional()
.build();
const orderByOptionalFieldReference = new ReferenceType(
"compas",
"sqlOrderByOptionalField",
)
.optional()
.build();
addToData(context.structure, orderByType);
addToData(context.structure, orderByOptionalField);
for (const type of getQueryEnabledObjects(context)) {

@@ -29,2 +51,3 @@ const fields = getSearchableFields(type);

// AnyOf: QueryPart & an array of searchable fields
const orderByType = new AnyOfType(type.group, `${type.name}OrderBy`)

@@ -34,5 +57,11 @@ .values()

// Array of searchable fields
const orderByArrayType = new ArrayType()
.values(new StringType().oneOf("foo"))
.build();
// Reset searchable fields array
orderByArrayType.values.oneOf = [];
// Object mapping searchable fields to possible values
const orderBySpecType = new ObjectType(

@@ -60,4 +89,2 @@ type.group,

);
// Reset oneOf array
orderByArrayType.values.oneOf = [];

@@ -67,18 +94,16 @@ for (const key of Object.keys(fields)) {

const options = ["ASC", "DESC"];
let usedReference = orderByReference;
if (fieldType.isOptional) {
if (
(key !== "createdAt" && key !== "updatedAt" && key !== "deletedAt") ||
(!type.queryOptions.withSoftDeletes && !type.queryOptions.withDates)
)
options.push(
"ASC NULLS FIRST",
"ASC NULLS LAST",
"DESC NULLS FIRST",
"DESC NULLS LAST",
);
if (
fieldType.isOptional &&
((key !== "createdAt" && key !== "updatedAt") ||
(!type.queryOptions.withSoftDeletes && !type.queryOptions.withDates))
) {
usedReference = orderByOptionalFieldReference;
}
orderBySpecType.keys[key] = merge({}, defaults, { oneOf: options });
orderBySpecType.keys[key] = merge({}, usedReference);
orderBySpecType.keys[key].reference =
context.structure["compas"][usedReference.reference.name];
orderByArrayType.values.oneOf.push(key);

@@ -89,3 +114,2 @@

optional: fieldType.isOptional,
options,
});

@@ -92,0 +116,0 @@ }

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

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